more string support stuff
authorbdemsky <bdemsky>
Sat, 3 Nov 2007 18:39:16 +0000 (18:39 +0000)
committerbdemsky <bdemsky>
Sat, 3 Nov 2007 18:39:16 +0000 (18:39 +0000)
Robust/src/ClassLibrary/String.java
Robust/src/IR/AssignOperation.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java

index c93d67cfd0f44ba8448e1548cceb9a689aa88665..00cf7a0fae2e7535f85586c7da2db8a17b81ccb3 100644 (file)
@@ -71,6 +71,13 @@ public class String {
        return this.lastindexOf(ch, count - 1);
     }
 
+    public static String concat2(String s1, String s2) {
+       if (s1==null)
+           return "null".concat(s2);
+       else
+           return s1.concat(s2);
+    }
+
     public String concat(String str) {
        String newstr=new String();
        newstr.count=this.count+str.count;
index 1a4e2a2b80ad7e841c3560e02445c89cdfd40593..3e750b9f44b7d8d07b6f3eff33271b8146bc100b 100644 (file)
@@ -25,6 +25,10 @@ public class AssignOperation {
        this.operation=parseOp(op);
     }
 
+    public int getOp() {
+       return operation;
+    }
+
     public Operation getBaseOp() {
        switch(operation) {
        case EQ:
index d873cbe8a58ddb1d4f9a3d357cfffebeb0ef3219..5bc766fdb97b1e8d94d82c8be8c029ac9369e103 100644 (file)
@@ -414,14 +414,23 @@ public class BuildFlat {
                //If it is a preinc we need to store the initial value
                TempDescriptor src_tmp2=pre?TempDescriptor.tempFactory("src",an.getDest().getType()):out_temp;
                TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3",an.getDest().getType());
-
                FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
                last.addNext(ffn);
                last=ffn;
-               FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
-               src_tmp=tmp;
-               last.addNext(fon);
-               last=fon;
+
+               if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+                   ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+                   MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+                   FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+                   src_tmp=tmp;
+                   last.addNext(fc);
+                   last=fc;
+               } else {
+                   FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+                   src_tmp=tmp;
+                   last.addNext(fon);
+                   last=fon;
+               }
            }
 
            FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
@@ -460,10 +469,22 @@ public class BuildFlat {
                FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
                last.addNext(fen);
                last=fen;
-               FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
-               src_tmp=tmp;
-               last.addNext(fon);
-               last=fon;
+
+               if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+                   ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+                   MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+                   FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+                   src_tmp=tmp;
+                   last.addNext(fc);
+                   last=fc;
+               } else {
+
+
+                   FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+                   src_tmp=tmp;
+                   last.addNext(fon);
+                   last=fon;
+               }
            }
 
 
@@ -500,10 +521,21 @@ public class BuildFlat {
                    FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
                    last.addNext(ffn);
                    last=ffn;
-                   FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
-                   src_tmp=tmp;
-                   last.addNext(fon);
-                   last=fon;
+
+                   
+                   if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+                       ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+                       MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+                       FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+                       src_tmp=tmp;
+                       last.addNext(fc);
+                       last=fc;
+                   } else {
+                       FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+                       src_tmp=tmp;
+                       last.addNext(fon);
+                       last=fon;
+                   }
                }
 
 
@@ -534,10 +566,21 @@ public class BuildFlat {
                            last.addNext(ffn);
                        }
                        last=ffn;
-                       FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
-                       src_tmp=tmp;
-                       last.addNext(fon);
-                       last=fon;
+
+                       
+                       if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+                           ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+                           MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+                           FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+                           src_tmp=tmp;
+                           last.addNext(fc);
+                           last=fc;
+                       } else {
+                           FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+                           src_tmp=tmp;
+                           last.addNext(fon);
+                           last=fon;
+                       }
                    }               
 
                    FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
@@ -570,13 +613,26 @@ public class BuildFlat {
                            last=fon;
                        }
 
-                       FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
-                       if (first==null) 
-                           first=fon;
-                       else 
-                           last.addNext(fon);
-                       src_tmp=tmp;
-                       last=fon;
+                       
+                       if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+                           ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+                           MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+                           FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+                           if (first==null)
+                               first=fc;
+                           else
+                               last.addNext(fc);
+                           src_tmp=tmp;
+                           last=fc;
+                       } else {
+                           FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+                           if (first==null) 
+                               first=fon;
+                           else 
+                               last.addNext(fon);
+                           src_tmp=tmp;
+                           last=fon;
+                       }
                    }
 
                    FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
index 53df0128e75a370b5b4d54921de74e65226342e6..145f8efa6b343793e39952ed96d38d9c8241d14d 100644 (file)
@@ -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));
        }
index 9471925c8fdb7cc1ac7d25047e6797e79f208c51..92e4e5861b45b6483e7a1dedf14b70ef882ff5df 100644 (file)
@@ -121,6 +121,9 @@ public class TypeUtil {
                 /* Is this more specific than bestmd */
             }
         }
+       if (bestmd==null)
+           throw new Error("Could find: "+name + " in "+cd);
+
        return bestmd;
     }