Ejemplo n.º 1
0
  public Object visitStmtVarDecl(StmtVarDecl stmt) {
    // Make sure the variable declaration stays first.  This will
    // have no initializers, except for where there is an array
    // initializer.
    ArrayList newInits = new ArrayList(stmt.getNumVars());
    for (int i = 0; i < stmt.getNumVars(); i++) {
      // if (stmt.getInit(i) instanceof ExprArrayInit) {
      // newInits.add(stmt.getInit(i));
      // } else {
      newInits.add(null);
      // }
    }
    Statement newDecl = new StmtVarDecl(stmt, stmt.getTypes(), stmt.getNames(), newInits);
    addStatement(newDecl);

    // Now go through the original statement; if there are
    // any initializers, create a new assignment statement.
    for (int i = 0; i < stmt.getNumVars(); i++) {
      String name = stmt.getName(i);
      Expression init = stmt.getInit(i);
      // don't separate array initializations, because it become
      // illegal syntax
      if (init != null) // && !(init instanceof ExprArrayInit))
      {
        Statement assign = new StmtAssign(new ExprVar(stmt, name), init);
        addStatement(assign);
      }
    }

    // Already added the base statement.
    return null;
  }
Ejemplo n.º 2
0
  public Object visitStmtVarDecl(StmtVarDecl stmt) {
    if (collecting) {
      for (int i = 0; i < stmt.getNumVars(); i++) {
        String name = stmt.getName(i);
        if (variables.get(name) == null) variables.put(name, stmt);
      }
      return stmt;
    }
    // take care of variable substitution in the initializers first
    stmt = (StmtVarDecl) super.visitStmtVarDecl(stmt);

    List<String> names = new ArrayList<String>(stmt.getNames());
    boolean change = false;
    for (int i = 0; i < stmt.getNumVars(); i++) {
      final String name = names.get(i);
      if (variables.get(name) != stmt) {
        for (int suff = 2; ; suff++) {
          final String newName = name + suff;
          if (variables.get(newName) == null) {
            names.set(i, newName);
            renameMap.put(name, newName);
            variables.put(newName, newName);
            change = true;
            break;
          }
        }
      }
    }
    if (change) {
      stmt = new StmtVarDecl(stmt, stmt.getTypes(), names, stmt.getInits());
    }
    return stmt;
  }
Ejemplo n.º 3
0
 public Object visitStmtVarDecl(StmtVarDecl stmt) {
   Object result = super.visitStmtVarDecl(stmt);
   for (int i = 0; i < stmt.getNumVars(); i++) {
     Expression ie = stmt.getInit(i);
     if (ie != null) {
       Type rt = getType(ie);
       Type ftype = matchTypes(stmt, stmt.getName(i), (stmt.getType(i)), rt);
       upgradeStarToInt(ie, ftype);
     }
   }
   return result;
 }