X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTApply.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTApply.java;h=88d80882e67312989f945ee6a81524b79418fcad;hb=9a175feb652b2b7bba7afa540831b9076be3c10e;hp=ced969286a869109ea739c2ff7fdb76edb888a14;hpb=0b72d3e4ec886838314ffeba0fa201e32c0aae3e;p=simantics%2Fplatform.git 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..88d80882e 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,43 @@ 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; + } + + 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()); + } }