public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2) { return new BinExpr(op, oprand1, new ASTList(oprand2)); }
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; }
private ASTree binaryExpr2(SymbolTable tbl, ASTree expr, int prec) throws CompileError { int t = lex.get(); if (t == INSTANCEOF) return parseInstanceOf(tbl, expr); ASTree expr2 = parseUnaryExpr(tbl); for (;;) { int t2 = lex.lookAhead(); int p2 = getOpPrecedence(t2); if (p2 != 0 && prec > p2) expr2 = binaryExpr2(tbl, expr2, p2); else return BinExpr.makeBin(t, expr, expr2); } }
private int compileOprands(BinExpr expr) throws CompileError { expr.oprand1().accept(this); int type1 = exprType; int dim1 = arrayDim; expr.oprand2().accept(this); if (dim1 != arrayDim) if (type1 != NULL && exprType != NULL) throw new CompileError("incompatible array types"); else if (exprType == NULL) arrayDim = dim1; if (type1 == NULL) return exprType; else return type1; }
public void atBinExpr(BinExpr expr) throws CompileError { int token = expr.getOperator(); int k = CodeGen.lookupBinOp(token); if (k >= 0) { expr.setOprand1(e); expr.setOprand2(null); // <---- look at this! className = jvmJavaLangString; ASTree left = expr.oprand1(); ASTree right = expr.oprand2(); left.accept(this); int type1 = exprType;
public void atBinExpr(BinExpr expr) throws CompileError { int token = expr.getOperator(); expr.oprand1().accept(this); ASTree right = expr.oprand2(); if (right == null) return; // see TypeChecker.atBinExpr().
private boolean isConstant(BinExpr expr, int op, ASTree left, ASTree right) throws CompileError { left = stripPlusExpr(left); right = stripPlusExpr(right); ASTree newExpr = null; if (left instanceof StringL && right instanceof StringL && op == '+') newExpr = new StringL(((StringL)left).get() + ((StringL)right).get()); else if (left instanceof IntConst) newExpr = ((IntConst)left).compute(op, right); else if (left instanceof DoubleConst) newExpr = ((DoubleConst)left).compute(op, right); if (newExpr == null) return false; // not a constant expression else { expr.setOperator('+'); expr.setOprand1(newExpr); expr.setOprand2(null); newExpr.accept(this); // for setting exprType, arrayDim, ... return true; } }
private static boolean isPlusExpr(ASTree expr) { if (expr instanceof BinExpr) { BinExpr bexpr = (BinExpr)expr; int token = bexpr.getOperator(); return token == '+'; } return false; }
@Override public void atBinExpr(BinExpr expr) throws CompileError { int token = expr.getOperator(); int k = CodeGen.lookupBinOp(token); if (k >= 0) { expr.setOprand1(e); expr.setOprand2(null); // <---- look at this! className = jvmJavaLangString; ASTree left = expr.oprand1(); ASTree right = expr.oprand2(); left.accept(this); int type1 = exprType;
@Override public void atBinExpr(BinExpr expr) throws CompileError { int token = expr.getOperator(); expr.oprand1().accept(this); ASTree right = expr.oprand2(); if (right == null) return; // see TypeChecker.atBinExpr().
private int compileOprands(BinExpr expr) throws CompileError { expr.oprand1().accept(this); int type1 = exprType; int dim1 = arrayDim; expr.oprand2().accept(this); if (dim1 != arrayDim) if (type1 != NULL && exprType != NULL) throw new CompileError("incompatible array types"); else if (exprType == NULL) arrayDim = dim1; if (type1 == NULL) return exprType; return type1; }
private boolean isConstant(BinExpr expr, int op, ASTree left, ASTree right) throws CompileError { left = stripPlusExpr(left); right = stripPlusExpr(right); ASTree newExpr = null; if (left instanceof StringL && right instanceof StringL && op == '+') newExpr = new StringL(((StringL)left).get() + ((StringL)right).get()); else if (left instanceof IntConst) newExpr = ((IntConst)left).compute(op, right); else if (left instanceof DoubleConst) newExpr = ((DoubleConst)left).compute(op, right); if (newExpr == null) return false; // not a constant expression expr.setOperator('+'); expr.setOprand1(newExpr); expr.setOprand2(null); newExpr.accept(this); // for setting exprType, arrayDim, ... return true; }
private static boolean isPlusExpr(ASTree expr) { if (expr instanceof BinExpr) { BinExpr bexpr = (BinExpr)expr; int token = bexpr.getOperator(); return token == '+'; } return false; }
public void atBinExpr(BinExpr expr) throws CompileError { int token = expr.getOperator(); int k = CodeGen.lookupBinOp(token); if (k >= 0) { expr.setOprand1(e); expr.setOprand2(null); // <---- look at this! className = jvmJavaLangString; ASTree left = expr.oprand1(); ASTree right = expr.oprand2(); left.accept(this); int type1 = exprType;
compareExpr(branchIf, bexpr.getOperator(), type1, bexpr); else if ((isAndAnd = (op == ANDAND)) || op == OROR) { BinExpr bexpr = (BinExpr)expr; if (booleanExpr(!isAndAnd, bexpr.oprand1())) { exprType = BOOLEAN; arrayDim = 0; int pc = bytecode.currentPc(); bytecode.addIndex(0); // correct later if (booleanExpr(isAndAnd, bexpr.oprand2())) bytecode.addOpcode(Opcode.GOTO);
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 boolean isConstant(BinExpr expr, int op, ASTree left, ASTree right) throws CompileError { left = stripPlusExpr(left); right = stripPlusExpr(right); ASTree newExpr = null; if (left instanceof StringL && right instanceof StringL && op == '+') newExpr = new StringL(((StringL)left).get() + ((StringL)right).get()); else if (left instanceof IntConst) newExpr = ((IntConst)left).compute(op, right); else if (left instanceof DoubleConst) newExpr = ((DoubleConst)left).compute(op, right); if (newExpr == null) return false; // not a constant expression else { expr.setOperator('+'); expr.setOprand1(newExpr); expr.setOprand2(null); newExpr.accept(this); // for setting exprType, arrayDim, ... return true; } }
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; }