| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import com.google.common.collect.Lists; |
| 20 |
import com.google.javascript.rhino.Node; |
| 21 |
|
| 22 |
import java.util.List; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class OptimizeCalls implements CompilerPass { |
| 35 |
List<CallGraphCompilerPass> passes = Lists.newArrayList(); |
| 36 |
private AbstractCompiler compiler; |
| 37 |
|
| 38 |
OptimizeCalls(AbstractCompiler compiler) { |
| 39 |
this.compiler = compiler; |
| 40 |
} |
| 41 |
|
| 42 |
OptimizeCalls addPass(CallGraphCompilerPass pass) { |
| 43 |
passes.add(pass); |
| 44 |
return this; |
| 45 |
} |
| 46 |
|
| 47 |
interface CallGraphCompilerPass { |
| 48 |
void process(Node externs, Node root, SimpleDefinitionFinder definitions); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void process(Node externs, Node root) { |
| 53 |
if (passes.size() > 0) { |
| 54 |
SimpleDefinitionFinder defFinder = new SimpleDefinitionFinder(compiler); |
| 55 |
defFinder.process(externs, root); |
| 56 |
for (CallGraphCompilerPass pass : passes) { |
| 57 |
pass.process(externs, root, defFinder); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |