}
// Perform the name replacement
NameRefReplacerVisitor v = new NameRefReplacerVisitor(x, invokedFunction);
for (ListIterator<JsName> nameIterator = localVariableNames.listIterator(); nameIterator.hasNext();) {
JsName name = nameIterator.next();
/*
* Find an unused identifier in the caller's scope. It's possible that
* the same function has been inlined in multiple places within the
* function so we'll use a counter for disambiguation.
*/
String ident;
String base = invokedFunction.getName() + "_" + name.getIdent();
JsScope scope = callerFunction.getScope();
HashMap<String, Integer> startIdent = startIdentForScope.get(scope);
if (startIdent == null) {
startIdent = new HashMap<String, Integer>();
startIdentForScope.put(scope, startIdent);
}
Integer s = startIdent.get(base);
int suffix = (s == null) ? 0 : s.intValue();
do {
ident = base + "_" + suffix++;
} while (scope.findExistingName(ident) != null);
startIdent.put(base, suffix);
JsName newName = scope.declareName(ident, name.getShortIdent());
v.setReplacementName(name, newName);
nameIterator.set(newName);
}
op = v.accept(op);