Exemple #1
0
 public Expression getRangeMax() {
   if (!(cond instanceof ExprBinary)) {
     return null;
   }
   ExprBinary eb = (ExprBinary) cond;
   if (eb.getOp() == ExprBinary.BINOP_LE) {
     return eb.getRight();
   }
   if (eb.getOp() == ExprBinary.BINOP_LT) {
     return new ExprBinary(eb.getRight(), "-", ExprConstInt.one);
   }
   return null;
 }
Exemple #2
0
 public Expression getIncrVal() {
   if (incr instanceof StmtExpr) {
     StmtExpr se = (StmtExpr) incr;
     if (se.getExpression() instanceof ExprUnary) {
       ExprUnary eu = (ExprUnary) se.getExpression();
       int op = eu.getOp();
       if (op == ExprUnary.UNOP_POSTINC || op == ExprUnary.UNOP_PREINC) {
         return ExprConstInt.one;
       }
       if (op == ExprUnary.UNOP_POSTDEC || op == ExprUnary.UNOP_PREDEC) {
         return ExprConstInt.minusone;
       }
     }
   }
   if (incr instanceof StmtAssign) {
     StmtAssign sa = (StmtAssign) incr;
     if (sa.getOp() == 0) {
       if (sa.getRHS() instanceof ExprBinary) {
         ExprBinary eb = (ExprBinary) sa.getRHS();
         if (eb.getLeft().equals(sa.getLHS())) {
           return eb.getRight();
         }
         if (eb.getRight().equals(sa.getLHS())) {
           return eb.getLeft();
         }
       }
     }
     if (sa.getOp() == ExprBinary.BINOP_ADD) {
       return sa.getRHS();
     }
     if (sa.getOp() == ExprBinary.BINOP_SUB) {
       return new ExprUnary("-", sa.getRHS());
     }
   }
   return null;
 }
    public Object visitExprBinary(ExprBinary exp) {
      switch (exp.getOp()) {
        case ExprBinary.BINOP_GE:
        case ExprBinary.BINOP_GT:
        case ExprBinary.BINOP_LE:
        case ExprBinary.BINOP_LT:
          {
            Type oldType = type;
            Type tleft = getType(exp.getLeft());
            Type tright = getType(exp.getRight());
            Type tt = tright.leastCommonPromotion(tleft, nres);
            type = tt; // TypePrimitive.inttype;
            Expression left = doExpression(exp.getLeft());
            Expression right = doExpression(exp.getRight());
            type = oldType;
            if (left == exp.getLeft() && right == exp.getRight()) return exp;
            else return new ExprBinary(exp, exp.getOp(), left, right, exp.getAlias());
          }
        case ExprBinary.BINOP_LSHIFT:
        case ExprBinary.BINOP_RSHIFT:
          {
            Expression left = doExpression(exp.getLeft());
            Type oldType = type;
            type = TypePrimitive.inttype;
            Expression right = doExpression(exp.getRight());
            type = oldType;
            if (left == exp.getLeft() && right == exp.getRight()) return exp;
            else return new ExprBinary(exp, exp.getOp(), left, right, exp.getAlias());
          }
        case ExprBinary.BINOP_NEQ:
        case ExprBinary.BINOP_EQ:
          {
            Type tleft = stv.getType(exp.getLeft());
            Type tright = stv.getType(exp.getRight());
            Type tboth = tleft.leastCommonPromotion(tright, nres);
            Type oldType = type;
            type = tboth;
            Expression left = doExpression(exp.getLeft());
            Expression right = doExpression(exp.getRight());
            type = oldType;
            if (left == exp.getLeft() && right == exp.getRight()) return exp;
            else return new ExprBinary(exp, exp.getOp(), left, right, exp.getAlias());
          }

        default:
          return super.visitExprBinary(exp);
      }
    }