\r
#include "repr.h"\r
\r
-Type getType(TocParser::TypeContext * ctx);\r
-Variable getVariable(TocParser::VarContext * ctx);\r
-Body getBody(TocParser::BodyContext * ctx);\r
-Function getFunction(TocParser::FuncContext * ctx);\r
-Struct getStruct(TocParser::StructDeclContext * ctx);\r
-Program getProgram(TocParser::ProgContext * ctx);\r
-//Expr getExpr(TocParser::NonOpExprContext * ctx);\r
-//Expr getExpr(TocParser::NonAccessExprContext * ctx);\r
-Expr getExpr(TocParser::ExprContext * ctx);\r
-Stmt getStmt(TocParser::StmtContext * ctx);\r
-\r
-Type getType(TocParser::TypeContext * ctx) {\r
+Type getType(TocParser::TypeContext * ctx);\r
+Variable getVariable(TocParser::VarContext * ctx);\r
+Body getBody(TocParser::BodyContext * ctx);\r
+Function getFunction(TocParser::FuncContext * ctx);\r
+Struct getStruct(TocParser::StructDeclContext * ctx);\r
+Namespace getNamespace(TocParser::NamespaceDeclContext * ctx);\r
+Program getProgram(TocParser::ProgContext * ctx);\r
+\r
+\r
+Expr getExpr(TocParser::FuncExprContext * ctx);\r
+Expr getExpr(TocParser::MethodExprContext * ctx);\r
+Expr getExpr(TocParser::LitExprContext * ctx);\r
+Expr getExpr(TocParser::ParenExprContext * ctx);\r
+Expr getExpr(TocParser::DotExprContext * ctx);\r
+Expr getExpr(TocParser::PrefixOpExprContext * ctx);\r
+Expr getExpr(TocParser::PostfixOpExprContext * ctx);\r
+Expr getExpr(TocParser::BinaryOpExprContext * ctx);\r
+Expr getExpr(TocParser::TernaryOpExprContext * ctx);\r
+Expr getExpr(TocParser::BracketExprContext * ctx);\r
+Expr getExpr(TocParser::IdentifierExprContext * ctx);\r
+Expr getExpr(TocParser::ExprContext * ctx);\r
+\r
+Stmt getStmt(TocParser::StmtContext * ctx);\r
+\r
+Type getType(TocParser::TypeContext * ctx)\r
+{\r
Type result;\r
+ for (auto n : ctx->namespaceSpecifier())\r
+ result.namespacePrefixes.push_back(n->typeName()->getText());\r
result.name = ctx->typeName()->NAME()->toString();\r
+ for (auto m : ctx->typeModifier())\r
+ {\r
+ bool isPointer = m->getText() == "*";\r
+ bool isStaticArray = m->INT_LIT() != nullptr;\r
+\r
+ result.modifiers.emplace_back(\r
+ isPointer ? TypeModifierType::Pointer : TypeModifierType::Array,\r
+ isStaticArray,\r
+ isStaticArray ? atoi(m->INT_LIT()->toString().c_str()) : -1\r
+ );\r
+ }\r
return result;\r
}\r
-Variable getVariable(TocParser::VarContext * ctx) {\r
+Variable getVariable(TocParser::VarContext * ctx)\r
+{\r
Variable result;\r
result.name = ctx->varName()->NAME()->toString();\r
result.type = getType(ctx->type());\r
return result;\r
}\r
-Body getBody(TocParser::BodyContext * ctx) {\r
+Body getBody(TocParser::BodyContext * ctx)\r
+{\r
Body result;\r
- for (auto s : ctx->stmt()) {\r
- if (s->varDecl() != nullptr) {\r
+ for (auto s : ctx->stmt())\r
+ {\r
+ if (s->varDecl() != nullptr)\r
+ {\r
result.variables.push_back(getVariable(s->varDecl()->var()));\r
+ if (s->varDecl()->var()->expr() != nullptr)\r
+ result.statements.push_back(getStmt(s));\r
}\r
- else {\r
+ else\r
+ {\r
result.statements.push_back(getStmt(s));\r
}\r
}\r
return result;\r
}\r
-Function getFunction(TocParser::FuncContext * ctx) {\r
+Function getFunction(TocParser::FuncContext * ctx)\r
+{\r
Function result;\r
result.name = ctx->funcName()->NAME()->toString();\r
result.returnType = getType(ctx->type());\r
- if (!ctx->parameter()->var().empty()) {\r
+ if (!ctx->parameter()->var().empty())\r
+ {\r
for (auto p : ctx->parameter()->var())\r
result.parameters.push_back(getVariable(p));\r
}\r
result.body = getBody(ctx->body());\r
return result;\r
}\r
-Struct getStruct(TocParser::StructDeclContext * ctx) {\r
+Struct getStruct(TocParser::StructDeclContext * ctx)\r
+{\r
Struct result;\r
result.name = ctx->structName()->NAME()->toString();\r
- for (auto m : ctx->structMember()) {\r
- if (m->structVar() != nullptr) {\r
- result.members.push_back(getVariable(m->structVar()->var()));\r
+ for (auto m : ctx->structMember())\r
+ {\r
+ if (m->structVar() != nullptr)\r
+ {\r
+ result.members.push_back({\r
+ getVariable(m->structVar()->var()),\r
+ m->privateDecl() != nullptr\r
+ });\r
}\r
- if (m->structMethod() != nullptr) {\r
- result.methods.push_back(getFunction(m->structMethod()->func()));\r
+ if (m->structMethod() != nullptr)\r
+ {\r
+ result.methods.push_back({\r
+ getFunction(m->structMethod()->func()),\r
+ m->privateDecl() != nullptr\r
+ });\r
}\r
}\r
return result;\r
}\r
-Program getProgram(TocParser::ProgContext * ctx) {\r
+Namespace getNamespace(TocParser::NamespaceDeclContext * ctx)\r
+{\r
+ Namespace result;\r
+ result.name = ctx->typeName()->getText();\r
+ for (auto d : ctx->decl())\r
+ {\r
+ if (d->varDecl() != nullptr)\r
+ {\r
+ result.variables.push_back(getVariable(d->varDecl()->var()));\r
+ }\r
+ if (d->funcDecl() != nullptr)\r
+ {\r
+ result.functions.push_back(getFunction(d->funcDecl()->func()));\r
+ }\r
+ if (d->structDecl() != nullptr)\r
+ {\r
+ result.structs.push_back(getStruct(d->structDecl()));\r
+ }\r
+ if (d->namespaceDecl() != nullptr)\r
+ {\r
+ result.namespaces.push_back(getNamespace(d->namespaceDecl()));\r
+ }\r
+ }\r
+ return result;\r
+}\r
+Program getProgram(TocParser::ProgContext * ctx)\r
+{\r
Program result;\r
- for (auto d : ctx->decl()) {\r
- if (d->varDecl() != nullptr) {\r
+ for (auto d : ctx->decl())\r
+ {\r
+ if (d->varDecl() != nullptr)\r
+ {\r
result.variables.push_back(getVariable(d->varDecl()->var()));\r
}\r
- if (d->funcDecl() != nullptr) {\r
+ if (d->funcDecl() != nullptr)\r
+ {\r
result.functions.push_back(getFunction(d->funcDecl()->func()));\r
}\r
- if (d->structDecl() != nullptr) {\r
+ if (d->structDecl() != nullptr)\r
+ {\r
result.structs.push_back(getStruct(d->structDecl()));\r
}\r
+ if (d->namespaceDecl() != nullptr)\r
+ {\r
+ result.namespaces.push_back(getNamespace(d->namespaceDecl()));\r
+ }\r
}\r
return result;\r
}\r
-OperatorExpr getOperatorExpr(TocParser::OpExprContext * ctx) {\r
- OperatorExpr result;\r
- result.lexpr = std::make_unique<Expr>(getExpr(ctx->binaryOp()->nonOpExpr(0)));\r
- result.rexpr = std::make_unique<Expr>(getExpr(ctx->binaryOp()->nonOpExpr(1)));\r
- \r
- std::string op = ctx->binaryOp()->BINARY_OP(0)->toString();\r
- for (auto o : ops) {\r
-\r
+template<typename OpType>\r
+OpType getOperatorType(const std::string & s, std::string typeStrings[])\r
+{\r
+ for (int i = 0; i < (int)OpType::COUNT; i++)\r
+ {\r
+ if (typeStrings[i] == s)\r
+ {\r
+ return (OpType)i;\r
+ }\r
}\r
- if (op == "+") result.type = OperatorType::Plus;\r
- if (op == "-") result.type = OperatorType::Minus;\r
- if (op == "*") result.type = OperatorType::Multiply;\r
- if (op == "/") result.type = OperatorType::Divide;\r
- if (op == "==") result.type = OperatorType::Equals;\r
- if (op == "!=") result.type = OperatorType::NotEquals;\r
- if (op == "<") result.type = OperatorType::LessThan;\r
- if (op == ">") result.type = OperatorType::GreaterThan;\r
+ return OpType::COUNT;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+Expr getExpr(TocParser::FuncExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::Func;\r
+ for (auto n : ctx->namespaceSpecifier())\r
+ result._func.namespacePrefixes.push_back(n->typeName()->getText());\r
+ result._func.functionName = ctx->funcName()->NAME()->toString();\r
+ for (auto e : ctx->expr())\r
+ result._func.arguments.push_back(getExpr(e));\r
return result;\r
}\r
-Expr getExpr(TocParser::NonOpExprContext * ctx) {\r
+Expr getExpr(TocParser::MethodExprContext * ctx)\r
+{\r
Expr result;\r
- if (ctx->funcCall() != nullptr) {\r
- result.type = ExprType::Call;\r
- for (auto e : ctx->funcCall()->expr())\r
- result._call.arguments.push_back(getExpr(e));\r
- result._call.functionName = ctx->funcCall()->funcName()->NAME()->toString();\r
- }\r
- if (ctx->literal() != nullptr) {\r
- result.type = ExprType::Literal;\r
- result._literal.i = atoi(ctx->literal()->INTLIT()->toString().c_str());\r
- }\r
- if (ctx->identifier() != nullptr) {\r
- result.type = ExprType::Variable;\r
- result._variable.name = ctx->identifier()->varName()->NAME()->toString();\r
- }\r
- if (ctx->subscript() != nullptr) {\r
- result.type = ExprType::Brackets;\r
- result._brackets.lexpr = std::make_unique<Expr>(getExpr(ctx->subscript()->nonSubscriptExpr()));\r
- result._brackets.rexpr = std::make_unique<Expr>(getExpr(ctx->subscript()->expr()));\r
- }\r
- if (ctx->memberAccess() != nullptr) {\r
- result.type = ExprType::Dot;\r
- Expr e; e.type = ExprType::Variable; e._variable.name = ctx->memberAccess()->identifier(0)->varName()->NAME()->toString();\r
- result._dot.lexpr = std::make_unique<Expr>(e);\r
- result._dot.name = ctx->memberAccess()->identifier(1)->varName()->NAME()->toString();\r
- }\r
+ result.type = ExprType::Method;\r
+ result._method.expr = std::make_unique<Expr>(getExpr(ctx->expr(0)));\r
+ result._method.methodName = ctx->funcName()->NAME()->toString();\r
+ for (int i = 1; i < ctx->expr().size(); i++)\r
+ result._method.arguments.push_back(getExpr(ctx->expr(i)));\r
return result;\r
}\r
-Expr getExpr(TocParser::NonAccessExprContext * ctx) {\r
+Expr getExpr(TocParser::LitExprContext * ctx)\r
+{\r
Expr result;\r
- if (ctx->funcCall() != nullptr) {\r
- result.type = ExprType::Call;\r
- for (auto e : ctx->funcCall()->expr())\r
- result._call.arguments.push_back(getExpr(e));\r
- result._call.functionName = ctx->funcCall()->funcName()->NAME()->toString();\r
+ result.type = ExprType::Lit;\r
+ if (ctx->literal()->INT_LIT() != nullptr)\r
+ {\r
+ result._lit.type = LitType::Int;\r
+ result._lit._int = atoi(ctx->literal()->INT_LIT()->toString().c_str());\r
}\r
- if (ctx->literal() != nullptr) {\r
- result.type = ExprType::Literal;\r
- result._literal.i = atoi(ctx->literal()->INTLIT()->toString().c_str());\r
+ else if (ctx->literal()->DECIMAL_LIT() != nullptr)\r
+ {\r
+ result._lit.type = LitType::Decimal;\r
+ result._lit._decimal = atof(ctx->literal()->DECIMAL_LIT()->toString().c_str());\r
}\r
- if (ctx->identifier() != nullptr) {\r
- result.type = ExprType::Variable;\r
- result._variable.name = ctx->identifier()->varName()->NAME()->toString();\r
+ else if (ctx->literal()->STRING_LIT() != nullptr)\r
+ {\r
+ result._lit.type = LitType::String;\r
+ result._lit._string = ctx->literal()->STRING_LIT()->toString();\r
}\r
- if (ctx->memberAccess() != nullptr) {\r
- result.type = ExprType::Dot;\r
- Expr e; e.type = ExprType::Variable; e._variable.name = ctx->memberAccess()->identifier(0)->varName()->NAME()->toString();\r
- result._dot.lexpr = std::make_unique<Expr>(e);\r
- result._dot.name = ctx->memberAccess()->identifier(1)->varName()->NAME()->toString();\r
+ else if (ctx->literal()->BOOL_LIT() != nullptr)\r
+ {\r
+ result._lit.type = LitType::Bool;\r
+ result._lit._bool = ctx->literal()->BOOL_LIT()->toString() == "true";\r
}\r
return result;\r
}\r
-Expr getExpr(TocParser::ExprContext * ctx) {\r
+Expr getExpr(TocParser::ParenExprContext * ctx)\r
+{\r
Expr result;\r
- if (ctx->funcCall() != nullptr) {\r
- result.type = ExprType::Call;\r
- for (auto e : ctx->funcCall()->expr())\r
- result._call.arguments.push_back(getExpr(e));\r
- result._call.functionName = ctx->funcCall()->funcName()->NAME()->toString();\r
- }\r
- if (ctx->literal() != nullptr) {\r
- result.type = ExprType::Literal;\r
- result._literal.i = atoi(ctx->literal()->INTLIT()->toString().c_str());\r
- }\r
- if (ctx->identifier() != nullptr) {\r
- result.type = ExprType::Variable;\r
- result._variable.name = ctx->identifier()->varName()->NAME()->toString();\r
- }\r
- if (ctx->subscript() != nullptr) {\r
- result.type = ExprType::Brackets;\r
- result._brackets.lexpr = std::make_unique<Expr>(getExpr(ctx->subscript()->nonSubscriptExpr()));\r
- result._brackets.rexpr = std::make_unique<Expr>(getExpr(ctx->subscript()->expr()));\r
- }\r
- if (ctx->memberAccess() != nullptr) {\r
- result.type = ExprType::Dot;\r
- Expr e; e.type = ExprType::Variable; e._variable.name = ctx->memberAccess()->identifier(0)->varName()->NAME()->toString();\r
- result._dot.lexpr = std::make_unique<Expr>(e);\r
- result._dot.name = ctx->memberAccess()->identifier(1)->varName()->NAME()->toString();\r
- }\r
- if (ctx->operatorExpr() != nullptr) {\r
- result.type = ExprType::Operator;\r
- result._operator = getOperatorExpr(ctx->operatorExpr());\r
- }\r
+ result.type = ExprType::Paren;\r
+ result._paren.expr = std::make_unique<Expr>(getExpr(ctx->expr()));\r
return result;\r
}\r
-Stmt getStmt(TocParser::StmtContext * ctx) {\r
+Expr getExpr(TocParser::DotExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::Dot;\r
+ result._dot.expr = std::make_unique<Expr>(getExpr(ctx->expr()));\r
+ result._dot.identifier = ctx->varName()->getText();\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::PrefixOpExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::PrefixOp;\r
+ result._prefixOp.expr = std::make_unique<Expr>(getExpr(ctx->expr()));\r
+ result._prefixOp.type = getOperatorType<PrefixOperatorType>(\r
+ ctx->prefix_op()->getText(),\r
+ PrefixOperatorTypeStrings);\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::PostfixOpExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::PostfixOp;\r
+ result._postfixOp.expr = std::make_unique<Expr>(getExpr(ctx->expr()));\r
+ result._postfixOp.type = getOperatorType<PostfixOperatorType>(\r
+ ctx->postfix_op()->getText(),\r
+ PostfixOperatorTypeStrings);\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::BinaryOpExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::BinaryOp;\r
+ result._binaryOp.lexpr = std::make_unique<Expr>(getExpr(ctx->expr(0)));\r
+ result._binaryOp.rexpr = std::make_unique<Expr>(getExpr(ctx->expr(1)));\r
+ result._binaryOp.type = getOperatorType<BinaryOperatorType>(\r
+ ctx->binary_op()->getText(),\r
+ BinaryOperatorTypeStrings);\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::TernaryOpExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::TernaryOp;\r
+ result._ternaryOp.lexpr = std::make_unique<Expr>(getExpr(ctx->expr(0)));\r
+ result._ternaryOp.rexprTrue = std::make_unique<Expr>(getExpr(ctx->expr(1)));\r
+ result._ternaryOp.rexprFalse = std::make_unique<Expr>(getExpr(ctx->expr(2)));\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::BracketExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::Bracket;\r
+ result._brackets.lexpr = std::make_unique<Expr>(getExpr(ctx->expr(0)));\r
+ result._brackets.rexpr = std::make_unique<Expr>(getExpr(ctx->expr(1)));\r
+ return result;\r
+}\r
+Expr getExpr(TocParser::IdentifierExprContext * ctx)\r
+{\r
+ Expr result;\r
+ result.type = ExprType::Identifier;\r
+ for (auto n : ctx->namespaceSpecifier())\r
+ result._identifier.namespacePrefixes.push_back(n->typeName()->getText());\r
+ result._identifier.identifier = ctx->varName()->getText();\r
+ return result;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+Expr getExpr(TocParser::ExprContext * ctx)\r
+{\r
+ Expr result;\r
+ if (dynamic_cast<TocParser::FuncExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::FuncExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::MethodExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::MethodExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::LitExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::LitExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::ParenExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::ParenExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::DotExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::DotExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::PrefixOpExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::PrefixOpExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::PostfixOpExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::PostfixOpExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::BinaryOpExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::BinaryOpExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::TernaryOpExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::TernaryOpExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::BracketExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::BracketExprContext *>(ctx));\r
+ if (dynamic_cast<TocParser::IdentifierExprContext *>(ctx) != nullptr)\r
+ result = getExpr(dynamic_cast<TocParser::IdentifierExprContext *>(ctx));\r
+ return result;\r
+}\r
+Stmt getStmt(TocParser::StmtContext * ctx)\r
+{\r
Stmt result;\r
- if (ctx->conditional() != nullptr) {\r
+ if (ctx->varDecl() != nullptr && ctx->varDecl()->var()->expr() != nullptr)\r
+ {\r
+ result.type = StmtType::Assign;\r
+ result._assign.lexpr.type = ExprType::Identifier;\r
+ result._assign.lexpr._identifier.identifier = ctx->varDecl()->var()->varName()->getText();\r
+ result._assign.rexpr = getExpr(ctx->varDecl()->var()->expr());\r
+ }\r
+ if (ctx->ifStmt() != nullptr)\r
+ {\r
result.type = StmtType::If;\r
- result._if.condition = getExpr(ctx->conditional()->ifCond()->expr());\r
- result._if.body = getBody(ctx->conditional()->ifCond()->body());\r
+ result._if.condition = getExpr(ctx->ifStmt()->expr());\r
+ result._if.body = getBody(ctx->ifStmt()->body());\r
+ for (auto ei : ctx->ifStmt()->elseIfStmt())\r
+ {\r
+ result._if.elses.emplace_back(\r
+ true,\r
+ std::make_unique<Expr>(getExpr(ei->expr())),\r
+ getBody(ei->body())\r
+ );\r
+ }\r
+ if (ctx->ifStmt()->elseStmt() != nullptr)\r
+ {\r
+ result._if.elses.emplace_back(\r
+ false,\r
+ nullptr,\r
+ getBody(ctx->ifStmt()->elseStmt()->body())\r
+ );\r
+ }\r
}\r
- if (ctx->loop() != nullptr) {\r
+ if (ctx->switchStmt() != nullptr)\r
+ {\r
+ result.type = StmtType::Switch;\r
+ result._switch.ident = std::make_unique<Expr>(getExpr(ctx->switchStmt()->expr()));\r
+ for (auto c : ctx->switchStmt()->switchBody()->switchCase())\r
+ {\r
+ result._switch.cases.emplace_back(\r
+ std::make_unique<Expr>(getExpr(c->expr())),\r
+ getBody(c->body())\r
+ );\r
+ }\r
+ }\r
+ if (ctx->forStmt() != nullptr)\r
+ {\r
+ result.type = StmtType::For;\r
+ result._for.init = std::make_unique<AssignStmt>();\r
+ result._for.init->lexpr.type = ExprType::Identifier;\r
+ result._for.init->lexpr._identifier.identifier = ctx->forStmt()->varInit()->varName()->getText();\r
+ result._for.init->rexpr = getExpr(ctx->forStmt()->varInit()->expr());\r
+ result._for.condition = std::make_unique<Expr>(getExpr(ctx->forStmt()->expr(0)));\r
+ result._for.action = std::make_unique<Expr>(getExpr(ctx->forStmt()->expr(1)));\r
+ result._for.body = getBody(ctx->forStmt()->body());\r
+ }\r
+ if (ctx->whileStmt() != nullptr)\r
+ {\r
result.type = StmtType::While;\r
- result._while.condition = getExpr(ctx->loop()->whileLoop()->expr());\r
- result._while.body = getBody(ctx->loop()->whileLoop()->body());\r
+ result._while.condition = getExpr(ctx->whileStmt()->expr());\r
+ result._while.body = getBody(ctx->whileStmt()->body());\r
}\r
- if (ctx->assignment() != nullptr) {\r
+ if (ctx->assignStmt() != nullptr)\r
+ {\r
result.type = StmtType::Assign;\r
- //result._assign.lexpr = getExpr(ctx->assignment()->);\r
- result._assign.rexpr = getExpr(ctx->assignment()->expr());\r
+ result._assign.lexpr = getExpr(ctx->assignStmt()->expr(0));\r
+ result._assign.rexpr = getExpr(ctx->assignStmt()->expr(1));\r
}\r
- if (ctx->returnStmt() != nullptr) {\r
+ if (ctx->returnStmt() != nullptr)\r
+ {\r
result.type = StmtType::Return;\r
result._return.expr = getExpr(ctx->returnStmt()->expr());\r
}\r
- if (ctx->expr() != nullptr) {\r
+ if (ctx->expr() != nullptr)\r
+ {\r
result.type = StmtType::Expr;\r
result._expr = getExpr(ctx->expr());\r
}\r
- if (ctx->varDecl() != nullptr && ctx->varDecl()->var()->expr() != nullptr) {\r
- result.type = StmtType::Assign;\r
- result._assign.rexpr = getExpr(ctx->varDecl()->var()->expr());\r
- }\r
return result;\r
}
\ No newline at end of file