HaxeDoc2

(やまだぃちぅ) #1

1 import haxe.macro.Context;
2 import haxe.macro.Expr;
3
4 using Main;
5 using haxe.macro.Tools;
6
7 class Main {
8 static public function main() {
9 "foo".test();
10 }
11
12 macro static function
13 test(e:ExprOf) {
14 trace(e.toString()); // @:thisthis
15 // TInst(String,[])
16 trace(Context.typeof(e));
17 return e;
18 }
19 }


9.6.3 Build Order


The build order of types is unspecified and this extends to the execution order of build-macros
(9.5). While certain rules can be determined, we strongly recommend to not rely on the execution
order of build-macros. If type building requires multiple passes, this should be reflected directly
in the macro code. In order to avoid multiple build-macro execution on the same type, state can
be stored in static variables or added as metadata (6.9) to the type in question:
1 import haxe.macro.Context;
2 import haxe.macro.Expr;
3
4 #if !macro
5 @:autoBuild(MyMacro.build())
6 #end
7 interface I1 {}
8
9 #if !macro
10 @:autoBuild(MyMacro.build())
11 #end
12 interface I2 {}
13
14 class C implements I1 implementsI2 {}
15
16 class MyMacro {
17 macro static public function
18 build():Array{
19 var c = Context.getLocalClass().get();
20 if (c.meta.has(":processed"))return null;
21 c.meta.add(":processed",[],c.pos);
22 // process here
23 return null;

Free download pdf