comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 20984:6361fa2e3321

Truffle-DSL: further fixes for polymorphic execute signatures.
author Christian Humer <christian.humer@oracle.com>
date Wed, 15 Apr 2015 21:13:43 +0200
parents 05a2b72c071f
children 8e5f9310f3aa
comparison
equal deleted inserted replaced
20983:b99da6d86cfe 20984:6361fa2e3321
161 161
162 private static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror type1, TypeMirror type2) { 162 private static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror type1, TypeMirror type2) {
163 if (typeEquals(type1, type2)) { 163 if (typeEquals(type1, type2)) {
164 return type1; 164 return type1;
165 } 165 }
166 if (isVoid(type1)) {
167 return type2;
168 } else if (isVoid(type2)) {
169 return type1;
170 }
171 if (isObject(type1)) {
172 return type1;
173 } else if (isObject(type2)) {
174 return type2;
175 }
176
177 if (isPrimitive(type1) || isPrimitive(type2)) {
178 return context.getType(Object.class);
179 }
180
181 if (isSubtype(type1, type2)) {
182 return type2;
183 } else if (isSubtype(type2, type1)) {
184 return type1;
185 }
186
166 TypeElement element1 = fromTypeMirror(type1); 187 TypeElement element1 = fromTypeMirror(type1);
167 TypeElement element2 = fromTypeMirror(type2); 188 TypeElement element2 = fromTypeMirror(type2);
189
168 if (element1 == null || element2 == null) { 190 if (element1 == null || element2 == null) {
169 if (element1 != null) {
170 return type1;
171 } else if (element2 != null) {
172 return type2;
173 }
174 return context.getType(Object.class); 191 return context.getType(Object.class);
175 } 192 }
176 193
177 List<TypeElement> element1Types = getDirectSuperTypes(element1); 194 List<TypeElement> element1Types = getSuperTypes(element1);
178 element1Types.add(0, element1); 195 List<TypeElement> element2Types = getSuperTypes(element2);
179 List<TypeElement> element2Types = getDirectSuperTypes(element2);
180 element2Types.add(0, element2);
181 196
182 for (TypeElement superType1 : element1Types) { 197 for (TypeElement superType1 : element1Types) {
183 for (TypeElement superType2 : element2Types) { 198 for (TypeElement superType2 : element2Types) {
184 if (typeEquals(superType1.asType(), superType2.asType())) { 199 if (typeEquals(superType1.asType(), superType2.asType())) {
185 return superType2.asType(); 200 return superType2.asType();
186 } 201 }
187 } 202 }
188 } 203 }
204
189 return context.getType(Object.class); 205 return context.getType(Object.class);
190 } 206 }
191 207
192 public static String getReadableSignature(ExecutableElement method) { 208 public static String getReadableSignature(ExecutableElement method) {
193 StringBuilder builder = new StringBuilder(); 209 StringBuilder builder = new StringBuilder();