Adding the -cplusplus option. This option writes virual table pointers into allocate...
[repair.git] / Repair / RepairCompiler / MCC / IR / VarExpr.java
index ddc0e8eb9b7de1c0c246de76ea57365502638614..12a47f364ac74001bac92ae06c00aaf4fdd5b56b 100755 (executable)
@@ -3,7 +3,7 @@ package MCC.IR;
 import java.util.*;
 
 public class VarExpr extends Expr {
-    static boolean DOMEMCHECKS=true;
+    static boolean DOMEMCHECKS=false;
     static boolean DOTYPECHECKS=false;
     static boolean DONULL=false;
 
@@ -17,7 +17,17 @@ public class VarExpr extends Expr {
        return hs;
     }
 
+    public Expr getLower() {
+       return vd.getLower();
+    }
+
+    public Expr getUpper() {
+       return vd.getUpper();
+    }
+
     public SetDescriptor getSet() {
+       if (vd==null)
+           return null;
        return vd.getSet();
     }
 
@@ -84,12 +94,32 @@ public class VarExpr extends Expr {
        return vd.isGlobal();
     }
 
-    public void generate(CodeWriter writer, VarDescriptor dest) {        
+    public boolean isInvariant(Set vars) {
+       return vd.isGlobal()||vars.contains(vd);
+    }
+
+    public Set findInvariants(Set vars) {
+       if (isInvariant(vars)) {
+           Set s=new HashSet();
+           s.add(this);
+           return s;
+       } else 
+           return new HashSet();
+    }
+
+    public void generate(CodeWriter writer, VarDescriptor dest) {
         // #TBD#: bit of a hack, really should have been type checked properly 
         assert vd != null;
         assert vd.getType() != null;
        this.td = vd.getType();
 
+       if (writer.getInvariantValue()!=null&&
+           writer.getInvariantValue().isInvariant(this)) {
+           writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
+           writer.outputline(vd.getType().getGenerateType().getSafeSymbol()+
+                             " "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+           return;
+       }
 
         writer.outputline(vd.getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + 
                           " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; //varexpr");