use of kalang.ast.BinaryExpr in project kalang by kasonyang.
the class Ast2Class method visitIncrementExpr.
@Override
public Object visitIncrementExpr(IncrementExpr node) {
if (!node.isIsPrefix()) {
visit(node.getExpr());
}
Type exprType = node.getExpr().getType();
ConstExpr ce = getConstX(exprType, node.isIsDesc() ? -1 : 1);
BinaryExpr be = new MathExpr(node.getExpr(), ce, "+");
AssignExpr addOne = new AssignExpr(node.getExpr(), be);
visit(addOne);
pop(exprType);
if (node.isIsPrefix()) {
visit(node.getExpr());
}
return null;
}
use of kalang.ast.BinaryExpr in project kalang by kasonyang.
the class AstBuilder method visitPostIfStmt.
@Override
public AstNode visitPostIfStmt(KalangParser.PostIfStmtContext ctx) {
ExprNode leftExpr = visitExpression(ctx.expression(0));
if (!(leftExpr instanceof AssignExpr)) {
diagnosisReporter.report(Diagnosis.Kind.ERROR, "AssignExpr required", ctx);
}
AssignExpr assignExpr = (AssignExpr) leftExpr;
AssignableExpr to = assignExpr.getTo();
ExprNode from = assignExpr.getFrom();
ExprNode cond = visitExpression(ctx.expression(1));
Token op = ctx.op;
if (op != null) {
String opStr = op.getText();
BinaryExpr be = createBinaryExpr(to, cond, opStr);
cond = be;
}
AssignExpr as = new AssignExpr(to, from);
IfStmt is = new IfStmt(cond);
is.getTrueBody().statements.add(new ExprStmt(as));
mapAst(is, ctx);
return is;
}
use of kalang.ast.BinaryExpr in project kalang by kasonyang.
the class AstBuilder method createBinaryExpr.
private BinaryExpr createBinaryExpr(ExprNode expr1, ExprNode expr2, String op) {
BinaryExpr binExpr;
switch(op) {
case "==":
case "!=":
case ">":
case ">=":
case "<":
case "<=":
binExpr = new CompareExpr(expr1, expr2, op);
break;
case "&&":
case "||":
binExpr = new LogicExpr(expr1, expr2, op);
break;
default:
binExpr = new MathExpr(expr1, expr2, op);
break;
}
semanticAnalyzer.validateBinaryExpr(binExpr);
return binExpr;
}
Aggregations