remove dependence on concat2...it isn't a standard string method
authorbdemsky <bdemsky>
Thu, 9 Jun 2011 16:42:58 +0000 (16:42 +0000)
committerbdemsky <bdemsky>
Thu, 9 Jun 2011 16:42:58 +0000 (16:42 +0000)
fix some bugs...

Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/Lex/Lexer.java
Robust/src/Main/Main.java

index fb9ecf313aec9dbfe174283632ba3bf8d09a3217..71f4801907fc445dd3a9d28fe8b641a147007b57 100644 (file)
@@ -663,11 +663,18 @@ public class BuildFlat {
 
         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});
+          ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+         TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+          MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+          FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+          fc1.setNumLine(an.getNumLine());
+
+          MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+          FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
           fc.setNumLine(an.getNumLine());
           src_tmp=tmp;
-          last.addNext(fc);
+          last.addNext(fc1);
+         fc1.addNext(fc);
           last=fc;
         } else {
           FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
@@ -730,11 +737,19 @@ public class BuildFlat {
         }
         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});
+          ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+         TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+          MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+          FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+          fc1.setNumLine(an.getNumLine());
+
+          MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+          FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
           fc.setNumLine(an.getNumLine());
+
           src_tmp=tmp;
-          last.addNext(fc);
+          last.addNext(fc1);
+         fc1.addNext(fc);
           last=fc;
         } else {
           FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
@@ -807,13 +822,20 @@ public class BuildFlat {
 
 
           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});
-            fc.setNumLine(an.getNumLine());
-            src_tmp=tmp;
-            last.addNext(fc);
-            last=fc;
+           ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+           ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+           TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+           MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+           FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+           fc1.setNumLine(an.getNumLine());
+           
+           MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+           FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
+           fc.setNumLine(an.getNumLine());
+           
+           src_tmp=tmp;
+           last.addNext(fc1);
+           last=fc;
           } else {
             FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
             fon.setNumLine(an.getNumLine());
@@ -866,12 +888,19 @@ public class BuildFlat {
 
 
             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});
-              fc.setNumLine(an.getNumLine());
-              src_tmp=tmp;
-              last.addNext(fc);
+             ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+             ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+             TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+             MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+             FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+             fc1.setNumLine(an.getNumLine());
+             
+             MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+             FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
+             fc.setNumLine(an.getNumLine());
+             src_tmp=tmp;
+             last.addNext(fc1);
+             fc1.addNext(fc);
               last=fc;
             } else {
               FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
@@ -924,14 +953,23 @@ public class BuildFlat {
 
 
             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});
-              fc.setNumLine(an.getNumLine());
+             ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+             ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+             TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+             MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+             FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+             fc1.setNumLine(an.getNumLine());
+             
+             MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+             FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
+             fc.setNumLine(an.getNumLine());
+             src_tmp=tmp;
+             fc1.addNext(fc);
+
               if (first==null)
-                first=fc;
+                first=fc1;
               else
-                last.addNext(fc);
+                last.addNext(fc1);
               src_tmp=tmp;
               last=fc;
             } else {
@@ -1044,11 +1082,18 @@ public class BuildFlat {
     } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
       //We have a string concatenate
       ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+      ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+      TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+      MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+      FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {temp_left});
+      fc1.setNumLine(on.getNumLine());
+      
       MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
-      FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
+      FlatCall fc=new FlatCall(concatmd, out_temp, src_tmp3, new TempDescriptor[] {temp_right});
       fc.setNumLine(on.getNumLine());
       left.getEnd().addNext(right.getBegin());
-      right.getEnd().addNext(fc);
+      right.getEnd().addNext(fc1);
+      fc1.addNext(fc);
       return new NodePair(left.getBegin(), fc);
     }
 
index 4e36cee08699e3a4223944a940bf301166fe3e25..72d73703c53183d9c46f59f637c25488e21bcdd3 100644 (file)
@@ -86,7 +86,6 @@ public class SemanticCheck {
           if (oldstatus<REFERENCE) {
             cd.addSuperInterfaces(superif);
             cd.getFieldTable().addParentIF(superif.getFieldTable());
-            cd.getMethodTable().addParentIF(superif.getMethodTable());
           }
         }
       }
@@ -646,6 +645,8 @@ public class SemanticCheck {
     ExpressionNode left=fan.getExpression();
     checkExpressionNode(md,nametable,left,null);
     TypeDescriptor ltd=left.getType();
+    if (!ltd.isArray())
+      checkClass(ltd.getClassDesc(), INIT);
     String fieldname=fan.getFieldName();
 
     FieldDescriptor fd=null;
@@ -1194,6 +1195,7 @@ NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.ha
       ExpressionNode en=min.getArg(i);
       checkExpressionNode(md,nametable,en,null);
       tdarray[i]=en.getType();
+
       if(en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
         tdarray[i] = new TypeDescriptor(TypeDescriptor.INT);
       }
@@ -1202,9 +1204,6 @@ NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.ha
     if (min.getExpression()!=null) {
       checkExpressionNode(md,nametable,min.getExpression(),null);
       typetolookin=min.getExpression().getType();
-      //if (typetolookin==null)
-      //throw new Error(md+" has null return type");
-
     } else if (min.getBaseName()!=null) {
       String rootname=min.getBaseName().getRoot();
       if (rootname.equals("super")) {
@@ -1252,7 +1251,7 @@ NextMethod: for (Iterator methodit = methoddescriptorset.iterator(); methodit.ha
       throw new Error("Unknown method call to "+min.getMethodName()+"in task"+md.getSymbol());
     }
     if (!typetolookin.isClass())
-      throw new Error("Error with method call to "+min.getMethodName());
+      throw new Error("Error with method call to "+min.getMethodName()+" in class "+typetolookin);
     ClassDescriptor classtolookin=typetolookin.getClassDesc();
     checkClass(classtolookin, INIT);
 
index 7b03ab817c90ff8a18b3676b6077edbc6efe7a05..d6f18175fe625ba490ca0b141aa1a3fdad95c73a 100644 (file)
@@ -17,20 +17,22 @@ public class Lexer {
   boolean isJava14;
   boolean isJava15;
   boolean taskExt;
+  boolean dsmExt;
   String line = null;
   int line_pos = 1;
   public int line_num = 0;
   LineList lineL = new LineList(-line_pos, null); // sentinel for line #0
 
   public Lexer(Reader reader) {
-    this(reader, true);
+    this(reader, true, true);
   }
 
-  public Lexer(Reader reader, boolean task) {
+  public Lexer(Reader reader, boolean task, boolean dsm) {
     this.reader = new LineNumberReader(new EscapedUnicodeReader(reader));
     this.isJava12 = true;
     this.isJava14 = true;
     taskExt=task;
+    dsmExt=dsm;
   }
 
   public java_cup.runtime.Symbol nextToken() throws java.io.IOException {
@@ -298,6 +300,7 @@ public class Lexer {
     //  pre-java 1.5 compatibility:
     //if (!isJava15 && s.equals("enum")) return new Identifier(s);
     //  pre-java 1.4 compatibility:
+    if (!dsmExt && s.equals("global")) return new Identifier(s);
 
     if (!taskExt && s.equals("taskexit")) return new Identifier(s);
     if (!taskExt && s.equals("tag")) return new Identifier(s);
index ff59d3d4843e38920d7280478428e78ec2f7b0f7..d800573341ba39c74581c09a405e8cb3010724bb 100644 (file)
@@ -715,7 +715,7 @@ public class Main {
   public static ParseNode readSourceFile(State state, String sourcefile) {
     try {
       Reader fr= new BufferedReader(new FileReader(sourcefile));
-      Lex.Lexer l = new Lex.Lexer(fr, state.TASK);
+      Lex.Lexer l = new Lex.Lexer(fr, state.TASK, state.DSM);
       java_cup.runtime.lr_parser g;
       g = new Parse.Parser(l);
       ParseNode p=null;