File: Main.hx

package info (click to toggle)
haxe 1%3A4.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,556 kB
  • sloc: ml: 125,171; ansic: 2,408; makefile: 436; java: 362; cs: 323; cpp: 318; python: 316; sh: 75; objc: 64; php: 39; xml: 30; javascript: 11
file content (69 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import haxe.macro.Context;
import haxe.macro.Type;
import haxe.macro.Expr;
using haxe.macro.Tools;

interface IA {}
interface IB {}
interface IC extends IA extends IB {}

class Main {

    static function main() test();

    macro static function test() {

        function get_type_path(ct:ComplexType) return switch ct {
            case TPath(tp):tp;
            case _:throw("bad");
        };

        var td = macro class ID {};
        var ia = macro : Main.IA;
        var ib = macro : Main.IB;
        var ic = macro : Main.IC;
        td.kind = TDClass(null,[ia,ib,ic].map(get_type_path),true);
        Context.defineType(td);
        var t = Context.getType("ID");
        switch t {
            case TInst(_.get()=>tt,_):
                if (tt.interfaces.length != 3)
                    Context.error("Number of extended interfaces must be 3",Context.currentPos());
            case _:
        }

        var td = macro class IE {};
        var ia = macro : Main.IA;
        var ib = macro : Main.IB;
        var ic = macro : Main.IC;

        var ia_tpath = switch ia {
            case TPath(tp):tp;
            case _:Context.error("must be TPath",Context.currentPos());
        }
        td.kind = TDClass(ia_tpath,[ib,ic].map(get_type_path),true);
        Context.defineType(td);

        var t = Context.getType("IE");
        switch t {
            case TInst(_.get()=>tt,_):
                if (tt.interfaces.length != 3)
                    Context.error("Number of extended interfaces must be 3",Context.currentPos());
            case _:
        }

        var reification = macro interface IF extends Main.IA extends Main.IB {

        };
        Context.defineType(reification);
        var t = Context.getType("IF");
        switch t {
            case TInst(_.get()=>tt,_):
                if (tt.interfaces.length != 2){
                    Context.error("Number of extended interfaces must be 2",Context.currentPos());
                }
            case _:
        }
        return macro null;
    }
}