]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TPred.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / TPred.java
index d9fd79f917f3770b7f730caaacd9017d5aba348f..e8a0469c5d996f428c205c13018fe1e6e009707c 100644 (file)
@@ -1,11 +1,9 @@
 package org.simantics.scl.compiler.types;
 
-import gnu.trove.map.hash.THashMap;
-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.TApplyAst;
 import org.simantics.scl.compiler.internal.types.ast.TypeAst;
@@ -15,6 +13,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;
+
 
 
 public class TPred extends Type {
@@ -172,4 +173,42 @@ public class TPred extends Type {
             newParameters[i] = parameters[i].copySkeleton(metaVarMap);
         return new TPred(typeClass, parameters);
     }
+    
+    @Override
+    public int hashCode(int hash) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+        hash = typeClass.hashCode(hash);
+        for(Type parameter : parameters)
+            hash = parameter.hashCode(hash);
+        return hash;
+    }
+    
+    @Override
+    public int hashCode(int hash, TVar[] boundVars) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+        hash = typeClass.hashCode(hash, boundVars);
+        for(Type parameter : parameters)
+            hash = parameter.hashCode(hash, boundVars);
+        return hash;
+    }
+
+    @Override
+    public boolean equalsCanonical(Type other) {
+        if(this == other)
+            return true;
+        if(!other.getClass().equals(TPred.class))
+            return false;
+        TPred pred = (TPred)other;
+        if(typeClass != pred.typeClass || parameters.length != pred.parameters.length)
+            return false;
+        for(int i=0;i<parameters.length;++i)
+            if(!Types.canonical(parameters[i]).equalsCanonical(Types.canonical(pred.parameters[i])))
+                return false;
+        return true;
+    }
+
+    @Override
+    public Kind getKind(Environment context) {
+        return Kinds.STAR;
+    }
 }