use of kalang.ast.AstNode 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.AstNode in project kalang by kasonyang.
the class AstBuilder method visitIdentifierExpr.
@Override
public AstNode visitIdentifierExpr(IdentifierExprContext ctx) {
String name = ctx.Identifier().getText();
AstNode expr = this.getNodeById(name, ctx.Identifier().getSymbol());
if (expr == null) {
this.handleSyntaxError(name + " is undefined!", ctx);
return null;
}
mapAst(expr, ctx);
return expr;
}
use of kalang.ast.AstNode in project kalang by kasonyang.
the class AstOutputUtil method toString.
public static String toString(AstNode node) {
if (node == null)
return "null";
String nodeStr = node.toString();
StringBuilder sb = new StringBuilder();
sb.append(nodeStr).append(":");
for (AstNode c : node.getChildren()) {
sb.append(LINE_DELIMITER);
String cStr = toString(c);
sb.append(StringUtil.indentLines(cStr, INDENT, LINE_DELIMITER));
}
return sb.toString();
}
use of kalang.ast.AstNode in project kalang by kasonyang.
the class AstBuilder method visitSelfRefExpr.
@Override
public AstNode visitSelfRefExpr(SelfRefExprContext ctx) {
String key = ctx.ref.getText();
AstNode expr;
if (key.equals("this")) {
expr = new ThisExpr(getThisType());
} else if (key.equals("super")) {
expr = new SuperExpr(thisClazz);
} else {
throw Exceptions.unknownValue(key);
}
mapAst(expr, ctx);
return expr;
}
use of kalang.ast.AstNode in project kalang by kasonyang.
the class AstBuilder method visitExpression.
protected ExprNode visitExpression(ExpressionContext expression) {
Object node = visit(expression);
if (node instanceof ExprNode) {
return (ExprNode) node;
} else {
ExprNode expr;
if (node instanceof AstNode) {
expr = new ErrorousExpr((AstNode) node);
} else {
expr = new ErrorousExpr();
}
this.diagnosisReporter.report(Diagnosis.Kind.ERROR, "not an expression", expression);
return expr;
}
}
Aggregations