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;
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;
+
/**
* @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) {
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() {
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)};
+ }
}