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;
12:
13: import java.util.*;
14:
15: /**
16: * Inequality between monotypes
17: *
18: * @author bonniot
19: */
20:
21: public class MonotypeLeqCst extends AtomicConstraint {
22: public MonotypeLeqCst(Monotype m1, Monotype m2) {
23: this .m1 = m1;
24: this .m2 = m2;
25: }
26:
27: /**
28: * Perform type symbol substitution inside the constraint.
29: *
30: * Does not need to create a new object, but must not
31: * imperatively modify the constraint.
32: *
33: * @param map a map from TypeSymbols to TypeSymbols
34: * @return an atomic constraint with substitution performed
35: */
36: AtomicConstraint substitute(java.util.Map map) {
37: Monotype new1 = m1.substitute(map);
38: Monotype new2 = m2.substitute(map);
39:
40: if (new1 == m1 && new2 == m2)
41: return this ;
42:
43: return new MonotypeLeqCst(new1, new2);
44: }
45:
46: void enter() throws TypingEx {
47: Typing.leq(m1, m2);
48: }
49:
50: /****************************************************************
51: * Manipulation
52: ****************************************************************/
53:
54: public static Constraint constraint(Monotype[] c1, Monotype[] c2) {
55: ArrayList a = new ArrayList(c1.length);
56:
57: for (int i = 0; i < c1.length; i++) {
58: Monotype m1 = c1[i], m2 = c2[i];
59:
60: // optimization: the constraint m<=m is useless since trivially true
61: if (m1.equals(m2))
62: continue;
63:
64: a.add(new MonotypeLeqCst(m1, m2));
65: }
66:
67: return new Constraint(null, (AtomicConstraint[]) a
68: .toArray(new AtomicConstraint[a.size()]));
69: }
70:
71: /****************************************************************
72: * Printing
73: ****************************************************************/
74:
75: public String toString() {
76: return m1 + " <: " + m2;
77: }
78:
79: private Monotype m1, m2;
80: }
|