01: /**************************************************************************/
02: /* N I C E */
03: /* A high-level object-oriented research language */
04: /* (c) Daniel Bonniot 2002 */
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;
12:
13: /**
14: * Constraint a type constructor to be lower than a monotype's head.
15: *
16: * The constraint is posed on the raw monotype, after the nullness marker.
17: *
18: * @author Daniel Bonniot
19: */
20:
21: public final class TypeConstructorLeqMonotypeCst extends
22: AtomicConstraint {
23: public TypeConstructorLeqMonotypeCst(TypeConstructor t1, Monotype t2) {
24: this .t1 = t1;
25: this .t2 = t2;
26: }
27:
28: /**
29: * Perform type symbol substitution inside the constraint.
30: *
31: * Does not need to create a new object, but must not
32: * imperatively modify the constraint.
33: *
34: * @param map a map from TypeSymbols to TypeSymbols
35: * @return an atomic constraint with substitution performed
36: */
37: AtomicConstraint substitute(java.util.Map map) {
38: Object tt1, tt2;
39: tt1 = map.get(t1);
40: tt2 = map.get(t2);
41:
42: if (tt1 == null && tt2 == null)
43: return this ;
44:
45: if (tt1 == null)
46: tt1 = t1;
47: else if (tt2 == null)
48: tt2 = t2;
49:
50: return new TypeConstructorLeqMonotypeCst((TypeConstructor) tt1,
51: (Monotype) tt2);
52: }
53:
54: public void enter() throws TypingEx {
55: // Use the raw type of t2, after the nullness marker.
56: Typing.leq(t1, nice.tools.typing.Types.rawType(t2));
57: }
58:
59: public String toString() {
60: return t1 + " < " + t2;
61: }
62:
63: private TypeConstructor t1;
64: private Monotype t2;
65:
66: public TypeConstructor t1() {
67: return t1;
68: }
69:
70: public Monotype t2() {
71: return t2;
72: }
73: }
|