1 #ifndef INSTANTIATE 2 3 #include "sys.h" 4 #include <libcwd/debug.h> 5 #include <libcwd/demangle.h> 6 #include <iostream> 7 8 char const* test_cases [] = { 9 "_ZN12libcw_app_ct10add_optionIS_EEvMT_FvPKcES3_cS3_S3_", 10 "_ZGVN5libcw24_GLOBAL__N_cbll.cc0ZhUKa23compiler_bug_workaroundISt6vectorINS_13omanip_id_tctINS_5debug32memblk_types_manipulator_data_ctEEESaIS6_EEE3idsE", 11 "_ZN6libcwd13cwprint_usingIN5libcw9_private_12GlobalObjectEEENS_17cwprint_using_tctIT_EERKS5_MS5_KFvRSt7ostreamE", 12 "_ZNKSt14priority_queueIP27timer_event_request_base_ctSt5dequeIS1_SaIS1_EE13timer_greaterE3topEv", 13 "_ZNKSt15_Deque_iteratorIP15memory_block_stRKS1_PS2_EeqERKS5_", 14 "_ZNKSt17__normal_iteratorIPK6optionSt6vectorIS0_SaIS0_EEEmiERKS6_", 15 "_ZNSbIcSt11char_traitsIcEN6libcwd27no_alloc_checking_allocatorEE12_S_constructIPcEES5_T_S6_RKS2_", 16 "_Z1fI1APS0_PKS0_EvT_T0_T1_PA4_S3_M1CS8_", 17 "_Z3fooiPiPS_PS0_PS1_PS2_PS3_PS4_PS5_PS6_PS7_PS8_PS9_PSA_PSB_PSC_", 18 "_ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ET0_T_SB_SA_PT1_", 19 "_ZngILi42EEvN1AIXplT_Li2EEE1TE", 20 "_X11TransParseAddress", 21 "_ZNSt13_Alloc_traitsISbIcSt18string_char_traitsIcEN6libcwd9_private_17allocator_adaptorIcSt24__default_alloc_templateILb0ELi327664EELb1EEEENS4_IS8_S6_Lb1EEEE15_S_instancelessE", 22 "_GLOBAL__I__Z2fnv", 23 "_Z1rM1GFivEMS_KFivES_M1HFivES1_4whatIKS_E5what2IS8_ES3_", 24 "_Z1xINiEE", 25 "_Z3fooIA6_KiEvA9_KT_rVPrS4_", 26 "_Z1fILi5E1AEvN1CIXqugtT_Li0ELi1ELi2EEE1qE", 27 "_Z1fILi5EEvN1AIXcvimlT_Li22EEE1qE", 28 "_Z1fPFYPFiiEiE", 29 "_Z1fI1XENT_1tES2_", 30 "_Z1fILi5E1AEvN1CIXstN1T1tEEXszsrS2_1tEE1qE", 31 "_Z1fILi1ELc120EEv1AIXplT_cviLd4028ae147ae147aeEEE", 32 "_Z1fILi1ELc120EEv1AIXplT_cviLf3f800000EEE", 33 "_Z9hairyfuncM1YKFPVPFrPA2_PM1XKFKPA3_ilEPcEiE", 34 "_Z4dep9ILi3EEvP3fooIXgtT_Li2EEE" 35 }; 36 37 MAIN_FUNCTION 38 { PREFIX_CODE 39 Debug( check_configuration() ); 40 Debug( libcw_do.on() ); 41 42 std::string result; 43 for (size_t i = 0; i < sizeof(test_cases)/sizeof(char const*); ++i) 44 { 45 libcwd::demangle_symbol(test_cases[i], result); 46 #ifndef _REENTRANT 47 std::cout << result << '\n'; 48 #else 49 // We could do this: 50 // 51 // pthread_mutex_lock(&cout_mutex); 52 // std::cout << result << '\n'; 53 // pthread_mutex_unlock(&cout_mutex); 54 // 55 // but that would cause this output to 56 // follow 'continued' debug output and 57 // debug output that uses nonewline_cf 58 // on the same line: 59 // 60 // Thread1&2: NOTICE Loading a file... _X11TransParseAddress 61 // Thread1 : done. 62 // 63 // While using the below will result in the 64 // better readable: 65 // 66 // Thread1 : NOTICE Loading a file... <unfinised> 67 // Thread2 : _X11TransParseAddress 68 // Thread1 : NOTICE <continued> done. 69 // 70 // 71 // Or (although the use of nonewline_cf is discouraged in the multi-threaded case!) 72 // 73 // Thread1&2: NOTICE This line does not end on a newline_X11TransParseAddress 74 // Thread1 : , but this does. 75 // 76 // will instead look like: 77 // 78 // Thread1 : NOTICE This line does not end on a newline<no newline> 79 // Thread2 : _X11TransParseAddress 80 // Thread1 : , but this does. 81 // 82 Dout(dc::always|noprefix_cf, result); 83 #endif 84 result.erase(); 85 } 86 EXIT(0); 87 } 88 89 #else // INSTANTIATE 90 91 namespace std { 92 template<typename T> 93 class allocator { }; 94 template<typename T, class _Alloc = allocator<T> > 95 class vector { 96 public: 97 vector(void); 98 void size(void) const { } 99 }; 100 class ostream { }; 101 template<typename T, class _Queue, class _Comp> 102 class priority_queue { 103 public: 104 void top(void) const { } 105 }; 106 template<typename T, class _Alloc = allocator<T> > 107 class deque { 108 }; 109 } 110 111 // _ZN12libcw_app_ct10add_optionIS_EEvMT_FvPKcES3_cS3_S3_ 112 113 class libcw_app_ct { 114 public: 115 void dummy(char const*) { } 116 template<typename T> 117 static void add_option(void (T::*)(char const*), char const*, char, char const*, char const*); 118 }; 119 120 template<typename T> 121 void libcw_app_ct::add_option(void (T::*)(char const*), char const*, char, char const*, char const*) 122 { 123 } 124 125 void fn(void) 126 { 127 // Instantiation. 128 libcw_app_ct::add_option(&libcw_app_ct::dummy, "", '\0', "", ""); 129 } 130 131 // _ZGVN5libcw16_GLOBAL__N__Z1fv23compiler_bug_workaroundISt6vectorINS_13omanip_id_tctINS_5debug32memblk_types_manipulator_data_ctEEESaIS6_EEE3idsE 132 133 namespace libcw { 134 namespace debug { 135 class memblk_types_manipulator_data_ct { }; 136 } 137 template<typename T> 138 class omanip_id_tct { }; 139 namespace { 140 template<typename T> 141 class compiler_bug_workaround { 142 public: 143 static std::vector<int> ids; 144 }; 145 template<typename T> 146 std::vector<int> compiler_bug_workaround<T>::ids; 147 typedef std::vector<libcw::omanip_id_tct<libcw::debug::memblk_types_manipulator_data_ct> > vector_t; 148 compiler_bug_workaround<vector_t> dummy; 149 } 150 } 151 152 void g(void) 153 { 154 // Instantiation. 155 libcw::dummy.ids.size(); 156 } 157 158 // _ZN6libcwd13cwprint_usingIN5libcw9_private_12GlobalObjectEEENS_17cwprint_using_tctIT_EERKS5_MS5_KFvRSt7ostreamE 159 160 namespace libcw { 161 namespace _private_ { 162 class GlobalObject { public: void dummy(std::ostream&) const; }; 163 } 164 } 165 namespace libcwd { 166 template<typename T> 167 class cwprint_using_tct { }; 168 template<typename T> 169 cwprint_using_tct<T> cwprint_using(T const&, void (T::*)(std::ostream&) const); 170 } 171 172 void h(void) 173 { 174 // Instantiation. 175 libcw::_private_::GlobalObject dummy; 176 (void)libcwd::cwprint_using(dummy, &libcw::_private_::GlobalObject::dummy); 177 } 178 179 // _ZNKSt14priority_queueIP27timer_event_request_base_ctSt5dequeIS1_SaIS1_EE13timer_greaterE3topEv 180 181 class timer_event_request_base_ct { }; 182 struct timer_greater { }; 183 184 void i(void) 185 { 186 // Instantiation. 187 std::priority_queue<timer_event_request_base_ct*, std::deque<timer_event_request_base_ct*>, timer_greater> dummy; 188 dummy.top(); 189 } 190 191 // _ZNKSt15_Deque_iteratorIP15memory_block_stRKS1_PS2_EeqERKS5_ 192 193 struct memory_block_st { }; 194 namespace std { 195 template<typename T, typename R = T const&, typename P = T const*> 196 class _Deque_iterator { 197 public: 198 void operator==(_Deque_iterator const&) const { } 199 }; 200 } 201 202 void j(void) 203 { 204 // Instantiation. 205 std::_Deque_iterator<memory_block_st*> dummy; 206 dummy.operator==(dummy); 207 } 208 209 // _ZNKSt17__normal_iteratorIPK6optionSt6vectorIS0_SaIS0_EEEmiERKS6_ 210 211 struct option { }; 212 namespace std { 213 template<typename T1, typename T2> 214 class __normal_iterator { 215 public: 216 void operator-(__normal_iterator const&) const { } 217 }; 218 } 219 220 void k(void) 221 { 222 // Instantiation. 223 std::__normal_iterator<option const*, std::vector<option> > dummy; 224 dummy.operator-(dummy); 225 } 226 227 // _ZNSbIcSt11char_traitsIcEN6libcwd27no_alloc_checking_allocatorEE12_S_constructIPcEES5_T_S6_RKS2_ 228 229 namespace libcwd { 230 class no_alloc_checking_allocator { }; 231 } 232 namespace std { 233 template<typename T> 234 class char_traits { }; 235 template<typename T, class _Traits, class _Alloc> 236 class basic_string { 237 public: 238 template<typename T2> 239 char* _S_construct(T2, T2, _Alloc const&) { return (char*)0; } 240 }; 241 } 242 243 void l(void) 244 { 245 // Instantiation. 246 std::basic_string<char, std::char_traits<char>, libcwd::no_alloc_checking_allocator> dummy; 247 char* cp; 248 libcwd::no_alloc_checking_allocator alloc; 249 dummy._S_construct(cp, cp, alloc); 250 } 251 252 // Original test case: _Z1fI1APS0_PKS0_EvT_T0_T1_PA4_S3_M1CS8_M1DRA3_S3_ 253 // But because it is illegal to have a member-pointer to reference, this does: 254 // _Z1fI1APS0_PKS0_EvT_T0_T1_PA4_S3_M1CS8_ 255 256 class A { }; 257 typedef A const* a4_t[4]; 258 typedef a4_t* ap4_t; 259 class C { 260 public: 261 ap4_t c; 262 }; 263 template<typename T1, typename T2, typename T3> 264 void f(T1, T2, T3, ap4_t, ap4_t (C::*)) { } 265 266 void m(void) 267 { 268 // Instantiation. 269 A a; 270 a4_t a4; 271 f(a, &a, static_cast<A const*>(&a), &a4, &C::c); 272 } 273 274 // _Z3fooiPiPS_PS0_PS1_PS2_PS3_PS4_PS5_PS6_PS7_PS8_PS9_PSA_PSB_PSC_ 275 276 void foo(int, int*, int**, int***, int****, int*****, int******, int*******, int********, int*********, int**********, int***********, int************, int*************, int**************, int***************) 277 { 278 } 279 280 void n(void) 281 { 282 int i0; 283 int* i1; 284 int** i2; 285 int*** i3; 286 int**** i4; 287 int***** i5; 288 int****** i6; 289 int******* i7; 290 int******** i8; 291 int********* i9; 292 int********** i10; 293 int*********** i11; 294 int************ i12; 295 int************* i13; 296 int************** i14; 297 int*************** i15; 298 foo(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15); 299 } 300 301 // Original test case: _ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ET0_T_SB_SA_PT1_ 302 // Real mangled name : _ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ES0_IT1_RSA_PSA_ET_SE_T0_SC_ 303 304 namespace std { 305 template<typename T1, typename T2, typename T3> 306 class D { }; 307 D<A*, A*&, A**> d; 308 template<typename T1, typename T2, typename T3> 309 D<T3, T3&, T3*> B(T1, T1, T2, T3*) { return d; } 310 } 311 312 void o(void) 313 { 314 std::D<A*, A* const&, A* const*> dummy1; 315 std::D<A*, A*&, A**> dummy2; 316 A* dummy3; 317 std::B(dummy1, dummy1, dummy2, &dummy3); 318 } 319 320 // _ZngILi42EEvN1QIXplT_Li2EEE1TE 321 322 template<int i> 323 struct Z { }; 324 template<int i> 325 struct Q { 326 typedef Z<i> T; 327 T t; 328 }; 329 template<int i> 330 void operator-(typename Q<i + 2>::T) { } 331 332 void p(void) 333 { 334 Q<42 + 2>::T z; 335 operator-<42>(z); 336 } 337 338 namespace std { 339 template<bool b, int i> 340 class __default_alloc_template { }; 341 342 template<typename CHAR> 343 class string_char_traits { }; 344 345 template<class BASIC_STRING, class ADAPTOR> 346 struct _Alloc_traits { 347 static char _S_instanceless; 348 }; 349 template<class BASIC_STRING, class ADAPTOR> 350 char _Alloc_traits<BASIC_STRING, ADAPTOR>::_S_instanceless; 351 } 352 namespace libcwd { 353 namespace _private_ { 354 template<typename CHAR, class ALLOCATOR, bool b> 355 class allocator_adaptor { }; 356 } 357 } 358 359 char x; 360 void q(void) 361 { 362 std::_Alloc_traits< 363 std::basic_string< 364 char, 365 std::string_char_traits<char>, 366 libcwd::_private_::allocator_adaptor< 367 char, 368 std::__default_alloc_template<false, 327664>, 369 true 370 > 371 >, 372 libcwd::_private_::allocator_adaptor< 373 std::basic_string< 374 char, 375 std::string_char_traits<char>, 376 libcwd::_private_::allocator_adaptor< 377 char, 378 std::__default_alloc_template<false, 327664>, 379 true 380 > 381 >, 382 std::__default_alloc_template<false, 327664>, 383 true 384 > 385 > dummy1; 386 x = dummy1._S_instanceless; 387 } 388 389 // _Z1rM1GKFivE 390 391 struct G { 392 int m(void) const { return 0; } 393 int n(void) { return 0; } 394 }; 395 396 struct H { 397 int m(void) const { return 0; } 398 int n(void) { return 0; } 399 }; 400 401 template<typename T> 402 class what 403 { 404 }; 405 406 template<typename T> 407 class what2 408 { 409 }; 410 411 void r(int (G::*)(void), 412 int (G::*)(void) const, 413 G, /* S_ */ 414 int (H::*)(void), /* M1HS0_ */ 415 int (G::*)(void), /* S1_ */ 416 what<G const>, /* what<S2_> */ 417 what2<G const>, /* what2<S8_> */ 418 int (G::*)(void) const /* S3_ */) 419 { 420 G g; 421 what<G const> y; 422 what2<G const> y2; 423 r(&G::n, &G::m, g, &H::n, &G::n, y, y2, &G::m); 424 } 425 426 #endif // INSTANTIATE 427