File: externmangle.d

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (369 lines) | stat: -rw-r--r-- 7,182 bytes parent folder | download | duplicates (4)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// EXTRA_CPP_SOURCES: externmangle.cpp
// REQUIRED_ARGS: -extern-std=c++11

import core.stdc.config;
import core.stdc.stdint;

extern(C++):

struct Foo(X)
{
    X* v;
}


struct Boo(X)
{
    X* v;
}


void test1(Foo!int arg1);
void test2(int* arg2, Boo!(int*) arg1);


struct Test3(int X, int Y)
{
}

void test3(Test3!(3,3) arg1);

void test4(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3, int*, Foo!(double));

void test5(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3);


struct Goo
{
    struct Foo(X)
    {
        X* v;
    }

    struct Boo(X)
    {
        struct Xoo(Y)
        {
            Y* v;
        };
        X* v;
    }


    void test6(Foo!(Boo!(Foo!(void))) arg1);
    void test7(Boo!(void).Xoo!(int) arg1);
}

struct P1
{
    struct Mem(T)
    {
    }
}

struct P2
{
    struct Mem(T)
    {
    }
}

void test8(P1.Mem!int, P2.Mem!int);
void test9(Foo!(int**), Foo!(int*), int**, int*);


interface Test10
{
    private final void test10();
    public final void test11();
    protected final void test12();
    public final void test13() const;

    private void test14();
    public void test15();
    protected void test16();

    private static void test17();
    public static void test18();
    protected static void test19();
};

Test10 Test10Ctor();
void Test10Dtor(ref Test10 ptr);

struct Test20
{
    __gshared:
    private extern int test20;
    protected extern int test21;
    public extern int test22;
};


int test23(Test10*, Test10, Test10**, const(Test10));
int test23b(const Test10*, const Test10, Test10);

void test24(int function(int,int));

void test25(int[291][6][5]* arr);
int test26(int[291][6]* arr);

void test27(int, ...);
void test28(int);

void test29(float);
void test30(const float);

struct Array(T)
{
    int dim;
}


interface Module
{
    public static void imports(Module);
    public static int dim(Array!Module*);
};

uint64_t testlongmangle(int a, uint b, int64_t c, uint64_t d);
cpp_ulong testCppLongMangle(cpp_long a, cpp_ulong b);
cpp_ulonglong testCppLongLongMangle(cpp_longlong a, cpp_ulonglong b);

// direct size_t/ptrdiff_t interop is fine except on 32-bit OS X
version (OSX) { version (D_LP64) {} else version = OSX_32; }
version (OSX_32)
    cpp_size_t testCppSizeTMangle(cpp_ptrdiff_t a, cpp_size_t b);
else
    size_t testCppSizeTMangle(ptrdiff_t a, size_t b);

__gshared extern int[2][2][2] test31;
__gshared extern int* test32;


alias int function(Expression , void* ) apply_fp_t;

interface Expression
{
    public final int apply(apply_fp_t fp, apply_fp_t fp2, void* param);
    public final int getType();
    public static Expression create(int);
    public static void dispose(ref Expression);
}

//int test34(int[0][0]*);
version(CRuntime_Microsoft){}
else
{
    int test35(real arg);
}

const(char)* test36(const(char)*);

final class Test37
{
    static Test37 create()
    {
        return new Test37;
    }

    bool test()
    {
        return true;
    }
}

bool test37();

interface Test38
{
     final int test(int, ...);
     public static Test38 create();
     public static void dispose(ref Test38);
}

extern(C++) int test39cpp(C2!char, S2!(int)*);

extern(C++, class)
struct S1
{
    private int val;
    static S1* init(int);
    int value();
}

extern(C++, class)
struct S2(T)
{
    private T val;
    static S2!T* init(int);
    T value();
}

extern(C++, struct)
class C1
{
    const(char)* data;

    static C1 init(const(char)* p);
    const(char)* getDataCPP();
    extern(C++) const(char)* getDataD()
    {
        return data;
    }
}

extern(C++, struct)
class C2(T)
{
    const(T)* data;

    static C2!T init(const(T)* p);
    const(T)* getData();
}

void test39()
{
    S1* s1 = S1.init(42);
    assert(s1.value == 42);
    assert(S2!int.init(43).value == 43);
    const(char)* ptr = "test".ptr;
    C1 c1 = C1.init(ptr);
    assert(c1.getDataCPP() == ptr);
    assert(c1.getDataD() == ptr);
    C2!char c2 = C2!char.init(ptr);
    assert(c2.getData() == ptr);
    auto result = test39cpp(c2, S2!int.init(43));
    assert(result == 0);
}

extern(C++, "foo", "bar", "baz") int doStuff(int);

version(CppRuntime_DigitalMars) // DMC doesn't support c++11
{
    void test40() {}
    void test41() {}
}
else
{
    void test40();

    void foovargs(T...)(T args)
    {
        static if (is(T[0] == char*))
        {
            assert(*args[0] == 'a');
        }
        else
        {
            float ret = args[0] + args[1];
            assert(ret == 3.0f);
        }
    }

    alias FooVargs = foovargs!(int, float);
    alias FooVargs2 = foovargs!(char*);

    void test41();
    void make_shared_poc(T, Args...)(ref Args args)
    {
       assert(args[0] + args[1] == 3);
    }
    alias Make_Shared_Poc =  make_shared_poc!(int, int, int);
}

void main()
{
    test1(Foo!int());
    test2(null, Boo!(int*)());
    test3(Test3!(3,3)());
    test4(Foo!(int*)(), Boo!(int*)(), Boo!(int*)(), null, Foo!(double)());
    test5(Foo!(int*)(), Boo!(int*)(), Boo!(int*)());
    Goo goo;
    goo.test6(Goo.Foo!(Goo.Boo!(Goo.Foo!(void)))());
    goo.test7(Goo.Boo!(void).Xoo!(int)());

    test8(P1.Mem!int(), P2.Mem!int());
    test9(Foo!(int**)(), Foo!(int*)(), null, null);

    auto t10 = Test10Ctor();
    scope(exit) Test10Dtor(t10);

    t10.test10();
    t10.test11();
    t10.test12();
    t10.test13();
    t10.test14();
    t10.test15();
    t10.test16();
    t10.test17();
    t10.test18();
    t10.test19();

    assert(Test20.test20 == 20);
    assert(Test20.test21 == 21);
    assert(Test20.test22 == 22);

    assert(test23(null, null, null, null) == 1);
    assert(test23b(null, null, null) == 1);

    extern(C++) static int cb(int a, int b){return a+b;}

    test24(&cb);
    int[291][6][5] arr;
    arr[1][1][1] = 42;
    test25(&arr);
    assert(test26(&arr[0]) == 42);

    test27(3,4,5);
    test28(3);

    test29(3.14f);
    test30(3.14f);

    auto t32 = &Module.imports;
    Array!Module arr2;
    arr2.dim = 20;
    assert(Module.dim(&arr2) == 20);

    assert(testlongmangle(1, 2, 3, 4) == 10);
    assert(testCppLongMangle(1, 2) == 3);
    assert(testCppLongLongMangle(3, 4) == 7);
    assert(testCppSizeTMangle(3, 4) == 7);
    assert(test31 == [[[1, 1], [1, 1]], [[1, 1], [1, 1]]]);
    assert(test32 == null);

    auto ee = Expression.create(42);
    extern(C++) static int efun(Expression e, void* p)
    {
        return cast(int)(cast(size_t)p ^ e.getType());
    }

    extern(C++) static int efun2(Expression e, void* p)
    {
        return cast(int)(cast(size_t)p * e.getType());
    }

    auto test33 = ee.apply(&efun, &efun2, cast(void*)&Expression.create);
    assert(test33 == cast(int)(cast(size_t)cast(void*)&Expression.create ^ 42) * cast(int)(cast(size_t)cast(void*)&Expression.create * 42));
    Expression.dispose(ee);
    assert(ee is null);
    //assert(test34(null) == 0);
    version(CRuntime_Microsoft){}
    else
    {
        assert(test35(3.14L) == 3);
    }
    const char* hello = "hello";
    assert(test36(hello) == hello);
    assert(test37());
    auto t38 = Test38.create();
    assert(t38.test(1, 2, 3) == 1);
    Test38.dispose(t38);
    test39();

    assert(doStuff(2) == 4);

    test40();
    test41();
}