a:w
authorbdemsky <bdemsky>
Sat, 4 Mar 2006 01:39:50 +0000 (01:39 +0000)
committerbdemsky <bdemsky>
Sat, 4 Mar 2006 01:39:50 +0000 (01:39 +0000)
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeDescriptor.java

index 7086d6dad72094ace6305d64489ec997b2544989..2374185a6b6168ec1656ebbcd8e62fd124bcbba0 100644 (file)
@@ -309,7 +309,35 @@ public class SemanticCheck {
     }
 
 
-    void checkOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,TypeDescriptor td) {
+    void checkOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
+       checkExpressionNode(md, nametable, on.getLeft(), null);
+       if (on.getRight()!=null)
+           checkExpressionNode(md, nametable, on.getRight(), null);
+       TypeDescriptor ltd=on.getLeft().getType();
+       TypeDescriptor rtd=on.getRight()!=null?on.getRight().getType():null;
+       TypeDescriptor thistype=null;
+       if (rtd!=null) {
+           // 5.6.2 Binary Numeric Promotion
+           //TODO unboxing of reference objects
+           if (ltd.isDouble()||rtd.isDouble())
+               thistype=new TypeDescriptor(TypeDescriptor.DOUBLE);
+           else if (ltd.isFloat()||rtd.isFloat())
+               thistype=new TypeDescriptor(TypeDescriptor.FLOAT);
+           else if (ltd.isLong()||rtd.isLong())
+               thistype=new TypeDescriptor(TypeDescriptor.LONG);
+           else 
+               thistype=new TypeDescriptor(TypeDescriptor.INT);
+           
+       } else {
+           //5.6.1 Unary Numeric Promotion
+           if (ltd.isByte()||ltd.isShort()||ltd.isInt())
+               thistype=new TypeDescriptor(TypeDescriptor.INT);
+           else
+               thistype=ltd;
+       }
+       on.setType(thistype);
+       if (!typeutil.isSuperorType(td, thistype))
+           throw new Error("Type of rside not compatible with type of lside"+on.printNode(0)); 
     }
 
 
index 14bb96e0dc06c8fa49d8d87596cb4a4862d6eaf4..27f57ebcdc6e23eea45bdeb68aafea53d702511b 100644 (file)
@@ -24,10 +24,36 @@ public class TypeDescriptor extends Descriptor {
     int type;
     ClassDescriptor class_desc;
 
+    public boolean isByte() {
+       return type==BYTE;
+    }
+    public boolean isShort() {
+       return type==SHORT;
+    }
+    public boolean isInt() {
+       return type==INT;
+    }
+    public boolean isLong() {
+       return type==LONG;
+    }
+    public boolean isChar() {
+       return type==CHAR;
+    }
+    public boolean isBoolean() {
+       return type==BOOLEAN;
+    }
+    public boolean isFloat() {
+       return type==FLOAT;
+    }
+    public boolean isDouble() {
+       return type==DOUBLE;
+    }
+
+
     public void setClassDescriptor(ClassDescriptor cd) {
        class_desc=cd;
     }
-
+  
     public boolean isVoid() {
        return type==VOID;
     }