diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.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 935dcd8ad8eb
children
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.java	Mon Aug 11 15:53:05 2014 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/Utils.java	Mon Aug 11 15:53:05 2014 +0200
@@ -50,14 +50,14 @@
         return null;
     }
 
-    public static boolean needsCastTo(ProcessorContext context, TypeMirror sourceType, TypeMirror targetType) {
+    public static boolean needsCastTo(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)) {
+        } else if (isAssignable(sourceType, targetType)) {
             return false;
         }
         return true;
@@ -125,7 +125,7 @@
         return prev;
     }
 
-    public static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror type1, TypeMirror type2) {
+    private static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror type1, TypeMirror type2) {
         if (typeEquals(type1, type2)) {
             return type1;
         }
@@ -178,15 +178,24 @@
         }
     }
 
-    public static boolean isAssignable(ProcessorContext context, TypeMirror from, TypeMirror to) {
+    public static boolean isSubtype(TypeMirror type1, TypeMirror type2) {
+        if (type1 instanceof CodeTypeMirror && type2 instanceof CodeTypeMirror) {
+            throw new UnsupportedOperationException();
+        }
+        return ProcessorContext.getInstance().getEnvironment().getTypeUtils().isSubtype(type1, type2);
+    }
+
+    public static boolean isAssignable(TypeMirror from, TypeMirror to) {
+        ProcessorContext context = ProcessorContext.getInstance();
+
         if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) {
             return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to));
         } else {
-            return isAssignableImpl(context, from, to);
+            return isAssignableImpl(from, to);
         }
     }
 
-    private static boolean isAssignableImpl(ProcessorContext context, TypeMirror from, TypeMirror to) {
+    private static boolean isAssignableImpl(TypeMirror from, TypeMirror to) {
         // JLS 5.1.1 identity conversion
         if (Utils.typeEquals(from, to)) {
             return true;
@@ -258,7 +267,7 @@
         }
 
         if (from instanceof ArrayType && to instanceof ArrayType) {
-            return isAssignable(context, ((ArrayType) from).getComponentType(), ((ArrayType) to).getComponentType());
+            return isAssignable(((ArrayType) from).getComponentType(), ((ArrayType) to).getComponentType());
         }
 
         if (from instanceof ArrayType || to instanceof ArrayType) {
@@ -461,11 +470,11 @@
     }
 
     public static boolean isVoid(TypeMirror mirror) {
-        return mirror.getKind() == TypeKind.VOID;
+        return mirror != null && mirror.getKind() == TypeKind.VOID;
     }
 
     public static boolean isPrimitive(TypeMirror mirror) {
-        return mirror.getKind().isPrimitive();
+        return mirror != null && mirror.getKind().isPrimitive();
     }
 
     public static boolean isPrimitiveOrVoid(TypeMirror mirror) {
@@ -495,6 +504,16 @@
         return null;
     }
 
+    public static boolean isEnclosedIn(Element enclosedIn, Element element) {
+        if (element == null) {
+            return false;
+        } else if (enclosedIn.equals(element)) {
+            return true;
+        } else {
+            return isEnclosedIn(enclosedIn, element.getEnclosingElement());
+        }
+    }
+
     public static TypeElement findRootEnclosingType(Element element) {
         List<Element> elements = getElementHierarchy(element);
 
@@ -767,10 +786,6 @@
 
     }
 
-    public static boolean getAnnotationValueBoolean(AnnotationMirror mirror, String name) {
-        return (Boolean) getAnnotationValue(mirror, name).getValue();
-    }
-
     public static String printException(Throwable e) {
         StringWriter string = new StringWriter();
         PrintWriter writer = new PrintWriter(string);