heh
authordroy <droy>
Wed, 26 Nov 2003 16:12:31 +0000 (16:12 +0000)
committerdroy <droy>
Wed, 26 Nov 2003 16:12:31 +0000 (16:12 +0000)
Repair/RepairCompiler/MCC/IR/MetaInclusion.java [new file with mode: 0755]
Repair/RepairCompiler/MCC/IR/RelationFunctionExpr.java [new file with mode: 0755]
Repair/RepairCompiler/MCC/IR/SizeofFunction.java [new file with mode: 0755]

diff --git a/Repair/RepairCompiler/MCC/IR/MetaInclusion.java b/Repair/RepairCompiler/MCC/IR/MetaInclusion.java
new file mode 100755 (executable)
index 0000000..52ab078
--- /dev/null
@@ -0,0 +1,151 @@
+package MCC.IR;
+
+import java.util.*;
+
+public class MetaInclusion extends Inclusion {
+    
+    Inclusion inclusion;
+    Vector rules;
+    Vector constraints;
+
+    public MetaInclusion() {
+        inclusion = null;
+        rules = new Vector();
+        constraints = new Vector();
+    }
+
+    public Set getTargetDescriptors() {
+        throw new IRException("unsupported");
+    }
+
+    public Set getRequiredDescriptors() {
+        return inclusion.getRequiredDescriptors();
+    }
+
+    public boolean typecheck(SemanticAnalyzer sa) {
+        throw new IRException("unsupported");
+    }
+
+    public void setInclusion(Inclusion in) {
+        assert (in instanceof SetInclusion); // we only support setinclusion meta inclusions
+        this.inclusion = in;
+    }
+
+    public Inclusion getInclusion() {
+        return inclusion;
+    }
+
+    public void addRules(Collection newrules) {
+        rules.addAll(newrules);
+    }
+
+    public void addConstraint(Constraint c) {
+        constraints.add(c);
+    }
+
+    public void generate(CodeWriter cr) {
+        
+        this.inclusion.generate(cr);
+
+        // for each of the rules, since they are guaranteed to be single quantifiers, and in fact,
+        // even stricter, there only quantifier is the same quantifier just generated by 
+        // the inclusion constraint, we only need to bind each of there vardescriptors in there 
+        // own blocks (to avoid name space clashes) to the newly quantified variable.
+
+        // we know that the inclusion is a  setinlusion
+        SetInclusion setinclusion = (SetInclusion) inclusion;
+
+        String addeditem = setinclusion.generatedaddeditem; // boolean : new item or not
+        String result = setinclusion.generatedresult; // item added to set... what we must bind
+
+        cr.outputline("if (" + addeditem + ")");
+        cr.startblock();
+        
+        ListIterator allrules = rules.listIterator();
+        while (allrules.hasNext()) {
+            Rule rule = (Rule) allrules.next();
+            
+            // we need to grab the vardescriptor of the first quantifeir (which is a setquantifier)
+            // and we need to instantiate it inside a new block scope and set it equal to the value
+            // in "result" .... we then need to generate the guard and inclusion inside of inner rule
+            
+            cr.startblock();{
+
+                cr.outputline("// embedding " + rule.getLabel() );
+                
+                SetQuantifier sq = (SetQuantifier) rule.quantifiers().next(); // get first qunatifier
+                VarDescriptor vd = sq.getVar();
+                cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
+
+                cr.pushSymbolTable(rule.getSymbolTable());
+                
+                VarDescriptor guardval = VarDescriptor.makeNew();
+                rule.getGuardExpr().generate(cr, guardval);
+                
+                cr.outputline("if (" + guardval.getSafeSymbol() + ")");
+                cr.startblock(); {
+                    rule.getInclusion().generate(cr);
+                } cr.endblock();
+
+                cr.popSymbolTable();
+           
+            } cr.endblock();                
+        }
+
+        cr.endblock();
+
+        // constraints!!!!!!!!!!!!!!
+
+        ListIterator allconstraints = constraints.listIterator();
+        while (allconstraints.hasNext()) {
+            Constraint constraint = (Constraint) allconstraints.next();
+            
+            // ok... um... we need to grab teh vardescripntor of the first quantifier which is guaranteed
+            // to be a setquantifier... we then need to bind it to variable, generatedresult.
+            // once this is done we can generated the logicstatement and we can then test for pass/fail
+            // and emit an error
+
+            cr.startblock(); {
+
+                cr.outputline("// checking embedded " + constraint.getLabel() );
+                
+                SetQuantifier sq = (SetQuantifier) constraint.quantifiers().next(); // get first qunatifier
+                VarDescriptor vd = sq.getVar();
+                cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
+
+                cr.pushSymbolTable(constraint.getSymbolTable());
+                
+                cr.outputline("int maybe = 0;");
+                
+                /* now we have to generate the guard test */
+                
+                VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
+                constraint.getLogicStatement().generate(cr, constraintboolean);
+                
+                cr.outputline("if (maybe)");
+                cr.startblock(); {
+
+                    cr.outputline("__Success = 0;");
+                    cr.outputline("printf(\"maybe fail " + constraint.getNum() + ". \");");
+                    cr.outputline("exit(1);");
+           
+                } cr.endblock();
+                cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");                
+                cr.startblock(); {
+                
+                    cr.outputline("__Success = 0;");
+                    cr.outputline("printf(\"fail " + constraint.getNum() + ". \");");
+                    cr.outputline("exit(1);");
+
+                } cr.endblock();
+
+                cr.popSymbolTable();
+           
+            } cr.endblock();                                      
+
+        }
+
+    }
+
+}
+
diff --git a/Repair/RepairCompiler/MCC/IR/RelationFunctionExpr.java b/Repair/RepairCompiler/MCC/IR/RelationFunctionExpr.java
new file mode 100755 (executable)
index 0000000..bb4050f
--- /dev/null
@@ -0,0 +1,106 @@
+package MCC.IR;
+
+import java.util.*;
+
+public class RelationFunctionExpr extends Expr {
+
+    // #WHAT I WAS DOING: about to define relationfunctionexpr thich should take a expr, relation and rule and generated
+    // the functional value or "maybe" if not there!
+
+    Expr expr;
+    RelationDescriptor relation;
+    Rule rule;
+
+    public RelationFunctionExpr(Expr expr, RelationDescriptor relation, Rule rule) {
+        this.expr = expr;
+        this.relation = relation;
+        this.rule = rule;
+    }
+
+    public RelationDescriptor getRelation() {
+        return relation;
+    }
+
+    public Set getInversedRelations() {
+        return expr.getInversedRelations();
+    }
+
+    public Set getRequiredDescriptors() {
+        Set v = expr.getRequiredDescriptors();        
+        v.add(relation);
+        return v;
+    }
+
+    public void generate(CodeWriter cr, VarDescriptor dest) {
+        
+        String destname = dest.getSafeSymbol();
+        cr.outputline("int " + destname + ";");
+
+        // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we 
+        // set the destination in the guard ... otherwise maybe!
+        
+        VarDescriptor domain = VarDescriptor.makeNew("domain");
+        expr.generate(cr, domain);
+
+        cr.pushSymbolTable(rule.getSymbolTable());
+        cr.startblock(); {
+
+            // ok... symbol table is set up... lets bind that initial vardescriptor of the quantifier
+            SetQuantifier sq = ((SetQuantifier) rule.quantifiers().next());
+            VarDescriptor rulebinding = sq.getVar();
+            String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
+            
+            // this is to be safe about name overlap because int t = t; sets t to 0!
+            cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
+            cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+            
+            /* pretty print! */
+            cr.outputline("// about to inbed relational function");
+            cr.output("// ");
+            rule.getGuardExpr().prettyPrint(cr);
+            cr.outputline("");
+            
+            /* now we have to generate the guard test */
+            VarDescriptor guardval = VarDescriptor.makeNew();
+            rule.getGuardExpr().generate(cr, guardval);
+            
+            cr.outputline("if (" + guardval.getSafeSymbol() + ")");
+            cr.startblock(); {
+                
+                /* now we have to generate the inclusion code */
+                RelationInclusion ri = (RelationInclusion) rule.getInclusion();
+                
+                // basically, destname = righthandside<r, r.field>            
+                VarDescriptor tempdest = VarDescriptor.makeNew("tempdest");
+                Expr rhs = ri.getRightExpr();
+                rhs.generate(cr, tempdest);
+                
+                cr.outputline(destname + " = " + tempdest.getSafeSymbol() + ";");
+                
+            } cr.endblock();
+            cr.outputline("else");
+            cr.startblock(); {
+
+                // three valued logic. if the relation (which is a partial function)
+                // fails its guard, then we have a "maybe" condition, which must
+                // propagate
+
+                cr.outputline("maybe = 1;");
+
+            } cr.endblock();
+
+        } cr.endblock();
+
+    }
+
+    public void prettyPrint(PrettyPrinter pp) {
+        expr.prettyPrint(pp);
+        pp.output(".");
+        pp.output(relation.getSafeSymbol());
+    }
+
+    public TypeDescriptor typecheck(SemanticAnalyzer sa) {
+        throw new IRException();
+    }
+
+}
diff --git a/Repair/RepairCompiler/MCC/IR/SizeofFunction.java b/Repair/RepairCompiler/MCC/IR/SizeofFunction.java
new file mode 100755 (executable)
index 0000000..1342cfd
--- /dev/null
@@ -0,0 +1,94 @@
+package MCC.IR;
+
+import java.util.*;
+
+public class SizeofFunction extends Expr {
+
+    public VarDescriptor vd;
+    public RelationDescriptor rd;
+    public Rule rule;
+
+    public SizeofFunction(VarDescriptor vd, RelationDescriptor rd, Rule rule) {
+        this.vd = vd;
+        this.rd = rd;
+        this.rule = rule;
+    }
+
+    public Set getInversedRelations() {
+        return new HashSet();
+    }
+
+    public Set getRequiredDescriptors() {
+        // because we don't actually use rd for any generation, we return the empty set
+        return new HashSet();
+    }
+
+    public TypeDescriptor getType() {
+        throw new IRException("unsupported");
+    }
+
+    public void generate(CodeWriter cr, VarDescriptor dest) {
+
+        // basically a sizeoffunction can have two values ... zero or one... so what we need to do
+        // is expand the guard of the rule and if its true then its 1 otherwise 0
+
+        String destname = dest.getSafeSymbol();
+        cr.outputline("int " + destname + ";");
+
+        // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we 
+        // set the destination in the guard ... otherwise maybe!
+        
+        VarDescriptor domain = vd;
+
+        cr.pushSymbolTable(rule.getSymbolTable());
+        cr.startblock(); {
+
+            // ok... symbol table is set up... lets bind that initial vardescriptor of the quantifier
+            SetQuantifier sq = ((SetQuantifier) rule.quantifiers().next());
+            VarDescriptor rulebinding = sq.getVar();
+            String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
+            
+            // this is to be safe about name overlap because int t = t; sets t to 0!
+            cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
+            cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+            
+            /* pretty print! */
+            cr.outputline("// about to inbed relational function");
+            cr.output("// ");
+            rule.getGuardExpr().prettyPrint(cr);
+            cr.outputline("");
+            
+            /* now we have to generate the guard test */
+            VarDescriptor guardval = VarDescriptor.makeNew();
+            rule.getGuardExpr().generate(cr, guardval);
+            
+            cr.outputline("if (" + guardval.getSafeSymbol() + ")");
+            cr.startblock(); {
+                
+                cr.outputline(destname + " = 1;");
+                
+            } cr.endblock();
+            cr.outputline("else");
+            cr.startblock(); {
+
+                cr.outputline(destname + " = 0;");
+
+            } cr.endblock();
+
+        } cr.endblock();
+
+
+
+    }
+
+    public void prettyPrint(PrettyPrinter pp) {
+        pp.output("sizeoffunction(");
+        pp.output(vd.toString() + "." + rd.toString());
+        pp.output(")");
+    }
+
+    public TypeDescriptor typecheck(SemanticAnalyzer sa) {
+        throw new IRException();
+    }
+        
+}