From be79585f0e81b27ce3dc6b94f1f502ff86dcef68 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 12 Apr 2015 17:34:09 +0200 Subject: Pass "isImplicit" flag to Handler::fieldStart --- src/core/parser/stack/DocumentHandler.cpp | 9 +++++++-- src/core/parser/stack/DocumentHandler.hpp | 9 +++++++-- src/core/parser/stack/Handler.cpp | 6 ++++-- src/core/parser/stack/Handler.hpp | 9 ++++++--- src/core/parser/stack/Stack.cpp | 11 +++++++---- 5 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index e6af615..0912eb6 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -87,7 +87,9 @@ Rooted DocumentField::getDescriptor() /* DocumentChildHandler */ DocumentChildHandler::DocumentChildHandler(const HandlerData &handlerData) - : Handler(handlerData), isExplicitField(false) + : Handler(handlerData), + isExplicitField(false), + inImplicitDefaultField(false) { // Register all user defined tokens if this has not yet been done if (!scope().getFlag(ParserFlag::POST_USER_DEFINED_TOKEN_REGISTRATION)) { @@ -670,13 +672,15 @@ void DocumentChildHandler::end() } } -bool DocumentChildHandler::fieldStart(bool &isDefault, size_t fieldIdx) +bool DocumentChildHandler::fieldStart(bool &isDefault, bool isImplicit, + size_t fieldIdx) { if (isExplicitField) { // In case of explicit fields we do not want to create another field. isDefault = true; return fieldIdx == 0; } + inImplicitDefaultField = isImplicit; Rooted parentNode = scope().getLeaf(); assert(parentNode->isa(&RttiTypes::StructuredEntity) || @@ -717,6 +721,7 @@ void DocumentChildHandler::fieldEnd() popTokens(); rollbackPath(); } + inImplicitDefaultField = false; } bool DocumentChildHandler::convertData(Handle field, diff --git a/src/core/parser/stack/DocumentHandler.hpp b/src/core/parser/stack/DocumentHandler.hpp index 3ef5f08..d047666 100644 --- a/src/core/parser/stack/DocumentHandler.hpp +++ b/src/core/parser/stack/DocumentHandler.hpp @@ -112,7 +112,12 @@ private: /** * If set to true, this handler represents an explicit field. */ - bool isExplicitField; + bool isExplicitField : 1; + + /** + * Set to true if the handler currently is in an implicit field. + */ + bool inImplicitDefaultField : 1; /** * Registers all user defined tokens in the parser. @@ -225,7 +230,7 @@ public: EndTokenResult endToken(Handle node, size_t maxStackDepth) override; void end() override; bool data() override; - bool fieldStart(bool &isDefault, size_t fieldIdx) override; + bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override; void fieldEnd() override; /** diff --git a/src/core/parser/stack/Handler.cpp b/src/core/parser/stack/Handler.cpp index 69bfc76..850da74 100644 --- a/src/core/parser/stack/Handler.cpp +++ b/src/core/parser/stack/Handler.cpp @@ -146,7 +146,8 @@ void EmptyHandler::end() // Do nothing if a command ends } -bool EmptyHandler::fieldStart(bool &isDefaultField, size_t fieldIndex) +bool EmptyHandler::fieldStart(bool &isDefaultField, bool isImplicit, + size_t fieldIndex) { // Accept any field return true; @@ -191,7 +192,8 @@ void StaticHandler::end() // Do nothing here } -bool StaticHandler::fieldStart(bool &isDefault, size_t fieldIdx) +bool StaticHandler::fieldStart(bool &isDefault, bool isImplicit, + size_t fieldIdx) { // Return true if either the default field is requested or the field index // is zero. This simulates that there is exactly one field (a default field) diff --git a/src/core/parser/stack/Handler.hpp b/src/core/parser/stack/Handler.hpp index bd6ea72..40b4fba 100644 --- a/src/core/parser/stack/Handler.hpp +++ b/src/core/parser/stack/Handler.hpp @@ -425,9 +425,12 @@ public: * @param isDefault is set to true if the field that is being started is the * default/tree field. The handler should set the value of this variable to * true if the referenced field is indeed the default field. + * @param isImplicit is set to true if the field was implicitly started + * (if true, isDefault is also set to true). * @param fieldIdx is the numerical index of the field. */ - virtual bool fieldStart(bool &isDefault, size_t fieldIdx) = 0; + virtual bool fieldStart(bool &isDefault, bool isImplicit, + size_t fieldIdx) = 0; /** * Called when a previously opened field ends, while the handler is active. @@ -470,7 +473,7 @@ public: bool startToken(Handle node) override; EndTokenResult endToken(Handle node, size_t maxStackDepth) override; void end() override; - bool fieldStart(bool &isDefault, size_t fieldIdx) override; + bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override; void fieldEnd() override; bool data() override; @@ -495,7 +498,7 @@ public: bool startToken(Handle node) override; EndTokenResult endToken(Handle node, size_t maxStackDepth) override; void end() override; - bool fieldStart(bool &isDefault, size_t fieldIdx) override; + bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override; void fieldEnd() override; bool data() override; }; diff --git a/src/core/parser/stack/Stack.cpp b/src/core/parser/stack/Stack.cpp index 696a070..2fe4a8f 100644 --- a/src/core/parser/stack/Stack.cpp +++ b/src/core/parser/stack/Stack.cpp @@ -799,7 +799,8 @@ bool StackImpl::prepareCurrentHandler(bool startImplicitDefaultField, // Try to start a new default field, abort if this did not work if (startImplicitDefaultField) { bool isDefault = true; - if (!info.handler->fieldStart(isDefault, info.fieldIdx)) { + if (!info.handler->fieldStart(isDefault, !info.range, + info.fieldIdx)) { endCurrentHandler(); continue; } @@ -1211,8 +1212,9 @@ void StackImpl::handleFieldEnd(bool endRange) if (info.range && endRange) { if (!info.hadDefaultField) { bool isDefault = true; - bool valid = info.handler->fieldStart(isDefault, true); - info.fieldStart(true, true, valid); + bool valid = + info.handler->fieldStart(isDefault, false, info.fieldIdx); + info.fieldStart(true, false, valid); } endCurrentHandler(); return; @@ -1453,7 +1455,8 @@ void StackImpl::fieldStart(bool isDefault) bool valid = false; if (handlersValid() && !info.hadDefaultField) { try { - valid = info.handler->fieldStart(defaultField, info.fieldIdx); + valid = + info.handler->fieldStart(defaultField, false, info.fieldIdx); } catch (LoggableException ex) { logger().log(ex); -- cgit v1.2.3