Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeData.java @ 16755:bd28da642eea
Truffle-DSL: Several new features implemented:
Implementation of a new code generation layout which shares code between generated nodes.
Declaration order of specializations is now used as specialization order.
Specializations do no longer perform fallthrough on respecialization, they now always respecialize from the first specialization.
Implemented support for contains relations between specializations.
Improved reachability error messages.
Preliminary support for @Implies.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | efe58aa92f86 |
children |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeData.java Mon Aug 11 15:53:05 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeData.java Mon Aug 11 15:53:05 2014 +0200 @@ -111,6 +111,20 @@ } @Override + public int hashCode() { + return Objects.hash(index, primitiveType); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof TypeData)) { + return false; + } + TypeData otherType = (TypeData) obj; + return index == otherType.index && Utils.typeEquals(primitiveType, otherType.primitiveType); + } + + @Override public String toString() { return getClass().getSimpleName() + "[" + Utils.getSimpleName(primitiveType) + "]"; } @@ -119,12 +133,39 @@ return Utils.typeEquals(boxedType, actualTypeData.boxedType); } - public boolean needsCastTo(ProcessorContext context, TypeData targetType) { - return Utils.needsCastTo(context, getPrimitiveType(), targetType.getPrimitiveType()); + public boolean needsCastTo(TypeData targetType) { + return Utils.needsCastTo(getPrimitiveType(), targetType.getPrimitiveType()); + } + + public boolean needsCastTo(TypeMirror targetType) { + return Utils.needsCastTo(getPrimitiveType(), targetType); } public boolean isPrimitive() { return Utils.isPrimitive(getPrimitiveType()); } + public boolean isImplicitSubtypeOf(TypeData other) { + List<ImplicitCastData> casts = other.getTypeSystem().lookupByTargetType(other); + for (ImplicitCastData cast : casts) { + if (isSubtypeOf(cast.getSourceType())) { + return true; + } + } + return isSubtypeOf(other); + } + + public boolean isSubtypeOf(TypeData other) { + return Utils.isSubtype(boxedType, other.boxedType); + } + + public boolean intersects(TypeData type) { + if (this.equals(type)) { + return true; + } + if (type.isGeneric() || isGeneric()) { + return true; + } + return isSubtypeOf(type) || type.isSubtypeOf(this); + } }