From 339683e64288a85b8d6f9355a10563417b7d2fa7 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 12 Feb 2015 00:05:08 +0100 Subject: addes special resolve case in ParserScope::resolve for default field descriptors and changed resolve mechanism in parent field refs to just asking for the FieldDescriptor with the given name. --- src/core/parser/ParserScope.cpp | 14 ++++++++++++++ src/plugins/xml/XmlParser.cpp | 15 ++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index 9c0b729..5440b9c 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "ParserScope.hpp" @@ -37,6 +38,19 @@ Rooted ParserScopeBase::resolve(const Rtti *type, const std::vector &path, Logger &logger) { + // if the last element of the path is the default field name, we want to + // resolve the parent descriptor first. + if (type == &RttiTypes::FieldDescriptor && + path.back() == DEFAULT_FIELD_NAME) { + std::vector descPath; + descPath.insert(descPath.end(), path.begin(), path.end() - 1); + Rooted res = resolve(&RttiTypes::Descriptor, descPath, logger); + if (res == nullptr) { + return nullptr; + } + return res.cast()->getFieldDescriptor(); + } + // Go up the stack and try to resolve the for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { std::vector res = (*it)->resolve(type, path); diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index d7efa4d..e0346ab 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -785,16 +785,14 @@ public: Handle strct, Logger &logger) { if (parent != nullptr) { - auto res = parent.cast()->resolve( - &RttiTypes::FieldDescriptor, name); - if (res.size() != 1) { + Rooted field = + parent.cast()->getFieldDescriptor(name); + if (field == nullptr) { logger.error( std::string("Could not find referenced field ") + name, loc); return; } - Rooted field = - res[0].node.cast(); field->addChild(strct.cast()); } }); @@ -985,10 +983,9 @@ static const ParserState DomainStructPrimitive = .parents({&DomainStruct, &DomainAnnotation}) .createdNodeType(&RttiTypes::FieldDescriptor) .elementHandler(DomainPrimitiveHandler::create) - .arguments({Argument::String("name", ""), - Argument::Bool("isSubtree", false), - Argument::Bool("optional", false), - Argument::String("type")}); + .arguments( + {Argument::String("name", ""), Argument::Bool("isSubtree", false), + Argument::Bool("optional", false), Argument::String("type")}); static const ParserState DomainStructChild = ParserStateBuilder() -- cgit v1.2.3