duke@1: /* ohair@158: * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@158: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@158: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@158: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@158: * or visit www.oracle.com if you need additional information or have any ohair@158: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * Licensed Materials - Property of IBM duke@1: * RMI-IIOP v1.0 duke@1: * Copyright IBM Corp. 1998 1999 All Rights Reserved duke@1: * duke@1: */ duke@1: duke@1: package sun.rmi.rmic.iiop; duke@1: duke@1: import sun.tools.java.CompilerError; duke@1: import sun.tools.java.Identifier; duke@1: import sun.tools.java.ClassDefinition; duke@1: duke@1: /** duke@1: * PrimitiveType wraps primitive types and void. duke@1: *

duke@1: * The static forPrimitive(...) method must be used to obtain an instance, and duke@1: * will return null if the type is non-conforming. duke@1: * duke@1: * @author Bryan Atsatt duke@1: */ duke@1: public class PrimitiveType extends Type { duke@1: duke@1: //_____________________________________________________________________ duke@1: // Public Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create a PrimitiveType object for the given type. duke@1: * duke@1: * If the type is not a properly formed or if some other error occurs, the duke@1: * return value will be null, and errors will have been reported to the duke@1: * supplied BatchEnvironment. duke@1: */ duke@1: public static PrimitiveType forPrimitive(sun.tools.java.Type type, duke@1: ContextStack stack) { duke@1: duke@1: if (stack.anyErrors()) return null; duke@1: duke@1: // Do we already have it? duke@1: duke@1: Type existing = getType(type,stack); duke@1: duke@1: if (existing != null) { duke@1: duke@1: if (!(existing instanceof PrimitiveType)) return null; // False hit. duke@1: duke@1: // Yep, so return it... duke@1: duke@1: return (PrimitiveType) existing; duke@1: } duke@1: duke@1: int typeCode; duke@1: duke@1: switch (type.getTypeCode()) { duke@1: case TC_VOID: typeCode = TYPE_VOID; break; duke@1: case TC_BOOLEAN: typeCode = TYPE_BOOLEAN; break; duke@1: case TC_BYTE: typeCode = TYPE_BYTE; break; duke@1: case TC_CHAR: typeCode = TYPE_CHAR; break; duke@1: case TC_SHORT: typeCode = TYPE_SHORT; break; duke@1: case TC_INT: typeCode = TYPE_INT; break; duke@1: case TC_LONG: typeCode = TYPE_LONG; break; duke@1: case TC_FLOAT: typeCode = TYPE_FLOAT; break; duke@1: case TC_DOUBLE: typeCode = TYPE_DOUBLE; break; duke@1: default: return null; duke@1: } duke@1: duke@1: PrimitiveType it = new PrimitiveType(stack,typeCode); duke@1: duke@1: // Add it... duke@1: duke@1: putType(type,it,stack); duke@1: duke@1: // Do the stack thing in case tracing on... duke@1: duke@1: stack.push(it); duke@1: stack.pop(true); duke@1: duke@1: return it; duke@1: } duke@1: duke@1: /** duke@1: * Return signature for this type (e.g. com.acme.Dynamite duke@1: * would return "com.acme.Dynamite", byte = "B") duke@1: */ duke@1: public String getSignature() { duke@1: switch (getTypeCode()) { duke@1: case TYPE_VOID: return SIG_VOID; duke@1: case TYPE_BOOLEAN: return SIG_BOOLEAN; duke@1: case TYPE_BYTE: return SIG_BYTE; duke@1: case TYPE_CHAR: return SIG_CHAR; duke@1: case TYPE_SHORT: return SIG_SHORT; duke@1: case TYPE_INT: return SIG_INT; duke@1: case TYPE_LONG: return SIG_LONG; duke@1: case TYPE_FLOAT: return SIG_FLOAT; duke@1: case TYPE_DOUBLE: return SIG_DOUBLE; duke@1: default: return null; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Return a string describing this type. duke@1: */ duke@1: public String getTypeDescription () { duke@1: return "Primitive"; duke@1: } duke@1: duke@1: /** duke@1: * IDL_Naming duke@1: * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would duke@1: * return "com::acme::Dynamite"). duke@1: * @param global If true, prepends "::". duke@1: */ duke@1: public String getQualifiedIDLName(boolean global) { duke@1: return super.getQualifiedIDLName(false); duke@1: } duke@1: duke@1: //_____________________________________________________________________ duke@1: // Subclass/Internal Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /* duke@1: * Load a Class instance. Return null if fail. duke@1: */ duke@1: protected Class loadClass() { duke@1: switch (getTypeCode()) { duke@1: case TYPE_VOID: return Null.class; duke@1: case TYPE_BOOLEAN: return boolean.class; duke@1: case TYPE_BYTE: return byte.class; duke@1: case TYPE_CHAR: return char.class; duke@1: case TYPE_SHORT: return short.class; duke@1: case TYPE_INT: return int.class; duke@1: case TYPE_LONG: return long.class; duke@1: case TYPE_FLOAT: return float.class; duke@1: case TYPE_DOUBLE: return double.class; duke@1: default: throw new CompilerError("Not a primitive type"); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * IDL_Naming duke@1: * Create an PrimitiveType instance for the given class. duke@1: */ duke@1: private PrimitiveType(ContextStack stack, int typeCode) { duke@1: super(stack,typeCode | TM_PRIMITIVE); duke@1: duke@1: // Validate type and set names... duke@1: duke@1: String idlName = IDLNames.getTypeName(typeCode,false); duke@1: Identifier id = null; duke@1: duke@1: switch (typeCode) { duke@1: case TYPE_VOID: id = idVoid; break; duke@1: case TYPE_BOOLEAN: id = idBoolean; break; duke@1: case TYPE_BYTE: id = idByte; break; duke@1: case TYPE_CHAR: id = idChar; break; duke@1: case TYPE_SHORT: id = idShort; break; duke@1: case TYPE_INT: id = idInt; break; duke@1: case TYPE_LONG: id = idLong; break; duke@1: case TYPE_FLOAT: id = idFloat; break; duke@1: case TYPE_DOUBLE: id = idDouble; break; duke@1: default: throw new CompilerError("Not a primitive type"); duke@1: } duke@1: duke@1: setNames(id,null,idlName); duke@1: setRepositoryID(); duke@1: } duke@1: } duke@1: duke@1: class Null {}