Make setter bypass in constructor optional.

This commit is contained in:
back2dos
2013-10-13 19:42:07 +02:00
parent 516479cc72
commit ef7fe70446
2 changed files with 12 additions and 8 deletions

View File

@@ -66,7 +66,9 @@ class Constructor {
public function addArg(name:String, ?t:ComplexType, ?e:Expr, ?opt = false)
args.push( { name : name, opt : opt || e != null, type : t, value: e } );
public function init(name:String, pos:Position, with:FieldInit, ?prepend:Bool) {
public function init(name:String, pos:Position, with:FieldInit, ?options:{ ?prepend:Bool, ?bypass:Bool }) {
if (options == null)
options = {};
var e =
switch with {
case Arg(t, noPublish):
@@ -84,8 +86,12 @@ class Constructor {
var tmp = MacroApi.tempName();
addStatement(macro @:pos(pos) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (untyped this).$name = $e, prepend);
if (options.bypass) {
addStatement(macro @:pos(pos) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (untyped this).$name = $e, options.prepend);
}
else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
}
public inline function publish()
if (isPublic == null)