Debian Codegraph @

rhino/src/org/mozilla/javascript/optimizer/OptFunctionNode.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
6 package org.mozilla.javascript.optimizer;
7
8 import org.mozilla.javascript.*;
9 import org.mozilla.javascript.ast.FunctionNode;
10 import org.mozilla.javascript.ast.ScriptNode;
11
12 public final class OptFunctionNode
13 {
14 OptFunctionNode(FunctionNode fnode)
15 {
16 this.fnode = fnode;
17 fnode.setCompilerData(this);
18 }
19
20 public static OptFunctionNode get(ScriptNode scriptOrFn, int i)
21 {
22 FunctionNode fnode = scriptOrFn.getFunctionNode(i);
23 return (OptFunctionNode)fnode.getCompilerData();
24 }
25
26 public static OptFunctionNode get(ScriptNode scriptOrFn)
27 {
28 return (OptFunctionNode)scriptOrFn.getCompilerData();
29 }
30
31 public boolean isTargetOfDirectCall()
32 {
33 return directTargetIndex >= 0;
34 }
35
36 public int getDirectTargetIndex()
37 {
38 return directTargetIndex;
39 }
40
41 void setDirectTargetIndex(int directTargetIndex)
42 {
43 // One time action
44 if (directTargetIndex < 0 || this.directTargetIndex >= 0)
45 Kit.codeBug();
46 this.directTargetIndex = directTargetIndex;
47 }
48
49 void setParameterNumberContext(boolean b)
50 {
51 itsParameterNumberContext = b;
52 }
53
54 public boolean getParameterNumberContext()
55 {
56 return itsParameterNumberContext;
57 }
58
59 public int getVarCount()
60 {
61 return fnode.getParamAndVarCount();
62 }
63
64 public boolean isParameter(int varIndex)
65 {
66 return varIndex < fnode.getParamCount();
67 }
68
69 public boolean isNumberVar(int varIndex)
70 {
71 varIndex -= fnode.getParamCount();
72 if (varIndex >= 0 && numberVarFlags != null) {
73 return numberVarFlags[varIndex];
74 }
75 return false;
76 }
77
78 void setIsNumberVar(int varIndex)
79 {
80 varIndex -= fnode.getParamCount();
81 // Can only be used with non-parameters
82 if (varIndex < 0) Kit.codeBug();
83 if (numberVarFlags == null) {
84 int size = fnode.getParamAndVarCount() - fnode.getParamCount();
85 numberVarFlags = new boolean[size];
86 }
87 numberVarFlags[varIndex] = true;
88 }
89
90 public int getVarIndex(Node n)
91 {
92 int index = n.getIntProp(Node.VARIABLE_PROP, -1);
93 if (index == -1) {
94 Node node;
95 int type = n.getType();
96 if (type == Token.GETVAR) {
97 node = n;
98 } else if (type == Token.SETVAR ||
99 type == Token.SETCONSTVAR) {
100 node = n.getFirstChild();
101 } else {
102 throw Kit.codeBug();
103 }
104 index = fnode.getIndexForNameNode(node);
105 if (index < 0) throw Kit.codeBug();
106 n.putIntProp(Node.VARIABLE_PROP, index);
107 }
108 return index;
109 }
110
111 public final FunctionNode fnode;
112
113 private boolean[] numberVarFlags;
114 private int directTargetIndex = -1;
115 private boolean itsParameterNumberContext;
116 boolean itsContainsCalls0;
117 boolean itsContainsCalls1;
118 }