- 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
+ result.parenthesized = false;\r
+ if (ctx->funcExpr() != nullptr)\r
+ {\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
+ {\r
+ result.type = ExprType::Lit;\r
+ if (ctx->litExpr()->INT_LIT() != nullptr)\r
+ {\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
+ {\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
+ {\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
+ {\r
+ result._lit.type = LitType::Bool;\r
+ result._lit._bool = ctx->litExpr()->BOOL_LIT()->toString() == "true";\r
+ }\r
+ }\r
+ if (ctx->identifierExpr() != nullptr)\r
+ {\r
+ result.type = ExprType::Identifier;\r
+ result._identifier.name = ctx->identifierExpr()->varName()->NAME()->toString();\r
+ }\r
+ if (ctx->parenExpr() != nullptr)\r
+ {\r
+ result = getExpr(ctx->parenExpr()->expr());\r
+ result.parenthesized = true;\r
+ }\r
+ if (ctx->accessExpr() != nullptr)\r
+ {\r
+ auto firstSub = ctx->accessExpr()->accessSubExpr(0);\r
+ if (firstSub->accessMember() != nullptr)\r
+ {\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
+ {\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
+ {\r
+ Expr tmp = result;\r
+ auto sub = ctx->accessExpr()->accessSubExpr(i);\r
+ if (sub->accessMember() != nullptr)\r
+ {\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
+ {\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
+ {\r
+ if (ctx->opExpr()->prefixOp() != nullptr || ctx->opExpr()->postfixOp() != nullptr)\r
+ {\r
+ result.type = ExprType::UnaryOperator;\r
+ result._unaryOperator = getUnaryOperatorExpr(ctx->opExpr());\r
+ }\r
+ else if (ctx->opExpr()->binaryOp() != nullptr)\r
+ {\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
+ {\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
+ {\r
+ result.type = ExprType::TernaryOperator;\r
+ result._ternaryOperator = getTernaryOperatorExpr(ctx->opExpr());\r
+ }\r