package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-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.TVarAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
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.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+
-public class TVar extends Type {
+public final class TVar extends Type {
public static final TVar[] EMPTY_ARRAY = new TVar[0];
private Kind kind;
return this == obj;
}
- @Override
- public int hashCode() {
- return System.identityHashCode(this);
- }
-
@Override
public void updateHashCode(TypeHashCodeContext context) {
TObjectIntHashMap<TVar> varHashCode = context.getVarHashCode();
public Type copySkeleton(THashMap<TMetaVar, TMetaVar> metaVarMap) {
return this;
}
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(this);
+ }
+
+ @Override
+ public int hashCode(int hash) {
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ for(int i=0;i<boundVars.length;++i)
+ if(boundVars[i] == this) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, BOUND_VAR_HASH);
+ return HashCodeUtils.update(hash, i);
+ }
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public int skeletonHashCode() {
+ return System.identityHashCode(this);
+ }
+
+ @Override
+ public int skeletonHashCode(int hash) {
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public int skeletonHashCode(int hash, TVar[] boundVars) {
+ for(int i=0;i<boundVars.length;++i)
+ if(boundVars[i] == this) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, BOUND_VAR_HASH);
+ return HashCodeUtils.update(hash, i);
+ }
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ return this == other;
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return kind;
+ }
+
+ @Override
+ public Type[] skeletonCanonicalChildren() {
+ return EMPTY_ARRAY;
+ }
}