提交 21cccc7f 编写于 作者: V vromero

8017104: javac should have a class for primitive types that inherits from Type

Reviewed-by: jjg
上级 2ef1fff2
...@@ -69,6 +69,7 @@ import com.sun.tools.javac.code.Type.ClassType; ...@@ -69,6 +69,7 @@ import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.ErrorType; import com.sun.tools.javac.code.Type.ErrorType;
import com.sun.tools.javac.code.Type.UnionClassType; import com.sun.tools.javac.code.Type.UnionClassType;
import com.sun.tools.javac.code.Types; import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types.TypeRelation; import com.sun.tools.javac.code.Types.TypeRelation;
import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.AttrContext;
...@@ -653,8 +654,7 @@ public class JavacTrees extends DocTrees { ...@@ -653,8 +654,7 @@ public class JavacTrees extends DocTrees {
switch (t.getTag()) { switch (t.getTag()) {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
return t.getTag() == s.getTag(); return t.hasTag(s.getTag());
default: default:
throw new AssertionError("fuzzyMatcher " + t.getTag()); throw new AssertionError("fuzzyMatcher " + t.getTag());
} }
...@@ -668,7 +668,7 @@ public class JavacTrees extends DocTrees { ...@@ -668,7 +668,7 @@ public class JavacTrees extends DocTrees {
if (s.isPartial()) if (s.isPartial())
return visit(s, t); return visit(s, t);
return s.getTag() == ARRAY return s.hasTag(ARRAY)
&& visit(t.elemtype, types.elemtype(s)); && visit(t.elemtype, types.elemtype(s));
} }
...@@ -685,7 +685,7 @@ public class JavacTrees extends DocTrees { ...@@ -685,7 +685,7 @@ public class JavacTrees extends DocTrees {
@Override @Override
public Boolean visitErrorType(ErrorType t, Type s) { public Boolean visitErrorType(ErrorType t, Type s) {
return s.getTag() == CLASS return s.hasTag(CLASS)
&& t.tsym.name == ((ClassType) s).tsym.name; && t.tsym.name == ((ClassType) s).tsym.name;
} }
}; };
......
...@@ -83,7 +83,7 @@ public abstract class Attribute implements AnnotationValue { ...@@ -83,7 +83,7 @@ public abstract class Attribute implements AnnotationValue {
return v.visitString((String) value, p); return v.visitString((String) value, p);
if (value instanceof Integer) { if (value instanceof Integer) {
int i = (Integer) value; int i = (Integer) value;
switch (type.tag) { switch (type.getTag()) {
case BOOLEAN: return v.visitBoolean(i != 0, p); case BOOLEAN: return v.visitBoolean(i != 0, p);
case CHAR: return v.visitChar((char) i, p); case CHAR: return v.visitChar((char) i, p);
case BYTE: return v.visitByte((byte) i, p); case BYTE: return v.visitByte((byte) i, p);
...@@ -91,7 +91,7 @@ public abstract class Attribute implements AnnotationValue { ...@@ -91,7 +91,7 @@ public abstract class Attribute implements AnnotationValue {
case INT: return v.visitInt(i, p); case INT: return v.visitInt(i, p);
} }
} }
switch (type.tag) { switch (type.getTag()) {
case LONG: return v.visitLong((Long) value, p); case LONG: return v.visitLong((Long) value, p);
case FLOAT: return v.visitFloat((Float) value, p); case FLOAT: return v.visitFloat((Float) value, p);
case DOUBLE: return v.visitDouble((Double) value, p); case DOUBLE: return v.visitDouble((Double) value, p);
......
...@@ -218,10 +218,10 @@ public class Kinds { ...@@ -218,10 +218,10 @@ public class Kinds {
/** A KindName representing the kind of a given class/interface type. /** A KindName representing the kind of a given class/interface type.
*/ */
public static KindName typeKindName(Type t) { public static KindName typeKindName(Type t) {
if (t.tag == TYPEVAR || if (t.hasTag(TYPEVAR) ||
t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0) t.hasTag(CLASS) && (t.tsym.flags() & COMPOUND) != 0)
return KindName.BOUND; return KindName.BOUND;
else if (t.tag == PACKAGE) else if (t.hasTag(PACKAGE))
return KindName.PACKAGE; return KindName.PACKAGE;
else if ((t.tsym.flags_field & ANNOTATION) != 0) else if ((t.tsym.flags_field & ANNOTATION) != 0)
return KindName.ANNOTATION; return KindName.ANNOTATION;
......
...@@ -215,7 +215,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi ...@@ -215,7 +215,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
@Override @Override
public String visitClassType(ClassType t, Locale locale) { public String visitClassType(ClassType t, Locale locale) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) { if (t.getEnclosingType().hasTag(CLASS) && t.tsym.owner.kind == Kinds.TYP) {
buf.append(visit(t.getEnclosingType(), locale)); buf.append(visit(t.getEnclosingType(), locale));
buf.append('.'); buf.append('.');
buf.append(className(t, false, locale)); buf.append(className(t, false, locale));
...@@ -379,7 +379,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi ...@@ -379,7 +379,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
? s.owner.name.toString() ? s.owner.name.toString()
: s.name.toString(); : s.name.toString();
if (s.type != null) { if (s.type != null) {
if (s.type.tag == FORALL) { if (s.type.hasTag(FORALL)) {
ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms; ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
} }
ms += "(" + printMethodArgs( ms += "(" + printMethodArgs(
......
...@@ -699,17 +699,17 @@ public abstract class Symbol implements Element { ...@@ -699,17 +699,17 @@ public abstract class Symbol implements Element {
public final boolean precedes(TypeSymbol that, Types types) { public final boolean precedes(TypeSymbol that, Types types) {
if (this == that) if (this == that)
return false; return false;
if (this.type.tag == that.type.tag) { if (type.hasTag(that.type.getTag())) {
if (this.type.hasTag(CLASS)) { if (type.hasTag(CLASS)) {
return return
types.rank(that.type) < types.rank(this.type) || types.rank(that.type) < types.rank(this.type) ||
types.rank(that.type) == types.rank(this.type) && types.rank(that.type) == types.rank(this.type) &&
that.getQualifiedName().compareTo(this.getQualifiedName()) < 0; that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
} else if (this.type.hasTag(TYPEVAR)) { } else if (type.hasTag(TYPEVAR)) {
return types.isSubtype(this.type, that.type); return types.isSubtype(this.type, that.type);
} }
} }
return this.type.hasTag(TYPEVAR); return type.hasTag(TYPEVAR);
} }
@Override @Override
......
...@@ -28,7 +28,6 @@ package com.sun.tools.javac.code; ...@@ -28,7 +28,6 @@ package com.sun.tools.javac.code;
import java.util.*; import java.util.*;
import javax.lang.model.element.ElementVisitor; import javax.lang.model.element.ElementVisitor;
import javax.lang.model.type.TypeVisitor;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Type.*;
...@@ -65,16 +64,16 @@ public class Symtab { ...@@ -65,16 +64,16 @@ public class Symtab {
/** Builtin types. /** Builtin types.
*/ */
public final Type byteType = new Type(BYTE, null); public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
public final Type charType = new Type(CHAR, null); public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
public final Type shortType = new Type(SHORT, null); public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
public final Type intType = new Type(INT, null); public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
public final Type longType = new Type(LONG, null); public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
public final Type floatType = new Type(FLOAT, null); public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
public final Type doubleType = new Type(DOUBLE, null); public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
public final Type booleanType = new Type(BOOLEAN, null); public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
public final Type botType = new BottomType(); public final Type botType = new BottomType();
public final JCNoType voidType = new JCNoType(VOID); public final JCVoidType voidType = new JCVoidType();
private final Names names; private final Names names;
private final ClassReader reader; private final ClassReader reader;
...@@ -208,7 +207,7 @@ public class Symtab { ...@@ -208,7 +207,7 @@ public class Symtab {
public void initType(Type type, ClassSymbol c) { public void initType(Type type, ClassSymbol c) {
type.tsym = c; type.tsym = c;
typeOfTag[type.tag.ordinal()] = type; typeOfTag[type.getTag().ordinal()] = type;
} }
public void initType(Type type, String name) { public void initType(Type type, String name) {
...@@ -220,7 +219,7 @@ public class Symtab { ...@@ -220,7 +219,7 @@ public class Symtab {
public void initType(Type type, String name, String bname) { public void initType(Type type, String name, String bname) {
initType(type, name); initType(type, name);
boxedName[type.tag.ordinal()] = names.fromString("java.lang." + bname); boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
} }
/** The class symbol that owns all predefined symbols. /** The class symbol that owns all predefined symbols.
...@@ -330,7 +329,7 @@ public class Symtab { ...@@ -330,7 +329,7 @@ public class Symtab {
} }
public void synthesizeBoxTypeIfMissing(final Type type) { public void synthesizeBoxTypeIfMissing(final Type type) {
ClassSymbol sym = reader.enterClass(boxedName[type.tag.ordinal()]); ClassSymbol sym = reader.enterClass(boxedName[type.getTag().ordinal()]);
final Completer completer = sym.completer; final Completer completer = sym.completer;
if (completer != null) { if (completer != null) {
sym.completer = new Completer() { sym.completer = new Completer() {
...@@ -388,12 +387,7 @@ public class Symtab { ...@@ -388,12 +387,7 @@ public class Symtab {
target = Target.instance(context); target = Target.instance(context);
// Create the unknown type // Create the unknown type
unknownType = new Type(UNKNOWN, null) { unknownType = new UnknownType();
@Override
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitUnknown(this, p);
}
};
// create the basic builtin symbols // create the basic builtin symbols
rootPackage = new PackageSymbol(names.empty, null); rootPackage = new PackageSymbol(names.empty, null);
......
...@@ -42,132 +42,107 @@ import static com.sun.tools.javac.code.TypeTag.NumericClasses.*; ...@@ -42,132 +42,107 @@ import static com.sun.tools.javac.code.TypeTag.NumericClasses.*;
public enum TypeTag { public enum TypeTag {
/** The tag of the basic type `byte'. /** The tag of the basic type `byte'.
*/ */
BYTE(BYTE_CLASS, BYTE_SUPERCLASSES, BYTE(BYTE_CLASS, BYTE_SUPERCLASSES, true),
TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
/** The tag of the basic type `char'. /** The tag of the basic type `char'.
*/ */
CHAR(CHAR_CLASS, CHAR_SUPERCLASSES, CHAR(CHAR_CLASS, CHAR_SUPERCLASSES, true),
TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
/** The tag of the basic type `short'. /** The tag of the basic type `short'.
*/ */
SHORT(SHORT_CLASS, SHORT_SUPERCLASSES, SHORT(SHORT_CLASS, SHORT_SUPERCLASSES, true),
TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
/** The tag of the basic type `int'.
*/
INT(INT_CLASS, INT_SUPERCLASSES,
TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
/** The tag of the basic type `long'. /** The tag of the basic type `long'.
*/ */
LONG(LONG_CLASS, LONG_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC), LONG(LONG_CLASS, LONG_SUPERCLASSES, true),
/** The tag of the basic type `float'. /** The tag of the basic type `float'.
*/ */
FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC), FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, true),
/** The tag of the basic type `int'.
*/
INT(INT_CLASS, INT_SUPERCLASSES, true),
/** The tag of the basic type `double'. /** The tag of the basic type `double'.
*/ */
DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC), DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, true),
/** The tag of the basic type `boolean'. /** The tag of the basic type `boolean'.
*/ */
BOOLEAN(TypeTagKind.PRIMITIVE), BOOLEAN(0, 0, true),
/** The tag of the type `void'. /** The tag of the type `void'.
*/ */
VOID(TypeTagKind.VOID), VOID,
/** The tag of all class and interface types. /** The tag of all class and interface types.
*/ */
CLASS(TypeTagKind.REFERENCE), CLASS,
/** The tag of all array types. /** The tag of all array types.
*/ */
ARRAY(TypeTagKind.REFERENCE), ARRAY,
/** The tag of all (monomorphic) method types. /** The tag of all (monomorphic) method types.
*/ */
METHOD(TypeTagKind.OTHER), METHOD,
/** The tag of all package "types". /** The tag of all package "types".
*/ */
PACKAGE(TypeTagKind.OTHER), PACKAGE,
/** The tag of all (source-level) type variables. /** The tag of all (source-level) type variables.
*/ */
TYPEVAR(TypeTagKind.REFERENCE), TYPEVAR,
/** The tag of all type arguments. /** The tag of all type arguments.
*/ */
WILDCARD(TypeTagKind.REFERENCE), WILDCARD,
/** The tag of all polymorphic (method-) types. /** The tag of all polymorphic (method-) types.
*/ */
FORALL(TypeTagKind.OTHER), FORALL,
/** The tag of deferred expression types in method context /** The tag of deferred expression types in method context
*/ */
DEFERRED(TypeTagKind.OTHER), DEFERRED,
/** The tag of the bottom type {@code <null>}. /** The tag of the bottom type {@code <null>}.
*/ */
BOT(TypeTagKind.OTHER), BOT,
/** The tag of a missing type. /** The tag of a missing type.
*/ */
NONE(TypeTagKind.OTHER), NONE,
/** The tag of the error type. /** The tag of the error type.
*/ */
ERROR(TypeTagKind.REFERENCE | TypeTagKind.PARTIAL), ERROR,
/** The tag of an unknown type /** The tag of an unknown type
*/ */
UNKNOWN(TypeTagKind.PARTIAL), UNKNOWN,
/** The tag of all instantiatable type variables. /** The tag of all instantiatable type variables.
*/ */
UNDETVAR(TypeTagKind.PARTIAL), UNDETVAR,
/** Pseudo-types, these are special tags /** Pseudo-types, these are special tags
*/ */
UNINITIALIZED_THIS(TypeTagKind.OTHER), UNINITIALIZED_THIS,
UNINITIALIZED_OBJECT(TypeTagKind.OTHER); UNINITIALIZED_OBJECT;
final boolean isPrimitive;
final boolean isNumeric;
final boolean isPartial;
final boolean isReference;
final boolean isPrimitiveOrVoid;
final int superClasses; final int superClasses;
final int numericClass; final int numericClass;
final boolean isPrimitive;
private TypeTag(int kind) { private TypeTag() {
this(0, 0, kind); this(0, 0, false);
} }
private TypeTag(int numericClass, int superClasses, int kind) { private TypeTag(int numericClass, int superClasses, boolean isPrimitive) {
isPrimitive = (kind & TypeTagKind.PRIMITIVE) != 0; this.superClasses = superClasses;
isNumeric = (kind & TypeTagKind.NUMERIC) != 0; this.numericClass = numericClass;
isPartial = (kind & TypeTagKind.PARTIAL) != 0; this.isPrimitive = isPrimitive;
isReference = (kind & TypeTagKind.REFERENCE) != 0;
isPrimitiveOrVoid = ((kind & TypeTagKind.PRIMITIVE) != 0) ||
((kind & TypeTagKind.VOID) != 0);
this.superClasses = superClasses;
this.numericClass = numericClass;
}
static class TypeTagKind {
static final int PRIMITIVE = 1;
static final int NUMERIC = 2;
static final int REFERENCE = 4;
static final int PARTIAL = 8;
static final int OTHER = 16;
static final int VOID = 32;
} }
public static class NumericClasses { public static class NumericClasses {
...@@ -261,4 +236,5 @@ public enum TypeTag { ...@@ -261,4 +236,5 @@ public enum TypeTag {
throw new AssertionError("unknown primitive type " + this); throw new AssertionError("unknown primitive type " + this);
} }
} }
} }
...@@ -115,12 +115,17 @@ public class DeferredAttr extends JCTree.Visitor { ...@@ -115,12 +115,17 @@ public class DeferredAttr extends JCTree.Visitor {
SpeculativeCache speculativeCache; SpeculativeCache speculativeCache;
DeferredType(JCExpression tree, Env<AttrContext> env) { DeferredType(JCExpression tree, Env<AttrContext> env) {
super(DEFERRED, null); super(null);
this.tree = tree; this.tree = tree;
this.env = env.dup(tree, env.info.dup()); this.env = env.dup(tree, env.info.dup());
this.speculativeCache = new SpeculativeCache(); this.speculativeCache = new SpeculativeCache();
} }
@Override
public TypeTag getTag() {
return DEFERRED;
}
/** /**
* A speculative cache is used to keep track of all overload resolution rounds * A speculative cache is used to keep track of all overload resolution rounds
* that triggered speculative attribution on a given deferred type. Each entry * that triggered speculative attribution on a given deferred type. Each entry
......
...@@ -96,7 +96,7 @@ public class Infer { ...@@ -96,7 +96,7 @@ public class Infer {
} }
/** A value for prototypes that admit any type, including polymorphic ones. */ /** A value for prototypes that admit any type, including polymorphic ones. */
public static final Type anyPoly = new Type(NONE, null); public static final Type anyPoly = new JCNoType();
/** /**
* This exception class is design to store a list of diagnostics corresponding * This exception class is design to store a list of diagnostics corresponding
......
...@@ -2843,7 +2843,7 @@ public class Resolve { ...@@ -2843,7 +2843,7 @@ public class Resolve {
protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Scope sc = new Scope(syms.arrayClass); Scope sc = new Scope(syms.arrayClass);
MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym); MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym);
arrayConstr.type = new MethodType(List.of(syms.intType), site, List.<Type>nil(), syms.methodClass); arrayConstr.type = new MethodType(List.<Type>of(syms.intType), site, List.<Type>nil(), syms.methodClass);
sc.enter(arrayConstr); sc.enter(arrayConstr);
return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false); return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false);
} }
......
...@@ -1859,7 +1859,7 @@ public class Code { ...@@ -1859,7 +1859,7 @@ public class Code {
} }
} }
static final Type jsrReturnValue = new Type(INT, null); static final Type jsrReturnValue = new JCPrimitiveType(INT, null);
/* ************************************************************************** /* **************************************************************************
......
...@@ -139,7 +139,7 @@ public class JavacTypes implements javax.lang.model.util.Types { ...@@ -139,7 +139,7 @@ public class JavacTypes implements javax.lang.model.util.Types {
Type unboxed = types.unboxedType((Type) t); Type unboxed = types.unboxedType((Type) t);
if (! unboxed.isPrimitive()) // only true primitives, not void if (! unboxed.isPrimitive()) // only true primitives, not void
throw new IllegalArgumentException(t.toString()); throw new IllegalArgumentException(t.toString());
return unboxed; return (PrimitiveType)unboxed;
} }
public TypeMirror capture(TypeMirror t) { public TypeMirror capture(TypeMirror t) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册