10 #include <hilti/ast/declarations/type.h> 11 #include <hilti/ast/id.h> 12 #include <hilti/ast/module.h> 13 #include <hilti/ast/node-ref.h> 14 #include <hilti/ast/type.h> 15 #include <hilti/base/visitor-types.h> 21 std::pair<bool, Result<std::pair<NodeRef, ID>>> lookupID(
const ID&
id,
const Node& n);
36 Result<std::pair<NodeRef, ID>> lookupID(
const ID&
id,
const visitor::Position<Node&>& p,
const std::string_view& what) {
38 logger().internalError(
"lookupID() called with empty ID");
40 for (
auto i = p.path.rbegin(); i != p.path.rend(); ++i ) {
41 auto [stop, resolved] = detail::lookupID(
id, **i);
44 if (
auto d = (*resolved).first->tryAs<D>() ) {
45 if ( ! resolved->second.namespace_() ) {
47 if (
auto m = (*i)->tryAs<Module>() )
48 return std::make_pair(resolved->first, ID(m->id(), resolved->second));
52 return std::move(resolved);
55 return result::Error(util::fmt(
"ID '%s' does not resolve to a %s (but to a %s)",
id, what,
56 (*resolved).first->as<Declaration>().displayName()));
61 return std::move(resolved);
70 bool skip_to_module =
false;
72 if (
auto t = (*i)->tryAs<Type>(); t && t->hasFlag(type::Flag::NoInheritScope) ) {
73 if (
auto x = i; ++x != p.path.rend() && (*x)->tryAs<declaration::Type>() )
77 skip_to_module =
true;
79 else if (
auto t = (*i)->tryAs<declaration::Type>(); t && t->type().hasFlag(type::Flag::NoInheritScope) )
80 skip_to_module =
true;
82 if ( skip_to_module ) {
84 while ( ++i != p.path.rend() ) {
85 if ( (*i)->isA<Module>() )
92 return result::Error(util::fmt(
"unknown ID '%s'",
id));
Definition: scope-lookup.h:17