From dd185959b9fff68008d02979fefde602d177ce75 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 9 Jan 2015 17:09:32 +0100 Subject: Implemented resolve function in Scope class --- src/core/parser/Scope.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/core/parser/Scope.cpp') 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 . */ +#include + #include "Scope.hpp" namespace ousia { namespace parser { +Rooted Scope::resolve(const std::vector &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 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; +} } } -- cgit v1.2.3