more using, rename
This commit is contained in:
+5
-5
@@ -7,22 +7,22 @@ import bindx.macro.BindMacros;
|
|||||||
class Bind {
|
class Bind {
|
||||||
|
|
||||||
@:noUsing macro static public function bind(field:Expr, listener:Expr):Expr {
|
@:noUsing macro static public function bind(field:Expr, listener:Expr):Expr {
|
||||||
return BindMacros.internalBind(field, listener, true);
|
return BindMacros.bind(field, listener, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function bindTo(field:Expr, target:Expr):Expr {
|
@:noUsing macro static public function bindTo(field:Expr, target:Expr):Expr {
|
||||||
return BindMacros.internalBindTo(field, target);
|
return BindMacros.bindTo(field, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function unbind(field:Expr, ?listener:Expr):Expr {
|
@:noUsing macro static public function unbind(field:Expr, ?listener:Expr):Expr {
|
||||||
return BindMacros.internalBind(field, listener, false);
|
return BindMacros.bind(field, listener, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
@:noUsing macro static public function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
||||||
return BindMacros.internalNotify(field, oldValue, newValue);
|
return BindMacros.notify(field, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function unbindAll(object:ExprOf<IBindable>):Expr {
|
@:noUsing macro static public function unbindAll(object:ExprOf<IBindable>):Expr {
|
||||||
return BindMacros.internalUnbindAll(object);
|
return BindMacros.unbindAll(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,25 +5,26 @@ import haxe.macro.Context;
|
|||||||
import bindx.macro.BindExtMacros;
|
import bindx.macro.BindExtMacros;
|
||||||
|
|
||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
|
using bindx.macro.MacroUtils;
|
||||||
|
|
||||||
@:access(bindx.macro.BindxExtMacro)
|
@:access(bindx.macro.BindxExtMacro)
|
||||||
class BindExt {
|
class BindExt {
|
||||||
|
|
||||||
@:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> {
|
@:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> {
|
||||||
return BindxExtMacro.internalBindExpr(expr, listener);
|
return BindxExtMacro.bindExpr(expr, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function exprTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
|
@:noUsing macro static public function exprTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
|
||||||
var type = Context.typeof(expr).toComplexType();
|
var type = expr.getComplexType();
|
||||||
return BindxExtMacro.internalBindExpr(expr, macro function (_, to:Null<$type>) $target = to);
|
return BindxExtMacro.bindExpr(expr, macro function (_, to:Null<$type>) $target = to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function chain<T>(expr:ExprOf<T>, listener:Expr):ExprOf<Void->Void> {
|
@:noUsing macro static public function chain<T>(expr:ExprOf<T>, listener:Expr):ExprOf<Void->Void> {
|
||||||
return BindxExtMacro.internalBindChain(expr, listener);
|
return BindxExtMacro.bindChain(expr, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function chainTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
|
@:noUsing macro static public function chainTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
|
||||||
var type = Context.typeof(expr).toComplexType();
|
var type = expr.getComplexType();
|
||||||
return BindxExtMacro.internalBindChain(expr, macro function (_, to:Null<$type>) $target = to);
|
return BindxExtMacro.bindChain(expr, macro function (_, to:Null<$type>) $target = to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import bindx.macro.BindMacros;
|
|||||||
|
|
||||||
using Lambda;
|
using Lambda;
|
||||||
using StringTools;
|
using StringTools;
|
||||||
|
using bindx.macro.MacroUtils;
|
||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
|
|
||||||
private typedef FieldExpr = {
|
private typedef FieldExpr = {
|
||||||
@@ -31,7 +32,7 @@ private typedef Chain = {
|
|||||||
@:access(bindx.macro.BindMacros)
|
@:access(bindx.macro.BindMacros)
|
||||||
class BindxExtMacro {
|
class BindxExtMacro {
|
||||||
|
|
||||||
static inline function internalBindChain(expr:Expr, listener:Expr):Expr {
|
static inline function bindChain(expr:Expr, listener:Expr):Expr {
|
||||||
var zeroListener = listenerName(0, "");
|
var zeroListener = listenerName(0, "");
|
||||||
var chain = null;
|
var chain = null;
|
||||||
try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError();
|
try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError();
|
||||||
@@ -42,18 +43,8 @@ class BindxExtMacro {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline function unwrapFormatedString(expr:Expr):Expr {
|
static function bindExpr(expr:Expr, listener:Expr):Expr {
|
||||||
return if (MacroStringTools.isFormatExpr(expr)) {
|
var type = expr.getComplexType();
|
||||||
var f = switch (expr.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
|
|
||||||
} else expr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function internalBindExpr(expr:Expr, listener:Expr):Expr {
|
|
||||||
var type = Context.typeof(expr).toComplexType();
|
|
||||||
var listenerNameExpr = macro listener;
|
var listenerNameExpr = macro listener;
|
||||||
var fieldListenerName = "fieldListener";
|
var fieldListenerName = "fieldListener";
|
||||||
var fieldListenerNameExpr = macro $i{fieldListenerName};
|
var fieldListenerNameExpr = macro $i{fieldListenerName};
|
||||||
@@ -259,7 +250,7 @@ class BindxExtMacro {
|
|||||||
while (++i < fields.length - 1) {
|
while (++i < fields.length - 1) {
|
||||||
var field = fields[i + 1];
|
var field = fields[i + 1];
|
||||||
var prev = fields[i];
|
var prev = fields[i];
|
||||||
var type = Context.typeof(field.e).toComplexType();
|
var type = field.e.getComplexType();
|
||||||
var listenerName = listenerName(i+1, prefix);
|
var listenerName = listenerName(i+1, prefix);
|
||||||
var listenerNameExpr = macro $i { listenerName };
|
var listenerNameExpr = macro $i { listenerName };
|
||||||
|
|
||||||
@@ -299,8 +290,7 @@ class BindxExtMacro {
|
|||||||
|
|
||||||
if (field.params != null) {
|
if (field.params != null) {
|
||||||
fieldListenerBody.unshift(macro $i { oldValue } = n);
|
fieldListenerBody.unshift(macro $i { oldValue } = n);
|
||||||
fieldListenerBody.unshift(macro try { n = $e; } catch (e:Dynamic) { });
|
fieldListenerBody.unshift(macro var n:Null<$type> = try { $e; } catch (_:Dynamic) { null; });
|
||||||
fieldListenerBody.unshift(macro var n:Null < $type > = null);
|
|
||||||
fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} );
|
fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} );
|
||||||
|
|
||||||
res.init.push(macro var $oldValue:Null<$type> = null);
|
res.init.push(macro var $oldValue:Null<$type> = null);
|
||||||
@@ -322,7 +312,7 @@ class BindxExtMacro {
|
|||||||
prevListenerNameExpr = listenerNameExpr;
|
prevListenerNameExpr = listenerNameExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zeroListener == null || zeroListener.f.bindable == false)
|
if (zeroListener == null || !zeroListener.f.bindable)
|
||||||
throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
|
throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
|
||||||
|
|
||||||
var zeroName = zeroListener.f.e.toString();
|
var zeroName = zeroListener.f.e.toString();
|
||||||
@@ -340,5 +330,15 @@ class BindxExtMacro {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline function unwrapFormatedString(expr:Expr):Expr {
|
||||||
|
return if (MacroStringTools.isFormatExpr(expr)) {
|
||||||
|
var f = switch (expr.expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: null;
|
||||||
|
}
|
||||||
|
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
|
||||||
|
} else expr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
@@ -8,30 +8,30 @@ import haxe.macro.Type;
|
|||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
|
|
||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
using bindx.macro.MetaUtils;
|
using bindx.macro.MacroUtils;
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
@:access(bindx.macro.BindableMacros)
|
@:access(bindx.macro.BindableMacros)
|
||||||
class BindMacros {
|
class BindMacros {
|
||||||
|
|
||||||
static inline function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
static inline function bind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
||||||
var fieldData = warnCheckField(field);
|
var fieldData = warnCheckField(field);
|
||||||
return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
|
return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
|
||||||
else BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
|
else BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline function internalBindTo(field:Expr, target:Expr):Expr {
|
static inline function bindTo(field:Expr, target:Expr):Expr {
|
||||||
var fieldData = warnCheckField(field);
|
var fieldData = warnCheckField(field);
|
||||||
return BindableMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
|
return BindableMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
static inline function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
||||||
var fieldData = warnCheckField(field);
|
var fieldData = warnCheckField(field);
|
||||||
return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
|
return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline function internalUnbindAll(object:ExprOf<IBindable>):Expr {
|
static inline function unbindAll(object:ExprOf<IBindable>):Expr {
|
||||||
var type = Context.typeof(object).follow();
|
var type = Context.typeof(object);
|
||||||
if (!isBindable(type.getClass())) {
|
if (!isBindable(type.getClass())) {
|
||||||
Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos);
|
Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import haxe.macro.Type;
|
|||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
import bindx.BindSignal;
|
import bindx.BindSignal;
|
||||||
|
|
||||||
using bindx.macro.MetaUtils;
|
using bindx.macro.MacroUtils;
|
||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import haxe.macro.Context;
|
|||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
using Lambda;
|
using Lambda;
|
||||||
using StringTools;
|
using StringTools;
|
||||||
using bindx.macro.MetaUtils;
|
using bindx.macro.MacroUtils;
|
||||||
|
|
||||||
class BindableMacros {
|
class BindableMacros {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package bindx.macro;
|
package bindx.macro;
|
||||||
|
|
||||||
|
#if macro
|
||||||
import haxe.macro.Type;
|
import haxe.macro.Type;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
@@ -62,7 +63,7 @@ class ClassTypeMetaUtils {
|
|||||||
return bindableMeta(classType) != null;
|
return bindableMeta(classType) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExprMetaUtils {
|
class ExprUtils {
|
||||||
static public inline function isTrue(expr:Expr):Bool
|
static public inline function isTrue(expr:Expr):Bool
|
||||||
return expr.expr.match(EConst(CIdent("true")));
|
return expr.expr.match(EConst(CIdent("true")));
|
||||||
|
|
||||||
@@ -78,4 +79,9 @@ class ExprMetaUtils {
|
|||||||
|
|
||||||
static public inline function isNullOrTrue(expr:Expr):Bool
|
static public inline function isNullOrTrue(expr:Expr):Bool
|
||||||
return expr == null || isTrue(expr);
|
return expr == null || isTrue(expr);
|
||||||
}
|
|
||||||
|
static public inline function getComplexType(expr:Expr):ComplexType {
|
||||||
|
return Context.typeof(expr).toComplexType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#end
|
||||||
Reference in New Issue
Block a user