diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-19 01:25:55 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-19 01:25:55 +0100 |
commit | 7df42d9e82fe935f9941aa20e2d118188e888573 (patch) | |
tree | 9851c390e8b878f1b6e972e07c9564fd69d27828 | |
parent | 5e779c017020a8e0405ee8e43c6ea7d4a9a11ad2 (diff) |
XML-Parsing for Typesystem structs works so far
-rw-r--r-- | src/core/model/Project.cpp | 1 | ||||
-rw-r--r-- | src/core/parser/Scope.cpp | 29 | ||||
-rw-r--r-- | src/core/parser/Scope.hpp | 10 | ||||
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 2 | ||||
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 23 |
5 files changed, 32 insertions, 33 deletions
diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp index c491d4f..fc08660 100644 --- a/src/core/model/Project.cpp +++ b/src/core/model/Project.cpp @@ -100,6 +100,7 @@ const Rtti Project = RttiBuilder<model::Project>("Project") .parent(&Node) .composedOf(&Document) .composedOf(&Typesystem) + .composedOf(&SystemTypesystem) .composedOf(&Domain); } } diff --git a/src/core/parser/Scope.cpp b/src/core/parser/Scope.cpp index 6942b9a..01292df 100644 --- a/src/core/parser/Scope.cpp +++ b/src/core/parser/Scope.cpp @@ -119,7 +119,7 @@ Rooted<Node> Scope::getLeaf() { return nodes.back(); } bool Scope::resolve(const std::vector<std::string> &path, const Rtti &type, Logger &logger, ResolutionImposterCallback imposterCallback, ResolutionResultCallback resultCallback, - const SourceLocation &location) + const SourceLocation &location) { if (!resolve(path, type, logger, resultCallback, location)) { resultCallback(imposterCallback(), logger); @@ -168,22 +168,21 @@ bool Scope::performDeferredResolution(Logger &logger) } } - // Output an error message if there are still deferred elements left that - // could not be resolved - if (!deferred.empty()) { - for (const auto &failed : deferred) { - logger.error( - std::string("Could not resolve a reference to \"") + - Utils::join(failed.path, ".") + - std::string("\" of type " + failed.type.name), - failed.location); - } + // We were successful if there are no more deferred resolutions + if (deferred.empty()) { + return true; } - // We were successful if there are no more deferred resolutions - return deferred.empty(); + // Output error messages for all elements for which resolution did not + // succeed. + for (const auto &failed : deferred) { + logger.error(std::string("Could not resolve ") + failed.type.name + std::string(" \"") + + Utils::join(failed.path, ".") + + std::string("\""), + failed.location); + } + deferred.clear(); + return false; } - -void Scope::purgeDeferredResolutions() { deferred.clear(); } } } diff --git a/src/core/parser/Scope.hpp b/src/core/parser/Scope.hpp index 1ceac2e..b9b7f80 100644 --- a/src/core/parser/Scope.hpp +++ b/src/core/parser/Scope.hpp @@ -467,18 +467,12 @@ public: } /** - * Tries to resolve all currently deferred resolution steps. + * Tries to resolve all currently deferred resolution steps. The list of + * pending deferred resolutions is cleared after this function has run. * * @param logger is the logger instance into which errors should be logged. */ bool performDeferredResolution(Logger &logger); - - /** - * Clears the list of currently deferred resolutions. This function may be - * used to gracefully continue parsing, even after the resolution has - * failed. - */ - void purgeDeferredResolutions(); }; } } diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index bcac7d3..434a72c 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -60,7 +60,7 @@ public: void start(Variant::mapType &args) override { - scope().push(new model::Typesystem(manager(), args["name"].asString())); + scope().push(project()->createTypesystem(args["name"].asString())); } void end() override diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index 6ac2fc1..f1956e0 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -53,22 +53,26 @@ const char *TEST_DATA = " <head>\n" " <typesystem name=\"color\">\n" " <types>\n" - " <struct name=\"color\" parent=\"blub\">\n" - " <field name=\"r\" type=\"int\"/>\n" - " <field name=\"g\" type=\"int\"/>\n" - " <field name=\"b\" type=\"int\"/>\n" + " <struct name=\"rgb\">\n" + " <field name=\"r\" type=\"double\"/>\n" + " <field name=\"g\" type=\"double\"/>\n" + " <field name=\"b\" type=\"double\"/>\n" " </struct>\n" - " <struct name=\"blub\">\n" - " <field name=\"a\" type=\"int\"/>\n" + " <struct name=\"rgba\" parent=\"rgb\">\n" + " <field name=\"a\" type=\"double\" default=\"0xf3\"/>\n" " </struct>\n" - " <struct name=\"blub\">\n" - " <field name=\"a\" type=\"int\"/>\n" + " </types>\n" + " </typesystem>\n" + " <typesystem name=\"color2\">\n" + " <types>\n" + " <struct name=\"rgba\" parent=\"rgb\">\n" + " <field name=\"a\" type=\"bla\" default=\"0xf3\"/>\n" " </struct>\n" " </types>\n" " </typesystem>\n" " </head>\n" " <body xmlAttr=\"blub\">\n" - " <book>Dies ist ein Test></book>\n" + " <!--<book>Dies ist ein Test></book>-->\n" " </body>\n" "</document>\n"; @@ -86,6 +90,7 @@ TEST(XmlParser, namespaces) catch (LoggableException ex) { logger.log(ex); } + ctx.manager.exportGraphviz("xmlDocument.dot"); } } } |