private void rewriteCall ( Node getprop , String newMethodName ) { checkArgument ( getprop . isGetProp ( ) , getprop ) ; Node call = getprop . getParent ( ) ; checkArgument ( call . isCall ( ) , call ) ; Node receiver = getprop . getFirstChild ( ) ; // This rewriting does not exactly preserve order of operations; the newly inserted static // method name will be resolved before `receiver` is evaluated. This is known to be safe due // to the eligibility checks earlier in the pass. // // We choose not to do a full-fidelity rewriting (e.g. using `ExpressionDecomposer`) because // doing so means extracting `receiver` into a new variable at each call-site. This has a // significant code-size impact (circa 2018-11-19). getprop . removeChild ( receiver ) ; call . replaceChild ( getprop , receiver ) ; call . addChildToFront ( IR . name ( newMethodName ) . srcref ( getprop ) ) ; if ( receiver . isSuper ( ) ) { // Case: `super.foo(a, b)` => `foo(this, a, b)` receiver . setToken ( Token . THIS ) ; } call . putBooleanProp ( Node . FREE_CALL , true ) ; compiler . reportChangeToEnclosingScope ( call ) ; }
Rewrites object method call sites as calls to global functions that take this as their first argument .