Source Code Cross Referenced for Instanceof.java in  » Scripting » Nice » nice » lang » inline » 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.lang.inline 
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.lang.inline;
012:
013:        /**
014:         Tests if a value belongs to a class.
015:
016:         The second parameter should be a QuoteExp wrapping a 
017:         <code>gnu.bytecode.Type</code>.
018:
019:         @version $Date: 2005/03/09 14:47:48 $
020:         @author Daniel Bonniot (Daniel.Bonniot@inria.fr)
021:         */
022:
023:        import gnu.bytecode.*;
024:        import gnu.mapping.*;
025:        import gnu.expr.*;
026:
027:        public class Instanceof extends Procedure2 implements  Inlineable {
028:            private final boolean option;
029:
030:            public static Instanceof create(String param) {
031:                if ("option".equals(param))
032:                    return optionInstance;
033:
034:                return instance;
035:            }
036:
037:            private Instanceof(boolean option) {
038:                this .option = option;
039:            }
040:
041:            public final static Instanceof instance = new Instanceof(false);
042:            public final static Instanceof optionInstance = new Instanceof(true);
043:
044:            public void compile(ApplyExp exp, Compilation comp, Target target) {
045:                Expression[] args = exp.getArgs();
046:                Expression value = args[0];
047:                Expression typeExp = args[1];
048:
049:                if (typeExp instanceof  QuoteExp
050:                        && ((QuoteExp) typeExp).getValue() instanceof  Type)
051:                    compile(value, (Type) ((QuoteExp) typeExp).getValue(),
052:                            comp, exp);
053:                else
054:                    compile(value, typeExp, comp);
055:
056:                target.compileFromStack(comp, Type.boolean_type);
057:            }
058:
059:            private void compile(Expression value, Type type, Compilation comp,
060:                    Expression applyExp) {
061:                gnu.bytecode.CodeAttr code = comp.getCode();
062:
063:                // instanceof on boolean can make sense
064:                if (type == Type.boolean_type)
065:                    type = Type.boolean_ctype;
066:
067:                if (type instanceof  PrimType)
068:                    throw new bossa.util.UserError(applyExp,
069:                            "instanceof cannot be used with primitive types");
070:
071:                value.compile(comp, Target.pushObject);
072:
073:                if (type == nice.tools.code.SpecialArray.wrappedType()
074:                        && code.topType().isArray()) {
075:                    /* If we want to test if the value is 'instanceof Array', and 
076:                       we know statically that it is an array, we just need to make
077:                       sure it is not null.
078:                     */
079:                    if (option)
080:                        code.emitPushBoolean(true);
081:                    else {
082:                        code.emitIfNull();
083:                        code.emitPushBoolean(false);
084:                        code.emitElse();
085:                        code.emitPushBoolean(true);
086:                        code.emitFi();
087:                    }
088:                } else {
089:                    if (option) {
090:                        code.emitDup();
091:                        code.emitIfNull();
092:                        code.emitPop(1);
093:                        code.emitPushBoolean(true);
094:                        code.emitElse();
095:                    }
096:
097:                    code.emitInstanceof(type);
098:
099:                    if (option)
100:                        code.emitFi();
101:                }
102:            }
103:
104:            private void compile(Expression value, Expression type,
105:                    Compilation comp) {
106:                gnu.bytecode.CodeAttr code = comp.getCode();
107:
108:                if (option) {
109:                    code.emitDup();
110:                    code.emitIfNull();
111:                    code.emitPop(1);
112:                    code.emitPushBoolean(true);
113:                    code.emitElse();
114:                }
115:
116:                type.compile(comp, Target.pushObject);
117:                value.compile(comp, Target.pushObject);
118:                code.emitInvoke(ClassType.make("java.lang.Class")
119:                        .getDeclaredMethod("isInstance", 1));
120:
121:                if (option)
122:                    code.emitFi();
123:            }
124:
125:            public Type getReturnType(Expression[] args) {
126:                return Type.boolean_type;
127:            }
128:
129:            /****************************************************************
130:             * Interpretation
131:             ****************************************************************/
132:
133:            public Object apply2(Object arg1, Object arg2) {
134:                throw new Error("Not implemented");
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.