From bb473e248c1f4236a790d6fcc44461d60ecc7db4 Mon Sep 17 00:00:00 2001 From: lyc Date: Tue, 17 Dec 2024 21:32:23 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 +- doc/三地址生成说明.md | 103 ++++ doc/汇编生成说明.md | 50 ++ include/ICG/{myGoListener.h => GoTo3code.h} | 2 +- main.cpp | 9 +- src/ICG/{myGoListener.cpp => GoTo3code.cpp} | 502 ++++++++++---------- 6 files changed, 435 insertions(+), 256 deletions(-) create mode 100644 doc/三地址生成说明.md create mode 100644 doc/汇编生成说明.md rename include/ICG/{myGoListener.h => GoTo3code.h} (99%) rename src/ICG/{myGoListener.cpp => GoTo3code.cpp} (62%) diff --git a/README.md b/README.md index 8997990..028f79a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 环境 -- x86 Debian GNU/Linux 12 +- `x86` Debian GNU/Linux 12 - Python 3.11.2 - gcc version 12.2.2 - openJDK version "17.0.12" @@ -55,4 +55,25 @@ bash test_all.sh ``` # 代码架构 -![code](./assest/code.jpg) \ No newline at end of file +![code](./assest/code.jpg) + +# 原理概述 +1. ANTLR的工作流程大致如下: + + - 定义语法规则:使用ANTLR的语法描述语言来定义语言的语法规则。 + + - 生成解析器和词法分析器:ANTLR根据这些语法规则自动生成源代码,这些源代码可以构建出解析器和词法分析器。 + + - 词法分析:词法分析器(lexer)将输入的源代码文本分解成一系列的标记(tokens),这些标记是语法分析的基本单位。 + + - 语法分析:解析器(parser)使用这些标记和定义的语法规则来构建解析树,这个树结构表示了源代码的语法结构。 + + - 树的遍历:ANTLR还支持遍历解析树,这可以通过定义访问者(visitors)和监听器(listeners)来实现,它们可以在遍历过程中执行特定的操作,如语义分析、代码转换等。(在这里实现三地址代码生成) + +2. 三地址转汇编 + + - 指令选择(Instruction Selection):根据三地址代码的指令和操作数,选择相应的汇编指令。例如,如果三地址代码是ADD R1, R2, R3,那么对应的汇编指令可能是add R1, R2, R3。 + + - 寄存器分配(Register Allocation):将三地址代码中的虚拟寄存器映射到实际的物理寄存器或内存位置。这通常涉及到寄存器分配算法,如贪心算法、图着色算法等。 + + - 指令调度(Instruction Scheduling):调整指令的顺序以提高执行效率,这可能包括延迟分支、指令重排等。 diff --git a/doc/三地址生成说明.md b/doc/三地址生成说明.md new file mode 100644 index 0000000..9b9de28 --- /dev/null +++ b/doc/三地址生成说明.md @@ -0,0 +1,103 @@ +通过例子来说明如何通过语法树实现三地址代码的生成。 +假设有一个非常简单的算术表达式语言,它支持加法和变量赋值。 +目标是将这个表达式转换为三地址代码。 + +### 步骤 1: 定义语法规则 + +首先需要定义这个简单语言的语法规则 + +```antlr +grammar SimpleLang; + +stat: assign + | expr + ; + +assign: ID '=' expr ';' { /* 生成赋值的三地址代码 */ } + ; + +expr: expr '+' expr + | num + ; + +num: INT { /* 生成数字的三地址代码 */ } + ; + +ID : [_a-zA-Z] [_a-zA-Z0-9]* + ; + +INT : [0-9]+ + ; +``` + +### 步骤 2: 生成解析器代码 + +使用ANTLR工具根据上述语法规则文件生成对应的词法分析器和语法分析器代码。 + +### 步骤 3: 遍历解析树 + +接下来遍历解析树来生成三地址代码。创建一个监听器或访问者来实现这一过程。 +以下是一个访问者实现,遍历解析树并生成三地址代码: + +```cpp +class SimpleLangVisitor : public SimpleLangBaseVisitor { +public: + // 访问数字节点时调用 + ThreeAddressCode* visitNum(SimpleLangParser::NumContext* ctx) { + string value = ctx->INT()->getText(); + return new ThreeAddressCode("MOV", "R0", value); // 假设R0是临时寄存器 + } + + // 访问加法表达式节点时调用 + ThreeAddressCode* visitExpr(SimpleLangParser::ExprContext* ctx) { + // 假设左右子树已经生成了三地址代码 + ThreeAddressCode* left = visit(ctx->expr(0)); + ThreeAddressCode* right = visit(ctx->expr(1)); + // 生成加法的三地址代码 + return new ThreeAddressCode("ADD", left->dest, right->dest); + } + + // 访问赋值节点时调用 + ThreeAddressCode* visitAssign(SimpleLangParser::AssignContext* ctx) { + string varName = ctx->ID()->getText(); + ThreeAddressCode* exprCode = visit(ctx->expr()); + // 生成赋值的三地址代码 + return new ThreeAddressCode("MOV", varName, exprCode->dest); + } +}; +``` + +### 步骤 4: 生成三地址代码 + +在上述访问者中,我们定义了如何生成数字、加法表达式和赋值语句的三地址代码。例如,对于数字,我们生成一个将数字移动到临时寄存器的指令。对于加法,我们生成一个将两个操作数相加的指令。对于赋值,我们生成一个将表达式的结果移动到变量的指令。 + +### 示例 + +假设我们有如下的源代码: + +``` +x = 3 + 4; +``` + +解析树将如下所示: + +``` + assign + / \ + ID expr + / \ + '=' + + / \ + num num + | | + 3 4 +``` + +遍历这个解析树,我们将生成以下三地址代码: + +1. `MOV R0, 3` (将数字3移动到临时寄存器R0) +2. `MOV R1, 4` (将数字4移动到另一个临时寄存器R1) +3. `ADD R0, R0, R1` (将R0和R1相加,结果存回R0) +4. `MOV x, R0` (将R0的值移动到变量x) + +这样,我们就通过语法树实现了从源代码到三地址代码的转换。这个过程可以根据具体的语言和需求进行扩展和修改。 diff --git a/doc/汇编生成说明.md b/doc/汇编生成说明.md new file mode 100644 index 0000000..e9b8879 --- /dev/null +++ b/doc/汇编生成说明.md @@ -0,0 +1,50 @@ +结合之前的`main`代码: + +### 步骤 1: 定义三地址代码结构 + +在`TCG/Translator.h`中,你可能已经定义了一个`TACFile`类来存储三地址代码块,其中每个块包含一系列的三地址代码指令。 + +### 步骤 2: 实现翻译器 + +在`TCG/Translator.h`和`TCG/Translator.cpp`中,你实现了一个`Translator`类,它负责将三地址代码翻译为汇编代码。这个类可能包含如下方法: + +- `Translate()`:遍历`TACFile`中的所有三地址代码指令,并为每个指令生成对应的汇编代码。 +- `OutputFile()`:将生成的汇编代码输出到文件。 + +### 步骤 3: 遍历三地址代码 + +在`main`函数中,你已经创建了一个`TACFile`对象,并将其传递给`Translator`对象。`Translator`对象的`Translate()`方法将遍历所有的三地址代码指令,并生成汇编代码。 + +### 步骤 4: 生成汇编代码 + +在`Translator`类的`Translate()`方法中,你需要为每种三地址代码指令编写一个翻译规则,将它们转换为对应的汇编指令。例如: + +- 对于`MOV`指令,生成一个将值移动到寄存器的汇编指令。 +- 对于`ADD`指令,生成一个加法汇编指令。 +- 对于`SUB`指令,生成一个减法汇编指令。 + +### 步骤 5: 输出汇编代码 + +在`Translator`类的`OutputFile()`方法中,你需要将生成的汇编代码写入到文件中。这通常涉及到打开文件、格式化汇编代码和写入文件。 + +### 示例 + +假设你有以下三地址代码: + +``` +MOV R1, 5 +MOV R2, 3 +ADD R3, R1, R2 +``` + +对应的汇编代码可能是: + +``` +mov R1, #5 +mov R2, #3 +add R3, R1, R2 +``` + +在你的`Translator`类中,你需要为`MOV`、`ADD`等操作编写翻译规则,并将它们输出为上述汇编代码。 + +总结来说,将三地址代码翻译为汇编代码是一个涉及指令选择、寄存器分配和代码生成的过程。你需要在编译器后端实现这些步骤,并将它们集成到你的`main`函数中,以便将三地址代码转换为汇编代码。 diff --git a/include/ICG/myGoListener.h b/include/ICG/GoTo3code.h similarity index 99% rename from include/ICG/myGoListener.h rename to include/ICG/GoTo3code.h index e24418f..6ceba8d 100644 --- a/include/ICG/myGoListener.h +++ b/include/ICG/GoTo3code.h @@ -13,7 +13,7 @@ namespace std { -class myGoListener : public GoParserListener +class GoTo3code : public GoParserListener { public: diff --git a/main.cpp b/main.cpp index 5ed33b1..4c90618 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,6 @@ #include #include "Public/Public.h" -#include "ICG/myGoListener.h" +#include "ICG/GoTo3code.h" #include "GoParser.h" #include "GoLexer.h" #include "GoParserListener.h" @@ -110,18 +110,23 @@ int main(int argc, char* argv[]) { LOG(INFO) << "Starting lexical analysis."; GoLexer lexer(&inputStream); antlr4::CommonTokenStream tokens(&lexer); + LOG(INFO) << "Starting syntax analysis."; GoParser parser(&tokens); - myGoListener listener; + + // 遍历AST,自定义生成三地址代码 + GoTo3code listener; antlr4::tree::ParseTreeWalker::DEFAULT.walk(&listener, parser.sourceFile()); std::string path_3code = cmd_param.output + "/" + cmd_param.output_3code; listener.Go23file_(path_3code); + // 三地址转汇编 LOG(INFO) << "Translating three-address code to assembly."; auto tac_file = make_shared(std::move(listener.TACBlocks)); Translator translator(tac_file, listener.globalScope); translator.Translate(); + std::string path_asm = cmd_param.output + "/" + cmd_param.output_asm; translator.OutputFile(path_asm); diff --git a/src/ICG/myGoListener.cpp b/src/ICG/GoTo3code.cpp similarity index 62% rename from src/ICG/myGoListener.cpp rename to src/ICG/GoTo3code.cpp index 9c29114..b66ad62 100644 --- a/src/ICG/myGoListener.cpp +++ b/src/ICG/GoTo3code.cpp @@ -5,19 +5,19 @@ #include "GoLexer.h" #include "GoParserListener.h" #include "GoParserBaseListener.h" -#include "ICG/myGoListener.h" +#include "ICG/GoTo3code.h" #include "ICG/Utils.h" #include "ICG/StmtICG/ForStmt.h" using namespace std; -string myGoListener::CreateLocalVar(){ +string GoTo3code::CreateLocalVar(){ string Local; bool CheckResult = 0; do { - Local = "T" + to_string(myGoListener::LocalIndex); - myGoListener::LocalIndex++; + Local = "T" + to_string(GoTo3code::LocalIndex); + GoTo3code::LocalIndex++; shared_ptr tmp; if(currentScope->resolve(Local,tmp)==SUCCESS){ CheckResult=1; // 临时变量与已经定义的变量重名 @@ -29,27 +29,27 @@ string myGoListener::CreateLocalVar(){ while(CheckResult); /* TODO: 判断tmp类型 */ std::shared_ptr symbol= make_shared(Local,currentScope,Symbol::SymbolType::VAR,defineTmpType()); - myGoListener::currentScope->para_define(symbol); + GoTo3code::currentScope->para_define(symbol); return Local; } -string myGoListener::CreateElseLabel(){ +string GoTo3code::CreateElseLabel(){ string Local; bool CheckResult = 0; - Local = to_string(myGoListener::IFIndex); - myGoListener::IFIndex++; + Local = to_string(GoTo3code::IFIndex); + GoTo3code::IFIndex++; return Local; } -string myGoListener::CreateForLabel(){ +string GoTo3code::CreateForLabel(){ string Local; bool CheckResult = 0; - Local = to_string(myGoListener::ForIndex); - myGoListener::ForIndex++; + Local = to_string(GoTo3code::ForIndex); + GoTo3code::ForIndex++; return Local; } -string myGoListener::ToString(TACOP num){ +string GoTo3code::ToString(TACOP num){ switch (num) { case TACOP::ADD: return "ADD"; @@ -76,7 +76,7 @@ string myGoListener::ToString(TACOP num){ } } -string myGoListener::ToString(TACOPERANDTYPE num){ +string GoTo3code::ToString(TACOPERANDTYPE num){ switch (num) { case TACOPERANDTYPE::VAR: return "VAR"; @@ -88,7 +88,7 @@ string myGoListener::ToString(TACOPERANDTYPE num){ } } -TACOPERANDTYPE myGoListener::OperandTypereslove(string name){ +TACOPERANDTYPE GoTo3code::OperandTypereslove(string name){ if(ptrs[name]==1){ return TACOPERANDTYPE::PTR; } @@ -99,7 +99,7 @@ TACOPERANDTYPE myGoListener::OperandTypereslove(string name){ return TACOPERANDTYPE::VAR; } -bool myGoListener::is_digit(string s){ +bool GoTo3code::is_digit(string s){ if(s[0]=='-') s=s.substr(1,s.size()-1); for(auto c:s){ if((c>= '0' && c<= '9')) continue; @@ -108,7 +108,7 @@ bool myGoListener::is_digit(string s){ return true; } -void myGoListener::Go23file(string filename){ +void GoTo3code::Go23file(string filename){ ofstream outfile; outfile.open(filename, ios::out); outfile.clear(); @@ -126,7 +126,7 @@ void myGoListener::Go23file(string filename){ outfile.close(); } -void myGoListener::Go23file_(string filename){ +void GoTo3code::Go23file_(string filename){ ofstream outfile; outfile.open(filename, ios::out); outfile.clear(); @@ -145,12 +145,12 @@ void myGoListener::Go23file_(string filename){ } // 第一个参数,改成函数名字 -void myGoListener::push_line(TACOP op, Operand src1, Operand src2, Operand dst){ - TACBlocks[curFun]->push_back(TACLine(myGoListener::LineIndex, op, src1, src2, dst, currentScope)); - myGoListener::LineIndex ++; +void GoTo3code::push_line(TACOP op, Operand src1, Operand src2, Operand dst){ + TACBlocks[curFun]->push_back(TACLine(GoTo3code::LineIndex, op, src1, src2, dst, currentScope)); + GoTo3code::LineIndex ++; } -void myGoListener::myPrint(std::shared_ptr currentScope){ +void GoTo3code::myPrint(std::shared_ptr currentScope){ for(auto it:currentScope->para_symbols) { LOG(INFO) << "para_symbol: " << it.first; } @@ -159,33 +159,33 @@ void myGoListener::myPrint(std::shared_ptr currentScope){ } } -void myGoListener::addScope(){ +void GoTo3code::addScope(){ std::shared_ptr scope(new Scope(currentScope)); // scopes.put(ctx,scope); allScopes.push_back(scope); currentScope=scope; } -void myGoListener::popScope(){ +void GoTo3code::popScope(){ myPrint(currentScope); currentScope=currentScope->enclosing_scope; } -void myGoListener::exitPackageClause(GoParser::PackageClauseContext *ctx) +void GoTo3code::exitPackageClause(GoParser::PackageClauseContext *ctx) { } -void myGoListener::enterPackageClause(GoParser::PackageClauseContext *ctx){} +void GoTo3code::enterPackageClause(GoParser::PackageClauseContext *ctx){} -void myGoListener::enterInteger(GoParser::IntegerContext *ctx){} -void myGoListener::exitInteger(GoParser::IntegerContext *ctx){ +void GoTo3code::enterInteger(GoParser::IntegerContext *ctx){} +void GoTo3code::exitInteger(GoParser::IntegerContext *ctx){ values->put(ctx,ctx->DECIMAL_LIT()->getText()); } -void myGoListener::enterBasicLit(GoParser::BasicLitContext *ctx){} -void myGoListener::exitBasicLit(GoParser::BasicLitContext *ctx){ +void GoTo3code::enterBasicLit(GoParser::BasicLitContext *ctx){} +void GoTo3code::exitBasicLit(GoParser::BasicLitContext *ctx){ if (ctx->integer()){ // string dst = CreateLocalVar(); string BasicLitValue = values->get(ctx->integer()); @@ -196,8 +196,8 @@ void myGoListener::exitBasicLit(GoParser::BasicLitContext *ctx){ } -void myGoListener::enterOperand(GoParser::OperandContext *ctx){} -void myGoListener::exitOperand(GoParser::OperandContext *ctx){ +void GoTo3code::enterOperand(GoParser::OperandContext *ctx){} +void GoTo3code::exitOperand(GoParser::OperandContext *ctx){ if (ctx->literal()){ string OperandValue = values->get(ctx->literal()); values->put(ctx, OperandValue); @@ -212,10 +212,10 @@ void myGoListener::exitOperand(GoParser::OperandContext *ctx){ } } -void myGoListener::enterLiteral(GoParser::LiteralContext *ctx){ +void GoTo3code::enterLiteral(GoParser::LiteralContext *ctx){ } -void myGoListener::exitLiteral(GoParser::LiteralContext *ctx){ +void GoTo3code::exitLiteral(GoParser::LiteralContext *ctx){ if (ctx->basicLit()){ string LiteralValue = values->get(ctx->basicLit()); @@ -223,8 +223,8 @@ void myGoListener::exitLiteral(GoParser::LiteralContext *ctx){ } } -void myGoListener::enterPrimaryExpr(GoParser::PrimaryExprContext *ctx){} -void myGoListener::exitPrimaryExpr(GoParser::PrimaryExprContext *ctx){ +void GoTo3code::enterPrimaryExpr(GoParser::PrimaryExprContext *ctx){} +void GoTo3code::exitPrimaryExpr(GoParser::PrimaryExprContext *ctx){ /* 是函数调用 */ if(ctx->arguments()){ @@ -331,23 +331,23 @@ void myGoListener::exitPrimaryExpr(GoParser::PrimaryExprContext *ctx){ } -void myGoListener::enterExpression(GoParser::ExpressionContext *ctx){} -void myGoListener::exitExpression(GoParser::ExpressionContext *ctx){ +void GoTo3code::enterExpression(GoParser::ExpressionContext *ctx){} +void GoTo3code::exitExpression(GoParser::ExpressionContext *ctx){ } -void myGoListener::enterUnaryOperation(GoParser::UnaryOperationContext *ctx){} -void myGoListener::exitUnaryOperation(GoParser::UnaryOperationContext *ctx){ +void GoTo3code::enterUnaryOperation(GoParser::UnaryOperationContext *ctx){} +void GoTo3code::exitUnaryOperation(GoParser::UnaryOperationContext *ctx){ } -void myGoListener::enterPrimaryExpression(GoParser::PrimaryExpressionContext *ctx){} -void myGoListener::exitPrimaryExpression(GoParser::PrimaryExpressionContext *ctx){ +void GoTo3code::enterPrimaryExpression(GoParser::PrimaryExpressionContext *ctx){} +void GoTo3code::exitPrimaryExpression(GoParser::PrimaryExpressionContext *ctx){ string ExpresionValue = values->get(ctx->primaryExpr()); values->put(ctx, ExpresionValue); } -void myGoListener::enterPlusMinusOperation(GoParser::PlusMinusOperationContext *ctx){} -void myGoListener::exitPlusMinusOperation(GoParser::PlusMinusOperationContext *ctx){ +void GoTo3code::enterPlusMinusOperation(GoParser::PlusMinusOperationContext *ctx){} +void GoTo3code::exitPlusMinusOperation(GoParser::PlusMinusOperationContext *ctx){ std::shared_ptr> left=ctx_decoder(values->get(ctx->expression(0))); std::shared_ptr> right=ctx_decoder(values->get(ctx->expression(1))); /*判断value是否只有一个*/ @@ -371,8 +371,8 @@ void myGoListener::exitPlusMinusOperation(GoParser::PlusMinusOperationContext *c values->put(ctx, ctx_encoder(plusMinusOperation_values)); } -void myGoListener::enterRelationOperation(GoParser::RelationOperationContext *ctx){} -void myGoListener::exitRelationOperation(GoParser::RelationOperationContext *ctx){ +void GoTo3code::enterRelationOperation(GoParser::RelationOperationContext *ctx){} +void GoTo3code::exitRelationOperation(GoParser::RelationOperationContext *ctx){ std::shared_ptr> left=ctx_decoder(values->get(ctx->expression(0))); std::shared_ptr> right=ctx_decoder(values->get(ctx->expression(1))); if(left->size()!=1 || right->size()!=1){ @@ -393,37 +393,37 @@ void myGoListener::exitRelationOperation(GoParser::RelationOperationContext *ctx TACLine tmpline; if(ctx->EQUALS()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFNEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } else if(ctx->NOT_EQUALS()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFNEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFNEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFEQ, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } else if(ctx->GREATER()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFGT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFGT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFLE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } else if(ctx->GREATER_OR_EQUALS()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFGE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFGE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFLT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } else if(ctx->LESS()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFLT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFLT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFGE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } else if(ctx->LESS_OR_EQUALS()) { - tmpline = TACLine(myGoListener::LineIndex, TACOP::IFLE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); + tmpline = TACLine(GoTo3code::LineIndex, TACOP::IFLE, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst_, TACOPERANDTYPE::LABEL), currentScope); push_line (TACOP::IFGT, Operand((*left)[0], OperandTypereslove((*left)[0])), Operand((*right)[0], OperandTypereslove((*right)[0])), Operand(dst, TACOPERANDTYPE::LABEL)); } @@ -477,8 +477,8 @@ void myGoListener::exitRelationOperation(GoParser::RelationOperationContext *ctx } -void myGoListener::enterMulDivOperation(GoParser::MulDivOperationContext *ctx){} -void myGoListener::exitMulDivOperation(GoParser::MulDivOperationContext *ctx){ +void GoTo3code::enterMulDivOperation(GoParser::MulDivOperationContext *ctx){} +void GoTo3code::exitMulDivOperation(GoParser::MulDivOperationContext *ctx){ std::shared_ptr> left=ctx_decoder(values->get(ctx->expression(0))); std::shared_ptr> right=ctx_decoder(values->get(ctx->expression(1))); /*判断value是否只有一个*/ @@ -504,52 +504,52 @@ void myGoListener::exitMulDivOperation(GoParser::MulDivOperationContext *ctx){ } -void myGoListener::enterLogicalOrOperation(GoParser::LogicalOrOperationContext *ctx){} -void myGoListener::exitLogicalOrOperation(GoParser::LogicalOrOperationContext *ctx){ +void GoTo3code::enterLogicalOrOperation(GoParser::LogicalOrOperationContext *ctx){} +void GoTo3code::exitLogicalOrOperation(GoParser::LogicalOrOperationContext *ctx){ } -void myGoListener::enterLogicalAndOperation(GoParser::LogicalAndOperationContext *ctx){} -void myGoListener::exitLogicalAndOperation(GoParser::LogicalAndOperationContext *ctx){ +void GoTo3code::enterLogicalAndOperation(GoParser::LogicalAndOperationContext *ctx){} +void GoTo3code::exitLogicalAndOperation(GoParser::LogicalAndOperationContext *ctx){ } -void myGoListener::enterSourceFile(GoParser::SourceFileContext *ctx){ +void GoTo3code::enterSourceFile(GoParser::SourceFileContext *ctx){ globalScope=make_shared(); currentScope = globalScope; std::shared_ptr currentBlock=make_shared(); TACBlocks[curFun]=currentBlock; } -void myGoListener::exitSourceFile(GoParser::SourceFileContext *ctx){ +void GoTo3code::exitSourceFile(GoParser::SourceFileContext *ctx){ cout<<"exit source file"< expression_values; for(int i=0;iexpression().size();++i){ string s=values->get(ctx->expression(i)); @@ -561,13 +561,13 @@ void myGoListener::exitExpressionList(GoParser::ExpressionListContext *ctx){ values->put(ctx,ctx_encoder(expression_values)); } -void myGoListener::enterTypeDecl(GoParser::TypeDeclContext *ctx){} -void myGoListener::exitTypeDecl(GoParser::TypeDeclContext *ctx){} +void GoTo3code::enterTypeDecl(GoParser::TypeDeclContext *ctx){} +void GoTo3code::exitTypeDecl(GoParser::TypeDeclContext *ctx){} -void myGoListener::enterTypeSpec(GoParser::TypeSpecContext *ctx){} -void myGoListener::exitTypeSpec(GoParser::TypeSpecContext *ctx){} +void GoTo3code::enterTypeSpec(GoParser::TypeSpecContext *ctx){} +void GoTo3code::exitTypeSpec(GoParser::TypeSpecContext *ctx){} -void myGoListener::enterFunctionDecl(GoParser::FunctionDeclContext *ctx){ +void GoTo3code::enterFunctionDecl(GoParser::FunctionDeclContext *ctx){ string identifier=ctx->IDENTIFIER()->getText(); /*判断是否函数名字重复*/ @@ -616,7 +616,7 @@ void myGoListener::enterFunctionDecl(GoParser::FunctionDeclContext *ctx){ std::shared_ptr symbol= make_shared(identifier,currentScope,Symbol::SymbolType::FUN,funRetTypeList, funParaList); std::shared_ptr scope=make_shared(currentScope); - myGoListener::currentScope->fun_define(symbol); + GoTo3code::currentScope->fun_define(symbol); currentScope=scope; /*打印 FUN_PARA*/ @@ -630,24 +630,24 @@ void myGoListener::enterFunctionDecl(GoParser::FunctionDeclContext *ctx){ } } -void myGoListener::exitFunctionDecl(GoParser::FunctionDeclContext *ctx){ +void GoTo3code::exitFunctionDecl(GoParser::FunctionDeclContext *ctx){ curFun="global"; popScope(); } -void myGoListener::enterMethodDecl(GoParser::MethodDeclContext *ctx){} -void myGoListener::exitMethodDecl(GoParser::MethodDeclContext *ctx){} +void GoTo3code::enterMethodDecl(GoParser::MethodDeclContext *ctx){} +void GoTo3code::exitMethodDecl(GoParser::MethodDeclContext *ctx){} -void myGoListener::enterReceiver(GoParser::ReceiverContext *ctx){} -void myGoListener::exitReceiver(GoParser::ReceiverContext *ctx){} +void GoTo3code::enterReceiver(GoParser::ReceiverContext *ctx){} +void GoTo3code::exitReceiver(GoParser::ReceiverContext *ctx){} -void myGoListener::enterVarDecl(GoParser::VarDeclContext *ctx){} -void myGoListener::exitVarDecl(GoParser::VarDeclContext *ctx){} +void GoTo3code::enterVarDecl(GoParser::VarDeclContext *ctx){} +void GoTo3code::exitVarDecl(GoParser::VarDeclContext *ctx){} -void myGoListener::enterVarSpec(GoParser::VarSpecContext *ctx){ +void GoTo3code::enterVarSpec(GoParser::VarSpecContext *ctx){ } -void myGoListener::exitVarSpec(GoParser::VarSpecContext *ctx){ +void GoTo3code::exitVarSpec(GoParser::VarSpecContext *ctx){ /*是否是数组*/ bool is_array=0; int array_length=0; @@ -713,7 +713,7 @@ void myGoListener::exitVarSpec(GoParser::VarSpecContext *ctx){ if(is_array){ push_line (TACOP::CREATLIST, Operand(varname, OperandTypereslove(varname)), Operand(std::to_string(array_length), OperandTypereslove(std::to_string(array_length))), Operand("INT", TACOPERANDTYPE::NULL_)); } - myGoListener::currentScope->para_define(symbol); + GoTo3code::currentScope->para_define(symbol); } /*定义时赋值*/ @@ -737,7 +737,7 @@ void myGoListener::exitVarSpec(GoParser::VarSpecContext *ctx){ } -void myGoListener::enterBlock(GoParser::BlockContext *ctx){ +void GoTo3code::enterBlock(GoParser::BlockContext *ctx){ //for 情况 if(ctx->parent->children[0]->getText() == "for") { @@ -750,7 +750,7 @@ void myGoListener::enterBlock(GoParser::BlockContext *ctx){ addScope(); } -void myGoListener::exitBlock(GoParser::BlockContext *ctx){ +void GoTo3code::exitBlock(GoParser::BlockContext *ctx){ //for 情况 if(ctx->parent->children[0]->getText() == "for") { @@ -771,25 +771,25 @@ void myGoListener::exitBlock(GoParser::BlockContext *ctx){ } -void myGoListener::enterStatementList(GoParser::StatementListContext *ctx){} -void myGoListener::exitStatementList(GoParser::StatementListContext *ctx){} +void GoTo3code::enterStatementList(GoParser::StatementListContext *ctx){} +void GoTo3code::exitStatementList(GoParser::StatementListContext *ctx){} -void myGoListener::enterStatement(GoParser::StatementContext *ctx){ +void GoTo3code::enterStatement(GoParser::StatementContext *ctx){ } -void myGoListener::exitStatement(GoParser::StatementContext *ctx){} +void GoTo3code::exitStatement(GoParser::StatementContext *ctx){} -void myGoListener::enterSimpleStmt(GoParser::SimpleStmtContext *ctx){} -void myGoListener::exitSimpleStmt(GoParser::SimpleStmtContext *ctx){} +void GoTo3code::enterSimpleStmt(GoParser::SimpleStmtContext *ctx){} +void GoTo3code::exitSimpleStmt(GoParser::SimpleStmtContext *ctx){} -void myGoListener::enterExpressionStmt(GoParser::ExpressionStmtContext *ctx){} -void myGoListener::exitExpressionStmt(GoParser::ExpressionStmtContext *ctx){} +void GoTo3code::enterExpressionStmt(GoParser::ExpressionStmtContext *ctx){} +void GoTo3code::exitExpressionStmt(GoParser::ExpressionStmtContext *ctx){} -void myGoListener::enterSendStmt(GoParser::SendStmtContext *ctx){} -void myGoListener::exitSendStmt(GoParser::SendStmtContext *ctx){} +void GoTo3code::enterSendStmt(GoParser::SendStmtContext *ctx){} +void GoTo3code::exitSendStmt(GoParser::SendStmtContext *ctx){} -void myGoListener::enterIncDecStmt(GoParser::IncDecStmtContext *ctx){} -void myGoListener::exitIncDecStmt(GoParser::IncDecStmtContext *ctx){ +void GoTo3code::enterIncDecStmt(GoParser::IncDecStmtContext *ctx){} +void GoTo3code::exitIncDecStmt(GoParser::IncDecStmtContext *ctx){ if (ctx->children[1]->getText() == "++") { std::shared_ptr> left_values; @@ -806,7 +806,7 @@ void myGoListener::exitIncDecStmt(GoParser::IncDecStmtContext *ctx){ string varname = (*left_values)[0]; string varvalue = "1"; ForStmt fortmp = forvalues->get(ctx->parent->parent->parent); - TACLine tmpline = TACLine(myGoListener::LineIndex, TACOP::ADD, Operand(varname, OperandTypereslove(varname)), Operand(varvalue, OperandTypereslove(varvalue)), Operand(varname, OperandTypereslove(varname)), currentScope); + TACLine tmpline = TACLine(GoTo3code::LineIndex, TACOP::ADD, Operand(varname, OperandTypereslove(varname)), Operand(varvalue, OperandTypereslove(varvalue)), Operand(varname, OperandTypereslove(varname)), currentScope); fortmp.UpdateCon = tmpline; forvalues->put(ctx->parent->parent->parent, fortmp); } @@ -821,8 +821,8 @@ void myGoListener::exitIncDecStmt(GoParser::IncDecStmtContext *ctx){ } } -void myGoListener::enterAssignment(GoParser::AssignmentContext *ctx){} -void myGoListener::exitAssignment(GoParser::AssignmentContext *ctx){ +void GoTo3code::enterAssignment(GoParser::AssignmentContext *ctx){} +void GoTo3code::exitAssignment(GoParser::AssignmentContext *ctx){ if(ctx->assign_op()->getText() == "=") @@ -878,7 +878,7 @@ void myGoListener::exitAssignment(GoParser::AssignmentContext *ctx){ string varname = (*left_values)[0]; string varvalue = (*right_values)[0]; ForStmt fortmp = forvalues->get(ctx->parent->parent->parent); - TACLine tmpline = TACLine(myGoListener::LineIndex, TACOP::ADD, Operand(varname, OperandTypereslove(varname)), Operand(varvalue, OperandTypereslove(varvalue)), Operand(varname, OperandTypereslove(varname)), currentScope); + TACLine tmpline = TACLine(GoTo3code::LineIndex, TACOP::ADD, Operand(varname, OperandTypereslove(varname)), Operand(varvalue, OperandTypereslove(varvalue)), Operand(varname, OperandTypereslove(varname)), currentScope); fortmp.UpdateCon = tmpline; forvalues->put(ctx->parent->parent->parent, fortmp); } @@ -893,11 +893,11 @@ void myGoListener::exitAssignment(GoParser::AssignmentContext *ctx){ } } -void myGoListener::enterAssign_op(GoParser::Assign_opContext *ctx){} -void myGoListener::exitAssign_op(GoParser::Assign_opContext *ctx){} +void GoTo3code::enterAssign_op(GoParser::Assign_opContext *ctx){} +void GoTo3code::exitAssign_op(GoParser::Assign_opContext *ctx){} -void myGoListener::enterShortVarDecl(GoParser::ShortVarDeclContext *ctx){} -void myGoListener::exitShortVarDecl(GoParser::ShortVarDeclContext *ctx){ +void GoTo3code::enterShortVarDecl(GoParser::ShortVarDeclContext *ctx){} +void GoTo3code::exitShortVarDecl(GoParser::ShortVarDeclContext *ctx){ int n = ctx->identifierList()->IDENTIFIER().size(); for(int i=0;i symbol=make_shared(varname,currentScope,Symbol::SymbolType::VAR,type); - myGoListener::currentScope->para_define(symbol); + GoTo3code::currentScope->para_define(symbol); } @@ -946,14 +946,14 @@ void myGoListener::exitShortVarDecl(GoParser::ShortVarDeclContext *ctx){ } } -void myGoListener::enterEmptyStmt(GoParser::EmptyStmtContext *ctx){} -void myGoListener::exitEmptyStmt(GoParser::EmptyStmtContext *ctx){} +void GoTo3code::enterEmptyStmt(GoParser::EmptyStmtContext *ctx){} +void GoTo3code::exitEmptyStmt(GoParser::EmptyStmtContext *ctx){} -void myGoListener::enterLabeledStmt(GoParser::LabeledStmtContext *ctx){} -void myGoListener::exitLabeledStmt(GoParser::LabeledStmtContext *ctx){} +void GoTo3code::enterLabeledStmt(GoParser::LabeledStmtContext *ctx){} +void GoTo3code::exitLabeledStmt(GoParser::LabeledStmtContext *ctx){} -void myGoListener::enterReturnStmt(GoParser::ReturnStmtContext *ctx){} -void myGoListener::exitReturnStmt(GoParser::ReturnStmtContext *ctx){ +void GoTo3code::enterReturnStmt(GoParser::ReturnStmtContext *ctx){} +void GoTo3code::exitReturnStmt(GoParser::ReturnStmtContext *ctx){ std::shared_ptr> return_values; return_values=ctx_decoder(values->get(ctx->expressionList())); /*是否声明*/ @@ -970,76 +970,76 @@ void myGoListener::exitReturnStmt(GoParser::ReturnStmtContext *ctx){ } } -void myGoListener::enterBreakStmt(GoParser::BreakStmtContext *ctx){} -void myGoListener::exitBreakStmt(GoParser::BreakStmtContext *ctx){} +void GoTo3code::enterBreakStmt(GoParser::BreakStmtContext *ctx){} +void GoTo3code::exitBreakStmt(GoParser::BreakStmtContext *ctx){} -void myGoListener::enterContinueStmt(GoParser::ContinueStmtContext *ctx){} -void myGoListener::exitContinueStmt(GoParser::ContinueStmtContext *ctx){} +void GoTo3code::enterContinueStmt(GoParser::ContinueStmtContext *ctx){} +void GoTo3code::exitContinueStmt(GoParser::ContinueStmtContext *ctx){} -void myGoListener::enterGotoStmt(GoParser::GotoStmtContext *ctx){} -void myGoListener::exitGotoStmt(GoParser::GotoStmtContext *ctx){} +void GoTo3code::enterGotoStmt(GoParser::GotoStmtContext *ctx){} +void GoTo3code::exitGotoStmt(GoParser::GotoStmtContext *ctx){} -void myGoListener::enterFallthroughStmt(GoParser::FallthroughStmtContext *ctx){} -void myGoListener::exitFallthroughStmt(GoParser::FallthroughStmtContext *ctx){} +void GoTo3code::enterFallthroughStmt(GoParser::FallthroughStmtContext *ctx){} +void GoTo3code::exitFallthroughStmt(GoParser::FallthroughStmtContext *ctx){} -void myGoListener::enterDeferStmt(GoParser::DeferStmtContext *ctx){} -void myGoListener::exitDeferStmt(GoParser::DeferStmtContext *ctx){} +void GoTo3code::enterDeferStmt(GoParser::DeferStmtContext *ctx){} +void GoTo3code::exitDeferStmt(GoParser::DeferStmtContext *ctx){} -void myGoListener::enterIfStmt(GoParser::IfStmtContext *ctx){ +void GoTo3code::enterIfStmt(GoParser::IfStmtContext *ctx){ std::string iftmp = CreateElseLabel(); ifvalues->put(ctx, iftmp); } -void myGoListener::exitIfStmt(GoParser::IfStmtContext *ctx){ +void GoTo3code::exitIfStmt(GoParser::IfStmtContext *ctx){ push_line(TACOP::LABEL,Operand("ENDIF" + ifvalues->get(ctx),TACOPERANDTYPE::LABEL),Operand("",TACOPERANDTYPE::NULL_),Operand("",TACOPERANDTYPE::NULL_)); } -void myGoListener::enterSwitchStmt(GoParser::SwitchStmtContext *ctx){} -void myGoListener::exitSwitchStmt(GoParser::SwitchStmtContext *ctx){} +void GoTo3code::enterSwitchStmt(GoParser::SwitchStmtContext *ctx){} +void GoTo3code::exitSwitchStmt(GoParser::SwitchStmtContext *ctx){} -void myGoListener::enterExprSwitchStmt(GoParser::ExprSwitchStmtContext *ctx){} -void myGoListener::exitExprSwitchStmt(GoParser::ExprSwitchStmtContext *ctx){} +void GoTo3code::enterExprSwitchStmt(GoParser::ExprSwitchStmtContext *ctx){} +void GoTo3code::exitExprSwitchStmt(GoParser::ExprSwitchStmtContext *ctx){} -void myGoListener::enterExprCaseClause(GoParser::ExprCaseClauseContext *ctx){} -void myGoListener::exitExprCaseClause(GoParser::ExprCaseClauseContext *ctx){} +void GoTo3code::enterExprCaseClause(GoParser::ExprCaseClauseContext *ctx){} +void GoTo3code::exitExprCaseClause(GoParser::ExprCaseClauseContext *ctx){} -void myGoListener::enterExprSwitchCase(GoParser::ExprSwitchCaseContext *ctx){} -void myGoListener::exitExprSwitchCase(GoParser::ExprSwitchCaseContext *ctx){} +void GoTo3code::enterExprSwitchCase(GoParser::ExprSwitchCaseContext *ctx){} +void GoTo3code::exitExprSwitchCase(GoParser::ExprSwitchCaseContext *ctx){} -void myGoListener::enterTypeSwitchStmt(GoParser::TypeSwitchStmtContext *ctx){} -void myGoListener::exitTypeSwitchStmt(GoParser::TypeSwitchStmtContext *ctx){} +void GoTo3code::enterTypeSwitchStmt(GoParser::TypeSwitchStmtContext *ctx){} +void GoTo3code::exitTypeSwitchStmt(GoParser::TypeSwitchStmtContext *ctx){} -void myGoListener::enterTypeSwitchGuard(GoParser::TypeSwitchGuardContext *ctx){} -void myGoListener::exitTypeSwitchGuard(GoParser::TypeSwitchGuardContext *ctx){} +void GoTo3code::enterTypeSwitchGuard(GoParser::TypeSwitchGuardContext *ctx){} +void GoTo3code::exitTypeSwitchGuard(GoParser::TypeSwitchGuardContext *ctx){} -void myGoListener::enterTypeCaseClause(GoParser::TypeCaseClauseContext *ctx){} -void myGoListener::exitTypeCaseClause(GoParser::TypeCaseClauseContext *ctx){} +void GoTo3code::enterTypeCaseClause(GoParser::TypeCaseClauseContext *ctx){} +void GoTo3code::exitTypeCaseClause(GoParser::TypeCaseClauseContext *ctx){} -void myGoListener::enterTypeSwitchCase(GoParser::TypeSwitchCaseContext *ctx){} -void myGoListener::exitTypeSwitchCase(GoParser::TypeSwitchCaseContext *ctx){} +void GoTo3code::enterTypeSwitchCase(GoParser::TypeSwitchCaseContext *ctx){} +void GoTo3code::exitTypeSwitchCase(GoParser::TypeSwitchCaseContext *ctx){} -void myGoListener::enterTypeList(GoParser::TypeListContext *ctx){} -void myGoListener::exitTypeList(GoParser::TypeListContext *ctx){} +void GoTo3code::enterTypeList(GoParser::TypeListContext *ctx){} +void GoTo3code::exitTypeList(GoParser::TypeListContext *ctx){} -void myGoListener::enterSelectStmt(GoParser::SelectStmtContext *ctx){} -void myGoListener::exitSelectStmt(GoParser::SelectStmtContext *ctx){} +void GoTo3code::enterSelectStmt(GoParser::SelectStmtContext *ctx){} +void GoTo3code::exitSelectStmt(GoParser::SelectStmtContext *ctx){} -void myGoListener::enterCommClause(GoParser::CommClauseContext *ctx){} -void myGoListener::exitCommClause(GoParser::CommClauseContext *ctx){} +void GoTo3code::enterCommClause(GoParser::CommClauseContext *ctx){} +void GoTo3code::exitCommClause(GoParser::CommClauseContext *ctx){} -void myGoListener::enterCommCase(GoParser::CommCaseContext *ctx){} -void myGoListener::exitCommCase(GoParser::CommCaseContext *ctx){} +void GoTo3code::enterCommCase(GoParser::CommCaseContext *ctx){} +void GoTo3code::exitCommCase(GoParser::CommCaseContext *ctx){} -void myGoListener::enterRecvStmt(GoParser::RecvStmtContext *ctx){} -void myGoListener::exitRecvStmt(GoParser::RecvStmtContext *ctx){} +void GoTo3code::enterRecvStmt(GoParser::RecvStmtContext *ctx){} +void GoTo3code::exitRecvStmt(GoParser::RecvStmtContext *ctx){} -void myGoListener::enterForStmt(GoParser::ForStmtContext *ctx){ +void GoTo3code::enterForStmt(GoParser::ForStmtContext *ctx){ std::string tmp = CreateForLabel(); ForStmt newfor = ForStmt(tmp); cout << newfor.CurIndex<put(ctx, newfor); addScope(); } -void myGoListener::exitForStmt(GoParser::ForStmtContext *ctx){ +void GoTo3code::exitForStmt(GoParser::ForStmtContext *ctx){ ForStmt tmp = forvalues->get(ctx); popScope(); // for (auto para : tmp.newParas) @@ -1049,64 +1049,64 @@ void myGoListener::exitForStmt(GoParser::ForStmtContext *ctx){ push_line(TACOP::LABEL,Operand("ENDFOR" + forvalues->get(ctx).CurIndex,TACOPERANDTYPE::LABEL),Operand("",TACOPERANDTYPE::NULL_),Operand("",TACOPERANDTYPE::NULL_)); } -void myGoListener::enterForClause(GoParser::ForClauseContext *ctx){} -void myGoListener::exitForClause(GoParser::ForClauseContext *ctx){} +void GoTo3code::enterForClause(GoParser::ForClauseContext *ctx){} +void GoTo3code::exitForClause(GoParser::ForClauseContext *ctx){} -void myGoListener::enterRangeClause(GoParser::RangeClauseContext *ctx){} -void myGoListener::exitRangeClause(GoParser::RangeClauseContext *ctx){} +void GoTo3code::enterRangeClause(GoParser::RangeClauseContext *ctx){} +void GoTo3code::exitRangeClause(GoParser::RangeClauseContext *ctx){} -void myGoListener::enterGoStmt(GoParser::GoStmtContext *ctx){} -void myGoListener::exitGoStmt(GoParser::GoStmtContext *ctx){} +void GoTo3code::enterGoStmt(GoParser::GoStmtContext *ctx){} +void GoTo3code::exitGoStmt(GoParser::GoStmtContext *ctx){} -void myGoListener::enterType_(GoParser::Type_Context *ctx){} -void myGoListener::exitType_(GoParser::Type_Context *ctx){} +void GoTo3code::enterType_(GoParser::Type_Context *ctx){} +void GoTo3code::exitType_(GoParser::Type_Context *ctx){} -void myGoListener::enterTypeName(GoParser::TypeNameContext *ctx){} -void myGoListener::exitTypeName(GoParser::TypeNameContext *ctx){} +void GoTo3code::enterTypeName(GoParser::TypeNameContext *ctx){} +void GoTo3code::exitTypeName(GoParser::TypeNameContext *ctx){} -void myGoListener::enterTypeLit(GoParser::TypeLitContext *ctx){} -void myGoListener::exitTypeLit(GoParser::TypeLitContext *ctx){} +void GoTo3code::enterTypeLit(GoParser::TypeLitContext *ctx){} +void GoTo3code::exitTypeLit(GoParser::TypeLitContext *ctx){} -void myGoListener::enterArrayType(GoParser::ArrayTypeContext *ctx){} -void myGoListener::exitArrayType(GoParser::ArrayTypeContext *ctx){} +void GoTo3code::enterArrayType(GoParser::ArrayTypeContext *ctx){} +void GoTo3code::exitArrayType(GoParser::ArrayTypeContext *ctx){} -void myGoListener::enterArrayLength(GoParser::ArrayLengthContext *ctx){} -void myGoListener::exitArrayLength(GoParser::ArrayLengthContext *ctx){} +void GoTo3code::enterArrayLength(GoParser::ArrayLengthContext *ctx){} +void GoTo3code::exitArrayLength(GoParser::ArrayLengthContext *ctx){} -void myGoListener::enterElementType(GoParser::ElementTypeContext *ctx){} -void myGoListener::exitElementType(GoParser::ElementTypeContext *ctx){} +void GoTo3code::enterElementType(GoParser::ElementTypeContext *ctx){} +void GoTo3code::exitElementType(GoParser::ElementTypeContext *ctx){} -void myGoListener::enterPointerType(GoParser::PointerTypeContext *ctx){} -void myGoListener::exitPointerType(GoParser::PointerTypeContext *ctx){} +void GoTo3code::enterPointerType(GoParser::PointerTypeContext *ctx){} +void GoTo3code::exitPointerType(GoParser::PointerTypeContext *ctx){} -void myGoListener::enterInterfaceType(GoParser::InterfaceTypeContext *ctx){} -void myGoListener::exitInterfaceType(GoParser::InterfaceTypeContext *ctx){} +void GoTo3code::enterInterfaceType(GoParser::InterfaceTypeContext *ctx){} +void GoTo3code::exitInterfaceType(GoParser::InterfaceTypeContext *ctx){} -void myGoListener::enterSliceType(GoParser::SliceTypeContext *ctx){} -void myGoListener::exitSliceType(GoParser::SliceTypeContext *ctx){} +void GoTo3code::enterSliceType(GoParser::SliceTypeContext *ctx){} +void GoTo3code::exitSliceType(GoParser::SliceTypeContext *ctx){} -void myGoListener::enterMapType(GoParser::MapTypeContext *ctx){} -void myGoListener::exitMapType(GoParser::MapTypeContext *ctx){} +void GoTo3code::enterMapType(GoParser::MapTypeContext *ctx){} +void GoTo3code::exitMapType(GoParser::MapTypeContext *ctx){} -void myGoListener::enterChannelType(GoParser::ChannelTypeContext *ctx){} -void myGoListener::exitChannelType(GoParser::ChannelTypeContext *ctx){} +void GoTo3code::enterChannelType(GoParser::ChannelTypeContext *ctx){} +void GoTo3code::exitChannelType(GoParser::ChannelTypeContext *ctx){} -void myGoListener::enterMethodSpec(GoParser::MethodSpecContext *ctx){} -void myGoListener::exitMethodSpec(GoParser::MethodSpecContext *ctx){} +void GoTo3code::enterMethodSpec(GoParser::MethodSpecContext *ctx){} +void GoTo3code::exitMethodSpec(GoParser::MethodSpecContext *ctx){} -void myGoListener::enterFunctionType(GoParser::FunctionTypeContext *ctx){} -void myGoListener::exitFunctionType(GoParser::FunctionTypeContext *ctx){} +void GoTo3code::enterFunctionType(GoParser::FunctionTypeContext *ctx){} +void GoTo3code::exitFunctionType(GoParser::FunctionTypeContext *ctx){} -void myGoListener::enterSignature(GoParser::SignatureContext *ctx){} -void myGoListener::exitSignature(GoParser::SignatureContext *ctx){} +void GoTo3code::enterSignature(GoParser::SignatureContext *ctx){} +void GoTo3code::exitSignature(GoParser::SignatureContext *ctx){} -void myGoListener::enterResult(GoParser::ResultContext *ctx){} -void myGoListener::exitResult(GoParser::ResultContext *ctx){} +void GoTo3code::enterResult(GoParser::ResultContext *ctx){} +void GoTo3code::exitResult(GoParser::ResultContext *ctx){} -void myGoListener::enterParameters(GoParser::ParametersContext *ctx){} -void myGoListener::exitParameters(GoParser::ParametersContext *ctx){} +void GoTo3code::enterParameters(GoParser::ParametersContext *ctx){} +void GoTo3code::exitParameters(GoParser::ParametersContext *ctx){} -void myGoListener::enterParameterDecl(GoParser::ParameterDeclContext *ctx){ +void GoTo3code::enterParameterDecl(GoParser::ParameterDeclContext *ctx){ if(ctx->identifierList()){ /* x int */ int n=ctx->identifierList()->IDENTIFIER().size(); @@ -1117,24 +1117,24 @@ void myGoListener::enterParameterDecl(GoParser::ParameterDeclContext *ctx){ string stype=ctx->type_()->typeName()->getText(); Symbol::Type type=Symbol::toType(stype); std::shared_ptr symbol= make_shared(integer,currentScope,Symbol::SymbolType::VAR,type); - myGoListener::currentScope->para_define(symbol); + GoTo3code::currentScope->para_define(symbol); } } } -void myGoListener::exitParameterDecl(GoParser::ParameterDeclContext *ctx){} +void GoTo3code::exitParameterDecl(GoParser::ParameterDeclContext *ctx){} -void myGoListener::enterConversion(GoParser::ConversionContext *ctx){} -void myGoListener::exitConversion(GoParser::ConversionContext *ctx){} +void GoTo3code::enterConversion(GoParser::ConversionContext *ctx){} +void GoTo3code::exitConversion(GoParser::ConversionContext *ctx){} -void myGoListener::enterNonNamedType(GoParser::NonNamedTypeContext *ctx){} -void myGoListener::exitNonNamedType(GoParser::NonNamedTypeContext *ctx){} +void GoTo3code::enterNonNamedType(GoParser::NonNamedTypeContext *ctx){} +void GoTo3code::exitNonNamedType(GoParser::NonNamedTypeContext *ctx){} -void myGoListener::enterOperandName(GoParser::OperandNameContext *ctx){} -void myGoListener::exitOperandName(GoParser::OperandNameContext *ctx){ +void GoTo3code::enterOperandName(GoParser::OperandNameContext *ctx){} +void GoTo3code::exitOperandName(GoParser::OperandNameContext *ctx){ shared_ptr tmp; if(currentScope->resolve(ctx->IDENTIFIER()->getText(),tmp)==FAIL){ LOG(FATAL) << "Undefined: " << ctx->IDENTIFIER()->getText(); @@ -1143,71 +1143,71 @@ void myGoListener::exitOperandName(GoParser::OperandNameContext *ctx){ values->put(ctx,ctx->IDENTIFIER()->getText()+DELIMITER); } -void myGoListener::enterQualifiedIdent(GoParser::QualifiedIdentContext *ctx){} -void myGoListener::exitQualifiedIdent(GoParser::QualifiedIdentContext *ctx){} +void GoTo3code::enterQualifiedIdent(GoParser::QualifiedIdentContext *ctx){} +void GoTo3code::exitQualifiedIdent(GoParser::QualifiedIdentContext *ctx){} -void myGoListener::enterCompositeLit(GoParser::CompositeLitContext *ctx){} -void myGoListener::exitCompositeLit(GoParser::CompositeLitContext *ctx){} +void GoTo3code::enterCompositeLit(GoParser::CompositeLitContext *ctx){} +void GoTo3code::exitCompositeLit(GoParser::CompositeLitContext *ctx){} -void myGoListener::enterLiteralType(GoParser::LiteralTypeContext *ctx){} -void myGoListener::exitLiteralType(GoParser::LiteralTypeContext *ctx){} +void GoTo3code::enterLiteralType(GoParser::LiteralTypeContext *ctx){} +void GoTo3code::exitLiteralType(GoParser::LiteralTypeContext *ctx){} -void myGoListener::enterLiteralValue(GoParser::LiteralValueContext *ctx){} -void myGoListener::exitLiteralValue(GoParser::LiteralValueContext *ctx){} +void GoTo3code::enterLiteralValue(GoParser::LiteralValueContext *ctx){} +void GoTo3code::exitLiteralValue(GoParser::LiteralValueContext *ctx){} -void myGoListener::enterElementList(GoParser::ElementListContext *ctx){} -void myGoListener::exitElementList(GoParser::ElementListContext *ctx){} +void GoTo3code::enterElementList(GoParser::ElementListContext *ctx){} +void GoTo3code::exitElementList(GoParser::ElementListContext *ctx){} -void myGoListener::enterKeyedElement(GoParser::KeyedElementContext *ctx){} -void myGoListener::exitKeyedElement(GoParser::KeyedElementContext *ctx){} +void GoTo3code::enterKeyedElement(GoParser::KeyedElementContext *ctx){} +void GoTo3code::exitKeyedElement(GoParser::KeyedElementContext *ctx){} -void myGoListener::enterKey(GoParser::KeyContext *ctx){} -void myGoListener::exitKey(GoParser::KeyContext *ctx){} +void GoTo3code::enterKey(GoParser::KeyContext *ctx){} +void GoTo3code::exitKey(GoParser::KeyContext *ctx){} -void myGoListener::enterElement(GoParser::ElementContext *ctx){} -void myGoListener::exitElement(GoParser::ElementContext *ctx){} +void GoTo3code::enterElement(GoParser::ElementContext *ctx){} +void GoTo3code::exitElement(GoParser::ElementContext *ctx){} -void myGoListener::enterStructType(GoParser::StructTypeContext *ctx){} -void myGoListener::exitStructType(GoParser::StructTypeContext *ctx){} +void GoTo3code::enterStructType(GoParser::StructTypeContext *ctx){} +void GoTo3code::exitStructType(GoParser::StructTypeContext *ctx){} -void myGoListener::enterFieldDecl(GoParser::FieldDeclContext *ctx){} -void myGoListener::exitFieldDecl(GoParser::FieldDeclContext *ctx){} +void GoTo3code::enterFieldDecl(GoParser::FieldDeclContext *ctx){} +void GoTo3code::exitFieldDecl(GoParser::FieldDeclContext *ctx){} -void myGoListener::enterString_(GoParser::String_Context *ctx){} -void myGoListener::exitString_(GoParser::String_Context *ctx){} +void GoTo3code::enterString_(GoParser::String_Context *ctx){} +void GoTo3code::exitString_(GoParser::String_Context *ctx){} -void myGoListener::enterEmbeddedField(GoParser::EmbeddedFieldContext *ctx){} -void myGoListener::exitEmbeddedField(GoParser::EmbeddedFieldContext *ctx){} +void GoTo3code::enterEmbeddedField(GoParser::EmbeddedFieldContext *ctx){} +void GoTo3code::exitEmbeddedField(GoParser::EmbeddedFieldContext *ctx){} -void myGoListener::enterFunctionLit(GoParser::FunctionLitContext *ctx){} -void myGoListener::exitFunctionLit(GoParser::FunctionLitContext *ctx){} +void GoTo3code::enterFunctionLit(GoParser::FunctionLitContext *ctx){} +void GoTo3code::exitFunctionLit(GoParser::FunctionLitContext *ctx){} -void myGoListener::enterIndex(GoParser::IndexContext *ctx){} -void myGoListener::exitIndex(GoParser::IndexContext *ctx){} +void GoTo3code::enterIndex(GoParser::IndexContext *ctx){} +void GoTo3code::exitIndex(GoParser::IndexContext *ctx){} -void myGoListener::enterSlice_(GoParser::Slice_Context *ctx){} -void myGoListener::exitSlice_(GoParser::Slice_Context *ctx){} +void GoTo3code::enterSlice_(GoParser::Slice_Context *ctx){} +void GoTo3code::exitSlice_(GoParser::Slice_Context *ctx){} -void myGoListener::enterTypeAssertion(GoParser::TypeAssertionContext *ctx){} -void myGoListener::exitTypeAssertion(GoParser::TypeAssertionContext *ctx){} +void GoTo3code::enterTypeAssertion(GoParser::TypeAssertionContext *ctx){} +void GoTo3code::exitTypeAssertion(GoParser::TypeAssertionContext *ctx){} -void myGoListener::enterArguments(GoParser::ArgumentsContext *ctx){} -void myGoListener::exitArguments(GoParser::ArgumentsContext *ctx){ +void GoTo3code::enterArguments(GoParser::ArgumentsContext *ctx){} +void GoTo3code::exitArguments(GoParser::ArgumentsContext *ctx){ if(ctx->expressionList()){ values->put(ctx, values->get(ctx->expressionList())); } } -void myGoListener::enterMethodExpr(GoParser::MethodExprContext *ctx){} -void myGoListener::exitMethodExpr(GoParser::MethodExprContext *ctx){} +void GoTo3code::enterMethodExpr(GoParser::MethodExprContext *ctx){} +void GoTo3code::exitMethodExpr(GoParser::MethodExprContext *ctx){} -void myGoListener::enterReceiverType(GoParser::ReceiverTypeContext *ctx){} -void myGoListener::exitReceiverType(GoParser::ReceiverTypeContext *ctx){} +void GoTo3code::enterReceiverType(GoParser::ReceiverTypeContext *ctx){} +void GoTo3code::exitReceiverType(GoParser::ReceiverTypeContext *ctx){} -void myGoListener::enterEoss(GoParser::EossContext *ctx){} -void myGoListener::exitEoss(GoParser::EossContext *ctx){} +void GoTo3code::enterEoss(GoParser::EossContext *ctx){} +void GoTo3code::exitEoss(GoParser::EossContext *ctx){} -void myGoListener::visitTerminal(antlr4::tree::TerminalNode *node){} -void myGoListener::visitErrorNode(antlr4::tree::ErrorNode *node){} -void myGoListener::enterEveryRule(antlr4::ParserRuleContext *ctx){} -void myGoListener::exitEveryRule(antlr4::ParserRuleContext *ctx){} +void GoTo3code::visitTerminal(antlr4::tree::TerminalNode *node){} +void GoTo3code::visitErrorNode(antlr4::tree::ErrorNode *node){} +void GoTo3code::enterEveryRule(antlr4::ParserRuleContext *ctx){} +void GoTo3code::exitEveryRule(antlr4::ParserRuleContext *ctx){}