Beispiel #1
0
 public Expression getRangeMin() {
   if (init instanceof StmtVarDecl) {
     StmtVarDecl svd = (StmtVarDecl) init;
     return svd.getInit(0);
   }
   if (init instanceof StmtAssign) {
     StmtAssign sa = (StmtAssign) init;
     return sa.getRHS();
   }
   return null;
 }
Beispiel #2
0
 public String getIndVar() {
   if (init instanceof StmtVarDecl) {
     StmtVarDecl svd = (StmtVarDecl) init;
     return svd.getName(0);
   }
   if (init instanceof StmtAssign) {
     StmtAssign sa = (StmtAssign) init;
     return sa.getLHS().toString();
   }
   return null;
 }
Beispiel #3
0
 public Expression getICond() {
   String nm = null;
   Expression start = null;
   if (init instanceof StmtVarDecl) {
     StmtVarDecl svd = (StmtVarDecl) init;
     nm = svd.getName(0);
     start = svd.getInit(0);
   }
   if (init instanceof StmtAssign) {
     StmtAssign sa = (StmtAssign) init;
     assert sa.getLHS() instanceof ExprVar;
     nm = sa.getLHS().toString();
     start = sa.getRHS();
   }
   VarReplacer vr = new VarReplacer(nm, start);
   return (Expression) cond.accept(vr);
 }
 public Object visitStmtAssign(StmtAssign stmt) {
   Type lt = getType(stmt.getLHS());
   Type rt = getType(stmt.getRHS());
   String lhsn = null;
   Expression lhsExp = stmt.getLHS();
   while (lhsExp instanceof ExprArrayRange) {
     lhsExp = ((ExprArrayRange) lhsExp).getBase();
   }
   if (lhsExp instanceof ExprVar) {
     lhsn = ((ExprVar) lhsExp).getName();
   }
   Type ftype = matchTypes(stmt, lhsn, lt, rt);
   upgradeStarToInt(stmt.getRHS(), ftype);
   upgradeStarToInt(stmt.getLHS(), ftype);
   // recurse:
   Statement result = (Statement) super.visitStmtAssign(stmt);
   return result;
 }
Beispiel #5
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;
 }