]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TPred.java
Merge "Remove unused import in DeleteHandler"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / TPred.java
index d9fd79f917f3770b7f730caaacd9017d5aba348f..c28e62093abb249896adf6689135b1ac787296d2 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,68 @@ 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 int skeletonHashCode(int hash) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+        hash = typeClass.skeletonHashCode(hash);
+        for(Type parameter : parameters)
+            hash = parameter.skeletonHashCode(hash);
+        return hash;
+    }
+    
+    @Override
+    public int skeletonHashCode(int hash, TVar[] boundVars) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+        hash = typeClass.skeletonHashCode(hash, boundVars);
+        for(Type parameter : parameters)
+            hash = parameter.skeletonHashCode(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;
+    }
+
+    @Override
+    public Type[] skeletonCanonicalChildren() {
+        Type[] result = new Type[parameters.length];
+        for(int i=0;i<parameters.length;++i)
+            result[i] = Skeletons.canonicalSkeleton(parameters[i]);
+        return result;
+    }
 }