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

changeset 1374
c002fdee76fd
parent 1358
fc123bdeddb8
child 1381
23fe1a96bc0f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeTag.java	Thu Oct 25 11:09:36 2012 -0700
     1.3 @@ -0,0 +1,226 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. 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.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.code;
    1.30 +
    1.31 +import com.sun.source.tree.Tree.Kind;
    1.32 +
    1.33 +import javax.lang.model.type.TypeKind;
    1.34 +
    1.35 +/** An interface for type tag values, which distinguish between different
    1.36 + *  sorts of types.
    1.37 + *
    1.38 + *  <p><b>This is NOT part of any supported API.
    1.39 + *  If you write code that depends on this, you do so at your own risk.
    1.40 + *  This code and its internal interfaces are subject to change or
    1.41 + *  deletion without notice.</b>
    1.42 + */
    1.43 +public enum TypeTag {
    1.44 +    /** The tag of the basic type `byte'.
    1.45 +     */
    1.46 +    BYTE(1),
    1.47 +
    1.48 +    /** The tag of the basic type `char'.
    1.49 +     */
    1.50 +    CHAR(2),
    1.51 +
    1.52 +    /** The tag of the basic type `short'.
    1.53 +     */
    1.54 +    SHORT(3),
    1.55 +
    1.56 +    /** The tag of the basic type `int'.
    1.57 +     */
    1.58 +    INT(4),
    1.59 +
    1.60 +    /** The tag of the basic type `long'.
    1.61 +     */
    1.62 +    LONG(5),
    1.63 +
    1.64 +    /** The tag of the basic type `float'.
    1.65 +     */
    1.66 +    FLOAT(6),
    1.67 +
    1.68 +    /** The tag of the basic type `double'.
    1.69 +     */
    1.70 +    DOUBLE(7),
    1.71 +
    1.72 +    /** The tag of the basic type `boolean'.
    1.73 +     */
    1.74 +    BOOLEAN,
    1.75 +
    1.76 +    /** The tag of the type `void'.
    1.77 +     */
    1.78 +    VOID,
    1.79 +
    1.80 +    /** The tag of all class and interface types.
    1.81 +     */
    1.82 +    CLASS,
    1.83 +
    1.84 +    /** The tag of all array types.
    1.85 +     */
    1.86 +    ARRAY,
    1.87 +
    1.88 +    /** The tag of all (monomorphic) method types.
    1.89 +     */
    1.90 +    METHOD,
    1.91 +
    1.92 +    /** The tag of all package "types".
    1.93 +     */
    1.94 +    PACKAGE,
    1.95 +
    1.96 +    /** The tag of all (source-level) type variables.
    1.97 +     */
    1.98 +    TYPEVAR,
    1.99 +
   1.100 +    /** The tag of all type arguments.
   1.101 +     */
   1.102 +    WILDCARD,
   1.103 +
   1.104 +    /** The tag of all polymorphic (method-) types.
   1.105 +     */
   1.106 +    FORALL,
   1.107 +
   1.108 +    /** The tag of deferred expression types in method context
   1.109 +     */
   1.110 +    DEFERRED,
   1.111 +
   1.112 +    /** The tag of the bottom type <null>.
   1.113 +     */
   1.114 +    BOT,
   1.115 +
   1.116 +    /** The tag of a missing type.
   1.117 +     */
   1.118 +    NONE,
   1.119 +
   1.120 +    /** The tag of the error type.
   1.121 +     */
   1.122 +    ERROR,
   1.123 +
   1.124 +    /** The tag of an unknown type
   1.125 +     */
   1.126 +    UNKNOWN,
   1.127 +
   1.128 +    /** The tag of all instantiatable type variables.
   1.129 +     */
   1.130 +    UNDETVAR,
   1.131 +
   1.132 +    /** Pseudo-types, these are special tags
   1.133 +     */
   1.134 +    UNINITIALIZED_THIS,
   1.135 +
   1.136 +    UNINITIALIZED_OBJECT;
   1.137 +
   1.138 +    /** This field will only be used for tags related with numeric types for
   1.139 +     *  optimization reasons.
   1.140 +     */
   1.141 +    private int order = 0;
   1.142 +
   1.143 +    private TypeTag() {}
   1.144 +
   1.145 +    private TypeTag(int order) {
   1.146 +        this.order = order;
   1.147 +    }
   1.148 +
   1.149 +    private static final int MIN_NUMERIC_TAG_ORDER = 1;
   1.150 +    private static final int MAX_NUMERIC_TAG_ORDER = 7;
   1.151 +
   1.152 +    /** Returns the number of type tags.
   1.153 +     */
   1.154 +    public static int getTypeTagCount() {
   1.155 +        // last two tags are not included in the total as long as they are pseudo-types
   1.156 +        return (UNDETVAR.ordinal() + 1);
   1.157 +    }
   1.158 +
   1.159 +    public boolean isSubRangeOf(TypeTag range) {
   1.160 +        return (this == range) || isStrictSubRangeOf(range);
   1.161 +    }
   1.162 +
   1.163 +    public boolean isStrictSubRangeOf(TypeTag range) {
   1.164 +        if (this.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER &&
   1.165 +            range.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER) {
   1.166 +            if (this == range)
   1.167 +                return false;
   1.168 +            switch (this) {
   1.169 +                case BYTE:
   1.170 +                    return true;
   1.171 +                case CHAR: case SHORT: case INT:
   1.172 +                case LONG: case FLOAT:
   1.173 +                    return this.order < range.order && range.order <= MAX_NUMERIC_TAG_ORDER;
   1.174 +                default:
   1.175 +                    return false;
   1.176 +            }
   1.177 +        }
   1.178 +        else
   1.179 +            return false;
   1.180 +    }
   1.181 +
   1.182 +    public Kind getKindLiteral() {
   1.183 +        switch (this) {
   1.184 +        case INT:
   1.185 +            return Kind.INT_LITERAL;
   1.186 +        case LONG:
   1.187 +            return Kind.LONG_LITERAL;
   1.188 +        case FLOAT:
   1.189 +            return Kind.FLOAT_LITERAL;
   1.190 +        case DOUBLE:
   1.191 +            return Kind.DOUBLE_LITERAL;
   1.192 +        case BOOLEAN:
   1.193 +            return Kind.BOOLEAN_LITERAL;
   1.194 +        case CHAR:
   1.195 +            return Kind.CHAR_LITERAL;
   1.196 +        case CLASS:
   1.197 +            return Kind.STRING_LITERAL;
   1.198 +        case BOT:
   1.199 +            return Kind.NULL_LITERAL;
   1.200 +        default:
   1.201 +            throw new AssertionError("unknown literal kind " + this);
   1.202 +        }
   1.203 +    }
   1.204 +
   1.205 +    public TypeKind getPrimitiveTypeKind() {
   1.206 +        switch (this) {
   1.207 +        case BOOLEAN:
   1.208 +            return TypeKind.BOOLEAN;
   1.209 +        case BYTE:
   1.210 +            return TypeKind.BYTE;
   1.211 +        case SHORT:
   1.212 +            return TypeKind.SHORT;
   1.213 +        case INT:
   1.214 +            return TypeKind.INT;
   1.215 +        case LONG:
   1.216 +            return TypeKind.LONG;
   1.217 +        case CHAR:
   1.218 +            return TypeKind.CHAR;
   1.219 +        case FLOAT:
   1.220 +            return TypeKind.FLOAT;
   1.221 +        case DOUBLE:
   1.222 +            return TypeKind.DOUBLE;
   1.223 +        case VOID:
   1.224 +            return TypeKind.VOID;
   1.225 +        default:
   1.226 +            throw new AssertionError("unknown primitive type " + this);
   1.227 +        }
   1.228 +    }
   1.229 +}

mercurial