9 #include <hilti/ast/node.h> 10 #include <hilti/base/logger.h> 11 #include <hilti/base/util.h> 21 using Path = std::vector<std::reference_wrapper<N>>;
27 logger().internalError(
"empty path in visitor");
29 return (*(path.end() - 1)).get();
40 if ( path.size() < 1 + parent_nr )
41 throw std::out_of_range(
"node does not have requested parent");
43 return (*(path.end() - 1 - parent_nr)).get();
54 if ( path.size() < 1 + parent_nr )
55 throw std::out_of_range(
"node does not have requested parent");
57 return (*(path.end() - 1 - parent_nr)).get();
64 template<
typename T, IF_NOT_SAME(T, Node)>
66 for (
auto i = path.rbegin() + 1; i != path.rend(); i++ ) {
67 if (
auto t = (*i).get().tryAs<T>() )
78 template<
typename T, IF_NOT_SAME(T, Node)>
80 for (
auto i = path.rbegin() + 1; i != path.rend(); i++ ) {
81 if (
auto t = (*i).get().tryAs<T>() )
N & current(const Path< N > &path)
Definition: visitor-util.h:25
std::vector< std::reference_wrapper< N > > Path
Definition: visitor-util.h:21
const Node & parent(const Path< const Node > &path, int parent_nr=1)
Definition: visitor-util.h:39
std::optional< const T > findParent(const Path< Node > &path)
Definition: visitor-util.h:65