Source Code Cross Referenced for LiteralArrayProc.java in  » Scripting » Nice » nice » tools » code » 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 » Nice » nice.tools.code 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************/
002:        /*                                N I C E                                 */
003:        /*             A high-level object-oriented research language             */
004:        /*                        (c) Daniel Bonniot 2002                         */
005:        /*                                                                        */
006:        /*  This program is free software; you can redistribute it and/or modify  */
007:        /*  it under the terms of the GNU General Public License as published by  */
008:        /*  the Free Software Foundation; either version 2 of the License, or     */
009:        /*  (at your option) any later version.                                   */
010:        /*                                                                        */
011:        /**************************************************************************/package nice.tools.code;
012:
013:        import gnu.expr.*;
014:        import gnu.bytecode.*;
015:
016:        /**
017:         Creates a literal array constant.
018:        
019:         @author Daniel Bonniot
020:         */
021:
022:        public class LiteralArrayProc extends gnu.mapping.ProcedureN implements 
023:                Inlineable {
024:            /**
025:               @param arrayType the type of the array
026:               @param nbElements the number of elements of the array
027:                 The corresponding number of elements are expected as arguments 
028:                 of the procedure.
029:             */
030:            public LiteralArrayProc(ArrayType arrayType, int nbElements,
031:                    boolean wrapAsCollection) {
032:                this .arrayType = arrayType;
033:                this .nbElements = nbElements;
034:                this .wrapAsCollection = wrapAsCollection;
035:            }
036:
037:            private ArrayType arrayType;
038:            private int nbElements;
039:            private boolean wrapAsCollection;
040:
041:            public void compile(ApplyExp exp, Compilation comp, Target target) {
042:                // The type was not specified explicitely, so we allow promotion.
043:                arrayType = MultiArrayNewProc.creationType(arrayType, target,
044:                        true);
045:
046:                Expression[] args = exp.getArgs();
047:                CodeAttr code = comp.getCode();
048:
049:                Type componentType = arrayType.getComponentType()
050:                        .getImplementationType();
051:
052:                code.emitPushInt(nbElements);
053:                code.emitNewArray(componentType);
054:
055:                // Set a special type, not the legacy array type.
056:                code.popType();
057:                code.pushType(arrayType);
058:
059:                /*
060:                  Optimization:
061:                  We need to keep the reference to the array.
062:
063:                  Instead of `dup'ing it before each use,
064:                  we `dup2' it every second iteration.
065:
066:                  This is better than producing all the references in advance,
067:                  which would make the stack grow unboundedly.
068:
069:                  This saves nbElements/2 bytecodes.
070:                 */
071:
072:                if (nbElements > 0)
073:                    code.emitDup();
074:
075:                for (int i = 0; i < nbElements; i++) {
076:                    // Duplicate the reference to the array, according to our future needs.
077:                    if (i % 2 == 0)
078:                        if (i < nbElements - 2)
079:                            code.emitDup(2);
080:                        else if (i == nbElements - 2)
081:                            code.emitDup();
082:
083:                    // Get the specific type for this rank of the array (useful for tuples)
084:                    Type specificType = Types.componentType(arrayType, i);
085:                    // Only use it if it is more specific than the expected type.
086:                    // For instance don't use int if we store it in an Object[] anyway.
087:                    if (!specificType.isAssignableTo(componentType))
088:                        specificType = componentType;
089:
090:                    code.emitPushInt(i);
091:                    args[i].compile(comp, specificType);
092:                    code.emitArrayStore(componentType);
093:                }
094:
095:                if (wrapAsCollection)
096:                    SpecialArray.emitCoerceToCollection(code);
097:                else
098:                    target.compileFromStack(comp, code.topType());
099:            }
100:
101:            public Type getReturnType(Expression[] args) {
102:                if (wrapAsCollection)
103:                    return ClassType.make("java.util.List");
104:
105:                return arrayType;
106:            }
107:
108:            public Object applyN(Object[] args) {
109:                throw new Error("Not implemented");
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.