automatic add Process to DCEHack
This commit is contained in:
45
src/macros/DCEHack.hx
Normal file
45
src/macros/DCEHack.hx
Normal file
@@ -0,0 +1,45 @@
|
||||
package macros;
|
||||
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
using Lambda;
|
||||
|
||||
|
||||
class DCEHack {
|
||||
|
||||
public static final classes: Array<haxe.macro.Type> = [];
|
||||
|
||||
macro static public function dceInclude(): Array<Field> {
|
||||
#if !display
|
||||
var localClass = Context.getLocalClass();
|
||||
|
||||
if (localClass == null){
|
||||
return Context.getBuildFields();
|
||||
}
|
||||
|
||||
// Ignore abstract classes
|
||||
if (localClass.get().isAbstract){
|
||||
return Context.getBuildFields();
|
||||
}
|
||||
|
||||
classes.push(Context.getLocalType());
|
||||
#end
|
||||
return Context.getBuildFields();
|
||||
}
|
||||
|
||||
macro static public function dceGenerateCreate(){
|
||||
var exprs = [];
|
||||
|
||||
for (c in classes){
|
||||
switch (c){
|
||||
case TInst(_.get() => t, _):
|
||||
var path: TypePath = {pack: t.pack, name: t.name};
|
||||
exprs.push(macro new $path());
|
||||
default:
|
||||
Context.error("Unknown type: " + c, Context.currentPos());
|
||||
}
|
||||
}
|
||||
|
||||
return macro return $a{exprs};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user