Fixed some analysis problems...
[repair.git] / Repair / RepairCompiler / MCC / IR / Constraint.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class Constraint implements Quantifiers {
6     
7     private static int count = 1;
8
9     String label = null;
10     boolean crash = false;
11     SymbolTable st = new SymbolTable();
12     Vector quantifiers = new Vector(); 
13     LogicStatement logicstatement = null;
14     DNFConstraint dnfconstraint;
15     int num;
16
17     public Constraint() {
18         num = count;
19         label = new String("c" + count++);
20     }
21
22     public String toString() {
23         String name="";
24         for(int i=0;i<numQuantifiers();i++) {
25             name+=getQuantifier(i).toString()+",";
26         }
27         name+=logicstatement.name();
28         return name;
29     }
30
31     public int getNum() {
32         return num;
33     }
34
35     public int numQuantifiers() {
36         return quantifiers.size();
37     }
38
39     public Quantifier getQuantifier(int i) {
40         return (Quantifier) quantifiers.get(i);
41     }
42
43     public String getLabel() {
44         return label;
45     }
46
47     public SymbolTable getSymbolTable() {
48         return st;
49     }
50
51     public void addQuantifier(Quantifier q) {
52         quantifiers.addElement(q);
53     }
54
55     public void setLogicStatement(LogicStatement ls) {
56         logicstatement = ls;
57         // Construct DNF form for analysis
58         dnfconstraint=logicstatement.constructDNF();
59     }
60
61     public LogicStatement getLogicStatement() {
62         return logicstatement;
63     }
64     
65     public void setCrash(boolean crash) {
66         this.crash = crash;
67     }
68
69     public ListIterator quantifiers() {
70         return quantifiers.listIterator();
71     }
72
73     public Set getRequiredDescriptorsFromQuantifiers() {
74
75         HashSet topdescriptors = new HashSet();
76
77         for (int i = 0; i < quantifiers.size(); i++) {            
78             Quantifier q = (Quantifier) quantifiers.elementAt(i);
79             topdescriptors.addAll(q.getRequiredDescriptors());
80         }
81
82         return SetDescriptor.expand(topdescriptors);
83     }
84
85     public Set getRequiredDescriptorsFromLogicStatement() {
86         
87         HashSet topdescriptors = new HashSet();
88
89         topdescriptors.addAll(logicstatement.getRequiredDescriptors());
90
91         return SetDescriptor.expand(topdescriptors);
92     }
93    
94     public Set getRequiredDescriptors() {
95         Set set = getRequiredDescriptorsFromQuantifiers();
96         set.addAll(getRequiredDescriptorsFromLogicStatement());
97         return set;
98     }
99 }
100