|
1 |
| package edu.rice.cs.dynamicjava.symbol; |
|
2 |
| |
|
3 |
| import edu.rice.cs.dynamicjava.symbol.type.Type; |
|
4 |
| import edu.rice.cs.plt.lambda.DelayedThunk; |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| public class BoundedSymbol { |
|
18 |
| |
|
19 |
| private final Object _id; |
|
20 |
| private final boolean _generated; |
|
21 |
| private final String _name; |
|
22 |
| private final DelayedThunk<Type> _upperBound; |
|
23 |
| private final DelayedThunk<Type> _lowerBound; |
|
24 |
| |
|
25 |
842
| public BoundedSymbol(Object id) {
|
|
26 |
842
| _id = id;
|
|
27 |
842
| _generated = true;
|
|
28 |
842
| _name = null;
|
|
29 |
842
| _upperBound = new DelayedThunk<Type>();
|
|
30 |
842
| _lowerBound = new DelayedThunk<Type>();
|
|
31 |
| } |
|
32 |
| |
|
33 |
12607
| public BoundedSymbol(Object id, String name) {
|
|
34 |
12607
| _id = id;
|
|
35 |
12607
| _generated = false;
|
|
36 |
12607
| _name = name;
|
|
37 |
12607
| _upperBound = new DelayedThunk<Type>();
|
|
38 |
12607
| _lowerBound = new DelayedThunk<Type>();
|
|
39 |
| } |
|
40 |
| |
|
41 |
143
| public BoundedSymbol(Object id, Type upperBound, Type lowerBound) {
|
|
42 |
143
| this(id);
|
|
43 |
143
| _upperBound.set(upperBound);
|
|
44 |
143
| _lowerBound.set(lowerBound);
|
|
45 |
| } |
|
46 |
| |
|
47 |
69
| public BoundedSymbol(Object id, String name, Type upperBound, Type lowerBound) {
|
|
48 |
69
| this(id, name);
|
|
49 |
69
| _upperBound.set(upperBound);
|
|
50 |
69
| _lowerBound.set(lowerBound);
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
13
| public boolean generated() { return _generated; }
|
|
63 |
| |
|
64 |
773
| public String name() {
|
|
65 |
0
| if (_generated) { throw new IllegalArgumentException("Symbol is unnamed"); }
|
|
66 |
773
| else { return _name; }
|
|
67 |
| } |
|
68 |
| |
|
69 |
13222
| public void initializeUpperBound(Type t) { _upperBound.set(t); }
|
|
70 |
| |
|
71 |
13222
| public void initializeLowerBound(Type t) { _lowerBound.set(t); }
|
|
72 |
| |
|
73 |
3078
| public Type upperBound() { return _upperBound.value(); }
|
|
74 |
| |
|
75 |
2682
| public Type lowerBound() { return _lowerBound.value(); }
|
|
76 |
| |
|
77 |
0
| public String toString() { return "symbol " + _id; }
|
|
78 |
| |
|
79 |
2730
| public boolean equals(Object o) {
|
|
80 |
0
| if (this == o) { return true; }
|
|
81 |
0
| else if (!(o instanceof BoundedSymbol)) { return false; }
|
|
82 |
2730
| else { return ((BoundedSymbol) o)._id.equals(_id); }
|
|
83 |
| } |
|
84 |
| |
|
85 |
5172
| public int hashCode() {
|
|
86 |
5172
| return getClass().hashCode() ^ _id.hashCode();
|
|
87 |
| } |
|
88 |
| |
|
89 |
| } |