| 1 |
version (CppRuntime_LLVM) version = CppMangle_Itanium; |
| 2 |
version (CppRuntime_GNU) version = CppMangle_Itanium; |
| 3 |
version (CppRuntime_Sun) version = CppMangle_Itanium; |
| 4 |
|
| 5 |
template ScopeClass(C , string name = C.stringof) |
| 6 |
//if (is(C == class) && __traits(getLinkage, C) == "C++") |
| 7 |
{ |
| 8 |
//enum name = C.stringof; |
| 9 |
enum ns = __traits(getCppNamespaces,C); |
| 10 |
extern(C++, class) |
| 11 |
{ |
| 12 |
extern(C++,(ns)) |
| 13 |
{ |
| 14 |
pragma(mangle, C, name) |
| 15 |
struct ScopeClass |
| 16 |
{ |
| 17 |
char[__traits(classInstanceSize, C)] buffer; |
| 18 |
//... all the things ... |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
// Basic tests |
| 25 |
extern(C++) |
| 26 |
{ |
| 27 |
class MyClassA {} |
| 28 |
void funa(ScopeClass!MyClassA); // mangles MyClass |
| 29 |
void funb(const ScopeClass!MyClassA); // mangles const MyClass |
| 30 |
void func(ref ScopeClass!MyClassA); // mangles MyClass& |
| 31 |
void fund(ref const ScopeClass!MyClassA); // mangles const MyClass& |
| 32 |
void fune(const(ScopeClass!MyClassA)*); |
| 33 |
} |
| 34 |
|
| 35 |
version (CppMangle_Itanium) |
| 36 |
{ |
| 37 |
static assert(funa.mangleof == "_Z4funa8MyClassA"); |
| 38 |
static assert(funb.mangleof == "_Z4funb8MyClassA"); |
| 39 |
static assert(func.mangleof == "_Z4funcR8MyClassA"); |
| 40 |
static assert(fund.mangleof == "_Z4fundRK8MyClassA"); |
| 41 |
static assert(fune.mangleof == "_Z4funePK8MyClassA"); |
| 42 |
} |
| 43 |
else version (CppRuntime_Microsoft) |
| 44 |
{ |
| 45 |
static assert(funa.mangleof == "?funa@@YAXVMyClassA@@@Z"); |
| 46 |
static assert(funb.mangleof == "?funb@@YAXVMyClassA@@@Z"); |
| 47 |
static if (size_t.sizeof == ulong.sizeof) |
| 48 |
{ |
| 49 |
static assert(func.mangleof == "?func@@YAXAEAVMyClassA@@@Z"); |
| 50 |
static assert(fund.mangleof == "?fund@@YAXAEBVMyClassA@@@Z"); |
| 51 |
static assert(fune.mangleof == "?fune@@YAXPEBVMyClassA@@@Z"); |
| 52 |
} |
| 53 |
else |
| 54 |
{ |
| 55 |
static assert(func.mangleof == "?func@@YAXAAVMyClassA@@@Z"); |
| 56 |
static assert(fund.mangleof == "?fund@@YAXABVMyClassA@@@Z"); |
| 57 |
static assert(fune.mangleof == "?fune@@YAXPBVMyClassA@@@Z"); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
//Basic tests with a namespace |
| 62 |
extern(C++, "ns") |
| 63 |
{ |
| 64 |
class MyClassB {} |
| 65 |
void funf(ScopeClass!MyClassB); // mangles MyClass |
| 66 |
void fung(const ScopeClass!MyClassB); // mangles const MyClass |
| 67 |
void funh(ref ScopeClass!MyClassB); // mangles MyClass& |
| 68 |
void funi(ref const ScopeClass!MyClassB); // mangles const MyClass& |
| 69 |
void funj(const(ScopeClass!MyClassB)*); |
| 70 |
} |
| 71 |
|
| 72 |
version (CppMangle_Itanium) |
| 73 |
{ |
| 74 |
static assert(funf.mangleof == "_ZN2ns4funfENS_8MyClassBE"); |
| 75 |
static assert(fung.mangleof == "_ZN2ns4fungENS_8MyClassBE"); |
| 76 |
static assert(funh.mangleof == "_ZN2ns4funhERNS_8MyClassBE"); |
| 77 |
static assert(funi.mangleof == "_ZN2ns4funiERKNS_8MyClassBE"); |
| 78 |
static assert(funj.mangleof == "_ZN2ns4funjEPKNS_8MyClassBE"); |
| 79 |
} |
| 80 |
else version (CppRuntime_Microsoft) |
| 81 |
{ |
| 82 |
static assert(funf.mangleof == "?funf@ns@@YAXVMyClassB@1@@Z"); |
| 83 |
static assert(fung.mangleof == "?fung@ns@@YAXVMyClassB@1@@Z"); |
| 84 |
static if (size_t.sizeof == ulong.sizeof) |
| 85 |
{ |
| 86 |
static assert(funh.mangleof == "?funh@ns@@YAXAEAVMyClassB@1@@Z"); |
| 87 |
static assert(funi.mangleof == "?funi@ns@@YAXAEBVMyClassB@1@@Z"); |
| 88 |
static assert(funj.mangleof == "?funj@ns@@YAXPEBVMyClassB@1@@Z"); |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
| 92 |
static assert(funh.mangleof == "?funh@ns@@YAXAAVMyClassB@1@@Z"); |
| 93 |
static assert(funi.mangleof == "?funi@ns@@YAXABVMyClassB@1@@Z"); |
| 94 |
static assert(funj.mangleof == "?funj@ns@@YAXPBVMyClassB@1@@Z"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
//Templates |
| 99 |
extern(C++) |
| 100 |
{ |
| 101 |
void funTempl(T)(); |
| 102 |
class MyClassC {} |
| 103 |
alias funTemplA = funTempl!(ScopeClass!MyClassC); |
| 104 |
alias funTemplB = funTempl!(const ScopeClass!MyClassC); |
| 105 |
alias funTemplC = funTempl!(const(ScopeClass!MyClassC)*); |
| 106 |
// N.B funTempl!([const] ref ScopeClass!MyClassC) is not permissable in D |
| 107 |
} |
| 108 |
version (CppMangle_Itanium) |
| 109 |
{ |
| 110 |
static assert(funTemplA.mangleof == "_Z8funTemplI8MyClassCEvv"); |
| 111 |
static assert(funTemplB.mangleof == "_Z8funTemplIK8MyClassCEvv"); |
| 112 |
static assert(funTemplC.mangleof == "_Z8funTemplIPK8MyClassCEvv"); |
| 113 |
} |
| 114 |
else version (CppRuntime_Microsoft) |
| 115 |
{ |
| 116 |
static assert(funTemplA.mangleof == "??$funTempl@VMyClassC@@@@YAXXZ"); |
| 117 |
static assert(funTemplB.mangleof == "??$funTempl@$$CBVMyClassC@@@@YAXXZ"); |
| 118 |
static if (size_t.sizeof == ulong.sizeof) |
| 119 |
static assert(funTemplC.mangleof == "??$funTempl@PEBVMyClassC@@@@YAXXZ"); |
| 120 |
else |
| 121 |
static assert(funTemplC.mangleof == "??$funTempl@PBVMyClassC@@@@YAXXZ"); |
| 122 |
} |
| 123 |
|
| 124 |
template _function(F) |
| 125 |
{ |
| 126 |
extern(C++, "std") |
| 127 |
{ |
| 128 |
extern(C++, struct) |
| 129 |
pragma(mangle, "function") |
| 130 |
class _function |
| 131 |
{ |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
template FunctionOf(F) |
| 136 |
{ |
| 137 |
F f; |
| 138 |
alias FunctionOf = typeof(*f); |
| 139 |
} |
| 140 |
extern(C++) void funk(ScopeClass!(_function!(FunctionOf!(void function(int))),"function") a ){ } |
| 141 |
|
| 142 |
version (CppMangle_Itanium) |
| 143 |
{ |
| 144 |
static assert(funk.mangleof == "_Z4funkSt8functionIFviEE"); |
| 145 |
} |
| 146 |
else version (CppRuntime_Microsoft) |
| 147 |
{ |
| 148 |
static assert(funk.mangleof == "?funk@@YAXV?$function@$$A6AXH@Z@std@@@Z"); |
| 149 |
} |
| 150 |
|
| 151 |
extern(C++, "ns") |
| 152 |
{ |
| 153 |
pragma(mangle, "function") |
| 154 |
class _function2 |
| 155 |
{ |
| 156 |
public final void test(); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
version (CppMangle_Itanium) |
| 161 |
{ |
| 162 |
static assert(_function2.test.mangleof == "_ZN2ns8function4testEv"); |
| 163 |
} |
| 164 |
else version (CppRuntime_Microsoft) |
| 165 |
{ |
| 166 |
static if (size_t.sizeof == ulong.sizeof) |
| 167 |
static assert(_function2.test.mangleof == "?test@function@ns@@QEAAXXZ"); |
| 168 |
else |
| 169 |
static assert(_function2.test.mangleof == "?test@function@ns@@QAEXXZ"); |
| 170 |
} |
| 171 |
|
| 172 |
extern(C++, "ns") |
| 173 |
{ |
| 174 |
template _function3(T) |
| 175 |
{ |
| 176 |
pragma(mangle, _function3, "function") |
| 177 |
class _function3 |
| 178 |
{ |
| 179 |
public final void test(); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
version (CppMangle_Itanium) |
| 185 |
{ |
| 186 |
static assert(_function3!(int).test.mangleof == "_ZN2ns8functionIiE4testEv"); |
| 187 |
} |
| 188 |
else version (CppRuntime_Microsoft) |
| 189 |
{ |
| 190 |
static if (size_t.sizeof == ulong.sizeof) |
| 191 |
static assert(_function3!(int).test.mangleof == "?test@?$function@H@ns@@QEAAXXZ"); |
| 192 |
else |
| 193 |
static assert(_function3!(int).test.mangleof == "?test@?$function@H@ns@@QAEXXZ"); |
| 194 |
} |
| 195 |
|
| 196 |
extern(C++) |
| 197 |
{ |
| 198 |
struct Foo {} |
| 199 |
pragma(mangle, Foo) struct Foo_Doppelganger {} |
| 200 |
|
| 201 |
void funl(Foo_Doppelganger f); |
| 202 |
} |
| 203 |
version (CppMangle_Itanium) |
| 204 |
{ |
| 205 |
static assert(funl.mangleof == "_Z4funl3Foo"); |
| 206 |
} |
| 207 |
else version (CppRuntime_Microsoft) |
| 208 |
{ |
| 209 |
static assert(funl.mangleof == "?funl@@YAXUFoo@@@Z"); |
| 210 |
} |