*** empty log message ***
[repair.git] / Repair / RepairCompiler / MCC / IR / SemanticChecker.java
index be4e07d6e94f23ae39cd210dc84513a350633f9f..46e010553860bcf954588f0e15cdad070f2c7193 100755 (executable)
@@ -35,9 +35,6 @@ public class SemanticChecker {
        this.state = state;
        State.currentState = state;
 
        this.state = state;
        State.currentState = state;
 
-       // Don't clear the state!!  Do clear the IR-related state
-       this.state.stTypes = null;
-
        if (er == null) {
            throw new IRException("IRBuilder.build: Received null ErrorReporter");
        } else {
        if (er == null) {
            throw new IRException("IRBuilder.build: Received null ErrorReporter");
        } else {
@@ -392,8 +389,8 @@ public class SemanticChecker {
         }
 
         /* do any post checks... (type constraints, etc?) */
         }
 
         /* do any post checks... (type constraints, etc?) */
-         
-        return ok;
+
+       return ok;
     }
 
     private boolean parse_constraint(ParseNode pn) {
     }
 
     private boolean parse_constraint(ParseNode pn) {
@@ -477,7 +474,7 @@ public class SemanticChecker {
             /* return to caller */
             return sq;
 
             /* return to caller */
             return sq;
 
-        } else if (pn.getChild("relatiion") != null) { /* for < v1, v2 > in Relation */
+        } else if (pn.getChild("relation") != null) { /* for < v1, v2 > in Relation */
             RelationQuantifier rq = new RelationQuantifier();
 
             /* get vars */
             RelationQuantifier rq = new RelationQuantifier();
 
             /* get vars */
@@ -530,7 +527,6 @@ public class SemanticChecker {
         } else {
             throw new IRException("not supported yet");
         }
         } else {
             throw new IRException("not supported yet");
         }
-
     }
 
     private LogicStatement parse_body(ParseNode pn) {
     }
 
     private LogicStatement parse_body(ParseNode pn) {
@@ -563,7 +559,7 @@ public class SemanticChecker {
             return new LogicStatement(LogicStatement.OR, left, right);
         } else if (pn.getChild("not") != null) {
             /* NOT body */
             return new LogicStatement(LogicStatement.OR, left, right);
         } else if (pn.getChild("not") != null) {
             /* NOT body */
-            LogicStatement left = parse_body(pn.getChild("not").getChild("left").getChild("body"));
+            LogicStatement left = parse_body(pn.getChild("not").getChild("body"));
             
             if (left == null) {
                 return null;
             
             if (left == null) {
                 return null;
@@ -582,29 +578,13 @@ public class SemanticChecker {
             return null;
         }
 
             return null;
         }
 
-        if (pn.getChild("comparison") != null) {
-            ParseNode cn = pn.getChild("comparison");
-            
-            /* get the expr's */
-            Expr left = parse_expr(cn.getChild("left").getChild("expr"));
-            Expr right = parse_expr(cn.getChild("right").getChild("expr"));
-
-            if ((left == null) || (right == null)) {
-                return null;
-            }
-
-            /* get comparison operator */
-            String comparison = cn.getChild("compare").getTerminal();
-            assert comparison != null;
-                         
-            return new ComparisonPredicate(comparison, left, right);
-        } else if (pn.getChild("inclusion") != null) {
+        if (pn.getChild("inclusion") != null) {
             ParseNode in = pn.getChild("inclusion");
             
             ParseNode in = pn.getChild("inclusion");
             
-            /* get quantiifer var */
-            VarDescriptor vd = parse_quantifiervar(in.getChild("quantifiervar"));
+            /* Expr */
+            Expr expr = parse_expr(in.getChild("expr"));
            
            
-            if (vd == null) { 
+            if (expr == null) { 
                 return null;
             }
 
                 return null;
             }
 
@@ -615,7 +595,15 @@ public class SemanticChecker {
                 return null;
             }
 
                 return null;
             }
 
-            return new InclusionPredicate(vd, setexpr);
+            return new InclusionPredicate(expr, setexpr);
+        } else if (pn.getChild("expr") != null) {
+            Expr expr = parse_expr(pn.getChild("expr"));
+            
+            if (expr == null) {
+                return null;
+            }
+
+            return new ExprPredicate(expr);
         } else {
             throw new IRException();
         }       
         } else {
             throw new IRException();
         }       
@@ -871,7 +859,7 @@ public class SemanticChecker {
             } else if (t instanceof StructureTypeDescriptor) {
                 
                 StructureTypeDescriptor type = (StructureTypeDescriptor) t;
             } else if (t instanceof StructureTypeDescriptor) {
                 
                 StructureTypeDescriptor type = (StructureTypeDescriptor) t;
-                TypeDescriptor subtype = type.getSubType();
+                TypeDescriptor subtype = type.getSuperType();
 
                 // check that the subtype is valid
                 if (subtype instanceof MissingTypeDescriptor) {
 
                 // check that the subtype is valid
                 if (subtype instanceof MissingTypeDescriptor) {
@@ -882,7 +870,7 @@ public class SemanticChecker {
                         er.report(null, "Undefined subtype '" + subtype.getSymbol() + "'");
                         ok = false;
                     } else {
                         er.report(null, "Undefined subtype '" + subtype.getSymbol() + "'");
                         ok = false;
                     } else {
-                        type.setSubType(newtype);
+                        type.setSuperType(newtype);
                     }
                 }
 
                     }
                 }
 
@@ -951,7 +939,7 @@ public class SemanticChecker {
             } else if (t instanceof StructureTypeDescriptor) {
                 
                 StructureTypeDescriptor type = (StructureTypeDescriptor)t;
             } else if (t instanceof StructureTypeDescriptor) {
                 
                 StructureTypeDescriptor type = (StructureTypeDescriptor)t;
-                TypeDescriptor subtype = type.getSubType();
+                TypeDescriptor subtype = type.getSuperType();
                 Iterator fields = type.getFields();
 
                 while (fields.hasNext()) {
                 Iterator fields = type.getFields();
 
                 while (fields.hasNext()) {
@@ -1050,7 +1038,7 @@ public class SemanticChecker {
             }
 
             /* lookup the type to get the type descriptor */
             }
 
             /* lookup the type to get the type descriptor */
-            type.setSubType(lookupType(subtype, CREATE_MISSING));
+            type.setSuperType(lookupType(subtype, CREATE_MISSING));
         }
 
         // set the current type so that the recursive parses on the labels
         }
 
         // set the current type so that the recursive parses on the labels
@@ -1328,49 +1316,26 @@ public class SemanticChecker {
             return null;
         }
 
             return null;
         }
 
-        RelationExpr re = new RelationExpr();
+        String relname = pn.getChild("name").getTerminal();
+        boolean inverse = pn.getChild("inv") != null;
+        Expr expr = parse_expr(pn.getChild("expr"));        
 
 
-        /* get quantitifer var */
-        VarDescriptor vd = parse_quantifiervar(pn.getChild("quantifiervar"));
-        
-        if (vd == null) {
+        if (expr == null) {
             return null;
         }
             return null;
         }
-
-        // #TBD#: bad name
-        re.setDomain(vd);
-
-        /* grab list of relations */
-        ParseNodeVector relations = pn.getChild("relations").getChildren();
-        assert relations.size() >= 1;
-        
-        // #TBD#: verify that the relations are in the correct order and that the 
-        // first relation is getting the correct "inv" assigned from "expr"
-
-        /* lets verify that these relations are defined */
-        for (int i = 0; i < relations.size(); i++) {           
-            ParseNode rn = relations.elementAt(i);
-            String relname = rn.getLabel();
-            boolean inverse = rn.getChild("inv") != null;
-            
-            RelationDescriptor relation = lookupRelation(relname);
+                    
+        RelationDescriptor relation = lookupRelation(relname);
             
             
-            if (relation == null) {
-                /* Semantic Error: relation not definied" */
-                er.report(rn, "Undefined relation '" + relname + "'");
-                return null;
-            }                       
+        if (relation == null) {
+            /* Semantic Error: relation not definied" */
+            er.report(pn, "Undefined relation '" + relname + "'");
+            return null;
+        }                       
 
 
-            re.setRelation(relation, inverse);
+        /* add usage so correct sets are created */
+        relation.addUsage(inverse ? RelationDescriptor.INVIMAGE : RelationDescriptor.IMAGE);
             
             
-            /* if we are not at end of list then create new relation and 
-               replace it to chain the relations */
-            if (i + 1 < relations.size()) {
-                re = new RelationExpr(re);  // should create relation with domain as older 're'
-            } 
-        }
-
-        return re;                  
+        return new RelationExpr(expr, relation, inverse);
     }
 
     private SizeofExpr parse_sizeof(ParseNode pn) {
     }
 
     private SizeofExpr parse_sizeof(ParseNode pn) {
@@ -1435,10 +1400,12 @@ public class SemanticChecker {
         } else if (pn.getChild("dot") != null) {
             VarDescriptor vd = parse_quantifiervar(pn.getChild("dot").getChild("quantifiervar"));
             RelationDescriptor relation = lookupRelation(pn.getChild("dot").getChild("relation").getTerminal());
         } else if (pn.getChild("dot") != null) {
             VarDescriptor vd = parse_quantifiervar(pn.getChild("dot").getChild("quantifiervar"));
             RelationDescriptor relation = lookupRelation(pn.getChild("dot").getChild("relation").getTerminal());
+            relation.addUsage(RelationDescriptor.IMAGE);
             return new ImageSetExpr(vd, relation);
         } else if (pn.getChild("dotinv") != null) {
             VarDescriptor vd = parse_quantifiervar(pn.getChild("dotinv").getChild("quantifiervar"));
             RelationDescriptor relation = lookupRelation(pn.getChild("dotinv").getChild("relation").getTerminal());
             return new ImageSetExpr(vd, relation);
         } else if (pn.getChild("dotinv") != null) {
             VarDescriptor vd = parse_quantifiervar(pn.getChild("dotinv").getChild("quantifiervar"));
             RelationDescriptor relation = lookupRelation(pn.getChild("dotinv").getChild("relation").getTerminal());
+            relation.addUsage(RelationDescriptor.INVIMAGE);
             return new ImageSetExpr(ImageSetExpr.INVERSE, vd, relation);
         } else {
             throw new IRException();
             return new ImageSetExpr(ImageSetExpr.INVERSE, vd, relation);
         } else {
             throw new IRException();
@@ -1522,36 +1489,9 @@ public class SemanticChecker {
         }
 
         String opname = pn.getChild("op").getTerminal();
         }
 
         String opname = pn.getChild("op").getTerminal();
+        Opcode opcode = Opcode.decodeFromString(opname);
 
 
-        Opcode opcode;
-
-        if (opname.equals("add")) {
-            opcode = Opcode.ADD;
-        } else if (opname.equals("sub")) {
-            opcode = Opcode.SUB;
-        } else if (opname.equals("mult")) {
-            opcode = Opcode.MULT;
-        } else if (opname.equals("div")) {
-            opcode = Opcode.DIV;
-        } else if (opname.equals("and")) {
-            opcode = Opcode.AND;
-        } else if (opname.equals("or")) {
-            opcode = Opcode.OR;
-        } else if (opname.equals("not")) {
-            opcode = Opcode.NOT;
-        } else if (opname.equals("gt")) {
-            opcode = Opcode.GT;
-        } else if (opname.equals("ge")) {
-            opcode = Opcode.GE;
-        } else if (opname.equals("lt")) {
-            opcode = Opcode.LT;
-        } else if (opname.equals("le")) {
-            opcode = Opcode.LE;
-        } else if (opname.equals("eq")) {
-            opcode = Opcode.EQ;
-        } else if (opname.equals("ne")) {
-            opcode = Opcode.NE;
-        } else {
+        if (opcode == null) {
             er.report(pn, "Unsupported operation: " + opname);
             return null;
         }
             er.report(pn, "Unsupported operation: " + opname);
             return null;
         }