]> gitweb.ps.run Git - toc/blobdiff - src/repr_get.h
comments
[toc] / src / repr_get.h
index a1f496a0314ae5205b73d55c05af58526729e093..373b366ae3849da99bb4c7a1441986bf65c34efd 100644 (file)
@@ -2,6 +2,8 @@
 \r
 #include "repr.h"\r
 \r
+// Transform ANTLR-generated types to corresponding IR types recursively\r
+\r
 Type                getType(TocParser::TypeContext * ctx);\r
 Variable            getVariable(TocParser::VarContext * ctx);\r
 Body                getBody(TocParser::BodyContext * ctx, std::shared_ptr<Context> parent);\r
@@ -26,6 +28,11 @@ Expr                getExpr(TocParser::ExprContext * ctx);
 \r
 Stmt                getStmt(TocParser::StmtContext * ctx, std::shared_ptr<Context> parent);\r
 \r
+// all of these functions get the relevant information\r
+// from the parse tree and call each other for sub expressions\r
+// the getVariable is called for variable declarations and parameter definitions\r
+// for example, because they have the same rule in the grammar file\r
+\r
 Type getType(TocParser::TypeContext * ctx)\r
 {\r
   Type result;\r
@@ -216,7 +223,11 @@ OpType getOperatorType(const std::string & s, std::string typeStrings[])
 \r
 \r
 \r
-\r
+// Expressions are somewhat of an exception, because some of their\r
+// grammar rules are recursive, so they have to be defined\r
+// in a single rule using Labels (https://github.com/antlr/antlr4/blob/master/doc/parser-rules.md#alternative-labels)\r
+// Because this results in a polymorphic type, getExpr for the base expression type\r
+// is always called and from there the polymorphic type is determined at runtime\r
 Expr getExpr(TocParser::FuncExprContext * ctx)\r
 {\r
   Expr result;\r
@@ -361,7 +372,9 @@ Expr getExpr(TocParser::IdentifierExprContext * ctx)
 \r
 \r
 \r
-\r
+// this is always called for Expression rules\r
+// attempt dynamic_cast at runtime and call corresponding\r
+// function\r
 Expr getExpr(TocParser::ExprContext * ctx)\r
 {\r
   Expr result;\r