- 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
+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
+ result._dot.isPointer = ctx->arrow() != nullptr;\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