Thu, 05 Jan 2017 18:58:06 +0000
8168774: Polymorhic signature method check crashes javac
Summary: Check for polysig method assumes arity is greater than zero
Reviewed-by: vromero
duke@1 | 1 | /* |
vromero@1826 | 2 | * Copyright (c) 1999, 2013, 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 | |
vromero@1826 | 32 | import static com.sun.tools.javac.code.TypeTag.NumericClasses.*; |
vromero@1826 | 33 | |
duke@1 | 34 | /** An interface for type tag values, which distinguish between different |
duke@1 | 35 | * sorts of types. |
duke@1 | 36 | * |
jjg@581 | 37 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 38 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 39 | * This code and its internal interfaces are subject to change or |
duke@1 | 40 | * deletion without notice.</b> |
duke@1 | 41 | */ |
jjg@1374 | 42 | public enum TypeTag { |
duke@1 | 43 | /** The tag of the basic type `byte'. |
duke@1 | 44 | */ |
vromero@1853 | 45 | BYTE(BYTE_CLASS, BYTE_SUPERCLASSES, true), |
duke@1 | 46 | |
duke@1 | 47 | /** The tag of the basic type `char'. |
duke@1 | 48 | */ |
vromero@1853 | 49 | CHAR(CHAR_CLASS, CHAR_SUPERCLASSES, true), |
duke@1 | 50 | |
duke@1 | 51 | /** The tag of the basic type `short'. |
duke@1 | 52 | */ |
vromero@1853 | 53 | SHORT(SHORT_CLASS, SHORT_SUPERCLASSES, true), |
duke@1 | 54 | |
duke@1 | 55 | /** The tag of the basic type `long'. |
duke@1 | 56 | */ |
vromero@1853 | 57 | LONG(LONG_CLASS, LONG_SUPERCLASSES, true), |
duke@1 | 58 | |
duke@1 | 59 | /** The tag of the basic type `float'. |
duke@1 | 60 | */ |
vromero@1853 | 61 | FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, true), |
vromero@1853 | 62 | /** The tag of the basic type `int'. |
vromero@1853 | 63 | */ |
vromero@1853 | 64 | INT(INT_CLASS, INT_SUPERCLASSES, true), |
duke@1 | 65 | /** The tag of the basic type `double'. |
duke@1 | 66 | */ |
vromero@1853 | 67 | DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, true), |
duke@1 | 68 | /** The tag of the basic type `boolean'. |
duke@1 | 69 | */ |
vromero@1853 | 70 | BOOLEAN(0, 0, true), |
duke@1 | 71 | |
duke@1 | 72 | /** The tag of the type `void'. |
duke@1 | 73 | */ |
vromero@1853 | 74 | VOID, |
duke@1 | 75 | |
duke@1 | 76 | /** The tag of all class and interface types. |
duke@1 | 77 | */ |
vromero@1853 | 78 | CLASS, |
duke@1 | 79 | |
duke@1 | 80 | /** The tag of all array types. |
duke@1 | 81 | */ |
vromero@1853 | 82 | ARRAY, |
duke@1 | 83 | |
duke@1 | 84 | /** The tag of all (monomorphic) method types. |
duke@1 | 85 | */ |
vromero@1853 | 86 | METHOD, |
duke@1 | 87 | |
duke@1 | 88 | /** The tag of all package "types". |
duke@1 | 89 | */ |
vromero@1853 | 90 | PACKAGE, |
duke@1 | 91 | |
duke@1 | 92 | /** The tag of all (source-level) type variables. |
duke@1 | 93 | */ |
vromero@1853 | 94 | TYPEVAR, |
duke@1 | 95 | |
duke@1 | 96 | /** The tag of all type arguments. |
duke@1 | 97 | */ |
vromero@1853 | 98 | WILDCARD, |
duke@1 | 99 | |
duke@1 | 100 | /** The tag of all polymorphic (method-) types. |
duke@1 | 101 | */ |
vromero@1853 | 102 | FORALL, |
duke@1 | 103 | |
mcimadamore@1347 | 104 | /** The tag of deferred expression types in method context |
mcimadamore@1347 | 105 | */ |
vromero@1853 | 106 | DEFERRED, |
mcimadamore@1347 | 107 | |
jjg@1381 | 108 | /** The tag of the bottom type {@code <null>}. |
duke@1 | 109 | */ |
vromero@1853 | 110 | BOT, |
duke@1 | 111 | |
duke@1 | 112 | /** The tag of a missing type. |
duke@1 | 113 | */ |
vromero@1853 | 114 | NONE, |
duke@1 | 115 | |
duke@1 | 116 | /** The tag of the error type. |
duke@1 | 117 | */ |
vromero@1853 | 118 | ERROR, |
duke@1 | 119 | |
duke@1 | 120 | /** The tag of an unknown type |
duke@1 | 121 | */ |
vromero@1853 | 122 | UNKNOWN, |
duke@1 | 123 | |
duke@1 | 124 | /** The tag of all instantiatable type variables. |
duke@1 | 125 | */ |
vromero@1853 | 126 | UNDETVAR, |
duke@1 | 127 | |
jjg@1374 | 128 | /** Pseudo-types, these are special tags |
duke@1 | 129 | */ |
vromero@1853 | 130 | UNINITIALIZED_THIS, |
duke@1 | 131 | |
vromero@1853 | 132 | UNINITIALIZED_OBJECT; |
jjg@1374 | 133 | |
vromero@1826 | 134 | final int superClasses; |
vromero@1826 | 135 | final int numericClass; |
vromero@1853 | 136 | final boolean isPrimitive; |
duke@1 | 137 | |
vromero@1853 | 138 | private TypeTag() { |
vromero@1853 | 139 | this(0, 0, false); |
vromero@1442 | 140 | } |
jjg@1374 | 141 | |
vromero@1853 | 142 | private TypeTag(int numericClass, int superClasses, boolean isPrimitive) { |
vromero@1853 | 143 | this.superClasses = superClasses; |
vromero@1853 | 144 | this.numericClass = numericClass; |
vromero@1853 | 145 | this.isPrimitive = isPrimitive; |
jjg@1374 | 146 | } |
jjg@1374 | 147 | |
vromero@1826 | 148 | public static class NumericClasses { |
vromero@1826 | 149 | public static final int BYTE_CLASS = 1; |
vromero@1826 | 150 | public static final int CHAR_CLASS = 2; |
vromero@1826 | 151 | public static final int SHORT_CLASS = 4; |
vromero@1826 | 152 | public static final int INT_CLASS = 8; |
vromero@1826 | 153 | public static final int LONG_CLASS = 16; |
vromero@1826 | 154 | public static final int FLOAT_CLASS = 32; |
vromero@1826 | 155 | public static final int DOUBLE_CLASS = 64; |
vromero@1826 | 156 | |
vromero@1826 | 157 | static final int BYTE_SUPERCLASSES = BYTE_CLASS | SHORT_CLASS | INT_CLASS | |
vromero@1826 | 158 | LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 159 | |
vromero@1826 | 160 | static final int CHAR_SUPERCLASSES = CHAR_CLASS | INT_CLASS | |
vromero@1826 | 161 | LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 162 | |
vromero@1826 | 163 | static final int SHORT_SUPERCLASSES = SHORT_CLASS | INT_CLASS | |
vromero@1826 | 164 | LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 165 | |
vromero@1826 | 166 | static final int INT_SUPERCLASSES = INT_CLASS | LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 167 | |
vromero@1826 | 168 | static final int LONG_SUPERCLASSES = LONG_CLASS | FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 169 | |
vromero@1826 | 170 | static final int FLOAT_SUPERCLASSES = FLOAT_CLASS | DOUBLE_CLASS; |
vromero@1826 | 171 | } |
vromero@1826 | 172 | |
vromero@1826 | 173 | public boolean isStrictSubRangeOf(TypeTag tag) { |
vromero@1826 | 174 | /* Please don't change the implementation of this method to call method |
vromero@1826 | 175 | * isSubRangeOf. Both methods are called from hotspot code, the current |
vromero@1826 | 176 | * implementation is better performance-wise than the commented modification. |
vromero@1826 | 177 | */ |
vromero@1826 | 178 | return (this.superClasses & tag.numericClass) != 0 && this != tag; |
vromero@1826 | 179 | } |
vromero@1826 | 180 | |
vromero@1826 | 181 | public boolean isSubRangeOf(TypeTag tag) { |
vromero@1826 | 182 | return (this.superClasses & tag.numericClass) != 0; |
vromero@1826 | 183 | } |
jjg@1374 | 184 | |
jjg@1374 | 185 | /** Returns the number of type tags. |
duke@1 | 186 | */ |
jjg@1374 | 187 | public static int getTypeTagCount() { |
jjg@1374 | 188 | // last two tags are not included in the total as long as they are pseudo-types |
jjg@1374 | 189 | return (UNDETVAR.ordinal() + 1); |
jjg@1374 | 190 | } |
jjg@1374 | 191 | |
jjg@1374 | 192 | public Kind getKindLiteral() { |
jjg@1374 | 193 | switch (this) { |
jjg@1374 | 194 | case INT: |
jjg@1374 | 195 | return Kind.INT_LITERAL; |
jjg@1374 | 196 | case LONG: |
jjg@1374 | 197 | return Kind.LONG_LITERAL; |
jjg@1374 | 198 | case FLOAT: |
jjg@1374 | 199 | return Kind.FLOAT_LITERAL; |
jjg@1374 | 200 | case DOUBLE: |
jjg@1374 | 201 | return Kind.DOUBLE_LITERAL; |
jjg@1374 | 202 | case BOOLEAN: |
jjg@1374 | 203 | return Kind.BOOLEAN_LITERAL; |
jjg@1374 | 204 | case CHAR: |
jjg@1374 | 205 | return Kind.CHAR_LITERAL; |
jjg@1374 | 206 | case CLASS: |
jjg@1374 | 207 | return Kind.STRING_LITERAL; |
jjg@1374 | 208 | case BOT: |
jjg@1374 | 209 | return Kind.NULL_LITERAL; |
jjg@1374 | 210 | default: |
jjg@1374 | 211 | throw new AssertionError("unknown literal kind " + this); |
jjg@1374 | 212 | } |
jjg@1374 | 213 | } |
jjg@1374 | 214 | |
jjg@1374 | 215 | public TypeKind getPrimitiveTypeKind() { |
jjg@1374 | 216 | switch (this) { |
jjg@1374 | 217 | case BOOLEAN: |
jjg@1374 | 218 | return TypeKind.BOOLEAN; |
jjg@1374 | 219 | case BYTE: |
jjg@1374 | 220 | return TypeKind.BYTE; |
jjg@1374 | 221 | case SHORT: |
jjg@1374 | 222 | return TypeKind.SHORT; |
jjg@1374 | 223 | case INT: |
jjg@1374 | 224 | return TypeKind.INT; |
jjg@1374 | 225 | case LONG: |
jjg@1374 | 226 | return TypeKind.LONG; |
jjg@1374 | 227 | case CHAR: |
jjg@1374 | 228 | return TypeKind.CHAR; |
jjg@1374 | 229 | case FLOAT: |
jjg@1374 | 230 | return TypeKind.FLOAT; |
jjg@1374 | 231 | case DOUBLE: |
jjg@1374 | 232 | return TypeKind.DOUBLE; |
jjg@1374 | 233 | case VOID: |
jjg@1374 | 234 | return TypeKind.VOID; |
jjg@1374 | 235 | default: |
jjg@1374 | 236 | throw new AssertionError("unknown primitive type " + this); |
jjg@1374 | 237 | } |
jjg@1374 | 238 | } |
vromero@1853 | 239 | |
duke@1 | 240 | } |