Macro to generate function calls from TypeDef

The conversion is fair enough because you have to go from expression to type somehow. There are multiple avenues here, and going through Context.getType is fine.

What isn’t fine is that EnumValuesTools usage. Don’t use that, use normal switches. You can simplify your code like so:

import haxe.macro.Context;
import haxe.macro.Expr;

using haxe.macro.Tools;

class Macros {
    macro public static function build(td:Expr):Array<Field> {
        var t = Context.getType(td.toString()).follow();
		var anon = switch (t) {
			case TAnonymous(ref): ref.get();
			case _: Context.error("Structure expected", td.pos);
		}
        for (tdf in anon.fields) {
            trace('generate function: resolve_${tdf.name};');
        }

        return null;
    }
}
2 Likes