public void atArrayLength(Expr expr) throws CompileError { expr.oprand1().accept(this); if (arrayDim == 0) throw new NoFieldException("length", expr); exprType = INT; arrayDim = 0; }
public void atArrayLength(Expr expr) throws CompileError { expr.oprand1().accept(this); if (arrayDim == 0) throw new NoFieldException("length", expr); exprType = INT; arrayDim = 0; }
private void atArrayAssign(Expr expr, int op, Expr array, ASTree right) throws CompileError { atArrayRead(array.oprand1(), array.oprand2()); int aType = exprType; int aDim = arrayDim; String cname = className; right.accept(this); exprType = aType; arrayDim = aDim; className = cname; }
public void atClassObject(Expr expr) throws CompileError { ASTree op1 = expr.oprand1(); if (!(op1 instanceof Symbol)) throw new CompileError("fatal error: badly parsed .class expr");
private void atArrayAssign(Expr expr, int op, Expr array, ASTree right) throws CompileError { atArrayRead(array.oprand1(), array.oprand2()); int aType = exprType; int aDim = arrayDim; String cname = className; right.accept(this); exprType = aType; arrayDim = aDim; className = cname; }
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); }
/** * 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); }
/** * 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; }
public void atArrayPlusPlus(int token, boolean isPost, Expr expr, boolean doDup) throws CompileError { arrayAccess(expr.oprand1(), expr.oprand2()); int t = exprType; int dim = arrayDim; if (dim > 0) badType(expr); bytecode.addOpcode(DUP2); bytecode.addOpcode(getArrayReadOp(t, arrayDim)); int dup_code = is2word(t, dim) ? DUP2_X2 : DUP_X2; atPlusPlusCore(dup_code, doDup, token, isPost, expr); bytecode.addOpcode(getArrayWriteOp(t, dim)); }
private void atPlusPlus(int token, ASTree oprand, Expr expr) throws CompileError { boolean isPost = oprand == null; // ++i or i++? if (isPost) oprand = expr.oprand2(); if (oprand instanceof Variable) { Declarator d = ((Variable)oprand).getDeclarator(); exprType = d.getType(); arrayDim = d.getArrayDim(); } else { if (oprand instanceof Expr) { Expr e = (Expr)oprand; if (e.getOperator() == ARRAY) { atArrayRead(e.oprand1(), e.oprand2()); // arrayDim should be 0. int t = exprType; if (t == INT || t == BYTE || t == CHAR || t == SHORT) exprType = INT; return; } } atFieldPlusPlus(oprand); } }
ASTree oprand = expr.oprand1(); if (token == '.') { String member = ((Symbol)expr.oprand2()).get();
private void atArrayAssign(Expr expr, int op, Expr array, ASTree right, boolean doDup) throws CompileError { arrayAccess(array.oprand1(), array.oprand2()); if (op != '=') { bytecode.addOpcode(DUP2); bytecode.addOpcode(getArrayReadOp(exprType, arrayDim)); } int aType = exprType; int aDim = arrayDim; String cname = className; atAssignCore(expr, op, right, aType, aDim, cname); if (doDup) if (is2word(aType, aDim)) bytecode.addOpcode(DUP2_X2); else bytecode.addOpcode(DUP_X2); bytecode.addOpcode(getArrayWriteOp(aType, aDim)); exprType = aType; arrayDim = aDim; className = cname; }
public void atArrayPlusPlus(int token, boolean isPost, Expr expr, boolean doDup) throws CompileError { arrayAccess(expr.oprand1(), expr.oprand2()); int t = exprType; int dim = arrayDim; if (dim > 0) badType(expr); bytecode.addOpcode(DUP2); bytecode.addOpcode(getArrayReadOp(t, arrayDim)); int dup_code = is2word(t, dim) ? DUP2_X2 : DUP_X2; atPlusPlusCore(dup_code, doDup, token, isPost, expr); bytecode.addOpcode(getArrayWriteOp(t, dim)); }
private void booleanExpr(ASTree expr) throws CompileError { int op = CodeGen.getCompOperator(expr); if (op == EQ) { // ==, !=, ... BinExpr bexpr = (BinExpr)expr; bexpr.oprand1().accept(this); int type1 = exprType; int dim1 = arrayDim; bexpr.oprand2().accept(this); if (dim1 == 0 && arrayDim == 0) insertCast(bexpr, type1, exprType); } else if (op == '!') ((Expr)expr).oprand1().accept(this); else if (op == ANDAND || op == OROR) { BinExpr bexpr = (BinExpr)expr; bexpr.oprand1().accept(this); bexpr.oprand2().accept(this); } else // others expr.accept(this); exprType = BOOLEAN; arrayDim = 0; }
private void atArrayAssign(Expr expr, int op, Expr array, ASTree right, boolean doDup) throws CompileError { arrayAccess(array.oprand1(), array.oprand2()); if (op != '=') { bytecode.addOpcode(DUP2); bytecode.addOpcode(getArrayReadOp(exprType, arrayDim)); } int aType = exprType; int aDim = arrayDim; String cname = className; atAssignCore(expr, op, right, aType, aDim, cname); if (doDup) if (is2word(aType, aDim)) bytecode.addOpcode(DUP2_X2); else bytecode.addOpcode(DUP_X2); bytecode.addOpcode(getArrayWriteOp(aType, aDim)); exprType = aType; arrayDim = aDim; className = cname; }
return booleanExpr(!branchIf, ((Expr)expr).oprand1()); else if ((isAndAnd = (op == ANDAND)) || op == OROR) { BinExpr bexpr = (BinExpr)expr;