|
@@ -51,14 +51,12 @@ class Compiler {
|
|
|
return macro $v{haxe.macro.Context.definedValue(key)};
|
|
|
}
|
|
|
|
|
|
- #if (neko || (macro && hl) || (macro && eval))
|
|
|
+ #if macro
|
|
|
static var ident = ~/^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
|
static var path = ~/^[A-Za-z_][A-Za-z0-9_.]*$/;
|
|
|
|
|
|
public static function allowPackage(v:String) {
|
|
|
- #if (neko || eval)
|
|
|
load("allow_package", 1)(v);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -67,48 +65,30 @@ class Compiler {
|
|
|
Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
|
|
|
**/
|
|
|
public static function define(flag:String, ?value:String) {
|
|
|
- #if (neko || eval)
|
|
|
Context.assertInitMacro();
|
|
|
load("define", 2)(flag, value);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
- #if (!neko && !eval)
|
|
|
- private static function addGlobalMetadataImpl(pathFilter:String, meta:String, recursive:Bool, toTypes:Bool, toFields:Bool) {}
|
|
|
- #end
|
|
|
-
|
|
|
/**
|
|
|
Add a class path where ".hx" source files or packages (sub-directories) can be found.
|
|
|
|
|
|
Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
|
|
|
**/
|
|
|
public static function addClassPath(path:String) {
|
|
|
- #if (neko || eval)
|
|
|
Context.assertInitMacro();
|
|
|
load("add_class_path", 1)(path);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
public static function getOutput():String {
|
|
|
- #if (neko || eval)
|
|
|
return load("get_output", 0)();
|
|
|
- #else
|
|
|
- return null;
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
public static function setOutput(fileOrDir:String) {
|
|
|
- #if (neko || eval)
|
|
|
load("set_output", 1)(fileOrDir);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
public static function getDisplayPos():Null<{file:String, pos:Int}> {
|
|
|
- #if (neko || eval)
|
|
|
return load("get_display_pos", 0)();
|
|
|
- #else
|
|
|
- return null;
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -117,11 +97,7 @@ class Compiler {
|
|
|
Usage of this function outside a macro context returns `null`.
|
|
|
**/
|
|
|
public static function getConfiguration():Null<CompilerConfiguration> {
|
|
|
- #if (neko || eval)
|
|
|
return load("get_configuration", 0)();
|
|
|
- #else
|
|
|
- return null;
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -130,9 +106,7 @@ class Compiler {
|
|
|
Usage of this function outside a macro context does nothing.
|
|
|
**/
|
|
|
public static function setPlatformConfiguration(config:PlatformConfig):Void {
|
|
|
- #if (neko || eval)
|
|
|
load("set_platform_configuration", 1)(config);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -141,10 +115,8 @@ class Compiler {
|
|
|
Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
|
|
|
**/
|
|
|
public static function addNativeLib(name:String) {
|
|
|
- #if (neko || eval)
|
|
|
Context.assertInitMacro();
|
|
|
load("add_native_lib", 1)(name);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -367,11 +339,7 @@ class Compiler {
|
|
|
through `Context.getType`.
|
|
|
**/
|
|
|
public static function addGlobalMetadata(pathFilter:String, meta:String, ?recursive:Bool = true, ?toTypes:Bool = true, ?toFields:Bool = false) {
|
|
|
- #if (neko || eval)
|
|
|
load("add_global_metadata_impl", 5)(pathFilter, meta, recursive, toTypes, toFields);
|
|
|
- #else
|
|
|
- addGlobalMetadataImpl(pathFilter, meta, recursive, toTypes, toFields);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
@:deprecated
|
|
@@ -406,80 +374,39 @@ class Compiler {
|
|
|
Register a custom metadata for documentation and completion purposes
|
|
|
**/
|
|
|
public static function registerCustomMetadata(meta:MetadataDescription, ?source:String):Void {
|
|
|
- #if (neko || eval)
|
|
|
load("register_metadata_impl", 2)(meta, source);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
Register a custom define for documentation purposes
|
|
|
**/
|
|
|
public static function registerCustomDefine(define:DefineDescription, ?source:String):Void {
|
|
|
- #if (neko || eval)
|
|
|
load("register_define_impl", 2)(define, source);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
Change the default JS output by using a custom generator callback
|
|
|
**/
|
|
|
public static function setCustomJSGenerator(callb:JSGenApi->Void) {
|
|
|
- #if (neko || eval)
|
|
|
load("set_custom_js_generator", 1)(callb);
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
- #if (neko || eval)
|
|
|
static inline function load(f, nargs):Dynamic {
|
|
|
return @:privateAccess Context.load(f, nargs);
|
|
|
}
|
|
|
- #end
|
|
|
|
|
|
/**
|
|
|
Clears cached results of file lookups
|
|
|
**/
|
|
|
public static function flushDiskCache() {
|
|
|
- #if (neko || eval)
|
|
|
load("flush_disk_cache", 0)();
|
|
|
- #end
|
|
|
}
|
|
|
- #end
|
|
|
-
|
|
|
- #if (js || lua || macro)
|
|
|
- /**
|
|
|
- Embed a JavaScript or Lua file at compile time (can be called by `--macro` or within an `__init__` method).
|
|
|
- **/
|
|
|
- public static #if !macro macro #end function includeFile(file:String, position:IncludePosition = Top) {
|
|
|
- return switch ((position : String).toLowerCase()) {
|
|
|
- case Inline:
|
|
|
- if (Context.getLocalModule() == "")
|
|
|
- Context.error("Cannot use inline mode when includeFile is called by `--macro`", Context.currentPos());
|
|
|
-
|
|
|
- var f = try sys.io.File.getContent(Context.resolvePath(file)) catch (e:Dynamic) Context.error(Std.string(e), Context.currentPos());
|
|
|
- var p = Context.currentPos();
|
|
|
- if (Context.defined("js")) {
|
|
|
- macro @:pos(p) js.Syntax.plainCode($v{f});
|
|
|
- } else {
|
|
|
- macro @:pos(p) untyped __lua__($v{f});
|
|
|
- }
|
|
|
- case Top | Closure:
|
|
|
- @:privateAccess Context.includeFile(file, position);
|
|
|
- macro {};
|
|
|
- case _:
|
|
|
- Context.error("unknown includeFile position: " + position, Context.currentPos());
|
|
|
- }
|
|
|
- }
|
|
|
- #end
|
|
|
|
|
|
/**
|
|
|
Gets the current hxb writer configuration, if any.
|
|
|
**/
|
|
|
static public function getHxbWriterConfiguration():Null<WriterConfig> {
|
|
|
- #if macro
|
|
|
return load("get_hxb_writer_config", 0)();
|
|
|
- #else
|
|
|
- return null;
|
|
|
- #end
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -500,10 +427,35 @@ class Compiler {
|
|
|
@see haxe.hxb.WriterConfig
|
|
|
**/
|
|
|
static public function setHxbWriterConfiguration(config:Null<WriterConfig>) {
|
|
|
- #if macro
|
|
|
load("set_hxb_writer_config", 1)(config);
|
|
|
- #end
|
|
|
}
|
|
|
+ #end
|
|
|
+
|
|
|
+ #if (js || lua || macro)
|
|
|
+ /**
|
|
|
+ Embed a JavaScript or Lua file at compile time (can be called by `--macro` or within an `__init__` method).
|
|
|
+ **/
|
|
|
+ public static #if !macro macro #end function includeFile(file:String, position:IncludePosition = Top) {
|
|
|
+ return switch ((position : String).toLowerCase()) {
|
|
|
+ case Inline:
|
|
|
+ if (Context.getLocalModule() == "")
|
|
|
+ Context.error("Cannot use inline mode when includeFile is called by `--macro`", Context.currentPos());
|
|
|
+
|
|
|
+ var f = try sys.io.File.getContent(Context.resolvePath(file)) catch (e:Dynamic) Context.error(Std.string(e), Context.currentPos());
|
|
|
+ var p = Context.currentPos();
|
|
|
+ if (Context.defined("js")) {
|
|
|
+ macro @:pos(p) js.Syntax.plainCode($v{f});
|
|
|
+ } else {
|
|
|
+ macro @:pos(p) untyped __lua__($v{f});
|
|
|
+ }
|
|
|
+ case Top | Closure:
|
|
|
+ @:privateAccess Context.includeFile(file, position);
|
|
|
+ macro {};
|
|
|
+ case _:
|
|
|
+ Context.error("unknown includeFile position: " + position, Context.currentPos());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #end
|
|
|
}
|
|
|
|
|
|
enum abstract IncludePosition(String) from String to String {
|