Make type comparator available.

This commit is contained in:
Juraj Kirchheim
2018-09-22 10:12:02 +02:00
parent d6142847eb
commit 13d11f4f66
2 changed files with 16 additions and 15 deletions

View File

@@ -5,7 +5,6 @@ import haxe.ds.BalancedTree;
import haxe.macro.Context;
import haxe.macro.Type;
using haxe.macro.Tools;
using tink.MacroApi;
class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
@@ -16,18 +15,7 @@ class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
super();
}
override function compare(k1:Type, k2:Type):Int {
if (follow) {
k1 = k1.reduce();
k2 = k2.reduce();
}
return switch k1.getIndex() - k2.getIndex() {
case 0:
Reflect.compare(k1.toString(), k2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
case v: v;
}
}
override function compare(k1:Type, k2:Type):Int
return k1.compare(k2, follow);
}

View File

@@ -1,12 +1,12 @@
package tink.macro;
import haxe.macro.Printer;
import Type in Enums;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.Tools;
using tink.MacroApi;
using tink.CoreApi;
@@ -226,4 +226,17 @@ class Types {
throw 'assert';
}
static public function compare(t1:Type, t2:Type, ?follow:Bool = true) {
if (follow) {
t1 = t1.reduce();
t2 = t2.reduce();
}
return switch t1.getIndex() - t2.getIndex() {
case 0:
Reflect.compare(t1.toString(), t2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
case v: v;
}
}
}