use of kalang.antlr.KalangParser.LiteralExprContext in project kalang by kasonyang.
the class AstBuilder method visitLocalVarDecl.
@Override
public Statement visitLocalVarDecl(LocalVarDeclContext ctx) {
MultiStmt ms = new MultiStmt();
for (VarDeclContext v : ctx.varDecl()) {
TypeContext varType = v.varType;
Type exceptedType = varType == null ? null : parseType(varType);
ExprNode initExpr = null;
ExpressionContext initExprContext = v.expression();
if (initExprContext != null) {
if (initExprContext instanceof LiteralExprContext) {
initExpr = this.parseLiteral(((LiteralExprContext) initExprContext).literal(), exceptedType);
} else {
initExpr = visitExpression(initExprContext);
}
}
VarInfo varInfo = varDecl(v, initExpr == null ? Types.getRootType() : initExpr.getType());
LocalVarNode localVar = this.declareLocalVar(varInfo.name, varInfo.type, varInfo.modifier, ctx);
if (localVar == null)
return null;
VarDeclStmt vds = new VarDeclStmt(localVar);
ms.statements.add(vds);
if (initExpr != null) {
AssignExpr assignExpr = new AssignExpr(new VarExpr(localVar), initExpr);
mapAst(assignExpr, v);
ms.statements.add(new ExprStmt(assignExpr));
}
mapAst(localVar, ctx);
}
return ms;
}
Aggregations