From: bdemsky Date: Fri, 20 Oct 2006 20:29:33 +0000 (+0000) Subject: This update should allow casting between char's and other types including bytes. X-Git-Tag: preEdgeChange~815 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c61340bc5b14c55fe3ba0688945c3aec1157b887;p=IRC.git This update should allow casting between char's and other types including bytes. --- diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index 47dcc524..4502d4c9 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -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)); diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 2f2a9e99..da25f219 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -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))