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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial