]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/kinds/KMetaVar.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/kinds/KMetaVar.java
new file mode 100644 (file)
index 0000000..08a908f
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.scl.compiler.types.kinds;
+
+import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
+import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+
+/**
+ * This class represents a kind metavariable that can contain a reference to a kind
+ * that is has been unified with. 
+ */
+public class KMetaVar extends Kind {
+    Kind ref;
+
+    KMetaVar() {
+    }
+
+    /**
+     * Write the name of the reference type, or a name returned by #tuc.
+     */
+    @Override
+    protected void toStringPar(TypeUnparsingContext tuc, StringBuilder b) {
+        if(ref != null)
+            ref.toString(tuc, b);
+        else
+            b.append("?" + tuc.getName(this));
+    }
+
+    public void setRef(Kind a) throws KindUnificationException {
+        if(a.contains(this))
+            throw new KindUnificationException();
+        ref = a;
+    }
+
+    @Override
+    public boolean contains(KMetaVar var) {
+        if(ref == null)
+            return this == var;
+        else
+            return ref.contains(var);
+    }
+}