ALL NEW improved Binstore
also automaticly inlcude everything in src/bin
This commit is contained in:
68
src/macros/Binstore.hx
Normal file
68
src/macros/Binstore.hx
Normal file
@@ -0,0 +1,68 @@
|
||||
package macros;
|
||||
|
||||
import haxe.macro.TypeTools;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
|
||||
using Lambda;
|
||||
|
||||
class Binstore {
|
||||
static var bins:Array<{c:TypePath, name:String, alias:Array<String>}> = [];
|
||||
|
||||
macro static function includeBin(name:String, alias:Array<String>):Array<Field> {
|
||||
var fields = Context.getBuildFields();
|
||||
var localClass = Context.getLocalClass().get();
|
||||
|
||||
// FIXME: Right now we are trusting the dev that the class implements Process. It will fail later
|
||||
// anyway but better tell ihm now.
|
||||
|
||||
var constructor = fields.find((field) -> field.name == "new");
|
||||
|
||||
if (!constructor.access.contains(APublic)) {
|
||||
Context.error("Constructor needs to be public", constructor.pos);
|
||||
}
|
||||
|
||||
switch constructor.kind {
|
||||
case FFun(f):
|
||||
if (f.args.length != 0) {
|
||||
Context.error("Process constructor are not allowed to have args", constructor.pos);
|
||||
}
|
||||
default:
|
||||
Context.error("Somethings wrong with your constructor", constructor.pos);
|
||||
}
|
||||
|
||||
switch TypeTools.toComplexType(Context.getLocalType()) {
|
||||
case TPath(p):
|
||||
bins.push({
|
||||
c: p,
|
||||
name: name,
|
||||
alias: alias
|
||||
});
|
||||
default:
|
||||
Context.error("IDFK what went wrong", localClass.pos);
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
public macro static function generateBinStore() {
|
||||
var exprs:Array<Expr> = [];
|
||||
|
||||
for (bin in bins) {
|
||||
var c = bin.c;
|
||||
exprs.push(macro {
|
||||
bins.push({
|
||||
c: () -> {
|
||||
return new $c();
|
||||
},
|
||||
name: $v{bin.name},
|
||||
aliases: $v{bin.alias}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return macro {
|
||||
$a{exprs}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
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