start of new file
[IRC.git] / Robust / src / IR / Tree / SemanticCheck.java
index 7680db3d7ab64a5757c69a0bb047260c53e472a3..816ee712eae68d6d8fd7d74353d1903575c13b93 100644 (file)
@@ -101,7 +101,7 @@ public class SemanticCheck {
            //Make sure the variable is declared as a parameter to the task
            VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
            if (vd==null)
-               throw new Error("Parameter "+varname+" in Flag Effects not declared");
+               throw new Error("Parameter "+varname+" in Flag Effects not declared in "+td);
            fe.setVar(vd);
 
            //Make sure it correspods to a class
@@ -280,7 +280,7 @@ public class SemanticCheck {
            (d instanceof FieldDescriptor)) {
            nametable.add(vd);
        } else
-           throw new Error(vd.getSymbol()+" defined a second time");
+           throw new Error(vd.getSymbol()+" in "+md+" defined a second time");
        if (dn.getExpression()!=null)
            checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
     }
@@ -413,7 +413,7 @@ public class SemanticCheck {
        else
            fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
        if (fd==null)
-           throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0));
+           throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
        fan.setField(fd);
        if (td!=null)
            if (!typeutil.isSuperorType(td,fan.getType()))
@@ -470,7 +470,7 @@ public class SemanticCheck {
            String varname=nd.toString();
            Descriptor d=(Descriptor)nametable.get(varname);
            if (d==null) {
-               throw new Error("Name "+varname+" undefined");
+               throw new Error("Name "+varname+" undefined in: "+md);
            }
            if (d instanceof VarDescriptor) {
                nn.setVar(d);
@@ -502,6 +502,7 @@ public class SemanticCheck {
            throw new Error("Bad lside in "+an.printNode(0));
        checkExpressionNode(md, nametable, an.getDest(), null);
 
+
        /* We want parameter variables to tasks to be immutable */
        if (md instanceof TaskDescriptor) {
            if (an.getDest() instanceof NameNode) {
@@ -513,6 +514,22 @@ public class SemanticCheck {
            }
        }
        
+       if (an.getDest().getType().isString()&&an.getOperation().getOp()==AssignOperation.PLUSEQ) {
+           //String add
+           ClassDescriptor stringcl=typeutil.getClass(TypeUtil.StringClass);
+           TypeDescriptor stringtd=new TypeDescriptor(stringcl);
+           NameDescriptor nd=new NameDescriptor("String");
+           NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
+           
+           if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
+               MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+               rightmin.addArgument(an.getSrc());
+               an.right=rightmin;
+               checkExpressionNode(md, nametable, an.getSrc(), null);
+           }
+       }
+
+       
        if (!postinc&&!typeutil.isSuperorType(an.getDest().getType(),an.getSrc().getType())) {
            throw new Error("Type of rside ("+an.getSrc().getType()+") not compatible with type of lside ("+an.getDest().getType()+")"+an.printNode(0));
        }
@@ -624,7 +641,7 @@ public class SemanticCheck {
                }
            }
            if (bestmd==null)
-               throw new Error("No method found for "+con.printNode(0));
+               throw new Error("No method found for "+con.printNode(0)+" in "+md);
            con.setConstructor(bestmd);
        }
     }
@@ -732,7 +749,7 @@ public class SemanticCheck {
            }
        }
        if (bestmd==null)
-           throw new Error("No method found for :"+min.printNode(0));
+           throw new Error("No method found for :"+min.printNode(0)+" in class: " + classtolookin+" in "+md);
        min.setMethod(bestmd);
 
        if ((td!=null)&&(min.getType()!=null)&&!typeutil.isSuperorType(td,  min.getType()))
@@ -773,6 +790,21 @@ public class SemanticCheck {
            on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
            break;
 
+       case Operation.COMP:
+           // 5.6.2 Binary Numeric Promotion
+           //TODO unboxing of reference objects
+           if (ltd.isDouble())
+               throw new Error();
+           else if (ltd.isFloat())
+               throw new Error();
+           else if (ltd.isLong())
+               lefttype=new TypeDescriptor(TypeDescriptor.LONG);
+           else 
+               lefttype=new TypeDescriptor(TypeDescriptor.INT);
+           on.setLeftType(lefttype);
+           on.setType(lefttype);
+           break;
+
        case Operation.BIT_OR:
        case Operation.BIT_XOR:
        case Operation.BIT_AND:
@@ -859,14 +891,20 @@ public class SemanticCheck {
                TypeDescriptor stringtd=new TypeDescriptor(stringcl);
                NameDescriptor nd=new NameDescriptor("String");
                NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
-               MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
-               MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
-               leftmin.addArgument(on.getLeft());
-               rightmin.addArgument(on.getRight());
-               on.left=leftmin;
-               on.right=rightmin;
-               checkExpressionNode(md, nametable, on.getLeft(), null);
-               checkExpressionNode(md, nametable, on.getRight(), null);
+               if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
+                   MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
+                   leftmin.addArgument(on.getLeft());
+                   on.left=leftmin;
+                   checkExpressionNode(md, nametable, on.getLeft(), null);
+               }
+
+               if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
+                   MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+                   rightmin.addArgument(on.getRight());
+                   on.right=rightmin;
+                   checkExpressionNode(md, nametable, on.getRight(), null);
+               }
+
                on.setLeftType(stringtd);
                on.setRightType(stringtd);
                on.setType(stringtd);
@@ -898,6 +936,7 @@ public class SemanticCheck {
 
        case Operation.LEFTSHIFT:
        case Operation.RIGHTSHIFT:
+       case Operation.URIGHTSHIFT:
            if (!rtd.isIntegerType())
                throw new Error();
            //5.6.1 Unary Numeric Promotion