This update should allow casting between char's and other types including bytes.
authorbdemsky <bdemsky>
Fri, 20 Oct 2006 20:29:33 +0000 (20:29 +0000)
committerbdemsky <bdemsky>
Fri, 20 Oct 2006 20:29:33 +0000 (20:29 +0000)
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java

index 47dcc524f8634ea3ed41799aac6d297a6f3b41c7..4502d4c9bc0c6b35203fe7fc6bb1cfcfa44cf271 100644 (file)
@@ -345,7 +345,9 @@ public class SemanticCheck {
 
        if (typeutil.isSuperorType(etd,cast_type)) /* Cast may succeed */
            return;
-
+       if (typeutil.isCastable(etd, cast_type))
+           return;
+       
        /* Different branches */
        /* TODO: change if add interfaces */
        throw new Error("Cast will always fail\n"+cn.printNode(0));
index 2f2a9e99288571e327d04187859819997e804b9e..da25f219da1321803eabcfe91cf3f96302983ca5 100644 (file)
@@ -59,6 +59,24 @@ public class TypeUtil {
        return (ClassDescriptor)supertable.get(cd);
     }
 
+    public boolean isCastable(TypeDescriptor original, TypeDescriptor casttype) {
+       if (original.isChar()&&
+           (casttype.isByte()||
+            casttype.isShort()))
+           return true;
+
+       if (casttype.isChar()&&
+           (original.isByte()||
+            original.isShort()||
+            original.isInt()||
+            original.isLong()||
+            original.isFloat()||
+            original.isDouble()))
+           return true;
+           
+       return false;
+    }
+
     public boolean isSuperorType(TypeDescriptor possiblesuper, TypeDescriptor cd2) {
        //Matching type are always okay
        if (possiblesuper.equals(cd2))