Mercurial > hg > truffle
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemData.java @ 11545:2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 16:16:40 +0200 |
parents | 43eab069ca9b |
children | bd28da642eea |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemData.java Fri Sep 06 16:11:15 2013 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemData.java Fri Sep 06 16:16:40 2013 +0200 @@ -36,6 +36,7 @@ private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>(); private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); + private List<ImplicitCastData> implicitCasts; private List<TypeCastData> casts; private List<TypeCheckData> checks; @@ -61,6 +62,14 @@ } } + public void setImplicitCasts(List<ImplicitCastData> implicitCasts) { + this.implicitCasts = implicitCasts; + } + + public List<ImplicitCastData> getImplicitCasts() { + return implicitCasts; + } + public void setCasts(List<TypeCastData> casts) { this.casts = casts; } @@ -89,6 +98,9 @@ if (casts != null) { sinks.addAll(casts); } + if (implicitCasts != null) { + sinks.addAll(implicitCasts); + } return sinks; } @@ -161,4 +173,55 @@ return getClass().getSimpleName() + "[template = " + Utils.getSimpleName(getTemplateType()) + ", types = " + types + "]"; } + public Set<TypeData> lookupCastSourceTypes() { + if (getImplicitCasts() == null) { + return null; + } + + Set<TypeData> sourceTypes = new TreeSet<>(); + for (ImplicitCastData cast : getImplicitCasts()) { + sourceTypes.add(cast.getSourceType()); + } + return sourceTypes; + } + + public List<ImplicitCastData> lookupByTargetType(TypeData targetType) { + if (getImplicitCasts() == null) { + return Collections.emptyList(); + } + List<ImplicitCastData> foundCasts = new ArrayList<>(); + for (ImplicitCastData cast : getImplicitCasts()) { + if (cast.getTargetType().equals(targetType)) { + foundCasts.add(cast); + } + } + return foundCasts; + } + + public ImplicitCastData lookupCast(TypeData sourceType, TypeData targetType) { + if (getImplicitCasts() == null) { + return null; + } + for (ImplicitCastData cast : getImplicitCasts()) { + if (cast.getSourceType().equals(sourceType) && cast.getTargetType().equals(targetType)) { + return cast; + } + } + return null; + } + + public List<TypeData> lookupSourceTypes(TypeData type) { + List<TypeData> sourceTypes = new ArrayList<>(); + sourceTypes.add(type); + if (getImplicitCasts() != null) { + for (ImplicitCastData cast : getImplicitCasts()) { + if (cast.getTargetType() == type) { + sourceTypes.add(cast.getSourceType()); + } + } + } + Collections.sort(sourceTypes); + return sourceTypes; + } + }