correct
[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 DNFConstraint getDNFConstraint() {
23         return dnfconstraint;
24     }
25
26     public String toString() {
27         String name="";
28         for(int i=0;i<numQuantifiers();i++) {
29             name+=getQuantifier(i).toString()+",";
30         }
31         name+=logicstatement.name();
32         return name;
33     }
34
35     public int getNum() {
36         return num;
37     }
38
39     public int numQuantifiers() {
40         return quantifiers.size();
41     }
42
43     public Quantifier getQuantifier(int i) {
44         return (Quantifier) quantifiers.get(i);
45     }
46
47     public String getLabel() {
48         return label;
49     }
50
51     public SymbolTable getSymbolTable() {
52         return st;
53     }
54
55     public void addQuantifier(Quantifier q) {
56         quantifiers.addElement(q);
57     }
58
59     public void setLogicStatement(LogicStatement ls) {
60         logicstatement = ls;
61         // Construct DNF form for analysis
62         dnfconstraint=logicstatement.constructDNF();
63     }
64
65     public LogicStatement getLogicStatement() {
66         return logicstatement;
67     }
68
69     public void setCrash(boolean crash) {
70         this.crash = crash;
71     }
72
73     public ListIterator quantifiers() {
74         return quantifiers.listIterator();
75     }
76
77     public Set getRequiredDescriptorsFromQuantifiers() {
78
79         HashSet topdescriptors = new HashSet();
80
81         for (int i = 0; i < quantifiers.size(); i++) {
82             Quantifier q = (Quantifier) quantifiers.elementAt(i);
83             topdescriptors.addAll(q.getRequiredDescriptors());
84         }
85
86         return SetDescriptor.expand(topdescriptors);
87     }
88
89     public Set getRequiredDescriptorsFromLogicStatement() {
90
91         HashSet topdescriptors = new HashSet();
92
93         topdescriptors.addAll(logicstatement.getRequiredDescriptors());
94
95         return SetDescriptor.expand(topdescriptors);
96     }
97
98     public Set getRequiredDescriptors() {
99         Set set = getRequiredDescriptorsFromQuantifiers();
100         set.addAll(getRequiredDescriptorsFromLogicStatement());
101         return set;
102     }
103 }