]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Type.java
Merge "List the unsatisfied dependencies in CanvasContext"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / Type.java
index 1709ebbeeeab415361894829982922bf8201bc13..c158cb31bc8b99b42d4b390c09bce0df0aef396b 100644 (file)
@@ -1,12 +1,10 @@
 package org.simantics.scl.compiler.types;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayList;
 import java.util.Map;
 
 import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
 import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
 import org.simantics.scl.compiler.internal.types.ast.TypeAst;
 import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
@@ -16,6 +14,9 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.Polarity;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
 
 
 /**
@@ -37,8 +38,13 @@ public abstract class Type {
     public static final int METAVAR_ID = 5;
     public static final int VAR_ID = 6;
     public static final int UNION_ID = 7;
-    public static final int ALIAS_ID = 8;
     
+    protected static final int APPLY_HASH = HashCodeUtils.preprocessValue(0);
+    protected static final int FORALL_HASH = HashCodeUtils.preprocessValue(1);
+    protected static final int FUN_HASH = HashCodeUtils.preprocessValue(2);
+    protected static final int PRED_HASH = HashCodeUtils.preprocessValue(3);
+    protected static final int UNION_HASH = HashCodeUtils.preprocessValue(4);
+    protected static final int BOUND_VAR_HASH = HashCodeUtils.preprocessValue(5);
     
     /*
      * This class is not meant to be extended outside of this package. 
@@ -107,12 +113,19 @@ public abstract class Type {
     
     @Override
     public int hashCode() {
-        TypeHashCodeContext context = new TypeHashCodeContext();
-        updateHashCode(context);
-        return context.getResult();
+        return hashCode(HashCodeUtils.SEED);
     }
     
     public abstract void updateHashCode(TypeHashCodeContext context);
+    public abstract int hashCode(int hash);
+    public abstract int hashCode(int hash, TVar[] boundVars);
+    
+    public int skeletonHashCode() {
+        return skeletonHashCode(HashCodeUtils.SEED);
+    }
+    
+    public abstract int skeletonHashCode(int hash);
+    public abstract int skeletonHashCode(int hash, TVar[] boundVars);
 
     public abstract void collectFreeVars(ArrayList<TVar> vars);
     
@@ -160,5 +173,15 @@ public abstract class Type {
      * Creates an independent copy of the type, but replaces all effects by metavars
      */
     public abstract Type copySkeleton(THashMap<TMetaVar,TMetaVar> metaVarMap);
+    
+    public abstract boolean equalsCanonical(Type other);
+    
+    public Type canonical() {
+        return this;
+    }
+
+    public abstract Kind getKind(Environment context);
 
+    public abstract Type[] skeletonCanonicalChildren(); 
+            
 }
\ No newline at end of file