Last active
December 24, 2015 09:19
-
-
Save AxGord/6776505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
import neko.Lib; | |
/** | |
* ... | |
* @author AxGord <[email protected]> | |
*/ | |
#if !macro | |
class Main implements Elvis { | |
var obj:Dynamic; | |
static function main() { | |
new Main(); | |
} | |
var width:Null<Int>; | |
function new() { | |
~obj.width = 20; | |
obj = { | |
width: 123 | |
}; | |
~obj.width = 100; | |
trace(obj); | |
} | |
} | |
#end | |
#if !macro | |
@:autoBuild(ElvisBuilder.build()) | |
#end | |
interface Elvis {} | |
class ElvisBuilder { | |
macro public static function build():Array<Field> { | |
var fields:Array<Field> = Context.getBuildFields(); | |
for (f in fields) { | |
switch (f.kind) { | |
case FFun( { expr: { expr:EBlock(blocks) }} ): | |
for (b in blocks) switch (b.expr) { | |
case EBinop(OpAssign, { expr:EUnop(OpNegBits, false, e1={expr:EField(subex,_)}) }, e2): | |
var m = macro if ($subex != null) $e1 = $e2; | |
b.expr = m.expr; | |
case _: | |
} | |
case _: | |
} | |
} | |
return fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment