示例#1
0
  public void atBinExpr(BinExpr expr) throws CompileError {
    int token = expr.getOperator();

    /* arithmetic operators: +, -, *, /, %, |, ^, &, <<, >>, >>>
     */
    int k = lookupBinOp(token);
    if (k >= 0) {
      expr.oprand1().accept(this);
      ASTree right = expr.oprand2();
      if (right == null) return; // see TypeChecker.atBinExpr().

      int type1 = exprType;
      int dim1 = arrayDim;
      String cname1 = className;
      right.accept(this);
      if (dim1 != arrayDim) throw new CompileError("incompatible array types");

      if (token == '+' && dim1 == 0 && (type1 == CLASS || exprType == CLASS))
        atStringConcatExpr(expr, type1, dim1, cname1);
      else atArithBinExpr(expr, token, k, type1);
    } else {
      /* equation: &&, ||, ==, !=, <=, >=, <, >
       */
      if (!booleanExpr(true, expr)) {
        bytecode.addIndex(7);
        bytecode.addIconst(0); // false
        bytecode.addOpcode(Opcode.GOTO);
        bytecode.addIndex(4);
      }

      bytecode.addIconst(1); // true
    }
  }
示例#2
0
  protected void atAssignCore(Expr expr, int op, ASTree right, int type, int dim, String cname)
      throws CompileError {
    if (op == PLUS_E && dim == 0 && type == CLASS) atStringPlusEq(expr, type, dim, cname, right);
    else {
      right.accept(this);
      if (invalidDim(exprType, arrayDim, className, type, dim, cname, false)
          || (op != '=' && dim > 0)) badAssign(expr);

      if (op != '=') {
        int token = assignOps[op - MOD_E];
        int k = lookupBinOp(token);
        if (k < 0) fatal();

        atArithBinExpr(expr, token, k, type);
      }
    }

    if (op != '=' || (dim == 0 && !isRefType(type))) atNumCastExpr(exprType, type);

    // type check should be done here.
  }