From 190c28875b8b8a7f6d9d1c790c5b4f23dffbd72e Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Thu, 8 Jan 2015 23:28:52 +0200 Subject: [PATCH 1/8] new buddy macro autogenerate main --- test/Tests.hx | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/test/Tests.hx b/test/Tests.hx index eecc43e..27c1dce 100644 --- a/test/Tests.hx +++ b/test/Tests.hx @@ -3,28 +3,14 @@ package ; import buddy.BuddySuite; import buddy.SuitesRunner; -class Tests extends BuddySuite { - - public static function main() { - var reporter = new buddy.reporting.TravisHxReporter(); - - var runner = new SuitesRunner([ - new BaseTest(), - new InheritanceTest(), - new InlineTest(), - new MetaTest(), - new SignalTest(), - new TestProperty(), - new ChainBindTest(), - new ExprBindTest(), - ], reporter); - - runner.run(); - - #if sys - Sys.exit(runner.statusCode()); - #else - return runner.statusCode(); - #end - } -} \ No newline at end of file +@:build(buddy.GenerateMain.withSuites([ + new BaseTest(), + new InheritanceTest(), + new InlineTest(), + new MetaTest(), + new SignalTest(), + new TestProperty(), + new ChainBindTest(), + new ExprBindTest(), +])) +class Tests extends BuddySuite {} \ No newline at end of file From 8e62ede9d78ca41d8884d738f5ef4b89477d9300 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Fri, 9 Jan 2015 03:05:05 +0200 Subject: [PATCH 2/8] strict std.Reflect --- src/bindx/BindSignal.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindx/BindSignal.hx b/src/bindx/BindSignal.hx index 93c57ff..11ec51b 100644 --- a/src/bindx/BindSignal.hx +++ b/src/bindx/BindSignal.hx @@ -82,7 +82,7 @@ class SignalTools { if (meta != null) for (m in std.Reflect.fields(meta)) { var data = std.Reflect.field(meta, m); if (std.Reflect.hasField(data, BIND_SIGNAL_META)) { - var signal:bindx.BindSignal.Signal = cast Reflect.field(bindable, m); + var signal:bindx.BindSignal.Signal = cast std.Reflect.field(bindable, m); if (signal != null) { signal.removeAll(); var args:Array = std.Reflect.field(data, BIND_SIGNAL_META); From 2520a6585049174d9b5121e6063dd44387e7aaf1 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Fri, 9 Jan 2015 03:06:24 +0200 Subject: [PATCH 3/8] more using, rename --- src/bindx/Bind.hx | 10 +++--- src/bindx/BindExt.hx | 13 +++---- src/bindx/macro/BindExtMacros.hx | 34 +++++++++---------- src/bindx/macro/BindMacros.hx | 12 +++---- src/bindx/macro/BindSignalProvider.hx | 2 +- src/bindx/macro/BindableMacros.hx | 2 +- .../macro/{MetaUtils.hx => MacroUtils.hx} | 10 ++++-- 7 files changed, 45 insertions(+), 38 deletions(-) rename src/bindx/macro/{MetaUtils.hx => MacroUtils.hx} (93%) diff --git a/src/bindx/Bind.hx b/src/bindx/Bind.hx index c755e32..3de4fe0 100644 --- a/src/bindx/Bind.hx +++ b/src/bindx/Bind.hx @@ -7,22 +7,22 @@ import bindx.macro.BindMacros; class Bind { @: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 { - return BindMacros.internalBindTo(field, target); + return BindMacros.bindTo(field, target); } @: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 { - return BindMacros.internalNotify(field, oldValue, newValue); + return BindMacros.notify(field, oldValue, newValue); } @:noUsing macro static public function unbindAll(object:ExprOf):Expr { - return BindMacros.internalUnbindAll(object); + return BindMacros.unbindAll(object); } } \ No newline at end of file diff --git a/src/bindx/BindExt.hx b/src/bindx/BindExt.hx index f479168..246df25 100644 --- a/src/bindx/BindExt.hx +++ b/src/bindx/BindExt.hx @@ -5,25 +5,26 @@ import haxe.macro.Context; import bindx.macro.BindExtMacros; using haxe.macro.Tools; +using bindx.macro.MacroUtils; @:access(bindx.macro.BindxExtMacro) class BindExt { @:noUsing macro static public function expr(expr:ExprOf, listener:ExprOf->Null->Void>):ExprOfVoid> { - return BindxExtMacro.internalBindExpr(expr, listener); + return BindxExtMacro.bindExpr(expr, listener); } @:noUsing macro static public function exprTo(expr:ExprOf, target:ExprOf):ExprOfVoid> { - var type = Context.typeof(expr).toComplexType(); - return BindxExtMacro.internalBindExpr(expr, macro function (_, to:Null<$type>) $target = to); + var type = expr.getComplexType(); + return BindxExtMacro.bindExpr(expr, macro function (_, to:Null<$type>) $target = to); } @:noUsing macro static public function chain(expr:ExprOf, listener:Expr):ExprOfVoid> { - return BindxExtMacro.internalBindChain(expr, listener); + return BindxExtMacro.bindChain(expr, listener); } @:noUsing macro static public function chainTo(expr:ExprOf, target:ExprOf):ExprOfVoid> { - var type = Context.typeof(expr).toComplexType(); - return BindxExtMacro.internalBindChain(expr, macro function (_, to:Null<$type>) $target = to); + var type = expr.getComplexType(); + return BindxExtMacro.bindChain(expr, macro function (_, to:Null<$type>) $target = to); } } \ No newline at end of file diff --git a/src/bindx/macro/BindExtMacros.hx b/src/bindx/macro/BindExtMacros.hx index 545c047..2be00d3 100644 --- a/src/bindx/macro/BindExtMacros.hx +++ b/src/bindx/macro/BindExtMacros.hx @@ -11,6 +11,7 @@ import bindx.macro.BindMacros; using Lambda; using StringTools; +using bindx.macro.MacroUtils; using haxe.macro.Tools; private typedef FieldExpr = { @@ -31,7 +32,7 @@ private typedef Chain = { @:access(bindx.macro.BindMacros) 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 chain = null; try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError(); @@ -42,18 +43,8 @@ class BindxExtMacro { 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; - } - - static function internalBindExpr(expr:Expr, listener:Expr):Expr { - var type = Context.typeof(expr).toComplexType(); + static function bindExpr(expr:Expr, listener:Expr):Expr { + var type = expr.getComplexType(); var listenerNameExpr = macro listener; var fieldListenerName = "fieldListener"; var fieldListenerNameExpr = macro $i{fieldListenerName}; @@ -259,7 +250,7 @@ class BindxExtMacro { while (++i < fields.length - 1) { var field = fields[i + 1]; var prev = fields[i]; - var type = Context.typeof(field.e).toComplexType(); + var type = field.e.getComplexType(); var listenerName = listenerName(i+1, prefix); var listenerNameExpr = macro $i { listenerName }; @@ -299,8 +290,7 @@ class BindxExtMacro { if (field.params != null) { fieldListenerBody.unshift(macro $i { oldValue } = n); - fieldListenerBody.unshift(macro try { n = $e; } catch (e:Dynamic) { }); - fieldListenerBody.unshift(macro var n:Null < $type > = null); + fieldListenerBody.unshift(macro var n:Null<$type> = try { $e; } catch (_:Dynamic) { null; }); fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} ); res.init.push(macro var $oldValue:Null<$type> = null); @@ -322,7 +312,7 @@ class BindxExtMacro { 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); var zeroName = zeroListener.f.e.toString(); @@ -340,5 +330,15 @@ class BindxExtMacro { } 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 \ No newline at end of file diff --git a/src/bindx/macro/BindMacros.hx b/src/bindx/macro/BindMacros.hx index dca2e3a..d828eb9 100644 --- a/src/bindx/macro/BindMacros.hx +++ b/src/bindx/macro/BindMacros.hx @@ -8,30 +8,30 @@ import haxe.macro.Type; import haxe.macro.Context; using haxe.macro.Tools; -using bindx.macro.MetaUtils; +using bindx.macro.MacroUtils; using Lambda; @:access(bindx.macro.BindableMacros) 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); return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(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); 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); return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue); } - static inline function internalUnbindAll(object:ExprOf):Expr { - var type = Context.typeof(object).follow(); + static inline function unbindAll(object:ExprOf):Expr { + var type = Context.typeof(object); if (!isBindable(type.getClass())) { Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos); } diff --git a/src/bindx/macro/BindSignalProvider.hx b/src/bindx/macro/BindSignalProvider.hx index bd47262..736867b 100644 --- a/src/bindx/macro/BindSignalProvider.hx +++ b/src/bindx/macro/BindSignalProvider.hx @@ -6,7 +6,7 @@ import haxe.macro.Type; import haxe.macro.Context; import bindx.BindSignal; -using bindx.macro.MetaUtils; +using bindx.macro.MacroUtils; using haxe.macro.Tools; using Lambda; diff --git a/src/bindx/macro/BindableMacros.hx b/src/bindx/macro/BindableMacros.hx index 766ff68..58cf0e7 100644 --- a/src/bindx/macro/BindableMacros.hx +++ b/src/bindx/macro/BindableMacros.hx @@ -8,7 +8,7 @@ import haxe.macro.Context; using haxe.macro.Tools; using Lambda; using StringTools; -using bindx.macro.MetaUtils; +using bindx.macro.MacroUtils; class BindableMacros { diff --git a/src/bindx/macro/MetaUtils.hx b/src/bindx/macro/MacroUtils.hx similarity index 93% rename from src/bindx/macro/MetaUtils.hx rename to src/bindx/macro/MacroUtils.hx index eb02fd4..6c5a218 100644 --- a/src/bindx/macro/MetaUtils.hx +++ b/src/bindx/macro/MacroUtils.hx @@ -1,5 +1,6 @@ package bindx.macro; +#if macro import haxe.macro.Type; import haxe.macro.Expr; import haxe.macro.Context; @@ -62,7 +63,7 @@ class ClassTypeMetaUtils { return bindableMeta(classType) != null; } -class ExprMetaUtils { +class ExprUtils { static public inline function isTrue(expr:Expr):Bool return expr.expr.match(EConst(CIdent("true"))); @@ -78,4 +79,9 @@ class ExprMetaUtils { static public inline function isNullOrTrue(expr:Expr):Bool return expr == null || isTrue(expr); -} \ No newline at end of file + + static public inline function getComplexType(expr:Expr):ComplexType { + return Context.typeof(expr).toComplexType(); + } +} +#end \ No newline at end of file From 94bca97041f7b353744d36bf06764372ea3a2774 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Sun, 18 Jan 2015 02:34:44 +0200 Subject: [PATCH 4/8] typedefs correct resolve --- src/bindx/macro/BindExtMacros.hx | 13 +++++++------ src/bindx/macro/BindMacros.hx | 9 +++++---- src/bindx/macro/MacroUtils.hx | 6 +++++- test/BaseTest.hx | 11 +++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/bindx/macro/BindExtMacros.hx b/src/bindx/macro/BindExtMacros.hx index 2be00d3..1254ba5 100644 --- a/src/bindx/macro/BindExtMacros.hx +++ b/src/bindx/macro/BindExtMacros.hx @@ -87,7 +87,7 @@ class BindxExtMacro { if (!binded.exists(key)) { var ecall = switch (c.expr.expr) { case EField(e, field): - var type = Context.typeof(e); + var type = e.deepTypeof(); var classRef = type.getClass(); var field = classRef.findField(field); field.kind.match(FMethod(_)); @@ -237,6 +237,7 @@ class BindxExtMacro { inline static function listenerName(idx:Int, prefix) return '${prefix}listener$idx'; static function prepareChain(fields:Array, expr:Expr, prefix = ""):Chain { + var bsp = BindableMacros.bindingSignalProvider; var res:Chain = { init:[], bind:[], unbind:[], expr:null }; var prevListenerName = listenerName(0, prefix); @@ -274,7 +275,7 @@ class BindxExtMacro { } if (prev.bindable) { - var unbind = BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr ); + var unbind = bsp.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr ); res.bind.push(macro var $value:Null<$type> = null ); res.unbind.push(macro if ($valueExpr != null) { $unbind; $valueExpr = null; } ); @@ -282,7 +283,7 @@ class BindxExtMacro { fieldListenerBody.push(macro if ($valueExpr != null) $unbind ); fieldListenerBody.push(macro $valueExpr = n ); fieldListenerBody.push(macro if (n != null) - $ { BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) }); + $ { bsp.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) }); } var callPrevArgs = prev.params != null ? [] : [macro o != null ? o.$fieldName : null, macro n != null ? n.$fieldName : null]; var callPrev = macro $prevListenerNameExpr($a { callPrevArgs } ); @@ -300,7 +301,7 @@ class BindxExtMacro { } else { if (prev.bindable) { fieldListenerBody.unshift(macro if (o != null) - ${BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )} + ${bsp.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )} ); } fieldListener = macro function $listenerName (o:Null<$type>, n:Null<$type>):Void $b { fieldListenerBody }; @@ -319,8 +320,8 @@ class BindxExtMacro { if (zeroName != "this") res.init.unshift(macro var $zeroName = $i{zeroName}); - res.bind.push(BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); - res.unbind.push(BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); + res.bind.push(bsp.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); + res.unbind.push(bsp.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); if (zeroListener.f.params != null) { res.bind.push(macro ${zeroListener.l}()); diff --git a/src/bindx/macro/BindMacros.hx b/src/bindx/macro/BindMacros.hx index d828eb9..d0fbd80 100644 --- a/src/bindx/macro/BindMacros.hx +++ b/src/bindx/macro/BindMacros.hx @@ -16,8 +16,9 @@ class BindMacros { static inline function bind(field:Expr, listener:Expr, doBind:Bool):Expr { var fieldData = warnCheckField(field); - return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener); - else BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener); + var bsp = BindableMacros.bindingSignalProvider; + return if (doBind) bsp.getClassFieldBindExpr(fieldData.e, fieldData.field, listener); + else bsp.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener); } static inline function bindTo(field:Expr, target:Expr):Expr { @@ -31,7 +32,7 @@ class BindMacros { } static inline function unbindAll(object:ExprOf):Expr { - var type = Context.typeof(object); + var type = object.deepTypeof(); if (!isBindable(type.getClass())) { Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos); } @@ -55,7 +56,7 @@ class BindMacros { var error:GenericError = null; switch (f.expr) { case EField(e, field): - var type = Context.typeof(e); + var type = e.deepTypeof(); var classType = switch (type) { case TInst(c, _): c.get(); case _: null; }; if (classType == null) { error = new FatalError('Type \'${e.toString()}\' is unknown', e.pos); diff --git a/src/bindx/macro/MacroUtils.hx b/src/bindx/macro/MacroUtils.hx index 6c5a218..8db39ed 100644 --- a/src/bindx/macro/MacroUtils.hx +++ b/src/bindx/macro/MacroUtils.hx @@ -81,7 +81,11 @@ class ExprUtils { return expr == null || isTrue(expr); static public inline function getComplexType(expr:Expr):ComplexType { - return Context.typeof(expr).toComplexType(); + return deepTypeof(expr).toComplexType(); + } + + static public inline function deepTypeof(expr:Expr):haxe.macro.Type { + return Context.typeof(expr).follow(); } } #end \ No newline at end of file diff --git a/test/BaseTest.hx b/test/BaseTest.hx index 079845a..6b297bc 100644 --- a/test/BaseTest.hx +++ b/test/BaseTest.hx @@ -288,10 +288,21 @@ class BaseTest extends BuddySuite { true.should.be(true); }); + + it("bindx should resolve typedefs", { + var a:TypeBindable1 = new TypeBindable1(); + Bind.bind(a.str, function (_, _) { + callNum ++; + }); + + a.str = "123"; + callNum.should.be(1); + }); }); } } +typedef TypeBindable1 = Bindable1; class Bindable1 implements bindx.IBindable { From 95aa6865f2e1eb49be16cdcfa0128d13ce7743ff Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Sun, 18 Jan 2015 02:54:28 +0200 Subject: [PATCH 5/8] test generic --- test/BaseTest.hx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/BaseTest.hx b/test/BaseTest.hx index 6b297bc..8aa241c 100644 --- a/test/BaseTest.hx +++ b/test/BaseTest.hx @@ -298,10 +298,28 @@ class BaseTest extends BuddySuite { a.str = "123"; callNum.should.be(1); }); + + it("bindx should resolve parametric types", { + var b = new GenericBindable(); + b.a = new TypeBindable1(); + Bind.bind(b.a.str, function (_, _) { + callNum ++; + }); + + b.a.str = "123"; + callNum.should.be(1); + }); }); } } +//@:generic +class GenericBindable { + public var a:A; + + public function new() {} +} + typedef TypeBindable1 = Bindable1; class Bindable1 implements bindx.IBindable { From 181191797b3a8e5f32f1527a6b0249a4f93800da Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Wed, 21 Jan 2015 02:46:15 +0200 Subject: [PATCH 6/8] idea strict parser support --- test/BaseTest.hx | 38 +++++++++++++++++++------------------- test/ChainBindTest.hx | 16 ++++++++-------- test/ExprBindTest.hx | 8 ++++---- test/ForceTest.hx | 6 +++--- test/InheritanceTest.hx | 6 +++--- test/InlineTest.hx | 8 ++++---- test/MetaTest.hx | 10 +++++----- test/SignalTest.hx | 16 ++++++++-------- test/TestProperty.hx | 28 ++++++++++++++-------------- 9 files changed, 68 insertions(+), 68 deletions(-) diff --git a/test/BaseTest.hx b/test/BaseTest.hx index 8aa241c..982ec73 100644 --- a/test/BaseTest.hx +++ b/test/BaseTest.hx @@ -11,17 +11,17 @@ class BaseTest extends BuddySuite { public function new() { super(); - describe("Using base functionality", { + describe("Using base functionality", function () { var b:Bindable1; var callNum:Int; - - before({ + + before(function () { b = new Bindable1(); callNum = 0; }); - it("bindx should bind/unbind fields (lazySignal=true)", { + it("bindx should bind/unbind fields (lazySignal=true)", function () { var strFrom = b.str = "a"; var callNum2 = 0; @@ -51,7 +51,7 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind fields (lazySignal=false)", { + it("bindx should bind/unbind fields (lazySignal=false)", function () { var strFrom = b.str2 = "a"; var callNum2 = 0; @@ -81,7 +81,7 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind 'null' values (lazySignal=true)", { + it("bindx should bind/unbind 'null' values (lazySignal=true)", function () { var strFrom = b.str = null; var callNum2 = 0; var listener = function (from:String, to:String) { @@ -109,7 +109,7 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind 'null' values (lazySignal=false)", { + it("bindx should bind/unbind 'null' values (lazySignal=false)", function () { var strFrom = b.str2 = null; var callNum2 = 0; var listener = function (from:String, to:String) { @@ -137,7 +137,7 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind 2 objects (lazySignal=true)", { + it("bindx should bind 2 objects (lazySignal=true)", function() { var callNum2 = 0; var target = {a:""}; var s = ""; @@ -157,7 +157,7 @@ class BaseTest extends BuddySuite { s.should.be(prev); }); - it("bindx should bind 2 objects (lazySignal=false)", { + it("bindx should bind 2 objects (lazySignal=false)", function () { var callNum2 = 0; var target = {a:""}; var s = ""; @@ -176,7 +176,7 @@ class BaseTest extends BuddySuite { s.should.be(prev); }); - it("bindx should bind and notify methods (lazySignal=true)", { + it("bindx should bind and notify methods (lazySignal=true)", function () { var listener = function () callNum++; bind(b.bind, listener); Bind.notify(b.bind); @@ -189,7 +189,7 @@ class BaseTest extends BuddySuite { callNum.should.be(1); }); - it("bindx should bind and notify methods (lazySignal=false)", { + it("bindx should bind and notify methods (lazySignal=false)", function () { var listener = function () callNum++; bind(b.bind2, listener); Bind.notify(b.bind2); @@ -202,7 +202,7 @@ class BaseTest extends BuddySuite { callNum.should.be(1); }); - it("bindx should notify properties manual (lazySignal=true)", { + it("bindx should notify properties manual (lazySignal=true)", function () { b.str = "3"; var f = "1"; var t = "2"; @@ -217,7 +217,7 @@ class BaseTest extends BuddySuite { callNum.should.be(1); }); - it("bindx should notify properties manual (lazySignal=false)", { + it("bindx should notify properties manual (lazySignal=false)", function () { b.str2 = "3"; var f = "1"; var t = "2"; @@ -232,7 +232,7 @@ class BaseTest extends BuddySuite { callNum.should.be(1); }); - it("bindx should unbind all properties listeners (lazySignal=true)", { + it("bindx should unbind all properties listeners (lazySignal=true)", function () { bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++); @@ -242,7 +242,7 @@ class BaseTest extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all properties listeners (lazySignal=false)", { + it("bindx should unbind all properties listeners (lazySignal=false)", function () { bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++); @@ -252,7 +252,7 @@ class BaseTest extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", { + it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () { bind(b.str, function (_, _) callNum++); // create binding signal bind(b.str2, function (_, _) callNum++); bind(b.bind, function () callNum++); @@ -273,7 +273,7 @@ class BaseTest extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", { + it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () { Bind.unbindAll(b); try { @@ -289,7 +289,7 @@ class BaseTest extends BuddySuite { true.should.be(true); }); - it("bindx should resolve typedefs", { + it("bindx should resolve typedefs", function () { var a:TypeBindable1 = new TypeBindable1(); Bind.bind(a.str, function (_, _) { callNum ++; @@ -299,7 +299,7 @@ class BaseTest extends BuddySuite { callNum.should.be(1); }); - it("bindx should resolve parametric types", { + it("bindx should resolve parametric types", function () { var b = new GenericBindable(); b.a = new TypeBindable1(); Bind.bind(b.a.str, function (_, _) { diff --git a/test/ChainBindTest.hx b/test/ChainBindTest.hx index 8392279..9021a53 100644 --- a/test/ChainBindTest.hx +++ b/test/ChainBindTest.hx @@ -11,7 +11,7 @@ class ChainBindTest extends BuddySuite { public function new() { - describe("Using BindExt.chain", { + describe("Using BindExt.chain", function () { var from:String; var val:String; @@ -19,7 +19,7 @@ class ChainBindTest extends BuddySuite { var callNum:Int; var target:{a:String}; - before({ + before(function () { from = null; val = "a"; b = new BindableChain(4); @@ -27,7 +27,7 @@ class ChainBindTest extends BuddySuite { callNum = 0; }); - it("BindExt.chain should bind chain changes (unset links)", { + it("BindExt.chain should bind chain changes (unset links)", function () { b.c.c.d = val; var listener = function (f:String, t:String) { @@ -61,7 +61,7 @@ class ChainBindTest extends BuddySuite { callNum.should.be(5); }); - it("BindExt.chain should bind chain changes (null links)", { + it("BindExt.chain should bind chain changes (null links)", function () { b.c = null; val = null; @@ -84,7 +84,7 @@ class ChainBindTest extends BuddySuite { callNum.should.be(3); }); - it("BindExt.chain should bind chain changes (0 gap)", { + it("BindExt.chain should bind chain changes (0 gap)", function () { var b2 = new BindableChain(4); b.c.c.f("tada").d = val; b2.c.c.f("tada").d = val; @@ -121,7 +121,7 @@ class ChainBindTest extends BuddySuite { callNum.should.be(4); }); - it("BindExt.chain should bind chain changes (1 gap)", { + it("BindExt.chain should bind chain changes (1 gap)", function () { b.c.nc.c.f("tada").d = "a"; var unbind = BindExt.chain(b.c.nc.c.f("tada").d, function (f:String, t:String) { f.should.be(from); @@ -166,7 +166,7 @@ class ChainBindTest extends BuddySuite { callNum.should.be(3); }); - it("BindExt.chain should bind chain changes (double gap)", { + it("BindExt.chain should bind chain changes (double gap)", function () { b.c.nc.nc.d = "a"; BindExt.chain(b.c.nc.nc.d, function (f, t:String) { @@ -205,7 +205,7 @@ class ChainBindTest extends BuddySuite { callNum.should.be(2); }); - it("BindExt.chain should bind default fields", { + it("BindExt.chain should bind default fields", function () { b.d = val = "a"; var unbind = BindExt.chain(b.d, function (f:String, t:String) { diff --git a/test/ExprBindTest.hx b/test/ExprBindTest.hx index f96f3c6..2742764 100644 --- a/test/ExprBindTest.hx +++ b/test/ExprBindTest.hx @@ -11,18 +11,18 @@ class ExprBindTest extends BuddySuite { public function new() { - describe("Using BindExt.expr", { + describe("Using BindExt.expr", function () { var callNum:Int; var from:String; var target:{a:String}; - before({ + before(function () { target = {a:null}; from = null; callNum = 0; }); - it("BindExt.chain should bind simple expr", { + it("BindExt.chain should bind simple expr", function () { var a = new BaseTest.Bindable1(); var b = new BaseTest.Bindable1(); a.str = "a1"; @@ -51,7 +51,7 @@ class ExprBindTest extends BuddySuite { callNum.should.be(3); }); - it("BindExt.chain should bind complex expresions", { + it("BindExt.chain should bind complex expresions", function () { var a = new BaseTest.Bindable1(); var b = new BaseTest.Bindable1(); var c = new BaseTest.Bindable1(); diff --git a/test/ForceTest.hx b/test/ForceTest.hx index 6ac45ae..7db1af2 100644 --- a/test/ForceTest.hx +++ b/test/ForceTest.hx @@ -10,17 +10,17 @@ class ForceTest extends BuddySuite { public function new() { - describe("Using @:bindable(force=true)", { + describe("Using @:bindable(force=true)", function () { var b:BindableForce; var callNum:Int; - before({ + before(function () { b = new BindableForce(); callNum = 0; }); - it("bindx should correct work with 'force' fields", { + it("bindx should correct work with 'force' fields", function () { Bind.bind(b.str, function (_, _) callNum++); Bind.bind(b.str2, function (_, _) callNum++); Bind.bind(b.str3, function (_, _) callNum++); diff --git a/test/InheritanceTest.hx b/test/InheritanceTest.hx index 998711b..2cddcb1 100644 --- a/test/InheritanceTest.hx +++ b/test/InheritanceTest.hx @@ -10,18 +10,18 @@ class InheritanceTest extends BuddySuite { public function new() { super(); - describe("Using classes inheritance", { + describe("Using classes inheritance", function () { var b:BindableChild; var bp:BindableParent; var callNum:Int; - before({ + before(function () { b = new BindableChild(); bp = new BindableParent(); callNum = 0; }); - it("bindx should support class/interface inheritance", { + it("bindx should support class/interface inheritance", function () { b.i = 1; b.s = "a"; Bind.bind(b.i, function (_, _) callNum++); diff --git a/test/InlineTest.hx b/test/InlineTest.hx index 0d79794..2cb1a7c 100644 --- a/test/InlineTest.hx +++ b/test/InlineTest.hx @@ -12,13 +12,13 @@ class InlineTest extends BuddySuite { public function new() { - describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", { + describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", function () { var b:BindableInline; var cd:Classdef; var foundFields:Int; - before({ + before(function () { foundFields = 0; b = new BindableInline(); var rttiData:String = untyped BindableInline.__rtti; @@ -26,7 +26,7 @@ class InlineTest extends BuddySuite { cd = switch (rtti) { case TClassdecl(c): c; case _: null; }; }); - it("bindx should generate inline setter", { + it("bindx should generate inline setter", function () { for (c in cd.fields) { switch (c.name) { case "set_str": @@ -41,7 +41,7 @@ class InlineTest extends BuddySuite { foundFields.should.be(2); }); - it("bindx should generate inline signal getter", { + it("bindx should generate inline signal getter", function () { for (c in cd.fields) { switch (c.name) { case "get_str3Changed": diff --git a/test/MetaTest.hx b/test/MetaTest.hx index 5695a14..4b539a8 100644 --- a/test/MetaTest.hx +++ b/test/MetaTest.hx @@ -10,17 +10,17 @@ class MetaTest extends BuddySuite { public function new() { - describe("Using @bindable meta inheritance", { + describe("Using @bindable meta inheritance", function () { var b:BindableMeta; var callNum:Int; - before({ + before(function () { b = new BindableMeta(); callNum = 0; }); - it("bindx inherit metadata bindable for public fields", { + it("bindx inherit metadata bindable for public fields", function () { b.str = "a"; Bind.bind(b.str, function(_, _) callNum++); @@ -28,7 +28,7 @@ class MetaTest extends BuddySuite { callNum.should.be(1); }); - it("bindx inherit metadata bindable for public fields", { + it("bindx inherit metadata bindable for public fields", function () { b.str2 = "a"; Bind.bind(b.str2, function(_, _) callNum++); @@ -36,7 +36,7 @@ class MetaTest extends BuddySuite { callNum.should.be(1); }); - it("bindx inherit metadata params", { + it("bindx inherit metadata params", function () { @:privateAccess b.strChanged.should.not.be(null); @:privateAccess b.str2Changed.should.not.be(null); }); diff --git a/test/SignalTest.hx b/test/SignalTest.hx index db7056c..8326ff0 100644 --- a/test/SignalTest.hx +++ b/test/SignalTest.hx @@ -10,17 +10,17 @@ class SignalTest extends BuddySuite { public function new() { super(); - describe("Using BindSignal", { + describe("Using BindSignal", function () { var fs:FieldSignal; var callNum:Int; - before({ + before(function () { fs = new FieldSignal(); callNum = 0; }); - it("signal listeners should listen signal", { + it("signal listeners should listen signal", function () { var f = "1"; var t = "2"; function listener(from:String, to:String) { @@ -49,7 +49,7 @@ class SignalTest extends BuddySuite { callNum.should.be(3); }); - it("signal should correct add/remove listeners", { + it("signal should correct add/remove listeners", function () { function listener2(_, _) { callNum ++; } @@ -79,7 +79,7 @@ class SignalTest extends BuddySuite { callNum.should.be(4); // all listeners removed }); - it("signal should correct dispatch in listener", { + it("signal should correct dispatch in listener", function () { function listener(_, _) { fs.remove(listener); fs.dispatch(null, null); @@ -97,17 +97,17 @@ class SignalTest extends BuddySuite { }); }); - describe("Using MethodSignal", { + describe("Using MethodSignal", function () { var ms:MethodSignal; var callNum:Int; - before({ + before(function () { ms = new MethodSignal(); callNum = 0; }); - it("signal listeners should listen signal", { + it("signal listeners should listen signal", function () { function listener() { callNum ++; ms.remove(listener); diff --git a/test/TestProperty.hx b/test/TestProperty.hx index 13a3a6f..70897e3 100644 --- a/test/TestProperty.hx +++ b/test/TestProperty.hx @@ -10,17 +10,17 @@ class TestProperty extends BuddySuite { public function new() { super(); - describe("Using bind properties", { + describe("Using bind properties", function () { var b:BindableProperty; var callNum:Int; - before({ + before(function () { b = new BindableProperty(); callNum = 0; }); - it("bindx should bind/unbind fields (lazySignal=true)", { + it("bindx should bind/unbind fields (lazySignal=true)", function () { var strFrom = b.str = "a"; var callNum2 = 0; @@ -50,7 +50,7 @@ class TestProperty extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind fields (lazySignal=false)", { + it("bindx should bind/unbind fields (lazySignal=false)", function () { var strFrom = b.str2 = "a"; var callNum2 = 0; @@ -80,7 +80,7 @@ class TestProperty extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind 'null' values (lazySignal=true)", { + it("bindx should bind/unbind 'null' values (lazySignal=true)", function () { var strFrom = b.str = null; var callNum2 = 0; var listener = function (from:String, to:String) { @@ -108,7 +108,7 @@ class TestProperty extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind/unbind 'null' values (lazySignal=false)", { + it("bindx should bind/unbind 'null' values (lazySignal=false)", function () { var strFrom = b.str2 = null; var callNum2 = 0; var listener = function (from:String, to:String) { @@ -136,7 +136,7 @@ class TestProperty extends BuddySuite { callNum2.should.be(1); }); - it("bindx should bind 2 objects (lazySignal=true)", { + it("bindx should bind 2 objects (lazySignal=true)", function () { var callNum2 = 0; var target = {a:""}; var s = ""; @@ -156,7 +156,7 @@ class TestProperty extends BuddySuite { s.should.be(prev); }); - it("bindx should bind 2 objects (lazySignal=false)", { + it("bindx should bind 2 objects (lazySignal=false)", function () { var callNum2 = 0; var target = {a:""}; var s = ""; @@ -175,7 +175,7 @@ class TestProperty extends BuddySuite { s.should.be(prev); }); - it("bindx should notify properties manual (lazySignal=true)", { + it("bindx should notify properties manual (lazySignal=true)", function () { b.str = "3"; var f = "1"; var t = "2"; @@ -190,7 +190,7 @@ class TestProperty extends BuddySuite { callNum.should.be(1); }); - it("bindx should notify properties manual (lazySignal=false)", { + it("bindx should notify properties manual (lazySignal=false)", function () { b.str2 = "3"; var f = "1"; var t = "2"; @@ -205,7 +205,7 @@ class TestProperty extends BuddySuite { callNum.should.be(1); }); - it("bindx should unbind all properties listeners (lazySignal=true)", { + it("bindx should unbind all properties listeners (lazySignal=true)", function () { bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++); @@ -215,7 +215,7 @@ class TestProperty extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all properties listeners (lazySignal=false)", { + it("bindx should unbind all properties listeners (lazySignal=false)", function () { bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++); @@ -225,7 +225,7 @@ class TestProperty extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", { + it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () { bind(b.str, function (_, _) callNum++); // create binding signal bind(b.str2, function (_, _) callNum++); @@ -242,7 +242,7 @@ class TestProperty extends BuddySuite { callNum.should.be(0); }); - it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", { + it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () { Bind.unbindAll(b); try { From f21df0e898bbd9fe3860ba26f3b501e4cc82309f Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Wed, 21 Jan 2015 02:54:23 +0200 Subject: [PATCH 7/8] more parser fixes --- src/bindx/BindExt.hx | 1 - src/bindx/macro/BindSignalProvider.hx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindx/BindExt.hx b/src/bindx/BindExt.hx index 246df25..9904494 100644 --- a/src/bindx/BindExt.hx +++ b/src/bindx/BindExt.hx @@ -1,7 +1,6 @@ package bindx; import haxe.macro.Expr; -import haxe.macro.Context; import bindx.macro.BindExtMacros; using haxe.macro.Tools; diff --git a/src/bindx/macro/BindSignalProvider.hx b/src/bindx/macro/BindSignalProvider.hx index 736867b..7f65e2e 100644 --- a/src/bindx/macro/BindSignalProvider.hx +++ b/src/bindx/macro/BindSignalProvider.hx @@ -113,7 +113,7 @@ class BindSignalProvider implements IBindingSignalProvider { name: signalName, kind: FProp("get", "never", type, null), pos: field.pos, - access: [APrivate], + access: [APrivate] }); var getter = macro function foo() { From 1cf26de8b84a6b1b959c3412d6a2c8e0287b4a00 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Sun, 25 Jan 2015 03:34:46 +0200 Subject: [PATCH 8/8] minor speedup --- src/bindx/macro/BindMacros.hx | 1 - src/bindx/macro/BindSignalProvider.hx | 1 - src/bindx/macro/BindableMacros.hx | 6 +++--- src/bindx/macro/MacroUtils.hx | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bindx/macro/BindMacros.hx b/src/bindx/macro/BindMacros.hx index d0fbd80..c5cbe9a 100644 --- a/src/bindx/macro/BindMacros.hx +++ b/src/bindx/macro/BindMacros.hx @@ -9,7 +9,6 @@ import haxe.macro.Context; using haxe.macro.Tools; using bindx.macro.MacroUtils; -using Lambda; @:access(bindx.macro.BindableMacros) class BindMacros { diff --git a/src/bindx/macro/BindSignalProvider.hx b/src/bindx/macro/BindSignalProvider.hx index 7f65e2e..8a68d61 100644 --- a/src/bindx/macro/BindSignalProvider.hx +++ b/src/bindx/macro/BindSignalProvider.hx @@ -8,7 +8,6 @@ import bindx.BindSignal; using bindx.macro.MacroUtils; using haxe.macro.Tools; -using Lambda; class BindSignalProvider implements IBindingSignalProvider { diff --git a/src/bindx/macro/BindableMacros.hx b/src/bindx/macro/BindableMacros.hx index 58cf0e7..9efea18 100644 --- a/src/bindx/macro/BindableMacros.hx +++ b/src/bindx/macro/BindableMacros.hx @@ -191,15 +191,15 @@ class BindableMacros { static inline function injectBindableMeta(fields:Array, meta:MetadataEntry):Void { for (f in fields) { - if (f.hasBindableMeta()) continue; - if (f.access.exists(function (it) return it.equals(APrivate))) continue; + if (f.access.indexOf(APrivate) > -1 || f.hasBindableMeta()) continue; var forceParam = meta.findParam(FORCE); - if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue())) + if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue())) { switch (f.kind) { case FFun(_): case _: f.meta.push({name:MetaUtils.BINDABLE_META, pos:f.pos, params:meta.params}); } + } } } diff --git a/src/bindx/macro/MacroUtils.hx b/src/bindx/macro/MacroUtils.hx index 8db39ed..f650e30 100644 --- a/src/bindx/macro/MacroUtils.hx +++ b/src/bindx/macro/MacroUtils.hx @@ -6,7 +6,6 @@ import haxe.macro.Expr; import haxe.macro.Context; using haxe.macro.Tools; -using Lambda; class MetaUtils {