private void rewriteAsObjectChildren(Node n, Node child) { // Force optimized children to be objects while (child != null) { Node nextChild = child.getNext(); int type = rewriteForNumberVariables(child, NoType); if (type == NumberType) { if (!convertParameter(child)) { n.removeChild(child); Node nuChild = new Node(Token.TO_OBJECT, child); if (nextChild == null) n.addChildToBack(nuChild); else n.addChildBefore(nuChild, nextChild); } } child = nextChild; } }
void optimize(ScriptOrFnNode scriptOrFn) { // run on one function at a time for now int functionCount = scriptOrFn.getFunctionCount(); for (int i = 0; i != functionCount; ++i) { OptFunctionNode f = OptFunctionNode.get(scriptOrFn, i); optimizeFunction(f); } }
case Token.EXPR_VOID : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child, NumberType); if (type == NumberType) n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); if (rewriteForNumberVariables(child, NumberType) == NumberType && !convertParameter(child)) markDCPNumberContext(child); return NumberType; return rewriteForNumberVariables(child, NumberType); Node lChild = n.getFirstChild(); Node rChild = lChild.getNext(); int rType = rewriteForNumberVariables(rChild, NumberType); int varIndex = theFunction.getVarIndex(n); if (inDirectCallFunction if (!convertParameter(rChild)) { n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); return NumberType; markDCPNumberContext(rChild); return NoType; markDCPNumberContext(rChild); return NumberType;
private void optimizeFunction(OptFunctionNode theFunction) { if (theFunction.fnode.requiresActivation()) return; inDirectCallFunction = theFunction.isTargetOfDirectCall(); this.theFunction = theFunction; ObjArray statementsArray = new ObjArray(); buildStatementList_r(theFunction.fnode, statementsArray); Node[] theStatementNodes = new Node[statementsArray.size()]; statementsArray.toArray(theStatementNodes); Block.runFlowAnalyzes(theFunction, theStatementNodes); if (!theFunction.fnode.requiresActivation()) { /* * Now that we know which local vars are in fact always * Numbers, we re-write the tree to take advantage of * that. Any arithmetic or assignment op involving just * Number typed vars is marked so that the codegen will * generate non-object code. */ parameterUsedInNumberContext = false; for (Node theStatementNode : theStatementNodes) { rewriteForNumberVariables(theStatementNode, NumberType); } theFunction.setParameterNumberContext(parameterUsedInNumberContext); } }
private static void buildStatementList_r(Node node, ObjArray statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK || type == Token.LOOP || type == Token.FUNCTION) { Node child = node.getFirstChild(); while (child != null) { buildStatementList_r(child, statements); child = child.getNext(); } } else { statements.add(node); } }
case Token.EXPR_VOID : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child); if (type == NumberType) n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); if (rewriteForNumberVariables(child) == NumberType) { n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); markDCPNumberContext(child); return NumberType; return rewriteForNumberVariables(child); Node lChild = n.getFirstChild(); Node rChild = lChild.getNext(); int rType = rewriteForNumberVariables(rChild); int varIndex = theFunction.getVarIndex(n); if (inDirectCallFunction if (!convertParameter(rChild)) { n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); return NumberType; markDCPNumberContext(rChild); return NoType; markDCPNumberContext(rChild); return NumberType;
private void optimizeFunction(OptFunctionNode theFunction) { if (theFunction.fnode.requiresActivation()) return; inDirectCallFunction = theFunction.isTargetOfDirectCall(); this.theFunction = theFunction; ObjArray statementsArray = new ObjArray(); buildStatementList_r(theFunction.fnode, statementsArray); Node[] theStatementNodes = new Node[statementsArray.size()]; statementsArray.toArray(theStatementNodes); Block.runFlowAnalyzes(theFunction, theStatementNodes); if (!theFunction.fnode.requiresActivation()) { /* * Now that we know which local vars are in fact always * Numbers, we re-write the tree to take advantage of * that. Any arithmetic or assignment op involving just * Number typed vars is marked so that the codegen will * generate non-object code. */ parameterUsedInNumberContext = false; for (int i = 0; i < theStatementNodes.length; i++) { rewriteForNumberVariables(theStatementNodes[i], NumberType); } theFunction.setParameterNumberContext(parameterUsedInNumberContext); } }
private static void buildStatementList_r(Node node, ObjArray statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK || type == Token.LOOP || type == Token.FUNCTION) { Node child = node.getFirstChild(); while (child != null) { buildStatementList_r(child, statements); child = child.getNext(); } } else { statements.add(node); } }
case Token.EXPR_VOID : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child, NumberType); if (type == NumberType) n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); case Token.DEC : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child, NumberType); if (child.getType() == Token.GETVAR) { if (type == NumberType && !convertParameter(child)) markDCPNumberContext(child); return NumberType; Node lChild = n.getFirstChild(); Node rChild = lChild.getNext(); int rType = rewriteForNumberVariables(rChild, NumberType); int varIndex = theFunction.getVarIndex(n); if (inDirectCallFunction if (!convertParameter(rChild)) { n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); return NumberType; markDCPNumberContext(rChild); return NoType; markDCPNumberContext(rChild);
private void rewriteAsObjectChildren(Node n, Node child) { // Force optimized children to be objects while (child != null) { Node nextChild = child.getNext(); int type = rewriteForNumberVariables(child); if (type == NumberType) { if (!convertParameter(child)) { n.removeChild(child); Node nuChild = new Node(Token.TO_OBJECT, child); if (nextChild == null) n.addChildToBack(nuChild); else n.addChildBefore(nuChild, nextChild); } } child = nextChild; } }
private void optimizeFunction(OptFunctionNode theFunction) { if (theFunction.fnode.requiresActivation()) return; inDirectCallFunction = theFunction.isTargetOfDirectCall(); this.theFunction = theFunction; ObjArray statementsArray = new ObjArray(); buildStatementList_r(theFunction.fnode, statementsArray); Node[] theStatementNodes = new Node[statementsArray.size()]; statementsArray.toArray(theStatementNodes); Block.runFlowAnalyzes(theFunction, theStatementNodes); if (!theFunction.fnode.requiresActivation()) { /* * Now that we know which local vars are in fact always * Numbers, we re-write the tree to take advantage of * that. Any arithmetic or assignment op involving just * Number typed vars is marked so that the codegen will * generate non-object code. */ parameterUsedInNumberContext = false; for (Node theStatementNode : theStatementNodes) { rewriteForNumberVariables(theStatementNode, NumberType); } theFunction.setParameterNumberContext(parameterUsedInNumberContext); } }
void optimize(ScriptNode scriptOrFn) { // run on one function at a time for now int functionCount = scriptOrFn.getFunctionCount(); for (int i = 0; i != functionCount; ++i) { OptFunctionNode f = OptFunctionNode.get(scriptOrFn, i); optimizeFunction(f); } }
private static void buildStatementList_r(Node node, ObjArray statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK || type == Token.LOOP || type == Token.FUNCTION) { Node child = node.getFirstChild(); while (child != null) { buildStatementList_r(child, statements); child = child.getNext(); } } else { statements.add(node); } }
case Token.EXPR_VOID : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child, NumberType); if (type == NumberType) n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); case Token.DEC : { Node child = n.getFirstChild(); int type = rewriteForNumberVariables(child, NumberType); if (child.getType() == Token.GETVAR) { if (type == NumberType && !convertParameter(child)) markDCPNumberContext(child); return NumberType; Node lChild = n.getFirstChild(); Node rChild = lChild.getNext(); int rType = rewriteForNumberVariables(rChild, NumberType); int varIndex = theFunction.getVarIndex(n); if (inDirectCallFunction if (!convertParameter(rChild)) { n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH); return NumberType; markDCPNumberContext(rChild); return NoType; markDCPNumberContext(rChild);
private void rewriteAsObjectChildren(Node n, Node child) { // Force optimized children to be objects while (child != null) { Node nextChild = child.getNext(); int type = rewriteForNumberVariables(child, NoType); if (type == NumberType) { if (!convertParameter(child)) { n.removeChild(child); Node nuChild = new Node(Token.TO_OBJECT, child); if (nextChild == null) n.addChildToBack(nuChild); else n.addChildBefore(nuChild, nextChild); } } child = nextChild; } }
private void optimizeFunction(OptFunctionNode theFunction) { if (theFunction.fnode.requiresActivation()) return; inDirectCallFunction = theFunction.isTargetOfDirectCall(); this.theFunction = theFunction; ObjArray statementsArray = new ObjArray(); buildStatementList_r(theFunction.fnode, statementsArray); Node[] theStatementNodes = new Node[statementsArray.size()]; statementsArray.toArray(theStatementNodes); Block.runFlowAnalyzes(theFunction, theStatementNodes); if (!theFunction.fnode.requiresActivation()) { /* * Now that we know which local vars are in fact always * Numbers, we re-write the tree to take advantage of * that. Any arithmetic or assignment op involving just * Number typed vars is marked so that the codegen will * generate non-object code. */ parameterUsedInNumberContext = false; for (Node theStatementNode : theStatementNodes) { rewriteForNumberVariables(theStatementNode, NumberType); } theFunction.setParameterNumberContext(parameterUsedInNumberContext); } }