X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTUnion.java;h=9b2449aa706c31a07e510157bfd0ec2127a6214e;hb=4bf8562ab7cbb3747f9c5844a07469291d43e905;hp=e14ddb3052d5f30a57177753ec32fbc01b078fff;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java index e14ddb305..9b2449aa7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java @@ -1,17 +1,21 @@ 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.common.exceptions.InternalCompilerError; +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.TConAst; import org.simantics.scl.compiler.internal.types.ast.TypeAst; +import org.simantics.scl.compiler.types.kinds.Kind; +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 TUnion extends Type { public final Type[] effects; @@ -164,4 +168,85 @@ public class TUnion extends Type { public Type copySkeleton(THashMap metaVarMap) { return Types.NO_EFFECTS; } + + @Override + public int hashCode(int hash) { + int sum = UNION_HASH; + for(Type effect : effects) + sum += effect.hashCode(HashCodeUtils.SEED); + return HashCodeUtils.updateWithPreprocessedValue(hash, sum); + } + + @Override + public int hashCode(int hash, TVar[] boundVars) { + int sum = UNION_HASH; + for(Type effect : effects) + sum += effect.hashCode(HashCodeUtils.SEED, boundVars); + return HashCodeUtils.updateWithPreprocessedValue(hash, sum); + } + + @Override + public int skeletonHashCode(int hash) { + int sum = UNION_HASH; + for(Type effect : effects) + sum += effect.skeletonHashCode(HashCodeUtils.SEED); + return HashCodeUtils.updateWithPreprocessedValue(hash, sum); + } + + @Override + public int skeletonHashCode(int hash, TVar[] boundVars) { + int sum = UNION_HASH; + for(Type effect : effects) + sum += effect.skeletonHashCode(HashCodeUtils.SEED, boundVars); + return HashCodeUtils.updateWithPreprocessedValue(hash, sum); + } + + @Override + public boolean equalsCanonical(Type other) { + if(this == other) + return true; + if(!other.getClass().equals(TUnion.class)) + return false; + TUnion union = (TUnion)other; + int length = effects.length; + if(length != union.effects.length) + return false; + if(length == 0) + return true; + for(int i=0;i i) { + effect = union.effects[i]; + union.effects[i] = union.effects[j]; + union.effects[j] = effect; + } + continue loop; + } + return false; + } + return true; + } + + @Override + public Kind getKind(Environment context) { + return Kinds.EFFECT; + } + + @Override + public Type[] skeletonCanonicalChildren() { + return EMPTY_ARRAY; + } }