diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-15 00:37:39 +0200 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:18 +0200 | 
| commit | 3803f1238f061a4cc962e67630c3bbbbae01eae5 (patch) | |
| tree | 4828a3473ce9fa48895fb51904ebcbe59e498a35 /src/core/parser | |
| parent | 3075b0de2e889199c65438d9b3680f08e75eaaeb (diff) | |
Replace Typesystem "MagicCallback" by a more generic one.
Diffstat (limited to 'src/core/parser')
| -rw-r--r-- | src/core/parser/ParserScope.cpp | 53 | ||||
| -rw-r--r-- | src/core/parser/ParserScope.hpp | 32 | ||||
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 4 | 
3 files changed, 26 insertions, 63 deletions
| diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index ed35839..5e4b37f 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -409,45 +409,20 @@ bool ParserScope::resolveType(const std::string &name, Handle<Node> owner,  	return resolveType(Utils::split(name, '.'), owner, logger, resultCallback);  } -bool ParserScope::resolveValue(Variant &data, Handle<Type> type, Logger &logger) +bool ParserScope::resolveValue(Variant &data, Handle<Node> owner, +                               Handle<Type> type, Logger &logger)  { -	return type->build( -	    data, logger, -	    [&](Variant &innerData, -	        const Type *innerType) mutable -> Type::MagicCallbackResult { -		    // Try to resolve the node -		    Rooted<Constant> constant = -		        ParserScopeBase::resolve(&RttiTypes::Constant, -		                                 Utils::split(innerData.asMagic(), '.'), -		                                 logger).cast<Constant>(); - -		    // Abort if nothing was found -		    if (constant == nullptr) { -			    return Type::MagicCallbackResult::NOT_FOUND; -		    } - -		    // Check whether the inner type of the constant is correct -		    Type::MagicCallbackResult res = -		        Type::MagicCallbackResult::FOUND_VALID; -		    Rooted<Type> constantType = constant->getType(); -		    if (!constantType->checkIsa(innerType)) { -			    logger.error(std::string("Expected value of type \"") + -			                     innerType->getName() + -			                     std::string("\" but found constant \"") + -			                     constant->getName() + -			                     std::string("\" of type \"") + -			                     constantType->getName() + "\" instead.", -			                 innerData); -			    logger.note("Constant was defined here:", *constant); -			    res = Type::MagicCallbackResult::FOUND_INVALID; -		    } - -		    // Set the data to the value of the constant (even if an error -		    // happend -- probably the type was not that wrong -- who knows?) -		    innerData = constant->getValue(); - -		    return res; -		}); +	return type->build(data, logger, +	                   [&](bool async, const Rtti *rttiType, +	                       const std::vector<std::string> &path, +	                       ResolutionResultCallback resultCallback) mutable { +		if (!async) { +			Rooted<Node> resolved = ParserScopeBase::resolve(rttiType, path, logger); +			resultCallback(resolved, owner, logger); +			return resolved != nullptr; +		} +		return resolve(rttiType, path, type, logger, resultCallback); +	});  }  bool ParserScope::resolveTypeWithValue(const std::vector<std::string> &path, @@ -465,7 +440,7 @@ bool ParserScope::resolveTypeWithValue(const std::vector<std::string> &path,  	    [=](Handle<Node> resolved, Handle<Node> owner, Logger &logger) mutable {  		    if (resolved != nullptr) {  			    Rooted<Type> type = resolved.cast<Type>(); -			    scope.resolveValue(*valuePtr, type, logger); +			    scope.resolveValue(*valuePtr, owner, type, logger);  		    }  		    // Call the result callback with the type diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index 85b5d8b..eec4751 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -28,6 +28,7 @@  #include <core/common/Rtti.hpp>  #include <core/common/Utils.hpp>  #include <core/model/Node.hpp> +#include <core/model/ResolutionCallbacks.hpp>  /**   * @file ParserScope.hpp @@ -48,23 +49,6 @@ class Type;  class Variant;  /** - * Callback function type used for creating a dummy object while no correct - * object is available for resolution. - */ -using ResolutionImposterCallback = std::function<Rooted<Node>()>; - -/** - * Callback function type called whenever the result of a resolution is - * available. - * - * @param resolved is the new, resolved node. - * @param owner is the node that was passed as "owner". - * @param logger is the logger to which errors should be logged. - */ -using ResolutionResultCallback = std::function< -    void(Handle<Node> resolved, Handle<Node> owner, Logger &logger)>; - -/**   * Base class for the ParserScope, does not contain the mechanisms for deferred   * lookup, only maintains the stack of nodes.   */ @@ -288,14 +272,14 @@ enum class ParserFlag {  	POST_HEAD,  	/** -	 * Set to the boolean value "true" if explicit fields may no longer be -	 * defined inside a structure element. -	 */ +     * Set to the boolean value "true" if explicit fields may no longer be +     * defined inside a structure element. +     */  	POST_EXPLICIT_FIELDS,  	/** -	 * Set to true if all user defined tokens have been registered. -	 */ +     * Set to true if all user defined tokens have been registered. +     */  	POST_USER_DEFINED_TOKEN_REGISTRATION  }; @@ -716,12 +700,14 @@ public:  	 * @param data is a reference at a variant that may contain magic values  	 * (even in inner structures). The data will be passed to the "build"  	 * function of the given type. +	 * @param owner is the node for which the resolution takes place.  	 * @param type is the Typesystem type the data should be interpreted with.  	 * @param logger is the logger instance into which resolution problems  	 * should be logged.  	 * @return true if the value was successfully built.  	 */ -	bool resolveValue(Variant &data, Handle<Type> type, Logger &logger); +	bool resolveValue(Variant &data, Handle<Node> owner, Handle<Type> type, +	                  Logger &logger);  	/**  	 * Resolves a type and makes sure the corresponding value is of the correct diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index 7564fad..2228f11 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -768,7 +768,9 @@ bool DocumentChildHandler::convertData(Handle<FieldDescriptor> field,  	}  	// Now try to resolve the value for the primitive type -	return valid && scope().resolveValue(data, type, logger); +	return valid && +	       scope().resolveValue(data, field->getParent().cast<Node>(), type, +	                            logger);  }  bool DocumentChildHandler::data() | 
