use of kalang.antlr.KalangParser.ExpressionContext in project kalang by kasonyang.
the class AstBuilder method visitArrayExpr.
@Override
public Object visitArrayExpr(KalangParser.ArrayExprContext ctx) {
ExprNode[] initExprs;
List<ExpressionContext> exprCtx = ctx.expression();
if (exprCtx != null) {
initExprs = new ExprNode[exprCtx.size()];
for (int i = 0; i < initExprs.length; i++) {
initExprs[i] = visitExpression(exprCtx.get(i));
}
} else {
initExprs = new ExprNode[0];
}
TypeContext typeCtx = ctx.type();
Type type;
if (typeCtx != null) {
type = parseType(typeCtx);
} else {
type = TypeUtil.getCommonType(AstUtil.getExprTypes(initExprs));
}
for (int i = 0; i < initExprs.length; i++) {
if (exprCtx == null)
throw Exceptions.unexceptedValue(exprCtx);
initExprs[i] = requireCastable(initExprs[i], initExprs[i].getType(), type, exprCtx.get(i).getStart());
if (initExprs[i] == null)
return null;
}
ExprNode arrExpr = createInitializedArray(type, initExprs);
mapAst(arrExpr, ctx);
return arrExpr;
}
use of kalang.antlr.KalangParser.ExpressionContext in project kalang by kasonyang.
the class AstBuilder method visitExpressions.
@Override
public List<Statement> visitExpressions(ExpressionsContext ctx) {
List<Statement> list = new LinkedList();
for (ExpressionContext e : ctx.expression()) {
ExprNode expr = visitExpression(e);
list.add(new ExprStmt(expr));
}
return list;
}
Aggregations