Some modifications to allow to print the name of the file when a syntax error is...
[repair.git] / Repair / RepairCompiler / MCC / IR / SemanticChecker.java
index a20c5a63f648fe23bc7480568256f4e2a1d6bed5..5339bb74f4ab956d1dad7e28584884d63060c1ce 100755 (executable)
@@ -35,9 +35,6 @@ public class SemanticChecker {
        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 {
@@ -392,8 +389,8 @@ public class SemanticChecker {
         }
 
         /* do any post checks... (type constraints, etc?) */
-         
-        return ok;
+
+       return ok;
     }
 
     private boolean parse_constraint(ParseNode pn) {
@@ -477,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 */
@@ -530,7 +527,6 @@ public class SemanticChecker {
         } else {
             throw new IRException("not supported yet");
         }
-
     }
 
     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 */
-            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;
@@ -585,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;
             }
 
@@ -599,45 +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(opname);
-
-            if (opcode == null) {
-                er.report(pn, "Unsupported operation: " + opname);
-                return null;
-            }
-
-
-
-            return new InclusionPredicate(vd, setexpr);
-        } else if (pn.getChild("comparison") != null) {
-            ParseNode cn = pn.getChild("comparison");
+            return new InclusionPredicate(expr, setexpr);
+        } else if (pn.getChild("expr") != null) {
+            Expr expr = parse_expr(pn.getChild("expr"));
             
-            /* 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)) {
+            if (expr == null) {
                 return null;
             }
 
-            /* get comparison operator */
-            String comparison = cn.getChild("compare").getTerminal();
-            assert comparison != null;
-                         
-            return new ComparisonPredicate(comparison, left, right);
+            return new ExprPredicate(expr);
         } else {
             throw new IRException();
         }       
@@ -819,13 +785,17 @@ public class SemanticChecker {
         String rangesetname = pn.getChild("range").getChild("type").getTerminal();
         assert rangesetname != null;
 
-        /* get domain multiplicity */
-        String domainmult = pn.getChild("domain").getChild("mult").getTerminal();
-        assert domainmult != null;
+        /* get domain multiplicity */  
+       String domainmult;
+       if (pn.getChild("domain").getChild("domainmult") != null)
+           domainmult = pn.getChild("domain").getChild("domainmult").getChild("mult").getTerminal();
+        //assert domainmult != null;
 
         /* get range multiplicity */
-        String rangemult = pn.getChild("range").getChild("mult").getTerminal();
-        assert rangemult != null;
+       String rangemult;
+       if (pn.getChild("range").getChild("domainrange") != null)
+           rangemult = pn.getChild("range").getChild("domainrange").getChild("mult").getTerminal();
+        //assert rangemult != null;
 
         /* NOTE: it is assumed that the sets have been parsed already so that the 
            set namespace is fully populated. any missing setdescriptors for the set
@@ -893,7 +863,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) {
@@ -904,7 +874,7 @@ public class SemanticChecker {
                         er.report(null, "Undefined subtype '" + subtype.getSymbol() + "'");
                         ok = false;
                     } else {
-                        type.setSubType(newtype);
+                        type.setSuperType(newtype);
                     }
                 }
 
@@ -973,7 +943,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()) {
@@ -1048,7 +1018,7 @@ public class SemanticChecker {
             return false;
         }
 
-        stGlobals.add(new VarDescriptor(name, name, td));
+        stGlobals.add(new VarDescriptor(name, name, td,true));
         return true;
     }
 
@@ -1072,7 +1042,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
@@ -1350,49 +1320,26 @@ public class SemanticChecker {
             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;
         }
-
-        // #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) {
@@ -1457,10 +1404,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();