67cdd3c28dd9342e5e2b001fc052337175c19dbd
[IRC.git] / Robust / src / IR / Tree / DNFFlag.java
1 package IR.Tree;
2 import java.util.Vector;
3 import IR.*;
4
5 public class DNFFlag {
6     Vector conjunctions;
7     public DNFFlag(FlagNode flag) {
8         DNFFlagAtom dfa=new DNFFlagAtom(flag, false);
9         conjunctions=new Vector();
10         Vector conjunct=new Vector();
11         conjunct.add(dfa);
12         conjunctions.add(conjunct);
13     }
14     private DNFFlag() {
15         conjunctions=new Vector();
16     }
17
18     /** This method negates a DNFFlag expression. */
19
20     public DNFFlag not() {
21         DNFFlag notflag=null;
22         for (int i=0;i<conjunctions.size();i++) {
23             Vector conj=(Vector)conjunctions.get(i);
24             DNFFlag newflag=null;
25             for (int j=0;j<conj.size();j++) {
26                 DNFFlagAtom dfa=(DNFFlagAtom) conj.get(j);
27                 DNFFlagAtom negdfa=new DNFFlagAtom(dfa.flag,!dfa.negated);
28                 DNFFlag tmp=new DNFFlag();
29                 Vector v=new Vector();
30                 tmp.conjunctions.add(v);
31                 v.add(negdfa);
32
33                 if (newflag==null)
34                     newflag=tmp;
35                 else
36                    newflag=newflag.or(tmp);
37             }
38             if (notflag==null)
39                 notflag=newflag;
40             else
41                 notflag=notflag.and(newflag);
42         }
43         return notflag;
44     }
45
46     /** This method or's two DNFFlag expressions together. */
47     public DNFFlag or(DNFFlag dnf2) {
48         DNFFlag result=new DNFFlag();
49         for(int i=0;i<conjunctions.size();i++) {
50             Vector conjunct=(Vector)conjunctions.get(i);
51             Vector newvector=new Vector();
52             result.conjunctions.add(newvector);
53             for(int j=0;j<conjunct.size();j++) {
54                 newvector.add(conjunct.get(j));
55             }
56         }
57
58         for(int i=0;i<dnf2.conjunctions.size();i++) {
59             Vector conjunct=(Vector)dnf2.conjunctions.get(i);
60             Vector newvector=new Vector();
61             result.conjunctions.add(newvector);
62             for(int j=0;j<conjunct.size();j++) {
63                 newvector.add(conjunct.get(j));
64             }
65         }
66         return result;
67     }
68
69     /** This method and's two DNFFlag expressions together. */
70     public DNFFlag and(DNFFlag dnf2) {
71         DNFFlag result=new DNFFlag();
72         for(int i=0;i<conjunctions.size();i++) {
73             for(int i2=0;i2<dnf2.conjunctions.size();i2++) {
74                 Vector conjunct=(Vector)conjunctions.get(i);
75                 Vector conjunct2=(Vector)conjunctions.get(i2);
76                 Vector newconjunct=new Vector();
77                 result.conjunctions.add(newconjunct);
78                 for(int j=0;j<conjunct.size();j++) {
79                     newconjunct.add(conjunct.get(j));
80                 }
81                 for(int j2=0;j2<conjunct2.size();j2++) {                
82                     newconjunct.add(conjunct2.get(j2));
83                 }
84             }
85         }
86         return result;
87     }
88 }