]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TApply.java
Merge "Ensure GetElementClassRequest is not constructed without elementFactory"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / TApply.java
index ced969286a869109ea739c2ff7fdb76edb888a14..bd58949a6309918eb1ee0fce39425231c4056149 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.List;
 
 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.TListAst;
@@ -19,6 +17,9 @@ import org.simantics.scl.compiler.types.util.Polarity;
 import org.simantics.scl.compiler.types.util.TMultiApply;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
 
 
 /**
@@ -26,8 +27,8 @@ import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
  * @author Hannu Niemistö
  */
 public class TApply extends Type {
-    public final Type function;
-    public final Type parameter;
+    public Type function;
+    public Type parameter;
     
     public TApply(Type function, Type parameter) {
         if(NULL_CHECKS) {
@@ -156,6 +157,12 @@ public class TApply extends Type {
         Kind parameterKind = parameter.inferKind(context);
         Kinds.unify(functionKind, Kinds.arrow(parameterKind, requiredKind));
     }
+       
+       @Override
+       public Kind getKind(Environment context) {
+           Kind functionKind = function.getKind(context);
+           return Kinds.rangeOfArrow(functionKind);
+       }
 
     @Override
     public boolean containsMetaVars() {
@@ -194,4 +201,64 @@ public class TApply extends Type {
         else
             return new TApply(newFunction, newParameter);
     }
+
+    @Override
+    public int hashCode(int hash) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+        hash = function.hashCode(hash);
+        hash = parameter.hashCode(hash);
+        return hash;
+    }
+    
+    @Override
+    public int hashCode(int hash, TVar[] boundVars) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+        hash = function.hashCode(hash, boundVars);
+        hash = parameter.hashCode(hash, boundVars);
+        return hash;
+    }
+    
+    @Override
+    public int skeletonHashCode(int hash) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+        hash = function.skeletonHashCode(hash);
+        hash = parameter.skeletonHashCode(hash);
+        return hash;
+    }
+    
+    @Override
+    public int skeletonHashCode(int hash, TVar[] boundVars) {
+        hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+        hash = function.skeletonHashCode(hash, boundVars);
+        hash = parameter.skeletonHashCode(hash, boundVars);
+        return hash;
+    }
+    
+    public Type getCanonicalFunction() {
+        if(function instanceof TMetaVar)
+            function = function.canonical();
+        return function;
+    }
+    
+    public Type getCanonicalParameter() {
+        if(parameter instanceof TMetaVar)
+            parameter = parameter.canonical();
+        return parameter;
+    }
+    
+    @Override
+    public boolean equalsCanonical(Type other) {
+        if(this == other)
+            return true;
+        if(!other.getClass().equals(TApply.class))
+            return false;
+        TApply apply = (TApply)other;
+        return getCanonicalFunction().equalsCanonical(apply.getCanonicalFunction())
+                && getCanonicalParameter().equalsCanonical(apply.getCanonicalParameter());
+    }
+    
+    @Override
+    public Type[] skeletonCanonicalChildren() {
+        return new Type[] {Skeletons.canonicalSkeleton(function), Skeletons.canonicalSkeleton(parameter)};
+    }
 }