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

changeset 1374
c002fdee76fd
parent 1358
fc123bdeddb8
child 1393
d7d932236fee
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Oct 23 13:58:56 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Oct 25 11:09:36 2012 -0700
     1.3 @@ -40,7 +40,7 @@
     1.4  import static com.sun.tools.javac.code.Scope.*;
     1.5  import static com.sun.tools.javac.code.Symbol.*;
     1.6  import static com.sun.tools.javac.code.Type.*;
     1.7 -import static com.sun.tools.javac.code.TypeTags.*;
     1.8 +import static com.sun.tools.javac.code.TypeTag.*;
     1.9  import static com.sun.tools.javac.util.ListBuffer.lb;
    1.10  
    1.11  /**
    1.12 @@ -605,8 +605,8 @@
    1.13      }
    1.14      //where
    1.15          private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
    1.16 -            if (t.tag == ARRAY && s.tag == ARRAY) {
    1.17 -                if (((ArrayType)t).elemtype.tag <= lastBaseTag) {
    1.18 +            if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) {
    1.19 +                if (((ArrayType)t).elemtype.isPrimitive()) {
    1.20                      return isSameType(elemtype(t), elemtype(s));
    1.21                  } else {
    1.22                      return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
    1.23 @@ -664,7 +664,7 @@
    1.24          if (t == s)
    1.25              return true;
    1.26  
    1.27 -        if (s.tag >= firstPartialTag)
    1.28 +        if (s.isPartial())
    1.29              return isSuperType(s, t);
    1.30  
    1.31          if (s.isCompound()) {
    1.32 @@ -686,25 +686,27 @@
    1.33          {
    1.34              public Boolean visitType(Type t, Type s) {
    1.35                  switch (t.tag) {
    1.36 -                case BYTE: case CHAR:
    1.37 -                    return (t.tag == s.tag ||
    1.38 -                              t.tag + 2 <= s.tag && s.tag <= DOUBLE);
    1.39 -                case SHORT: case INT: case LONG: case FLOAT: case DOUBLE:
    1.40 -                    return t.tag <= s.tag && s.tag <= DOUBLE;
    1.41 -                case BOOLEAN: case VOID:
    1.42 -                    return t.tag == s.tag;
    1.43 -                case TYPEVAR:
    1.44 -                    return isSubtypeNoCapture(t.getUpperBound(), s);
    1.45 -                case BOT:
    1.46 -                    return
    1.47 -                        s.tag == BOT || s.tag == CLASS ||
    1.48 -                        s.tag == ARRAY || s.tag == TYPEVAR;
    1.49 -                case WILDCARD: //we shouldn't be here - avoids crash (see 7034495)
    1.50 -                case NONE:
    1.51 -                    return false;
    1.52 -                default:
    1.53 -                    throw new AssertionError("isSubtype " + t.tag);
    1.54 -                }
    1.55 +                 case BYTE:
    1.56 +                     return (!s.hasTag(CHAR) && t.getTag().isSubRangeOf(s.getTag()));
    1.57 +                 case CHAR:
    1.58 +                     return (!s.hasTag(SHORT) && t.getTag().isSubRangeOf(s.getTag()));
    1.59 +                 case SHORT: case INT: case LONG:
    1.60 +                 case FLOAT: case DOUBLE:
    1.61 +                     return t.getTag().isSubRangeOf(s.getTag());
    1.62 +                 case BOOLEAN: case VOID:
    1.63 +                     return t.hasTag(s.getTag());
    1.64 +                 case TYPEVAR:
    1.65 +                     return isSubtypeNoCapture(t.getUpperBound(), s);
    1.66 +                 case BOT:
    1.67 +                     return
    1.68 +                         s.hasTag(BOT) || s.hasTag(CLASS) ||
    1.69 +                         s.hasTag(ARRAY) || s.hasTag(TYPEVAR);
    1.70 +                 case WILDCARD: //we shouldn't be here - avoids crash (see 7034495)
    1.71 +                 case NONE:
    1.72 +                     return false;
    1.73 +                 default:
    1.74 +                     throw new AssertionError("isSubtype " + t.tag);
    1.75 +                 }
    1.76              }
    1.77  
    1.78              private Set<TypePair> cache = new HashSet<TypePair>();
    1.79 @@ -774,7 +776,7 @@
    1.80              @Override
    1.81              public Boolean visitArrayType(ArrayType t, Type s) {
    1.82                  if (s.tag == ARRAY) {
    1.83 -                    if (t.elemtype.tag <= lastBaseTag)
    1.84 +                    if (t.elemtype.isPrimitive())
    1.85                          return isSameType(t.elemtype, elemtype(s));
    1.86                      else
    1.87                          return isSubtypeNoCapture(t.elemtype, elemtype(s));
    1.88 @@ -907,7 +909,7 @@
    1.89                  if (t == s)
    1.90                      return true;
    1.91  
    1.92 -                if (s.tag >= firstPartialTag)
    1.93 +                if (s.isPartial())
    1.94                      return visit(s, t);
    1.95  
    1.96                  switch (t.tag) {
    1.97 @@ -936,7 +938,7 @@
    1.98  
    1.99              @Override
   1.100              public Boolean visitWildcardType(WildcardType t, Type s) {
   1.101 -                if (s.tag >= firstPartialTag)
   1.102 +                if (s.isPartial())
   1.103                      return visit(s, t);
   1.104                  else
   1.105                      return false;
   1.106 @@ -947,7 +949,7 @@
   1.107                  if (t == s)
   1.108                      return true;
   1.109  
   1.110 -                if (s.tag >= firstPartialTag)
   1.111 +                if (s.isPartial())
   1.112                      return visit(s, t);
   1.113  
   1.114                  if (s.isSuperBound() && !s.isExtendsBound())
   1.115 @@ -976,10 +978,10 @@
   1.116                  if (t == s)
   1.117                      return true;
   1.118  
   1.119 -                if (s.tag >= firstPartialTag)
   1.120 +                if (s.isPartial())
   1.121                      return visit(s, t);
   1.122  
   1.123 -                return s.tag == ARRAY
   1.124 +                return s.hasTag(ARRAY)
   1.125                      && containsTypeEquivalent(t.elemtype, elemtype(s));
   1.126              }
   1.127  
   1.128 @@ -1120,7 +1122,7 @@
   1.129              }
   1.130  
   1.131              public Boolean visitType(Type t, Type s) {
   1.132 -                if (s.tag >= firstPartialTag)
   1.133 +                if (s.isPartial())
   1.134                      return containedBy(s, t);
   1.135                  else
   1.136                      return isSameType(t, s);
   1.137 @@ -1142,7 +1144,7 @@
   1.138  
   1.139              @Override
   1.140              public Boolean visitWildcardType(WildcardType t, Type s) {
   1.141 -                if (s.tag >= firstPartialTag)
   1.142 +                if (s.isPartial())
   1.143                      return containedBy(s, t);
   1.144                  else {
   1.145  //                    debugContainsType(t, s);
   1.146 @@ -1232,7 +1234,7 @@
   1.147                  switch (t.tag) {
   1.148                  case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
   1.149                  case DOUBLE:
   1.150 -                    return s.tag <= DOUBLE;
   1.151 +                    return s.isNumeric();
   1.152                  case BOOLEAN:
   1.153                      return s.tag == BOOLEAN;
   1.154                  case VOID:
   1.155 @@ -1373,8 +1375,7 @@
   1.156                  case CLASS:
   1.157                      return isSubtype(t, s);
   1.158                  case ARRAY:
   1.159 -                    if (elemtype(t).tag <= lastBaseTag ||
   1.160 -                            elemtype(s).tag <= lastBaseTag) {
   1.161 +                    if (elemtype(t).isPrimitive() || elemtype(s).isPrimitive()) {
   1.162                          return elemtype(t).tag == elemtype(s).tag;
   1.163                      } else {
   1.164                          return visit(elemtype(t), elemtype(s));
   1.165 @@ -1648,8 +1649,8 @@
   1.166       */
   1.167      public ArrayType makeArrayType(Type t) {
   1.168          if (t.tag == VOID ||
   1.169 -            t.tag >= PACKAGE) {
   1.170 -            Assert.error("Type t must not be a a VOID or PACKAGE type, " + t.toString());
   1.171 +            t.tag == PACKAGE) {
   1.172 +            Assert.error("Type t must not be a VOID or PACKAGE type, " + t.toString());
   1.173          }
   1.174          return new ArrayType(t, syms.arrayClass);
   1.175      }
   1.176 @@ -1847,7 +1848,7 @@
   1.177      public boolean isAssignable(Type t, Type s, Warner warn) {
   1.178          if (t.tag == ERROR)
   1.179              return true;
   1.180 -        if (t.tag <= INT && t.constValue() != null) {
   1.181 +        if (t.tag.isSubRangeOf(INT) && t.constValue() != null) {
   1.182              int value = ((Number)t.constValue()).intValue();
   1.183              switch (s.tag) {
   1.184              case BYTE:
   1.185 @@ -1891,11 +1892,11 @@
   1.186          // We don't want to erase primitive types and String type as that
   1.187          // operation is idempotent. Also, erasing these could result in loss
   1.188          // of information such as constant values attached to such types.
   1.189 -        return (t.tag <= lastBaseTag) || (syms.stringType.tsym == t.tsym);
   1.190 +        return (t.isPrimitive()) || (syms.stringType.tsym == t.tsym);
   1.191      }
   1.192  
   1.193      private Type erasure(Type t, boolean recurse) {
   1.194 -        if (t.tag <= lastBaseTag)
   1.195 +        if (t.isPrimitive())
   1.196              return t; /* fast special case */
   1.197          else
   1.198              return erasure.visit(t, recurse);
   1.199 @@ -1903,7 +1904,7 @@
   1.200      // where
   1.201          private SimpleVisitor<Type, Boolean> erasure = new SimpleVisitor<Type, Boolean>() {
   1.202              public Type visitType(Type t, Boolean recurse) {
   1.203 -                if (t.tag <= lastBaseTag)
   1.204 +                if (t.isPrimitive())
   1.205                      return t; /*fast special case*/
   1.206                  else
   1.207                      return t.map(recurse ? erasureRecFun : erasureFun);
   1.208 @@ -3314,7 +3315,7 @@
   1.209          private static final UnaryVisitor<Integer> hashCode = new UnaryVisitor<Integer>() {
   1.210  
   1.211              public Integer visitType(Type t, Void ignored) {
   1.212 -                return t.tag;
   1.213 +                return t.tag.ordinal();
   1.214              }
   1.215  
   1.216              @Override
   1.217 @@ -3430,7 +3431,7 @@
   1.218       * Return the class that boxes the given primitive.
   1.219       */
   1.220      public ClassSymbol boxedClass(Type t) {
   1.221 -        return reader.enterClass(syms.boxedName[t.tag]);
   1.222 +        return reader.enterClass(syms.boxedName[t.tag.ordinal()]);
   1.223      }
   1.224  
   1.225      /**

mercurial