]> gitweb.ps.run Git - toc/blobdiff - src/visit.h
fix function and method return types
[toc] / src / visit.h
index 3fe2cb2b96f833aa16ae47e63b026bcb287b127d..646ac61d270756dd7d9ab0266fd87e3dcebdcfdb 100644 (file)
@@ -4,6 +4,9 @@
 \r
 #include <functional>\r
 \r
+// struct with callback functions for all relevant types\r
+// tree can be walked selectively by providing only\r
+// needed callbacks\r
 struct Visitor {\r
   std::function<void(const Type &, const std::shared_ptr<Context> ctx)> onType = [](auto, auto){};\r
   std::function<void(const Expr &, const std::shared_ptr<Context> ctx)> onExpr = [](auto, auto){};\r
@@ -20,6 +23,7 @@ struct Visitor {
 \r
 #define VISIT(XS) for (auto x : XS) visit(x);\r
 \r
+// simply walk IR by recursively calling functions for all children\r
 struct Visit {\r
 private:\r
   Visitor v;\r
@@ -141,7 +145,7 @@ public:
     \r
     ctx = x.ctx;\r
 \r
-    VISIT(x.namespaces)\r
+    VISIT(x.ctx->namespaces)\r
     VISIT(x.ctx->variables)\r
     VISIT(x.ctx->structs)\r
     VISIT(x.ctx->functions)\r
@@ -188,7 +192,7 @@ public:
 \r
     ctx = x.ctx;\r
 \r
-    VISIT(x.namespaces)\r
+    VISIT(x.ctx->namespaces)\r
     VISIT(x.ctx->variables)\r
     VISIT(x.ctx->structs)\r
     VISIT(x.ctx->functions)\r