*** empty log message ***
[repair.git] / Repair / RepairCompiler / MCC / IR / SemanticChecker.java
index ab0e7f01e3b24e72e658836b007cc305a0400777..46e010553860bcf954588f0e15cdad070f2c7193 100755 (executable)
@@ -389,8 +389,8 @@ public class SemanticChecker {
         }
 
         /* do any post checks... (type constraints, etc?) */
-         
-        return ok;
+
+       return ok;
     }
 
     private boolean parse_constraint(ParseNode pn) {
@@ -474,7 +474,7 @@ public class SemanticChecker {
             /* 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 */
@@ -527,7 +527,6 @@ public class SemanticChecker {
         } else {
             throw new IRException("not supported yet");
         }
-
     }
 
     private LogicStatement parse_body(ParseNode pn) {
@@ -560,7 +559,7 @@ public class SemanticChecker {
             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;
@@ -582,10 +581,10 @@ public class SemanticChecker {
         if (pn.getChild("inclusion") != null) {
             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;
             }
 
@@ -596,79 +595,15 @@ public class SemanticChecker {
                 return null;
             }
 
-            return new InclusionPredicate(vd, setexpr);
-        } else if (pn.getChild("sizeof") != null) {
-            ParseNode sizeof = pn.getChild("sizeof");
-            
-            /* get set expr */
-            SetExpr setexpr = parse_setexpr(sizeof.getChild("setexpr"));
-
-            if (setexpr == null) {
-                return null;
-            }
-
-            /* get comparison operator */
-            String compareop = sizeof.getChild("compare").getTerminal();
-            Opcode opcode = Opcode.decodeFromString(compareop);
-
-            if (opcode == null) {
-                er.report(pn, "Unsupported operation '" + compareop + "'");
-                return null;
-            } else if (opcode != Opcode.EQ &&
-                       opcode != Opcode.GE &&
-                       opcode != Opcode.LE) {
-                er.report(pn, "Invalid operation '" + compareop + "': Must be one of '=', '>=', '<='");
-                return null;
-            }
+            return new InclusionPredicate(expr, setexpr);
+        } else if (pn.getChild("expr") != null) {
+            Expr expr = parse_expr(pn.getChild("expr"));
             
-            /* get decimal */
-            String decimal = sizeof.getChild("decimal").getTerminal();
-            IntegerLiteralExpr cardinality = new IntegerLiteralExpr(Integer.parseInt(decimal));
-                       
-            return new SizeofPredicate(setexpr, opcode, cardinality);
-        } else if (pn.getChild("comparison") != null) {
-            ParseNode cn = pn.getChild("comparison");
-
-            /* get quantifier variable */
-            String varname = cn.getChild("quantifier").getTerminal();
-            String relation = cn.getChild("relation").getTerminal();            
-
-            if (!sts.peek().contains(varname)) {
-                er.report(pn, "Undefined quantifier '" + varname + "'");
-                return null;
-            } 
-
-            VarDescriptor vd = (VarDescriptor) sts.peek().get(varname);
-
-            if (!stRelations.contains(relation)) {
-                er.report(pn, "Undefined relation '" + varname + "'");
-                return null;
-            }
-
-            RelationDescriptor rd = (RelationDescriptor) stRelations.get(relation);
-
-            /* get the expr's */
-            Expr expr = parse_expr(cn.getChild("expr"));
-
             if (expr == null) {
                 return null;
             }
 
-            /* get comparison operator */
-            String compareop = cn.getChild("compare").getTerminal();
-            Opcode opcode = Opcode.decodeFromString(compareop);
-
-            if (opcode == null) {
-                er.report(pn, "Unsupported operation '" + compareop + "'");
-                return null;
-            } else if (opcode != Opcode.EQ &&
-                       opcode != Opcode.GE &&
-                       opcode != Opcode.LE) {
-                er.report(pn, "Invalid operation '" + compareop + "': Must be one of '=', '>=', '<='");
-                return null;
-            }
-
-            return new ComparisonPredicate(vd, rd, opcode, expr);
+            return new ExprPredicate(expr);
         } else {
             throw new IRException();
         }       
@@ -924,7 +859,7 @@ public class SemanticChecker {
             } 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) {
@@ -935,7 +870,7 @@ public class SemanticChecker {
                         er.report(null, "Undefined subtype '" + subtype.getSymbol() + "'");
                         ok = false;
                     } else {
-                        type.setSubType(newtype);
+                        type.setSuperType(newtype);
                     }
                 }
 
@@ -1004,7 +939,7 @@ public class SemanticChecker {
             } else if (t instanceof StructureTypeDescriptor) {
                 
                 StructureTypeDescriptor type = (StructureTypeDescriptor)t;
-                TypeDescriptor subtype = type.getSubType();
+                TypeDescriptor subtype = type.getSuperType();
                 Iterator fields = type.getFields();
 
                 while (fields.hasNext()) {
@@ -1103,7 +1038,7 @@ public class SemanticChecker {
             }
 
             /* 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
@@ -1382,7 +1317,7 @@ public class SemanticChecker {
         }
 
         String relname = pn.getChild("name").getTerminal();
-        boolean inverse = pn.getChild("inv") == null;
+        boolean inverse = pn.getChild("inv") != null;
         Expr expr = parse_expr(pn.getChild("expr"));        
 
         if (expr == null) {
@@ -1397,6 +1332,9 @@ public class SemanticChecker {
             return null;
         }                       
 
+        /* add usage so correct sets are created */
+        relation.addUsage(inverse ? RelationDescriptor.INVIMAGE : RelationDescriptor.IMAGE);
+            
         return new RelationExpr(expr, relation, inverse);
     }
 
@@ -1462,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());
+            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());
+            relation.addUsage(RelationDescriptor.INVIMAGE);
             return new ImageSetExpr(ImageSetExpr.INVERSE, vd, relation);
         } else {
             throw new IRException();