Java Code Examples for org.mozilla.javascript.ast.ScriptNode#getType()
The following examples show how to use
org.mozilla.javascript.ast.ScriptNode#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeTransformer.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
private void transformCompilationUnit(ScriptNode tree, boolean inStrictMode) { loops = new ObjArray(); loopEnds = new ObjArray(); // to save against upchecks if no finally blocks are used. hasFinally = false; // Flatten all only if we are not using scope objects for block scope boolean createScopeObjects = tree.getType() != Token.FUNCTION || ((FunctionNode)tree).requiresActivation(); tree.flattenSymbolTable(!createScopeObjects); //uncomment to print tree before transformation if (Token.printTrees) System.out.println(tree.toStringTree(tree)); transformCompilationUnit_r(tree, tree, tree, createScopeObjects, inStrictMode); }
Example 2
Source File: NodeTransformer.java From astor with GNU General Public License v2.0 | 6 votes |
private void transformCompilationUnit(ScriptNode tree) { loops = new ObjArray(); loopEnds = new ObjArray(); // to save against upchecks if no finally blocks are used. hasFinally = false; // Flatten all only if we are not using scope objects for block scope boolean createScopeObjects = tree.getType() != Token.FUNCTION || ((FunctionNode)tree).requiresActivation(); tree.flattenSymbolTable(!createScopeObjects); //uncomment to print tree before transformation if (Token.printTrees) System.out.println(tree.toStringTree(tree)); boolean inStrictMode = tree instanceof AstRoot && ((AstRoot)tree).isInStrictMode(); transformCompilationUnit_r(tree, tree, tree, createScopeObjects, inStrictMode); }
Example 3
Source File: OptTransformer.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private void detectDirectCall(Node node, ScriptNode tree) { if (tree.getType() == Token.FUNCTION) { Node left = node.getFirstChild(); // count the arguments int argCount = 0; Node arg = left.getNext(); while (arg != null) { arg = arg.getNext(); argCount++; } if (argCount == 0) { OptFunctionNode.get(tree).itsContainsCalls0 = true; } /* * Optimize a call site by converting call("a", b, c) into : * * FunctionObjectFor"a" <-- instance variable init'd by constructor * * // this is a DIRECTCALL node * fn = GetProp(tmp = GetBase("a"), "a"); * if (fn == FunctionObjectFor"a") * fn.call(tmp, b, c) * else * ScriptRuntime.Call(fn, tmp, b, c) */ if (possibleDirectCalls != null) { String targetName = null; if (left.getType() == Token.NAME) { targetName = left.getString(); } else if (left.getType() == Token.GETPROP) { targetName = left.getFirstChild().getNext().getString(); } else if (left.getType() == Token.GETPROPNOWARN) { throw Kit.codeBug(); } if (targetName != null) { OptFunctionNode ofn; ofn = possibleDirectCalls.get(targetName); if (ofn != null && argCount == ofn.fnode.getParamCount() && !ofn.fnode.requiresActivation()) { // Refuse to directCall any function with more // than 32 parameters - prevent code explosion // for wacky test cases if (argCount <= 32) { node.putProp(Node.DIRECTCALL_PROP, ofn); if (!ofn.isTargetOfDirectCall()) { int index = directCallTargets.size(); directCallTargets.add(ofn); ofn.setDirectTargetIndex(index); } } } } } } }
Example 4
Source File: OptTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
private void detectDirectCall(Node node, ScriptNode tree) { if (tree.getType() == Token.FUNCTION) { Node left = node.getFirstChild(); // count the arguments int argCount = 0; Node arg = left.getNext(); while (arg != null) { arg = arg.getNext(); argCount++; } if (argCount == 0) { OptFunctionNode.get(tree).itsContainsCalls0 = true; } /* * Optimize a call site by converting call("a", b, c) into : * * FunctionObjectFor"a" <-- instance variable init'd by constructor * * // this is a DIRECTCALL node * fn = GetProp(tmp = GetBase("a"), "a"); * if (fn == FunctionObjectFor"a") * fn.call(tmp, b, c) * else * ScriptRuntime.Call(fn, tmp, b, c) */ if (possibleDirectCalls != null) { String targetName = null; if (left.getType() == Token.NAME) { targetName = left.getString(); } else if (left.getType() == Token.GETPROP) { targetName = left.getFirstChild().getNext().getString(); } else if (left.getType() == Token.GETPROPNOWARN) { throw Kit.codeBug(); } if (targetName != null) { OptFunctionNode ofn; ofn = possibleDirectCalls.get(targetName); if (ofn != null && argCount == ofn.fnode.getParamCount() && !ofn.fnode.requiresActivation()) { // Refuse to directCall any function with more // than 32 parameters - prevent code explosion // for wacky test cases if (argCount <= 32) { node.putProp(Node.DIRECTCALL_PROP, ofn); if (!ofn.isTargetOfDirectCall()) { int index = directCallTargets.size(); directCallTargets.add(ofn); ofn.setDirectTargetIndex(index); } } } } } } }