|
@@ -175,6 +175,7 @@ class Context {
|
|
Returns `null` if the current macro is not a `@:genericBuild` macro.
|
|
Returns `null` if the current macro is not a `@:genericBuild` macro.
|
|
**/
|
|
**/
|
|
public static function getCallArguments():Null<Array<Expr>> {
|
|
public static function getCallArguments():Null<Array<Expr>> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_call_arguments", 0)();
|
|
return load("get_call_arguments", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -184,6 +185,7 @@ class Context {
|
|
If no such class exists, `null` is returned.
|
|
If no such class exists, `null` is returned.
|
|
**/
|
|
**/
|
|
public static function getLocalClass():Null<Type.Ref<Type.ClassType>> {
|
|
public static function getLocalClass():Null<Type.Ref<Type.ClassType>> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
var l:Type = load("get_local_type", 0)();
|
|
var l:Type = load("get_local_type", 0)();
|
|
if (l == null)
|
|
if (l == null)
|
|
return null;
|
|
return null;
|
|
@@ -197,6 +199,7 @@ class Context {
|
|
Returns the current module path in/on which the macro was called.
|
|
Returns the current module path in/on which the macro was called.
|
|
**/
|
|
**/
|
|
public static function getLocalModule():String {
|
|
public static function getLocalModule():String {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_local_module", 0)();
|
|
return load("get_local_module", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -206,6 +209,7 @@ class Context {
|
|
If no such type exists, `null` is returned.
|
|
If no such type exists, `null` is returned.
|
|
**/
|
|
**/
|
|
public static function getLocalType():Null<Type> {
|
|
public static function getLocalType():Null<Type> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_local_type", 0)();
|
|
return load("get_local_type", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -215,6 +219,7 @@ class Context {
|
|
If no such method exists, `null` is returned.
|
|
If no such method exists, `null` is returned.
|
|
**/
|
|
**/
|
|
public static function getLocalMethod():Null<String> {
|
|
public static function getLocalMethod():Null<String> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_local_method", 0)();
|
|
return load("get_local_method", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -225,6 +230,7 @@ class Context {
|
|
Modifying the returned array has no effect on the compiler.
|
|
Modifying the returned array has no effect on the compiler.
|
|
**/
|
|
**/
|
|
public static function getLocalUsing():Array<Type.Ref<Type.ClassType>> {
|
|
public static function getLocalUsing():Array<Type.Ref<Type.ClassType>> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_local_using", 0)();
|
|
return load("get_local_using", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -234,6 +240,7 @@ class Context {
|
|
Modifying the returned array has no effect on the compiler.
|
|
Modifying the returned array has no effect on the compiler.
|
|
**/
|
|
**/
|
|
public static function getLocalImports():Array<ImportExpr> {
|
|
public static function getLocalImports():Array<ImportExpr> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_local_imports", 0)();
|
|
return load("get_local_imports", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -248,6 +255,7 @@ class Context {
|
|
**/
|
|
**/
|
|
@:deprecated("Use Context.getLocalTVars() instead")
|
|
@:deprecated("Use Context.getLocalTVars() instead")
|
|
public static function getLocalVars():Map<String, Type> {
|
|
public static function getLocalVars():Map<String, Type> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("local_vars", 1)(false);
|
|
return load("local_vars", 1)(false);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -256,6 +264,7 @@ class Context {
|
|
of `Type`.
|
|
of `Type`.
|
|
**/
|
|
**/
|
|
public static function getLocalTVars():Map<String, Type.TVar> {
|
|
public static function getLocalTVars():Map<String, Type.TVar> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("local_vars", 1)(true);
|
|
return load("local_vars", 1)(true);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -459,8 +468,11 @@ class Context {
|
|
actual typing.
|
|
actual typing.
|
|
**/
|
|
**/
|
|
public static function onAfterInitMacros(callback:Void->Void):Void {
|
|
public static function onAfterInitMacros(callback:Void->Void):Void {
|
|
- assertInitMacro();
|
|
|
|
- load("on_after_init_macros", 1)(callback);
|
|
|
|
|
|
+ if (Context.initMacrosDone()) {
|
|
|
|
+ callback();
|
|
|
|
+ } else {
|
|
|
|
+ load("on_after_init_macros", 1)(callback);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -534,6 +546,7 @@ class Context {
|
|
build any type or trigger macros.
|
|
build any type or trigger macros.
|
|
**/
|
|
**/
|
|
public static function resolveComplexType(t:ComplexType, p:Position):ComplexType {
|
|
public static function resolveComplexType(t:ComplexType, p:Position):ComplexType {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("resolve_complex_type", 2)(t, p);
|
|
return load("resolve_complex_type", 2)(t, p);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -632,6 +645,7 @@ class Context {
|
|
This is only defined for `@:build/@:autoBuild` macros.
|
|
This is only defined for `@:build/@:autoBuild` macros.
|
|
**/
|
|
**/
|
|
public static function getBuildFields():Array<Field> {
|
|
public static function getBuildFields():Array<Field> {
|
|
|
|
+ assertInitMacrosDone(false);
|
|
return load("get_build_fields", 0)();
|
|
return load("get_build_fields", 0)();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -773,8 +787,7 @@ class Context {
|
|
run your code once typer is ready to be used.
|
|
run your code once typer is ready to be used.
|
|
**/
|
|
**/
|
|
public static function registerModuleDependency(modulePath:String, externFile:String) {
|
|
public static function registerModuleDependency(modulePath:String, externFile:String) {
|
|
- assertInitMacrosDone();
|
|
|
|
- load("register_module_dependency", 2)(modulePath, externFile);
|
|
|
|
|
|
+ onAfterInitMacros(() -> load("register_module_dependency", 2)(modulePath, externFile));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -861,7 +874,7 @@ class Context {
|
|
}
|
|
}
|
|
|
|
|
|
private static function sExpr(e:TypedExpr, pretty:Bool):String {
|
|
private static function sExpr(e:TypedExpr, pretty:Bool):String {
|
|
- return haxe.macro.Context.load("s_expr", 2)(e, pretty);
|
|
|
|
|
|
+ return load("s_expr", 2)(e, pretty);
|
|
}
|
|
}
|
|
|
|
|
|
@:allow(haxe.macro.Compiler)
|
|
@:allow(haxe.macro.Compiler)
|
|
@@ -876,20 +889,19 @@ class Context {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @:allow(haxe.macro.Compiler)
|
|
private static function assertInitMacrosDone(includeSuggestion = true):Void {
|
|
private static function assertInitMacrosDone(includeSuggestion = true):Void {
|
|
- #if haxe_next
|
|
|
|
if (!initMacrosDone()) {
|
|
if (!initMacrosDone()) {
|
|
var stack = getMacroStack();
|
|
var stack = getMacroStack();
|
|
var suggestion = includeSuggestion
|
|
var suggestion = includeSuggestion
|
|
? "\nUse `Context.onAfterInitMacros` to register a callback to run when context is ready."
|
|
? "\nUse `Context.onAfterInitMacros` to register a callback to run when context is ready."
|
|
: "";
|
|
: "";
|
|
|
|
|
|
- warning(
|
|
|
|
|
|
+ fatalError(
|
|
"Cannot use this API from initialization macros." + suggestion,
|
|
"Cannot use this API from initialization macros." + suggestion,
|
|
if (stack.length > 2) stack[2] else currentPos()
|
|
if (stack.length > 2) stack[2] else currentPos()
|
|
);
|
|
);
|
|
}
|
|
}
|
|
- #end
|
|
|
|
}
|
|
}
|
|
#end
|
|
#end
|
|
}
|
|
}
|