use of kalang.ast.BlockStmt in project kalang by kasonyang.
the class Ast2Class method visitMethodNode.
@Override
public Object visitMethodNode(MethodNode node) {
int access = node.getModifier();
md = classWriter.visitMethod(access, internalName(node.getName()), getMethodDescriptor(node), methodSignature(node), internalName(node.getExceptionTypes()));
if (node.getType() instanceof ObjectType) {
annotationNullable(md, (ObjectType) node.getType());
}
annotation(md, node.getAnnotations());
this.methodStartLabel = new Label();
this.methodEndLabel = new Label();
if (AstUtil.isStatic(node.getModifier())) {
varIdCounter = 0;
} else {
varIdCounter = 1;
}
BlockStmt body = node.getBody();
ParameterNode[] parameters = node.getParameters();
for (int i = 0; i < parameters.length; i++) {
ParameterNode p = parameters[i];
visit(p);
if (p.getType() instanceof ObjectType) {
md.visitParameterAnnotation(i, getClassDescriptor(getNullableAnnotation((ObjectType) p.getType())), true).visitEnd();
}
}
md.visitLabel(methodStartLabel);
if (body != null) {
visit(body);
if (node.getType().equals(VOID_TYPE)) {
md.visitInsn(RETURN);
}
md.visitLabel(methodEndLabel);
try {
md.visitMaxs(0, 0);
} catch (Exception ex) {
ex.printStackTrace(System.err);
// throw new RuntimeException("exception when visit method:" + node.name, ex);
}
}
md.visitEnd();
return null;
}
use of kalang.ast.BlockStmt in project kalang by kasonyang.
the class AstBuilder method wrapBlock.
BlockStmt wrapBlock(Statement... statms) {
BlockStmt bs = newBlock();
bs.statements.addAll(Arrays.asList(statms));
popBlock();
return bs;
}
use of kalang.ast.BlockStmt in project kalang by kasonyang.
the class AstBuilder method visitWhileStat.
@Override
public AstNode visitWhileStat(WhileStatContext ctx) {
ExprNode preConditionExpr = visitExpression(ctx.expression());
BlockStmt loopBody = null;
if (ctx.stat() != null) {
loopBody = requireBlock(ctx.stat());
}
LoopStmt ws = new LoopStmt(preConditionExpr, null, loopBody, null);
mapAst(ws, ctx);
return ws;
}
use of kalang.ast.BlockStmt in project kalang by kasonyang.
the class AstBuilder method newBlock.
BlockStmt newBlock() {
BlockStmt bs = new BlockStmt();
this.newFrame();
return bs;
}
use of kalang.ast.BlockStmt in project kalang by kasonyang.
the class AstBuilder method visitEmptyStat.
@Override
public Object visitEmptyStat(KalangParser.EmptyStatContext ctx) {
BlockStmt b = this.newBlock();
this.popBlock();
return b;
}
Aggregations