Search in sources :

Example 1 with BlockStmt

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;
}
Also used : ObjectType(kalang.core.ObjectType) ParameterNode(kalang.ast.ParameterNode) BlockStmt(kalang.ast.BlockStmt) Label(org.objectweb.asm.Label) AstNotFoundException(kalang.AstNotFoundException)

Example 2 with BlockStmt

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;
}
Also used : BlockStmt(kalang.ast.BlockStmt)

Example 3 with BlockStmt

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;
}
Also used : ExprNode(kalang.ast.ExprNode) LoopStmt(kalang.ast.LoopStmt) BlockStmt(kalang.ast.BlockStmt)

Example 4 with BlockStmt

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;
}
Also used : BlockStmt(kalang.ast.BlockStmt)

Example 5 with BlockStmt

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;
}
Also used : BlockStmt(kalang.ast.BlockStmt)

Aggregations

BlockStmt (kalang.ast.BlockStmt)20 ExprNode (kalang.ast.ExprNode)10 ObjectType (kalang.core.ObjectType)7 ExprStmt (kalang.ast.ExprStmt)6 MethodNode (kalang.ast.MethodNode)6 GenericType (kalang.core.GenericType)6 LoopStmt (kalang.ast.LoopStmt)5 ParameterNode (kalang.ast.ParameterNode)5 ArrayType (kalang.core.ArrayType)5 ClassType (kalang.core.ClassType)5 Type (kalang.core.Type)5 AmbiguousMethodException (kalang.AmbiguousMethodException)4 MethodNotFoundException (kalang.MethodNotFoundException)4 AssignExpr (kalang.ast.AssignExpr)4 ParameterExpr (kalang.ast.ParameterExpr)4 ClassNode (kalang.ast.ClassNode)3 ClassReference (kalang.ast.ClassReference)3 Statement (kalang.ast.Statement)3 ThisExpr (kalang.ast.ThisExpr)3 LinkedList (java.util.LinkedList)2