use of kalang.antlr.KalangParser.GetFieldExprContext in project kalang by kasonyang.
the class AstBuilder method visitAssignExpr.
@Override
public ExprNode visitAssignExpr(AssignExprContext ctx) {
ExprNode expr;
String assignOp = ctx.getChild(1).getText();
ExpressionContext toCtx = ctx.expression(0);
ExpressionContext fromCtx = ctx.expression(1);
if (toCtx instanceof GetFieldExprContext) {
// TODO check readonly
expr = createFieldExpr((GetFieldExprContext) toCtx, fromCtx, OffsetRangeHelper.getOffsetRange(ctx));
} else {
ExprNode to = visitExpression(toCtx);
ExprNode from = visitExpression(fromCtx);
if (assignOp.length() > 1) {
String op = assignOp.substring(0, assignOp.length() - 1);
from = createBinaryExpr(to, from, op);
}
AssignableExpr toExpr;
if (to instanceof AssignableExpr) {
toExpr = (AssignableExpr) to;
if (!this.semanticAnalyzer.validateAssign(toExpr, from, OffsetRangeHelper.getOffsetRange(ctx))) {
return null;
}
AssignExpr aexpr = new AssignExpr(toExpr, from);
mapAst(aexpr, ctx);
// TODO remove override information before assign
onAssign(toExpr, from);
expr = aexpr;
} else {
AstBuilder.this.handleSyntaxError("unsupported assign statement", ctx);
return null;
}
}
return expr;
}
Aggregations