|
@@ -77,64 +77,9 @@ class Compiler {
|
|
|
}
|
|
|
|
|
|
#if (!neko && !eval)
|
|
|
- private static function typePatch(cl:String, f:String, stat:Bool, t:String) {}
|
|
|
-
|
|
|
- private static function metaPatch(meta:String, cl:String, f:String, stat:Bool) {}
|
|
|
-
|
|
|
private static function addGlobalMetadataImpl(pathFilter:String, meta:String, recursive:Bool, toTypes:Bool, toFields:Bool) {}
|
|
|
#end
|
|
|
|
|
|
- /**
|
|
|
- Removes a (static) field from a given class by name.
|
|
|
- An error is thrown when `className` or `field` is invalid.
|
|
|
- **/
|
|
|
- @:deprecated
|
|
|
- public static function removeField(className:String, field:String, ?isStatic:Bool) {
|
|
|
- if (!path.match(className))
|
|
|
- throw "Invalid " + className;
|
|
|
- if (!ident.match(field))
|
|
|
- throw "Invalid " + field;
|
|
|
- #if (neko || eval)
|
|
|
- Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, null));
|
|
|
- #else
|
|
|
- typePatch(className, field, isStatic == true, null);
|
|
|
- #end
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- Set the type of a (static) field at a given class by name.
|
|
|
- An error is thrown when `className` or `field` is invalid.
|
|
|
- **/
|
|
|
- @:deprecated
|
|
|
- public static function setFieldType(className:String, field:String, type:String, ?isStatic:Bool) {
|
|
|
- if (!path.match(className))
|
|
|
- throw "Invalid " + className;
|
|
|
- if (!ident.match((field.charAt(0) == "$") ? field.substr(1) : field))
|
|
|
- throw "Invalid " + field;
|
|
|
- #if (neko || eval)
|
|
|
- Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, type));
|
|
|
- #else
|
|
|
- typePatch(className, field, isStatic == true, type);
|
|
|
- #end
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- Add metadata to a (static) field or class by name.
|
|
|
- An error is thrown when `className` or `field` is invalid.
|
|
|
- **/
|
|
|
- @:deprecated
|
|
|
- public static function addMetadata(meta:String, className:String, ?field:String, ?isStatic:Bool) {
|
|
|
- if (!path.match(className))
|
|
|
- throw "Invalid " + className;
|
|
|
- if (field != null && !ident.match(field))
|
|
|
- throw "Invalid " + field;
|
|
|
- #if (neko || eval)
|
|
|
- Context.onAfterInitMacros(() -> load("meta_patch", 4)(meta, className, field, isStatic == true));
|
|
|
- #else
|
|
|
- metaPatch(meta, className, field, isStatic == true);
|
|
|
- #end
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
Add a class path where ".hx" source files or packages (sub-directories) can be found.
|
|
|
|
|
@@ -374,61 +319,6 @@ class Compiler {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- Load a type patch file that can modify the field types within declared classes and enums.
|
|
|
- **/
|
|
|
- public static function patchTypes(file:String):Void {
|
|
|
- var file = Context.resolvePath(file);
|
|
|
- var f = sys.io.File.read(file, true);
|
|
|
- try {
|
|
|
- while (true) {
|
|
|
- var r = StringTools.trim(f.readLine());
|
|
|
- if (r == "" || r.substr(0, 2) == "//")
|
|
|
- continue;
|
|
|
- if (StringTools.endsWith(r, ";"))
|
|
|
- r = r.substr(0, -1);
|
|
|
- if (r.charAt(0) == "-") {
|
|
|
- r = r.substr(1);
|
|
|
- var isStatic = StringTools.startsWith(r, "static ");
|
|
|
- if (isStatic)
|
|
|
- r = r.substr(7);
|
|
|
- var p = r.split(".");
|
|
|
- var field = p.pop();
|
|
|
- removeField(p.join("."), field, isStatic);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (r.charAt(0) == "@") {
|
|
|
- var rp = r.split(" ");
|
|
|
- var type = rp.pop();
|
|
|
- var isStatic = rp[rp.length - 1] == "static";
|
|
|
- if (isStatic)
|
|
|
- rp.pop();
|
|
|
- var meta = rp.join(" ");
|
|
|
- var p = type.split(".");
|
|
|
- var field = if (p.length > 1 && p[p.length - 2].charAt(0) >= "a") null else p.pop();
|
|
|
- addMetadata(meta, p.join("."), field, isStatic);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (StringTools.startsWith(r, "enum ")) {
|
|
|
- define("enumAbstract:" + r.substr(5));
|
|
|
- continue;
|
|
|
- }
|
|
|
- var rp = r.split(" : ");
|
|
|
- if (rp.length > 1) {
|
|
|
- r = rp.shift();
|
|
|
- var isStatic = StringTools.startsWith(r, "static ");
|
|
|
- if (isStatic)
|
|
|
- r = r.substr(7);
|
|
|
- var p = r.split(".");
|
|
|
- var field = p.pop();
|
|
|
- setFieldType(p.join("."), field, rp.join(" : "), isStatic);
|
|
|
- continue;
|
|
|
- }
|
|
|
- throw "Invalid type patch " + r;
|
|
|
- }
|
|
|
- } catch (e:haxe.io.Eof) {}
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
Marks types or packages to be kept by DCE.
|
|
|
|
|
@@ -487,6 +377,11 @@ class Compiler {
|
|
|
#end
|
|
|
}
|
|
|
|
|
|
+ public static function addMetadata(meta:String, className:String, ?field:String, ?isStatic:Bool) {
|
|
|
+ var pathFilter = field == null ? className : '$className.$field';
|
|
|
+ addGlobalMetadata(pathFilter, meta, true, field == null, field != null);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
Reference a json file describing user-defined metadata
|
|
|
See https://github.com/HaxeFoundation/haxe/blob/development/src-json/meta.json
|