summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver/cc2/regression-tests/pure2-print.cpp2
blob: 2cf3343824934adfce6df49fa48ee259edda4047 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

//  Exercise the pretty-print visualizer for the various grammar elements

testing_enabled: bool = false;

outer: @print type = {

    object_alias: <T> T requires true == 42;

    mytype: final type =
    {
        protected f: () -> int = 42;

        g: (virtual this, i:int) -> int = {
            using namespace ::std;

            s := "string literal";
            ret: int = i;
            p: const * const int = ret&;
            if p* < 0 {
                ret = -p*;
            }
            ret += strlen(s) - 10 + s.strlen() * (16 / (3 & 2)) % 3;

            m: map<const int,string> = ();
            m[0] = "har" as string;
            ret -= h("x", m).length();
            _ = m;

            return ret;
        }

        private h: (s: std::string, inout m: std::map<const int,std::string> ) -> std::string
            pre( m.empty() == false || false, "message" )
            pre<Bounds, testing_enabled>( 0 < m.ssize() < 100 && true != false, "size is (m.ssize())$" )
        = {
            a := :()={};
            b := :()={};
            c := :()={};

            while s.empty() next a() { break; }

            do { } next b() while s.empty();

            label: for m next c() do (_) { continue label; }

            if !s.empty() is (true) { a(); }
            else if !m.empty() { b(); }
            else { c(); }

            assert( true );

            return :() -> std::string = (s + m[0])$; ();
        }

        values: <T> (this, _: T) throws -> (offset: int, name: std::string) = {
            offset = 53;
            name = "plugh";
        }

        operator=: (out this) = { }

        operator=: (out this, that) = { }

        operator=: (implicit out this, _: int) = { }

        variadic: (x...: int) = { (std::cout << ... << x); }
    }

    test: () = {
        namespace_alias: namespace == ::std;

        using std::array;
        using std::cout;

        type_alias: type == array<int,10>;

        object_alias_1: i8 == 42;
        object_alias_2: == 42;


        var: ::outer::mytype = ();
        cout << var.g(42) << "\n";

        cout << inspect var.g(42) -> namespace_alias::string {
            is 43 = "forty-and-three";
            is _  = "default case";
        } << "\n";
    }

    x: <Ts...: type> type = {
        tup: std::tuple<Ts...> = ();
    }

    print: <Args...: type> (inout out: std::ostream, args...: Args) requires sizeof...(Args) >= 0u = {
        (out << ... << args);
    }

    all: <Args...: type> (args...: Args) -> bool =
        (... && args);

}

main: () = {
    outer::test();
}