Debian Codegraph @

src/com/google/javascript/jscomp/OptimizeCalls.java

raw symbols SCIP
1 /*
2 * Copyright 2010 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * A root pass that container for other passes that should run on
26 * with a single call graph (currently a SimpleDefinitionFinder).
27 * Expected passes include:
28 * - optimize parameters
29 * - optimize returns
30 * - devirtualize prototype methods
31 *
32 * @author [email protected] (John Lenz)
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 }