1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/sun/rmi/rmic/iiop/PrimitiveType.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,195 @@ 1.4 +/* 1.5 + * Portions Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +/* 1.30 + * Licensed Materials - Property of IBM 1.31 + * RMI-IIOP v1.0 1.32 + * Copyright IBM Corp. 1998 1999 All Rights Reserved 1.33 + * 1.34 + */ 1.35 + 1.36 +package sun.rmi.rmic.iiop; 1.37 + 1.38 +import sun.tools.java.CompilerError; 1.39 +import sun.tools.java.Identifier; 1.40 +import sun.tools.java.ClassDefinition; 1.41 + 1.42 +/** 1.43 + * PrimitiveType wraps primitive types and void. 1.44 + * <p> 1.45 + * The static forPrimitive(...) method must be used to obtain an instance, and 1.46 + * will return null if the type is non-conforming. 1.47 + * 1.48 + * @author Bryan Atsatt 1.49 + */ 1.50 +public class PrimitiveType extends Type { 1.51 + 1.52 + //_____________________________________________________________________ 1.53 + // Public Interfaces 1.54 + //_____________________________________________________________________ 1.55 + 1.56 + /** 1.57 + * Create a PrimitiveType object for the given type. 1.58 + * 1.59 + * If the type is not a properly formed or if some other error occurs, the 1.60 + * return value will be null, and errors will have been reported to the 1.61 + * supplied BatchEnvironment. 1.62 + */ 1.63 + public static PrimitiveType forPrimitive(sun.tools.java.Type type, 1.64 + ContextStack stack) { 1.65 + 1.66 + if (stack.anyErrors()) return null; 1.67 + 1.68 + // Do we already have it? 1.69 + 1.70 + Type existing = getType(type,stack); 1.71 + 1.72 + if (existing != null) { 1.73 + 1.74 + if (!(existing instanceof PrimitiveType)) return null; // False hit. 1.75 + 1.76 + // Yep, so return it... 1.77 + 1.78 + return (PrimitiveType) existing; 1.79 + } 1.80 + 1.81 + int typeCode; 1.82 + 1.83 + switch (type.getTypeCode()) { 1.84 + case TC_VOID: typeCode = TYPE_VOID; break; 1.85 + case TC_BOOLEAN: typeCode = TYPE_BOOLEAN; break; 1.86 + case TC_BYTE: typeCode = TYPE_BYTE; break; 1.87 + case TC_CHAR: typeCode = TYPE_CHAR; break; 1.88 + case TC_SHORT: typeCode = TYPE_SHORT; break; 1.89 + case TC_INT: typeCode = TYPE_INT; break; 1.90 + case TC_LONG: typeCode = TYPE_LONG; break; 1.91 + case TC_FLOAT: typeCode = TYPE_FLOAT; break; 1.92 + case TC_DOUBLE: typeCode = TYPE_DOUBLE; break; 1.93 + default: return null; 1.94 + } 1.95 + 1.96 + PrimitiveType it = new PrimitiveType(stack,typeCode); 1.97 + 1.98 + // Add it... 1.99 + 1.100 + putType(type,it,stack); 1.101 + 1.102 + // Do the stack thing in case tracing on... 1.103 + 1.104 + stack.push(it); 1.105 + stack.pop(true); 1.106 + 1.107 + return it; 1.108 + } 1.109 + 1.110 + /** 1.111 + * Return signature for this type (e.g. com.acme.Dynamite 1.112 + * would return "com.acme.Dynamite", byte = "B") 1.113 + */ 1.114 + public String getSignature() { 1.115 + switch (getTypeCode()) { 1.116 + case TYPE_VOID: return SIG_VOID; 1.117 + case TYPE_BOOLEAN: return SIG_BOOLEAN; 1.118 + case TYPE_BYTE: return SIG_BYTE; 1.119 + case TYPE_CHAR: return SIG_CHAR; 1.120 + case TYPE_SHORT: return SIG_SHORT; 1.121 + case TYPE_INT: return SIG_INT; 1.122 + case TYPE_LONG: return SIG_LONG; 1.123 + case TYPE_FLOAT: return SIG_FLOAT; 1.124 + case TYPE_DOUBLE: return SIG_DOUBLE; 1.125 + default: return null; 1.126 + } 1.127 + } 1.128 + 1.129 + /** 1.130 + * Return a string describing this type. 1.131 + */ 1.132 + public String getTypeDescription () { 1.133 + return "Primitive"; 1.134 + } 1.135 + 1.136 + /** 1.137 + * IDL_Naming 1.138 + * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would 1.139 + * return "com::acme::Dynamite"). 1.140 + * @param global If true, prepends "::". 1.141 + */ 1.142 + public String getQualifiedIDLName(boolean global) { 1.143 + return super.getQualifiedIDLName(false); 1.144 + } 1.145 + 1.146 + //_____________________________________________________________________ 1.147 + // Subclass/Internal Interfaces 1.148 + //_____________________________________________________________________ 1.149 + 1.150 + /* 1.151 + * Load a Class instance. Return null if fail. 1.152 + */ 1.153 + protected Class loadClass() { 1.154 + switch (getTypeCode()) { 1.155 + case TYPE_VOID: return Null.class; 1.156 + case TYPE_BOOLEAN: return boolean.class; 1.157 + case TYPE_BYTE: return byte.class; 1.158 + case TYPE_CHAR: return char.class; 1.159 + case TYPE_SHORT: return short.class; 1.160 + case TYPE_INT: return int.class; 1.161 + case TYPE_LONG: return long.class; 1.162 + case TYPE_FLOAT: return float.class; 1.163 + case TYPE_DOUBLE: return double.class; 1.164 + default: throw new CompilerError("Not a primitive type"); 1.165 + } 1.166 + } 1.167 + 1.168 + /** 1.169 + * IDL_Naming 1.170 + * Create an PrimitiveType instance for the given class. 1.171 + */ 1.172 + private PrimitiveType(ContextStack stack, int typeCode) { 1.173 + super(stack,typeCode | TM_PRIMITIVE); 1.174 + 1.175 + // Validate type and set names... 1.176 + 1.177 + String idlName = IDLNames.getTypeName(typeCode,false); 1.178 + Identifier id = null; 1.179 + 1.180 + switch (typeCode) { 1.181 + case TYPE_VOID: id = idVoid; break; 1.182 + case TYPE_BOOLEAN: id = idBoolean; break; 1.183 + case TYPE_BYTE: id = idByte; break; 1.184 + case TYPE_CHAR: id = idChar; break; 1.185 + case TYPE_SHORT: id = idShort; break; 1.186 + case TYPE_INT: id = idInt; break; 1.187 + case TYPE_LONG: id = idLong; break; 1.188 + case TYPE_FLOAT: id = idFloat; break; 1.189 + case TYPE_DOUBLE: id = idDouble; break; 1.190 + default: throw new CompilerError("Not a primitive type"); 1.191 + } 1.192 + 1.193 + setNames(id,null,idlName); 1.194 + setRepositoryID(); 1.195 + } 1.196 +} 1.197 + 1.198 +class Null {}