diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-28 03:30:55 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-28 03:30:55 +0100 |
commit | 56bc493306c3b442ed0f2a3f040107c1807488a3 (patch) | |
tree | 79de212b525ff32fe1bb4aa22180af29b80ece49 /src/plugins/xml | |
parent | 6f25c96065a7ced66d3808e95344a2127055de05 (diff) |
Implemented constants
Diffstat (limited to 'src/plugins/xml')
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index d71ceac..f254326 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -161,7 +161,7 @@ public: const std::string &parent = args["parent"].asString(); // Fetch the current typesystem and create the struct node - Rooted<Typesystem> typesystem = scope().getLeaf().cast<Typesystem>(); + Rooted<Typesystem> typesystem = scope().select<Typesystem>(); Rooted<StructType> structType = typesystem->createStructType(name); structType->setLocation(location()); @@ -201,11 +201,11 @@ public: // Read the argument values const std::string &name = args["name"].asString(); const std::string &type = args["type"].asString(); - const Variant &defaultValue = args["default"]; + const Variant &defaultValue = args["default"]; // Build! const bool optional = !(defaultValue.isObject() && defaultValue.asObject() == nullptr); - Rooted<StructType> structType = scope().getLeaf().cast<StructType>(); + Rooted<StructType> structType = scope().select<StructType>(); Rooted<Attribute> attribute = structType->createAttribute(name, defaultValue, optional, logger()); attribute->setLocation(location()); @@ -227,6 +227,38 @@ public: } }; +class ConstantHandler : public Handler { +public: + using Handler::Handler; + + void start(Variant::mapType &args) override + { + // Read the argument values + const std::string &name = args["name"].asString(); + const std::string &type = args["type"].asString(); + const Variant &value = args["value"]; + + Rooted<Typesystem> typesystem = scope().select<Typesystem>(); + Rooted<Constant> constant = typesystem->createConstant(name, value); + constant->setLocation(location()); + + // Try to resolve the type + scope().resolve<Type>( + type, logger(), + [constant](Handle<Type> type, Logger &logger) mutable { + constant->setType(type, logger); + }, + location()); + } + + void end() override {} + + static Handler *create(const HandlerData &handlerData) + { + return new ConstantHandler{handlerData}; + } +}; + /* Document structure */ static const State STATE_DOCUMENT = 0; static const State STATE_DOCUMENT_HEAD = 1; @@ -289,7 +321,13 @@ static const std::multimap<std::string, HandlerDescriptor> XML_HANDLERS{ Argument::Any("default", Variant::fromObject(nullptr))}}}, {"constants", {{STATE_TYPESYSTEM}, DisableHeadHandler::create, STATE_CONSTANTS}}, - {"constant", {{STATE_CONSTANTS}, nullptr, STATE_CONSTANT}}}; + {"constant", + {{STATE_CONSTANTS}, + ConstantHandler::create, + STATE_CONSTANT, + false, + {Argument::String("name"), Argument::String("type"), + Argument::Any("value")}}}}; /** * Wrapper class around the XML_Parser pointer which safely frees it whenever |