Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.java @ 11439:efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 27 Aug 2013 22:08:26 +0200 |
parents | 79041ab43660 |
children | fc509b6fbfdf |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.java Tue Aug 27 18:11:35 2013 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.java Tue Aug 27 22:08:26 2013 +0200 @@ -32,7 +32,7 @@ import javax.lang.model.util.*; import com.oracle.truffle.dsl.processor.ast.*; -import com.oracle.truffle.dsl.processor.ast.CodeTypeMirror.*; +import com.oracle.truffle.dsl.processor.ast.CodeTypeMirror.DeclaredCodeTypeMirror; import com.oracle.truffle.dsl.processor.compiler.*; /** @@ -50,6 +50,19 @@ return null; } + public static boolean needsCastTo(ProcessorContext context, TypeMirror sourceType, TypeMirror targetType) { + if (typeEquals(sourceType, targetType)) { + return false; + } else if (isObject(targetType)) { + return false; + } else if (isVoid(targetType)) { + return false; + } else if (isAssignable(context, sourceType, targetType)) { + return false; + } + return true; + } + public static VariableElement findVariableElement(DeclaredType type, String name) { List<? extends VariableElement> elements = ElementFilter.fieldsIn(type.asElement().getEnclosedElements()); for (VariableElement variableElement : elements) { @@ -502,6 +515,24 @@ return types; } + public static List<TypeMirror> getAssignableTypes(ProcessorContext context, TypeMirror type) { + if (isPrimitive(type)) { + return Arrays.asList(type, boxType(context, type), context.getType(Object.class)); + } else if (type.getKind() == TypeKind.ARRAY) { + return Arrays.asList(type, context.getType(Object.class)); + } else if (type.getKind() == TypeKind.DECLARED) { + List<TypeElement> types = getSuperTypes(fromTypeMirror(type)); + List<TypeMirror> mirrors = new ArrayList<>(types.size()); + mirrors.add(type); + for (TypeElement typeElement : types) { + mirrors.add(typeElement.asType()); + } + return mirrors; + } else { + return Collections.emptyList(); + } + } + public static List<TypeElement> getSuperTypes(TypeElement element) { List<TypeElement> types = new ArrayList<>(); List<TypeElement> superTypes = null;