public Object visitExprFunCall(ExprFunCall efc) {
    Function fun = nres.getFun(efc.getName());
    List<Expression> newParams = new ArrayList<Expression>(fun.getParams().size());
    Map<Expression, Integer> pset = new HashMap<Expression, Integer>();
    Iterator<Expression> eit = efc.getParams().iterator();
    for (Parameter p : fun.getParams()) {
      Expression actual = eit.next();

      {
        ExprVar ev = getBaseVar(actual);
        if (ev != null && pset.containsKey(ev)) {
          pset.put(ev, pset.get(ev) + 1);
        } else {
          pset.put(ev, 1);
        }
      }
    }
    boolean hasChanged = false;
    eit = efc.getParams().iterator();

    Map<String, Expression> repl = new HashMap<String, Expression>();
    VarReplacer vr = new VarReplacer(repl);

    for (Parameter p : fun.getParams()) {
      Expression actual = eit.next();
      repl.put(p.getName(), actual);
      if (p.isParameterOutput()) {
        ExprVar ev = getBaseVar(actual);
        if (ev == null) {
          newParams.add(actual);
          continue;
        }
        if (ev == FromHeap) {
          addTemp(p, actual, newParams, vr);
          hasChanged = true;
          continue;
        }
        int cnt = pset.get(ev);
        if (cnt > 1) {
          addTemp(p, actual, newParams, vr);
          hasChanged = true;
        } else {
          newParams.add(actual);
        }
      } else {
        newParams.add(actual);
      }
    }

    if (!hasChanged) addStatement(new StmtExpr(efc));
    else addStatement(new StmtExpr(new ExprFunCall(efc, efc.getName(), newParams)));
    addStatements(after);
    after.clear();
    return null;
  }
Exemplo n.º 2
0
 @Override
 public Object visitExprFunCall(ExprFunCall exp) {
   exp = (ExprFunCall) super.visitExprFunCall(exp);
   Function callee = nres.getFun(exp.getName());
   Map<String, Expression> repl = new HashMap<String, Expression>();
   VarReplacer vr = new VarReplacer(repl);
   for (ZipIdxEnt<Expression> arg : zipwithindex(exp.getParams())) {
     Expression actual = arg.entry;
     Parameter p = callee.getParams().get(arg.idx);
     Type t = p.getType();
     repl.put(p.getName(), actual);
     upgradeStarToInt(actual, (Type) t.accept(vr));
   }
   return exp;
 }