/** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); }
public boolean isConstructor() { Symbol sym = getReturn().getVariable(); return sym != null && initName.equals(sym.get()); }
private static void astToClassName(StringBuffer sbuf, ASTList name, char sep) { for (;;) { ASTree h = name.head(); if (h instanceof Symbol) sbuf.append(((Symbol)h).get()); else if (h instanceof ASTList) astToClassName(sbuf, (ASTList)h, sep); name = name.tail(); if (name == null) break; sbuf.append(sep); } } }
/** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); }
public boolean isConstructor() { Symbol sym = getReturn().getVariable(); return sym != null && initName.equals(sym.get()); }
private static void astToClassName(StringBuffer sbuf, ASTList name, char sep) { for (;;) { ASTree h = name.head(); if (h instanceof Symbol) sbuf.append(((Symbol)h).get()); else if (h instanceof ASTList) astToClassName(sbuf, (ASTList)h, sep); name = name.tail(); if (name == null) break; sbuf.append(sep); } } }
throw new CompileError("fatal error: badly parsed .class expr"); String cname = ((Symbol)op1).get(); if (cname.startsWith("[")) { int i = cname.indexOf("[L");
private void toClassName(ASTree name, StringBuffer sbuf) throws CompileError { if (name instanceof Symbol) { sbuf.append(((Symbol)name).get()); return; } else if (name instanceof Expr) { Expr expr = (Expr)name; if (expr.getOperator() == '.') { toClassName(expr.oprand1(), sbuf); sbuf.append('.'); toClassName(expr.oprand2(), sbuf); return; } } throw new CompileError("bad static member access", lex); }
private static void makeCflowName(StringBuffer sbuf, ASTree name) throws CompileError { if (name instanceof Symbol) { sbuf.append(((Symbol)name).get()); return; } else if (name instanceof Expr) { Expr expr = (Expr)name; if (expr.getOperator() == '.') { makeCflowName(sbuf, expr.oprand1()); sbuf.append('.'); makeCflowName(sbuf, expr.oprand2()); return; } } throw new CompileError("bad " + cflowName); }
public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(codeGen.returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(JvstCodeGen.wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
/** * Returns non-null if target is something like Foo.super * for accessing the default method in an interface. * Otherwise, null. * * @return the class name followed by {@code .super} or null. */ static String isDotSuper(ASTree target) { if (target instanceof Expr) { Expr e = (Expr)target; if (e.getOperator() == '.') { ASTree right = e.oprand2(); if (right instanceof Keyword && ((Keyword)right).get() == SUPER) return ((Symbol)e.oprand1()).get(); } } return null; }
private static void makeCflowName(StringBuffer sbuf, ASTree name) throws CompileError { if (name instanceof Symbol) { sbuf.append(((Symbol)name).get()); return; } else if (name instanceof Expr) { Expr expr = (Expr)name; if (expr.getOperator() == '.') { makeCflowName(sbuf, expr.oprand1()); sbuf.append('.'); makeCflowName(sbuf, expr.oprand2()); return; } } throw new CompileError("bad " + cflowName); }
private void toClassName(ASTree name, StringBuffer sbuf) throws CompileError { if (name instanceof Symbol) { sbuf.append(((Symbol)name).get()); return; } else if (name instanceof Expr) { Expr expr = (Expr)name; if (expr.getOperator() == '.') { toClassName(expr.oprand1(), sbuf); sbuf.append('.'); toClassName(expr.oprand2(), sbuf); return; } } throw new CompileError("bad static member access", lex); }
/** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } }
@Override public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(codeGen.returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(JvstCodeGen.wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
/** * Returns non-null if target is something like Foo.super * for accessing the default method in an interface. * Otherwise, null. * * @return the class name followed by {@code .super} or null. */ static String isDotSuper(ASTree target) { if (target instanceof Expr) { Expr e = (Expr)target; if (e.getOperator() == '.') { ASTree right = e.oprand2(); if (right instanceof Keyword && ((Keyword)right).get() == SUPER) return ((Symbol)e.oprand1()).get(); } } return null; }
@Override public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
private CtField compileField(FieldDecl fd) throws CompileError, CannotCompileException { CtFieldWithInit f; Declarator d = fd.getDeclarator(); f = new CtFieldWithInit(gen.resolver.lookupClass(d), d.getVariable().get(), gen.getThisClass()); f.setModifiers(MemberResolver.getModifiers(fd.getModifiers())); if (fd.getInit() != null) f.setInit(fd.getInit()); return f; }
private CtField compileField(FieldDecl fd) throws CompileError, CannotCompileException { CtFieldWithInit f; Declarator d = fd.getDeclarator(); f = new CtFieldWithInit(gen.resolver.lookupClass(d), d.getVariable().get(), gen.getThisClass()); f.setModifiers(MemberResolver.getModifiers(fd.getModifiers())); if (fd.getInit() != null) f.setInit(fd.getInit()); return f; }