equal
deleted
inserted
replaced
41 import jdk.nashorn.internal.codegen.Compiler; |
41 import jdk.nashorn.internal.codegen.Compiler; |
42 import jdk.nashorn.internal.codegen.Frame; |
42 import jdk.nashorn.internal.codegen.Frame; |
43 import jdk.nashorn.internal.codegen.MethodEmitter; |
43 import jdk.nashorn.internal.codegen.MethodEmitter; |
44 import jdk.nashorn.internal.codegen.Namespace; |
44 import jdk.nashorn.internal.codegen.Namespace; |
45 import jdk.nashorn.internal.codegen.Splitter; |
45 import jdk.nashorn.internal.codegen.Splitter; |
46 import jdk.nashorn.internal.codegen.Transform; |
|
47 import jdk.nashorn.internal.codegen.types.Type; |
46 import jdk.nashorn.internal.codegen.types.Type; |
48 import jdk.nashorn.internal.ir.annotations.Ignore; |
47 import jdk.nashorn.internal.ir.annotations.Ignore; |
49 import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
48 import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
50 import jdk.nashorn.internal.parser.Parser; |
49 import jdk.nashorn.internal.parser.Parser; |
51 import jdk.nashorn.internal.runtime.Source; |
50 import jdk.nashorn.internal.runtime.Source; |
187 /** Does this function need to store all its variables in scope? */ |
186 /** Does this function need to store all its variables in scope? */ |
188 private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_WITH_OR_EVAL | IS_SPLIT; |
187 private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_WITH_OR_EVAL | IS_SPLIT; |
189 /** Does this function need a scope object? */ |
188 /** Does this function need a scope object? */ |
190 private static final int NEEDS_SCOPE = HAS_ALL_VARS_IN_SCOPE | IS_VAR_ARG; |
189 private static final int NEEDS_SCOPE = HAS_ALL_VARS_IN_SCOPE | IS_VAR_ARG; |
191 |
190 |
192 |
|
193 /** What is the return type of this function? */ |
191 /** What is the return type of this function? */ |
194 private Type returnType = Type.OBJECT; |
192 private Type returnType = Type.OBJECT; |
195 |
|
196 /** Transforms that have been applied to this function, a list as some transforms conceivably can run many times */ |
|
197 @Ignore |
|
198 private final List<Class<? extends Transform>> appliedTransforms; |
|
199 |
193 |
200 /** |
194 /** |
201 * Used to keep track of a function's parent blocks. |
195 * Used to keep track of a function's parent blocks. |
202 * This is needed when a (finally body) block is cloned than contains inner functions. |
196 * This is needed when a (finally body) block is cloned than contains inner functions. |
203 * Does not include function.getParent(). |
197 * Does not include function.getParent(). |
230 this.namespace = new Namespace(compiler.getNamespace().getParent()); |
224 this.namespace = new Namespace(compiler.getNamespace().getParent()); |
231 this.thisProperties = new LinkedHashMap<>(); |
225 this.thisProperties = new LinkedHashMap<>(); |
232 this.labelStack = new Stack<>(); |
226 this.labelStack = new Stack<>(); |
233 this.controlStack = new Stack<>(); |
227 this.controlStack = new Stack<>(); |
234 this.declarations = new ArrayList<>(); |
228 this.declarations = new ArrayList<>(); |
235 this.appliedTransforms = new ArrayList<>(); |
|
236 // my block -> function is this. We added @SuppressWarnings("LeakingThisInConstructor") as NetBeans identifies |
229 // my block -> function is this. We added @SuppressWarnings("LeakingThisInConstructor") as NetBeans identifies |
237 // it as such a leak - this is a false positive as we're setting this into a field of the object being |
230 // it as such a leak - this is a false positive as we're setting this into a field of the object being |
238 // constructed, so it can't be seen from other threads. |
231 // constructed, so it can't be seen from other threads. |
239 this.function = this; |
232 this.function = this; |
240 } |
233 } |
264 this.calleeNode = (IdentNode)cs.existingOrCopy(functionNode.calleeNode); |
257 this.calleeNode = (IdentNode)cs.existingOrCopy(functionNode.calleeNode); |
265 this.thisProperties = new LinkedHashMap<>(); |
258 this.thisProperties = new LinkedHashMap<>(); |
266 this.labelStack = new Stack<>(); |
259 this.labelStack = new Stack<>(); |
267 this.controlStack = new Stack<>(); |
260 this.controlStack = new Stack<>(); |
268 this.declarations = new ArrayList<>(); |
261 this.declarations = new ArrayList<>(); |
269 this.appliedTransforms = new ArrayList<>(); |
|
270 |
262 |
271 for (final VarNode decl : functionNode.getDeclarations()) { |
263 for (final VarNode decl : functionNode.getDeclarations()) { |
272 declarations.add((VarNode) cs.existingOrCopy(decl)); //TODO same? |
264 declarations.add((VarNode) cs.existingOrCopy(decl)); //TODO same? |
273 } |
265 } |
274 |
266 |
788 * |
780 * |
789 * @return true if all variables should be in scope |
781 * @return true if all variables should be in scope |
790 */ |
782 */ |
791 public boolean varsInScope() { |
783 public boolean varsInScope() { |
792 return isScript() || (flags & HAS_ALL_VARS_IN_SCOPE) != 0; |
784 return isScript() || (flags & HAS_ALL_VARS_IN_SCOPE) != 0; |
793 } |
|
794 |
|
795 /** |
|
796 * Check if a {@link Transform} has been taken place to this method. |
|
797 * @param transform to check for |
|
798 * @return true if transform has been applied |
|
799 */ |
|
800 public boolean isTransformApplied(final Class<? extends Transform> transform) { |
|
801 return appliedTransforms.contains(transform); |
|
802 } |
|
803 |
|
804 /** |
|
805 * Tag this function with an applied transform |
|
806 * @param transform the transform |
|
807 */ |
|
808 public void registerTransform(final Class<? extends Transform> transform) { |
|
809 appliedTransforms.add(transform); |
|
810 } |
785 } |
811 |
786 |
812 /** |
787 /** |
813 * Checks if this function is a sub-function generated by splitting a larger one |
788 * Checks if this function is a sub-function generated by splitting a larger one |
814 * @see Splitter |
789 * @see Splitter |