]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TVar.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / TVar.java
index 1fca6c59aa4b884fa6679dc68390e17ff82d2865..df342dd5fb2e9074e9da1e3a3b3c9a76a6ff80a7 100644 (file)
@@ -1,12 +1,9 @@
 package org.simantics.scl.compiler.types;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayList;
 
 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.TVarAst;
 import org.simantics.scl.compiler.internal.types.ast.TypeAst;
@@ -17,8 +14,12 @@ 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.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+
 
-public class TVar extends Type {
+public final class TVar extends Type {
     public static final TVar[] EMPTY_ARRAY = new TVar[0];
     
     private Kind kind;
@@ -58,11 +59,6 @@ public class TVar extends Type {
         return this == obj;
     }
     
-    @Override
-    public int hashCode() {
-        return System.identityHashCode(this);
-    }
-    
     @Override
     public void updateHashCode(TypeHashCodeContext context) {
         TObjectIntHashMap<TVar> varHashCode = context.getVarHashCode();
@@ -139,4 +135,59 @@ public class TVar extends Type {
     public Type copySkeleton(THashMap<TMetaVar, TMetaVar> metaVarMap) {
         return this;
     }
+    
+    @Override
+    public int hashCode() {
+        return System.identityHashCode(this);
+    }
+    
+    @Override
+    public int hashCode(int hash) {
+        return HashCodeUtils.update(hash, System.identityHashCode(this));
+    }
+    
+    @Override
+    public int hashCode(int hash, TVar[] boundVars) {
+        for(int i=0;i<boundVars.length;++i)
+            if(boundVars[i] == this) {
+                hash = HashCodeUtils.updateWithPreprocessedValue(hash, BOUND_VAR_HASH);
+                return HashCodeUtils.update(hash, i);
+            }
+        return HashCodeUtils.update(hash, System.identityHashCode(this));
+    }
+    
+    @Override
+    public int skeletonHashCode() {
+        return System.identityHashCode(this);
+    }
+    
+    @Override
+    public int skeletonHashCode(int hash) {
+        return HashCodeUtils.update(hash, System.identityHashCode(this));
+    }
+    
+    @Override
+    public int skeletonHashCode(int hash, TVar[] boundVars) {
+        for(int i=0;i<boundVars.length;++i)
+            if(boundVars[i] == this) {
+                hash = HashCodeUtils.updateWithPreprocessedValue(hash, BOUND_VAR_HASH);
+                return HashCodeUtils.update(hash, i);
+            }
+        return HashCodeUtils.update(hash, System.identityHashCode(this));
+    }
+    
+    @Override
+    public boolean equalsCanonical(Type other) {
+        return this == other;
+    }
+
+    @Override
+    public Kind getKind(Environment context) {
+        return kind;
+    }
+    
+    @Override
+    public Type[] skeletonCanonicalChildren() {
+        return EMPTY_ARRAY;
+    }
 }