-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#if macro | ||
import haxe.macro.Compiler; | ||
import haxe.macro.Context; | ||
import haxe.macro.Expr; | ||
|
||
class Macro { | ||
public static function initMacro() { | ||
Compiler.addGlobalMetadata("Main", "@:build(Macro.instrumentFields())", true, true, false); | ||
} | ||
|
||
static function instrumentFields():Null<Array<Field>> { | ||
var fields:Array<Field> = Context.getBuildFields(); | ||
for (field in fields) { | ||
switch (field.kind) { | ||
case FFun(f): | ||
if (f.expr == null) { | ||
continue; | ||
} | ||
switch (f.expr.expr) { | ||
case EBlock(exprs): | ||
exprs.unshift(macro trace($v{field.name})); | ||
case _: | ||
} | ||
case _: | ||
} | ||
} | ||
return fields; | ||
} | ||
} | ||
#end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Main { | ||
static function main() { | ||
var name = new ImageName("abc"); | ||
trace(name); | ||
} | ||
} | ||
|
||
abstract ImageName(String) { | ||
public function new(name:String) { | ||
this = name; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--macro Macro.initMacro() | ||
--run Main |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Macro.hx:21: main | ||
Macro.hx:21: _new | ||
Main.hx:4: abc |