From ec6306ad1e746d47ed66af6274fb6710c70933a2 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 3 Feb 2015 22:54:17 +0100 Subject: Fixed XML-Importer failing --- src/plugins/xml/XmlParser.cpp | 68 ++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-) (limited to 'src/plugins/xml/XmlParser.cpp') diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index f4e5caf..e56d528 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -86,12 +86,6 @@ public: project()->createTypesystem(args["name"].asString()); typesystem->setLocation(location()); - // Check whether this typesystem is a direct child of a domain - Handle parent = scope().select({&RttiTypes::Domain}); - if (parent != nullptr) { - parent.cast()->referenceTypesystem(typesystem); - } - // Push the typesystem onto the scope, set the POST_HEAD flag to true scope().push(typesystem); scope().setFlag(ParserFlag::POST_HEAD, false); @@ -105,7 +99,7 @@ public: } }; -class TypesystemStructHandler : public Handler { +class TypesystemEnumHandler : public Handler { public: using Handler::Handler; @@ -118,7 +112,7 @@ public: const std::string &parent = args["parent"].asString(); // Fetch the current typesystem and create the struct node - Rooted typesystem = scope().select(); + Rooted typesystem = scope().selectOrThrow(); Rooted structType = typesystem->createStructType(name); structType->setLocation(location()); @@ -134,14 +128,54 @@ public: } }); } + scope().push(structType); + } + + void end() override + { + scope().pop(); + } + + static Handler *create(const HandlerData &handlerData) + { + return new TypesystemEnumHandler{handlerData}; + } +}; + +class TypesystemStructHandler : public Handler { +public: + using Handler::Handler; + + void start(Variant::mapType &args) override + { + scope().setFlag(ParserFlag::POST_HEAD, true); - // Descend into the struct type + // Fetch the arguments used for creating this type + const std::string &name = args["name"].asString(); + const std::string &parent = args["parent"].asString(); + + // Fetch the current typesystem and create the struct node + Rooted typesystem = scope().selectOrThrow(); + Rooted structType = typesystem->createStructType(name); + structType->setLocation(location()); + + // Try to resolve the parent type and set it as parent structure + if (!parent.empty()) { + scope().resolve( + parent, structType, logger(), + [](Handle parent, Handle structType, + Logger &logger) { + if (parent != nullptr) { + structType.cast()->setParentStructure( + parent.cast(), logger); + } + }); + } scope().push(structType); } void end() override { - // Descend from the struct type scope().pop(); } @@ -164,7 +198,7 @@ public: const bool optional = !(defaultValue.isObject() && defaultValue.asObject() == nullptr); - Rooted structType = scope().select(); + Rooted structType = scope().selectOrThrow(); Rooted attribute = structType->createAttribute(name, defaultValue, optional, logger()); attribute->setLocation(location()); @@ -212,7 +246,7 @@ public: const std::string &type = args["type"].asString(); const Variant &value = args["value"]; - Rooted typesystem = scope().select(); + Rooted typesystem = scope().selectOrThrow(); Rooted constant = typesystem->createConstant(name, value); constant->setLocation(location()); @@ -266,7 +300,7 @@ public: const std::string &isa = args["isa"].asString(); - Rooted domain = scope().select(); + Rooted domain = scope().selectOrThrow(); Rooted structuredClass = domain->createStructuredClass( args["name"].asString(), args["cardinality"].asCardinality(), nullptr, nullptr, args["transparent"].asBool(), @@ -439,13 +473,14 @@ static const ParserState Typesystem = .elementHandler(TypesystemHandler::create) .arguments({Argument::String("name", "")}); static const ParserState TypesystemEnum = - ParserStateBuilder().createdNodeType(&RttiTypes::EnumType).parent( - &Typesystem); + ParserStateBuilder() + .createdNodeType(&RttiTypes::EnumType) + .elementHandler(TypesystemEnumHandler::create) + .parent(&Typesystem); static const ParserState TypesystemStruct = ParserStateBuilder() .parent(&Typesystem) .createdNodeType(&RttiTypes::StructType) - .elementHandler(TypesystemStructHandler::create) .arguments({Argument::String("name"), Argument::String("parent", "")}); static const ParserState TypesystemStructField = @@ -458,7 +493,6 @@ static const ParserState TypesystemConstant = ParserStateBuilder() .parent(&Typesystem) .createdNodeType(&RttiTypes::Constant) - .elementHandler(TypesystemConstantHandler::create) .arguments({Argument::String("name"), Argument::String("type"), Argument::Any("value")}); -- cgit v1.2.3