diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/parser/ParserScope.cpp | 48 | ||||
| -rw-r--r-- | src/core/parser/ParserScope.hpp | 41 | 
2 files changed, 73 insertions, 16 deletions
| diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index 5440b9c..3929abf 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -38,19 +38,6 @@ Rooted<Node> ParserScopeBase::resolve(const Rtti *type,                                        const std::vector<std::string> &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<std::string> descPath; -		descPath.insert(descPath.end(), path.begin(), path.end() - 1); -		Rooted<Node> res = resolve(&RttiTypes::Descriptor, descPath, logger); -		if (res == nullptr) { -			return nullptr; -		} -		return res.cast<Descriptor>()->getFieldDescriptor(); -	} -  	// Go up the stack and try to resolve the  	for (auto it = nodes.rbegin(); it != nodes.rend(); it++) {  		std::vector<ResolutionResult> res = (*it)->resolve(type, path); @@ -486,5 +473,40 @@ bool ParserScope::performDeferredResolution(Logger &logger)  	deferred.clear();  	return false;  } + +bool ParserScope::resolveFieldDescriptor( +    const std::vector<std::string> &path, Handle<Node> owner, Logger &logger, +    ResolutionResultCallback resultCallback) +{ +	// if the last element of the path is the default field name, we want to +	// resolve the parent descriptor first. +	if (path.back() == DEFAULT_FIELD_NAME) { +		std::vector<std::string> descPath; +		descPath.insert(descPath.end(), path.begin(), path.end() - 1); +		return resolve(&RttiTypes::Descriptor, descPath, owner, logger, +		               [resultCallback](Handle<Node> resolved, +		                                Handle<Node> owner, Logger &logger) { +			if (resolved != nullptr) { +				resultCallback( +				    resolved.cast<Descriptor>()->getFieldDescriptor(), owner, +				    logger); +			} else { +				resultCallback(nullptr, owner, logger); +			} +		}); +	} + +	// If it is not the default field, we can just forward to resolve +	return resolve(&RttiTypes::FieldDescriptor, path, owner, logger, +	               resultCallback); +} + +bool ParserScope::resolveFieldDescriptor( +    const std::string &name, Handle<Node> owner, Logger &logger, +    ResolutionResultCallback resultCallback) +{ +	return resolveFieldDescriptor(Utils::split(name, '.'), owner, logger, +	                              resultCallback); +}  } diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index bd6a29f..58fc037 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -679,7 +679,6 @@ public:  	 * Resolves a typesystem type. Makes sure an array type is returned if an  	 * array type is requested.  	 * -	 * @tparam T is the type of the node that should be resolved.  	 * @param name is the path for which a node should be resolved. The name is  	 * split at '.' to form a path.  	 * @param owner is the node for which the resolution takes place. @@ -715,7 +714,6 @@ public:  	 * Resolves a type and makes sure the corresponding value is of the correct  	 * type.  	 * -	 * @tparam T is the type of the node that should be resolved.  	 * @param path is the path for which a node should be resolved.  	 * @param owner is the node for which the resolution takes place.  	 * @param value is a reference at the Variant that represents the value for @@ -739,7 +737,6 @@ public:  	 * Resolves a type and makes sure the corresponding value is of the correct  	 * type.  	 * -	 * @tparam T is the type of the node that should be resolved.  	 * @param name is the path for which a node should be resolved. The name is  	 * split at '.' to form a path.  	 * @param owner is the node for which the resolution takes place. @@ -760,6 +757,44 @@ public:  	                          ResolutionResultCallback resultCallback);  	/** +	 * Resolves a FieldDescriptor. Makes sure that the default field can be +	 * handled. +	 * +	 * @param path is the path for which a node should be resolved. +	 * @param owner is the node for which the resolution takes place. +	 * @param logger is the logger instance into which resolution problems +	 * should be logged. +	 * @param resultCallback is the callback function to which the result of +	 * the resolution process is passed. This function is called once the +	 * resolution was successful. +	 * @return true if the resolution was immediately successful. This does not +	 * mean, that the resolved object does not exist, as it may be resolved +	 * later. +	 */ +	bool resolveFieldDescriptor(const std::vector<std::string> &path, +	                            Handle<Node> owner, Logger &logger, +	                            ResolutionResultCallback resultCallback); + +	/** +	 * Resolves a FieldDescriptor. Makes sure that the default field can be +	 * handled. +	 * +	 * @param name is the path for which a node should be resolved. The name is +	 * split at '.' to form a path. +	 * @param owner is the node for which the resolution takes place. +	 * @param logger is the logger instance into which resolution problems +	 * should be logged. +	 * @param resultCallback is the callback function to which the result of +	 * the resolution process is passed. This function is called once the +	 * resolution was successful. +	 * @return true if the resolution was immediately successful. This does not +	 * mean, that the resolved object does not exist, as it may be resolved +	 * later. +	 */ +	bool resolveFieldDescriptor(const std::string &name, Handle<Node> owner, +	                            Logger &logger, +	                            ResolutionResultCallback resultCallback); +	/**  	 * Tries to resolve all currently deferred resolution steps. The list of  	 * pending deferred resolutions is cleared after this function has run.  	 * | 
