diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/parser/Scope.cpp | 26 | ||||
| -rw-r--r-- | src/core/parser/Scope.hpp | 19 | 
2 files changed, 43 insertions, 2 deletions
diff --git a/src/core/parser/Scope.cpp b/src/core/parser/Scope.cpp index a60ade0..f452ce8 100644 --- a/src/core/parser/Scope.cpp +++ b/src/core/parser/Scope.cpp @@ -16,11 +16,37 @@      along with this program.  If not, see <http://www.gnu.org/licenses/>.  */ +#include <core/common/Utils.hpp> +  #include "Scope.hpp"  namespace ousia {  namespace parser { +Rooted<Node> Scope::resolve(const std::vector<std::string> &path, +                            const RttiBase &type, 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); + +		// Abort if the object could not be resolved +		if (res.empty()) { +			continue; +		} +		// Log an error if the object is not unique +		if (res.size() > 1) { +			logger.error(std::string("The reference ") + +			             Utils::join(path, ".") + (" is ambigous!")); +			logger.note("Referenced objects are:"); +			for (const ResolutionResult &r : res) { +				logger.note(std::string("\t") + Utils::join(r.path(), ".")); +			} +		} +		return res[0].node; +	} +	return nullptr; +}  }  } diff --git a/src/core/parser/Scope.hpp b/src/core/parser/Scope.hpp index ac0f1fd..d015371 100644 --- a/src/core/parser/Scope.hpp +++ b/src/core/parser/Scope.hpp @@ -19,8 +19,9 @@  #ifndef _OUSIA_PARSER_SCOPE_H_  #define _OUSIA_PARSER_SCOPE_H_ -#include <deque> +#include <vector> +#include <core/common/Logger.hpp>  #include <core/model/Node.hpp>  /** @@ -96,7 +97,7 @@ public:   */  class Scope {  private: -	std::deque<Rooted<Node>> nodes; +	std::vector<Rooted<Node>> nodes;  public:  	/** @@ -139,6 +140,20 @@ public:  	 * @return a reference at the leaf node.  	 */  	Rooted<Node> getLeaf() { return nodes.back(); } + +	/** +	 * 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 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 RttiBase &type, Logger &logger);  };  /* Class ScopedScope -- inline declaration of some methods */  | 
