src/share/classes/com/sun/tools/javac/code/TypeTag.java

Sun, 17 Feb 2013 16:44:55 -0500

author
dholmes
date
Sun, 17 Feb 2013 16:44:55 -0500
changeset 1571
af8417e590f4
parent 1442
fcf89720ae71
child 1826
9851071b551a
permissions
-rw-r--r--

Merge

duke@1 1 /*
jjg@1358 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.code;
duke@1 27
jjg@1374 28 import com.sun.source.tree.Tree.Kind;
jjg@1374 29
jjg@1374 30 import javax.lang.model.type.TypeKind;
duke@1 31
duke@1 32 /** An interface for type tag values, which distinguish between different
duke@1 33 * sorts of types.
duke@1 34 *
jjg@581 35 * <p><b>This is NOT part of any supported API.
jjg@581 36 * If you write code that depends on this, you do so at your own risk.
duke@1 37 * This code and its internal interfaces are subject to change or
duke@1 38 * deletion without notice.</b>
duke@1 39 */
jjg@1374 40 public enum TypeTag {
duke@1 41 /** The tag of the basic type `byte'.
duke@1 42 */
jjg@1374 43 BYTE(1),
duke@1 44
duke@1 45 /** The tag of the basic type `char'.
duke@1 46 */
jjg@1374 47 CHAR(2),
duke@1 48
duke@1 49 /** The tag of the basic type `short'.
duke@1 50 */
jjg@1374 51 SHORT(3),
duke@1 52
duke@1 53 /** The tag of the basic type `int'.
duke@1 54 */
jjg@1374 55 INT(4),
duke@1 56
duke@1 57 /** The tag of the basic type `long'.
duke@1 58 */
jjg@1374 59 LONG(5),
duke@1 60
duke@1 61 /** The tag of the basic type `float'.
duke@1 62 */
jjg@1374 63 FLOAT(6),
duke@1 64
duke@1 65 /** The tag of the basic type `double'.
duke@1 66 */
jjg@1374 67 DOUBLE(7),
duke@1 68
duke@1 69 /** The tag of the basic type `boolean'.
duke@1 70 */
jjg@1374 71 BOOLEAN,
duke@1 72
duke@1 73 /** The tag of the type `void'.
duke@1 74 */
jjg@1374 75 VOID,
duke@1 76
duke@1 77 /** The tag of all class and interface types.
duke@1 78 */
jjg@1374 79 CLASS,
duke@1 80
duke@1 81 /** The tag of all array types.
duke@1 82 */
jjg@1374 83 ARRAY,
duke@1 84
duke@1 85 /** The tag of all (monomorphic) method types.
duke@1 86 */
jjg@1374 87 METHOD,
duke@1 88
duke@1 89 /** The tag of all package "types".
duke@1 90 */
jjg@1374 91 PACKAGE,
duke@1 92
duke@1 93 /** The tag of all (source-level) type variables.
duke@1 94 */
jjg@1374 95 TYPEVAR,
duke@1 96
duke@1 97 /** The tag of all type arguments.
duke@1 98 */
jjg@1374 99 WILDCARD,
duke@1 100
duke@1 101 /** The tag of all polymorphic (method-) types.
duke@1 102 */
jjg@1374 103 FORALL,
duke@1 104
mcimadamore@1347 105 /** The tag of deferred expression types in method context
mcimadamore@1347 106 */
jjg@1374 107 DEFERRED,
mcimadamore@1347 108
jjg@1381 109 /** The tag of the bottom type {@code <null>}.
duke@1 110 */
jjg@1374 111 BOT,
duke@1 112
duke@1 113 /** The tag of a missing type.
duke@1 114 */
jjg@1374 115 NONE,
duke@1 116
duke@1 117 /** The tag of the error type.
duke@1 118 */
jjg@1374 119 ERROR,
duke@1 120
duke@1 121 /** The tag of an unknown type
duke@1 122 */
jjg@1374 123 UNKNOWN,
duke@1 124
duke@1 125 /** The tag of all instantiatable type variables.
duke@1 126 */
jjg@1374 127 UNDETVAR,
duke@1 128
jjg@1374 129 /** Pseudo-types, these are special tags
duke@1 130 */
jjg@1374 131 UNINITIALIZED_THIS,
duke@1 132
jjg@1374 133 UNINITIALIZED_OBJECT;
jjg@1374 134
jjg@1374 135 /** This field will only be used for tags related with numeric types for
jjg@1374 136 * optimization reasons.
duke@1 137 */
vromero@1442 138 private final int order;
duke@1 139
vromero@1442 140 private TypeTag() {
vromero@1442 141 this(0);
vromero@1442 142 }
jjg@1374 143
jjg@1374 144 private TypeTag(int order) {
jjg@1374 145 this.order = order;
jjg@1374 146 }
jjg@1374 147
jjg@1374 148 private static final int MIN_NUMERIC_TAG_ORDER = 1;
jjg@1374 149 private static final int MAX_NUMERIC_TAG_ORDER = 7;
jjg@1374 150
jjg@1374 151 /** Returns the number of type tags.
duke@1 152 */
jjg@1374 153 public static int getTypeTagCount() {
jjg@1374 154 // last two tags are not included in the total as long as they are pseudo-types
jjg@1374 155 return (UNDETVAR.ordinal() + 1);
jjg@1374 156 }
jjg@1374 157
jjg@1374 158 public boolean isSubRangeOf(TypeTag range) {
jjg@1374 159 return (this == range) || isStrictSubRangeOf(range);
jjg@1374 160 }
jjg@1374 161
jjg@1374 162 public boolean isStrictSubRangeOf(TypeTag range) {
jjg@1374 163 if (this.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER &&
jjg@1374 164 range.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER) {
jjg@1374 165 if (this == range)
jjg@1374 166 return false;
jjg@1374 167 switch (this) {
jjg@1374 168 case BYTE:
jjg@1374 169 return true;
jjg@1374 170 case CHAR: case SHORT: case INT:
jjg@1374 171 case LONG: case FLOAT:
jjg@1374 172 return this.order < range.order && range.order <= MAX_NUMERIC_TAG_ORDER;
jjg@1374 173 default:
jjg@1374 174 return false;
jjg@1374 175 }
jjg@1374 176 }
jjg@1374 177 else
jjg@1374 178 return false;
jjg@1374 179 }
jjg@1374 180
jjg@1374 181 public Kind getKindLiteral() {
jjg@1374 182 switch (this) {
jjg@1374 183 case INT:
jjg@1374 184 return Kind.INT_LITERAL;
jjg@1374 185 case LONG:
jjg@1374 186 return Kind.LONG_LITERAL;
jjg@1374 187 case FLOAT:
jjg@1374 188 return Kind.FLOAT_LITERAL;
jjg@1374 189 case DOUBLE:
jjg@1374 190 return Kind.DOUBLE_LITERAL;
jjg@1374 191 case BOOLEAN:
jjg@1374 192 return Kind.BOOLEAN_LITERAL;
jjg@1374 193 case CHAR:
jjg@1374 194 return Kind.CHAR_LITERAL;
jjg@1374 195 case CLASS:
jjg@1374 196 return Kind.STRING_LITERAL;
jjg@1374 197 case BOT:
jjg@1374 198 return Kind.NULL_LITERAL;
jjg@1374 199 default:
jjg@1374 200 throw new AssertionError("unknown literal kind " + this);
jjg@1374 201 }
jjg@1374 202 }
jjg@1374 203
jjg@1374 204 public TypeKind getPrimitiveTypeKind() {
jjg@1374 205 switch (this) {
jjg@1374 206 case BOOLEAN:
jjg@1374 207 return TypeKind.BOOLEAN;
jjg@1374 208 case BYTE:
jjg@1374 209 return TypeKind.BYTE;
jjg@1374 210 case SHORT:
jjg@1374 211 return TypeKind.SHORT;
jjg@1374 212 case INT:
jjg@1374 213 return TypeKind.INT;
jjg@1374 214 case LONG:
jjg@1374 215 return TypeKind.LONG;
jjg@1374 216 case CHAR:
jjg@1374 217 return TypeKind.CHAR;
jjg@1374 218 case FLOAT:
jjg@1374 219 return TypeKind.FLOAT;
jjg@1374 220 case DOUBLE:
jjg@1374 221 return TypeKind.DOUBLE;
jjg@1374 222 case VOID:
jjg@1374 223 return TypeKind.VOID;
jjg@1374 224 default:
jjg@1374 225 throw new AssertionError("unknown primitive type " + this);
jjg@1374 226 }
jjg@1374 227 }
duke@1 228 }

mercurial