summaryrefslogtreecommitdiff
path: root/src/core/parser/Scope.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-09 17:09:32 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-01-09 17:09:32 +0100
commitdd185959b9fff68008d02979fefde602d177ce75 (patch)
treeea005aac74a15015c46abfe939de6a248ffa6af7 /src/core/parser/Scope.cpp
parent7d10e59d822f1e405f1f5ac252db11790a1e9b43 (diff)
Implemented resolve function in Scope class
Diffstat (limited to 'src/core/parser/Scope.cpp')
-rw-r--r--src/core/parser/Scope.cpp26
1 files changed, 26 insertions, 0 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;
+}
}
}