List<Parameter> parameters = Lists.newArrayList();
boolean firstCall = true;
// Build a list of parameters to remove
Definition definition = defSite.definition;
Collection<UseSite> useSites = defFinder.getUseSites(definition);
boolean continueLooking = false;
for (UseSite site : useSites) {
Preconditions.checkState(SimpleDefinitionFinder.isCallOrNewSite(site));
Node call = site.node.getParent();
Node cur = call.getFirstChild();
if (firstCall) {
// Use the first call to construct a list of parameters of the
// function.
continueLooking = buildParameterList(parameters, cur, site.scope);
firstCall = false;
} else {
continueLooking = findFixedParameters(parameters, cur);
}
if (!continueLooking) {
return;
}
}
continueLooking = adjustForSideEffects(parameters);
if (!continueLooking) {
return;
}
// Remove the constant parameters in all the calls
for (UseSite site : useSites) {
Preconditions.checkState(SimpleDefinitionFinder.isCallOrNewSite(site));
Node call = site.node.getParent();
optimizeCallSite(defFinder, parameters, call);
}
// Remove the constant parameters in the definitions and add it as a local
// variable.
Node function = definition.getRValue();
if (function.isFunction()) {
optimizeFunctionDefinition(parameters, function);
}
}