comparison 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
comparison
equal deleted inserted replaced
11544:e5b5a5cb0ac7 11545:2fb276f5e3e9
34 34
35 private List<TypeData> types; 35 private List<TypeData> types;
36 private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>(); 36 private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>();
37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); 37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>();
38 38
39 private List<ImplicitCastData> implicitCasts;
39 private List<TypeCastData> casts; 40 private List<TypeCastData> casts;
40 private List<TypeCheckData> checks; 41 private List<TypeCheckData> checks;
41 42
42 private TypeMirror genericType; 43 private TypeMirror genericType;
43 private TypeData voidType; 44 private TypeData voidType;
59 boxedTypeMirrors.add(typeData.getBoxedType()); 60 boxedTypeMirrors.add(typeData.getBoxedType());
60 } 61 }
61 } 62 }
62 } 63 }
63 64
65 public void setImplicitCasts(List<ImplicitCastData> implicitCasts) {
66 this.implicitCasts = implicitCasts;
67 }
68
69 public List<ImplicitCastData> getImplicitCasts() {
70 return implicitCasts;
71 }
72
64 public void setCasts(List<TypeCastData> casts) { 73 public void setCasts(List<TypeCastData> casts) {
65 this.casts = casts; 74 this.casts = casts;
66 } 75 }
67 76
68 public void setChecks(List<TypeCheckData> checks) { 77 public void setChecks(List<TypeCheckData> checks) {
87 sinks.addAll(checks); 96 sinks.addAll(checks);
88 } 97 }
89 if (casts != null) { 98 if (casts != null) {
90 sinks.addAll(casts); 99 sinks.addAll(casts);
91 } 100 }
101 if (implicitCasts != null) {
102 sinks.addAll(implicitCasts);
103 }
92 return sinks; 104 return sinks;
93 } 105 }
94 106
95 public boolean isGeneric(TypeMirror type) { 107 public boolean isGeneric(TypeMirror type) {
96 return Utils.typeEquals(getGenericType(), type); 108 return Utils.typeEquals(getGenericType(), type);
159 @Override 171 @Override
160 public String toString() { 172 public String toString() {
161 return getClass().getSimpleName() + "[template = " + Utils.getSimpleName(getTemplateType()) + ", types = " + types + "]"; 173 return getClass().getSimpleName() + "[template = " + Utils.getSimpleName(getTemplateType()) + ", types = " + types + "]";
162 } 174 }
163 175
176 public Set<TypeData> lookupCastSourceTypes() {
177 if (getImplicitCasts() == null) {
178 return null;
179 }
180
181 Set<TypeData> sourceTypes = new TreeSet<>();
182 for (ImplicitCastData cast : getImplicitCasts()) {
183 sourceTypes.add(cast.getSourceType());
184 }
185 return sourceTypes;
186 }
187
188 public List<ImplicitCastData> lookupByTargetType(TypeData targetType) {
189 if (getImplicitCasts() == null) {
190 return Collections.emptyList();
191 }
192 List<ImplicitCastData> foundCasts = new ArrayList<>();
193 for (ImplicitCastData cast : getImplicitCasts()) {
194 if (cast.getTargetType().equals(targetType)) {
195 foundCasts.add(cast);
196 }
197 }
198 return foundCasts;
199 }
200
201 public ImplicitCastData lookupCast(TypeData sourceType, TypeData targetType) {
202 if (getImplicitCasts() == null) {
203 return null;
204 }
205 for (ImplicitCastData cast : getImplicitCasts()) {
206 if (cast.getSourceType().equals(sourceType) && cast.getTargetType().equals(targetType)) {
207 return cast;
208 }
209 }
210 return null;
211 }
212
213 public List<TypeData> lookupSourceTypes(TypeData type) {
214 List<TypeData> sourceTypes = new ArrayList<>();
215 sourceTypes.add(type);
216 if (getImplicitCasts() != null) {
217 for (ImplicitCastData cast : getImplicitCasts()) {
218 if (cast.getTargetType() == type) {
219 sourceTypes.add(cast.getSourceType());
220 }
221 }
222 }
223 Collections.sort(sourceTypes);
224 return sourceTypes;
225 }
226
164 } 227 }