Source Code Cross Referenced for OptTransformer.java in  » Scripting » rhino » org » mozilla » javascript » optimizer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » rhino » org.mozilla.javascript.optimizer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ***** BEGIN LICENSE BLOCK *****
002:         * Version: MPL 1.1/GPL 2.0
003:         *
004:         * The contents of this file are subject to the Mozilla Public License Version
005:         * 1.1 (the "License"); you may not use this file except in compliance with
006:         * the License. You may obtain a copy of the License at
007:         * http://www.mozilla.org/MPL/
008:         *
009:         * Software distributed under the License is distributed on an "AS IS" basis,
010:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011:         * for the specific language governing rights and limitations under the
012:         * License.
013:         *
014:         * The Original Code is Rhino code, released
015:         * May 6, 1999.
016:         *
017:         * The Initial Developer of the Original Code is
018:         * Netscape Communications Corporation.
019:         * Portions created by the Initial Developer are Copyright (C) 1997-1999
020:         * the Initial Developer. All Rights Reserved.
021:         *
022:         * Contributor(s):
023:         *   Norris Boyd
024:         *   Roger Lawrence
025:         *
026:         * Alternatively, the contents of this file may be used under the terms of
027:         * the GNU General Public License Version 2 or later (the "GPL"), in which
028:         * case the provisions of the GPL are applicable instead of those above. If
029:         * you wish to allow use of your version of this file only under the terms of
030:         * the GPL and not to allow others to use your version of this file under the
031:         * MPL, indicate your decision by deleting the provisions above and replacing
032:         * them with the notice and other provisions required by the GPL. If you do
033:         * not delete the provisions above, a recipient may use your version of this
034:         * file under either the MPL or the GPL.
035:         *
036:         * ***** END LICENSE BLOCK ***** */
037:
038:        package org.mozilla.javascript.optimizer;
039:
040:        import org.mozilla.javascript.*;
041:        import java.util.Hashtable;
042:
043:        /**
044:         * This class performs node transforms to prepare for optimization.
045:         *
046:         * @see NodeTransformer
047:         * @author Norris Boyd
048:         */
049:
050:        class OptTransformer extends NodeTransformer {
051:
052:            OptTransformer(Hashtable possibleDirectCalls,
053:                    ObjArray directCallTargets) {
054:                this .possibleDirectCalls = possibleDirectCalls;
055:                this .directCallTargets = directCallTargets;
056:            }
057:
058:            protected void visitNew(Node node, ScriptOrFnNode tree) {
059:                detectDirectCall(node, tree);
060:                super .visitNew(node, tree);
061:            }
062:
063:            protected void visitCall(Node node, ScriptOrFnNode tree) {
064:                detectDirectCall(node, tree);
065:                super .visitCall(node, tree);
066:            }
067:
068:            private void detectDirectCall(Node node, ScriptOrFnNode tree) {
069:                if (tree.getType() == Token.FUNCTION) {
070:                    Node left = node.getFirstChild();
071:
072:                    // count the arguments
073:                    int argCount = 0;
074:                    Node arg = left.getNext();
075:                    while (arg != null) {
076:                        arg = arg.getNext();
077:                        argCount++;
078:                    }
079:
080:                    if (argCount == 0) {
081:                        OptFunctionNode.get(tree).itsContainsCalls0 = true;
082:                    }
083:
084:                    /*
085:                     * Optimize a call site by converting call("a", b, c) into :
086:                     *
087:                     *  FunctionObjectFor"a" <-- instance variable init'd by constructor
088:                     *
089:                     *  // this is a DIRECTCALL node
090:                     *  fn = GetProp(tmp = GetBase("a"), "a");
091:                     *  if (fn == FunctionObjectFor"a")
092:                     *      fn.call(tmp, b, c)
093:                     *  else
094:                     *      ScriptRuntime.Call(fn, tmp, b, c)
095:                     */
096:                    if (possibleDirectCalls != null) {
097:                        String targetName = null;
098:                        if (left.getType() == Token.NAME) {
099:                            targetName = left.getString();
100:                        } else if (left.getType() == Token.GETPROP) {
101:                            targetName = left.getFirstChild().getNext()
102:                                    .getString();
103:                        } else if (left.getType() == Token.GETPROPNOWARN) {
104:                            throw Kit.codeBug();
105:                        }
106:                        if (targetName != null) {
107:                            OptFunctionNode ofn;
108:                            ofn = (OptFunctionNode) possibleDirectCalls
109:                                    .get(targetName);
110:                            if (ofn != null
111:                                    && argCount == ofn.fnode.getParamCount()
112:                                    && !ofn.fnode.requiresActivation()) {
113:                                // Refuse to directCall any function with more
114:                                // than 32 parameters - prevent code explosion
115:                                // for wacky test cases
116:                                if (argCount <= 32) {
117:                                    node.putProp(Node.DIRECTCALL_PROP, ofn);
118:                                    if (!ofn.isTargetOfDirectCall()) {
119:                                        int index = directCallTargets.size();
120:                                        directCallTargets.add(ofn);
121:                                        ofn.setDirectTargetIndex(index);
122:                                    }
123:                                }
124:                            }
125:                        }
126:                    }
127:                }
128:            }
129:
130:            private Hashtable possibleDirectCalls;
131:            private ObjArray directCallTargets;
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.