diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/model/Node.cpp | 26 | ||||
| -rw-r--r-- | src/core/model/Node.hpp | 17 | ||||
| -rw-r--r-- | src/core/parser/ParserScope.cpp | 35 | ||||
| -rw-r--r-- | src/core/parser/ParserScope.hpp | 89 | 
4 files changed, 80 insertions, 87 deletions
diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index 6c00e89..7cbbbe1 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -60,14 +60,14 @@ using VisitorSet =  class SharedResolutionState {  public:  	/** -	 * Actual path (name pattern) that was requested for resolution. +	 * Type of the node that was requested for resolution.  	 */ -	const std::vector<std::string> &path; +	const Rtti &type;  	/** -	 * Type of the node that was requested for resolution. +	 * Actual path (name pattern) that was requested for resolution.  	 */ -	const Rtti &type; +	const std::vector<std::string> &path;  	/**  	 * Tracks all nodes that have already been visited. @@ -82,13 +82,13 @@ public:  	/**  	 * Constructor of the SharedResolutionState class.  	 * +	 * @param type is the type of the node that should be resolved.  	 * @param path is a const reference to the actual path that should be  	 * resolved. -	 * @param type is the type of the node that should be resolved.  	 */ -	SharedResolutionState(const std::vector<std::string> &path, -	                      const Rtti &type) -	    : path(path), type(type) +	SharedResolutionState(const Rtti &type, +	                      const std::vector<std::string> &path) +	    : type(type), path(path)  	{  	}  }; @@ -329,10 +329,10 @@ bool Node::continueResolveReference(Handle<Node> h, ResolutionState &state)  }  std::vector<ResolutionResult> Node::resolve( -    const std::vector<std::string> &path, const Rtti &type) +    const Rtti &type, const std::vector<std::string> &path)  {  	// Create the state variables -	SharedResolutionState sharedState(path, type); +	SharedResolutionState sharedState(type, path);  	ResolutionState state(sharedState, this);  	// Kickstart the resolution process by treating this very node as compositum @@ -344,11 +344,11 @@ std::vector<ResolutionResult> Node::resolve(  	return sharedState.result;  } -std::vector<ResolutionResult> Node::resolve(const std::string &name, -                                            const Rtti &type) +std::vector<ResolutionResult> Node::resolve(const Rtti &type, +                                            const std::string &name)  {  	// Place the name in a vector and call the corresponding resolve function -	return resolve(std::vector<std::string>{name}, type); +	return resolve(type, std::vector<std::string>{name});  }  bool Node::checkDuplicate(Handle<Node> elem, diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 036bcae..61bf418 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -223,7 +223,7 @@ private:  	 * @param thisRef is the Node of which the reference should be returned.  	 * @return the value of the reference.  	 */ -	using NodeReferenceCallback = const Node* (const Node* thisRef); +	using NodeReferenceCallback = const Node *(const Node *thisRef);  	/**  	 * Checks whether the a certain property is acyclic. @@ -400,7 +400,8 @@ protected:  	 * @return true if the parent reference is acyclic, false otherwise.  	 */  	bool validateIsAcyclic(const std::string &name, -	                       NodeReferenceCallback callback, Logger &logger) const; +	                       NodeReferenceCallback callback, +	                       Logger &logger) const;  	/**  	 * Makes sure the "parent" reference is not cyclic. @@ -538,26 +539,26 @@ public:  	 * Function which resolves a name path to a list of possible nodes starting  	 * from this node.  	 * +	 * @param type specifies the type of the node that should be located.  	 * @param path is a list specifying a path of node names meant to specify a  	 * certain named node. -	 * @param type specifies the type of the node that should be located.  	 * @return a vector containing ResolutionResult structures which describe  	 * the resolved elements.  	 */ -	std::vector<ResolutionResult> resolve(const std::vector<std::string> &path, -	                                      const Rtti &type); +	std::vector<ResolutionResult> resolve(const Rtti &type, +	                                      const std::vector<std::string> &path);  	/**  	 * Function which resolves a single name to a list of possible nodes  	 * starting from this node.  	 * -	 * @param name is the name which should be resolved.  	 * @param type specifies the type of the node that should be located. +	 * @param name is the name which should be resolved.  	 * @return a vector containing ResolutionResult structures which describe  	 * the resolved elements.  	 */ -	std::vector<ResolutionResult> resolve(const std::string &name, -	                                      const Rtti &type); +	std::vector<ResolutionResult> resolve(const Rtti &type, +	                                      const std::string &name);  	/**  	 * Checks whether this node is valid and returns true if it is and false diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index 0de0dbf..b76bb28 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -31,12 +31,13 @@ ParserScopeBase::ParserScopeBase(const NodeVector<Node> &nodes) : nodes(nodes)  {  } -Rooted<Node> ParserScopeBase::resolve(const std::vector<std::string> &path, -                                      const Rtti &type, Logger &logger) +Rooted<Node> ParserScopeBase::resolve(const Rtti &type, +                                      const std::vector<std::string> &path, +                                      Logger &logger)  {  	// Go up the stack and try to resolve the  	for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { -		std::vector<ResolutionResult> res = (*it)->resolve(path, type); +		std::vector<ResolutionResult> res = (*it)->resolve(type, path);  		// Abort if the object could not be resolved  		if (res.empty()) { @@ -79,14 +80,14 @@ bool DeferredResolution::resolve(  	// Fork the logger to prevent error messages from being shown if we actively  	// ignore the resolution result  	LoggerFork loggerFork = logger.fork(); -	Rooted<Node> res = scope.resolve(path, type, loggerFork); +	Rooted<Node> res = scope.resolve(type, path, loggerFork);  	if (res != nullptr) {  		if (!ignore.count(res.get())) {  			loggerFork.commit();  			try {  				// Push the location onto the logger default location stack  				GuardedLogger loggerGuard(logger, *owner); -				resultCallback(res, logger); +				resultCallback(res, owner, logger);  			}  			catch (LoggableException ex) {  				logger.log(ex); @@ -227,29 +228,29 @@ bool ParserScope::getFlag(ParserFlag flag)  	return false;  } -bool ParserScope::resolve(const std::vector<std::string> &path, -                          const Rtti &type, Logger &logger, +bool ParserScope::resolve(const Rtti &type, +                          const std::vector<std::string> &path, +                          Handle<Node> owner, Logger &logger,                            ResolutionImposterCallback imposterCallback, -                          ResolutionResultCallback resultCallback, -                          Handle<Node> owner) +                          ResolutionResultCallback resultCallback)  { -	if (!resolve(path, type, logger, resultCallback, owner)) { -		resultCallback(imposterCallback(), logger); +	if (!resolve(type, path, owner, logger, resultCallback)) { +		resultCallback(imposterCallback(), owner, logger);  		return false;  	}  	return true;  } -bool ParserScope::resolve(const std::vector<std::string> &path, -                          const Rtti &type, Logger &logger, -                          ResolutionResultCallback resultCallback, -                          Handle<Node> owner) +bool ParserScope::resolve(const Rtti &type, +                          const std::vector<std::string> &path, +                          Handle<Node> owner, Logger &logger, +                          ResolutionResultCallback resultCallback)  {  	// Try to directly resolve the node -	Rooted<Node> res = ParserScopeBase::resolve(path, type, logger); +	Rooted<Node> res = ParserScopeBase::resolve(type, path, logger);  	if (res != nullptr && !awaitingResolution.count(res.get())) {  		try { -			resultCallback(res, logger); +			resultCallback(res, owner, logger);  		}  		catch (LoggableException ex) {  			logger.log(ex, *owner); diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index 2378967..e01acfe 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -50,14 +50,18 @@ class ParserScope;   * Callback function type used for creating a dummy object while no correct   * object is available for resolution.   */ -using ResolutionImposterCallback = std::function<Rooted<Node>()>; +using ResolutionImposterCallback = 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>, Logger &logger)>; +using ResolutionResultCallback = void (*)(Handle<Node> resolved, +                                          Handle<Node> owner, Logger &logger);  /**   * Base class for the @@ -90,14 +94,14 @@ public:  	 * Tries to resolve a node for the given type and path for all nodes that  	 * are currently in the stack, starting with the topmost node on the stack.  	 * -	 * @param path is the path for which a node should be resolved.  	 * @param type is the type of the node that should be resolved. +	 * @param path is the path for which a node should be resolved.  	 * @param logger is the logger instance into which resolution problems  	 * should be logged.  	 * @return a reference at a resolved node or nullptr if no node could be  	 * found.  	 */ -	Rooted<Node> resolve(const std::vector<std::string> &path, const Rtti &type, +	Rooted<Node> resolve(const Rtti &type, const std::vector<std::string> &path,  	                     Logger &logger);  }; @@ -396,8 +400,9 @@ public:  	 * temporary) and another time if the resolution turned out to be  	 * successful at a later point in time.  	 * -	 * @param path is the path for which a node should be resolved.  	 * @param type 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 logger is the logger instance into which resolution problems  	 * should be logged.  	 * @param imposterCallback is the callback function that is called if @@ -410,15 +415,14 @@ public:  	 * the resolved object directly when this function is called. If the  	 * resolution was not successful the first time, it may be called another  	 * time later in the context of the "performDeferredResolution" function. -	 * @param owner is the node for which the resolution takes place.  	 * @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 resolve(const std::vector<std::string> &path, const Rtti &type, -	             Logger &logger, ResolutionImposterCallback imposterCallback, -	             ResolutionResultCallback resultCallback, -	             Handle<Node> owner = nullptr); +	bool resolve(const Rtti &type, const std::vector<std::string> &path, +	             Handle<Node> owner, Logger &logger, +	             ResolutionImposterCallback imposterCallback, +	             ResolutionResultCallback resultCallback);  	/**  	 * Tries to resolve a node for the given type and path for all nodes @@ -426,21 +430,21 @@ public:  	 * The "resultCallback" is called when the resolution was successful, which  	 * may be at a later point in time.  	 * -	 * @param path is the path for which a node should be resolved.  	 * @param type 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 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. -	 * @param owner is the node for which the resolution takes place.  	 * @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 resolve(const std::vector<std::string> &path, const Rtti &type, -	             Logger &logger, ResolutionResultCallback resultCallback, -	             Handle<Node> owner = nullptr); +	bool resolve(const Rtti &type, const std::vector<std::string> &path, +	             Handle<Node> owner, Logger &logger, +	             ResolutionResultCallback resultCallback);  	/**  	 * Tries to resolve a node for the given type and path for all nodes @@ -453,6 +457,7 @@ public:  	 *  	 * @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 logger is the logger instance into which resolution problems  	 * should be logged.  	 * @param imposterCallback is the callback function that is called if @@ -465,24 +470,17 @@ public:  	 * resolved object directly when this function is called. If the resolution  	 * was not successful the first time, it may be called another time later  	 * in the context of the "performDeferredResolution" function. -	 * @param owner is the node for which the resolution takes place.  	 * @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.  	 */  	template <class T> -	bool resolve(const std::vector<std::string> &path, Logger &logger, -	             std::function<Rooted<T>()> imposterCallback, -	             std::function<void(Handle<T>, Logger &)> resultCallback, -	             Handle<Node> owner = nullptr) +	bool resolve(const std::vector<std::string> &path, Handle<Node> owner, +	             Logger &logger, ResolutionImposterCallback imposterCallback, +	             ResolutionResultCallback resultCallback)  	{ -		return resolve( -		    path, typeOf<T>(), logger, -		    [imposterCallback]() -> Rooted<Node> { return imposterCallback(); }, -		    [resultCallback](Handle<Node> node, Logger &logger) { -			    resultCallback(node.cast<T>(), logger); -			}, -		    owner); +		return resolve(typeOf<T>(), path, owner, logger, imposterCallback, +		               resultCallback);  	}  	/** @@ -493,26 +491,21 @@ public:  	 *  	 * @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 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. -	 * @param owner is the node for which the resolution takes place.  	 * @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.  	 */  	template <class T> -	bool resolve(const std::vector<std::string> &path, Logger &logger, -	             std::function<void(Handle<T>, Logger &)> resultCallback, -	             Handle<Node> owner = nullptr) +	bool resolve(const std::vector<std::string> &path, Handle<Node> owner, +	             Logger &logger, ResolutionResultCallback resultCallback)  	{ -		return resolve(path, typeOf<T>(), logger, -		               [resultCallback](Handle<Node> node, Logger &logger) { -			               resultCallback(node.cast<T>(), logger); -			           }, -		               owner); +		return resolve(typeOf<T>(), path, owner, logger, resultCallback);  	}  	/** @@ -527,6 +520,7 @@ public:  	 * @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.  	 * @param logger is the logger instance into which resolution problems  	 * should be logged.  	 * @param imposterCallback is the callback function that is called if @@ -539,19 +533,17 @@ public:  	 * resolved object directly when this function is called. If the resolution  	 * was not successful the first time, it may be called another time later  	 * in the context of the "performDeferredResolution" function. -	 * @param owner is the node for which the resolution takes place.  	 * @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.  	 */  	template <class T> -	bool resolve(const std::string &name, Logger &logger, -	             std::function<Rooted<T>()> imposterCallback, -	             std::function<void(Handle<T>, Logger &)> resultCallback, -	             Handle<Node> owner = nullptr) +	bool resolve(const std::string &name, Handle<Node> owner, Logger &logger, +	             ResolutionImposterCallback imposterCallback, +	             ResolutionResultCallback resultCallback)  	{ -		return resolve<T>(Utils::split(name, '.'), logger, imposterCallback, -		                  resultCallback, owner); +		return resolve<T>(Utils::split(name, '.'), owner, logger, +		                  imposterCallback, resultCallback);  	}  	/** @@ -574,12 +566,11 @@ public:  	 * later.  	 */  	template <class T> -	bool resolve(const std::string &name, Logger &logger, -	             std::function<void(Handle<T>, Logger &)> resultCallback, -	             Handle<Node> owner = nullptr) +	bool resolve(const std::string &name, Handle<Node> owner, Logger &logger, +	             ResolutionResultCallback resultCallback)  	{ -		return resolve<T>(Utils::split(name, '.'), logger, resultCallback, -		                  owner); +		return resolve<T>(Utils::split(name, '.'), owner, logger, +		                  resultCallback);  	}  	/**  | 
