From 66a27d2fc7c1ad4e97de76d4982168a0fed9920a Mon Sep 17 00:00:00 2001 From: Patrick Schönberger Date: Thu, 12 Aug 2021 10:32:51 +0200 Subject: comments --- src/repr_get.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/repr_get.h') diff --git a/src/repr_get.h b/src/repr_get.h index a1f496a..373b366 100644 --- a/src/repr_get.h +++ b/src/repr_get.h @@ -2,6 +2,8 @@ #include "repr.h" +// Transform ANTLR-generated types to corresponding IR types recursively + Type getType(TocParser::TypeContext * ctx); Variable getVariable(TocParser::VarContext * ctx); Body getBody(TocParser::BodyContext * ctx, std::shared_ptr parent); @@ -26,6 +28,11 @@ Expr getExpr(TocParser::ExprContext * ctx); Stmt getStmt(TocParser::StmtContext * ctx, std::shared_ptr parent); +// all of these functions get the relevant information +// from the parse tree and call each other for sub expressions +// the getVariable is called for variable declarations and parameter definitions +// for example, because they have the same rule in the grammar file + Type getType(TocParser::TypeContext * ctx) { Type result; @@ -216,7 +223,11 @@ OpType getOperatorType(const std::string & s, std::string typeStrings[]) - +// Expressions are somewhat of an exception, because some of their +// grammar rules are recursive, so they have to be defined +// in a single rule using Labels (https://github.com/antlr/antlr4/blob/master/doc/parser-rules.md#alternative-labels) +// Because this results in a polymorphic type, getExpr for the base expression type +// is always called and from there the polymorphic type is determined at runtime Expr getExpr(TocParser::FuncExprContext * ctx) { Expr result; @@ -361,7 +372,9 @@ Expr getExpr(TocParser::IdentifierExprContext * ctx) - +// this is always called for Expression rules +// attempt dynamic_cast at runtime and call corresponding +// function Expr getExpr(TocParser::ExprContext * ctx) { Expr result; -- cgit v1.2.3