9 #include <hilti/ast/node.h> 10 #include <hilti/base/logger.h> 11 #include <hilti/base/util.h> 20 using Path = std::vector<std::reference_wrapper<N>>;
26 logger().internalError(
"empty path in visitor");
28 return (*(path.end() - 1)).get();
39 if ( path.size() < 1 + parent_nr )
40 throw std::out_of_range(
"node does not have requested parent");
42 return (*(path.end() - 1 - parent_nr)).get();
53 if ( path.size() < 1 + parent_nr )
54 throw std::out_of_range(
"node does not have requested parent");
56 return (*(path.end() - 1 - parent_nr)).get();
63 template<
typename T, IF_NOT_SAME(T, Node)>
65 for (
auto i = path.rbegin() + 1; i != path.rend(); i++ ) {
66 if (
auto t = (*i).get().tryAs<T>() )
77 template<
typename T, IF_NOT_SAME(T, Node)>
79 for (
auto i = path.rbegin() + 1; i != path.rend(); i++ ) {
80 if (
auto t = (*i).get().tryAs<T>() )
Definition: operator.h:22
N & current(const Path< N > &path)
Definition: visitor-util.h:24
std::vector< std::reference_wrapper< N > > Path
Definition: visitor-util.h:20
const Node & parent(const Path< const Node > &path, int parent_nr=1)
Definition: visitor-util.h:38
std::optional< const T > findParent(const Path< Node > &path)
Definition: visitor-util.h:64