Skip to content

Instantly share code, notes, and snippets.

@AxGord
Last active December 24, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AxGord/6776505 to your computer and use it in GitHub Desktop.
Save AxGord/6776505 to your computer and use it in GitHub Desktop.
package ;
import haxe.macro.Context;
import haxe.macro.Expr;
import neko.Lib;
/**
* ...
* @author AxGord <axgord@gmail.com>
*/
#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