X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/17860defa84c6d8bc0e8bc088a7e09361f17db07..9f94b672a5dc32da5ad01742bd4e976315a30d9c:/src/visit.h diff --git a/src/visit.h b/src/visit.h index 3fe2cb2..646ac61 100644 --- a/src/visit.h +++ b/src/visit.h @@ -4,6 +4,9 @@ #include +// struct with callback functions for all relevant types +// tree can be walked selectively by providing only +// needed callbacks struct Visitor { std::function ctx)> onType = [](auto, auto){}; std::function ctx)> onExpr = [](auto, auto){}; @@ -20,6 +23,7 @@ struct Visitor { #define VISIT(XS) for (auto x : XS) visit(x); +// simply walk IR by recursively calling functions for all children struct Visit { private: Visitor v; @@ -141,7 +145,7 @@ public: ctx = x.ctx; - VISIT(x.namespaces) + VISIT(x.ctx->namespaces) VISIT(x.ctx->variables) VISIT(x.ctx->structs) VISIT(x.ctx->functions) @@ -188,7 +192,7 @@ public: ctx = x.ctx; - VISIT(x.namespaces) + VISIT(x.ctx->namespaces) VISIT(x.ctx->variables) VISIT(x.ctx->structs) VISIT(x.ctx->functions)