HaxeDoc2

(やまだぃちぅ) #1

9 return null;
10 }
11
12 macro static public
13 function fromBaseClass():Array{
14 trace("fromBaseClass: "
15 + Context.getLocalType());
16 return null;
17 }
18 }


1 @:autoBuild(AutoBuildingMacro.fromInterface())
2 interface I {}
3
4 interface I2 extends I {}
5
6 @:autoBuild(AutoBuildingMacro.fromBaseClass())
7 class Base {}
8
9 class Main extends Base implementsI2 {
10 static public function main() { }
11 }


This outputs during compilation:
1 AutoBuildingMacro.hx:6:
2 fromInterface: TInst(I2,[])
3 AutoBuildingMacro.hx:6:
4 fromInterface: TInst(Main,[])
5 AutoBuildingMacro.hx:11:
6 fromBaseClass: TInst(Main,[])
It is important to keep in mind that the order of these macro executions is undefined, which
is detailed inBuild Order(Section 9.6.3).

9.6 Limitations..........................................


9.6.1 Macro-in-Macro...................................


9.6.2 Static extension


The concepts or static extensions (6.3) and macros are somewhat conflicting: While the former
requires a known type in order to determine used functions, macros execute before typing on
plain syntax. It is thus not surprising that combining these two features can lead to issues. Haxe
3.0 would try to convert the typed expression back to a syntax expression, which is not always
possible and may lose important information. We recommend that it is used with caution.
Since Haxe 3.1.0

The combination of static extensions and macros was reworked for the 3.1.0 release. The Haxe
Compiler does not even try to find the original expression for the macro argument and instead
passes a special@:this thisexpression. While the structure of this expression conveys no
information, the expression can still be typed correctly:
Free download pdf