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;
 }
 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;
 }
Example #3
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());
  }