public static Expr make(int op, ASTree oprand1) { return new Expr(op, oprand1); }
static ASTree stripPlusExpr(ASTree expr) { if (expr instanceof BinExpr) { BinExpr e = (BinExpr)expr; if (e.getOperator() == '+' && e.oprand2() == null) return e.getLeft(); } else if (expr instanceof Expr) { // note: BinExpr extends Expr. Expr e = (Expr)expr; int op = e.getOperator(); if (op == MEMBER) { ASTree cexpr = getConstantFieldValue((Member)e.oprand2()); if (cexpr != null) return cexpr; } else if (op == '+' && e.getRight() == null) return e.getLeft(); } else if (expr instanceof Member) { ASTree cexpr = getConstantFieldValue((Member)expr); if (cexpr != null) return cexpr; } return 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 CtField fieldAccess2(Expr e, String jvmClassName) throws CompileError { Member fname = (Member)e.oprand2(); CtField f = resolver.lookupFieldByJvmName2(jvmClassName, fname, e); e.setOperator(MEMBER); e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(jvmClassName))); fname.setField(f); return f; }
private boolean needsSuperCall(Stmnt body) throws CompileError { if (body.getOperator() == BLOCK) body = (Stmnt)body.head(); if (body != null && body.getOperator() == EXPR) { ASTree expr = body.head(); if (expr != null && expr instanceof Expr && ((Expr)expr).getOperator() == CALL) { ASTree target = ((Expr)expr).head(); if (target instanceof Keyword) { int token = ((Keyword)target).get(); return token != THIS && token != SUPER; } } } return true; }
protected String getTag() { return "op:" + getName(); } }
private ASTree parseDotClass(ASTree className, int dim) throws CompileError { String cname = toClassName(className); if (dim > 0) { StringBuffer sbuf = new StringBuffer(); while (dim-- > 0) sbuf.append('['); sbuf.append('L').append(cname.replace('.', '/')).append(';'); cname = sbuf.toString(); } return Expr.make('.', new Symbol(cname), new Member("class")); }
public void setOprand2(ASTree expr) { getRight().setLeft(expr); }
private static boolean isPlusPlusExpr(ASTree expr) { if (expr instanceof Expr) { int op = ((Expr)expr).getOperator(); return op == PLUSPLUS || op == MINUSMINUS; } return false; }
public ASTree oprand1() { return getLeft(); }
public void atArrayLength(Expr expr) throws CompileError { expr.oprand1().accept(this); if (arrayDim == 0) throw new NoFieldException("length", expr); exprType = INT; arrayDim = 0; }
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 boolean needsSuperCall(Stmnt body) throws CompileError { if (body.getOperator() == BLOCK) body = (Stmnt)body.head(); if (body != null && body.getOperator() == EXPR) { ASTree expr = body.head(); if (expr != null && expr instanceof Expr && ((Expr)expr).getOperator() == CALL) { ASTree target = ((Expr)expr).head(); if (target instanceof Keyword) { int token = ((Keyword)target).get(); return token != THIS && token != SUPER; } } } return true; }
private CtField fieldAccess2(Expr e, String jvmClassName) throws CompileError { Member fname = (Member)e.oprand2(); CtField f = resolver.lookupFieldByJvmName2(jvmClassName, fname, e); e.setOperator(MEMBER); e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(jvmClassName))); fname.setField(f); return f; }
@Override protected String getTag() { return "op:" + getName(); } }
private ASTree parseDotClass(ASTree className, int dim) throws CompileError { String cname = toClassName(className); if (dim > 0) { StringBuffer sbuf = new StringBuffer(); while (dim-- > 0) sbuf.append('['); sbuf.append('L').append(cname.replace('.', '/')).append(';'); cname = sbuf.toString(); } return Expr.make('.', new Symbol(cname), new Member("class")); }
public ASTree oprand2() { return getRight().getLeft(); }