01: /**************************************************************************/
02: /* B O S S A */
03: /* A simple imperative object-oriented research language */
04: /* (c) Daniel Bonniot 1999 */
05: /* */
06: /* This program is free software; you can redistribute it and/or modify */
07: /* it under the terms of the GNU General Public License as published by */
08: /* the Free Software Foundation; either version 2 of the License, or */
09: /* (at your option) any later version. */
10: /* */
11: /**************************************************************************/package mlsub.typing.lowlevel;
12:
13: class Interface {
14: Interface(K0 k0, int iid) {
15: this .k0 = k0;
16: this .iid = iid;
17: }
18:
19: private K0 k0;
20:
21: // index in the corresponding vector K0.interfaces
22: private int iid;
23:
24: int getIndex() {
25: return iid;
26: }
27:
28: // the set of IDs of all the sub-interfaces of this interface
29: BitVector subInterfaces = new BitVector();
30:
31: // the set of all rigid indexes that implement this interface
32: BitVector rigidImplementors = null;
33:
34: // the set of all indexes (rigid and soft) that implement this interface
35: BitVector implementors = new BitVector();
36:
37: // the set of all (rigid) indexes that abstract this interface
38: BitVector abstractors = new BitVector();
39:
40: // the approximation of each node of the original context
41: private final IntVect approx = new IntVect(
42: BitVector.UNDEFINED_INDEX);
43: private final BitVector hasapprox = new BitVector();
44:
45: public BitVector getHasApprox() {
46: return hasapprox;
47: }
48:
49: public void setApprox(int node, int approx) {
50: if (node >= this .approx.size())
51: this .approx.setSize(node + 1, BitVector.UNDEFINED_INDEX);
52: this .approx.set(node, approx);
53: if (approx == BitVector.UNDEFINED_INDEX)
54: hasapprox.clear(node);
55: else
56: hasapprox.set(node);
57: }
58:
59: /**
60: * Get the approximation of a node
61: *
62: * @param node the index of a node
63: * @return its approximation
64: */
65: public int getApprox(int node) {
66: return approx.get(node);
67: }
68:
69: void setIndexSize(int n) {
70: implementors.truncate(n);
71: approx.setSize(n, BitVector.UNDEFINED_INDEX);
72: hasapprox.truncate(n);
73: }
74:
75: void indexMove(int src, int dest) {
76: implementors.bitCopy(src, dest);
77: approx.set(dest, approx.get(src));
78: hasapprox.set(dest);
79: if (k0.isRigid(src)) {
80: // strange as the relation on the rigid indexes should already be
81: // condensed... but let's be general
82: rigidImplementors.bitCopy(src, dest);
83: abstractors.bitCopy(src, dest);
84: }
85: }
86:
87: void indexMerge(int src, int dest) {
88: implementors.bitMerge(src, dest);
89: if (k0.isRigid(src)) {
90: // this is strange... (see above)
91: rigidImplementors.bitMerge(src, dest);
92: abstractors.bitMerge(src, dest);
93: }
94: }
95:
96: public String toString() {
97: return k0.interfaceToString(iid);
98: }
99: }
|