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