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 if (targets.hasNext()) {
37 Descriptor d = (Descriptor)targets.next();
38 additionallabel = "\\n" + d.getSymbol();
41 GraphNode gn = new GraphNode(rule.getLabel(), rule.getLabel() + additionallabel, rule);
42 rulenodes.put(rule.getLabel(), gn);
45 /* build up graph constraintnodes (not edges yet) */
46 for (int i = 0; i < constraints.size(); i++) {
47 Constraint constraint = (Constraint) constraints.elementAt(i);
48 assert constraint != null;
49 assert constraint.getLabel() != null;
50 GraphNode gn = new GraphNode(constraint.getLabel(), constraint);
51 gn.setDotNodeParameters("shape=box");
52 constraintnodes.put(constraint.getLabel(), gn);
55 /* calculate rule->rule dependencies */
56 for (int i = 0; i < rules.size(); i++) {
57 Rule rule = (Rule) rules.elementAt(i);
58 GraphNode rulenode = (GraphNode) rulenodes.get(rule.getLabel());
59 Set requiredsymbols = rule.getRequiredDescriptors();
61 for (int j = 0; j < rules.size(); j++) {
67 Rule otherrule = (Rule) rules.elementAt(j);
68 Inclusion inclusion = otherrule.getInclusion();
69 Iterator targets = inclusion.getTargetDescriptors().iterator();
70 GraphNode otherrulenode = (GraphNode) rulenodes.get(otherrule.getLabel());
72 while (targets.hasNext()) {
73 Descriptor d = (Descriptor) targets.next();
75 if (requiredsymbols.contains(d)) { /* rule->rule dependency */
76 otherrulenode.addEdge(new GraphNode.Edge(d.getSymbol(), rulenode));
82 /* build constraint->rule dependencies */
83 for (int i = 0; i < constraints.size(); i++) {
84 Constraint constraint = (Constraint) constraints.elementAt(i);
85 GraphNode constraintnode = (GraphNode) constraintnodes.get(constraint.getLabel());
86 Set requiredsymbols = constraint.getRequiredDescriptorsFromLogicStatement();
87 Set requiredquantifiers = constraint.getRequiredDescriptorsFromQuantifiers();
89 for (int j = 0; j < rules.size(); j++) {
90 Rule otherrule = (Rule) rules.elementAt(j);
91 Inclusion inclusion = otherrule.getInclusion();
92 Iterator targets = inclusion.getTargetDescriptors().iterator();
93 GraphNode otherrulenode = (GraphNode) rulenodes.get(otherrule.getLabel());
95 while (targets.hasNext()) {
96 Descriptor d = (Descriptor) targets.next();
98 if (requiredsymbols.contains(d)) { /* logic->rule dependency */
99 GraphNode.Edge edge = new GraphNode.Edge(d.getSymbol(), constraintnode);
100 //edge.setDotNodeParameters("style=bold");
101 otherrulenode.addEdge(edge);
104 if (requiredquantifiers.contains(d)) { /* quantifier-> dependency */
105 GraphNode.Edge edge = new GraphNode.Edge(d.getSymbol(), constraintnode);
106 edge.setDotNodeParameters("style=dotted");
107 otherrulenode.addEdge(edge);
113 /* store results in state */
114 state.rulenodes = rulenodes;
115 state.constraintnodes = constraintnodes;
118 static class IntegerLattice {
124 public static final IntegerLattice TOP = new IntegerLattice(true);
125 public static final IntegerLattice BOT = new IntegerLattice(false);
127 private IntegerLattice(boolean top) {
132 public IntegerLattice(int num) {
139 public IntegerLattice setSize(SetDescriptor sd) {
140 String setname = sd.getSymbol();
142 if (setname.equals("Block")) {
143 return IntegerLattice.TOP;
144 } else if (setname.equals("UsedBlock")) {
145 return IntegerLattice.TOP;
146 } else if (setname.equals("FreeBlock")) {
147 return IntegerLattice.TOP;
148 } else if (setname.equals("Inode")) {
149 return IntegerLattice.TOP;
150 } else if (setname.equals("UsedInode")) {
151 return IntegerLattice.TOP;
152 } else if (setname.equals("FileInode")) {
153 return IntegerLattice.TOP;
154 } else if (setname.equals("DirectoryInode")) {
155 return new IntegerLattice(1);
156 } else if (setname.equals("RootDirectoryInode")) {
157 return new IntegerLattice(1);
158 } else if (setname.equals("SuperBlock")) {
159 return new IntegerLattice(1);
160 } else if (setname.equals("GroupBlock")) {
161 return new IntegerLattice(1);
162 } else if (setname.equals("FileDirectoryBlock")) {
163 return IntegerLattice.TOP;
164 } else if (setname.equals("InodeTableBlock")) {
165 return new IntegerLattice(1);
166 } else if (setname.equals("InodeBitmapBlock")) {
167 return new IntegerLattice(1);
168 } else if (setname.equals("BlockBitmapBlock")) {
169 return new IntegerLattice(1);
170 } else if (setname.equals("DirectoryBlock")) {
171 return new IntegerLattice(0);
172 } else if (setname.equals("FileBlock")) {
173 return IntegerLattice.TOP;
174 } else if (setname.equals("DirectoryEntry")) {
175 return IntegerLattice.TOP;
177 throw new IRException();