IR
[repair.git] / Repair / RepairCompiler / MCC / IR / LogicStatement.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class LogicStatement {
6
7     public static final Operation AND = new Operation("AND");
8     public static final Operation OR = new Operation("OR");
9     public static final Operation NOT = new Operation("NOT");
10     
11     public static class Operation {
12         private final String name;
13         private Operation(String opname) { name = opname; }
14         public String toString() { return name; }
15     }
16
17     Operation op;
18     LogicStatement left;
19     LogicStatement right;
20
21     public LogicStatement(Operation op, LogicStatement left, LogicStatement right) {
22         if (op == NOT) {
23             throw new IllegalArgumentException("Must be a AND or OR expression.");
24         }
25
26         this.op = op;
27         this.left = left;
28         this.right = right;
29     }
30
31     public LogicStatement(Operation op, LogicStatement left) {
32         if (op != NOT) {
33             throw new IllegalArgumentException("Must be a NOT expression.");
34         }
35
36         this.op = op;
37         this.left = left;
38         this.right = null;
39     }
40
41     protected LogicStatement() {
42         this.op = null;
43         this.left = null;
44         this.right = null;
45     }
46
47     public Set getRequiredDescriptors() {
48         Set v = left.getRequiredDescriptors();
49         if (right != null) {
50             v.addAll(right.getRequiredDescriptors());
51         }
52         return v;
53     }
54    
55 }