Esempio n. 1
0
  public Object visitExprArrayRange(ExprArrayRange exp) {
    RangeLen rl = exp.getSelection();
    if (!rl.hasLen()) {
      Expression newBase = doExpression(exp.getBase());
      Expression newIndex = doExpression(rl.start());
      return new ExprArrayRange(exp, newBase, newIndex);
    } else {
      TypeArray arrType = (TypeArray) getType(exp.getBase());
      Type baseType = arrType.getBase();
      Type type =
          new TypeArray(baseType, doExpression(rl.getLenExpression()), arrType.getMaxlength());

      Expression newBase = doExpression(exp.getBase());
      Expression newIndex = doExpression(rl.start());
      Expression newLen = doExpression(rl.getLenExpression());
      if (newIndex != rl.start() || newLen != rl.getLenExpression() || newBase != exp.getBase()) {
        exp = new ExprArrayRange(exp, newBase, new RangeLen(newIndex, newLen));
      }
      String newName = varGen.nextVar(lhsname);
      StmtVarDecl decl = new StmtVarDecl(exp, type, newName, null);
      this.addStatement(decl);
      Statement assign = new StmtAssign(new ExprVar(exp, newName), exp);
      this.addStatement(assign);
      return new ExprVar(exp, newName);
    }
  }
Esempio n. 2
0
    public Object visitExprArrayRange(ExprArrayRange exp) {
      boolean change = false;
      Type oType = type;
      RangeLen range = exp.getSelection();
      Expression l = range.getLenExpression();
      if (l == null) {
        l = ExprConstInt.one;
        type = new TypeArray(type, new ExprBinary(range.start(), "+", l));
      }
      Expression newBase = doExpression(exp.getBase());
      type = oType;
      if (newBase != exp.getBase()) change = true;

      Expression newStart = null;
      {
        Type oldType = type;
        type = TypePrimitive.inttype;
        newStart = doExpression(range.start());
        type = oldType;
      }
      if (newStart != range.start()) change = true;

      Expression newLen = null;
      if (range.hasLen()) {
        Type oldType = type;
        type = TypePrimitive.inttype;
        newLen = doExpression(range.getLenExpression());
        type = oldType;
      }
      if (range.getLenExpression() != newLen) change = true;

      if (!change) return exp;
      return new ExprArrayRange(exp, newBase, new RangeLen(newStart, newLen));
    }
 public Object visitStmtAssign(StmtAssign stmt) {
   if (stmt.getLHS() instanceof ExprArrayRange) {
     ExprArrayRange v = (ExprArrayRange) stmt.getLHS();
     if (v.getBase() instanceof ExprVar) {
       ExprVar v2 = (ExprVar) (v.getBase());
       if (inputParameters.contains(v2.getName())) {
         parametersToInout.add(v2.getName());
       }
     }
   }
   return stmt;
 }
Esempio n. 4
0
  public Object visitStmtAssign(StmtAssign stmt) {
    if (stmt.getLHS() instanceof ExprVar) {
      lhsname = stmt.getLHS().toString();
    }

    Expression newRHS = doExpression(stmt.getRHS());

    lhsname = null;

    Expression newLHS;
    Statement postAssign = null;
    if (stmt.getLHS() instanceof ExprArrayRange) {
      ExprArrayRange arng = (ExprArrayRange) stmt.getLHS();

      RangeLen rl = arng.getSelection();
      if (rl.hasLen()) {
        TypeArray arrType = (TypeArray) getType(arng.getBase());
        Type baseType = arrType.getBase();
        Type type = new TypeArray(baseType, rl.getLenExpression(), arrType.getMaxlength());

        Expression newBase = doExpression(arng.getBase());
        Expression newIndex = doExpression(rl.start());
        Expression newLen = doExpression(rl.getLenExpression());
        if (newIndex != rl.start()
            || newLen != rl.getLenExpression()
            || newBase != arng.getBase()) {
          arng = new ExprArrayRange(arng, newBase, new RangeLen(newIndex, newLen));
        }
        String newName = varGen.nextVar();
        StmtVarDecl decl = new StmtVarDecl(arng, type, newName, null);
        addStatement(decl);
        Statement assign = new StmtAssign(new ExprVar(arng, newName), newRHS);
        addStatement(assign);
        return new StmtAssign(stmt, arng, new ExprVar(stmt, newName), stmt.getOp());
      } else {
        newLHS = doExpression(stmt.getLHS());
      }
    } else {
      newLHS = doExpression(stmt.getLHS());
    }

    if (newLHS == stmt.getLHS() && newRHS == stmt.getRHS()) return stmt;
    return new StmtAssign(stmt, newLHS, newRHS, stmt.getOp());
  }