1 package org.simantics.scl.compiler.types.util;
3 import java.util.Comparator;
5 import org.simantics.scl.compiler.types.TApply;
6 import org.simantics.scl.compiler.types.TCon;
7 import org.simantics.scl.compiler.types.TFun;
8 import org.simantics.scl.compiler.types.TPred;
9 import org.simantics.scl.compiler.types.TUnion;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
13 public enum TypeComparator implements Comparator<Type> {
17 public int compare(Type t1, Type t2) {
18 t1 = Types.canonical(t1);
19 t2 = Types.canonical(t2);
20 int id1 = t1.getClassId();
21 int id2 = t2.getClassId();
29 TApply p1 = (TApply)t1;
30 TApply p2 = (TApply)t2;
31 cur = compare(p1.function, p2.function);
34 return compare(p1.parameter, p2.parameter);
37 return TConComparator.INSTANCE.compare((TCon)t1, (TCon)t2);
39 return 0; // TODO hard to compare
43 cur = TConComparator.INSTANCE.compare(p1.typeClass, p2.typeClass);
46 cur = p1.parameters.length - p2.parameters.length;
49 for(int i=0;i<p1.parameters.length;++i) {
50 cur = compare(p1.parameters[i], p2.parameters[i]);
59 cur = compare(p1.domain, p2.domain);
62 cur = compare(p1.range, p2.range);
65 return compare(p1.effect, p2.effect);
68 TUnion p1 = (TUnion)t1;
69 TUnion p2 = (TUnion)t2;
70 cur = p1.effects.length - p2.effects.length;
76 return 0; // cannot compare
78 return 0; // cannot compare
80 throw new IllegalArgumentException();