X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTApply.java;h=bd58949a6309918eb1ee0fce39425231c4056149;hp=ced969286a869109ea739c2ff7fdb76edb888a14;hb=cb5fc8d606d8b322563e9345c441eecfa7f01753;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TApply.java index ced969286..bd58949a6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TApply.java @@ -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)}; + } }