6 public class DependencyBuilder {
8 Hashtable constraintnodes = new Hashtable();
9 Hashtable rulenodes = new Hashtable();
12 public DependencyBuilder(State state) {
16 public void calculate() {
17 /* reinitialize (clear) nodes */
18 constraintnodes = new Hashtable();
19 rulenodes = new Hashtable();
21 /* load up the rules and constraints */
22 Vector rules = state.vRules;
23 Vector constraints = state.vConstraints;
25 /* build up graph rulenodes (not edges yet) */
26 for (int i = 0; i < rules.size(); i++) {
27 Rule rule = (Rule) rules.elementAt(i);
29 assert rule.getLabel() != null;
31 Inclusion inclusion = rule.getInclusion();
32 Iterator targets = inclusion.getTargetDescriptors().iterator();
33 String additionallabel = new String();
35 /* #ATTN#: is this meant to be while, not if? */
36 /* perhaps there is only one descriptor for targets */
37 if (targets.hasNext()) {
38 Descriptor d = (Descriptor)targets.next();
39 additionallabel = "\\n" + d.getSymbol();
42 GraphNode gn = new GraphNode(rule.getLabel(), rule.getLabel() + additionallabel, rule);
43 rulenodes.put(rule.getLabel(), gn);
46 /* build up graph constraintnodes (not edges yet) */
47 for (int i = 0; i < constraints.size(); i++) {
48 Constraint constraint = (Constraint) constraints.elementAt(i);
49 assert constraint != null;
50 assert constraint.getLabel() != null;
51 GraphNode gn = new GraphNode(constraint.getLabel(), constraint);
52 gn.setDotNodeParameters("shape=box");
53 constraintnodes.put(constraint.getLabel(), gn);
56 /* calculate rule->rule dependencies */
57 for (int i = 0; i < rules.size(); i++) {
58 Rule rule = (Rule) rules.elementAt(i);
59 GraphNode rulenode = (GraphNode) rulenodes.get(rule.getLabel());
60 Set requiredsymbols = rule.getRequiredDescriptors();
61 requiredsymbols.addAll(rule.getInclusion().getRequiredDescriptors());
63 for (int j = 0; j < rules.size(); j++) {
69 Rule otherrule = (Rule) rules.elementAt(j);
70 Inclusion inclusion = otherrule.getInclusion();
71 Iterator targets = inclusion.getTargetDescriptors().iterator();
72 GraphNode otherrulenode = (GraphNode) rulenodes.get(otherrule.getLabel());
74 while (targets.hasNext()) {
75 Descriptor d = (Descriptor) targets.next();
77 if (requiredsymbols.contains(d)) { /* rule->rule dependency */
78 otherrulenode.addEdge(new GraphNode.Edge(d.getSymbol(), rulenode));
84 /* build constraint->rule dependencies */
85 for (int i = 0; i < constraints.size(); i++) {
86 Constraint constraint = (Constraint) constraints.elementAt(i);
87 GraphNode constraintnode = (GraphNode) constraintnodes.get(constraint.getLabel());
88 Set requiredsymbols = constraint.getRequiredDescriptorsFromLogicStatement();
89 Set requiredquantifiers = constraint.getRequiredDescriptorsFromQuantifiers();
91 for (int j = 0; j < rules.size(); j++) {
92 Rule otherrule = (Rule) rules.elementAt(j);
93 Inclusion inclusion = otherrule.getInclusion();
94 Iterator targets = inclusion.getTargetDescriptors().iterator();
95 GraphNode otherrulenode = (GraphNode) rulenodes.get(otherrule.getLabel());
97 while (targets.hasNext()) {
98 Descriptor d = (Descriptor) targets.next();
100 if (requiredsymbols.contains(d)) { /* logic->rule dependency */
101 GraphNode.Edge edge = new GraphNode.Edge(d.getSymbol(), constraintnode);
102 //edge.setDotNodeParameters("style=bold");
103 otherrulenode.addEdge(edge);
106 if (requiredquantifiers.contains(d)) { /* quantifier-> dependency */
107 GraphNode.Edge edge = new GraphNode.Edge(d.getSymbol(), constraintnode);
108 edge.setDotNodeParameters("style=dotted");
109 otherrulenode.addEdge(edge);
115 /* store results in state */
116 state.rulenodes = rulenodes;
117 state.constraintnodes = constraintnodes;
120 static class IntegerLattice {
126 public static final IntegerLattice TOP = new IntegerLattice(true);
127 public static final IntegerLattice BOT = new IntegerLattice(false);
129 private IntegerLattice(boolean top) {
134 public IntegerLattice(int num) {
141 public IntegerLattice setSize(SetDescriptor sd) {
142 String setname = sd.getSymbol();
144 if (setname.equals("Block")) {
145 return IntegerLattice.TOP;
146 } else if (setname.equals("UsedBlock")) {
147 return IntegerLattice.TOP;
148 } else if (setname.equals("FreeBlock")) {
149 return IntegerLattice.TOP;
150 } else if (setname.equals("Inode")) {
151 return IntegerLattice.TOP;
152 } else if (setname.equals("UsedInode")) {
153 return IntegerLattice.TOP;
154 } else if (setname.equals("FileInode")) {
155 return IntegerLattice.TOP;
156 } else if (setname.equals("DirectoryInode")) {
157 return new IntegerLattice(1);
158 } else if (setname.equals("RootDirectoryInode")) {
159 return new IntegerLattice(1);
160 } else if (setname.equals("SuperBlock")) {
161 return new IntegerLattice(1);
162 } else if (setname.equals("GroupBlock")) {
163 return new IntegerLattice(1);
164 } else if (setname.equals("FileDirectoryBlock")) {
165 return IntegerLattice.TOP;
166 } else if (setname.equals("InodeTableBlock")) {
167 return new IntegerLattice(1);
168 } else if (setname.equals("InodeBitmapBlock")) {
169 return new IntegerLattice(1);
170 } else if (setname.equals("BlockBitmapBlock")) {
171 return new IntegerLattice(1);
172 } else if (setname.equals("DirectoryBlock")) {
173 return new IntegerLattice(0);
174 } else if (setname.equals("FileBlock")) {
175 return IntegerLattice.TOP;
176 } else if (setname.equals("DirectoryEntry")) {
177 return IntegerLattice.TOP;
179 throw new IRException();