- result.parenthesized = false;\r
- if (ctx->funcExpr() != nullptr) {\r
- result.type = ExprType::Func;\r
- result._func.functionName = ctx->funcExpr()->funcName()->NAME()->toString();\r
- for (auto e : ctx->funcExpr()->expr())\r
- result._func.arguments.push_back(getExpr(e));\r
- }\r
- if (ctx->litExpr() != nullptr) {\r
- result.type = ExprType::Lit;\r
- if (ctx->litExpr()->INT_LIT() != nullptr) {\r
- result._lit.type = LitType::Int;\r
- result._lit._int = atoi(ctx->litExpr()->INT_LIT()->toString().c_str());\r
- }\r
- else if (ctx->litExpr()->DECIMAL_LIT() != nullptr) {\r
- result._lit.type = LitType::Decimal;\r
- result._lit._decimal = atof(ctx->litExpr()->DECIMAL_LIT()->toString().c_str());\r
- }\r
- else if (ctx->litExpr()->STRING_LIT() != nullptr) {\r
- result._lit.type = LitType::String;\r
- result._lit._string = ctx->litExpr()->STRING_LIT()->toString();\r
- }\r
- else if (ctx->litExpr()->BOOL_LIT() != nullptr) {\r
- result._lit.type = LitType::Bool;\r
- result._lit._bool = ctx->litExpr()->BOOL_LIT()->toString() == "true";\r
- }\r
- }\r
- if (ctx->identifierExpr() != nullptr) {\r
- result.type = ExprType::Identifier;\r
- result._identifier.name = ctx->identifierExpr()->varName()->NAME()->toString();\r
- }\r
- if (ctx->parenExpr() != nullptr) {\r
- result = getExpr(ctx->parenExpr()->expr());\r
- result.parenthesized = true;\r
- }\r
- if (ctx->accessExpr() != nullptr) {\r
- auto firstSub = ctx->accessExpr()->accessSubExpr(0);\r
- if (firstSub->accessMember() != nullptr) {\r
- result.type = ExprType::Dot;\r
- result._dot.expr = std::make_unique<Expr>(getExpr(ctx->accessExpr()->nonAccessExpr()));\r
- result._dot.ident.name = firstSub->accessMember()->identifierExpr()->varName()->NAME()->toString();\r
- }\r
- else {\r
- result.type = ExprType::Brackets;\r
- result._brackets.lexpr = std::make_unique<Expr>(getExpr(ctx->accessExpr()->nonAccessExpr()));\r
- result._brackets.rexpr = std::make_unique<Expr>(getExpr(firstSub->accessBrackets()->expr()));\r
- }\r
- for (int i = 1; i < ctx->accessExpr()->accessSubExpr().size(); i++) {\r
- Expr tmp = result;\r
- auto sub = ctx->accessExpr()->accessSubExpr(i);\r
- if (sub->accessMember() != nullptr) {\r
- result.type = ExprType::Dot;\r
- result._dot.expr = std::make_unique<Expr>(tmp);\r
- result._dot.ident.name = sub->accessMember()->identifierExpr()->varName()->NAME()->toString();\r
- }\r
- else {\r
- result.type = ExprType::Brackets;\r
- result._brackets.lexpr = std::make_unique<Expr>(tmp);\r
- result._brackets.rexpr = std::make_unique<Expr>(getExpr(sub->accessBrackets()->expr()));\r
- }\r
- }\r
- }\r
- if (ctx->opExpr() != nullptr) {\r
- if (ctx->opExpr()->prefixOp() != nullptr || ctx->opExpr()->postfixOp() != nullptr) {\r
- result.type = ExprType::UnaryOperator;\r
- result._unaryOperator = getUnaryOperatorExpr(ctx->opExpr());\r
- }\r
- else if (ctx->opExpr()->binaryOp() != nullptr) {\r
- result.type = ExprType::BinaryOperator;\r
- result._binaryOperator = getBinaryOperatorExpr(ctx->opExpr());\r
- for (int i = 1; i < ctx->opExpr()->binaryOp()->binary_op().size(); i++) {\r
- Expr tmp = result;\r
- result._binaryOperator.lexpr = std::make_unique<Expr>(tmp);\r
- result._binaryOperator.type = getBinaryOperatorType(ctx->opExpr()->binaryOp()->binary_op(i)->getText());\r
- result._binaryOperator.rexpr = std::make_unique<Expr>(getExpr(ctx->opExpr()->binaryOp()->nonOpExpr(i+1)));\r
- }\r
- }\r
- else if (ctx->opExpr()->ternaryOp() != nullptr) {\r
- result.type = ExprType::TernaryOperator;\r
- result._ternaryOperator = getTernaryOperatorExpr(ctx->opExpr());\r
- }\r
- }\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