diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-12 17:34:09 +0200 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:15 +0200 | 
| commit | be79585f0e81b27ce3dc6b94f1f502ff86dcef68 (patch) | |
| tree | bce664b2d1827e4e7d12f674c51471d586fd3b2c | |
| parent | ebc411f2bc9cb7b1742ed5211d36a2b2ac57cdb5 (diff) | |
Pass "isImplicit" flag to Handler::fieldStart
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 9 | ||||
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.hpp | 9 | ||||
| -rw-r--r-- | src/core/parser/stack/Handler.cpp | 6 | ||||
| -rw-r--r-- | src/core/parser/stack/Handler.hpp | 9 | ||||
| -rw-r--r-- | src/core/parser/stack/Stack.cpp | 11 | ||||
| -rw-r--r-- | test/core/parser/stack/StackTest.cpp | 5 | 
6 files changed, 35 insertions, 14 deletions
| 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<FieldDescriptor> 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<Node> parentNode = scope().getLeaf();  	assert(parentNode->isa(&RttiTypes::StructuredEntity) || @@ -717,6 +721,7 @@ void DocumentChildHandler::fieldEnd()  		popTokens();  		rollbackPath();  	} +	inImplicitDefaultField = false;  }  bool DocumentChildHandler::convertData(Handle<FieldDescriptor> 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> 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> node) override;  	EndTokenResult endToken(Handle<Node> 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> node) override;  	EndTokenResult endToken(Handle<Node> 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); diff --git a/test/core/parser/stack/StackTest.cpp b/test/core/parser/stack/StackTest.cpp index e23cde7..739bc99 100644 --- a/test/core/parser/stack/StackTest.cpp +++ b/test/core/parser/stack/StackTest.cpp @@ -76,6 +76,7 @@ struct Tracker {  	bool fieldStartReturnValue;  	size_t fieldStartIdx;  	bool fieldStartIsDefault; +	bool fieldStartIsImplicit;  	bool fieldStartSetIsDefault;  	Variant dataData; @@ -105,6 +106,7 @@ struct Tracker {  		fieldStartIdx = 0;  		fieldStartIsDefault = false; +		fieldStartIsImplicit = false;  		fieldStartSetIsDefault = false;  		dataData = Variant{}; @@ -165,9 +167,10 @@ public:  	void end() override { tracker.endCount++; } -	bool fieldStart(bool &isDefault, size_t fieldIdx) override +	bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override  	{  		tracker.fieldStartIsDefault = isDefault; +		tracker.fieldStartIsImplicit = isImplicit;  		tracker.fieldStartIdx = fieldIdx;  		if (tracker.fieldStartSetIsDefault) {  			isDefault = true; | 
