use of kalang.ast.InstanceOfExpr in project kalang by kasonyang.
the class AstBuilder method visitInstanceofExpr.
@Override
public Object visitInstanceofExpr(KalangParser.InstanceofExprContext ctx) {
ExprNode expr = visitExpression(ctx.expression());
Token ts = ctx.Identifier().getSymbol();
AstNode tnode = getNodeById(ts.getText(), ts);
if (tnode instanceof ClassReference) {
InstanceOfExpr ie = new InstanceOfExpr(expr, (ClassReference) tnode);
mapAst(ie, ctx);
return ie;
} else {
AstBuilder.this.handleSyntaxError("unsupported type", ts);
return null;
}
}
use of kalang.ast.InstanceOfExpr in project kalang by kasonyang.
the class AstBuilder method onIf.
protected void onIf(ExprNode expr, boolean onTrue) {
if (expr instanceof InstanceOfExpr && onTrue) {
InstanceOfExpr ie = (InstanceOfExpr) expr;
changeTypeTemporarilyIfCould(ie.getExpr(), Types.getClassType(ie.getTarget().getReferencedClassNode()));
}
if (expr instanceof CompareExpr) {
CompareExpr ce = (CompareExpr) expr;
ExprNode e1 = ce.getExpr1();
ExprNode e2 = ce.getExpr2();
boolean isEQ = ce.getOperation().equals(CompareExpr.OP_EQ);
if (e1.getType().equals(Types.NULL_TYPE)) {
onNull(e2, onTrue, isEQ);
} else if (e2.getType().equals(Types.NULL_TYPE)) {
onNull(e1, onTrue, isEQ);
}
}
if (expr instanceof UnaryExpr) {
onIf(((UnaryExpr) expr).getExpr(), !onTrue);
}
if (expr instanceof LogicExpr) {
LogicExpr le = (LogicExpr) expr;
if (le.getOperation().equals(LogicExpr.OP_LOGIC_AND)) {
if (onTrue) {
onIf(le.getExpr1(), true);
onIf(le.getExpr2(), true);
}
} else if (le.getOperation().equals(LogicExpr.OP_LOGIC_OR)) {
if (!onTrue) {
onIf(le.getExpr1(), false);
onIf(le.getExpr2(), false);
}
}
}
}
Aggregations