]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/kinds/KMetaVar.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / kinds / KMetaVar.java
1 package org.simantics.scl.compiler.types.kinds;
2
3 import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
4 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
5
6 /**
7  * This class represents a kind metavariable that can contain a reference to a kind
8  * that is has been unified with. 
9  */
10 public class KMetaVar extends Kind {
11     Kind ref;
12
13     KMetaVar() {
14     }
15
16     /**
17      * Write the name of the reference type, or a name returned by #tuc.
18      */
19     @Override
20     protected void toStringPar(TypeUnparsingContext tuc, StringBuilder b) {
21         if(ref != null)
22             ref.toString(tuc, b);
23         else
24             b.append("?" + tuc.getName(this));
25     }
26
27     public void setRef(Kind a) throws KindUnificationException {
28         if(a.contains(this))
29             throw new KindUnificationException();
30         ref = a;
31     }
32
33     @Override
34     public boolean contains(KMetaVar var) {
35         if(ref == null)
36             return this == var;
37         else
38             return ref.contains(var);
39     }
40 }