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;
}
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));
}
Aggregations