Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: mlsub/typing/TypeConstructorLeqMonotypeCst.java


1   /**************************************************************************/
2   /*                                N I C E                                 */
3   /*             A high-level object-oriented research language             */
4   /*                        (c) Daniel Bonniot 2002                         */
5   /*                                                                        */
6   /*  This program is free software; you can redistribute it and/or modify  */
7   /*  it under the terms of the GNU General Public License as published by  */
8   /*  the Free Software Foundation; either version 2 of the License, or     */
9   /*  (at your option) any later version.                                   */
10  /*                                                                        */
11  /**************************************************************************/
12  
13  package mlsub.typing;
14  
15  /**
16   * Constraint a type constructor to be lower than a monotype's head.
17   *
18   * The constraint is posed on the raw monotype, after the nullness marker.
19   * 
20   * @author Daniel Bonniot
21   */
22  
23  public final class TypeConstructorLeqMonotypeCst extends AtomicConstraint
24  {
25    public TypeConstructorLeqMonotypeCst(TypeConstructor t1, Monotype t2)
26    {
27      this.t1 = t1;
28      this.t2 = t2;
29    }
30  
31    /**
32     * Perform type symbol substitution inside the constraint.
33     *
34     * Does not need to create a new object, but must not
35     * imperatively modify the constraint.
36     *
37     * @param map a map from TypeSymbols to TypeSymbols
38     * @return an atomic constraint with substitution performed
39     */
40    AtomicConstraint substitute(java.util.Map map)
41    {
42      Object tt1, tt2;
43      tt1 = map.get(t1);
44      tt2 = map.get(t2);
45      
46      if(tt1==null && tt2==null)
47        return this;
48      
49      if(tt1==null)
50        tt1 = t1;
51      else if(tt2==null)
52        tt2 = t2;
53      
54      return new TypeConstructorLeqMonotypeCst
55        ((TypeConstructor) tt1, (Monotype) tt2);
56    }
57  
58    public void enter()
59    throws TypingEx
60    {
61      // Use the raw type of t2, after the nullness marker.
62      Typing.leq(t1, nice.tools.code.Types.rawType(t2));
63    }
64    
65    public String toString()
66    {
67      return t1 + " < " + t2;
68    }
69  
70    private TypeConstructor t1;
71    private Monotype t2;
72  
73    public TypeConstructor t1() { return t1; }
74    public Monotype t2() { return t2; }
75  }