Search in sources :

Example 1 with ReturnStmt

use of kalang.ast.ReturnStmt in project kalang by kasonyang.

the class AstBuilder method visitReturnStat.

@Override
public AstNode visitReturnStat(ReturnStatContext ctx) {
    ReturnStmt rs = new ReturnStmt();
    mapAst(rs, ctx);
    if (ctx.expression() != null) {
        rs.expr = visitExpression(ctx.expression());
    }
    if (!semanticAnalyzer.validateReturnStmt(method, rs))
        return null;
    this.returned = true;
    return rs;
}
Also used : ReturnStmt(kalang.ast.ReturnStmt)

Example 2 with ReturnStmt

use of kalang.ast.ReturnStmt in project kalang by kasonyang.

the class AstUtil method createGetter.

public static void createGetter(ClassNode clazz, FieldDescriptor field, int accessModifier) {
    String fn = field.getName();
    String getterName = "get" + NameUtil.firstCharToUpperCase(fn);
    boolean isStatic = isStatic(field.getModifier());
    if (isStatic) {
        accessModifier |= Modifier.STATIC;
    }
    MethodNode getter = clazz.createMethodNode(field.getType(), getterName, accessModifier);
    // getter.offset = field.offset;
    BlockStmt body = getter.getBody();
    FieldExpr fe;
    ClassReference cr = new ClassReference(clazz);
    if (isStatic) {
        fe = new StaticFieldExpr(cr, field);
    } else {
        fe = new ObjectFieldExpr(new ThisExpr(Types.getClassType(clazz)), field);
    }
    body.statements.add(new ReturnStmt(fe));
}
Also used : StaticFieldExpr(kalang.ast.StaticFieldExpr) ObjectFieldExpr(kalang.ast.ObjectFieldExpr) MethodNode(kalang.ast.MethodNode) BlockStmt(kalang.ast.BlockStmt) ClassReference(kalang.ast.ClassReference) StaticFieldExpr(kalang.ast.StaticFieldExpr) FieldExpr(kalang.ast.FieldExpr) ObjectFieldExpr(kalang.ast.ObjectFieldExpr) ReturnStmt(kalang.ast.ReturnStmt) ThisExpr(kalang.ast.ThisExpr)

Aggregations

ReturnStmt (kalang.ast.ReturnStmt)2 BlockStmt (kalang.ast.BlockStmt)1 ClassReference (kalang.ast.ClassReference)1 FieldExpr (kalang.ast.FieldExpr)1 MethodNode (kalang.ast.MethodNode)1 ObjectFieldExpr (kalang.ast.ObjectFieldExpr)1 StaticFieldExpr (kalang.ast.StaticFieldExpr)1 ThisExpr (kalang.ast.ThisExpr)1