Main.hx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import haxe.macro.Context;
  2. import haxe.macro.Type;
  3. import haxe.macro.Expr;
  4. using haxe.macro.Tools;
  5. interface IA {}
  6. interface IB {}
  7. interface IC extends IA extends IB {}
  8. class Main {
  9. static function main() test();
  10. macro static function test() {
  11. function get_type_path(ct:ComplexType) return switch ct {
  12. case TPath(tp):tp;
  13. case _:throw("bad");
  14. };
  15. var td = macro class ID {};
  16. var ia = macro : Main.IA;
  17. var ib = macro : Main.IB;
  18. var ic = macro : Main.IC;
  19. td.kind = TDClass(null,[ia,ib,ic].map(get_type_path),true);
  20. Context.defineType(td);
  21. var t = Context.getType("ID");
  22. switch t {
  23. case TInst(_.get()=>tt,_):
  24. if (tt.interfaces.length != 3)
  25. Context.error("Number of extended interfaces must be 3",Context.currentPos());
  26. case _:
  27. }
  28. var td = macro class IE {};
  29. var ia = macro : Main.IA;
  30. var ib = macro : Main.IB;
  31. var ic = macro : Main.IC;
  32. var ia_tpath = switch ia {
  33. case TPath(tp):tp;
  34. case _:Context.error("must be TPath",Context.currentPos());
  35. }
  36. td.kind = TDClass(ia_tpath,[ib,ic].map(get_type_path),true);
  37. Context.defineType(td);
  38. var t = Context.getType("IE");
  39. switch t {
  40. case TInst(_.get()=>tt,_):
  41. if (tt.interfaces.length != 3)
  42. Context.error("Number of extended interfaces must be 3",Context.currentPos());
  43. case _:
  44. }
  45. var reification = macro interface IF extends Main.IA extends Main.IB {
  46. };
  47. Context.defineType(reification);
  48. var t = Context.getType("IF");
  49. switch t {
  50. case TInst(_.get()=>tt,_):
  51. if (tt.interfaces.length != 2){
  52. Context.error("Number of extended interfaces must be 2",Context.currentPos());
  53. }
  54. case _:
  55. }
  56. return macro null;
  57. }
  58. }