public void Transform(ScriptNode tree) { TransformCompilationUnit(tree); for (int i = 0; i != tree.GetFunctionCount(); ++i) { FunctionNode fn = tree.GetFunctionNode(i); Transform(fn); } }
// It is assumed that (NumberType | AnyType) == AnyType internal virtual 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 CollectScriptNodes_r(ScriptNode n, ObjArray x) { x.Add(n); int nestedCount = n.GetFunctionCount(); for (int i = 0; i != nestedCount; ++i) { CollectScriptNodes_r(n.GetFunctionNode(i), x); } }
private static void InitOptFunctions_r(ScriptNode scriptOrFn) { for (int i = 0, N = scriptOrFn.GetFunctionCount(); i != N; ++i) { FunctionNode fn = scriptOrFn.GetFunctionNode(i); new OptFunctionNode(fn); InitOptFunctions_r(fn); } }
private void Transform(ScriptNode tree) { InitOptFunctions_r(tree); int optLevel = compilerEnv.GetOptimizationLevel(); IDictionary<string, OptFunctionNode> possibleDirectCalls = null; if (optLevel > 0) { if (tree.GetType() == Token.SCRIPT) { int functionCount = tree.GetFunctionCount(); for (int i = 0; i != functionCount; ++i) { OptFunctionNode ofn = OptFunctionNode.Get(tree, i); if (ofn.fnode.GetFunctionType() == FunctionNode.FUNCTION_STATEMENT) { string name = ofn.fnode.GetName(); if (name.Length != 0) { if (possibleDirectCalls == null) { possibleDirectCalls = new Dictionary<string, OptFunctionNode>(); } possibleDirectCalls.Put(name, ofn); } } } } } if (possibleDirectCalls != null) { directCallTargets = new ObjArray(); } OptTransformer ot = new OptTransformer(possibleDirectCalls, directCallTargets); ot.Transform(tree); if (optLevel > 0) { (new Rhino.Optimizer.Optimizer()).Optimize(tree); } }