Added Exprs.has. Minor cleanup.
This commit is contained in:
@@ -22,8 +22,26 @@ typedef ParamSubst = {
|
|||||||
var get(default, null):String->ComplexType;
|
var get(default, null):String->ComplexType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Heureka { public function new() {} }
|
||||||
|
|
||||||
class Exprs {
|
class Exprs {
|
||||||
|
|
||||||
|
static public function has(e:Expr, condition:Expr->Bool, ?options: { ?enterFunctions: Bool }) {
|
||||||
|
var enterFunctions = options != null && options.enterFunctions;
|
||||||
|
function seek(e:Expr)
|
||||||
|
switch e {
|
||||||
|
case { expr: EFunction(_) } if (options != null || options.enterFunctions != true):
|
||||||
|
case _ if (condition(e)): throw new Heureka();
|
||||||
|
default: haxe.macro.ExprTools.iter(e, seek);
|
||||||
|
}
|
||||||
|
|
||||||
|
return try {
|
||||||
|
haxe.macro.ExprTools.iter(e, seek);
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
catch (e:Heureka) true;
|
||||||
|
}
|
||||||
|
|
||||||
static public inline function is(e:Expr, c:ComplexType)
|
static public inline function is(e:Expr, c:ComplexType)
|
||||||
return ECheckType(e, c).at(e.pos).typeof().isSuccess();
|
return ECheckType(e, c).at(e.pos).typeof().isSuccess();
|
||||||
|
|
||||||
@@ -37,7 +55,7 @@ class Exprs {
|
|||||||
if (Reflect.hasField(rules, s))
|
if (Reflect.hasField(rules, s))
|
||||||
Reflect.field(rules, s)
|
Reflect.field(rules, s)
|
||||||
else if (s.startsWith('tmp')) {
|
else if (s.startsWith('tmp')) {
|
||||||
Reflect.setField(rules, s, MacroApi.tempName('__tink' + s.substr(3)));
|
Reflect.setField(rules, s, MacroApi.tempName(s.substr(3)));
|
||||||
replace(s);
|
replace(s);
|
||||||
}
|
}
|
||||||
else s;
|
else s;
|
||||||
@@ -201,13 +219,11 @@ class Exprs {
|
|||||||
switch (Inspect.typeof(target)) {
|
switch (Inspect.typeof(target)) {
|
||||||
case TNull, TInt, TFloat, TBool, TFunction, TUnknown, TClass(_): target;
|
case TNull, TInt, TFloat, TBool, TFunction, TUnknown, TClass(_): target;
|
||||||
case TEnum(e):
|
case TEnum(e):
|
||||||
// if (Inspect.getEnum(target) == ComplexType) return retyper(target);
|
|
||||||
// else {
|
|
||||||
var ret:Dynamic = Inspect.createEnumIndex(e, Inspect.enumIndex(target), crawlArray(Inspect.enumParameters(target), transformer, retyper, pos));
|
var ret:Dynamic = Inspect.createEnumIndex(e, Inspect.enumIndex(target), crawlArray(Inspect.enumParameters(target), transformer, retyper, pos));
|
||||||
return
|
if (Inspect.getEnum(ret) == ComplexType)
|
||||||
if (Inspect.getEnum(ret) == ComplexType) retyper(ret);
|
retyper(ret);
|
||||||
else ret;
|
else
|
||||||
// }
|
ret;
|
||||||
case TObject:
|
case TObject:
|
||||||
var ret:Dynamic = { };
|
var ret:Dynamic = { };
|
||||||
for (field in Reflect.fields(target))
|
for (field in Reflect.fields(target))
|
||||||
@@ -416,7 +432,7 @@ class Exprs {
|
|||||||
static public inline function toArray(exprs:Iterable<Expr>, ?pos)
|
static public inline function toArray(exprs:Iterable<Expr>, ?pos)
|
||||||
return EArrayDecl(exprs.array()).at(pos);
|
return EArrayDecl(exprs.array()).at(pos);
|
||||||
|
|
||||||
static public inline function toMBlock(exprs, ?pos)
|
static public inline function toMBlock(exprs:Array<Expr>, ?pos)
|
||||||
return EBlock(exprs).at(pos);
|
return EBlock(exprs).at(pos);
|
||||||
|
|
||||||
static public inline function toBlock(exprs:Iterable<Expr>, ?pos)
|
static public inline function toBlock(exprs:Iterable<Expr>, ?pos)
|
||||||
|
Reference in New Issue
Block a user