1 1.1 christos /* Demangler for g++ V3 ABI. 2 1.10 christos Copyright (C) 2003-2025 Free Software Foundation, Inc. 3 1.1 christos Written by Ian Lance Taylor <ian (at) wasabisystems.com>. 4 1.1 christos 5 1.1 christos This file is part of the libiberty library, which is part of GCC. 6 1.1 christos 7 1.1 christos This file is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 2 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos In addition to the permissions in the GNU General Public License, the 13 1.1 christos Free Software Foundation gives you unlimited permission to link the 14 1.1 christos compiled version of this file into combinations with other programs, 15 1.1 christos and to distribute those combinations without any restriction coming 16 1.1 christos from the use of this file. (The General Public License restrictions 17 1.1 christos do apply in other respects; for example, they cover modification of 18 1.1 christos the file, and distribution when not linked into a combined 19 1.1 christos executable.) 20 1.1 christos 21 1.1 christos This program is distributed in the hope that it will be useful, 22 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 23 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 1.1 christos GNU General Public License for more details. 25 1.1 christos 26 1.1 christos You should have received a copy of the GNU General Public License 27 1.1 christos along with this program; if not, write to the Free Software 28 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 29 1.1 christos */ 30 1.1 christos 31 1.1 christos /* This code implements a demangler for the g++ V3 ABI. The ABI is 32 1.1 christos described on this web page: 33 1.6 christos https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling 34 1.1 christos 35 1.1 christos This code was written while looking at the demangler written by 36 1.1 christos Alex Samuel <samuel (at) codesourcery.com>. 37 1.1 christos 38 1.1 christos This code first pulls the mangled name apart into a list of 39 1.1 christos components, and then walks the list generating the demangled 40 1.1 christos name. 41 1.1 christos 42 1.1 christos This file will normally define the following functions, q.v.: 43 1.1 christos char *cplus_demangle_v3(const char *mangled, int options) 44 1.1 christos char *java_demangle_v3(const char *mangled) 45 1.1 christos int cplus_demangle_v3_callback(const char *mangled, int options, 46 1.1 christos demangle_callbackref callback) 47 1.1 christos int java_demangle_v3_callback(const char *mangled, 48 1.1 christos demangle_callbackref callback) 49 1.1 christos enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name) 50 1.1 christos enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name) 51 1.1 christos 52 1.1 christos Also, the interface to the component list is public, and defined in 53 1.1 christos demangle.h. The interface consists of these types, which are 54 1.1 christos defined in demangle.h: 55 1.1 christos enum demangle_component_type 56 1.1 christos struct demangle_component 57 1.1 christos demangle_callbackref 58 1.1 christos and these functions defined in this file: 59 1.1 christos cplus_demangle_fill_name 60 1.1 christos cplus_demangle_fill_extended_operator 61 1.1 christos cplus_demangle_fill_ctor 62 1.1 christos cplus_demangle_fill_dtor 63 1.1 christos cplus_demangle_print 64 1.1 christos cplus_demangle_print_callback 65 1.1 christos and other functions defined in the file cp-demint.c. 66 1.1 christos 67 1.1 christos This file also defines some other functions and variables which are 68 1.1 christos only to be used by the file cp-demint.c. 69 1.1 christos 70 1.1 christos Preprocessor macros you can define while compiling this file: 71 1.1 christos 72 1.1 christos IN_LIBGCC2 73 1.1 christos If defined, this file defines the following functions, q.v.: 74 1.1 christos char *__cxa_demangle (const char *mangled, char *buf, size_t *len, 75 1.1 christos int *status) 76 1.1 christos int __gcclibcxx_demangle_callback (const char *, 77 1.1 christos void (*) 78 1.1 christos (const char *, size_t, void *), 79 1.1 christos void *) 80 1.1 christos instead of cplus_demangle_v3[_callback]() and 81 1.1 christos java_demangle_v3[_callback](). 82 1.1 christos 83 1.1 christos IN_GLIBCPP_V3 84 1.1 christos If defined, this file defines only __cxa_demangle() and 85 1.1 christos __gcclibcxx_demangle_callback(), and no other publically visible 86 1.1 christos functions or variables. 87 1.1 christos 88 1.1 christos STANDALONE_DEMANGLER 89 1.1 christos If defined, this file defines a main() function which demangles 90 1.1 christos any arguments, or, if none, demangles stdin. 91 1.1 christos 92 1.1 christos CP_DEMANGLE_DEBUG 93 1.1 christos If defined, turns on debugging mode, which prints information on 94 1.1 christos stdout about the mangled string. This is not generally useful. 95 1.5 christos 96 1.5 christos CHECK_DEMANGLER 97 1.5 christos If defined, additional sanity checks will be performed. It will 98 1.5 christos cause some slowdown, but will allow to catch out-of-bound access 99 1.5 christos errors earlier. This macro is intended for testing and debugging. */ 100 1.1 christos 101 1.1 christos #if defined (_AIX) && !defined (__GNUC__) 102 1.1 christos #pragma alloca 103 1.1 christos #endif 104 1.1 christos 105 1.1 christos #ifdef HAVE_CONFIG_H 106 1.1 christos #include "config.h" 107 1.1 christos #endif 108 1.1 christos 109 1.1 christos #include <stdio.h> 110 1.1 christos 111 1.1 christos #ifdef HAVE_STDLIB_H 112 1.1 christos #include <stdlib.h> 113 1.1 christos #endif 114 1.1 christos #ifdef HAVE_STRING_H 115 1.1 christos #include <string.h> 116 1.1 christos #endif 117 1.1 christos 118 1.1 christos #ifdef HAVE_ALLOCA_H 119 1.1 christos # include <alloca.h> 120 1.1 christos #else 121 1.1 christos # ifndef alloca 122 1.1 christos # ifdef __GNUC__ 123 1.1 christos # define alloca __builtin_alloca 124 1.1 christos # else 125 1.1 christos extern char *alloca (); 126 1.1 christos # endif /* __GNUC__ */ 127 1.1 christos # endif /* alloca */ 128 1.1 christos #endif /* HAVE_ALLOCA_H */ 129 1.1 christos 130 1.6 christos #ifdef HAVE_LIMITS_H 131 1.6 christos #include <limits.h> 132 1.6 christos #endif 133 1.6 christos #ifndef INT_MAX 134 1.6 christos # define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */ 135 1.6 christos #endif 136 1.6 christos 137 1.1 christos #include "ansidecl.h" 138 1.1 christos #include "libiberty.h" 139 1.1 christos #include "demangle.h" 140 1.1 christos #include "cp-demangle.h" 141 1.1 christos 142 1.1 christos /* If IN_GLIBCPP_V3 is defined, some functions are made static. We 143 1.1 christos also rename them via #define to avoid compiler errors when the 144 1.1 christos static definition conflicts with the extern declaration in a header 145 1.1 christos file. */ 146 1.1 christos #ifdef IN_GLIBCPP_V3 147 1.1 christos 148 1.1 christos #define CP_STATIC_IF_GLIBCPP_V3 static 149 1.1 christos 150 1.1 christos #define cplus_demangle_fill_name d_fill_name 151 1.1 christos static int d_fill_name (struct demangle_component *, const char *, int); 152 1.1 christos 153 1.1 christos #define cplus_demangle_fill_extended_operator d_fill_extended_operator 154 1.1 christos static int 155 1.1 christos d_fill_extended_operator (struct demangle_component *, int, 156 1.1 christos struct demangle_component *); 157 1.1 christos 158 1.1 christos #define cplus_demangle_fill_ctor d_fill_ctor 159 1.1 christos static int 160 1.1 christos d_fill_ctor (struct demangle_component *, enum gnu_v3_ctor_kinds, 161 1.1 christos struct demangle_component *); 162 1.1 christos 163 1.1 christos #define cplus_demangle_fill_dtor d_fill_dtor 164 1.1 christos static int 165 1.1 christos d_fill_dtor (struct demangle_component *, enum gnu_v3_dtor_kinds, 166 1.1 christos struct demangle_component *); 167 1.1 christos 168 1.1 christos #define cplus_demangle_mangled_name d_mangled_name 169 1.1 christos static struct demangle_component *d_mangled_name (struct d_info *, int); 170 1.1 christos 171 1.1 christos #define cplus_demangle_type d_type 172 1.1 christos static struct demangle_component *d_type (struct d_info *); 173 1.1 christos 174 1.1 christos #define cplus_demangle_print d_print 175 1.6 christos static char *d_print (int, struct demangle_component *, int, size_t *); 176 1.1 christos 177 1.1 christos #define cplus_demangle_print_callback d_print_callback 178 1.6 christos static int d_print_callback (int, struct demangle_component *, 179 1.1 christos demangle_callbackref, void *); 180 1.1 christos 181 1.1 christos #define cplus_demangle_init_info d_init_info 182 1.1 christos static void d_init_info (const char *, int, size_t, struct d_info *); 183 1.1 christos 184 1.1 christos #else /* ! defined(IN_GLIBCPP_V3) */ 185 1.1 christos #define CP_STATIC_IF_GLIBCPP_V3 186 1.1 christos #endif /* ! defined(IN_GLIBCPP_V3) */ 187 1.1 christos 188 1.1 christos /* See if the compiler supports dynamic arrays. */ 189 1.1 christos 190 1.1 christos #ifdef __GNUC__ 191 1.1 christos #define CP_DYNAMIC_ARRAYS 192 1.1 christos #else 193 1.1 christos #ifdef __STDC__ 194 1.1 christos #ifdef __STDC_VERSION__ 195 1.7 christos #if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ 196 1.1 christos #define CP_DYNAMIC_ARRAYS 197 1.7 christos #endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */ 198 1.1 christos #endif /* defined (__STDC_VERSION__) */ 199 1.1 christos #endif /* defined (__STDC__) */ 200 1.1 christos #endif /* ! defined (__GNUC__) */ 201 1.1 christos 202 1.1 christos /* We avoid pulling in the ctype tables, to prevent pulling in 203 1.1 christos additional unresolved symbols when this code is used in a library. 204 1.1 christos FIXME: Is this really a valid reason? This comes from the original 205 1.1 christos V3 demangler code. 206 1.1 christos 207 1.1 christos As of this writing this file has the following undefined references 208 1.1 christos when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy, 209 1.1 christos strcat, strlen. */ 210 1.1 christos 211 1.1 christos #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') 212 1.1 christos #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') 213 1.1 christos #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') 214 1.1 christos 215 1.1 christos /* The prefix prepended by GCC to an identifier represnting the 216 1.1 christos anonymous namespace. */ 217 1.1 christos #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_" 218 1.1 christos #define ANONYMOUS_NAMESPACE_PREFIX_LEN \ 219 1.1 christos (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1) 220 1.1 christos 221 1.1 christos /* Information we keep for the standard substitutions. */ 222 1.1 christos 223 1.1 christos struct d_standard_sub_info 224 1.1 christos { 225 1.1 christos /* The code for this substitution. */ 226 1.1 christos char code; 227 1.1 christos /* The simple string it expands to. */ 228 1.1 christos const char *simple_expansion; 229 1.1 christos /* The length of the simple expansion. */ 230 1.1 christos int simple_len; 231 1.1 christos /* The results of a full, verbose, expansion. This is used when 232 1.1 christos qualifying a constructor/destructor, or when in verbose mode. */ 233 1.1 christos const char *full_expansion; 234 1.1 christos /* The length of the full expansion. */ 235 1.1 christos int full_len; 236 1.1 christos /* What to set the last_name field of d_info to; NULL if we should 237 1.1 christos not set it. This is only relevant when qualifying a 238 1.1 christos constructor/destructor. */ 239 1.1 christos const char *set_last_name; 240 1.1 christos /* The length of set_last_name. */ 241 1.1 christos int set_last_name_len; 242 1.1 christos }; 243 1.1 christos 244 1.1 christos /* Accessors for subtrees of struct demangle_component. */ 245 1.1 christos 246 1.1 christos #define d_left(dc) ((dc)->u.s_binary.left) 247 1.1 christos #define d_right(dc) ((dc)->u.s_binary.right) 248 1.1 christos 249 1.1 christos /* A list of templates. This is used while printing. */ 250 1.1 christos 251 1.1 christos struct d_print_template 252 1.1 christos { 253 1.1 christos /* Next template on the list. */ 254 1.1 christos struct d_print_template *next; 255 1.1 christos /* This template. */ 256 1.1 christos const struct demangle_component *template_decl; 257 1.1 christos }; 258 1.1 christos 259 1.1 christos /* A list of type modifiers. This is used while printing. */ 260 1.1 christos 261 1.1 christos struct d_print_mod 262 1.1 christos { 263 1.1 christos /* Next modifier on the list. These are in the reverse of the order 264 1.1 christos in which they appeared in the mangled string. */ 265 1.1 christos struct d_print_mod *next; 266 1.1 christos /* The modifier. */ 267 1.6 christos struct demangle_component *mod; 268 1.1 christos /* Whether this modifier was printed. */ 269 1.1 christos int printed; 270 1.1 christos /* The list of templates which applies to this modifier. */ 271 1.1 christos struct d_print_template *templates; 272 1.1 christos }; 273 1.1 christos 274 1.1 christos /* We use these structures to hold information during printing. */ 275 1.1 christos 276 1.1 christos struct d_growable_string 277 1.1 christos { 278 1.1 christos /* Buffer holding the result. */ 279 1.1 christos char *buf; 280 1.1 christos /* Current length of data in buffer. */ 281 1.1 christos size_t len; 282 1.1 christos /* Allocated size of buffer. */ 283 1.1 christos size_t alc; 284 1.1 christos /* Set to 1 if we had a memory allocation failure. */ 285 1.1 christos int allocation_failure; 286 1.1 christos }; 287 1.1 christos 288 1.3 christos /* Stack of components, innermost first, used to avoid loops. */ 289 1.3 christos 290 1.3 christos struct d_component_stack 291 1.3 christos { 292 1.3 christos /* This component. */ 293 1.3 christos const struct demangle_component *dc; 294 1.3 christos /* This component's parent. */ 295 1.3 christos const struct d_component_stack *parent; 296 1.3 christos }; 297 1.3 christos 298 1.3 christos /* A demangle component and some scope captured when it was first 299 1.3 christos traversed. */ 300 1.3 christos 301 1.3 christos struct d_saved_scope 302 1.3 christos { 303 1.3 christos /* The component whose scope this is. */ 304 1.3 christos const struct demangle_component *container; 305 1.3 christos /* The list of templates, if any, that was current when this 306 1.3 christos scope was captured. */ 307 1.3 christos struct d_print_template *templates; 308 1.3 christos }; 309 1.3 christos 310 1.3 christos /* Checkpoint structure to allow backtracking. This holds copies 311 1.3 christos of the fields of struct d_info that need to be restored 312 1.3 christos if a trial parse needs to be backtracked over. */ 313 1.3 christos 314 1.3 christos struct d_info_checkpoint 315 1.3 christos { 316 1.3 christos const char *n; 317 1.3 christos int next_comp; 318 1.3 christos int next_sub; 319 1.3 christos int expansion; 320 1.3 christos }; 321 1.3 christos 322 1.6 christos /* Maximum number of times d_print_comp may be called recursively. */ 323 1.6 christos #define MAX_RECURSION_COUNT 1024 324 1.6 christos 325 1.1 christos enum { D_PRINT_BUFFER_LENGTH = 256 }; 326 1.1 christos struct d_print_info 327 1.1 christos { 328 1.1 christos /* Fixed-length allocated buffer for demangled data, flushed to the 329 1.1 christos callback with a NUL termination once full. */ 330 1.1 christos char buf[D_PRINT_BUFFER_LENGTH]; 331 1.1 christos /* Current length of data in buffer. */ 332 1.1 christos size_t len; 333 1.1 christos /* The last character printed, saved individually so that it survives 334 1.1 christos any buffer flush. */ 335 1.1 christos char last_char; 336 1.1 christos /* Callback function to handle demangled buffer flush. */ 337 1.1 christos demangle_callbackref callback; 338 1.1 christos /* Opaque callback argument. */ 339 1.1 christos void *opaque; 340 1.1 christos /* The current list of templates, if any. */ 341 1.1 christos struct d_print_template *templates; 342 1.1 christos /* The current list of modifiers (e.g., pointer, reference, etc.), 343 1.1 christos if any. */ 344 1.1 christos struct d_print_mod *modifiers; 345 1.1 christos /* Set to 1 if we saw a demangling error. */ 346 1.1 christos int demangle_failure; 347 1.6 christos /* Number of times d_print_comp was recursively called. Should not 348 1.6 christos be bigger than MAX_RECURSION_COUNT. */ 349 1.6 christos int recursion; 350 1.9 christos /* 1 more than the number of explicit template parms of a lambda. Template 351 1.9 christos parm references >= are actually 'auto'. */ 352 1.9 christos int lambda_tpl_parms; 353 1.1 christos /* The current index into any template argument packs we are using 354 1.6 christos for printing, or -1 to print the whole pack. */ 355 1.1 christos int pack_index; 356 1.1 christos /* Number of d_print_flush calls so far. */ 357 1.1 christos unsigned long int flush_count; 358 1.3 christos /* Stack of components, innermost first, used to avoid loops. */ 359 1.3 christos const struct d_component_stack *component_stack; 360 1.3 christos /* Array of saved scopes for evaluating substitutions. */ 361 1.3 christos struct d_saved_scope *saved_scopes; 362 1.3 christos /* Index of the next unused saved scope in the above array. */ 363 1.3 christos int next_saved_scope; 364 1.3 christos /* Number of saved scopes in the above array. */ 365 1.3 christos int num_saved_scopes; 366 1.3 christos /* Array of templates for saving into scopes. */ 367 1.3 christos struct d_print_template *copy_templates; 368 1.3 christos /* Index of the next unused copy template in the above array. */ 369 1.3 christos int next_copy_template; 370 1.3 christos /* Number of copy templates in the above array. */ 371 1.3 christos int num_copy_templates; 372 1.3 christos /* The nearest enclosing template, if any. */ 373 1.3 christos const struct demangle_component *current_template; 374 1.1 christos }; 375 1.1 christos 376 1.1 christos #ifdef CP_DEMANGLE_DEBUG 377 1.1 christos static void d_dump (struct demangle_component *, int); 378 1.1 christos #endif 379 1.1 christos 380 1.1 christos static struct demangle_component * 381 1.1 christos d_make_empty (struct d_info *); 382 1.1 christos 383 1.1 christos static struct demangle_component * 384 1.1 christos d_make_comp (struct d_info *, enum demangle_component_type, 385 1.1 christos struct demangle_component *, 386 1.1 christos struct demangle_component *); 387 1.1 christos 388 1.1 christos static struct demangle_component * 389 1.1 christos d_make_name (struct d_info *, const char *, int); 390 1.1 christos 391 1.1 christos static struct demangle_component * 392 1.1 christos d_make_demangle_mangled_name (struct d_info *, const char *); 393 1.1 christos 394 1.1 christos static struct demangle_component * 395 1.1 christos d_make_builtin_type (struct d_info *, 396 1.1 christos const struct demangle_builtin_type_info *); 397 1.1 christos 398 1.1 christos static struct demangle_component * 399 1.1 christos d_make_operator (struct d_info *, 400 1.1 christos const struct demangle_operator_info *); 401 1.1 christos 402 1.1 christos static struct demangle_component * 403 1.1 christos d_make_extended_operator (struct d_info *, int, 404 1.1 christos struct demangle_component *); 405 1.1 christos 406 1.1 christos static struct demangle_component * 407 1.1 christos d_make_ctor (struct d_info *, enum gnu_v3_ctor_kinds, 408 1.1 christos struct demangle_component *); 409 1.1 christos 410 1.1 christos static struct demangle_component * 411 1.1 christos d_make_dtor (struct d_info *, enum gnu_v3_dtor_kinds, 412 1.1 christos struct demangle_component *); 413 1.1 christos 414 1.1 christos static struct demangle_component * 415 1.6 christos d_make_template_param (struct d_info *, int); 416 1.1 christos 417 1.1 christos static struct demangle_component * 418 1.1 christos d_make_sub (struct d_info *, const char *, int); 419 1.1 christos 420 1.1 christos static int 421 1.1 christos has_return_type (struct demangle_component *); 422 1.1 christos 423 1.1 christos static int 424 1.1 christos is_ctor_dtor_or_conversion (struct demangle_component *); 425 1.1 christos 426 1.1 christos static struct demangle_component *d_encoding (struct d_info *, int); 427 1.1 christos 428 1.8 christos static struct demangle_component *d_name (struct d_info *, int substable); 429 1.1 christos 430 1.1 christos static struct demangle_component *d_nested_name (struct d_info *); 431 1.1 christos 432 1.8 christos static int d_maybe_module_name (struct d_info *, struct demangle_component **); 433 1.1 christos 434 1.8 christos static struct demangle_component *d_prefix (struct d_info *, int); 435 1.8 christos 436 1.8 christos static struct demangle_component *d_unqualified_name (struct d_info *, 437 1.8 christos struct demangle_component *scope, struct demangle_component *module); 438 1.1 christos 439 1.1 christos static struct demangle_component *d_source_name (struct d_info *); 440 1.1 christos 441 1.6 christos static int d_number (struct d_info *); 442 1.1 christos 443 1.6 christos static struct demangle_component *d_identifier (struct d_info *, int); 444 1.1 christos 445 1.1 christos static struct demangle_component *d_operator_name (struct d_info *); 446 1.1 christos 447 1.1 christos static struct demangle_component *d_special_name (struct d_info *); 448 1.1 christos 449 1.6 christos static struct demangle_component *d_parmlist (struct d_info *); 450 1.6 christos 451 1.1 christos static int d_call_offset (struct d_info *, int); 452 1.1 christos 453 1.1 christos static struct demangle_component *d_ctor_dtor_name (struct d_info *); 454 1.1 christos 455 1.1 christos static struct demangle_component ** 456 1.1 christos d_cv_qualifiers (struct d_info *, struct demangle_component **, int); 457 1.1 christos 458 1.1 christos static struct demangle_component * 459 1.3 christos d_ref_qualifier (struct d_info *, struct demangle_component *); 460 1.3 christos 461 1.3 christos static struct demangle_component * 462 1.1 christos d_function_type (struct d_info *); 463 1.1 christos 464 1.1 christos static struct demangle_component * 465 1.1 christos d_bare_function_type (struct d_info *, int); 466 1.1 christos 467 1.1 christos static struct demangle_component * 468 1.8 christos d_class_enum_type (struct d_info *, int); 469 1.1 christos 470 1.1 christos static struct demangle_component *d_array_type (struct d_info *); 471 1.1 christos 472 1.1 christos static struct demangle_component *d_vector_type (struct d_info *); 473 1.1 christos 474 1.1 christos static struct demangle_component * 475 1.1 christos d_pointer_to_member_type (struct d_info *); 476 1.1 christos 477 1.1 christos static struct demangle_component * 478 1.1 christos d_template_param (struct d_info *); 479 1.1 christos 480 1.1 christos static struct demangle_component *d_template_args (struct d_info *); 481 1.6 christos static struct demangle_component *d_template_args_1 (struct d_info *); 482 1.1 christos 483 1.1 christos static struct demangle_component * 484 1.1 christos d_template_arg (struct d_info *); 485 1.1 christos 486 1.1 christos static struct demangle_component *d_expression (struct d_info *); 487 1.1 christos 488 1.1 christos static struct demangle_component *d_expr_primary (struct d_info *); 489 1.1 christos 490 1.1 christos static struct demangle_component *d_local_name (struct d_info *); 491 1.1 christos 492 1.1 christos static int d_discriminator (struct d_info *); 493 1.1 christos 494 1.9 christos static struct demangle_component *d_template_parm (struct d_info *, int *bad); 495 1.9 christos 496 1.9 christos static struct demangle_component *d_template_head (struct d_info *, int *bad); 497 1.9 christos 498 1.1 christos static struct demangle_component *d_lambda (struct d_info *); 499 1.1 christos 500 1.1 christos static struct demangle_component *d_unnamed_type (struct d_info *); 501 1.1 christos 502 1.1 christos static struct demangle_component * 503 1.1 christos d_clone_suffix (struct d_info *, struct demangle_component *); 504 1.1 christos 505 1.1 christos static int 506 1.1 christos d_add_substitution (struct d_info *, struct demangle_component *); 507 1.1 christos 508 1.1 christos static struct demangle_component *d_substitution (struct d_info *, int); 509 1.1 christos 510 1.3 christos static void d_checkpoint (struct d_info *, struct d_info_checkpoint *); 511 1.3 christos 512 1.3 christos static void d_backtrack (struct d_info *, struct d_info_checkpoint *); 513 1.3 christos 514 1.1 christos static void d_growable_string_init (struct d_growable_string *, size_t); 515 1.1 christos 516 1.1 christos static inline void 517 1.1 christos d_growable_string_resize (struct d_growable_string *, size_t); 518 1.1 christos 519 1.1 christos static inline void 520 1.1 christos d_growable_string_append_buffer (struct d_growable_string *, 521 1.1 christos const char *, size_t); 522 1.1 christos static void 523 1.1 christos d_growable_string_callback_adapter (const char *, size_t, void *); 524 1.1 christos 525 1.1 christos static void 526 1.3 christos d_print_init (struct d_print_info *, demangle_callbackref, void *, 527 1.7 christos struct demangle_component *); 528 1.1 christos 529 1.1 christos static inline void d_print_error (struct d_print_info *); 530 1.1 christos 531 1.1 christos static inline int d_print_saw_error (struct d_print_info *); 532 1.1 christos 533 1.1 christos static inline void d_print_flush (struct d_print_info *); 534 1.1 christos 535 1.1 christos static inline void d_append_char (struct d_print_info *, char); 536 1.1 christos 537 1.1 christos static inline void d_append_buffer (struct d_print_info *, 538 1.1 christos const char *, size_t); 539 1.1 christos 540 1.1 christos static inline void d_append_string (struct d_print_info *, const char *); 541 1.1 christos 542 1.1 christos static inline char d_last_char (struct d_print_info *); 543 1.1 christos 544 1.1 christos static void 545 1.6 christos d_print_comp (struct d_print_info *, int, struct demangle_component *); 546 1.1 christos 547 1.1 christos static void 548 1.1 christos d_print_java_identifier (struct d_print_info *, const char *, int); 549 1.1 christos 550 1.1 christos static void 551 1.1 christos d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int); 552 1.1 christos 553 1.1 christos static void 554 1.6 christos d_print_mod (struct d_print_info *, int, struct demangle_component *); 555 1.1 christos 556 1.1 christos static void 557 1.1 christos d_print_function_type (struct d_print_info *, int, 558 1.6 christos struct demangle_component *, 559 1.1 christos struct d_print_mod *); 560 1.1 christos 561 1.1 christos static void 562 1.1 christos d_print_array_type (struct d_print_info *, int, 563 1.6 christos struct demangle_component *, 564 1.1 christos struct d_print_mod *); 565 1.1 christos 566 1.1 christos static void 567 1.6 christos d_print_expr_op (struct d_print_info *, int, struct demangle_component *); 568 1.1 christos 569 1.5 christos static void d_print_cast (struct d_print_info *, int, 570 1.6 christos struct demangle_component *); 571 1.5 christos static void d_print_conversion (struct d_print_info *, int, 572 1.6 christos struct demangle_component *); 573 1.1 christos 574 1.1 christos static int d_demangle_callback (const char *, int, 575 1.1 christos demangle_callbackref, void *); 576 1.1 christos static char *d_demangle (const char *, int, size_t *); 577 1.1 christos 578 1.6 christos #define FNQUAL_COMPONENT_CASE \ 579 1.6 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: \ 580 1.6 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: \ 581 1.6 christos case DEMANGLE_COMPONENT_CONST_THIS: \ 582 1.6 christos case DEMANGLE_COMPONENT_REFERENCE_THIS: \ 583 1.6 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \ 584 1.9 christos case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: \ 585 1.6 christos case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \ 586 1.6 christos case DEMANGLE_COMPONENT_NOEXCEPT: \ 587 1.6 christos case DEMANGLE_COMPONENT_THROW_SPEC 588 1.6 christos 589 1.6 christos /* True iff TYPE is a demangling component representing a 590 1.6 christos function-type-qualifier. */ 591 1.6 christos 592 1.6 christos static int 593 1.6 christos is_fnqual_component_type (enum demangle_component_type type) 594 1.6 christos { 595 1.6 christos switch (type) 596 1.6 christos { 597 1.6 christos FNQUAL_COMPONENT_CASE: 598 1.6 christos return 1; 599 1.6 christos default: 600 1.6 christos break; 601 1.6 christos } 602 1.6 christos return 0; 603 1.6 christos } 604 1.6 christos 605 1.6 christos 606 1.1 christos #ifdef CP_DEMANGLE_DEBUG 607 1.1 christos 608 1.1 christos static void 609 1.1 christos d_dump (struct demangle_component *dc, int indent) 610 1.1 christos { 611 1.1 christos int i; 612 1.1 christos 613 1.1 christos if (dc == NULL) 614 1.1 christos { 615 1.1 christos if (indent == 0) 616 1.1 christos printf ("failed demangling\n"); 617 1.1 christos return; 618 1.1 christos } 619 1.1 christos 620 1.1 christos for (i = 0; i < indent; ++i) 621 1.1 christos putchar (' '); 622 1.1 christos 623 1.1 christos switch (dc->type) 624 1.1 christos { 625 1.1 christos case DEMANGLE_COMPONENT_NAME: 626 1.1 christos printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s); 627 1.1 christos return; 628 1.3 christos case DEMANGLE_COMPONENT_TAGGED_NAME: 629 1.3 christos printf ("tagged name\n"); 630 1.3 christos d_dump (dc->u.s_binary.left, indent + 2); 631 1.3 christos d_dump (dc->u.s_binary.right, indent + 2); 632 1.3 christos return; 633 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 634 1.1 christos printf ("template parameter %ld\n", dc->u.s_number.number); 635 1.1 christos return; 636 1.7 christos case DEMANGLE_COMPONENT_TPARM_OBJ: 637 1.7 christos printf ("template parameter object\n"); 638 1.7 christos break; 639 1.3 christos case DEMANGLE_COMPONENT_FUNCTION_PARAM: 640 1.3 christos printf ("function parameter %ld\n", dc->u.s_number.number); 641 1.3 christos return; 642 1.1 christos case DEMANGLE_COMPONENT_CTOR: 643 1.1 christos printf ("constructor %d\n", (int) dc->u.s_ctor.kind); 644 1.1 christos d_dump (dc->u.s_ctor.name, indent + 2); 645 1.1 christos return; 646 1.1 christos case DEMANGLE_COMPONENT_DTOR: 647 1.1 christos printf ("destructor %d\n", (int) dc->u.s_dtor.kind); 648 1.1 christos d_dump (dc->u.s_dtor.name, indent + 2); 649 1.1 christos return; 650 1.1 christos case DEMANGLE_COMPONENT_SUB_STD: 651 1.1 christos printf ("standard substitution %s\n", dc->u.s_string.string); 652 1.1 christos return; 653 1.1 christos case DEMANGLE_COMPONENT_BUILTIN_TYPE: 654 1.1 christos printf ("builtin type %s\n", dc->u.s_builtin.type->name); 655 1.1 christos return; 656 1.9 christos case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE: 657 1.9 christos { 658 1.10 christos char suffix[2] = { dc->u.s_extended_builtin.suffix, 0 }; 659 1.9 christos printf ("builtin type %s%d%s\n", dc->u.s_extended_builtin.type->name, 660 1.10 christos dc->u.s_extended_builtin.arg, suffix); 661 1.9 christos } 662 1.9 christos return; 663 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 664 1.1 christos printf ("operator %s\n", dc->u.s_operator.op->name); 665 1.1 christos return; 666 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 667 1.1 christos printf ("extended operator with %d args\n", 668 1.1 christos dc->u.s_extended_operator.args); 669 1.1 christos d_dump (dc->u.s_extended_operator.name, indent + 2); 670 1.1 christos return; 671 1.1 christos 672 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 673 1.1 christos printf ("qualified name\n"); 674 1.1 christos break; 675 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 676 1.1 christos printf ("local name\n"); 677 1.1 christos break; 678 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 679 1.1 christos printf ("typed name\n"); 680 1.1 christos break; 681 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 682 1.1 christos printf ("template\n"); 683 1.1 christos break; 684 1.1 christos case DEMANGLE_COMPONENT_VTABLE: 685 1.1 christos printf ("vtable\n"); 686 1.1 christos break; 687 1.1 christos case DEMANGLE_COMPONENT_VTT: 688 1.1 christos printf ("VTT\n"); 689 1.1 christos break; 690 1.1 christos case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE: 691 1.1 christos printf ("construction vtable\n"); 692 1.1 christos break; 693 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO: 694 1.1 christos printf ("typeinfo\n"); 695 1.1 christos break; 696 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_NAME: 697 1.1 christos printf ("typeinfo name\n"); 698 1.1 christos break; 699 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_FN: 700 1.1 christos printf ("typeinfo function\n"); 701 1.1 christos break; 702 1.1 christos case DEMANGLE_COMPONENT_THUNK: 703 1.1 christos printf ("thunk\n"); 704 1.1 christos break; 705 1.1 christos case DEMANGLE_COMPONENT_VIRTUAL_THUNK: 706 1.1 christos printf ("virtual thunk\n"); 707 1.1 christos break; 708 1.1 christos case DEMANGLE_COMPONENT_COVARIANT_THUNK: 709 1.1 christos printf ("covariant thunk\n"); 710 1.1 christos break; 711 1.1 christos case DEMANGLE_COMPONENT_JAVA_CLASS: 712 1.1 christos printf ("java class\n"); 713 1.1 christos break; 714 1.1 christos case DEMANGLE_COMPONENT_GUARD: 715 1.1 christos printf ("guard\n"); 716 1.1 christos break; 717 1.1 christos case DEMANGLE_COMPONENT_REFTEMP: 718 1.1 christos printf ("reference temporary\n"); 719 1.1 christos break; 720 1.1 christos case DEMANGLE_COMPONENT_HIDDEN_ALIAS: 721 1.1 christos printf ("hidden alias\n"); 722 1.1 christos break; 723 1.1 christos case DEMANGLE_COMPONENT_TRANSACTION_CLONE: 724 1.1 christos printf ("transaction clone\n"); 725 1.1 christos break; 726 1.1 christos case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: 727 1.1 christos printf ("non-transaction clone\n"); 728 1.1 christos break; 729 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 730 1.1 christos printf ("restrict\n"); 731 1.1 christos break; 732 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 733 1.1 christos printf ("volatile\n"); 734 1.1 christos break; 735 1.1 christos case DEMANGLE_COMPONENT_CONST: 736 1.1 christos printf ("const\n"); 737 1.1 christos break; 738 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 739 1.1 christos printf ("restrict this\n"); 740 1.1 christos break; 741 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 742 1.1 christos printf ("volatile this\n"); 743 1.1 christos break; 744 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 745 1.1 christos printf ("const this\n"); 746 1.1 christos break; 747 1.3 christos case DEMANGLE_COMPONENT_REFERENCE_THIS: 748 1.3 christos printf ("reference this\n"); 749 1.3 christos break; 750 1.3 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: 751 1.3 christos printf ("rvalue reference this\n"); 752 1.3 christos break; 753 1.9 christos case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: 754 1.9 christos printf ("explicit object parameter\n"); 755 1.9 christos break; 756 1.5 christos case DEMANGLE_COMPONENT_TRANSACTION_SAFE: 757 1.5 christos printf ("transaction_safe this\n"); 758 1.5 christos break; 759 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 760 1.1 christos printf ("vendor type qualifier\n"); 761 1.1 christos break; 762 1.1 christos case DEMANGLE_COMPONENT_POINTER: 763 1.1 christos printf ("pointer\n"); 764 1.1 christos break; 765 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 766 1.1 christos printf ("reference\n"); 767 1.1 christos break; 768 1.1 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 769 1.1 christos printf ("rvalue reference\n"); 770 1.1 christos break; 771 1.1 christos case DEMANGLE_COMPONENT_COMPLEX: 772 1.1 christos printf ("complex\n"); 773 1.1 christos break; 774 1.1 christos case DEMANGLE_COMPONENT_IMAGINARY: 775 1.1 christos printf ("imaginary\n"); 776 1.1 christos break; 777 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE: 778 1.1 christos printf ("vendor type\n"); 779 1.1 christos break; 780 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_TYPE: 781 1.1 christos printf ("function type\n"); 782 1.1 christos break; 783 1.1 christos case DEMANGLE_COMPONENT_ARRAY_TYPE: 784 1.1 christos printf ("array type\n"); 785 1.1 christos break; 786 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 787 1.1 christos printf ("pointer to member type\n"); 788 1.1 christos break; 789 1.1 christos case DEMANGLE_COMPONENT_ARGLIST: 790 1.1 christos printf ("argument list\n"); 791 1.1 christos break; 792 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: 793 1.1 christos printf ("template argument list\n"); 794 1.1 christos break; 795 1.1 christos case DEMANGLE_COMPONENT_INITIALIZER_LIST: 796 1.1 christos printf ("initializer list\n"); 797 1.1 christos break; 798 1.1 christos case DEMANGLE_COMPONENT_CAST: 799 1.1 christos printf ("cast\n"); 800 1.1 christos break; 801 1.5 christos case DEMANGLE_COMPONENT_CONVERSION: 802 1.5 christos printf ("conversion operator\n"); 803 1.5 christos break; 804 1.1 christos case DEMANGLE_COMPONENT_NULLARY: 805 1.1 christos printf ("nullary operator\n"); 806 1.1 christos break; 807 1.1 christos case DEMANGLE_COMPONENT_UNARY: 808 1.1 christos printf ("unary operator\n"); 809 1.1 christos break; 810 1.1 christos case DEMANGLE_COMPONENT_BINARY: 811 1.1 christos printf ("binary operator\n"); 812 1.1 christos break; 813 1.1 christos case DEMANGLE_COMPONENT_BINARY_ARGS: 814 1.1 christos printf ("binary operator arguments\n"); 815 1.1 christos break; 816 1.1 christos case DEMANGLE_COMPONENT_TRINARY: 817 1.1 christos printf ("trinary operator\n"); 818 1.1 christos break; 819 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG1: 820 1.1 christos printf ("trinary operator arguments 1\n"); 821 1.1 christos break; 822 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG2: 823 1.1 christos printf ("trinary operator arguments 1\n"); 824 1.1 christos break; 825 1.1 christos case DEMANGLE_COMPONENT_LITERAL: 826 1.1 christos printf ("literal\n"); 827 1.1 christos break; 828 1.1 christos case DEMANGLE_COMPONENT_LITERAL_NEG: 829 1.1 christos printf ("negative literal\n"); 830 1.1 christos break; 831 1.8 christos case DEMANGLE_COMPONENT_VENDOR_EXPR: 832 1.8 christos printf ("vendor expression\n"); 833 1.8 christos break; 834 1.1 christos case DEMANGLE_COMPONENT_JAVA_RESOURCE: 835 1.1 christos printf ("java resource\n"); 836 1.1 christos break; 837 1.1 christos case DEMANGLE_COMPONENT_COMPOUND_NAME: 838 1.1 christos printf ("compound name\n"); 839 1.1 christos break; 840 1.1 christos case DEMANGLE_COMPONENT_CHARACTER: 841 1.1 christos printf ("character '%c'\n", dc->u.s_character.character); 842 1.1 christos return; 843 1.3 christos case DEMANGLE_COMPONENT_NUMBER: 844 1.3 christos printf ("number %ld\n", dc->u.s_number.number); 845 1.3 christos return; 846 1.1 christos case DEMANGLE_COMPONENT_DECLTYPE: 847 1.1 christos printf ("decltype\n"); 848 1.1 christos break; 849 1.1 christos case DEMANGLE_COMPONENT_PACK_EXPANSION: 850 1.1 christos printf ("pack expansion\n"); 851 1.1 christos break; 852 1.3 christos case DEMANGLE_COMPONENT_TLS_INIT: 853 1.3 christos printf ("tls init function\n"); 854 1.3 christos break; 855 1.3 christos case DEMANGLE_COMPONENT_TLS_WRAPPER: 856 1.3 christos printf ("tls wrapper function\n"); 857 1.3 christos break; 858 1.3 christos case DEMANGLE_COMPONENT_DEFAULT_ARG: 859 1.3 christos printf ("default argument %d\n", dc->u.s_unary_num.num); 860 1.3 christos d_dump (dc->u.s_unary_num.sub, indent+2); 861 1.3 christos return; 862 1.3 christos case DEMANGLE_COMPONENT_LAMBDA: 863 1.3 christos printf ("lambda %d\n", dc->u.s_unary_num.num); 864 1.3 christos d_dump (dc->u.s_unary_num.sub, indent+2); 865 1.3 christos return; 866 1.1 christos } 867 1.1 christos 868 1.1 christos d_dump (d_left (dc), indent + 2); 869 1.1 christos d_dump (d_right (dc), indent + 2); 870 1.1 christos } 871 1.1 christos 872 1.1 christos #endif /* CP_DEMANGLE_DEBUG */ 873 1.1 christos 874 1.1 christos /* Fill in a DEMANGLE_COMPONENT_NAME. */ 875 1.1 christos 876 1.1 christos CP_STATIC_IF_GLIBCPP_V3 877 1.1 christos int 878 1.1 christos cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len) 879 1.1 christos { 880 1.7 christos if (p == NULL || s == NULL || len <= 0) 881 1.1 christos return 0; 882 1.6 christos p->d_printing = 0; 883 1.7 christos p->d_counting = 0; 884 1.1 christos p->type = DEMANGLE_COMPONENT_NAME; 885 1.1 christos p->u.s_name.s = s; 886 1.1 christos p->u.s_name.len = len; 887 1.1 christos return 1; 888 1.1 christos } 889 1.1 christos 890 1.1 christos /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */ 891 1.1 christos 892 1.1 christos CP_STATIC_IF_GLIBCPP_V3 893 1.1 christos int 894 1.1 christos cplus_demangle_fill_extended_operator (struct demangle_component *p, int args, 895 1.1 christos struct demangle_component *name) 896 1.1 christos { 897 1.1 christos if (p == NULL || args < 0 || name == NULL) 898 1.1 christos return 0; 899 1.6 christos p->d_printing = 0; 900 1.7 christos p->d_counting = 0; 901 1.1 christos p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR; 902 1.1 christos p->u.s_extended_operator.args = args; 903 1.1 christos p->u.s_extended_operator.name = name; 904 1.1 christos return 1; 905 1.1 christos } 906 1.1 christos 907 1.1 christos /* Fill in a DEMANGLE_COMPONENT_CTOR. */ 908 1.1 christos 909 1.1 christos CP_STATIC_IF_GLIBCPP_V3 910 1.1 christos int 911 1.1 christos cplus_demangle_fill_ctor (struct demangle_component *p, 912 1.1 christos enum gnu_v3_ctor_kinds kind, 913 1.1 christos struct demangle_component *name) 914 1.1 christos { 915 1.1 christos if (p == NULL 916 1.1 christos || name == NULL 917 1.1 christos || (int) kind < gnu_v3_complete_object_ctor 918 1.1 christos || (int) kind > gnu_v3_object_ctor_group) 919 1.1 christos return 0; 920 1.6 christos p->d_printing = 0; 921 1.7 christos p->d_counting = 0; 922 1.1 christos p->type = DEMANGLE_COMPONENT_CTOR; 923 1.1 christos p->u.s_ctor.kind = kind; 924 1.1 christos p->u.s_ctor.name = name; 925 1.1 christos return 1; 926 1.1 christos } 927 1.1 christos 928 1.1 christos /* Fill in a DEMANGLE_COMPONENT_DTOR. */ 929 1.1 christos 930 1.1 christos CP_STATIC_IF_GLIBCPP_V3 931 1.1 christos int 932 1.1 christos cplus_demangle_fill_dtor (struct demangle_component *p, 933 1.1 christos enum gnu_v3_dtor_kinds kind, 934 1.1 christos struct demangle_component *name) 935 1.1 christos { 936 1.1 christos if (p == NULL 937 1.1 christos || name == NULL 938 1.1 christos || (int) kind < gnu_v3_deleting_dtor 939 1.1 christos || (int) kind > gnu_v3_object_dtor_group) 940 1.1 christos return 0; 941 1.6 christos p->d_printing = 0; 942 1.7 christos p->d_counting = 0; 943 1.1 christos p->type = DEMANGLE_COMPONENT_DTOR; 944 1.1 christos p->u.s_dtor.kind = kind; 945 1.1 christos p->u.s_dtor.name = name; 946 1.1 christos return 1; 947 1.1 christos } 948 1.1 christos 949 1.1 christos /* Add a new component. */ 950 1.1 christos 951 1.1 christos static struct demangle_component * 952 1.1 christos d_make_empty (struct d_info *di) 953 1.1 christos { 954 1.1 christos struct demangle_component *p; 955 1.1 christos 956 1.1 christos if (di->next_comp >= di->num_comps) 957 1.1 christos return NULL; 958 1.1 christos p = &di->comps[di->next_comp]; 959 1.6 christos p->d_printing = 0; 960 1.7 christos p->d_counting = 0; 961 1.1 christos ++di->next_comp; 962 1.1 christos return p; 963 1.1 christos } 964 1.1 christos 965 1.1 christos /* Add a new generic component. */ 966 1.1 christos 967 1.1 christos static struct demangle_component * 968 1.1 christos d_make_comp (struct d_info *di, enum demangle_component_type type, 969 1.1 christos struct demangle_component *left, 970 1.1 christos struct demangle_component *right) 971 1.1 christos { 972 1.1 christos struct demangle_component *p; 973 1.1 christos 974 1.1 christos /* We check for errors here. A typical error would be a NULL return 975 1.1 christos from a subroutine. We catch those here, and return NULL 976 1.1 christos upward. */ 977 1.1 christos switch (type) 978 1.1 christos { 979 1.1 christos /* These types require two parameters. */ 980 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 981 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 982 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 983 1.3 christos case DEMANGLE_COMPONENT_TAGGED_NAME: 984 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 985 1.1 christos case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE: 986 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 987 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 988 1.1 christos case DEMANGLE_COMPONENT_UNARY: 989 1.1 christos case DEMANGLE_COMPONENT_BINARY: 990 1.1 christos case DEMANGLE_COMPONENT_BINARY_ARGS: 991 1.1 christos case DEMANGLE_COMPONENT_TRINARY: 992 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG1: 993 1.1 christos case DEMANGLE_COMPONENT_LITERAL: 994 1.1 christos case DEMANGLE_COMPONENT_LITERAL_NEG: 995 1.8 christos case DEMANGLE_COMPONENT_VENDOR_EXPR: 996 1.1 christos case DEMANGLE_COMPONENT_COMPOUND_NAME: 997 1.1 christos case DEMANGLE_COMPONENT_VECTOR_TYPE: 998 1.1 christos case DEMANGLE_COMPONENT_CLONE: 999 1.8 christos case DEMANGLE_COMPONENT_MODULE_ENTITY: 1000 1.9 christos case DEMANGLE_COMPONENT_CONSTRAINTS: 1001 1.1 christos if (left == NULL || right == NULL) 1002 1.1 christos return NULL; 1003 1.1 christos break; 1004 1.1 christos 1005 1.1 christos /* These types only require one parameter. */ 1006 1.1 christos case DEMANGLE_COMPONENT_VTABLE: 1007 1.1 christos case DEMANGLE_COMPONENT_VTT: 1008 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO: 1009 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_NAME: 1010 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_FN: 1011 1.1 christos case DEMANGLE_COMPONENT_THUNK: 1012 1.1 christos case DEMANGLE_COMPONENT_VIRTUAL_THUNK: 1013 1.1 christos case DEMANGLE_COMPONENT_COVARIANT_THUNK: 1014 1.1 christos case DEMANGLE_COMPONENT_JAVA_CLASS: 1015 1.1 christos case DEMANGLE_COMPONENT_GUARD: 1016 1.3 christos case DEMANGLE_COMPONENT_TLS_INIT: 1017 1.3 christos case DEMANGLE_COMPONENT_TLS_WRAPPER: 1018 1.1 christos case DEMANGLE_COMPONENT_REFTEMP: 1019 1.1 christos case DEMANGLE_COMPONENT_HIDDEN_ALIAS: 1020 1.1 christos case DEMANGLE_COMPONENT_TRANSACTION_CLONE: 1021 1.1 christos case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: 1022 1.1 christos case DEMANGLE_COMPONENT_POINTER: 1023 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 1024 1.1 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 1025 1.1 christos case DEMANGLE_COMPONENT_COMPLEX: 1026 1.1 christos case DEMANGLE_COMPONENT_IMAGINARY: 1027 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE: 1028 1.1 christos case DEMANGLE_COMPONENT_CAST: 1029 1.5 christos case DEMANGLE_COMPONENT_CONVERSION: 1030 1.1 christos case DEMANGLE_COMPONENT_JAVA_RESOURCE: 1031 1.1 christos case DEMANGLE_COMPONENT_DECLTYPE: 1032 1.1 christos case DEMANGLE_COMPONENT_PACK_EXPANSION: 1033 1.1 christos case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS: 1034 1.1 christos case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS: 1035 1.1 christos case DEMANGLE_COMPONENT_NULLARY: 1036 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG2: 1037 1.7 christos case DEMANGLE_COMPONENT_TPARM_OBJ: 1038 1.8 christos case DEMANGLE_COMPONENT_STRUCTURED_BINDING: 1039 1.8 christos case DEMANGLE_COMPONENT_MODULE_INIT: 1040 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_HEAD: 1041 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM: 1042 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM: 1043 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM: 1044 1.9 christos case DEMANGLE_COMPONENT_FRIEND: 1045 1.1 christos if (left == NULL) 1046 1.1 christos return NULL; 1047 1.1 christos break; 1048 1.1 christos 1049 1.1 christos /* This needs a right parameter, but the left parameter can be 1050 1.1 christos empty. */ 1051 1.1 christos case DEMANGLE_COMPONENT_ARRAY_TYPE: 1052 1.1 christos case DEMANGLE_COMPONENT_INITIALIZER_LIST: 1053 1.8 christos case DEMANGLE_COMPONENT_MODULE_NAME: 1054 1.8 christos case DEMANGLE_COMPONENT_MODULE_PARTITION: 1055 1.1 christos if (right == NULL) 1056 1.1 christos return NULL; 1057 1.1 christos break; 1058 1.1 christos 1059 1.1 christos /* These are allowed to have no parameters--in some cases they 1060 1.1 christos will be filled in later. */ 1061 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_TYPE: 1062 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 1063 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 1064 1.1 christos case DEMANGLE_COMPONENT_CONST: 1065 1.1 christos case DEMANGLE_COMPONENT_ARGLIST: 1066 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: 1067 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM: 1068 1.6 christos FNQUAL_COMPONENT_CASE: 1069 1.1 christos break; 1070 1.1 christos 1071 1.1 christos /* Other types should not be seen here. */ 1072 1.1 christos default: 1073 1.1 christos return NULL; 1074 1.1 christos } 1075 1.1 christos 1076 1.1 christos p = d_make_empty (di); 1077 1.1 christos if (p != NULL) 1078 1.1 christos { 1079 1.1 christos p->type = type; 1080 1.1 christos p->u.s_binary.left = left; 1081 1.1 christos p->u.s_binary.right = right; 1082 1.1 christos } 1083 1.1 christos return p; 1084 1.1 christos } 1085 1.1 christos 1086 1.1 christos /* Add a new demangle mangled name component. */ 1087 1.1 christos 1088 1.1 christos static struct demangle_component * 1089 1.1 christos d_make_demangle_mangled_name (struct d_info *di, const char *s) 1090 1.1 christos { 1091 1.1 christos if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z') 1092 1.1 christos return d_make_name (di, s, strlen (s)); 1093 1.1 christos d_advance (di, 2); 1094 1.1 christos return d_encoding (di, 0); 1095 1.1 christos } 1096 1.1 christos 1097 1.1 christos /* Add a new name component. */ 1098 1.1 christos 1099 1.1 christos static struct demangle_component * 1100 1.1 christos d_make_name (struct d_info *di, const char *s, int len) 1101 1.1 christos { 1102 1.1 christos struct demangle_component *p; 1103 1.1 christos 1104 1.1 christos p = d_make_empty (di); 1105 1.1 christos if (! cplus_demangle_fill_name (p, s, len)) 1106 1.1 christos return NULL; 1107 1.1 christos return p; 1108 1.1 christos } 1109 1.1 christos 1110 1.1 christos /* Add a new builtin type component. */ 1111 1.1 christos 1112 1.1 christos static struct demangle_component * 1113 1.1 christos d_make_builtin_type (struct d_info *di, 1114 1.1 christos const struct demangle_builtin_type_info *type) 1115 1.1 christos { 1116 1.1 christos struct demangle_component *p; 1117 1.1 christos 1118 1.1 christos if (type == NULL) 1119 1.1 christos return NULL; 1120 1.1 christos p = d_make_empty (di); 1121 1.1 christos if (p != NULL) 1122 1.1 christos { 1123 1.1 christos p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE; 1124 1.1 christos p->u.s_builtin.type = type; 1125 1.1 christos } 1126 1.1 christos return p; 1127 1.1 christos } 1128 1.1 christos 1129 1.9 christos /* Add a new extended builtin type component. */ 1130 1.9 christos 1131 1.9 christos static struct demangle_component * 1132 1.9 christos d_make_extended_builtin_type (struct d_info *di, 1133 1.9 christos const struct demangle_builtin_type_info *type, 1134 1.9 christos short arg, char suffix) 1135 1.9 christos { 1136 1.9 christos struct demangle_component *p; 1137 1.9 christos 1138 1.9 christos if (type == NULL) 1139 1.9 christos return NULL; 1140 1.9 christos p = d_make_empty (di); 1141 1.9 christos if (p != NULL) 1142 1.9 christos { 1143 1.9 christos p->type = DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE; 1144 1.9 christos p->u.s_extended_builtin.type = type; 1145 1.9 christos p->u.s_extended_builtin.arg = arg; 1146 1.9 christos p->u.s_extended_builtin.suffix = suffix; 1147 1.9 christos } 1148 1.9 christos return p; 1149 1.9 christos } 1150 1.9 christos 1151 1.1 christos /* Add a new operator component. */ 1152 1.1 christos 1153 1.1 christos static struct demangle_component * 1154 1.1 christos d_make_operator (struct d_info *di, const struct demangle_operator_info *op) 1155 1.1 christos { 1156 1.1 christos struct demangle_component *p; 1157 1.1 christos 1158 1.1 christos p = d_make_empty (di); 1159 1.1 christos if (p != NULL) 1160 1.1 christos { 1161 1.1 christos p->type = DEMANGLE_COMPONENT_OPERATOR; 1162 1.1 christos p->u.s_operator.op = op; 1163 1.1 christos } 1164 1.1 christos return p; 1165 1.1 christos } 1166 1.1 christos 1167 1.1 christos /* Add a new extended operator component. */ 1168 1.1 christos 1169 1.1 christos static struct demangle_component * 1170 1.1 christos d_make_extended_operator (struct d_info *di, int args, 1171 1.1 christos struct demangle_component *name) 1172 1.1 christos { 1173 1.1 christos struct demangle_component *p; 1174 1.1 christos 1175 1.1 christos p = d_make_empty (di); 1176 1.1 christos if (! cplus_demangle_fill_extended_operator (p, args, name)) 1177 1.1 christos return NULL; 1178 1.1 christos return p; 1179 1.1 christos } 1180 1.1 christos 1181 1.1 christos static struct demangle_component * 1182 1.1 christos d_make_default_arg (struct d_info *di, int num, 1183 1.1 christos struct demangle_component *sub) 1184 1.1 christos { 1185 1.1 christos struct demangle_component *p = d_make_empty (di); 1186 1.1 christos if (p) 1187 1.1 christos { 1188 1.1 christos p->type = DEMANGLE_COMPONENT_DEFAULT_ARG; 1189 1.1 christos p->u.s_unary_num.num = num; 1190 1.1 christos p->u.s_unary_num.sub = sub; 1191 1.1 christos } 1192 1.1 christos return p; 1193 1.1 christos } 1194 1.1 christos 1195 1.1 christos /* Add a new constructor component. */ 1196 1.1 christos 1197 1.1 christos static struct demangle_component * 1198 1.1 christos d_make_ctor (struct d_info *di, enum gnu_v3_ctor_kinds kind, 1199 1.1 christos struct demangle_component *name) 1200 1.1 christos { 1201 1.1 christos struct demangle_component *p; 1202 1.1 christos 1203 1.1 christos p = d_make_empty (di); 1204 1.1 christos if (! cplus_demangle_fill_ctor (p, kind, name)) 1205 1.1 christos return NULL; 1206 1.1 christos return p; 1207 1.1 christos } 1208 1.1 christos 1209 1.1 christos /* Add a new destructor component. */ 1210 1.1 christos 1211 1.1 christos static struct demangle_component * 1212 1.1 christos d_make_dtor (struct d_info *di, enum gnu_v3_dtor_kinds kind, 1213 1.1 christos struct demangle_component *name) 1214 1.1 christos { 1215 1.1 christos struct demangle_component *p; 1216 1.1 christos 1217 1.1 christos p = d_make_empty (di); 1218 1.1 christos if (! cplus_demangle_fill_dtor (p, kind, name)) 1219 1.1 christos return NULL; 1220 1.1 christos return p; 1221 1.1 christos } 1222 1.1 christos 1223 1.1 christos /* Add a new template parameter. */ 1224 1.1 christos 1225 1.1 christos static struct demangle_component * 1226 1.6 christos d_make_template_param (struct d_info *di, int i) 1227 1.1 christos { 1228 1.1 christos struct demangle_component *p; 1229 1.1 christos 1230 1.1 christos p = d_make_empty (di); 1231 1.1 christos if (p != NULL) 1232 1.1 christos { 1233 1.1 christos p->type = DEMANGLE_COMPONENT_TEMPLATE_PARAM; 1234 1.1 christos p->u.s_number.number = i; 1235 1.1 christos } 1236 1.1 christos return p; 1237 1.1 christos } 1238 1.1 christos 1239 1.1 christos /* Add a new function parameter. */ 1240 1.1 christos 1241 1.1 christos static struct demangle_component * 1242 1.6 christos d_make_function_param (struct d_info *di, int i) 1243 1.1 christos { 1244 1.1 christos struct demangle_component *p; 1245 1.1 christos 1246 1.1 christos p = d_make_empty (di); 1247 1.1 christos if (p != NULL) 1248 1.1 christos { 1249 1.1 christos p->type = DEMANGLE_COMPONENT_FUNCTION_PARAM; 1250 1.1 christos p->u.s_number.number = i; 1251 1.1 christos } 1252 1.1 christos return p; 1253 1.1 christos } 1254 1.1 christos 1255 1.1 christos /* Add a new standard substitution component. */ 1256 1.1 christos 1257 1.1 christos static struct demangle_component * 1258 1.1 christos d_make_sub (struct d_info *di, const char *name, int len) 1259 1.1 christos { 1260 1.1 christos struct demangle_component *p; 1261 1.1 christos 1262 1.1 christos p = d_make_empty (di); 1263 1.1 christos if (p != NULL) 1264 1.1 christos { 1265 1.1 christos p->type = DEMANGLE_COMPONENT_SUB_STD; 1266 1.1 christos p->u.s_string.string = name; 1267 1.1 christos p->u.s_string.len = len; 1268 1.1 christos } 1269 1.1 christos return p; 1270 1.1 christos } 1271 1.1 christos 1272 1.1 christos /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]* 1273 1.1 christos 1274 1.1 christos TOP_LEVEL is non-zero when called at the top level. */ 1275 1.1 christos 1276 1.1 christos CP_STATIC_IF_GLIBCPP_V3 1277 1.1 christos struct demangle_component * 1278 1.1 christos cplus_demangle_mangled_name (struct d_info *di, int top_level) 1279 1.1 christos { 1280 1.1 christos struct demangle_component *p; 1281 1.1 christos 1282 1.1 christos if (! d_check_char (di, '_') 1283 1.1 christos /* Allow missing _ if not at toplevel to work around a 1284 1.1 christos bug in G++ abi-version=2 mangling; see the comment in 1285 1.1 christos write_template_arg. */ 1286 1.1 christos && top_level) 1287 1.1 christos return NULL; 1288 1.1 christos if (! d_check_char (di, 'Z')) 1289 1.1 christos return NULL; 1290 1.1 christos p = d_encoding (di, top_level); 1291 1.1 christos 1292 1.1 christos /* If at top level and parsing parameters, check for a clone 1293 1.1 christos suffix. */ 1294 1.1 christos if (top_level && (di->options & DMGL_PARAMS) != 0) 1295 1.1 christos while (d_peek_char (di) == '.' 1296 1.1 christos && (IS_LOWER (d_peek_next_char (di)) 1297 1.1 christos || d_peek_next_char (di) == '_' 1298 1.1 christos || IS_DIGIT (d_peek_next_char (di)))) 1299 1.1 christos p = d_clone_suffix (di, p); 1300 1.1 christos 1301 1.1 christos return p; 1302 1.1 christos } 1303 1.1 christos 1304 1.1 christos /* Return whether a function should have a return type. The argument 1305 1.1 christos is the function name, which may be qualified in various ways. The 1306 1.1 christos rules are that template functions have return types with some 1307 1.1 christos exceptions, function types which are not part of a function name 1308 1.1 christos mangling have return types with some exceptions, and non-template 1309 1.1 christos function names do not have return types. The exceptions are that 1310 1.1 christos constructors, destructors, and conversion operators do not have 1311 1.1 christos return types. */ 1312 1.1 christos 1313 1.1 christos static int 1314 1.1 christos has_return_type (struct demangle_component *dc) 1315 1.1 christos { 1316 1.1 christos if (dc == NULL) 1317 1.1 christos return 0; 1318 1.1 christos switch (dc->type) 1319 1.1 christos { 1320 1.1 christos default: 1321 1.1 christos return 0; 1322 1.6 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 1323 1.6 christos return has_return_type (d_right (dc)); 1324 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 1325 1.1 christos return ! is_ctor_dtor_or_conversion (d_left (dc)); 1326 1.6 christos FNQUAL_COMPONENT_CASE: 1327 1.1 christos return has_return_type (d_left (dc)); 1328 1.1 christos } 1329 1.1 christos } 1330 1.1 christos 1331 1.1 christos /* Return whether a name is a constructor, a destructor, or a 1332 1.1 christos conversion operator. */ 1333 1.1 christos 1334 1.1 christos static int 1335 1.1 christos is_ctor_dtor_or_conversion (struct demangle_component *dc) 1336 1.1 christos { 1337 1.1 christos if (dc == NULL) 1338 1.1 christos return 0; 1339 1.1 christos switch (dc->type) 1340 1.1 christos { 1341 1.1 christos default: 1342 1.1 christos return 0; 1343 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 1344 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 1345 1.1 christos return is_ctor_dtor_or_conversion (d_right (dc)); 1346 1.1 christos case DEMANGLE_COMPONENT_CTOR: 1347 1.1 christos case DEMANGLE_COMPONENT_DTOR: 1348 1.5 christos case DEMANGLE_COMPONENT_CONVERSION: 1349 1.1 christos return 1; 1350 1.1 christos } 1351 1.1 christos } 1352 1.1 christos 1353 1.9 christos /* [ Q <constraint-expression> ] */ 1354 1.9 christos 1355 1.9 christos static struct demangle_component * 1356 1.9 christos d_maybe_constraints (struct d_info *di, struct demangle_component *dc) 1357 1.9 christos { 1358 1.9 christos if (d_peek_char (di) == 'Q') 1359 1.9 christos { 1360 1.9 christos d_advance (di, 1); 1361 1.9 christos struct demangle_component *expr = d_expression (di); 1362 1.9 christos if (expr == NULL) 1363 1.9 christos return NULL; 1364 1.9 christos dc = d_make_comp (di, DEMANGLE_COMPONENT_CONSTRAINTS, dc, expr); 1365 1.9 christos } 1366 1.9 christos return dc; 1367 1.9 christos } 1368 1.9 christos 1369 1.1 christos /* <encoding> ::= <(function) name> <bare-function-type> 1370 1.1 christos ::= <(data) name> 1371 1.1 christos ::= <special-name> 1372 1.1 christos 1373 1.1 christos TOP_LEVEL is non-zero when called at the top level, in which case 1374 1.1 christos if DMGL_PARAMS is not set we do not demangle the function 1375 1.1 christos parameters. We only set this at the top level, because otherwise 1376 1.1 christos we would not correctly demangle names in local scopes. */ 1377 1.1 christos 1378 1.1 christos static struct demangle_component * 1379 1.1 christos d_encoding (struct d_info *di, int top_level) 1380 1.1 christos { 1381 1.1 christos char peek = d_peek_char (di); 1382 1.6 christos struct demangle_component *dc; 1383 1.1 christos 1384 1.1 christos if (peek == 'G' || peek == 'T') 1385 1.6 christos dc = d_special_name (di); 1386 1.1 christos else 1387 1.1 christos { 1388 1.8 christos dc = d_name (di, 0); 1389 1.1 christos 1390 1.6 christos if (!dc) 1391 1.6 christos /* Failed already. */; 1392 1.6 christos else if (top_level && (di->options & DMGL_PARAMS) == 0) 1393 1.1 christos { 1394 1.1 christos /* Strip off any initial CV-qualifiers, as they really apply 1395 1.1 christos to the `this' parameter, and they were not output by the 1396 1.1 christos v2 demangler without DMGL_PARAMS. */ 1397 1.6 christos while (is_fnqual_component_type (dc->type)) 1398 1.1 christos dc = d_left (dc); 1399 1.1 christos 1400 1.1 christos /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then 1401 1.6 christos there may be function-qualifiers on its right argument which 1402 1.1 christos really apply here; this happens when parsing a class 1403 1.1 christos which is local to a function. */ 1404 1.1 christos if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME) 1405 1.7 christos { 1406 1.7 christos while (d_right (dc) != NULL 1407 1.7 christos && is_fnqual_component_type (d_right (dc)->type)) 1408 1.7 christos d_right (dc) = d_left (d_right (dc)); 1409 1.7 christos 1410 1.7 christos if (d_right (dc) == NULL) 1411 1.7 christos dc = NULL; 1412 1.7 christos } 1413 1.6 christos } 1414 1.6 christos else 1415 1.6 christos { 1416 1.6 christos peek = d_peek_char (di); 1417 1.6 christos if (peek != '\0' && peek != 'E') 1418 1.1 christos { 1419 1.6 christos struct demangle_component *ftype; 1420 1.6 christos 1421 1.6 christos ftype = d_bare_function_type (di, has_return_type (dc)); 1422 1.9 christos if (!ftype) 1423 1.9 christos return NULL; 1424 1.9 christos 1425 1.9 christos /* If this is a non-top-level local-name, clear the 1426 1.9 christos return type, so it doesn't confuse the user by 1427 1.9 christos being confused with the return type of whaever 1428 1.9 christos this is nested within. */ 1429 1.9 christos if (!top_level && dc->type == DEMANGLE_COMPONENT_LOCAL_NAME 1430 1.9 christos && ftype->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) 1431 1.9 christos d_left (ftype) = NULL; 1432 1.9 christos 1433 1.9 christos ftype = d_maybe_constraints (di, ftype); 1434 1.1 christos 1435 1.9 christos dc = d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, 1436 1.9 christos dc, ftype); 1437 1.1 christos } 1438 1.1 christos } 1439 1.6 christos } 1440 1.1 christos 1441 1.6 christos return dc; 1442 1.1 christos } 1443 1.1 christos 1444 1.3 christos /* <tagged-name> ::= <name> B <source-name> */ 1445 1.3 christos 1446 1.3 christos static struct demangle_component * 1447 1.3 christos d_abi_tags (struct d_info *di, struct demangle_component *dc) 1448 1.3 christos { 1449 1.3 christos struct demangle_component *hold_last_name; 1450 1.3 christos char peek; 1451 1.3 christos 1452 1.3 christos /* Preserve the last name, so the ABI tag doesn't clobber it. */ 1453 1.3 christos hold_last_name = di->last_name; 1454 1.3 christos 1455 1.3 christos while (peek = d_peek_char (di), 1456 1.3 christos peek == 'B') 1457 1.3 christos { 1458 1.3 christos struct demangle_component *tag; 1459 1.3 christos d_advance (di, 1); 1460 1.3 christos tag = d_source_name (di); 1461 1.3 christos dc = d_make_comp (di, DEMANGLE_COMPONENT_TAGGED_NAME, dc, tag); 1462 1.3 christos } 1463 1.3 christos 1464 1.3 christos di->last_name = hold_last_name; 1465 1.3 christos 1466 1.3 christos return dc; 1467 1.3 christos } 1468 1.3 christos 1469 1.1 christos /* <name> ::= <nested-name> 1470 1.1 christos ::= <unscoped-name> 1471 1.1 christos ::= <unscoped-template-name> <template-args> 1472 1.1 christos ::= <local-name> 1473 1.1 christos 1474 1.1 christos <unscoped-name> ::= <unqualified-name> 1475 1.1 christos ::= St <unqualified-name> 1476 1.1 christos 1477 1.1 christos <unscoped-template-name> ::= <unscoped-name> 1478 1.1 christos ::= <substitution> 1479 1.1 christos */ 1480 1.1 christos 1481 1.1 christos static struct demangle_component * 1482 1.8 christos d_name (struct d_info *di, int substable) 1483 1.1 christos { 1484 1.1 christos char peek = d_peek_char (di); 1485 1.8 christos struct demangle_component *dc = NULL; 1486 1.8 christos struct demangle_component *module = NULL; 1487 1.8 christos int subst = 0; 1488 1.1 christos 1489 1.1 christos switch (peek) 1490 1.1 christos { 1491 1.1 christos case 'N': 1492 1.8 christos dc = d_nested_name (di); 1493 1.8 christos break; 1494 1.1 christos 1495 1.1 christos case 'Z': 1496 1.8 christos dc = d_local_name (di); 1497 1.8 christos break; 1498 1.1 christos 1499 1.1 christos case 'U': 1500 1.8 christos dc = d_unqualified_name (di, NULL, NULL); 1501 1.8 christos break; 1502 1.1 christos 1503 1.1 christos case 'S': 1504 1.1 christos { 1505 1.8 christos if (d_peek_next_char (di) == 't') 1506 1.1 christos { 1507 1.1 christos d_advance (di, 2); 1508 1.8 christos dc = d_make_name (di, "std", 3); 1509 1.1 christos di->expansion += 3; 1510 1.1 christos } 1511 1.1 christos 1512 1.8 christos if (d_peek_char (di) == 'S') 1513 1.1 christos { 1514 1.8 christos module = d_substitution (di, 0); 1515 1.8 christos if (!module) 1516 1.8 christos return NULL; 1517 1.8 christos if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME 1518 1.8 christos || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION)) 1519 1.1 christos { 1520 1.8 christos if (dc) 1521 1.1 christos return NULL; 1522 1.8 christos subst = 1; 1523 1.8 christos dc = module; 1524 1.8 christos module = NULL; 1525 1.1 christos } 1526 1.1 christos } 1527 1.1 christos } 1528 1.8 christos /* FALLTHROUGH */ 1529 1.1 christos 1530 1.3 christos case 'L': 1531 1.1 christos default: 1532 1.8 christos if (!subst) 1533 1.8 christos dc = d_unqualified_name (di, dc, module); 1534 1.1 christos if (d_peek_char (di) == 'I') 1535 1.1 christos { 1536 1.1 christos /* This is <template-args>, which means that we just saw 1537 1.1 christos <unscoped-template-name>, which is a substitution 1538 1.1 christos candidate. */ 1539 1.8 christos if (!subst && !d_add_substitution (di, dc)) 1540 1.1 christos return NULL; 1541 1.1 christos dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc, 1542 1.1 christos d_template_args (di)); 1543 1.8 christos subst = 0; 1544 1.1 christos } 1545 1.8 christos break; 1546 1.1 christos } 1547 1.8 christos if (substable && !subst && !d_add_substitution (di, dc)) 1548 1.8 christos return NULL; 1549 1.8 christos return dc; 1550 1.1 christos } 1551 1.1 christos 1552 1.3 christos /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E 1553 1.3 christos ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E 1554 1.9 christos ::= N H <prefix> <unqualified-name> E 1555 1.9 christos ::= N H <template-prefix> <template-args> E 1556 1.1 christos */ 1557 1.1 christos 1558 1.1 christos static struct demangle_component * 1559 1.1 christos d_nested_name (struct d_info *di) 1560 1.1 christos { 1561 1.1 christos struct demangle_component *ret; 1562 1.1 christos struct demangle_component **pret; 1563 1.3 christos struct demangle_component *rqual; 1564 1.1 christos 1565 1.1 christos if (! d_check_char (di, 'N')) 1566 1.1 christos return NULL; 1567 1.1 christos 1568 1.9 christos if (d_peek_char (di) == 'H') 1569 1.9 christos { 1570 1.9 christos d_advance (di, 1); 1571 1.9 christos di->expansion += sizeof "this"; 1572 1.9 christos pret = &ret; 1573 1.9 christos rqual = d_make_comp (di, DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION, 1574 1.9 christos NULL, NULL); 1575 1.9 christos } 1576 1.9 christos else 1577 1.9 christos { 1578 1.9 christos pret = d_cv_qualifiers (di, &ret, 1); 1579 1.9 christos if (pret == NULL) 1580 1.9 christos return NULL; 1581 1.1 christos 1582 1.9 christos /* Parse the ref-qualifier now and then attach it 1583 1.9 christos once we have something to attach it to. */ 1584 1.9 christos rqual = d_ref_qualifier (di, NULL); 1585 1.9 christos } 1586 1.3 christos 1587 1.8 christos *pret = d_prefix (di, 1); 1588 1.1 christos if (*pret == NULL) 1589 1.1 christos return NULL; 1590 1.1 christos 1591 1.3 christos if (rqual) 1592 1.3 christos { 1593 1.3 christos d_left (rqual) = ret; 1594 1.3 christos ret = rqual; 1595 1.3 christos } 1596 1.3 christos 1597 1.1 christos if (! d_check_char (di, 'E')) 1598 1.1 christos return NULL; 1599 1.1 christos 1600 1.1 christos return ret; 1601 1.1 christos } 1602 1.1 christos 1603 1.1 christos /* <prefix> ::= <prefix> <unqualified-name> 1604 1.1 christos ::= <template-prefix> <template-args> 1605 1.1 christos ::= <template-param> 1606 1.1 christos ::= <decltype> 1607 1.1 christos ::= 1608 1.1 christos ::= <substitution> 1609 1.1 christos 1610 1.1 christos <template-prefix> ::= <prefix> <(template) unqualified-name> 1611 1.1 christos ::= <template-param> 1612 1.1 christos ::= <substitution> 1613 1.8 christos 1614 1.8 christos SUBST is true if we should add substitutions (as normal), false 1615 1.8 christos if not (in an unresolved-name). */ 1616 1.1 christos 1617 1.1 christos static struct demangle_component * 1618 1.8 christos d_prefix (struct d_info *di, int substable) 1619 1.1 christos { 1620 1.1 christos struct demangle_component *ret = NULL; 1621 1.1 christos 1622 1.8 christos for (;;) 1623 1.1 christos { 1624 1.8 christos char peek = d_peek_char (di); 1625 1.1 christos 1626 1.1 christos /* The older code accepts a <local-name> here, but I don't see 1627 1.1 christos that in the grammar. The older code does not accept a 1628 1.1 christos <template-param> here. */ 1629 1.1 christos 1630 1.8 christos if (peek == 'D' 1631 1.8 christos && (d_peek_next_char (di) == 'T' 1632 1.8 christos || d_peek_next_char (di) == 't')) 1633 1.1 christos { 1634 1.8 christos /* Decltype. */ 1635 1.8 christos if (ret) 1636 1.8 christos return NULL; 1637 1.8 christos ret = cplus_demangle_type (di); 1638 1.1 christos } 1639 1.1 christos else if (peek == 'I') 1640 1.1 christos { 1641 1.1 christos if (ret == NULL) 1642 1.1 christos return NULL; 1643 1.8 christos struct demangle_component *dc = d_template_args (di); 1644 1.8 christos if (!dc) 1645 1.8 christos return NULL; 1646 1.8 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, dc); 1647 1.1 christos } 1648 1.1 christos else if (peek == 'T') 1649 1.8 christos { 1650 1.8 christos if (ret) 1651 1.8 christos return NULL; 1652 1.8 christos ret = d_template_param (di); 1653 1.8 christos } 1654 1.1 christos else if (peek == 'M') 1655 1.1 christos { 1656 1.9 christos /* Initializer scope for a lambda. We already added it as a 1657 1.9 christos substitution candidate, don't do that again. */ 1658 1.1 christos d_advance (di, 1); 1659 1.9 christos continue; 1660 1.1 christos } 1661 1.1 christos else 1662 1.8 christos { 1663 1.8 christos struct demangle_component *module = NULL; 1664 1.8 christos if (peek == 'S') 1665 1.8 christos { 1666 1.8 christos module = d_substitution (di, 1); 1667 1.8 christos if (!module) 1668 1.8 christos return NULL; 1669 1.8 christos if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME 1670 1.8 christos || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION)) 1671 1.8 christos { 1672 1.8 christos if (ret) 1673 1.8 christos return NULL; 1674 1.8 christos ret = module; 1675 1.8 christos continue; 1676 1.8 christos } 1677 1.8 christos } 1678 1.8 christos ret = d_unqualified_name (di, ret, module); 1679 1.8 christos } 1680 1.8 christos 1681 1.8 christos if (!ret) 1682 1.8 christos break; 1683 1.8 christos 1684 1.8 christos if (d_peek_char (di) == 'E') 1685 1.8 christos break; 1686 1.8 christos 1687 1.8 christos if (substable && !d_add_substitution (di, ret)) 1688 1.1 christos return NULL; 1689 1.8 christos } 1690 1.1 christos 1691 1.8 christos return ret; 1692 1.8 christos } 1693 1.1 christos 1694 1.8 christos static int 1695 1.8 christos d_maybe_module_name (struct d_info *di, struct demangle_component **name) 1696 1.8 christos { 1697 1.8 christos while (d_peek_char (di) == 'W') 1698 1.8 christos { 1699 1.8 christos d_advance (di, 1); 1700 1.8 christos enum demangle_component_type code = DEMANGLE_COMPONENT_MODULE_NAME; 1701 1.8 christos if (d_peek_char (di) == 'P') 1702 1.1 christos { 1703 1.8 christos code = DEMANGLE_COMPONENT_MODULE_PARTITION; 1704 1.8 christos d_advance (di, 1); 1705 1.1 christos } 1706 1.8 christos 1707 1.8 christos *name = d_make_comp (di, code, *name, d_source_name (di)); 1708 1.8 christos if (!*name) 1709 1.8 christos return 0; 1710 1.8 christos if (!d_add_substitution (di, *name)) 1711 1.8 christos return 0; 1712 1.1 christos } 1713 1.8 christos return 1; 1714 1.1 christos } 1715 1.1 christos 1716 1.8 christos /* <unqualified-name> ::= [<module-name>] <operator-name> [<abi-tags>] 1717 1.8 christos ::= [<module-name>] <ctor-dtor-name> [<abi-tags>] 1718 1.8 christos ::= [<module-name>] <source-name> [<abi-tags>] 1719 1.9 christos ::= [<module-name>] F <source-name> [<abi-tags>] 1720 1.8 christos ::= [<module-name>] <local-source-name> [<abi-tags>] 1721 1.8 christos ::= [<module-name>] DC <source-name>+ E [<abi-tags>] 1722 1.8 christos <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>] 1723 1.1 christos */ 1724 1.1 christos 1725 1.1 christos static struct demangle_component * 1726 1.8 christos d_unqualified_name (struct d_info *di, struct demangle_component *scope, 1727 1.8 christos struct demangle_component *module) 1728 1.1 christos { 1729 1.3 christos struct demangle_component *ret; 1730 1.1 christos char peek; 1731 1.9 christos int member_like_friend = 0; 1732 1.1 christos 1733 1.8 christos if (!d_maybe_module_name (di, &module)) 1734 1.8 christos return NULL; 1735 1.8 christos 1736 1.1 christos peek = d_peek_char (di); 1737 1.9 christos if (peek == 'F') 1738 1.9 christos { 1739 1.9 christos member_like_friend = 1; 1740 1.9 christos d_advance (di, 1); 1741 1.9 christos peek = d_peek_char (di); 1742 1.9 christos } 1743 1.1 christos if (IS_DIGIT (peek)) 1744 1.3 christos ret = d_source_name (di); 1745 1.1 christos else if (IS_LOWER (peek)) 1746 1.1 christos { 1747 1.8 christos int was_expr = di->is_expression; 1748 1.6 christos if (peek == 'o' && d_peek_next_char (di) == 'n') 1749 1.8 christos { 1750 1.8 christos d_advance (di, 2); 1751 1.8 christos /* Treat cv as naming a conversion operator. */ 1752 1.8 christos di->is_expression = 0; 1753 1.8 christos } 1754 1.1 christos ret = d_operator_name (di); 1755 1.8 christos di->is_expression = was_expr; 1756 1.1 christos if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR) 1757 1.1 christos { 1758 1.1 christos di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2; 1759 1.1 christos if (!strcmp (ret->u.s_operator.op->code, "li")) 1760 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_UNARY, ret, 1761 1.1 christos d_source_name (di)); 1762 1.1 christos } 1763 1.1 christos } 1764 1.8 christos else if (peek == 'D' && d_peek_next_char (di) == 'C') 1765 1.8 christos { 1766 1.8 christos // structured binding 1767 1.8 christos d_advance (di, 2); 1768 1.8 christos struct demangle_component *prev = NULL; 1769 1.8 christos do 1770 1.8 christos { 1771 1.8 christos struct demangle_component *next = 1772 1.8 christos d_make_comp (di, DEMANGLE_COMPONENT_STRUCTURED_BINDING, 1773 1.8 christos d_source_name (di), NULL); 1774 1.8 christos if (prev) 1775 1.8 christos d_right (prev) = next; 1776 1.8 christos else 1777 1.8 christos ret = next; 1778 1.8 christos prev = next; 1779 1.8 christos } 1780 1.8 christos while (prev && d_peek_char (di) != 'E'); 1781 1.8 christos if (prev) 1782 1.8 christos d_advance (di, 1); 1783 1.8 christos else 1784 1.8 christos ret = NULL; 1785 1.8 christos } 1786 1.1 christos else if (peek == 'C' || peek == 'D') 1787 1.3 christos ret = d_ctor_dtor_name (di); 1788 1.1 christos else if (peek == 'L') 1789 1.1 christos { 1790 1.1 christos d_advance (di, 1); 1791 1.1 christos 1792 1.1 christos ret = d_source_name (di); 1793 1.1 christos if (ret == NULL) 1794 1.1 christos return NULL; 1795 1.1 christos if (! d_discriminator (di)) 1796 1.1 christos return NULL; 1797 1.1 christos } 1798 1.1 christos else if (peek == 'U') 1799 1.1 christos { 1800 1.1 christos switch (d_peek_next_char (di)) 1801 1.1 christos { 1802 1.1 christos case 'l': 1803 1.3 christos ret = d_lambda (di); 1804 1.3 christos break; 1805 1.1 christos case 't': 1806 1.3 christos ret = d_unnamed_type (di); 1807 1.3 christos break; 1808 1.1 christos default: 1809 1.1 christos return NULL; 1810 1.1 christos } 1811 1.1 christos } 1812 1.1 christos else 1813 1.1 christos return NULL; 1814 1.3 christos 1815 1.8 christos if (module) 1816 1.8 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_MODULE_ENTITY, ret, module); 1817 1.3 christos if (d_peek_char (di) == 'B') 1818 1.3 christos ret = d_abi_tags (di, ret); 1819 1.9 christos if (member_like_friend) 1820 1.9 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_FRIEND, ret, NULL); 1821 1.8 christos if (scope) 1822 1.8 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, scope, ret); 1823 1.8 christos 1824 1.3 christos return ret; 1825 1.1 christos } 1826 1.1 christos 1827 1.1 christos /* <source-name> ::= <(positive length) number> <identifier> */ 1828 1.1 christos 1829 1.1 christos static struct demangle_component * 1830 1.1 christos d_source_name (struct d_info *di) 1831 1.1 christos { 1832 1.6 christos int len; 1833 1.1 christos struct demangle_component *ret; 1834 1.1 christos 1835 1.1 christos len = d_number (di); 1836 1.1 christos if (len <= 0) 1837 1.1 christos return NULL; 1838 1.1 christos ret = d_identifier (di, len); 1839 1.1 christos di->last_name = ret; 1840 1.1 christos return ret; 1841 1.1 christos } 1842 1.1 christos 1843 1.1 christos /* number ::= [n] <(non-negative decimal integer)> */ 1844 1.1 christos 1845 1.6 christos static int 1846 1.1 christos d_number (struct d_info *di) 1847 1.1 christos { 1848 1.1 christos int negative; 1849 1.1 christos char peek; 1850 1.6 christos int ret; 1851 1.1 christos 1852 1.1 christos negative = 0; 1853 1.1 christos peek = d_peek_char (di); 1854 1.1 christos if (peek == 'n') 1855 1.1 christos { 1856 1.1 christos negative = 1; 1857 1.1 christos d_advance (di, 1); 1858 1.1 christos peek = d_peek_char (di); 1859 1.1 christos } 1860 1.1 christos 1861 1.1 christos ret = 0; 1862 1.1 christos while (1) 1863 1.1 christos { 1864 1.1 christos if (! IS_DIGIT (peek)) 1865 1.1 christos { 1866 1.1 christos if (negative) 1867 1.1 christos ret = - ret; 1868 1.1 christos return ret; 1869 1.1 christos } 1870 1.6 christos if (ret > ((INT_MAX - (peek - '0')) / 10)) 1871 1.6 christos return -1; 1872 1.7 christos ret = ret * 10 + (peek - '0'); 1873 1.1 christos d_advance (di, 1); 1874 1.1 christos peek = d_peek_char (di); 1875 1.1 christos } 1876 1.1 christos } 1877 1.1 christos 1878 1.1 christos /* Like d_number, but returns a demangle_component. */ 1879 1.1 christos 1880 1.1 christos static struct demangle_component * 1881 1.1 christos d_number_component (struct d_info *di) 1882 1.1 christos { 1883 1.1 christos struct demangle_component *ret = d_make_empty (di); 1884 1.1 christos if (ret) 1885 1.1 christos { 1886 1.1 christos ret->type = DEMANGLE_COMPONENT_NUMBER; 1887 1.1 christos ret->u.s_number.number = d_number (di); 1888 1.1 christos } 1889 1.1 christos return ret; 1890 1.1 christos } 1891 1.1 christos 1892 1.1 christos /* identifier ::= <(unqualified source code identifier)> */ 1893 1.1 christos 1894 1.1 christos static struct demangle_component * 1895 1.6 christos d_identifier (struct d_info *di, int len) 1896 1.1 christos { 1897 1.1 christos const char *name; 1898 1.1 christos 1899 1.1 christos name = d_str (di); 1900 1.1 christos 1901 1.1 christos if (di->send - name < len) 1902 1.1 christos return NULL; 1903 1.1 christos 1904 1.1 christos d_advance (di, len); 1905 1.1 christos 1906 1.1 christos /* A Java mangled name may have a trailing '$' if it is a C++ 1907 1.1 christos keyword. This '$' is not included in the length count. We just 1908 1.1 christos ignore the '$'. */ 1909 1.1 christos if ((di->options & DMGL_JAVA) != 0 1910 1.1 christos && d_peek_char (di) == '$') 1911 1.1 christos d_advance (di, 1); 1912 1.1 christos 1913 1.1 christos /* Look for something which looks like a gcc encoding of an 1914 1.1 christos anonymous namespace, and replace it with a more user friendly 1915 1.1 christos name. */ 1916 1.6 christos if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2 1917 1.1 christos && memcmp (name, ANONYMOUS_NAMESPACE_PREFIX, 1918 1.1 christos ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0) 1919 1.1 christos { 1920 1.1 christos const char *s; 1921 1.1 christos 1922 1.1 christos s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN; 1923 1.1 christos if ((*s == '.' || *s == '_' || *s == '$') 1924 1.1 christos && s[1] == 'N') 1925 1.1 christos { 1926 1.1 christos di->expansion -= len - sizeof "(anonymous namespace)"; 1927 1.1 christos return d_make_name (di, "(anonymous namespace)", 1928 1.1 christos sizeof "(anonymous namespace)" - 1); 1929 1.1 christos } 1930 1.1 christos } 1931 1.1 christos 1932 1.1 christos return d_make_name (di, name, len); 1933 1.1 christos } 1934 1.1 christos 1935 1.1 christos /* operator_name ::= many different two character encodings. 1936 1.1 christos ::= cv <type> 1937 1.1 christos ::= v <digit> <source-name> 1938 1.1 christos 1939 1.1 christos This list is sorted for binary search. */ 1940 1.1 christos 1941 1.1 christos #define NL(s) s, (sizeof s) - 1 1942 1.1 christos 1943 1.1 christos CP_STATIC_IF_GLIBCPP_V3 1944 1.1 christos const struct demangle_operator_info cplus_demangle_operators[] = 1945 1.1 christos { 1946 1.1 christos { "aN", NL ("&="), 2 }, 1947 1.1 christos { "aS", NL ("="), 2 }, 1948 1.1 christos { "aa", NL ("&&"), 2 }, 1949 1.1 christos { "ad", NL ("&"), 1 }, 1950 1.1 christos { "an", NL ("&"), 2 }, 1951 1.1 christos { "at", NL ("alignof "), 1 }, 1952 1.8 christos { "aw", NL ("co_await "), 1 }, 1953 1.1 christos { "az", NL ("alignof "), 1 }, 1954 1.1 christos { "cc", NL ("const_cast"), 2 }, 1955 1.1 christos { "cl", NL ("()"), 2 }, 1956 1.1 christos { "cm", NL (","), 2 }, 1957 1.1 christos { "co", NL ("~"), 1 }, 1958 1.1 christos { "dV", NL ("/="), 2 }, 1959 1.8 christos { "dX", NL ("[...]="), 3 }, /* [expr...expr] = expr */ 1960 1.1 christos { "da", NL ("delete[] "), 1 }, 1961 1.1 christos { "dc", NL ("dynamic_cast"), 2 }, 1962 1.1 christos { "de", NL ("*"), 1 }, 1963 1.8 christos { "di", NL ("="), 2 }, /* .name = expr */ 1964 1.1 christos { "dl", NL ("delete "), 1 }, 1965 1.1 christos { "ds", NL (".*"), 2 }, 1966 1.1 christos { "dt", NL ("."), 2 }, 1967 1.1 christos { "dv", NL ("/"), 2 }, 1968 1.8 christos { "dx", NL ("]="), 2 }, /* [expr] = expr */ 1969 1.1 christos { "eO", NL ("^="), 2 }, 1970 1.1 christos { "eo", NL ("^"), 2 }, 1971 1.1 christos { "eq", NL ("=="), 2 }, 1972 1.6 christos { "fL", NL ("..."), 3 }, 1973 1.6 christos { "fR", NL ("..."), 3 }, 1974 1.6 christos { "fl", NL ("..."), 2 }, 1975 1.6 christos { "fr", NL ("..."), 2 }, 1976 1.1 christos { "ge", NL (">="), 2 }, 1977 1.1 christos { "gs", NL ("::"), 1 }, 1978 1.1 christos { "gt", NL (">"), 2 }, 1979 1.1 christos { "ix", NL ("[]"), 2 }, 1980 1.1 christos { "lS", NL ("<<="), 2 }, 1981 1.1 christos { "le", NL ("<="), 2 }, 1982 1.1 christos { "li", NL ("operator\"\" "), 1 }, 1983 1.1 christos { "ls", NL ("<<"), 2 }, 1984 1.1 christos { "lt", NL ("<"), 2 }, 1985 1.1 christos { "mI", NL ("-="), 2 }, 1986 1.1 christos { "mL", NL ("*="), 2 }, 1987 1.1 christos { "mi", NL ("-"), 2 }, 1988 1.1 christos { "ml", NL ("*"), 2 }, 1989 1.1 christos { "mm", NL ("--"), 1 }, 1990 1.1 christos { "na", NL ("new[]"), 3 }, 1991 1.1 christos { "ne", NL ("!="), 2 }, 1992 1.1 christos { "ng", NL ("-"), 1 }, 1993 1.1 christos { "nt", NL ("!"), 1 }, 1994 1.1 christos { "nw", NL ("new"), 3 }, 1995 1.9 christos { "nx", NL ("noexcept"), 1 }, 1996 1.1 christos { "oR", NL ("|="), 2 }, 1997 1.1 christos { "oo", NL ("||"), 2 }, 1998 1.1 christos { "or", NL ("|"), 2 }, 1999 1.1 christos { "pL", NL ("+="), 2 }, 2000 1.1 christos { "pl", NL ("+"), 2 }, 2001 1.1 christos { "pm", NL ("->*"), 2 }, 2002 1.1 christos { "pp", NL ("++"), 1 }, 2003 1.1 christos { "ps", NL ("+"), 1 }, 2004 1.1 christos { "pt", NL ("->"), 2 }, 2005 1.1 christos { "qu", NL ("?"), 3 }, 2006 1.1 christos { "rM", NL ("%="), 2 }, 2007 1.1 christos { "rS", NL (">>="), 2 }, 2008 1.1 christos { "rc", NL ("reinterpret_cast"), 2 }, 2009 1.1 christos { "rm", NL ("%"), 2 }, 2010 1.1 christos { "rs", NL (">>"), 2 }, 2011 1.6 christos { "sP", NL ("sizeof..."), 1 }, 2012 1.6 christos { "sZ", NL ("sizeof..."), 1 }, 2013 1.1 christos { "sc", NL ("static_cast"), 2 }, 2014 1.8 christos { "ss", NL ("<=>"), 2 }, 2015 1.1 christos { "st", NL ("sizeof "), 1 }, 2016 1.1 christos { "sz", NL ("sizeof "), 1 }, 2017 1.1 christos { "tr", NL ("throw"), 0 }, 2018 1.1 christos { "tw", NL ("throw "), 1 }, 2019 1.1 christos { NULL, NULL, 0, 0 } 2020 1.1 christos }; 2021 1.1 christos 2022 1.1 christos static struct demangle_component * 2023 1.1 christos d_operator_name (struct d_info *di) 2024 1.1 christos { 2025 1.1 christos char c1; 2026 1.1 christos char c2; 2027 1.1 christos 2028 1.1 christos c1 = d_next_char (di); 2029 1.1 christos c2 = d_next_char (di); 2030 1.1 christos if (c1 == 'v' && IS_DIGIT (c2)) 2031 1.1 christos return d_make_extended_operator (di, c2 - '0', d_source_name (di)); 2032 1.1 christos else if (c1 == 'c' && c2 == 'v') 2033 1.3 christos { 2034 1.3 christos struct demangle_component *type; 2035 1.3 christos int was_conversion = di->is_conversion; 2036 1.5 christos struct demangle_component *res; 2037 1.3 christos 2038 1.3 christos di->is_conversion = ! di->is_expression; 2039 1.3 christos type = cplus_demangle_type (di); 2040 1.5 christos if (di->is_conversion) 2041 1.5 christos res = d_make_comp (di, DEMANGLE_COMPONENT_CONVERSION, type, NULL); 2042 1.5 christos else 2043 1.5 christos res = d_make_comp (di, DEMANGLE_COMPONENT_CAST, type, NULL); 2044 1.3 christos di->is_conversion = was_conversion; 2045 1.5 christos return res; 2046 1.3 christos } 2047 1.1 christos else 2048 1.1 christos { 2049 1.1 christos /* LOW is the inclusive lower bound. */ 2050 1.1 christos int low = 0; 2051 1.1 christos /* HIGH is the exclusive upper bound. We subtract one to ignore 2052 1.1 christos the sentinel at the end of the array. */ 2053 1.1 christos int high = ((sizeof (cplus_demangle_operators) 2054 1.1 christos / sizeof (cplus_demangle_operators[0])) 2055 1.1 christos - 1); 2056 1.1 christos 2057 1.1 christos while (1) 2058 1.1 christos { 2059 1.1 christos int i; 2060 1.1 christos const struct demangle_operator_info *p; 2061 1.1 christos 2062 1.1 christos i = low + (high - low) / 2; 2063 1.1 christos p = cplus_demangle_operators + i; 2064 1.1 christos 2065 1.1 christos if (c1 == p->code[0] && c2 == p->code[1]) 2066 1.1 christos return d_make_operator (di, p); 2067 1.1 christos 2068 1.1 christos if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1])) 2069 1.1 christos high = i; 2070 1.1 christos else 2071 1.1 christos low = i + 1; 2072 1.1 christos if (low == high) 2073 1.1 christos return NULL; 2074 1.1 christos } 2075 1.1 christos } 2076 1.1 christos } 2077 1.1 christos 2078 1.1 christos static struct demangle_component * 2079 1.1 christos d_make_character (struct d_info *di, int c) 2080 1.1 christos { 2081 1.1 christos struct demangle_component *p; 2082 1.1 christos p = d_make_empty (di); 2083 1.1 christos if (p != NULL) 2084 1.1 christos { 2085 1.1 christos p->type = DEMANGLE_COMPONENT_CHARACTER; 2086 1.1 christos p->u.s_character.character = c; 2087 1.1 christos } 2088 1.1 christos return p; 2089 1.1 christos } 2090 1.1 christos 2091 1.1 christos static struct demangle_component * 2092 1.1 christos d_java_resource (struct d_info *di) 2093 1.1 christos { 2094 1.1 christos struct demangle_component *p = NULL; 2095 1.1 christos struct demangle_component *next = NULL; 2096 1.6 christos int len, i; 2097 1.1 christos char c; 2098 1.1 christos const char *str; 2099 1.1 christos 2100 1.1 christos len = d_number (di); 2101 1.1 christos if (len <= 1) 2102 1.1 christos return NULL; 2103 1.1 christos 2104 1.1 christos /* Eat the leading '_'. */ 2105 1.1 christos if (d_next_char (di) != '_') 2106 1.1 christos return NULL; 2107 1.1 christos len--; 2108 1.1 christos 2109 1.1 christos str = d_str (di); 2110 1.1 christos i = 0; 2111 1.1 christos 2112 1.1 christos while (len > 0) 2113 1.1 christos { 2114 1.1 christos c = str[i]; 2115 1.1 christos if (!c) 2116 1.1 christos return NULL; 2117 1.1 christos 2118 1.1 christos /* Each chunk is either a '$' escape... */ 2119 1.1 christos if (c == '$') 2120 1.1 christos { 2121 1.1 christos i++; 2122 1.1 christos switch (str[i++]) 2123 1.1 christos { 2124 1.1 christos case 'S': 2125 1.1 christos c = '/'; 2126 1.1 christos break; 2127 1.1 christos case '_': 2128 1.1 christos c = '.'; 2129 1.1 christos break; 2130 1.1 christos case '$': 2131 1.1 christos c = '$'; 2132 1.1 christos break; 2133 1.1 christos default: 2134 1.1 christos return NULL; 2135 1.1 christos } 2136 1.1 christos next = d_make_character (di, c); 2137 1.1 christos d_advance (di, i); 2138 1.1 christos str = d_str (di); 2139 1.1 christos len -= i; 2140 1.1 christos i = 0; 2141 1.1 christos if (next == NULL) 2142 1.1 christos return NULL; 2143 1.1 christos } 2144 1.1 christos /* ... or a sequence of characters. */ 2145 1.1 christos else 2146 1.1 christos { 2147 1.1 christos while (i < len && str[i] && str[i] != '$') 2148 1.1 christos i++; 2149 1.1 christos 2150 1.1 christos next = d_make_name (di, str, i); 2151 1.1 christos d_advance (di, i); 2152 1.1 christos str = d_str (di); 2153 1.1 christos len -= i; 2154 1.1 christos i = 0; 2155 1.1 christos if (next == NULL) 2156 1.1 christos return NULL; 2157 1.1 christos } 2158 1.1 christos 2159 1.1 christos if (p == NULL) 2160 1.1 christos p = next; 2161 1.1 christos else 2162 1.1 christos { 2163 1.1 christos p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next); 2164 1.1 christos if (p == NULL) 2165 1.1 christos return NULL; 2166 1.1 christos } 2167 1.1 christos } 2168 1.1 christos 2169 1.1 christos p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL); 2170 1.1 christos 2171 1.1 christos return p; 2172 1.1 christos } 2173 1.1 christos 2174 1.1 christos /* <special-name> ::= TV <type> 2175 1.1 christos ::= TT <type> 2176 1.1 christos ::= TI <type> 2177 1.1 christos ::= TS <type> 2178 1.7 christos ::= TA <template-arg> 2179 1.1 christos ::= GV <(object) name> 2180 1.1 christos ::= T <call-offset> <(base) encoding> 2181 1.1 christos ::= Tc <call-offset> <call-offset> <(base) encoding> 2182 1.1 christos Also g++ extensions: 2183 1.1 christos ::= TC <type> <(offset) number> _ <(base) type> 2184 1.1 christos ::= TF <type> 2185 1.1 christos ::= TJ <type> 2186 1.1 christos ::= GR <name> 2187 1.1 christos ::= GA <encoding> 2188 1.1 christos ::= Gr <resource name> 2189 1.1 christos ::= GTt <encoding> 2190 1.1 christos ::= GTn <encoding> 2191 1.1 christos */ 2192 1.1 christos 2193 1.1 christos static struct demangle_component * 2194 1.1 christos d_special_name (struct d_info *di) 2195 1.1 christos { 2196 1.1 christos di->expansion += 20; 2197 1.1 christos if (d_check_char (di, 'T')) 2198 1.1 christos { 2199 1.1 christos switch (d_next_char (di)) 2200 1.1 christos { 2201 1.1 christos case 'V': 2202 1.1 christos di->expansion -= 5; 2203 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_VTABLE, 2204 1.1 christos cplus_demangle_type (di), NULL); 2205 1.1 christos case 'T': 2206 1.1 christos di->expansion -= 10; 2207 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_VTT, 2208 1.1 christos cplus_demangle_type (di), NULL); 2209 1.1 christos case 'I': 2210 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO, 2211 1.1 christos cplus_demangle_type (di), NULL); 2212 1.1 christos case 'S': 2213 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_NAME, 2214 1.1 christos cplus_demangle_type (di), NULL); 2215 1.1 christos 2216 1.1 christos case 'h': 2217 1.1 christos if (! d_call_offset (di, 'h')) 2218 1.1 christos return NULL; 2219 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_THUNK, 2220 1.1 christos d_encoding (di, 0), NULL); 2221 1.1 christos 2222 1.1 christos case 'v': 2223 1.1 christos if (! d_call_offset (di, 'v')) 2224 1.1 christos return NULL; 2225 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_VIRTUAL_THUNK, 2226 1.1 christos d_encoding (di, 0), NULL); 2227 1.1 christos 2228 1.1 christos case 'c': 2229 1.1 christos if (! d_call_offset (di, '\0')) 2230 1.1 christos return NULL; 2231 1.1 christos if (! d_call_offset (di, '\0')) 2232 1.1 christos return NULL; 2233 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_COVARIANT_THUNK, 2234 1.1 christos d_encoding (di, 0), NULL); 2235 1.1 christos 2236 1.1 christos case 'C': 2237 1.1 christos { 2238 1.1 christos struct demangle_component *derived_type; 2239 1.6 christos int offset; 2240 1.1 christos struct demangle_component *base_type; 2241 1.1 christos 2242 1.1 christos derived_type = cplus_demangle_type (di); 2243 1.1 christos offset = d_number (di); 2244 1.1 christos if (offset < 0) 2245 1.1 christos return NULL; 2246 1.1 christos if (! d_check_char (di, '_')) 2247 1.1 christos return NULL; 2248 1.1 christos base_type = cplus_demangle_type (di); 2249 1.1 christos /* We don't display the offset. FIXME: We should display 2250 1.1 christos it in verbose mode. */ 2251 1.1 christos di->expansion += 5; 2252 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, 2253 1.1 christos base_type, derived_type); 2254 1.1 christos } 2255 1.1 christos 2256 1.1 christos case 'F': 2257 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_FN, 2258 1.1 christos cplus_demangle_type (di), NULL); 2259 1.1 christos case 'J': 2260 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_JAVA_CLASS, 2261 1.1 christos cplus_demangle_type (di), NULL); 2262 1.1 christos 2263 1.3 christos case 'H': 2264 1.3 christos return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT, 2265 1.8 christos d_name (di, 0), NULL); 2266 1.3 christos 2267 1.3 christos case 'W': 2268 1.3 christos return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER, 2269 1.8 christos d_name (di, 0), NULL); 2270 1.3 christos 2271 1.7 christos case 'A': 2272 1.7 christos return d_make_comp (di, DEMANGLE_COMPONENT_TPARM_OBJ, 2273 1.7 christos d_template_arg (di), NULL); 2274 1.7 christos 2275 1.1 christos default: 2276 1.1 christos return NULL; 2277 1.1 christos } 2278 1.1 christos } 2279 1.1 christos else if (d_check_char (di, 'G')) 2280 1.1 christos { 2281 1.1 christos switch (d_next_char (di)) 2282 1.1 christos { 2283 1.1 christos case 'V': 2284 1.6 christos return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, 2285 1.8 christos d_name (di, 0), NULL); 2286 1.1 christos 2287 1.1 christos case 'R': 2288 1.1 christos { 2289 1.8 christos struct demangle_component *name = d_name (di, 0); 2290 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name, 2291 1.1 christos d_number_component (di)); 2292 1.1 christos } 2293 1.1 christos 2294 1.1 christos case 'A': 2295 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS, 2296 1.1 christos d_encoding (di, 0), NULL); 2297 1.1 christos 2298 1.8 christos case 'I': 2299 1.8 christos { 2300 1.8 christos struct demangle_component *module = NULL; 2301 1.8 christos if (!d_maybe_module_name (di, &module) || !module) 2302 1.8 christos return NULL; 2303 1.8 christos return d_make_comp (di, DEMANGLE_COMPONENT_MODULE_INIT, 2304 1.8 christos module, NULL); 2305 1.8 christos } 2306 1.1 christos case 'T': 2307 1.1 christos switch (d_next_char (di)) 2308 1.1 christos { 2309 1.1 christos case 'n': 2310 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE, 2311 1.1 christos d_encoding (di, 0), NULL); 2312 1.1 christos default: 2313 1.1 christos /* ??? The proposal is that other letters (such as 'h') stand 2314 1.1 christos for different variants of transaction cloning, such as 2315 1.1 christos compiling directly for hardware transaction support. But 2316 1.1 christos they still should all be transactional clones of some sort 2317 1.1 christos so go ahead and call them that. */ 2318 1.1 christos case 't': 2319 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TRANSACTION_CLONE, 2320 1.1 christos d_encoding (di, 0), NULL); 2321 1.1 christos } 2322 1.1 christos 2323 1.1 christos case 'r': 2324 1.1 christos return d_java_resource (di); 2325 1.1 christos 2326 1.1 christos default: 2327 1.1 christos return NULL; 2328 1.1 christos } 2329 1.1 christos } 2330 1.1 christos else 2331 1.1 christos return NULL; 2332 1.1 christos } 2333 1.1 christos 2334 1.1 christos /* <call-offset> ::= h <nv-offset> _ 2335 1.1 christos ::= v <v-offset> _ 2336 1.1 christos 2337 1.1 christos <nv-offset> ::= <(offset) number> 2338 1.1 christos 2339 1.1 christos <v-offset> ::= <(offset) number> _ <(virtual offset) number> 2340 1.1 christos 2341 1.1 christos The C parameter, if not '\0', is a character we just read which is 2342 1.1 christos the start of the <call-offset>. 2343 1.1 christos 2344 1.1 christos We don't display the offset information anywhere. FIXME: We should 2345 1.1 christos display it in verbose mode. */ 2346 1.1 christos 2347 1.1 christos static int 2348 1.1 christos d_call_offset (struct d_info *di, int c) 2349 1.1 christos { 2350 1.1 christos if (c == '\0') 2351 1.1 christos c = d_next_char (di); 2352 1.1 christos 2353 1.1 christos if (c == 'h') 2354 1.1 christos d_number (di); 2355 1.1 christos else if (c == 'v') 2356 1.1 christos { 2357 1.1 christos d_number (di); 2358 1.1 christos if (! d_check_char (di, '_')) 2359 1.1 christos return 0; 2360 1.1 christos d_number (di); 2361 1.1 christos } 2362 1.1 christos else 2363 1.1 christos return 0; 2364 1.1 christos 2365 1.1 christos if (! d_check_char (di, '_')) 2366 1.1 christos return 0; 2367 1.1 christos 2368 1.1 christos return 1; 2369 1.1 christos } 2370 1.1 christos 2371 1.1 christos /* <ctor-dtor-name> ::= C1 2372 1.1 christos ::= C2 2373 1.1 christos ::= C3 2374 1.1 christos ::= D0 2375 1.1 christos ::= D1 2376 1.1 christos ::= D2 2377 1.1 christos */ 2378 1.1 christos 2379 1.1 christos static struct demangle_component * 2380 1.1 christos d_ctor_dtor_name (struct d_info *di) 2381 1.1 christos { 2382 1.1 christos if (di->last_name != NULL) 2383 1.1 christos { 2384 1.1 christos if (di->last_name->type == DEMANGLE_COMPONENT_NAME) 2385 1.1 christos di->expansion += di->last_name->u.s_name.len; 2386 1.1 christos else if (di->last_name->type == DEMANGLE_COMPONENT_SUB_STD) 2387 1.1 christos di->expansion += di->last_name->u.s_string.len; 2388 1.1 christos } 2389 1.1 christos switch (d_peek_char (di)) 2390 1.1 christos { 2391 1.1 christos case 'C': 2392 1.1 christos { 2393 1.1 christos enum gnu_v3_ctor_kinds kind; 2394 1.6 christos int inheriting = 0; 2395 1.6 christos 2396 1.6 christos if (d_peek_next_char (di) == 'I') 2397 1.6 christos { 2398 1.6 christos inheriting = 1; 2399 1.6 christos d_advance (di, 1); 2400 1.6 christos } 2401 1.1 christos 2402 1.1 christos switch (d_peek_next_char (di)) 2403 1.1 christos { 2404 1.1 christos case '1': 2405 1.1 christos kind = gnu_v3_complete_object_ctor; 2406 1.1 christos break; 2407 1.1 christos case '2': 2408 1.1 christos kind = gnu_v3_base_object_ctor; 2409 1.1 christos break; 2410 1.1 christos case '3': 2411 1.1 christos kind = gnu_v3_complete_object_allocating_ctor; 2412 1.1 christos break; 2413 1.3 christos case '4': 2414 1.3 christos kind = gnu_v3_unified_ctor; 2415 1.3 christos break; 2416 1.1 christos case '5': 2417 1.1 christos kind = gnu_v3_object_ctor_group; 2418 1.1 christos break; 2419 1.1 christos default: 2420 1.1 christos return NULL; 2421 1.1 christos } 2422 1.6 christos 2423 1.1 christos d_advance (di, 2); 2424 1.6 christos 2425 1.6 christos if (inheriting) 2426 1.6 christos cplus_demangle_type (di); 2427 1.6 christos 2428 1.1 christos return d_make_ctor (di, kind, di->last_name); 2429 1.1 christos } 2430 1.1 christos 2431 1.1 christos case 'D': 2432 1.1 christos { 2433 1.1 christos enum gnu_v3_dtor_kinds kind; 2434 1.1 christos 2435 1.1 christos switch (d_peek_next_char (di)) 2436 1.1 christos { 2437 1.1 christos case '0': 2438 1.1 christos kind = gnu_v3_deleting_dtor; 2439 1.1 christos break; 2440 1.1 christos case '1': 2441 1.1 christos kind = gnu_v3_complete_object_dtor; 2442 1.1 christos break; 2443 1.1 christos case '2': 2444 1.1 christos kind = gnu_v3_base_object_dtor; 2445 1.1 christos break; 2446 1.3 christos /* digit '3' is not used */ 2447 1.3 christos case '4': 2448 1.3 christos kind = gnu_v3_unified_dtor; 2449 1.3 christos break; 2450 1.1 christos case '5': 2451 1.1 christos kind = gnu_v3_object_dtor_group; 2452 1.1 christos break; 2453 1.1 christos default: 2454 1.1 christos return NULL; 2455 1.1 christos } 2456 1.1 christos d_advance (di, 2); 2457 1.1 christos return d_make_dtor (di, kind, di->last_name); 2458 1.1 christos } 2459 1.1 christos 2460 1.1 christos default: 2461 1.1 christos return NULL; 2462 1.1 christos } 2463 1.1 christos } 2464 1.1 christos 2465 1.6 christos /* True iff we're looking at an order-insensitive type-qualifier, including 2466 1.6 christos function-type-qualifiers. */ 2467 1.6 christos 2468 1.6 christos static int 2469 1.6 christos next_is_type_qual (struct d_info *di) 2470 1.6 christos { 2471 1.6 christos char peek = d_peek_char (di); 2472 1.6 christos if (peek == 'r' || peek == 'V' || peek == 'K') 2473 1.6 christos return 1; 2474 1.6 christos if (peek == 'D') 2475 1.6 christos { 2476 1.6 christos peek = d_peek_next_char (di); 2477 1.6 christos if (peek == 'x' || peek == 'o' || peek == 'O' || peek == 'w') 2478 1.6 christos return 1; 2479 1.6 christos } 2480 1.6 christos return 0; 2481 1.6 christos } 2482 1.6 christos 2483 1.1 christos /* <type> ::= <builtin-type> 2484 1.1 christos ::= <function-type> 2485 1.1 christos ::= <class-enum-type> 2486 1.1 christos ::= <array-type> 2487 1.1 christos ::= <pointer-to-member-type> 2488 1.1 christos ::= <template-param> 2489 1.1 christos ::= <template-template-param> <template-args> 2490 1.1 christos ::= <substitution> 2491 1.1 christos ::= <CV-qualifiers> <type> 2492 1.1 christos ::= P <type> 2493 1.1 christos ::= R <type> 2494 1.1 christos ::= O <type> (C++0x) 2495 1.1 christos ::= C <type> 2496 1.1 christos ::= G <type> 2497 1.1 christos ::= U <source-name> <type> 2498 1.1 christos 2499 1.1 christos <builtin-type> ::= various one letter codes 2500 1.1 christos ::= u <source-name> 2501 1.1 christos */ 2502 1.1 christos 2503 1.1 christos CP_STATIC_IF_GLIBCPP_V3 2504 1.1 christos const struct demangle_builtin_type_info 2505 1.1 christos cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] = 2506 1.1 christos { 2507 1.1 christos /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT }, 2508 1.1 christos /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL }, 2509 1.1 christos /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT }, 2510 1.1 christos /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT }, 2511 1.1 christos /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT }, 2512 1.1 christos /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT }, 2513 1.1 christos /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT }, 2514 1.1 christos /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT }, 2515 1.1 christos /* i */ { NL ("int"), NL ("int"), D_PRINT_INT }, 2516 1.1 christos /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED }, 2517 1.1 christos /* k */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT }, 2518 1.1 christos /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG }, 2519 1.1 christos /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG }, 2520 1.1 christos /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT }, 2521 1.1 christos /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"), 2522 1.1 christos D_PRINT_DEFAULT }, 2523 1.1 christos /* p */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT }, 2524 1.1 christos /* q */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT }, 2525 1.1 christos /* r */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT }, 2526 1.1 christos /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT }, 2527 1.1 christos /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT }, 2528 1.1 christos /* u */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT }, 2529 1.1 christos /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID }, 2530 1.1 christos /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT }, 2531 1.1 christos /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG }, 2532 1.1 christos /* y */ { NL ("unsigned long long"), NL ("unsigned long long"), 2533 1.1 christos D_PRINT_UNSIGNED_LONG_LONG }, 2534 1.1 christos /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT }, 2535 1.1 christos /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT }, 2536 1.1 christos /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT }, 2537 1.1 christos /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT }, 2538 1.1 christos /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT }, 2539 1.7 christos /* 30 */ { NL ("char8_t"), NL ("char8_t"), D_PRINT_DEFAULT }, 2540 1.7 christos /* 31 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT }, 2541 1.7 christos /* 32 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT }, 2542 1.7 christos /* 33 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"), 2543 1.1 christos D_PRINT_DEFAULT }, 2544 1.9 christos /* 34 */ { NL ("_Float"), NL ("_Float"), D_PRINT_FLOAT }, 2545 1.9 christos /* 35 */ { NL ("std::bfloat16_t"), NL ("std::bfloat16_t"), D_PRINT_FLOAT }, 2546 1.1 christos }; 2547 1.1 christos 2548 1.1 christos CP_STATIC_IF_GLIBCPP_V3 2549 1.1 christos struct demangle_component * 2550 1.1 christos cplus_demangle_type (struct d_info *di) 2551 1.1 christos { 2552 1.1 christos char peek; 2553 1.1 christos struct demangle_component *ret; 2554 1.1 christos int can_subst; 2555 1.1 christos 2556 1.1 christos /* The ABI specifies that when CV-qualifiers are used, the base type 2557 1.1 christos is substitutable, and the fully qualified type is substitutable, 2558 1.1 christos but the base type with a strict subset of the CV-qualifiers is 2559 1.1 christos not substitutable. The natural recursive implementation of the 2560 1.1 christos CV-qualifiers would cause subsets to be substitutable, so instead 2561 1.1 christos we pull them all off now. 2562 1.1 christos 2563 1.1 christos FIXME: The ABI says that order-insensitive vendor qualifiers 2564 1.1 christos should be handled in the same way, but we have no way to tell 2565 1.1 christos which vendor qualifiers are order-insensitive and which are 2566 1.1 christos order-sensitive. So we just assume that they are all 2567 1.1 christos order-sensitive. g++ 3.4 supports only one vendor qualifier, 2568 1.1 christos __vector, and it treats it as order-sensitive when mangling 2569 1.1 christos names. */ 2570 1.1 christos 2571 1.6 christos if (next_is_type_qual (di)) 2572 1.1 christos { 2573 1.1 christos struct demangle_component **pret; 2574 1.1 christos 2575 1.1 christos pret = d_cv_qualifiers (di, &ret, 0); 2576 1.1 christos if (pret == NULL) 2577 1.1 christos return NULL; 2578 1.3 christos if (d_peek_char (di) == 'F') 2579 1.3 christos { 2580 1.3 christos /* cv-qualifiers before a function type apply to 'this', 2581 1.3 christos so avoid adding the unqualified function type to 2582 1.3 christos the substitution list. */ 2583 1.3 christos *pret = d_function_type (di); 2584 1.3 christos } 2585 1.3 christos else 2586 1.3 christos *pret = cplus_demangle_type (di); 2587 1.3 christos if (!*pret) 2588 1.3 christos return NULL; 2589 1.3 christos if ((*pret)->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS 2590 1.3 christos || (*pret)->type == DEMANGLE_COMPONENT_REFERENCE_THIS) 2591 1.3 christos { 2592 1.3 christos /* Move the ref-qualifier outside the cv-qualifiers so that 2593 1.3 christos they are printed in the right order. */ 2594 1.3 christos struct demangle_component *fn = d_left (*pret); 2595 1.3 christos d_left (*pret) = ret; 2596 1.3 christos ret = *pret; 2597 1.3 christos *pret = fn; 2598 1.3 christos } 2599 1.3 christos if (! d_add_substitution (di, ret)) 2600 1.1 christos return NULL; 2601 1.1 christos return ret; 2602 1.1 christos } 2603 1.1 christos 2604 1.1 christos can_subst = 1; 2605 1.1 christos 2606 1.6 christos peek = d_peek_char (di); 2607 1.1 christos switch (peek) 2608 1.1 christos { 2609 1.1 christos case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': 2610 1.1 christos case 'h': case 'i': case 'j': case 'l': case 'm': case 'n': 2611 1.1 christos case 'o': case 's': case 't': 2612 1.1 christos case 'v': case 'w': case 'x': case 'y': case 'z': 2613 1.1 christos ret = d_make_builtin_type (di, 2614 1.1 christos &cplus_demangle_builtin_types[peek - 'a']); 2615 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2616 1.1 christos can_subst = 0; 2617 1.1 christos d_advance (di, 1); 2618 1.1 christos break; 2619 1.1 christos 2620 1.1 christos case 'u': 2621 1.1 christos d_advance (di, 1); 2622 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE, 2623 1.1 christos d_source_name (di), NULL); 2624 1.1 christos break; 2625 1.1 christos 2626 1.1 christos case 'F': 2627 1.1 christos ret = d_function_type (di); 2628 1.1 christos break; 2629 1.1 christos 2630 1.1 christos case 'A': 2631 1.1 christos ret = d_array_type (di); 2632 1.1 christos break; 2633 1.1 christos 2634 1.1 christos case 'M': 2635 1.1 christos ret = d_pointer_to_member_type (di); 2636 1.1 christos break; 2637 1.1 christos 2638 1.1 christos case 'T': 2639 1.1 christos ret = d_template_param (di); 2640 1.1 christos if (d_peek_char (di) == 'I') 2641 1.1 christos { 2642 1.3 christos /* This may be <template-template-param> <template-args>. 2643 1.3 christos If this is the type for a conversion operator, we can 2644 1.3 christos have a <template-template-param> here only by following 2645 1.3 christos a derivation like this: 2646 1.3 christos 2647 1.3 christos <nested-name> 2648 1.3 christos -> <template-prefix> <template-args> 2649 1.3 christos -> <prefix> <template-unqualified-name> <template-args> 2650 1.3 christos -> <unqualified-name> <template-unqualified-name> <template-args> 2651 1.3 christos -> <source-name> <template-unqualified-name> <template-args> 2652 1.3 christos -> <source-name> <operator-name> <template-args> 2653 1.3 christos -> <source-name> cv <type> <template-args> 2654 1.3 christos -> <source-name> cv <template-template-param> <template-args> <template-args> 2655 1.3 christos 2656 1.3 christos where the <template-args> is followed by another. 2657 1.3 christos Otherwise, we must have a derivation like this: 2658 1.3 christos 2659 1.3 christos <nested-name> 2660 1.3 christos -> <template-prefix> <template-args> 2661 1.3 christos -> <prefix> <template-unqualified-name> <template-args> 2662 1.3 christos -> <unqualified-name> <template-unqualified-name> <template-args> 2663 1.3 christos -> <source-name> <template-unqualified-name> <template-args> 2664 1.3 christos -> <source-name> <operator-name> <template-args> 2665 1.3 christos -> <source-name> cv <type> <template-args> 2666 1.3 christos -> <source-name> cv <template-param> <template-args> 2667 1.3 christos 2668 1.3 christos where we need to leave the <template-args> to be processed 2669 1.3 christos by d_prefix (following the <template-prefix>). 2670 1.3 christos 2671 1.3 christos The <template-template-param> part is a substitution 2672 1.1 christos candidate. */ 2673 1.3 christos if (! di->is_conversion) 2674 1.3 christos { 2675 1.3 christos if (! d_add_substitution (di, ret)) 2676 1.3 christos return NULL; 2677 1.3 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, 2678 1.3 christos d_template_args (di)); 2679 1.3 christos } 2680 1.3 christos else 2681 1.3 christos { 2682 1.3 christos struct demangle_component *args; 2683 1.3 christos struct d_info_checkpoint checkpoint; 2684 1.3 christos 2685 1.3 christos d_checkpoint (di, &checkpoint); 2686 1.3 christos args = d_template_args (di); 2687 1.3 christos if (d_peek_char (di) == 'I') 2688 1.3 christos { 2689 1.3 christos if (! d_add_substitution (di, ret)) 2690 1.3 christos return NULL; 2691 1.3 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, 2692 1.3 christos args); 2693 1.3 christos } 2694 1.3 christos else 2695 1.3 christos d_backtrack (di, &checkpoint); 2696 1.3 christos } 2697 1.1 christos } 2698 1.1 christos break; 2699 1.1 christos 2700 1.1 christos case 'O': 2701 1.1 christos d_advance (di, 1); 2702 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE, 2703 1.1 christos cplus_demangle_type (di), NULL); 2704 1.1 christos break; 2705 1.1 christos 2706 1.1 christos case 'P': 2707 1.1 christos d_advance (di, 1); 2708 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_POINTER, 2709 1.1 christos cplus_demangle_type (di), NULL); 2710 1.1 christos break; 2711 1.1 christos 2712 1.1 christos case 'R': 2713 1.1 christos d_advance (di, 1); 2714 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_REFERENCE, 2715 1.1 christos cplus_demangle_type (di), NULL); 2716 1.1 christos break; 2717 1.1 christos 2718 1.1 christos case 'C': 2719 1.1 christos d_advance (di, 1); 2720 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_COMPLEX, 2721 1.1 christos cplus_demangle_type (di), NULL); 2722 1.1 christos break; 2723 1.1 christos 2724 1.1 christos case 'G': 2725 1.1 christos d_advance (di, 1); 2726 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_IMAGINARY, 2727 1.1 christos cplus_demangle_type (di), NULL); 2728 1.1 christos break; 2729 1.1 christos 2730 1.1 christos case 'U': 2731 1.1 christos d_advance (di, 1); 2732 1.1 christos ret = d_source_name (di); 2733 1.3 christos if (d_peek_char (di) == 'I') 2734 1.3 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, 2735 1.3 christos d_template_args (di)); 2736 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL, 2737 1.1 christos cplus_demangle_type (di), ret); 2738 1.1 christos break; 2739 1.1 christos 2740 1.1 christos case 'D': 2741 1.1 christos can_subst = 0; 2742 1.1 christos d_advance (di, 1); 2743 1.1 christos peek = d_next_char (di); 2744 1.1 christos switch (peek) 2745 1.1 christos { 2746 1.1 christos case 'T': 2747 1.1 christos case 't': 2748 1.1 christos /* decltype (expression) */ 2749 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_DECLTYPE, 2750 1.1 christos d_expression (di), NULL); 2751 1.1 christos if (ret && d_next_char (di) != 'E') 2752 1.1 christos ret = NULL; 2753 1.1 christos can_subst = 1; 2754 1.1 christos break; 2755 1.1 christos 2756 1.1 christos case 'p': 2757 1.1 christos /* Pack expansion. */ 2758 1.1 christos ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION, 2759 1.1 christos cplus_demangle_type (di), NULL); 2760 1.1 christos can_subst = 1; 2761 1.1 christos break; 2762 1.1 christos 2763 1.1 christos case 'a': 2764 1.1 christos /* auto */ 2765 1.1 christos ret = d_make_name (di, "auto", 4); 2766 1.1 christos break; 2767 1.6 christos case 'c': 2768 1.6 christos /* decltype(auto) */ 2769 1.6 christos ret = d_make_name (di, "decltype(auto)", 14); 2770 1.6 christos break; 2771 1.6 christos 2772 1.1 christos case 'f': 2773 1.1 christos /* 32-bit decimal floating point */ 2774 1.1 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[26]); 2775 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2776 1.1 christos break; 2777 1.1 christos case 'd': 2778 1.1 christos /* 64-bit DFP */ 2779 1.1 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[27]); 2780 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2781 1.1 christos break; 2782 1.1 christos case 'e': 2783 1.1 christos /* 128-bit DFP */ 2784 1.1 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[28]); 2785 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2786 1.1 christos break; 2787 1.1 christos case 'h': 2788 1.1 christos /* 16-bit half-precision FP */ 2789 1.1 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[29]); 2790 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2791 1.1 christos break; 2792 1.7 christos case 'u': 2793 1.7 christos /* char8_t */ 2794 1.7 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]); 2795 1.7 christos di->expansion += ret->u.s_builtin.type->len; 2796 1.7 christos break; 2797 1.1 christos case 's': 2798 1.1 christos /* char16_t */ 2799 1.7 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]); 2800 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2801 1.1 christos break; 2802 1.1 christos case 'i': 2803 1.1 christos /* char32_t */ 2804 1.7 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]); 2805 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2806 1.1 christos break; 2807 1.1 christos 2808 1.1 christos case 'F': 2809 1.9 christos /* DF<number>_ - _Float<number>. 2810 1.9 christos DF<number>x - _Float<number>x 2811 1.9 christos DF16b - std::bfloat16_t. */ 2812 1.9 christos { 2813 1.9 christos int arg = d_number (di); 2814 1.9 christos char buf[12]; 2815 1.9 christos char suffix = 0; 2816 1.9 christos if (d_peek_char (di) == 'b') 2817 1.9 christos { 2818 1.9 christos if (arg != 16) 2819 1.9 christos return NULL; 2820 1.9 christos d_advance (di, 1); 2821 1.9 christos ret = d_make_builtin_type (di, 2822 1.9 christos &cplus_demangle_builtin_types[35]); 2823 1.9 christos di->expansion += ret->u.s_builtin.type->len; 2824 1.9 christos break; 2825 1.9 christos } 2826 1.9 christos if (d_peek_char (di) == 'x') 2827 1.9 christos suffix = 'x'; 2828 1.9 christos if (!suffix && d_peek_char (di) != '_') 2829 1.9 christos return NULL; 2830 1.9 christos ret 2831 1.9 christos = d_make_extended_builtin_type (di, 2832 1.9 christos &cplus_demangle_builtin_types[34], 2833 1.9 christos arg, suffix); 2834 1.9 christos d_advance (di, 1); 2835 1.9 christos sprintf (buf, "%d", arg); 2836 1.9 christos di->expansion += ret->u.s_extended_builtin.type->len 2837 1.9 christos + strlen (buf) + (suffix != 0); 2838 1.9 christos break; 2839 1.9 christos } 2840 1.1 christos 2841 1.1 christos case 'v': 2842 1.1 christos ret = d_vector_type (di); 2843 1.1 christos can_subst = 1; 2844 1.1 christos break; 2845 1.1 christos 2846 1.1 christos case 'n': 2847 1.1 christos /* decltype(nullptr) */ 2848 1.7 christos ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[33]); 2849 1.1 christos di->expansion += ret->u.s_builtin.type->len; 2850 1.1 christos break; 2851 1.1 christos 2852 1.1 christos default: 2853 1.1 christos return NULL; 2854 1.1 christos } 2855 1.1 christos break; 2856 1.1 christos 2857 1.1 christos default: 2858 1.8 christos return d_class_enum_type (di, 1); 2859 1.1 christos } 2860 1.1 christos 2861 1.1 christos if (can_subst) 2862 1.1 christos { 2863 1.1 christos if (! d_add_substitution (di, ret)) 2864 1.1 christos return NULL; 2865 1.1 christos } 2866 1.1 christos 2867 1.1 christos return ret; 2868 1.1 christos } 2869 1.1 christos 2870 1.5 christos /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */ 2871 1.1 christos 2872 1.1 christos static struct demangle_component ** 2873 1.1 christos d_cv_qualifiers (struct d_info *di, 2874 1.1 christos struct demangle_component **pret, int member_fn) 2875 1.1 christos { 2876 1.1 christos struct demangle_component **pstart; 2877 1.1 christos char peek; 2878 1.1 christos 2879 1.1 christos pstart = pret; 2880 1.1 christos peek = d_peek_char (di); 2881 1.6 christos while (next_is_type_qual (di)) 2882 1.1 christos { 2883 1.1 christos enum demangle_component_type t; 2884 1.6 christos struct demangle_component *right = NULL; 2885 1.1 christos 2886 1.1 christos d_advance (di, 1); 2887 1.1 christos if (peek == 'r') 2888 1.1 christos { 2889 1.1 christos t = (member_fn 2890 1.1 christos ? DEMANGLE_COMPONENT_RESTRICT_THIS 2891 1.1 christos : DEMANGLE_COMPONENT_RESTRICT); 2892 1.1 christos di->expansion += sizeof "restrict"; 2893 1.1 christos } 2894 1.1 christos else if (peek == 'V') 2895 1.1 christos { 2896 1.1 christos t = (member_fn 2897 1.1 christos ? DEMANGLE_COMPONENT_VOLATILE_THIS 2898 1.1 christos : DEMANGLE_COMPONENT_VOLATILE); 2899 1.1 christos di->expansion += sizeof "volatile"; 2900 1.1 christos } 2901 1.5 christos else if (peek == 'K') 2902 1.1 christos { 2903 1.1 christos t = (member_fn 2904 1.1 christos ? DEMANGLE_COMPONENT_CONST_THIS 2905 1.1 christos : DEMANGLE_COMPONENT_CONST); 2906 1.1 christos di->expansion += sizeof "const"; 2907 1.1 christos } 2908 1.5 christos else 2909 1.5 christos { 2910 1.6 christos peek = d_next_char (di); 2911 1.6 christos if (peek == 'x') 2912 1.6 christos { 2913 1.6 christos t = DEMANGLE_COMPONENT_TRANSACTION_SAFE; 2914 1.6 christos di->expansion += sizeof "transaction_safe"; 2915 1.6 christos } 2916 1.6 christos else if (peek == 'o' 2917 1.6 christos || peek == 'O') 2918 1.6 christos { 2919 1.6 christos t = DEMANGLE_COMPONENT_NOEXCEPT; 2920 1.6 christos di->expansion += sizeof "noexcept"; 2921 1.6 christos if (peek == 'O') 2922 1.6 christos { 2923 1.6 christos right = d_expression (di); 2924 1.6 christos if (right == NULL) 2925 1.6 christos return NULL; 2926 1.6 christos if (! d_check_char (di, 'E')) 2927 1.6 christos return NULL; 2928 1.6 christos } 2929 1.6 christos } 2930 1.6 christos else if (peek == 'w') 2931 1.6 christos { 2932 1.6 christos t = DEMANGLE_COMPONENT_THROW_SPEC; 2933 1.6 christos di->expansion += sizeof "throw"; 2934 1.6 christos right = d_parmlist (di); 2935 1.6 christos if (right == NULL) 2936 1.6 christos return NULL; 2937 1.6 christos if (! d_check_char (di, 'E')) 2938 1.6 christos return NULL; 2939 1.6 christos } 2940 1.6 christos else 2941 1.6 christos return NULL; 2942 1.5 christos } 2943 1.1 christos 2944 1.6 christos *pret = d_make_comp (di, t, NULL, right); 2945 1.1 christos if (*pret == NULL) 2946 1.1 christos return NULL; 2947 1.1 christos pret = &d_left (*pret); 2948 1.1 christos 2949 1.1 christos peek = d_peek_char (di); 2950 1.1 christos } 2951 1.1 christos 2952 1.1 christos if (!member_fn && peek == 'F') 2953 1.1 christos { 2954 1.1 christos while (pstart != pret) 2955 1.1 christos { 2956 1.1 christos switch ((*pstart)->type) 2957 1.1 christos { 2958 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 2959 1.1 christos (*pstart)->type = DEMANGLE_COMPONENT_RESTRICT_THIS; 2960 1.1 christos break; 2961 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 2962 1.1 christos (*pstart)->type = DEMANGLE_COMPONENT_VOLATILE_THIS; 2963 1.1 christos break; 2964 1.1 christos case DEMANGLE_COMPONENT_CONST: 2965 1.1 christos (*pstart)->type = DEMANGLE_COMPONENT_CONST_THIS; 2966 1.1 christos break; 2967 1.1 christos default: 2968 1.1 christos break; 2969 1.1 christos } 2970 1.1 christos pstart = &d_left (*pstart); 2971 1.1 christos } 2972 1.1 christos } 2973 1.1 christos 2974 1.1 christos return pret; 2975 1.1 christos } 2976 1.1 christos 2977 1.3 christos /* <ref-qualifier> ::= R 2978 1.3 christos ::= O */ 2979 1.3 christos 2980 1.3 christos static struct demangle_component * 2981 1.3 christos d_ref_qualifier (struct d_info *di, struct demangle_component *sub) 2982 1.3 christos { 2983 1.3 christos struct demangle_component *ret = sub; 2984 1.3 christos char peek; 2985 1.3 christos 2986 1.3 christos peek = d_peek_char (di); 2987 1.3 christos if (peek == 'R' || peek == 'O') 2988 1.3 christos { 2989 1.3 christos enum demangle_component_type t; 2990 1.3 christos if (peek == 'R') 2991 1.3 christos { 2992 1.3 christos t = DEMANGLE_COMPONENT_REFERENCE_THIS; 2993 1.3 christos di->expansion += sizeof "&"; 2994 1.3 christos } 2995 1.3 christos else 2996 1.3 christos { 2997 1.3 christos t = DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS; 2998 1.3 christos di->expansion += sizeof "&&"; 2999 1.3 christos } 3000 1.3 christos d_advance (di, 1); 3001 1.3 christos 3002 1.3 christos ret = d_make_comp (di, t, ret, NULL); 3003 1.3 christos } 3004 1.3 christos 3005 1.3 christos return ret; 3006 1.3 christos } 3007 1.3 christos 3008 1.5 christos /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */ 3009 1.1 christos 3010 1.1 christos static struct demangle_component * 3011 1.1 christos d_function_type (struct d_info *di) 3012 1.1 christos { 3013 1.7 christos struct demangle_component *ret = NULL; 3014 1.7 christos 3015 1.7 christos if ((di->options & DMGL_NO_RECURSE_LIMIT) == 0) 3016 1.7 christos { 3017 1.7 christos if (di->recursion_level > DEMANGLE_RECURSION_LIMIT) 3018 1.7 christos /* FIXME: There ought to be a way to report 3019 1.7 christos that the recursion limit has been reached. */ 3020 1.7 christos return NULL; 3021 1.7 christos 3022 1.7 christos di->recursion_level ++; 3023 1.7 christos } 3024 1.1 christos 3025 1.7 christos if (d_check_char (di, 'F')) 3026 1.1 christos { 3027 1.7 christos if (d_peek_char (di) == 'Y') 3028 1.7 christos { 3029 1.7 christos /* Function has C linkage. We don't print this information. 3030 1.7 christos FIXME: We should print it in verbose mode. */ 3031 1.7 christos d_advance (di, 1); 3032 1.7 christos } 3033 1.7 christos ret = d_bare_function_type (di, 1); 3034 1.7 christos ret = d_ref_qualifier (di, ret); 3035 1.7 christos 3036 1.7 christos if (! d_check_char (di, 'E')) 3037 1.7 christos ret = NULL; 3038 1.1 christos } 3039 1.3 christos 3040 1.7 christos if ((di->options & DMGL_NO_RECURSE_LIMIT) == 0) 3041 1.7 christos di->recursion_level --; 3042 1.1 christos return ret; 3043 1.1 christos } 3044 1.1 christos 3045 1.1 christos /* <type>+ */ 3046 1.1 christos 3047 1.1 christos static struct demangle_component * 3048 1.1 christos d_parmlist (struct d_info *di) 3049 1.1 christos { 3050 1.1 christos struct demangle_component *tl; 3051 1.1 christos struct demangle_component **ptl; 3052 1.1 christos 3053 1.1 christos tl = NULL; 3054 1.1 christos ptl = &tl; 3055 1.1 christos while (1) 3056 1.1 christos { 3057 1.1 christos struct demangle_component *type; 3058 1.1 christos 3059 1.1 christos char peek = d_peek_char (di); 3060 1.9 christos if (peek == '\0' || peek == 'E' || peek == '.' || peek == 'Q') 3061 1.1 christos break; 3062 1.3 christos if ((peek == 'R' || peek == 'O') 3063 1.3 christos && d_peek_next_char (di) == 'E') 3064 1.3 christos /* Function ref-qualifier, not a ref prefix for a parameter type. */ 3065 1.3 christos break; 3066 1.1 christos type = cplus_demangle_type (di); 3067 1.1 christos if (type == NULL) 3068 1.1 christos return NULL; 3069 1.1 christos *ptl = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, type, NULL); 3070 1.1 christos if (*ptl == NULL) 3071 1.1 christos return NULL; 3072 1.1 christos ptl = &d_right (*ptl); 3073 1.1 christos } 3074 1.1 christos 3075 1.1 christos /* There should be at least one parameter type besides the optional 3076 1.1 christos return type. A function which takes no arguments will have a 3077 1.1 christos single parameter type void. */ 3078 1.1 christos if (tl == NULL) 3079 1.1 christos return NULL; 3080 1.1 christos 3081 1.1 christos /* If we have a single parameter type void, omit it. */ 3082 1.1 christos if (d_right (tl) == NULL 3083 1.1 christos && d_left (tl)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE 3084 1.1 christos && d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID) 3085 1.1 christos { 3086 1.1 christos di->expansion -= d_left (tl)->u.s_builtin.type->len; 3087 1.1 christos d_left (tl) = NULL; 3088 1.1 christos } 3089 1.1 christos 3090 1.1 christos return tl; 3091 1.1 christos } 3092 1.1 christos 3093 1.1 christos /* <bare-function-type> ::= [J]<type>+ */ 3094 1.1 christos 3095 1.1 christos static struct demangle_component * 3096 1.1 christos d_bare_function_type (struct d_info *di, int has_return_type) 3097 1.1 christos { 3098 1.1 christos struct demangle_component *return_type; 3099 1.1 christos struct demangle_component *tl; 3100 1.1 christos char peek; 3101 1.1 christos 3102 1.1 christos /* Detect special qualifier indicating that the first argument 3103 1.1 christos is the return type. */ 3104 1.1 christos peek = d_peek_char (di); 3105 1.1 christos if (peek == 'J') 3106 1.1 christos { 3107 1.1 christos d_advance (di, 1); 3108 1.1 christos has_return_type = 1; 3109 1.1 christos } 3110 1.1 christos 3111 1.1 christos if (has_return_type) 3112 1.1 christos { 3113 1.1 christos return_type = cplus_demangle_type (di); 3114 1.1 christos if (return_type == NULL) 3115 1.1 christos return NULL; 3116 1.1 christos } 3117 1.1 christos else 3118 1.1 christos return_type = NULL; 3119 1.1 christos 3120 1.1 christos tl = d_parmlist (di); 3121 1.1 christos if (tl == NULL) 3122 1.1 christos return NULL; 3123 1.1 christos 3124 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_FUNCTION_TYPE, 3125 1.1 christos return_type, tl); 3126 1.1 christos } 3127 1.1 christos 3128 1.1 christos /* <class-enum-type> ::= <name> */ 3129 1.1 christos 3130 1.1 christos static struct demangle_component * 3131 1.8 christos d_class_enum_type (struct d_info *di, int substable) 3132 1.1 christos { 3133 1.8 christos return d_name (di, substable); 3134 1.1 christos } 3135 1.1 christos 3136 1.1 christos /* <array-type> ::= A <(positive dimension) number> _ <(element) type> 3137 1.1 christos ::= A [<(dimension) expression>] _ <(element) type> 3138 1.1 christos */ 3139 1.1 christos 3140 1.1 christos static struct demangle_component * 3141 1.1 christos d_array_type (struct d_info *di) 3142 1.1 christos { 3143 1.1 christos char peek; 3144 1.1 christos struct demangle_component *dim; 3145 1.1 christos 3146 1.1 christos if (! d_check_char (di, 'A')) 3147 1.1 christos return NULL; 3148 1.1 christos 3149 1.1 christos peek = d_peek_char (di); 3150 1.1 christos if (peek == '_') 3151 1.1 christos dim = NULL; 3152 1.1 christos else if (IS_DIGIT (peek)) 3153 1.1 christos { 3154 1.1 christos const char *s; 3155 1.1 christos 3156 1.1 christos s = d_str (di); 3157 1.1 christos do 3158 1.1 christos { 3159 1.1 christos d_advance (di, 1); 3160 1.1 christos peek = d_peek_char (di); 3161 1.1 christos } 3162 1.1 christos while (IS_DIGIT (peek)); 3163 1.1 christos dim = d_make_name (di, s, d_str (di) - s); 3164 1.1 christos if (dim == NULL) 3165 1.1 christos return NULL; 3166 1.1 christos } 3167 1.1 christos else 3168 1.1 christos { 3169 1.1 christos dim = d_expression (di); 3170 1.1 christos if (dim == NULL) 3171 1.1 christos return NULL; 3172 1.1 christos } 3173 1.1 christos 3174 1.1 christos if (! d_check_char (di, '_')) 3175 1.1 christos return NULL; 3176 1.1 christos 3177 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_ARRAY_TYPE, dim, 3178 1.1 christos cplus_demangle_type (di)); 3179 1.1 christos } 3180 1.1 christos 3181 1.1 christos /* <vector-type> ::= Dv <number> _ <type> 3182 1.1 christos ::= Dv _ <expression> _ <type> */ 3183 1.1 christos 3184 1.1 christos static struct demangle_component * 3185 1.1 christos d_vector_type (struct d_info *di) 3186 1.1 christos { 3187 1.1 christos char peek; 3188 1.1 christos struct demangle_component *dim; 3189 1.1 christos 3190 1.1 christos peek = d_peek_char (di); 3191 1.1 christos if (peek == '_') 3192 1.1 christos { 3193 1.1 christos d_advance (di, 1); 3194 1.1 christos dim = d_expression (di); 3195 1.1 christos } 3196 1.1 christos else 3197 1.1 christos dim = d_number_component (di); 3198 1.1 christos 3199 1.1 christos if (dim == NULL) 3200 1.1 christos return NULL; 3201 1.1 christos 3202 1.1 christos if (! d_check_char (di, '_')) 3203 1.1 christos return NULL; 3204 1.1 christos 3205 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_VECTOR_TYPE, dim, 3206 1.1 christos cplus_demangle_type (di)); 3207 1.1 christos } 3208 1.1 christos 3209 1.1 christos /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */ 3210 1.1 christos 3211 1.1 christos static struct demangle_component * 3212 1.1 christos d_pointer_to_member_type (struct d_info *di) 3213 1.1 christos { 3214 1.1 christos struct demangle_component *cl; 3215 1.1 christos struct demangle_component *mem; 3216 1.1 christos 3217 1.1 christos if (! d_check_char (di, 'M')) 3218 1.1 christos return NULL; 3219 1.1 christos 3220 1.1 christos cl = cplus_demangle_type (di); 3221 1.3 christos if (cl == NULL) 3222 1.3 christos return NULL; 3223 1.3 christos 3224 1.3 christos /* The ABI says, "The type of a non-static member function is considered 3225 1.3 christos to be different, for the purposes of substitution, from the type of a 3226 1.3 christos namespace-scope or static member function whose type appears 3227 1.3 christos similar. The types of two non-static member functions are considered 3228 1.3 christos to be different, for the purposes of substitution, if the functions 3229 1.3 christos are members of different classes. In other words, for the purposes of 3230 1.3 christos substitution, the class of which the function is a member is 3231 1.3 christos considered part of the type of function." 3232 1.3 christos 3233 1.3 christos For a pointer to member function, this call to cplus_demangle_type 3234 1.3 christos will end up adding a (possibly qualified) non-member function type to 3235 1.3 christos the substitution table, which is not correct; however, the member 3236 1.3 christos function type will never be used in a substitution, so putting the 3237 1.3 christos wrong type in the substitution table is harmless. */ 3238 1.1 christos 3239 1.3 christos mem = cplus_demangle_type (di); 3240 1.3 christos if (mem == NULL) 3241 1.1 christos return NULL; 3242 1.1 christos 3243 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_PTRMEM_TYPE, cl, mem); 3244 1.1 christos } 3245 1.1 christos 3246 1.1 christos /* <non-negative number> _ */ 3247 1.1 christos 3248 1.6 christos static int 3249 1.1 christos d_compact_number (struct d_info *di) 3250 1.1 christos { 3251 1.6 christos int num; 3252 1.1 christos if (d_peek_char (di) == '_') 3253 1.1 christos num = 0; 3254 1.1 christos else if (d_peek_char (di) == 'n') 3255 1.1 christos return -1; 3256 1.1 christos else 3257 1.1 christos num = d_number (di) + 1; 3258 1.1 christos 3259 1.6 christos if (num < 0 || ! d_check_char (di, '_')) 3260 1.1 christos return -1; 3261 1.1 christos return num; 3262 1.1 christos } 3263 1.1 christos 3264 1.1 christos /* <template-param> ::= T_ 3265 1.1 christos ::= T <(parameter-2 non-negative) number> _ 3266 1.1 christos */ 3267 1.1 christos 3268 1.1 christos static struct demangle_component * 3269 1.1 christos d_template_param (struct d_info *di) 3270 1.1 christos { 3271 1.6 christos int param; 3272 1.1 christos 3273 1.1 christos if (! d_check_char (di, 'T')) 3274 1.1 christos return NULL; 3275 1.1 christos 3276 1.1 christos param = d_compact_number (di); 3277 1.1 christos if (param < 0) 3278 1.1 christos return NULL; 3279 1.1 christos 3280 1.1 christos return d_make_template_param (di, param); 3281 1.1 christos } 3282 1.1 christos 3283 1.1 christos /* <template-args> ::= I <template-arg>+ E */ 3284 1.1 christos 3285 1.1 christos static struct demangle_component * 3286 1.1 christos d_template_args (struct d_info *di) 3287 1.1 christos { 3288 1.6 christos if (d_peek_char (di) != 'I' 3289 1.6 christos && d_peek_char (di) != 'J') 3290 1.6 christos return NULL; 3291 1.6 christos d_advance (di, 1); 3292 1.6 christos 3293 1.6 christos return d_template_args_1 (di); 3294 1.6 christos } 3295 1.6 christos 3296 1.9 christos /* <template-arg>* [Q <constraint-expression>] E */ 3297 1.6 christos 3298 1.6 christos static struct demangle_component * 3299 1.6 christos d_template_args_1 (struct d_info *di) 3300 1.6 christos { 3301 1.1 christos struct demangle_component *hold_last_name; 3302 1.1 christos struct demangle_component *al; 3303 1.1 christos struct demangle_component **pal; 3304 1.1 christos 3305 1.1 christos /* Preserve the last name we saw--don't let the template arguments 3306 1.1 christos clobber it, as that would give us the wrong name for a subsequent 3307 1.1 christos constructor or destructor. */ 3308 1.1 christos hold_last_name = di->last_name; 3309 1.1 christos 3310 1.1 christos if (d_peek_char (di) == 'E') 3311 1.1 christos { 3312 1.1 christos /* An argument pack can be empty. */ 3313 1.1 christos d_advance (di, 1); 3314 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, NULL, NULL); 3315 1.1 christos } 3316 1.1 christos 3317 1.1 christos al = NULL; 3318 1.1 christos pal = &al; 3319 1.1 christos while (1) 3320 1.1 christos { 3321 1.1 christos struct demangle_component *a; 3322 1.1 christos 3323 1.1 christos a = d_template_arg (di); 3324 1.1 christos if (a == NULL) 3325 1.1 christos return NULL; 3326 1.1 christos 3327 1.1 christos *pal = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, a, NULL); 3328 1.1 christos if (*pal == NULL) 3329 1.1 christos return NULL; 3330 1.1 christos pal = &d_right (*pal); 3331 1.1 christos 3332 1.9 christos char peek = d_peek_char (di); 3333 1.9 christos if (peek == 'E' || peek == 'Q') 3334 1.9 christos break; 3335 1.1 christos } 3336 1.1 christos 3337 1.9 christos al = d_maybe_constraints (di, al); 3338 1.9 christos 3339 1.9 christos if (d_peek_char (di) != 'E') 3340 1.9 christos return NULL; 3341 1.9 christos d_advance (di, 1); 3342 1.9 christos 3343 1.1 christos di->last_name = hold_last_name; 3344 1.1 christos 3345 1.1 christos return al; 3346 1.1 christos } 3347 1.1 christos 3348 1.1 christos /* <template-arg> ::= <type> 3349 1.1 christos ::= X <expression> E 3350 1.1 christos ::= <expr-primary> 3351 1.1 christos */ 3352 1.1 christos 3353 1.1 christos static struct demangle_component * 3354 1.1 christos d_template_arg (struct d_info *di) 3355 1.1 christos { 3356 1.1 christos struct demangle_component *ret; 3357 1.1 christos 3358 1.1 christos switch (d_peek_char (di)) 3359 1.1 christos { 3360 1.1 christos case 'X': 3361 1.1 christos d_advance (di, 1); 3362 1.1 christos ret = d_expression (di); 3363 1.1 christos if (! d_check_char (di, 'E')) 3364 1.1 christos return NULL; 3365 1.1 christos return ret; 3366 1.1 christos 3367 1.1 christos case 'L': 3368 1.1 christos return d_expr_primary (di); 3369 1.1 christos 3370 1.1 christos case 'I': 3371 1.1 christos case 'J': 3372 1.1 christos /* An argument pack. */ 3373 1.1 christos return d_template_args (di); 3374 1.1 christos 3375 1.1 christos default: 3376 1.1 christos return cplus_demangle_type (di); 3377 1.1 christos } 3378 1.1 christos } 3379 1.1 christos 3380 1.1 christos /* Parse a sequence of expressions until we hit the terminator 3381 1.1 christos character. */ 3382 1.1 christos 3383 1.1 christos static struct demangle_component * 3384 1.1 christos d_exprlist (struct d_info *di, char terminator) 3385 1.1 christos { 3386 1.1 christos struct demangle_component *list = NULL; 3387 1.1 christos struct demangle_component **p = &list; 3388 1.1 christos 3389 1.1 christos if (d_peek_char (di) == terminator) 3390 1.1 christos { 3391 1.1 christos d_advance (di, 1); 3392 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, NULL, NULL); 3393 1.1 christos } 3394 1.1 christos 3395 1.1 christos while (1) 3396 1.1 christos { 3397 1.1 christos struct demangle_component *arg = d_expression (di); 3398 1.1 christos if (arg == NULL) 3399 1.1 christos return NULL; 3400 1.1 christos 3401 1.1 christos *p = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, arg, NULL); 3402 1.1 christos if (*p == NULL) 3403 1.1 christos return NULL; 3404 1.1 christos p = &d_right (*p); 3405 1.1 christos 3406 1.1 christos if (d_peek_char (di) == terminator) 3407 1.1 christos { 3408 1.1 christos d_advance (di, 1); 3409 1.1 christos break; 3410 1.1 christos } 3411 1.1 christos } 3412 1.1 christos 3413 1.1 christos return list; 3414 1.1 christos } 3415 1.1 christos 3416 1.1 christos /* Returns nonzero iff OP is an operator for a C++ cast: const_cast, 3417 1.1 christos dynamic_cast, static_cast or reinterpret_cast. */ 3418 1.1 christos 3419 1.1 christos static int 3420 1.1 christos op_is_new_cast (struct demangle_component *op) 3421 1.1 christos { 3422 1.1 christos const char *code = op->u.s_operator.op->code; 3423 1.1 christos return (code[1] == 'c' 3424 1.1 christos && (code[0] == 's' || code[0] == 'd' 3425 1.1 christos || code[0] == 'c' || code[0] == 'r')); 3426 1.1 christos } 3427 1.1 christos 3428 1.8 christos /* <unresolved-name> ::= [gs] <base-unresolved-name> # x or (with "gs") ::x 3429 1.8 christos ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x 3430 1.8 christos # T::N::x /decltype(p)::N::x 3431 1.8 christos ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name> 3432 1.8 christos # A::x, N::y, A<T>::z; "gs" means leading "::" 3433 1.8 christos ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name> 3434 1.8 christos 3435 1.8 christos "gs" is handled elsewhere, as a unary operator. */ 3436 1.8 christos 3437 1.8 christos static struct demangle_component * 3438 1.8 christos d_unresolved_name (struct d_info *di) 3439 1.8 christos { 3440 1.8 christos struct demangle_component *type; 3441 1.8 christos struct demangle_component *name; 3442 1.8 christos char peek; 3443 1.8 christos 3444 1.8 christos /* Consume the "sr". */ 3445 1.8 christos d_advance (di, 2); 3446 1.8 christos 3447 1.8 christos peek = d_peek_char (di); 3448 1.8 christos if (di->unresolved_name_state 3449 1.8 christos && (IS_DIGIT (peek) 3450 1.8 christos || IS_LOWER (peek) 3451 1.8 christos || peek == 'C' 3452 1.8 christos || peek == 'U' 3453 1.8 christos || peek == 'L')) 3454 1.8 christos { 3455 1.8 christos /* The third production is ambiguous with the old unresolved-name syntax 3456 1.8 christos of <type> <base-unresolved-name>; in the old mangling, A::x was mangled 3457 1.8 christos as sr1A1x, now sr1AE1x. So we first try to demangle using the new 3458 1.8 christos mangling, then with the old if that fails. */ 3459 1.8 christos di->unresolved_name_state = -1; 3460 1.8 christos type = d_prefix (di, 0); 3461 1.8 christos if (d_peek_char (di) == 'E') 3462 1.8 christos d_advance (di, 1); 3463 1.8 christos } 3464 1.8 christos else 3465 1.8 christos type = cplus_demangle_type (di); 3466 1.8 christos name = d_unqualified_name (di, type, NULL); 3467 1.8 christos if (d_peek_char (di) == 'I') 3468 1.8 christos name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name, 3469 1.8 christos d_template_args (di)); 3470 1.8 christos return name; 3471 1.8 christos } 3472 1.8 christos 3473 1.1 christos /* <expression> ::= <(unary) operator-name> <expression> 3474 1.1 christos ::= <(binary) operator-name> <expression> <expression> 3475 1.1 christos ::= <(trinary) operator-name> <expression> <expression> <expression> 3476 1.1 christos ::= cl <expression>+ E 3477 1.1 christos ::= st <type> 3478 1.1 christos ::= <template-param> 3479 1.8 christos ::= u <source-name> <template-arg>* E # vendor extended expression 3480 1.8 christos ::= <unresolved-name> 3481 1.1 christos ::= <expr-primary> 3482 1.8 christos 3483 1.8 christos <braced-expression> ::= <expression> 3484 1.8 christos ::= di <field source-name> <braced-expression> # .name = expr 3485 1.8 christos ::= dx <index expression> <braced-expression> # [expr] = expr 3486 1.8 christos ::= dX <range begin expression> <range end expression> <braced-expression> 3487 1.8 christos # [expr ... expr] = expr 3488 1.1 christos */ 3489 1.1 christos 3490 1.8 christos static struct demangle_component * 3491 1.3 christos d_expression_1 (struct d_info *di) 3492 1.1 christos { 3493 1.1 christos char peek; 3494 1.1 christos 3495 1.1 christos peek = d_peek_char (di); 3496 1.1 christos if (peek == 'L') 3497 1.1 christos return d_expr_primary (di); 3498 1.1 christos else if (peek == 'T') 3499 1.1 christos return d_template_param (di); 3500 1.1 christos else if (peek == 's' && d_peek_next_char (di) == 'r') 3501 1.8 christos return d_unresolved_name (di); 3502 1.1 christos else if (peek == 's' && d_peek_next_char (di) == 'p') 3503 1.1 christos { 3504 1.1 christos d_advance (di, 2); 3505 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION, 3506 1.3 christos d_expression_1 (di), NULL); 3507 1.1 christos } 3508 1.1 christos else if (peek == 'f' && d_peek_next_char (di) == 'p') 3509 1.1 christos { 3510 1.1 christos /* Function parameter used in a late-specified return type. */ 3511 1.1 christos int index; 3512 1.1 christos d_advance (di, 2); 3513 1.1 christos if (d_peek_char (di) == 'T') 3514 1.1 christos { 3515 1.1 christos /* 'this' parameter. */ 3516 1.1 christos d_advance (di, 1); 3517 1.1 christos index = 0; 3518 1.1 christos } 3519 1.1 christos else 3520 1.1 christos { 3521 1.6 christos index = d_compact_number (di); 3522 1.6 christos if (index == INT_MAX || index == -1) 3523 1.1 christos return NULL; 3524 1.6 christos index++; 3525 1.1 christos } 3526 1.1 christos return d_make_function_param (di, index); 3527 1.1 christos } 3528 1.1 christos else if (IS_DIGIT (peek) 3529 1.1 christos || (peek == 'o' && d_peek_next_char (di) == 'n')) 3530 1.1 christos { 3531 1.1 christos /* We can get an unqualified name as an expression in the case of 3532 1.1 christos a dependent function call, i.e. decltype(f(t)). */ 3533 1.1 christos struct demangle_component *name; 3534 1.1 christos 3535 1.1 christos if (peek == 'o') 3536 1.1 christos /* operator-function-id, i.e. operator+(t). */ 3537 1.1 christos d_advance (di, 2); 3538 1.1 christos 3539 1.8 christos name = d_unqualified_name (di, NULL, NULL); 3540 1.1 christos if (name == NULL) 3541 1.1 christos return NULL; 3542 1.1 christos if (d_peek_char (di) == 'I') 3543 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name, 3544 1.1 christos d_template_args (di)); 3545 1.1 christos else 3546 1.1 christos return name; 3547 1.1 christos } 3548 1.1 christos else if ((peek == 'i' || peek == 't') 3549 1.1 christos && d_peek_next_char (di) == 'l') 3550 1.1 christos { 3551 1.1 christos /* Brace-enclosed initializer list, untyped or typed. */ 3552 1.1 christos struct demangle_component *type = NULL; 3553 1.7 christos d_advance (di, 2); 3554 1.1 christos if (peek == 't') 3555 1.1 christos type = cplus_demangle_type (di); 3556 1.7 christos if (!d_peek_char (di) || !d_peek_next_char (di)) 3557 1.5 christos return NULL; 3558 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST, 3559 1.1 christos type, d_exprlist (di, 'E')); 3560 1.1 christos } 3561 1.8 christos else if (peek == 'u') 3562 1.8 christos { 3563 1.8 christos /* A vendor extended expression. */ 3564 1.8 christos struct demangle_component *name, *args; 3565 1.8 christos d_advance (di, 1); 3566 1.8 christos name = d_source_name (di); 3567 1.8 christos args = d_template_args_1 (di); 3568 1.8 christos return d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_EXPR, name, args); 3569 1.8 christos } 3570 1.1 christos else 3571 1.1 christos { 3572 1.1 christos struct demangle_component *op; 3573 1.1 christos const char *code = NULL; 3574 1.1 christos int args; 3575 1.1 christos 3576 1.1 christos op = d_operator_name (di); 3577 1.1 christos if (op == NULL) 3578 1.1 christos return NULL; 3579 1.1 christos 3580 1.1 christos if (op->type == DEMANGLE_COMPONENT_OPERATOR) 3581 1.1 christos { 3582 1.1 christos code = op->u.s_operator.op->code; 3583 1.1 christos di->expansion += op->u.s_operator.op->len - 2; 3584 1.1 christos if (strcmp (code, "st") == 0) 3585 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, 3586 1.1 christos cplus_demangle_type (di)); 3587 1.1 christos } 3588 1.1 christos 3589 1.1 christos switch (op->type) 3590 1.1 christos { 3591 1.1 christos default: 3592 1.1 christos return NULL; 3593 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 3594 1.1 christos args = op->u.s_operator.op->args; 3595 1.1 christos break; 3596 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 3597 1.1 christos args = op->u.s_extended_operator.args; 3598 1.1 christos break; 3599 1.1 christos case DEMANGLE_COMPONENT_CAST: 3600 1.1 christos args = 1; 3601 1.1 christos break; 3602 1.1 christos } 3603 1.1 christos 3604 1.1 christos switch (args) 3605 1.1 christos { 3606 1.1 christos case 0: 3607 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_NULLARY, op, NULL); 3608 1.1 christos 3609 1.1 christos case 1: 3610 1.1 christos { 3611 1.1 christos struct demangle_component *operand; 3612 1.1 christos int suffix = 0; 3613 1.1 christos 3614 1.1 christos if (code && (code[0] == 'p' || code[0] == 'm') 3615 1.1 christos && code[1] == code[0]) 3616 1.1 christos /* pp_ and mm_ are the prefix variants. */ 3617 1.1 christos suffix = !d_check_char (di, '_'); 3618 1.1 christos 3619 1.1 christos if (op->type == DEMANGLE_COMPONENT_CAST 3620 1.1 christos && d_check_char (di, '_')) 3621 1.1 christos operand = d_exprlist (di, 'E'); 3622 1.6 christos else if (code && !strcmp (code, "sP")) 3623 1.6 christos operand = d_template_args_1 (di); 3624 1.1 christos else 3625 1.3 christos operand = d_expression_1 (di); 3626 1.1 christos 3627 1.1 christos if (suffix) 3628 1.1 christos /* Indicate the suffix variant for d_print_comp. */ 3629 1.6 christos operand = d_make_comp (di, DEMANGLE_COMPONENT_BINARY_ARGS, 3630 1.6 christos operand, operand); 3631 1.6 christos 3632 1.6 christos return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, operand); 3633 1.1 christos } 3634 1.1 christos case 2: 3635 1.1 christos { 3636 1.1 christos struct demangle_component *left; 3637 1.1 christos struct demangle_component *right; 3638 1.1 christos 3639 1.5 christos if (code == NULL) 3640 1.5 christos return NULL; 3641 1.1 christos if (op_is_new_cast (op)) 3642 1.1 christos left = cplus_demangle_type (di); 3643 1.6 christos else if (code[0] == 'f') 3644 1.6 christos /* fold-expression. */ 3645 1.6 christos left = d_operator_name (di); 3646 1.8 christos else if (!strcmp (code, "di")) 3647 1.8 christos left = d_unqualified_name (di, NULL, NULL); 3648 1.1 christos else 3649 1.3 christos left = d_expression_1 (di); 3650 1.1 christos if (!strcmp (code, "cl")) 3651 1.1 christos right = d_exprlist (di, 'E'); 3652 1.1 christos else if (!strcmp (code, "dt") || !strcmp (code, "pt")) 3653 1.1 christos { 3654 1.8 christos peek = d_peek_char (di); 3655 1.8 christos /* These codes start a qualified name. */ 3656 1.8 christos if ((peek == 'g' && d_peek_next_char (di) == 's') 3657 1.8 christos || (peek == 's' && d_peek_next_char (di) == 'r')) 3658 1.8 christos right = d_expression_1 (di); 3659 1.8 christos else 3660 1.8 christos { 3661 1.8 christos /* Otherwise it's an unqualified name. We use 3662 1.8 christos d_unqualified_name rather than d_expression_1 here for 3663 1.8 christos old mangled names that didn't add 'on' before operator 3664 1.8 christos names. */ 3665 1.8 christos right = d_unqualified_name (di, NULL, NULL); 3666 1.8 christos if (d_peek_char (di) == 'I') 3667 1.8 christos right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, 3668 1.8 christos right, d_template_args (di)); 3669 1.8 christos } 3670 1.1 christos } 3671 1.1 christos else 3672 1.3 christos right = d_expression_1 (di); 3673 1.1 christos 3674 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_BINARY, op, 3675 1.1 christos d_make_comp (di, 3676 1.1 christos DEMANGLE_COMPONENT_BINARY_ARGS, 3677 1.1 christos left, right)); 3678 1.1 christos } 3679 1.1 christos case 3: 3680 1.1 christos { 3681 1.1 christos struct demangle_component *first; 3682 1.1 christos struct demangle_component *second; 3683 1.1 christos struct demangle_component *third; 3684 1.1 christos 3685 1.5 christos if (code == NULL) 3686 1.5 christos return NULL; 3687 1.8 christos else if (!strcmp (code, "qu") 3688 1.8 christos || !strcmp (code, "dX")) 3689 1.1 christos { 3690 1.1 christos /* ?: expression. */ 3691 1.3 christos first = d_expression_1 (di); 3692 1.3 christos second = d_expression_1 (di); 3693 1.3 christos third = d_expression_1 (di); 3694 1.6 christos if (third == NULL) 3695 1.6 christos return NULL; 3696 1.6 christos } 3697 1.6 christos else if (code[0] == 'f') 3698 1.6 christos { 3699 1.6 christos /* fold-expression. */ 3700 1.6 christos first = d_operator_name (di); 3701 1.6 christos second = d_expression_1 (di); 3702 1.6 christos third = d_expression_1 (di); 3703 1.6 christos if (third == NULL) 3704 1.6 christos return NULL; 3705 1.1 christos } 3706 1.1 christos else if (code[0] == 'n') 3707 1.1 christos { 3708 1.1 christos /* new-expression. */ 3709 1.1 christos if (code[1] != 'w' && code[1] != 'a') 3710 1.1 christos return NULL; 3711 1.1 christos first = d_exprlist (di, '_'); 3712 1.1 christos second = cplus_demangle_type (di); 3713 1.1 christos if (d_peek_char (di) == 'E') 3714 1.1 christos { 3715 1.1 christos d_advance (di, 1); 3716 1.1 christos third = NULL; 3717 1.1 christos } 3718 1.1 christos else if (d_peek_char (di) == 'p' 3719 1.1 christos && d_peek_next_char (di) == 'i') 3720 1.1 christos { 3721 1.1 christos /* Parenthesized initializer. */ 3722 1.1 christos d_advance (di, 2); 3723 1.1 christos third = d_exprlist (di, 'E'); 3724 1.1 christos } 3725 1.1 christos else if (d_peek_char (di) == 'i' 3726 1.1 christos && d_peek_next_char (di) == 'l') 3727 1.1 christos /* initializer-list. */ 3728 1.3 christos third = d_expression_1 (di); 3729 1.1 christos else 3730 1.1 christos return NULL; 3731 1.1 christos } 3732 1.1 christos else 3733 1.1 christos return NULL; 3734 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op, 3735 1.1 christos d_make_comp (di, 3736 1.1 christos DEMANGLE_COMPONENT_TRINARY_ARG1, 3737 1.1 christos first, 3738 1.1 christos d_make_comp (di, 3739 1.1 christos DEMANGLE_COMPONENT_TRINARY_ARG2, 3740 1.1 christos second, third))); 3741 1.1 christos } 3742 1.1 christos default: 3743 1.1 christos return NULL; 3744 1.1 christos } 3745 1.1 christos } 3746 1.1 christos } 3747 1.1 christos 3748 1.3 christos static struct demangle_component * 3749 1.3 christos d_expression (struct d_info *di) 3750 1.3 christos { 3751 1.3 christos struct demangle_component *ret; 3752 1.3 christos int was_expression = di->is_expression; 3753 1.3 christos 3754 1.3 christos di->is_expression = 1; 3755 1.3 christos ret = d_expression_1 (di); 3756 1.3 christos di->is_expression = was_expression; 3757 1.3 christos return ret; 3758 1.3 christos } 3759 1.3 christos 3760 1.1 christos /* <expr-primary> ::= L <type> <(value) number> E 3761 1.1 christos ::= L <type> <(value) float> E 3762 1.1 christos ::= L <mangled-name> E 3763 1.1 christos */ 3764 1.1 christos 3765 1.1 christos static struct demangle_component * 3766 1.1 christos d_expr_primary (struct d_info *di) 3767 1.1 christos { 3768 1.1 christos struct demangle_component *ret; 3769 1.1 christos 3770 1.1 christos if (! d_check_char (di, 'L')) 3771 1.1 christos return NULL; 3772 1.1 christos if (d_peek_char (di) == '_' 3773 1.1 christos /* Workaround for G++ bug; see comment in write_template_arg. */ 3774 1.1 christos || d_peek_char (di) == 'Z') 3775 1.1 christos ret = cplus_demangle_mangled_name (di, 0); 3776 1.1 christos else 3777 1.1 christos { 3778 1.1 christos struct demangle_component *type; 3779 1.1 christos enum demangle_component_type t; 3780 1.1 christos const char *s; 3781 1.1 christos 3782 1.1 christos type = cplus_demangle_type (di); 3783 1.1 christos if (type == NULL) 3784 1.1 christos return NULL; 3785 1.1 christos 3786 1.1 christos /* If we have a type we know how to print, we aren't going to 3787 1.1 christos print the type name itself. */ 3788 1.1 christos if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE 3789 1.1 christos && type->u.s_builtin.type->print != D_PRINT_DEFAULT) 3790 1.1 christos di->expansion -= type->u.s_builtin.type->len; 3791 1.1 christos 3792 1.7 christos if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE 3793 1.7 christos && strcmp (type->u.s_builtin.type->name, 3794 1.7 christos cplus_demangle_builtin_types[33].name) == 0) 3795 1.7 christos { 3796 1.7 christos if (d_peek_char (di) == 'E') 3797 1.7 christos { 3798 1.7 christos d_advance (di, 1); 3799 1.7 christos return type; 3800 1.7 christos } 3801 1.7 christos } 3802 1.7 christos 3803 1.1 christos /* Rather than try to interpret the literal value, we just 3804 1.1 christos collect it as a string. Note that it's possible to have a 3805 1.1 christos floating point literal here. The ABI specifies that the 3806 1.1 christos format of such literals is machine independent. That's fine, 3807 1.1 christos but what's not fine is that versions of g++ up to 3.2 with 3808 1.1 christos -fabi-version=1 used upper case letters in the hex constant, 3809 1.1 christos and dumped out gcc's internal representation. That makes it 3810 1.1 christos hard to tell where the constant ends, and hard to dump the 3811 1.1 christos constant in any readable form anyhow. We don't attempt to 3812 1.1 christos handle these cases. */ 3813 1.1 christos 3814 1.1 christos t = DEMANGLE_COMPONENT_LITERAL; 3815 1.1 christos if (d_peek_char (di) == 'n') 3816 1.1 christos { 3817 1.1 christos t = DEMANGLE_COMPONENT_LITERAL_NEG; 3818 1.1 christos d_advance (di, 1); 3819 1.1 christos } 3820 1.1 christos s = d_str (di); 3821 1.1 christos while (d_peek_char (di) != 'E') 3822 1.1 christos { 3823 1.1 christos if (d_peek_char (di) == '\0') 3824 1.1 christos return NULL; 3825 1.1 christos d_advance (di, 1); 3826 1.1 christos } 3827 1.1 christos ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s)); 3828 1.1 christos } 3829 1.1 christos if (! d_check_char (di, 'E')) 3830 1.1 christos return NULL; 3831 1.1 christos return ret; 3832 1.1 christos } 3833 1.1 christos 3834 1.1 christos /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>] 3835 1.1 christos ::= Z <(function) encoding> E s [<discriminator>] 3836 1.3 christos ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name> 3837 1.1 christos */ 3838 1.1 christos 3839 1.1 christos static struct demangle_component * 3840 1.1 christos d_local_name (struct d_info *di) 3841 1.1 christos { 3842 1.1 christos struct demangle_component *function; 3843 1.6 christos struct demangle_component *name; 3844 1.1 christos 3845 1.1 christos if (! d_check_char (di, 'Z')) 3846 1.1 christos return NULL; 3847 1.1 christos 3848 1.1 christos function = d_encoding (di, 0); 3849 1.6 christos if (!function) 3850 1.6 christos return NULL; 3851 1.1 christos 3852 1.1 christos if (! d_check_char (di, 'E')) 3853 1.1 christos return NULL; 3854 1.1 christos 3855 1.1 christos if (d_peek_char (di) == 's') 3856 1.1 christos { 3857 1.1 christos d_advance (di, 1); 3858 1.1 christos if (! d_discriminator (di)) 3859 1.1 christos return NULL; 3860 1.6 christos name = d_make_name (di, "string literal", sizeof "string literal" - 1); 3861 1.1 christos } 3862 1.1 christos else 3863 1.1 christos { 3864 1.1 christos int num = -1; 3865 1.1 christos 3866 1.1 christos if (d_peek_char (di) == 'd') 3867 1.1 christos { 3868 1.1 christos /* Default argument scope: d <number> _. */ 3869 1.1 christos d_advance (di, 1); 3870 1.1 christos num = d_compact_number (di); 3871 1.1 christos if (num < 0) 3872 1.1 christos return NULL; 3873 1.1 christos } 3874 1.1 christos 3875 1.8 christos name = d_name (di, 0); 3876 1.6 christos 3877 1.6 christos if (name 3878 1.6 christos /* Lambdas and unnamed types have internal discriminators 3879 1.6 christos and are not functions. */ 3880 1.6 christos && name->type != DEMANGLE_COMPONENT_LAMBDA 3881 1.6 christos && name->type != DEMANGLE_COMPONENT_UNNAMED_TYPE) 3882 1.6 christos { 3883 1.6 christos /* Read and ignore an optional discriminator. */ 3884 1.6 christos if (! d_discriminator (di)) 3885 1.6 christos return NULL; 3886 1.6 christos } 3887 1.6 christos 3888 1.1 christos if (num >= 0) 3889 1.1 christos name = d_make_default_arg (di, num, name); 3890 1.1 christos } 3891 1.6 christos 3892 1.6 christos /* Elide the return type of the containing function so as to not 3893 1.6 christos confuse the user thinking it is the return type of whatever local 3894 1.6 christos function we might be containing. */ 3895 1.6 christos if (function->type == DEMANGLE_COMPONENT_TYPED_NAME 3896 1.6 christos && d_right (function)->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) 3897 1.6 christos d_left (d_right (function)) = NULL; 3898 1.6 christos 3899 1.6 christos return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name); 3900 1.1 christos } 3901 1.1 christos 3902 1.6 christos /* <discriminator> ::= _ <number> # when number < 10 3903 1.6 christos ::= __ <number> _ # when number >= 10 3904 1.6 christos 3905 1.6 christos <discriminator> ::= _ <number> # when number >=10 3906 1.6 christos is also accepted to support gcc versions that wrongly mangled that way. 3907 1.1 christos 3908 1.1 christos We demangle the discriminator, but we don't print it out. FIXME: 3909 1.1 christos We should print it out in verbose mode. */ 3910 1.1 christos 3911 1.1 christos static int 3912 1.1 christos d_discriminator (struct d_info *di) 3913 1.1 christos { 3914 1.6 christos int discrim, num_underscores = 1; 3915 1.1 christos 3916 1.1 christos if (d_peek_char (di) != '_') 3917 1.1 christos return 1; 3918 1.1 christos d_advance (di, 1); 3919 1.6 christos if (d_peek_char (di) == '_') 3920 1.6 christos { 3921 1.6 christos ++num_underscores; 3922 1.6 christos d_advance (di, 1); 3923 1.6 christos } 3924 1.6 christos 3925 1.1 christos discrim = d_number (di); 3926 1.1 christos if (discrim < 0) 3927 1.1 christos return 0; 3928 1.6 christos if (num_underscores > 1 && discrim >= 10) 3929 1.6 christos { 3930 1.6 christos if (d_peek_char (di) == '_') 3931 1.6 christos d_advance (di, 1); 3932 1.6 christos else 3933 1.6 christos return 0; 3934 1.6 christos } 3935 1.6 christos 3936 1.1 christos return 1; 3937 1.1 christos } 3938 1.1 christos 3939 1.9 christos /* <template-parm> ::= Ty 3940 1.9 christos ::= Tn <type> 3941 1.9 christos ::= Tt <template-head> E 3942 1.9 christos ::= Tp <template-parm> */ 3943 1.9 christos 3944 1.9 christos static struct demangle_component * 3945 1.9 christos d_template_parm (struct d_info *di, int *bad) 3946 1.9 christos { 3947 1.9 christos if (d_peek_char (di) != 'T') 3948 1.9 christos return NULL; 3949 1.9 christos 3950 1.9 christos struct demangle_component *op; 3951 1.9 christos enum demangle_component_type kind; 3952 1.9 christos switch (d_peek_next_char (di)) 3953 1.9 christos { 3954 1.9 christos default: 3955 1.9 christos return NULL; 3956 1.9 christos 3957 1.9 christos case 'p': /* Pack */ 3958 1.9 christos d_advance (di, 2); 3959 1.9 christos op = d_template_parm (di, bad); 3960 1.9 christos kind = DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM; 3961 1.9 christos if (!op) 3962 1.9 christos { 3963 1.9 christos *bad = 1; 3964 1.9 christos return NULL; 3965 1.9 christos } 3966 1.9 christos break; 3967 1.9 christos 3968 1.9 christos case 'y': /* Typename */ 3969 1.9 christos d_advance (di, 2); 3970 1.9 christos op = NULL; 3971 1.9 christos kind = DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM; 3972 1.9 christos break; 3973 1.9 christos 3974 1.9 christos case 'n': /* Non-Type */ 3975 1.9 christos d_advance (di, 2); 3976 1.9 christos op = cplus_demangle_type (di); 3977 1.9 christos kind = DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM; 3978 1.9 christos if (!op) 3979 1.9 christos { 3980 1.9 christos *bad = 1; 3981 1.9 christos return NULL; 3982 1.9 christos } 3983 1.9 christos break; 3984 1.9 christos 3985 1.9 christos case 't': /* Template */ 3986 1.9 christos d_advance (di, 2); 3987 1.9 christos op = d_template_head (di, bad); 3988 1.9 christos kind = DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM; 3989 1.9 christos if (!op || !d_check_char (di, 'E')) 3990 1.9 christos { 3991 1.9 christos *bad = 1; 3992 1.9 christos return NULL; 3993 1.9 christos } 3994 1.9 christos } 3995 1.9 christos 3996 1.9 christos return d_make_comp (di, kind, op, NULL); 3997 1.9 christos } 3998 1.9 christos 3999 1.9 christos /* <template-head> ::= <template-head>? <template-parm> */ 4000 1.9 christos 4001 1.9 christos static struct demangle_component * 4002 1.9 christos d_template_head (struct d_info *di, int *bad) 4003 1.9 christos { 4004 1.9 christos struct demangle_component *res = NULL, **slot = &res; 4005 1.9 christos struct demangle_component *op; 4006 1.9 christos 4007 1.9 christos while ((op = d_template_parm (di, bad))) 4008 1.9 christos { 4009 1.9 christos *slot = op; 4010 1.9 christos slot = &d_right (op); 4011 1.9 christos } 4012 1.9 christos 4013 1.9 christos /* Wrap it in a template head, to make concatenating with any parm list, and 4014 1.9 christos printing simpler. */ 4015 1.9 christos if (res) 4016 1.9 christos res = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_HEAD, res, NULL); 4017 1.9 christos 4018 1.9 christos return res; 4019 1.9 christos } 4020 1.9 christos 4021 1.9 christos /* <closure-type-name> ::= Ul <template-head>? <lambda-sig> E [ <nonnegative number> ] _ */ 4022 1.1 christos 4023 1.1 christos static struct demangle_component * 4024 1.1 christos d_lambda (struct d_info *di) 4025 1.1 christos { 4026 1.1 christos if (! d_check_char (di, 'U')) 4027 1.1 christos return NULL; 4028 1.1 christos if (! d_check_char (di, 'l')) 4029 1.1 christos return NULL; 4030 1.1 christos 4031 1.9 christos int bad = 0; 4032 1.9 christos struct demangle_component *head = d_template_head (di, &bad); 4033 1.9 christos if (bad) 4034 1.9 christos return NULL; 4035 1.9 christos 4036 1.9 christos struct demangle_component *tl = d_parmlist (di); 4037 1.1 christos if (tl == NULL) 4038 1.1 christos return NULL; 4039 1.9 christos if (head) 4040 1.9 christos { 4041 1.9 christos d_right (head) = tl; 4042 1.9 christos tl = head; 4043 1.9 christos } 4044 1.1 christos 4045 1.1 christos if (! d_check_char (di, 'E')) 4046 1.1 christos return NULL; 4047 1.1 christos 4048 1.9 christos int num = d_compact_number (di); 4049 1.1 christos if (num < 0) 4050 1.1 christos return NULL; 4051 1.1 christos 4052 1.9 christos struct demangle_component *ret = d_make_empty (di); 4053 1.1 christos if (ret) 4054 1.1 christos { 4055 1.1 christos ret->type = DEMANGLE_COMPONENT_LAMBDA; 4056 1.1 christos ret->u.s_unary_num.sub = tl; 4057 1.1 christos ret->u.s_unary_num.num = num; 4058 1.1 christos } 4059 1.1 christos 4060 1.1 christos return ret; 4061 1.1 christos } 4062 1.1 christos 4063 1.1 christos /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */ 4064 1.1 christos 4065 1.1 christos static struct demangle_component * 4066 1.1 christos d_unnamed_type (struct d_info *di) 4067 1.1 christos { 4068 1.1 christos struct demangle_component *ret; 4069 1.6 christos int num; 4070 1.1 christos 4071 1.1 christos if (! d_check_char (di, 'U')) 4072 1.1 christos return NULL; 4073 1.1 christos if (! d_check_char (di, 't')) 4074 1.1 christos return NULL; 4075 1.1 christos 4076 1.1 christos num = d_compact_number (di); 4077 1.1 christos if (num < 0) 4078 1.1 christos return NULL; 4079 1.1 christos 4080 1.1 christos ret = d_make_empty (di); 4081 1.1 christos if (ret) 4082 1.1 christos { 4083 1.1 christos ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE; 4084 1.1 christos ret->u.s_number.number = num; 4085 1.1 christos } 4086 1.1 christos 4087 1.1 christos if (! d_add_substitution (di, ret)) 4088 1.1 christos return NULL; 4089 1.1 christos 4090 1.1 christos return ret; 4091 1.1 christos } 4092 1.1 christos 4093 1.1 christos /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]* 4094 1.1 christos */ 4095 1.1 christos 4096 1.1 christos static struct demangle_component * 4097 1.1 christos d_clone_suffix (struct d_info *di, struct demangle_component *encoding) 4098 1.1 christos { 4099 1.1 christos const char *suffix = d_str (di); 4100 1.1 christos const char *pend = suffix; 4101 1.1 christos struct demangle_component *n; 4102 1.1 christos 4103 1.8 christos if (*pend == '.' && (IS_LOWER (pend[1]) || IS_DIGIT (pend[1]) 4104 1.8 christos || pend[1] == '_')) 4105 1.1 christos { 4106 1.1 christos pend += 2; 4107 1.8 christos while (IS_LOWER (*pend) || IS_DIGIT (*pend) || *pend == '_') 4108 1.1 christos ++pend; 4109 1.1 christos } 4110 1.1 christos while (*pend == '.' && IS_DIGIT (pend[1])) 4111 1.1 christos { 4112 1.1 christos pend += 2; 4113 1.1 christos while (IS_DIGIT (*pend)) 4114 1.1 christos ++pend; 4115 1.1 christos } 4116 1.1 christos d_advance (di, pend - suffix); 4117 1.1 christos n = d_make_name (di, suffix, pend - suffix); 4118 1.1 christos return d_make_comp (di, DEMANGLE_COMPONENT_CLONE, encoding, n); 4119 1.1 christos } 4120 1.1 christos 4121 1.1 christos /* Add a new substitution. */ 4122 1.1 christos 4123 1.1 christos static int 4124 1.1 christos d_add_substitution (struct d_info *di, struct demangle_component *dc) 4125 1.1 christos { 4126 1.1 christos if (dc == NULL) 4127 1.1 christos return 0; 4128 1.1 christos if (di->next_sub >= di->num_subs) 4129 1.1 christos return 0; 4130 1.1 christos di->subs[di->next_sub] = dc; 4131 1.1 christos ++di->next_sub; 4132 1.1 christos return 1; 4133 1.1 christos } 4134 1.1 christos 4135 1.1 christos /* <substitution> ::= S <seq-id> _ 4136 1.1 christos ::= S_ 4137 1.1 christos ::= St 4138 1.1 christos ::= Sa 4139 1.1 christos ::= Sb 4140 1.1 christos ::= Ss 4141 1.1 christos ::= Si 4142 1.1 christos ::= So 4143 1.1 christos ::= Sd 4144 1.1 christos 4145 1.1 christos If PREFIX is non-zero, then this type is being used as a prefix in 4146 1.1 christos a qualified name. In this case, for the standard substitutions, we 4147 1.1 christos need to check whether we are being used as a prefix for a 4148 1.1 christos constructor or destructor, and return a full template name. 4149 1.1 christos Otherwise we will get something like std::iostream::~iostream() 4150 1.1 christos which does not correspond particularly well to any function which 4151 1.1 christos actually appears in the source. 4152 1.1 christos */ 4153 1.1 christos 4154 1.1 christos static const struct d_standard_sub_info standard_subs[] = 4155 1.1 christos { 4156 1.1 christos { 't', NL ("std"), 4157 1.1 christos NL ("std"), 4158 1.1 christos NULL, 0 }, 4159 1.1 christos { 'a', NL ("std::allocator"), 4160 1.1 christos NL ("std::allocator"), 4161 1.1 christos NL ("allocator") }, 4162 1.1 christos { 'b', NL ("std::basic_string"), 4163 1.1 christos NL ("std::basic_string"), 4164 1.1 christos NL ("basic_string") }, 4165 1.1 christos { 's', NL ("std::string"), 4166 1.1 christos NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"), 4167 1.1 christos NL ("basic_string") }, 4168 1.1 christos { 'i', NL ("std::istream"), 4169 1.1 christos NL ("std::basic_istream<char, std::char_traits<char> >"), 4170 1.1 christos NL ("basic_istream") }, 4171 1.1 christos { 'o', NL ("std::ostream"), 4172 1.1 christos NL ("std::basic_ostream<char, std::char_traits<char> >"), 4173 1.1 christos NL ("basic_ostream") }, 4174 1.1 christos { 'd', NL ("std::iostream"), 4175 1.1 christos NL ("std::basic_iostream<char, std::char_traits<char> >"), 4176 1.1 christos NL ("basic_iostream") } 4177 1.1 christos }; 4178 1.1 christos 4179 1.1 christos static struct demangle_component * 4180 1.1 christos d_substitution (struct d_info *di, int prefix) 4181 1.1 christos { 4182 1.1 christos char c; 4183 1.1 christos 4184 1.1 christos if (! d_check_char (di, 'S')) 4185 1.1 christos return NULL; 4186 1.1 christos 4187 1.1 christos c = d_next_char (di); 4188 1.1 christos if (c == '_' || IS_DIGIT (c) || IS_UPPER (c)) 4189 1.1 christos { 4190 1.1 christos unsigned int id; 4191 1.1 christos 4192 1.1 christos id = 0; 4193 1.1 christos if (c != '_') 4194 1.1 christos { 4195 1.1 christos do 4196 1.1 christos { 4197 1.1 christos unsigned int new_id; 4198 1.1 christos 4199 1.1 christos if (IS_DIGIT (c)) 4200 1.1 christos new_id = id * 36 + c - '0'; 4201 1.1 christos else if (IS_UPPER (c)) 4202 1.1 christos new_id = id * 36 + c - 'A' + 10; 4203 1.1 christos else 4204 1.1 christos return NULL; 4205 1.1 christos if (new_id < id) 4206 1.1 christos return NULL; 4207 1.1 christos id = new_id; 4208 1.1 christos c = d_next_char (di); 4209 1.1 christos } 4210 1.1 christos while (c != '_'); 4211 1.1 christos 4212 1.1 christos ++id; 4213 1.1 christos } 4214 1.1 christos 4215 1.1 christos if (id >= (unsigned int) di->next_sub) 4216 1.1 christos return NULL; 4217 1.1 christos 4218 1.1 christos return di->subs[id]; 4219 1.1 christos } 4220 1.1 christos else 4221 1.1 christos { 4222 1.1 christos int verbose; 4223 1.1 christos const struct d_standard_sub_info *p; 4224 1.1 christos const struct d_standard_sub_info *pend; 4225 1.1 christos 4226 1.1 christos verbose = (di->options & DMGL_VERBOSE) != 0; 4227 1.1 christos if (! verbose && prefix) 4228 1.1 christos { 4229 1.1 christos char peek; 4230 1.1 christos 4231 1.1 christos peek = d_peek_char (di); 4232 1.1 christos if (peek == 'C' || peek == 'D') 4233 1.1 christos verbose = 1; 4234 1.1 christos } 4235 1.1 christos 4236 1.1 christos pend = (&standard_subs[0] 4237 1.1 christos + sizeof standard_subs / sizeof standard_subs[0]); 4238 1.1 christos for (p = &standard_subs[0]; p < pend; ++p) 4239 1.1 christos { 4240 1.1 christos if (c == p->code) 4241 1.1 christos { 4242 1.1 christos const char *s; 4243 1.1 christos int len; 4244 1.6 christos struct demangle_component *dc; 4245 1.1 christos 4246 1.1 christos if (p->set_last_name != NULL) 4247 1.1 christos di->last_name = d_make_sub (di, p->set_last_name, 4248 1.1 christos p->set_last_name_len); 4249 1.1 christos if (verbose) 4250 1.1 christos { 4251 1.1 christos s = p->full_expansion; 4252 1.1 christos len = p->full_len; 4253 1.1 christos } 4254 1.1 christos else 4255 1.1 christos { 4256 1.1 christos s = p->simple_expansion; 4257 1.1 christos len = p->simple_len; 4258 1.1 christos } 4259 1.1 christos di->expansion += len; 4260 1.6 christos dc = d_make_sub (di, s, len); 4261 1.3 christos if (d_peek_char (di) == 'B') 4262 1.3 christos { 4263 1.3 christos /* If there are ABI tags on the abbreviation, it becomes 4264 1.3 christos a substitution candidate. */ 4265 1.6 christos dc = d_abi_tags (di, dc); 4266 1.6 christos if (! d_add_substitution (di, dc)) 4267 1.6 christos return NULL; 4268 1.3 christos } 4269 1.6 christos return dc; 4270 1.1 christos } 4271 1.1 christos } 4272 1.1 christos 4273 1.1 christos return NULL; 4274 1.1 christos } 4275 1.1 christos } 4276 1.1 christos 4277 1.3 christos static void 4278 1.3 christos d_checkpoint (struct d_info *di, struct d_info_checkpoint *checkpoint) 4279 1.3 christos { 4280 1.3 christos checkpoint->n = di->n; 4281 1.3 christos checkpoint->next_comp = di->next_comp; 4282 1.3 christos checkpoint->next_sub = di->next_sub; 4283 1.3 christos checkpoint->expansion = di->expansion; 4284 1.3 christos } 4285 1.3 christos 4286 1.3 christos static void 4287 1.3 christos d_backtrack (struct d_info *di, struct d_info_checkpoint *checkpoint) 4288 1.3 christos { 4289 1.3 christos di->n = checkpoint->n; 4290 1.3 christos di->next_comp = checkpoint->next_comp; 4291 1.3 christos di->next_sub = checkpoint->next_sub; 4292 1.3 christos di->expansion = checkpoint->expansion; 4293 1.3 christos } 4294 1.3 christos 4295 1.1 christos /* Initialize a growable string. */ 4296 1.1 christos 4297 1.1 christos static void 4298 1.1 christos d_growable_string_init (struct d_growable_string *dgs, size_t estimate) 4299 1.1 christos { 4300 1.1 christos dgs->buf = NULL; 4301 1.1 christos dgs->len = 0; 4302 1.1 christos dgs->alc = 0; 4303 1.1 christos dgs->allocation_failure = 0; 4304 1.1 christos 4305 1.1 christos if (estimate > 0) 4306 1.1 christos d_growable_string_resize (dgs, estimate); 4307 1.1 christos } 4308 1.1 christos 4309 1.1 christos /* Grow a growable string to a given size. */ 4310 1.1 christos 4311 1.1 christos static inline void 4312 1.1 christos d_growable_string_resize (struct d_growable_string *dgs, size_t need) 4313 1.1 christos { 4314 1.1 christos size_t newalc; 4315 1.1 christos char *newbuf; 4316 1.1 christos 4317 1.1 christos if (dgs->allocation_failure) 4318 1.1 christos return; 4319 1.1 christos 4320 1.1 christos /* Start allocation at two bytes to avoid any possibility of confusion 4321 1.1 christos with the special value of 1 used as a return in *palc to indicate 4322 1.1 christos allocation failures. */ 4323 1.1 christos newalc = dgs->alc > 0 ? dgs->alc : 2; 4324 1.1 christos while (newalc < need) 4325 1.1 christos newalc <<= 1; 4326 1.1 christos 4327 1.1 christos newbuf = (char *) realloc (dgs->buf, newalc); 4328 1.1 christos if (newbuf == NULL) 4329 1.1 christos { 4330 1.1 christos free (dgs->buf); 4331 1.1 christos dgs->buf = NULL; 4332 1.1 christos dgs->len = 0; 4333 1.1 christos dgs->alc = 0; 4334 1.1 christos dgs->allocation_failure = 1; 4335 1.1 christos return; 4336 1.1 christos } 4337 1.1 christos dgs->buf = newbuf; 4338 1.1 christos dgs->alc = newalc; 4339 1.1 christos } 4340 1.1 christos 4341 1.1 christos /* Append a buffer to a growable string. */ 4342 1.1 christos 4343 1.1 christos static inline void 4344 1.1 christos d_growable_string_append_buffer (struct d_growable_string *dgs, 4345 1.1 christos const char *s, size_t l) 4346 1.1 christos { 4347 1.1 christos size_t need; 4348 1.1 christos 4349 1.1 christos need = dgs->len + l + 1; 4350 1.1 christos if (need > dgs->alc) 4351 1.1 christos d_growable_string_resize (dgs, need); 4352 1.1 christos 4353 1.1 christos if (dgs->allocation_failure) 4354 1.1 christos return; 4355 1.1 christos 4356 1.1 christos memcpy (dgs->buf + dgs->len, s, l); 4357 1.1 christos dgs->buf[dgs->len + l] = '\0'; 4358 1.1 christos dgs->len += l; 4359 1.1 christos } 4360 1.1 christos 4361 1.1 christos /* Bridge growable strings to the callback mechanism. */ 4362 1.1 christos 4363 1.1 christos static void 4364 1.1 christos d_growable_string_callback_adapter (const char *s, size_t l, void *opaque) 4365 1.1 christos { 4366 1.1 christos struct d_growable_string *dgs = (struct d_growable_string*) opaque; 4367 1.1 christos 4368 1.1 christos d_growable_string_append_buffer (dgs, s, l); 4369 1.1 christos } 4370 1.1 christos 4371 1.3 christos /* Walk the tree, counting the number of templates encountered, and 4372 1.3 christos the number of times a scope might be saved. These counts will be 4373 1.3 christos used to allocate data structures for d_print_comp, so the logic 4374 1.3 christos here must mirror the logic d_print_comp will use. It is not 4375 1.3 christos important that the resulting numbers are exact, so long as they 4376 1.3 christos are larger than the actual numbers encountered. */ 4377 1.3 christos 4378 1.3 christos static void 4379 1.7 christos d_count_templates_scopes (struct d_print_info *dpi, 4380 1.7 christos struct demangle_component *dc) 4381 1.3 christos { 4382 1.7 christos if (dc == NULL || dc->d_counting > 1 || dpi->recursion > MAX_RECURSION_COUNT) 4383 1.3 christos return; 4384 1.3 christos 4385 1.7 christos ++ dc->d_counting; 4386 1.7 christos 4387 1.3 christos switch (dc->type) 4388 1.3 christos { 4389 1.3 christos case DEMANGLE_COMPONENT_NAME: 4390 1.3 christos case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 4391 1.3 christos case DEMANGLE_COMPONENT_FUNCTION_PARAM: 4392 1.3 christos case DEMANGLE_COMPONENT_SUB_STD: 4393 1.3 christos case DEMANGLE_COMPONENT_BUILTIN_TYPE: 4394 1.9 christos case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE: 4395 1.3 christos case DEMANGLE_COMPONENT_OPERATOR: 4396 1.3 christos case DEMANGLE_COMPONENT_CHARACTER: 4397 1.3 christos case DEMANGLE_COMPONENT_NUMBER: 4398 1.3 christos case DEMANGLE_COMPONENT_UNNAMED_TYPE: 4399 1.8 christos case DEMANGLE_COMPONENT_STRUCTURED_BINDING: 4400 1.8 christos case DEMANGLE_COMPONENT_MODULE_NAME: 4401 1.8 christos case DEMANGLE_COMPONENT_MODULE_PARTITION: 4402 1.8 christos case DEMANGLE_COMPONENT_MODULE_INIT: 4403 1.9 christos case DEMANGLE_COMPONENT_FIXED_TYPE: 4404 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_HEAD: 4405 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM: 4406 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM: 4407 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM: 4408 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM: 4409 1.3 christos break; 4410 1.3 christos 4411 1.3 christos case DEMANGLE_COMPONENT_TEMPLATE: 4412 1.7 christos dpi->num_copy_templates++; 4413 1.3 christos goto recurse_left_right; 4414 1.3 christos 4415 1.3 christos case DEMANGLE_COMPONENT_REFERENCE: 4416 1.3 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 4417 1.3 christos if (d_left (dc)->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM) 4418 1.7 christos dpi->num_saved_scopes++; 4419 1.3 christos goto recurse_left_right; 4420 1.3 christos 4421 1.3 christos case DEMANGLE_COMPONENT_QUAL_NAME: 4422 1.3 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 4423 1.3 christos case DEMANGLE_COMPONENT_TYPED_NAME: 4424 1.3 christos case DEMANGLE_COMPONENT_VTABLE: 4425 1.3 christos case DEMANGLE_COMPONENT_VTT: 4426 1.3 christos case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE: 4427 1.3 christos case DEMANGLE_COMPONENT_TYPEINFO: 4428 1.3 christos case DEMANGLE_COMPONENT_TYPEINFO_NAME: 4429 1.3 christos case DEMANGLE_COMPONENT_TYPEINFO_FN: 4430 1.3 christos case DEMANGLE_COMPONENT_THUNK: 4431 1.3 christos case DEMANGLE_COMPONENT_VIRTUAL_THUNK: 4432 1.3 christos case DEMANGLE_COMPONENT_COVARIANT_THUNK: 4433 1.3 christos case DEMANGLE_COMPONENT_JAVA_CLASS: 4434 1.3 christos case DEMANGLE_COMPONENT_GUARD: 4435 1.3 christos case DEMANGLE_COMPONENT_TLS_INIT: 4436 1.3 christos case DEMANGLE_COMPONENT_TLS_WRAPPER: 4437 1.3 christos case DEMANGLE_COMPONENT_REFTEMP: 4438 1.3 christos case DEMANGLE_COMPONENT_HIDDEN_ALIAS: 4439 1.3 christos case DEMANGLE_COMPONENT_RESTRICT: 4440 1.3 christos case DEMANGLE_COMPONENT_VOLATILE: 4441 1.3 christos case DEMANGLE_COMPONENT_CONST: 4442 1.3 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 4443 1.3 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 4444 1.3 christos case DEMANGLE_COMPONENT_CONST_THIS: 4445 1.3 christos case DEMANGLE_COMPONENT_REFERENCE_THIS: 4446 1.3 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: 4447 1.9 christos case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: 4448 1.5 christos case DEMANGLE_COMPONENT_TRANSACTION_SAFE: 4449 1.6 christos case DEMANGLE_COMPONENT_NOEXCEPT: 4450 1.6 christos case DEMANGLE_COMPONENT_THROW_SPEC: 4451 1.3 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 4452 1.3 christos case DEMANGLE_COMPONENT_POINTER: 4453 1.3 christos case DEMANGLE_COMPONENT_COMPLEX: 4454 1.3 christos case DEMANGLE_COMPONENT_IMAGINARY: 4455 1.3 christos case DEMANGLE_COMPONENT_VENDOR_TYPE: 4456 1.3 christos case DEMANGLE_COMPONENT_FUNCTION_TYPE: 4457 1.3 christos case DEMANGLE_COMPONENT_ARRAY_TYPE: 4458 1.3 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 4459 1.3 christos case DEMANGLE_COMPONENT_VECTOR_TYPE: 4460 1.3 christos case DEMANGLE_COMPONENT_ARGLIST: 4461 1.3 christos case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: 4462 1.7 christos case DEMANGLE_COMPONENT_TPARM_OBJ: 4463 1.3 christos case DEMANGLE_COMPONENT_INITIALIZER_LIST: 4464 1.3 christos case DEMANGLE_COMPONENT_CAST: 4465 1.5 christos case DEMANGLE_COMPONENT_CONVERSION: 4466 1.3 christos case DEMANGLE_COMPONENT_NULLARY: 4467 1.3 christos case DEMANGLE_COMPONENT_UNARY: 4468 1.3 christos case DEMANGLE_COMPONENT_BINARY: 4469 1.3 christos case DEMANGLE_COMPONENT_BINARY_ARGS: 4470 1.3 christos case DEMANGLE_COMPONENT_TRINARY: 4471 1.3 christos case DEMANGLE_COMPONENT_TRINARY_ARG1: 4472 1.3 christos case DEMANGLE_COMPONENT_TRINARY_ARG2: 4473 1.3 christos case DEMANGLE_COMPONENT_LITERAL: 4474 1.3 christos case DEMANGLE_COMPONENT_LITERAL_NEG: 4475 1.8 christos case DEMANGLE_COMPONENT_VENDOR_EXPR: 4476 1.3 christos case DEMANGLE_COMPONENT_JAVA_RESOURCE: 4477 1.3 christos case DEMANGLE_COMPONENT_COMPOUND_NAME: 4478 1.3 christos case DEMANGLE_COMPONENT_DECLTYPE: 4479 1.3 christos case DEMANGLE_COMPONENT_TRANSACTION_CLONE: 4480 1.3 christos case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: 4481 1.3 christos case DEMANGLE_COMPONENT_PACK_EXPANSION: 4482 1.3 christos case DEMANGLE_COMPONENT_TAGGED_NAME: 4483 1.3 christos case DEMANGLE_COMPONENT_CLONE: 4484 1.9 christos case DEMANGLE_COMPONENT_CONSTRAINTS: 4485 1.3 christos recurse_left_right: 4486 1.7 christos /* PR 89394 - Check for too much recursion. */ 4487 1.7 christos if (dpi->recursion > DEMANGLE_RECURSION_LIMIT) 4488 1.7 christos /* FIXME: There ought to be a way to report to the 4489 1.7 christos user that the recursion limit has been reached. */ 4490 1.7 christos return; 4491 1.7 christos 4492 1.7 christos ++ dpi->recursion; 4493 1.7 christos d_count_templates_scopes (dpi, d_left (dc)); 4494 1.7 christos d_count_templates_scopes (dpi, d_right (dc)); 4495 1.7 christos -- dpi->recursion; 4496 1.3 christos break; 4497 1.3 christos 4498 1.3 christos case DEMANGLE_COMPONENT_CTOR: 4499 1.7 christos d_count_templates_scopes (dpi, dc->u.s_ctor.name); 4500 1.3 christos break; 4501 1.3 christos 4502 1.3 christos case DEMANGLE_COMPONENT_DTOR: 4503 1.7 christos d_count_templates_scopes (dpi, dc->u.s_dtor.name); 4504 1.3 christos break; 4505 1.3 christos 4506 1.3 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 4507 1.7 christos d_count_templates_scopes (dpi, dc->u.s_extended_operator.name); 4508 1.3 christos break; 4509 1.3 christos 4510 1.3 christos case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS: 4511 1.3 christos case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS: 4512 1.8 christos case DEMANGLE_COMPONENT_MODULE_ENTITY: 4513 1.9 christos case DEMANGLE_COMPONENT_FRIEND: 4514 1.7 christos d_count_templates_scopes (dpi, d_left (dc)); 4515 1.3 christos break; 4516 1.3 christos 4517 1.3 christos case DEMANGLE_COMPONENT_LAMBDA: 4518 1.3 christos case DEMANGLE_COMPONENT_DEFAULT_ARG: 4519 1.7 christos d_count_templates_scopes (dpi, dc->u.s_unary_num.sub); 4520 1.3 christos break; 4521 1.3 christos } 4522 1.3 christos } 4523 1.3 christos 4524 1.1 christos /* Initialize a print information structure. */ 4525 1.1 christos 4526 1.1 christos static void 4527 1.1 christos d_print_init (struct d_print_info *dpi, demangle_callbackref callback, 4528 1.7 christos void *opaque, struct demangle_component *dc) 4529 1.1 christos { 4530 1.1 christos dpi->len = 0; 4531 1.1 christos dpi->last_char = '\0'; 4532 1.1 christos dpi->templates = NULL; 4533 1.1 christos dpi->modifiers = NULL; 4534 1.1 christos dpi->pack_index = 0; 4535 1.1 christos dpi->flush_count = 0; 4536 1.1 christos 4537 1.1 christos dpi->callback = callback; 4538 1.1 christos dpi->opaque = opaque; 4539 1.1 christos 4540 1.1 christos dpi->demangle_failure = 0; 4541 1.6 christos dpi->recursion = 0; 4542 1.9 christos dpi->lambda_tpl_parms = 0; 4543 1.3 christos 4544 1.3 christos dpi->component_stack = NULL; 4545 1.3 christos 4546 1.3 christos dpi->saved_scopes = NULL; 4547 1.3 christos dpi->next_saved_scope = 0; 4548 1.3 christos dpi->num_saved_scopes = 0; 4549 1.3 christos 4550 1.3 christos dpi->copy_templates = NULL; 4551 1.3 christos dpi->next_copy_template = 0; 4552 1.3 christos dpi->num_copy_templates = 0; 4553 1.3 christos 4554 1.7 christos d_count_templates_scopes (dpi, dc); 4555 1.7 christos /* If we did not reach the recursion limit, then reset the 4556 1.7 christos current recursion value back to 0, so that we can print 4557 1.7 christos the templates. */ 4558 1.7 christos if (dpi->recursion < DEMANGLE_RECURSION_LIMIT) 4559 1.7 christos dpi->recursion = 0; 4560 1.3 christos dpi->num_copy_templates *= dpi->num_saved_scopes; 4561 1.3 christos 4562 1.3 christos dpi->current_template = NULL; 4563 1.1 christos } 4564 1.1 christos 4565 1.1 christos /* Indicate that an error occurred during printing, and test for error. */ 4566 1.1 christos 4567 1.1 christos static inline void 4568 1.1 christos d_print_error (struct d_print_info *dpi) 4569 1.1 christos { 4570 1.1 christos dpi->demangle_failure = 1; 4571 1.1 christos } 4572 1.1 christos 4573 1.1 christos static inline int 4574 1.1 christos d_print_saw_error (struct d_print_info *dpi) 4575 1.1 christos { 4576 1.1 christos return dpi->demangle_failure != 0; 4577 1.1 christos } 4578 1.1 christos 4579 1.1 christos /* Flush buffered characters to the callback. */ 4580 1.1 christos 4581 1.1 christos static inline void 4582 1.1 christos d_print_flush (struct d_print_info *dpi) 4583 1.1 christos { 4584 1.1 christos dpi->buf[dpi->len] = '\0'; 4585 1.1 christos dpi->callback (dpi->buf, dpi->len, dpi->opaque); 4586 1.1 christos dpi->len = 0; 4587 1.1 christos dpi->flush_count++; 4588 1.1 christos } 4589 1.1 christos 4590 1.1 christos /* Append characters and buffers for printing. */ 4591 1.1 christos 4592 1.1 christos static inline void 4593 1.1 christos d_append_char (struct d_print_info *dpi, char c) 4594 1.1 christos { 4595 1.1 christos if (dpi->len == sizeof (dpi->buf) - 1) 4596 1.1 christos d_print_flush (dpi); 4597 1.1 christos 4598 1.1 christos dpi->buf[dpi->len++] = c; 4599 1.1 christos dpi->last_char = c; 4600 1.1 christos } 4601 1.1 christos 4602 1.1 christos static inline void 4603 1.1 christos d_append_buffer (struct d_print_info *dpi, const char *s, size_t l) 4604 1.1 christos { 4605 1.1 christos size_t i; 4606 1.1 christos 4607 1.1 christos for (i = 0; i < l; i++) 4608 1.1 christos d_append_char (dpi, s[i]); 4609 1.1 christos } 4610 1.1 christos 4611 1.1 christos static inline void 4612 1.1 christos d_append_string (struct d_print_info *dpi, const char *s) 4613 1.1 christos { 4614 1.1 christos d_append_buffer (dpi, s, strlen (s)); 4615 1.1 christos } 4616 1.1 christos 4617 1.1 christos static inline void 4618 1.6 christos d_append_num (struct d_print_info *dpi, int l) 4619 1.1 christos { 4620 1.1 christos char buf[25]; 4621 1.6 christos sprintf (buf,"%d", l); 4622 1.1 christos d_append_string (dpi, buf); 4623 1.1 christos } 4624 1.1 christos 4625 1.1 christos static inline char 4626 1.1 christos d_last_char (struct d_print_info *dpi) 4627 1.1 christos { 4628 1.1 christos return dpi->last_char; 4629 1.1 christos } 4630 1.1 christos 4631 1.1 christos /* Turn components into a human readable string. OPTIONS is the 4632 1.1 christos options bits passed to the demangler. DC is the tree to print. 4633 1.1 christos CALLBACK is a function to call to flush demangled string segments 4634 1.1 christos as they fill the intermediate buffer, and OPAQUE is a generalized 4635 1.1 christos callback argument. On success, this returns 1. On failure, 4636 1.1 christos it returns 0, indicating a bad parse. It does not use heap 4637 1.1 christos memory to build an output string, so cannot encounter memory 4638 1.1 christos allocation failure. */ 4639 1.1 christos 4640 1.1 christos CP_STATIC_IF_GLIBCPP_V3 4641 1.1 christos int 4642 1.1 christos cplus_demangle_print_callback (int options, 4643 1.6 christos struct demangle_component *dc, 4644 1.1 christos demangle_callbackref callback, void *opaque) 4645 1.1 christos { 4646 1.1 christos struct d_print_info dpi; 4647 1.1 christos 4648 1.3 christos d_print_init (&dpi, callback, opaque, dc); 4649 1.1 christos 4650 1.3 christos { 4651 1.3 christos #ifdef CP_DYNAMIC_ARRAYS 4652 1.6 christos /* Avoid zero-length VLAs, which are prohibited by the C99 standard 4653 1.6 christos and flagged as errors by Address Sanitizer. */ 4654 1.6 christos __extension__ struct d_saved_scope scopes[(dpi.num_saved_scopes > 0) 4655 1.6 christos ? dpi.num_saved_scopes : 1]; 4656 1.6 christos __extension__ struct d_print_template temps[(dpi.num_copy_templates > 0) 4657 1.6 christos ? dpi.num_copy_templates : 1]; 4658 1.3 christos 4659 1.3 christos dpi.saved_scopes = scopes; 4660 1.3 christos dpi.copy_templates = temps; 4661 1.3 christos #else 4662 1.3 christos dpi.saved_scopes = alloca (dpi.num_saved_scopes 4663 1.3 christos * sizeof (*dpi.saved_scopes)); 4664 1.3 christos dpi.copy_templates = alloca (dpi.num_copy_templates 4665 1.3 christos * sizeof (*dpi.copy_templates)); 4666 1.3 christos #endif 4667 1.3 christos 4668 1.3 christos d_print_comp (&dpi, options, dc); 4669 1.3 christos } 4670 1.1 christos 4671 1.1 christos d_print_flush (&dpi); 4672 1.1 christos 4673 1.1 christos return ! d_print_saw_error (&dpi); 4674 1.1 christos } 4675 1.1 christos 4676 1.1 christos /* Turn components into a human readable string. OPTIONS is the 4677 1.1 christos options bits passed to the demangler. DC is the tree to print. 4678 1.1 christos ESTIMATE is a guess at the length of the result. This returns a 4679 1.1 christos string allocated by malloc, or NULL on error. On success, this 4680 1.1 christos sets *PALC to the size of the allocated buffer. On failure, this 4681 1.1 christos sets *PALC to 0 for a bad parse, or to 1 for a memory allocation 4682 1.1 christos failure. */ 4683 1.1 christos 4684 1.1 christos CP_STATIC_IF_GLIBCPP_V3 4685 1.1 christos char * 4686 1.6 christos cplus_demangle_print (int options, struct demangle_component *dc, 4687 1.1 christos int estimate, size_t *palc) 4688 1.1 christos { 4689 1.1 christos struct d_growable_string dgs; 4690 1.1 christos 4691 1.1 christos d_growable_string_init (&dgs, estimate); 4692 1.1 christos 4693 1.1 christos if (! cplus_demangle_print_callback (options, dc, 4694 1.1 christos d_growable_string_callback_adapter, 4695 1.1 christos &dgs)) 4696 1.1 christos { 4697 1.1 christos free (dgs.buf); 4698 1.1 christos *palc = 0; 4699 1.1 christos return NULL; 4700 1.1 christos } 4701 1.1 christos 4702 1.1 christos *palc = dgs.allocation_failure ? 1 : dgs.alc; 4703 1.1 christos return dgs.buf; 4704 1.1 christos } 4705 1.1 christos 4706 1.1 christos /* Returns the I'th element of the template arglist ARGS, or NULL on 4707 1.6 christos failure. If I is negative, return the entire arglist. */ 4708 1.1 christos 4709 1.1 christos static struct demangle_component * 4710 1.1 christos d_index_template_argument (struct demangle_component *args, int i) 4711 1.1 christos { 4712 1.1 christos struct demangle_component *a; 4713 1.1 christos 4714 1.6 christos if (i < 0) 4715 1.6 christos /* Print the whole argument pack. */ 4716 1.6 christos return args; 4717 1.6 christos 4718 1.1 christos for (a = args; 4719 1.1 christos a != NULL; 4720 1.1 christos a = d_right (a)) 4721 1.1 christos { 4722 1.1 christos if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) 4723 1.1 christos return NULL; 4724 1.1 christos if (i <= 0) 4725 1.1 christos break; 4726 1.1 christos --i; 4727 1.1 christos } 4728 1.1 christos if (i != 0 || a == NULL) 4729 1.1 christos return NULL; 4730 1.1 christos 4731 1.1 christos return d_left (a); 4732 1.1 christos } 4733 1.1 christos 4734 1.1 christos /* Returns the template argument from the current context indicated by DC, 4735 1.1 christos which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */ 4736 1.1 christos 4737 1.1 christos static struct demangle_component * 4738 1.1 christos d_lookup_template_argument (struct d_print_info *dpi, 4739 1.1 christos const struct demangle_component *dc) 4740 1.1 christos { 4741 1.1 christos if (dpi->templates == NULL) 4742 1.1 christos { 4743 1.1 christos d_print_error (dpi); 4744 1.1 christos return NULL; 4745 1.1 christos } 4746 1.1 christos 4747 1.1 christos return d_index_template_argument 4748 1.1 christos (d_right (dpi->templates->template_decl), 4749 1.1 christos dc->u.s_number.number); 4750 1.1 christos } 4751 1.1 christos 4752 1.1 christos /* Returns a template argument pack used in DC (any will do), or NULL. */ 4753 1.1 christos 4754 1.1 christos static struct demangle_component * 4755 1.1 christos d_find_pack (struct d_print_info *dpi, 4756 1.1 christos const struct demangle_component *dc) 4757 1.1 christos { 4758 1.1 christos struct demangle_component *a; 4759 1.1 christos if (dc == NULL) 4760 1.1 christos return NULL; 4761 1.1 christos 4762 1.1 christos switch (dc->type) 4763 1.1 christos { 4764 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 4765 1.1 christos a = d_lookup_template_argument (dpi, dc); 4766 1.1 christos if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) 4767 1.1 christos return a; 4768 1.1 christos return NULL; 4769 1.1 christos 4770 1.1 christos case DEMANGLE_COMPONENT_PACK_EXPANSION: 4771 1.1 christos return NULL; 4772 1.1 christos 4773 1.1 christos case DEMANGLE_COMPONENT_LAMBDA: 4774 1.1 christos case DEMANGLE_COMPONENT_NAME: 4775 1.3 christos case DEMANGLE_COMPONENT_TAGGED_NAME: 4776 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 4777 1.1 christos case DEMANGLE_COMPONENT_BUILTIN_TYPE: 4778 1.9 christos case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE: 4779 1.1 christos case DEMANGLE_COMPONENT_SUB_STD: 4780 1.1 christos case DEMANGLE_COMPONENT_CHARACTER: 4781 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_PARAM: 4782 1.1 christos case DEMANGLE_COMPONENT_UNNAMED_TYPE: 4783 1.5 christos case DEMANGLE_COMPONENT_DEFAULT_ARG: 4784 1.5 christos case DEMANGLE_COMPONENT_NUMBER: 4785 1.1 christos return NULL; 4786 1.1 christos 4787 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 4788 1.1 christos return d_find_pack (dpi, dc->u.s_extended_operator.name); 4789 1.1 christos case DEMANGLE_COMPONENT_CTOR: 4790 1.1 christos return d_find_pack (dpi, dc->u.s_ctor.name); 4791 1.1 christos case DEMANGLE_COMPONENT_DTOR: 4792 1.1 christos return d_find_pack (dpi, dc->u.s_dtor.name); 4793 1.1 christos 4794 1.1 christos default: 4795 1.1 christos a = d_find_pack (dpi, d_left (dc)); 4796 1.1 christos if (a) 4797 1.1 christos return a; 4798 1.1 christos return d_find_pack (dpi, d_right (dc)); 4799 1.1 christos } 4800 1.1 christos } 4801 1.1 christos 4802 1.1 christos /* Returns the length of the template argument pack DC. */ 4803 1.1 christos 4804 1.1 christos static int 4805 1.1 christos d_pack_length (const struct demangle_component *dc) 4806 1.1 christos { 4807 1.1 christos int count = 0; 4808 1.1 christos while (dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST 4809 1.1 christos && d_left (dc) != NULL) 4810 1.1 christos { 4811 1.1 christos ++count; 4812 1.1 christos dc = d_right (dc); 4813 1.1 christos } 4814 1.1 christos return count; 4815 1.1 christos } 4816 1.1 christos 4817 1.6 christos /* Returns the number of template args in DC, expanding any pack expansions 4818 1.6 christos found there. */ 4819 1.6 christos 4820 1.6 christos static int 4821 1.6 christos d_args_length (struct d_print_info *dpi, const struct demangle_component *dc) 4822 1.6 christos { 4823 1.6 christos int count = 0; 4824 1.6 christos for (; dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST; 4825 1.6 christos dc = d_right (dc)) 4826 1.6 christos { 4827 1.6 christos struct demangle_component *elt = d_left (dc); 4828 1.6 christos if (elt == NULL) 4829 1.6 christos break; 4830 1.6 christos if (elt->type == DEMANGLE_COMPONENT_PACK_EXPANSION) 4831 1.6 christos { 4832 1.6 christos struct demangle_component *a = d_find_pack (dpi, d_left (elt)); 4833 1.6 christos count += d_pack_length (a); 4834 1.6 christos } 4835 1.6 christos else 4836 1.6 christos ++count; 4837 1.6 christos } 4838 1.6 christos return count; 4839 1.6 christos } 4840 1.6 christos 4841 1.1 christos /* DC is a component of a mangled expression. Print it, wrapped in parens 4842 1.1 christos if needed. */ 4843 1.1 christos 4844 1.1 christos static void 4845 1.1 christos d_print_subexpr (struct d_print_info *dpi, int options, 4846 1.6 christos struct demangle_component *dc) 4847 1.1 christos { 4848 1.1 christos int simple = 0; 4849 1.1 christos if (dc->type == DEMANGLE_COMPONENT_NAME 4850 1.1 christos || dc->type == DEMANGLE_COMPONENT_QUAL_NAME 4851 1.1 christos || dc->type == DEMANGLE_COMPONENT_INITIALIZER_LIST 4852 1.1 christos || dc->type == DEMANGLE_COMPONENT_FUNCTION_PARAM) 4853 1.1 christos simple = 1; 4854 1.1 christos if (!simple) 4855 1.1 christos d_append_char (dpi, '('); 4856 1.1 christos d_print_comp (dpi, options, dc); 4857 1.1 christos if (!simple) 4858 1.1 christos d_append_char (dpi, ')'); 4859 1.1 christos } 4860 1.1 christos 4861 1.3 christos /* Save the current scope. */ 4862 1.3 christos 4863 1.3 christos static void 4864 1.3 christos d_save_scope (struct d_print_info *dpi, 4865 1.3 christos const struct demangle_component *container) 4866 1.3 christos { 4867 1.3 christos struct d_saved_scope *scope; 4868 1.3 christos struct d_print_template *src, **link; 4869 1.3 christos 4870 1.3 christos if (dpi->next_saved_scope >= dpi->num_saved_scopes) 4871 1.3 christos { 4872 1.3 christos d_print_error (dpi); 4873 1.3 christos return; 4874 1.3 christos } 4875 1.3 christos scope = &dpi->saved_scopes[dpi->next_saved_scope]; 4876 1.3 christos dpi->next_saved_scope++; 4877 1.3 christos 4878 1.3 christos scope->container = container; 4879 1.3 christos link = &scope->templates; 4880 1.3 christos 4881 1.3 christos for (src = dpi->templates; src != NULL; src = src->next) 4882 1.3 christos { 4883 1.3 christos struct d_print_template *dst; 4884 1.3 christos 4885 1.3 christos if (dpi->next_copy_template >= dpi->num_copy_templates) 4886 1.3 christos { 4887 1.3 christos d_print_error (dpi); 4888 1.3 christos return; 4889 1.3 christos } 4890 1.3 christos dst = &dpi->copy_templates[dpi->next_copy_template]; 4891 1.3 christos dpi->next_copy_template++; 4892 1.3 christos 4893 1.3 christos dst->template_decl = src->template_decl; 4894 1.3 christos *link = dst; 4895 1.3 christos link = &dst->next; 4896 1.3 christos } 4897 1.3 christos 4898 1.3 christos *link = NULL; 4899 1.3 christos } 4900 1.3 christos 4901 1.3 christos /* Attempt to locate a previously saved scope. Returns NULL if no 4902 1.3 christos corresponding saved scope was found. */ 4903 1.3 christos 4904 1.3 christos static struct d_saved_scope * 4905 1.3 christos d_get_saved_scope (struct d_print_info *dpi, 4906 1.3 christos const struct demangle_component *container) 4907 1.3 christos { 4908 1.3 christos int i; 4909 1.3 christos 4910 1.3 christos for (i = 0; i < dpi->next_saved_scope; i++) 4911 1.3 christos if (dpi->saved_scopes[i].container == container) 4912 1.3 christos return &dpi->saved_scopes[i]; 4913 1.3 christos 4914 1.3 christos return NULL; 4915 1.3 christos } 4916 1.3 christos 4917 1.6 christos /* If DC is a C++17 fold-expression, print it and return true; otherwise 4918 1.6 christos return false. */ 4919 1.6 christos 4920 1.6 christos static int 4921 1.6 christos d_maybe_print_fold_expression (struct d_print_info *dpi, int options, 4922 1.6 christos struct demangle_component *dc) 4923 1.6 christos { 4924 1.6 christos struct demangle_component *ops, *operator_, *op1, *op2; 4925 1.6 christos int save_idx; 4926 1.6 christos 4927 1.6 christos const char *fold_code = d_left (dc)->u.s_operator.op->code; 4928 1.6 christos if (fold_code[0] != 'f') 4929 1.6 christos return 0; 4930 1.6 christos 4931 1.6 christos ops = d_right (dc); 4932 1.6 christos operator_ = d_left (ops); 4933 1.6 christos op1 = d_right (ops); 4934 1.6 christos op2 = 0; 4935 1.6 christos if (op1->type == DEMANGLE_COMPONENT_TRINARY_ARG2) 4936 1.6 christos { 4937 1.6 christos op2 = d_right (op1); 4938 1.6 christos op1 = d_left (op1); 4939 1.6 christos } 4940 1.6 christos 4941 1.6 christos /* Print the whole pack. */ 4942 1.6 christos save_idx = dpi->pack_index; 4943 1.6 christos dpi->pack_index = -1; 4944 1.6 christos 4945 1.6 christos switch (fold_code[1]) 4946 1.6 christos { 4947 1.6 christos /* Unary left fold, (... + X). */ 4948 1.6 christos case 'l': 4949 1.6 christos d_append_string (dpi, "(..."); 4950 1.6 christos d_print_expr_op (dpi, options, operator_); 4951 1.6 christos d_print_subexpr (dpi, options, op1); 4952 1.6 christos d_append_char (dpi, ')'); 4953 1.6 christos break; 4954 1.6 christos 4955 1.6 christos /* Unary right fold, (X + ...). */ 4956 1.6 christos case 'r': 4957 1.6 christos d_append_char (dpi, '('); 4958 1.6 christos d_print_subexpr (dpi, options, op1); 4959 1.6 christos d_print_expr_op (dpi, options, operator_); 4960 1.6 christos d_append_string (dpi, "...)"); 4961 1.6 christos break; 4962 1.6 christos 4963 1.6 christos /* Binary left fold, (42 + ... + X). */ 4964 1.6 christos case 'L': 4965 1.6 christos /* Binary right fold, (X + ... + 42). */ 4966 1.6 christos case 'R': 4967 1.6 christos d_append_char (dpi, '('); 4968 1.6 christos d_print_subexpr (dpi, options, op1); 4969 1.6 christos d_print_expr_op (dpi, options, operator_); 4970 1.6 christos d_append_string (dpi, "..."); 4971 1.6 christos d_print_expr_op (dpi, options, operator_); 4972 1.6 christos d_print_subexpr (dpi, options, op2); 4973 1.6 christos d_append_char (dpi, ')'); 4974 1.6 christos break; 4975 1.6 christos } 4976 1.6 christos 4977 1.6 christos dpi->pack_index = save_idx; 4978 1.6 christos return 1; 4979 1.6 christos } 4980 1.6 christos 4981 1.8 christos /* True iff DC represents a C99-style designated initializer. */ 4982 1.8 christos 4983 1.8 christos static int 4984 1.8 christos is_designated_init (struct demangle_component *dc) 4985 1.8 christos { 4986 1.8 christos if (dc->type != DEMANGLE_COMPONENT_BINARY 4987 1.8 christos && dc->type != DEMANGLE_COMPONENT_TRINARY) 4988 1.8 christos return 0; 4989 1.8 christos 4990 1.8 christos struct demangle_component *op = d_left (dc); 4991 1.8 christos const char *code = op->u.s_operator.op->code; 4992 1.8 christos return (code[0] == 'd' 4993 1.8 christos && (code[1] == 'i' || code[1] == 'x' || code[1] == 'X')); 4994 1.8 christos } 4995 1.8 christos 4996 1.8 christos /* If DC represents a C99-style designated initializer, print it and return 4997 1.8 christos true; otherwise, return false. */ 4998 1.8 christos 4999 1.8 christos static int 5000 1.8 christos d_maybe_print_designated_init (struct d_print_info *dpi, int options, 5001 1.8 christos struct demangle_component *dc) 5002 1.8 christos { 5003 1.8 christos if (!is_designated_init (dc)) 5004 1.8 christos return 0; 5005 1.8 christos 5006 1.8 christos const char *code = d_left (dc)->u.s_operator.op->code; 5007 1.8 christos 5008 1.8 christos struct demangle_component *operands = d_right (dc); 5009 1.8 christos struct demangle_component *op1 = d_left (operands); 5010 1.8 christos struct demangle_component *op2 = d_right (operands); 5011 1.8 christos 5012 1.8 christos if (code[1] == 'i') 5013 1.8 christos d_append_char (dpi, '.'); 5014 1.8 christos else 5015 1.8 christos d_append_char (dpi, '['); 5016 1.8 christos 5017 1.8 christos d_print_comp (dpi, options, op1); 5018 1.8 christos if (code[1] == 'X') 5019 1.8 christos { 5020 1.8 christos d_append_string (dpi, " ... "); 5021 1.8 christos d_print_comp (dpi, options, d_left (op2)); 5022 1.8 christos op2 = d_right (op2); 5023 1.8 christos } 5024 1.8 christos if (code[1] != 'i') 5025 1.8 christos d_append_char (dpi, ']'); 5026 1.8 christos if (is_designated_init (op2)) 5027 1.8 christos { 5028 1.8 christos /* Don't put '=' or '(' between chained designators. */ 5029 1.8 christos d_print_comp (dpi, options, op2); 5030 1.8 christos } 5031 1.8 christos else 5032 1.8 christos { 5033 1.8 christos d_append_char (dpi, '='); 5034 1.8 christos d_print_subexpr (dpi, options, op2); 5035 1.8 christos } 5036 1.8 christos return 1; 5037 1.8 christos } 5038 1.8 christos 5039 1.9 christos static void 5040 1.9 christos d_print_lambda_parm_name (struct d_print_info *dpi, int type, unsigned index) 5041 1.9 christos { 5042 1.9 christos const char *str; 5043 1.9 christos switch (type) 5044 1.9 christos { 5045 1.9 christos default: 5046 1.9 christos dpi->demangle_failure = 1; 5047 1.9 christos str = ""; 5048 1.9 christos break; 5049 1.9 christos 5050 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM: 5051 1.9 christos str = "$T"; 5052 1.9 christos break; 5053 1.9 christos 5054 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM: 5055 1.9 christos str = "$N"; 5056 1.9 christos break; 5057 1.9 christos 5058 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM: 5059 1.9 christos str = "$TT"; 5060 1.9 christos break; 5061 1.9 christos } 5062 1.9 christos d_append_string (dpi, str); 5063 1.9 christos d_append_num (dpi, index); 5064 1.9 christos } 5065 1.9 christos 5066 1.1 christos /* Subroutine to handle components. */ 5067 1.1 christos 5068 1.1 christos static void 5069 1.3 christos d_print_comp_inner (struct d_print_info *dpi, int options, 5070 1.6 christos struct demangle_component *dc) 5071 1.1 christos { 5072 1.1 christos /* Magic variable to let reference smashing skip over the next modifier 5073 1.1 christos without needing to modify *dc. */ 5074 1.6 christos struct demangle_component *mod_inner = NULL; 5075 1.1 christos 5076 1.3 christos /* Variable used to store the current templates while a previously 5077 1.3 christos captured scope is used. */ 5078 1.3 christos struct d_print_template *saved_templates; 5079 1.3 christos 5080 1.3 christos /* Nonzero if templates have been stored in the above variable. */ 5081 1.3 christos int need_template_restore = 0; 5082 1.3 christos 5083 1.1 christos if (dc == NULL) 5084 1.1 christos { 5085 1.1 christos d_print_error (dpi); 5086 1.1 christos return; 5087 1.1 christos } 5088 1.1 christos if (d_print_saw_error (dpi)) 5089 1.1 christos return; 5090 1.1 christos 5091 1.1 christos switch (dc->type) 5092 1.1 christos { 5093 1.1 christos case DEMANGLE_COMPONENT_NAME: 5094 1.1 christos if ((options & DMGL_JAVA) == 0) 5095 1.1 christos d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len); 5096 1.1 christos else 5097 1.1 christos d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len); 5098 1.1 christos return; 5099 1.1 christos 5100 1.3 christos case DEMANGLE_COMPONENT_TAGGED_NAME: 5101 1.3 christos d_print_comp (dpi, options, d_left (dc)); 5102 1.3 christos d_append_string (dpi, "[abi:"); 5103 1.3 christos d_print_comp (dpi, options, d_right (dc)); 5104 1.3 christos d_append_char (dpi, ']'); 5105 1.3 christos return; 5106 1.3 christos 5107 1.8 christos case DEMANGLE_COMPONENT_STRUCTURED_BINDING: 5108 1.8 christos d_append_char (dpi, '['); 5109 1.8 christos for (;;) 5110 1.8 christos { 5111 1.8 christos d_print_comp (dpi, options, d_left (dc)); 5112 1.8 christos dc = d_right (dc); 5113 1.8 christos if (!dc) 5114 1.8 christos break; 5115 1.8 christos d_append_string (dpi, ", "); 5116 1.8 christos } 5117 1.8 christos d_append_char (dpi, ']'); 5118 1.8 christos return; 5119 1.8 christos 5120 1.8 christos case DEMANGLE_COMPONENT_MODULE_ENTITY: 5121 1.8 christos d_print_comp (dpi, options, d_left (dc)); 5122 1.8 christos d_append_char (dpi, '@'); 5123 1.8 christos d_print_comp (dpi, options, d_right (dc)); 5124 1.8 christos return; 5125 1.8 christos 5126 1.8 christos case DEMANGLE_COMPONENT_MODULE_NAME: 5127 1.8 christos case DEMANGLE_COMPONENT_MODULE_PARTITION: 5128 1.8 christos { 5129 1.8 christos if (d_left (dc)) 5130 1.8 christos d_print_comp (dpi, options, d_left (dc)); 5131 1.8 christos char c = dc->type == DEMANGLE_COMPONENT_MODULE_PARTITION 5132 1.8 christos ? ':' : d_left (dc) ? '.' : 0; 5133 1.8 christos if (c) 5134 1.8 christos d_append_char (dpi, c); 5135 1.8 christos d_print_comp (dpi, options, d_right (dc)); 5136 1.8 christos } 5137 1.8 christos return; 5138 1.8 christos 5139 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 5140 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 5141 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5142 1.1 christos if ((options & DMGL_JAVA) == 0) 5143 1.1 christos d_append_string (dpi, "::"); 5144 1.1 christos else 5145 1.1 christos d_append_char (dpi, '.'); 5146 1.3 christos { 5147 1.3 christos struct demangle_component *local_name = d_right (dc); 5148 1.3 christos if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG) 5149 1.3 christos { 5150 1.3 christos d_append_string (dpi, "{default arg#"); 5151 1.3 christos d_append_num (dpi, local_name->u.s_unary_num.num + 1); 5152 1.3 christos d_append_string (dpi, "}::"); 5153 1.3 christos local_name = local_name->u.s_unary_num.sub; 5154 1.3 christos } 5155 1.3 christos d_print_comp (dpi, options, local_name); 5156 1.3 christos } 5157 1.1 christos return; 5158 1.1 christos 5159 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 5160 1.1 christos { 5161 1.1 christos struct d_print_mod *hold_modifiers; 5162 1.1 christos struct demangle_component *typed_name; 5163 1.1 christos struct d_print_mod adpm[4]; 5164 1.1 christos unsigned int i; 5165 1.1 christos struct d_print_template dpt; 5166 1.1 christos 5167 1.1 christos /* Pass the name down to the type so that it can be printed in 5168 1.1 christos the right place for the type. We also have to pass down 5169 1.1 christos any CV-qualifiers, which apply to the this parameter. */ 5170 1.1 christos hold_modifiers = dpi->modifiers; 5171 1.1 christos dpi->modifiers = 0; 5172 1.1 christos i = 0; 5173 1.1 christos typed_name = d_left (dc); 5174 1.1 christos while (typed_name != NULL) 5175 1.1 christos { 5176 1.1 christos if (i >= sizeof adpm / sizeof adpm[0]) 5177 1.1 christos { 5178 1.1 christos d_print_error (dpi); 5179 1.1 christos return; 5180 1.1 christos } 5181 1.1 christos 5182 1.1 christos adpm[i].next = dpi->modifiers; 5183 1.1 christos dpi->modifiers = &adpm[i]; 5184 1.1 christos adpm[i].mod = typed_name; 5185 1.1 christos adpm[i].printed = 0; 5186 1.1 christos adpm[i].templates = dpi->templates; 5187 1.1 christos ++i; 5188 1.1 christos 5189 1.6 christos if (!is_fnqual_component_type (typed_name->type)) 5190 1.1 christos break; 5191 1.1 christos 5192 1.1 christos typed_name = d_left (typed_name); 5193 1.1 christos } 5194 1.1 christos 5195 1.1 christos if (typed_name == NULL) 5196 1.1 christos { 5197 1.1 christos d_print_error (dpi); 5198 1.1 christos return; 5199 1.1 christos } 5200 1.1 christos 5201 1.1 christos /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then 5202 1.1 christos there may be CV-qualifiers on its right argument which 5203 1.6 christos really apply here; this happens when parsing a class that 5204 1.1 christos is local to a function. */ 5205 1.1 christos if (typed_name->type == DEMANGLE_COMPONENT_LOCAL_NAME) 5206 1.1 christos { 5207 1.6 christos typed_name = d_right (typed_name); 5208 1.6 christos if (typed_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG) 5209 1.6 christos typed_name = typed_name->u.s_unary_num.sub; 5210 1.7 christos while (typed_name != NULL 5211 1.7 christos && is_fnqual_component_type (typed_name->type)) 5212 1.1 christos { 5213 1.1 christos if (i >= sizeof adpm / sizeof adpm[0]) 5214 1.1 christos { 5215 1.1 christos d_print_error (dpi); 5216 1.1 christos return; 5217 1.1 christos } 5218 1.1 christos 5219 1.1 christos adpm[i] = adpm[i - 1]; 5220 1.1 christos adpm[i].next = &adpm[i - 1]; 5221 1.1 christos dpi->modifiers = &adpm[i]; 5222 1.1 christos 5223 1.6 christos adpm[i - 1].mod = typed_name; 5224 1.1 christos adpm[i - 1].printed = 0; 5225 1.1 christos adpm[i - 1].templates = dpi->templates; 5226 1.1 christos ++i; 5227 1.1 christos 5228 1.6 christos typed_name = d_left (typed_name); 5229 1.1 christos } 5230 1.7 christos if (typed_name == NULL) 5231 1.7 christos { 5232 1.7 christos d_print_error (dpi); 5233 1.7 christos return; 5234 1.7 christos } 5235 1.1 christos } 5236 1.1 christos 5237 1.6 christos /* If typed_name is a template, then it applies to the 5238 1.6 christos function type as well. */ 5239 1.6 christos if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE) 5240 1.6 christos { 5241 1.6 christos dpt.next = dpi->templates; 5242 1.6 christos dpi->templates = &dpt; 5243 1.6 christos dpt.template_decl = typed_name; 5244 1.9 christos 5245 1.9 christos /* Constraints are mangled as part of the template argument list, 5246 1.9 christos so they wrap the _TEMPLATE_ARGLIST. But 5247 1.9 christos d_lookup_template_argument expects the RHS of _TEMPLATE to be 5248 1.9 christos the _ARGLIST, and constraints need to refer to these args. So 5249 1.9 christos move the _CONSTRAINTS out of the _TEMPLATE and onto the type. 5250 1.9 christos This will result in them being printed after the () like a 5251 1.9 christos trailing requires-clause, but that seems like our best option 5252 1.9 christos given that we aren't printing a template-head. */ 5253 1.9 christos struct demangle_component *tnr = d_right (typed_name); 5254 1.9 christos if (tnr->type == DEMANGLE_COMPONENT_CONSTRAINTS) 5255 1.9 christos { 5256 1.9 christos d_right (typed_name) = d_left (tnr); 5257 1.9 christos d_left (tnr) = d_right (dc); 5258 1.9 christos d_right (dc) = tnr; 5259 1.9 christos } 5260 1.6 christos } 5261 1.6 christos 5262 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5263 1.1 christos 5264 1.1 christos if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE) 5265 1.1 christos dpi->templates = dpt.next; 5266 1.1 christos 5267 1.1 christos /* If the modifiers didn't get printed by the type, print them 5268 1.1 christos now. */ 5269 1.1 christos while (i > 0) 5270 1.1 christos { 5271 1.1 christos --i; 5272 1.1 christos if (! adpm[i].printed) 5273 1.1 christos { 5274 1.1 christos d_append_char (dpi, ' '); 5275 1.1 christos d_print_mod (dpi, options, adpm[i].mod); 5276 1.1 christos } 5277 1.1 christos } 5278 1.1 christos 5279 1.1 christos dpi->modifiers = hold_modifiers; 5280 1.1 christos 5281 1.1 christos return; 5282 1.1 christos } 5283 1.1 christos 5284 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 5285 1.1 christos { 5286 1.1 christos struct d_print_mod *hold_dpm; 5287 1.1 christos struct demangle_component *dcl; 5288 1.3 christos const struct demangle_component *hold_current; 5289 1.3 christos 5290 1.3 christos /* This template may need to be referenced by a cast operator 5291 1.3 christos contained in its subtree. */ 5292 1.3 christos hold_current = dpi->current_template; 5293 1.3 christos dpi->current_template = dc; 5294 1.1 christos 5295 1.1 christos /* Don't push modifiers into a template definition. Doing so 5296 1.1 christos could give the wrong definition for a template argument. 5297 1.1 christos Instead, treat the template essentially as a name. */ 5298 1.1 christos 5299 1.1 christos hold_dpm = dpi->modifiers; 5300 1.1 christos dpi->modifiers = NULL; 5301 1.1 christos 5302 1.1 christos dcl = d_left (dc); 5303 1.1 christos 5304 1.1 christos if ((options & DMGL_JAVA) != 0 5305 1.1 christos && dcl->type == DEMANGLE_COMPONENT_NAME 5306 1.1 christos && dcl->u.s_name.len == 6 5307 1.1 christos && strncmp (dcl->u.s_name.s, "JArray", 6) == 0) 5308 1.1 christos { 5309 1.1 christos /* Special-case Java arrays, so that JArray<TYPE> appears 5310 1.1 christos instead as TYPE[]. */ 5311 1.1 christos 5312 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5313 1.1 christos d_append_string (dpi, "[]"); 5314 1.1 christos } 5315 1.1 christos else 5316 1.1 christos { 5317 1.1 christos d_print_comp (dpi, options, dcl); 5318 1.1 christos if (d_last_char (dpi) == '<') 5319 1.1 christos d_append_char (dpi, ' '); 5320 1.1 christos d_append_char (dpi, '<'); 5321 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5322 1.1 christos /* Avoid generating two consecutive '>' characters, to avoid 5323 1.1 christos the C++ syntactic ambiguity. */ 5324 1.1 christos if (d_last_char (dpi) == '>') 5325 1.1 christos d_append_char (dpi, ' '); 5326 1.1 christos d_append_char (dpi, '>'); 5327 1.1 christos } 5328 1.1 christos 5329 1.1 christos dpi->modifiers = hold_dpm; 5330 1.3 christos dpi->current_template = hold_current; 5331 1.1 christos 5332 1.1 christos return; 5333 1.1 christos } 5334 1.1 christos 5335 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 5336 1.9 christos if (dpi->lambda_tpl_parms > dc->u.s_number.number + 1) 5337 1.9 christos { 5338 1.9 christos const struct demangle_component *a 5339 1.9 christos = d_left (dpi->templates->template_decl); 5340 1.9 christos unsigned c; 5341 1.9 christos for (c = dc->u.s_number.number; a && c; c--) 5342 1.9 christos a = d_right (a); 5343 1.9 christos if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM) 5344 1.9 christos a = d_left (a); 5345 1.9 christos if (!a) 5346 1.9 christos dpi->demangle_failure = 1; 5347 1.9 christos else 5348 1.9 christos d_print_lambda_parm_name (dpi, a->type, dc->u.s_number.number); 5349 1.9 christos } 5350 1.9 christos else if (dpi->lambda_tpl_parms) 5351 1.6 christos { 5352 1.6 christos /* Show the template parm index, as that's how g++ displays 5353 1.6 christos these, and future proofs us against potential 5354 1.6 christos '[]<typename T> (T *a, T *b) {...}'. */ 5355 1.6 christos d_append_buffer (dpi, "auto:", 5); 5356 1.6 christos d_append_num (dpi, dc->u.s_number.number + 1); 5357 1.6 christos } 5358 1.6 christos else 5359 1.6 christos { 5360 1.6 christos struct d_print_template *hold_dpt; 5361 1.6 christos struct demangle_component *a = d_lookup_template_argument (dpi, dc); 5362 1.1 christos 5363 1.6 christos if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) 5364 1.6 christos a = d_index_template_argument (a, dpi->pack_index); 5365 1.1 christos 5366 1.6 christos if (a == NULL) 5367 1.6 christos { 5368 1.6 christos d_print_error (dpi); 5369 1.6 christos return; 5370 1.6 christos } 5371 1.1 christos 5372 1.6 christos /* While processing this parameter, we need to pop the list 5373 1.6 christos of templates. This is because the template parameter may 5374 1.6 christos itself be a reference to a parameter of an outer 5375 1.6 christos template. */ 5376 1.1 christos 5377 1.6 christos hold_dpt = dpi->templates; 5378 1.6 christos dpi->templates = hold_dpt->next; 5379 1.1 christos 5380 1.6 christos d_print_comp (dpi, options, a); 5381 1.1 christos 5382 1.6 christos dpi->templates = hold_dpt; 5383 1.6 christos } 5384 1.6 christos return; 5385 1.1 christos 5386 1.7 christos case DEMANGLE_COMPONENT_TPARM_OBJ: 5387 1.7 christos d_append_string (dpi, "template parameter object for "); 5388 1.7 christos d_print_comp (dpi, options, d_left (dc)); 5389 1.7 christos return; 5390 1.7 christos 5391 1.1 christos case DEMANGLE_COMPONENT_CTOR: 5392 1.1 christos d_print_comp (dpi, options, dc->u.s_ctor.name); 5393 1.1 christos return; 5394 1.1 christos 5395 1.1 christos case DEMANGLE_COMPONENT_DTOR: 5396 1.1 christos d_append_char (dpi, '~'); 5397 1.1 christos d_print_comp (dpi, options, dc->u.s_dtor.name); 5398 1.1 christos return; 5399 1.1 christos 5400 1.8 christos case DEMANGLE_COMPONENT_MODULE_INIT: 5401 1.8 christos d_append_string (dpi, "initializer for module "); 5402 1.8 christos d_print_comp (dpi, options, d_left (dc)); 5403 1.8 christos return; 5404 1.8 christos 5405 1.1 christos case DEMANGLE_COMPONENT_VTABLE: 5406 1.1 christos d_append_string (dpi, "vtable for "); 5407 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5408 1.1 christos return; 5409 1.1 christos 5410 1.1 christos case DEMANGLE_COMPONENT_VTT: 5411 1.1 christos d_append_string (dpi, "VTT for "); 5412 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5413 1.1 christos return; 5414 1.1 christos 5415 1.1 christos case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE: 5416 1.1 christos d_append_string (dpi, "construction vtable for "); 5417 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5418 1.1 christos d_append_string (dpi, "-in-"); 5419 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5420 1.1 christos return; 5421 1.1 christos 5422 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO: 5423 1.1 christos d_append_string (dpi, "typeinfo for "); 5424 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5425 1.1 christos return; 5426 1.1 christos 5427 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_NAME: 5428 1.1 christos d_append_string (dpi, "typeinfo name for "); 5429 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5430 1.1 christos return; 5431 1.1 christos 5432 1.1 christos case DEMANGLE_COMPONENT_TYPEINFO_FN: 5433 1.1 christos d_append_string (dpi, "typeinfo fn for "); 5434 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5435 1.1 christos return; 5436 1.1 christos 5437 1.1 christos case DEMANGLE_COMPONENT_THUNK: 5438 1.1 christos d_append_string (dpi, "non-virtual thunk to "); 5439 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5440 1.1 christos return; 5441 1.1 christos 5442 1.1 christos case DEMANGLE_COMPONENT_VIRTUAL_THUNK: 5443 1.1 christos d_append_string (dpi, "virtual thunk to "); 5444 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5445 1.1 christos return; 5446 1.1 christos 5447 1.1 christos case DEMANGLE_COMPONENT_COVARIANT_THUNK: 5448 1.1 christos d_append_string (dpi, "covariant return thunk to "); 5449 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5450 1.1 christos return; 5451 1.1 christos 5452 1.1 christos case DEMANGLE_COMPONENT_JAVA_CLASS: 5453 1.1 christos d_append_string (dpi, "java Class for "); 5454 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5455 1.1 christos return; 5456 1.1 christos 5457 1.1 christos case DEMANGLE_COMPONENT_GUARD: 5458 1.1 christos d_append_string (dpi, "guard variable for "); 5459 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5460 1.1 christos return; 5461 1.1 christos 5462 1.3 christos case DEMANGLE_COMPONENT_TLS_INIT: 5463 1.3 christos d_append_string (dpi, "TLS init function for "); 5464 1.3 christos d_print_comp (dpi, options, d_left (dc)); 5465 1.3 christos return; 5466 1.3 christos 5467 1.3 christos case DEMANGLE_COMPONENT_TLS_WRAPPER: 5468 1.3 christos d_append_string (dpi, "TLS wrapper function for "); 5469 1.3 christos d_print_comp (dpi, options, d_left (dc)); 5470 1.3 christos return; 5471 1.3 christos 5472 1.1 christos case DEMANGLE_COMPONENT_REFTEMP: 5473 1.1 christos d_append_string (dpi, "reference temporary #"); 5474 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5475 1.1 christos d_append_string (dpi, " for "); 5476 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5477 1.1 christos return; 5478 1.1 christos 5479 1.1 christos case DEMANGLE_COMPONENT_HIDDEN_ALIAS: 5480 1.1 christos d_append_string (dpi, "hidden alias for "); 5481 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5482 1.1 christos return; 5483 1.1 christos 5484 1.1 christos case DEMANGLE_COMPONENT_TRANSACTION_CLONE: 5485 1.1 christos d_append_string (dpi, "transaction clone for "); 5486 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5487 1.1 christos return; 5488 1.1 christos 5489 1.1 christos case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: 5490 1.1 christos d_append_string (dpi, "non-transaction clone for "); 5491 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5492 1.1 christos return; 5493 1.1 christos 5494 1.1 christos case DEMANGLE_COMPONENT_SUB_STD: 5495 1.1 christos d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len); 5496 1.1 christos return; 5497 1.1 christos 5498 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 5499 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 5500 1.1 christos case DEMANGLE_COMPONENT_CONST: 5501 1.1 christos { 5502 1.1 christos struct d_print_mod *pdpm; 5503 1.1 christos 5504 1.1 christos /* When printing arrays, it's possible to have cases where the 5505 1.1 christos same CV-qualifier gets pushed on the stack multiple times. 5506 1.1 christos We only need to print it once. */ 5507 1.1 christos 5508 1.1 christos for (pdpm = dpi->modifiers; pdpm != NULL; pdpm = pdpm->next) 5509 1.1 christos { 5510 1.1 christos if (! pdpm->printed) 5511 1.1 christos { 5512 1.1 christos if (pdpm->mod->type != DEMANGLE_COMPONENT_RESTRICT 5513 1.1 christos && pdpm->mod->type != DEMANGLE_COMPONENT_VOLATILE 5514 1.1 christos && pdpm->mod->type != DEMANGLE_COMPONENT_CONST) 5515 1.1 christos break; 5516 1.1 christos if (pdpm->mod->type == dc->type) 5517 1.1 christos { 5518 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5519 1.1 christos return; 5520 1.1 christos } 5521 1.1 christos } 5522 1.1 christos } 5523 1.1 christos } 5524 1.1 christos goto modifier; 5525 1.1 christos 5526 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 5527 1.1 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 5528 1.1 christos { 5529 1.1 christos /* Handle reference smashing: & + && = &. */ 5530 1.6 christos struct demangle_component *sub = d_left (dc); 5531 1.9 christos if (!dpi->lambda_tpl_parms 5532 1.6 christos && sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM) 5533 1.1 christos { 5534 1.3 christos struct d_saved_scope *scope = d_get_saved_scope (dpi, sub); 5535 1.3 christos struct demangle_component *a; 5536 1.3 christos 5537 1.3 christos if (scope == NULL) 5538 1.3 christos { 5539 1.3 christos /* This is the first time SUB has been traversed. 5540 1.3 christos We need to capture the current templates so 5541 1.3 christos they can be restored if SUB is reentered as a 5542 1.3 christos substitution. */ 5543 1.3 christos d_save_scope (dpi, sub); 5544 1.3 christos if (d_print_saw_error (dpi)) 5545 1.3 christos return; 5546 1.3 christos } 5547 1.3 christos else 5548 1.3 christos { 5549 1.3 christos const struct d_component_stack *dcse; 5550 1.3 christos int found_self_or_parent = 0; 5551 1.3 christos 5552 1.3 christos /* This traversal is reentering SUB as a substition. 5553 1.3 christos If we are not beneath SUB or DC in the tree then we 5554 1.3 christos need to restore SUB's template stack temporarily. */ 5555 1.3 christos for (dcse = dpi->component_stack; dcse != NULL; 5556 1.3 christos dcse = dcse->parent) 5557 1.3 christos { 5558 1.3 christos if (dcse->dc == sub 5559 1.3 christos || (dcse->dc == dc 5560 1.3 christos && dcse != dpi->component_stack)) 5561 1.3 christos { 5562 1.3 christos found_self_or_parent = 1; 5563 1.3 christos break; 5564 1.3 christos } 5565 1.3 christos } 5566 1.3 christos 5567 1.3 christos if (!found_self_or_parent) 5568 1.3 christos { 5569 1.3 christos saved_templates = dpi->templates; 5570 1.3 christos dpi->templates = scope->templates; 5571 1.3 christos need_template_restore = 1; 5572 1.3 christos } 5573 1.3 christos } 5574 1.3 christos 5575 1.3 christos a = d_lookup_template_argument (dpi, sub); 5576 1.1 christos if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) 5577 1.1 christos a = d_index_template_argument (a, dpi->pack_index); 5578 1.1 christos 5579 1.1 christos if (a == NULL) 5580 1.1 christos { 5581 1.3 christos if (need_template_restore) 5582 1.3 christos dpi->templates = saved_templates; 5583 1.3 christos 5584 1.1 christos d_print_error (dpi); 5585 1.1 christos return; 5586 1.1 christos } 5587 1.1 christos 5588 1.1 christos sub = a; 5589 1.1 christos } 5590 1.1 christos 5591 1.1 christos if (sub->type == DEMANGLE_COMPONENT_REFERENCE 5592 1.1 christos || sub->type == dc->type) 5593 1.1 christos dc = sub; 5594 1.1 christos else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE) 5595 1.1 christos mod_inner = d_left (sub); 5596 1.1 christos } 5597 1.1 christos /* Fall through. */ 5598 1.1 christos 5599 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 5600 1.1 christos case DEMANGLE_COMPONENT_POINTER: 5601 1.1 christos case DEMANGLE_COMPONENT_COMPLEX: 5602 1.1 christos case DEMANGLE_COMPONENT_IMAGINARY: 5603 1.6 christos FNQUAL_COMPONENT_CASE: 5604 1.1 christos modifier: 5605 1.1 christos { 5606 1.1 christos /* We keep a list of modifiers on the stack. */ 5607 1.1 christos struct d_print_mod dpm; 5608 1.1 christos 5609 1.1 christos dpm.next = dpi->modifiers; 5610 1.1 christos dpi->modifiers = &dpm; 5611 1.1 christos dpm.mod = dc; 5612 1.1 christos dpm.printed = 0; 5613 1.1 christos dpm.templates = dpi->templates; 5614 1.1 christos 5615 1.1 christos if (!mod_inner) 5616 1.1 christos mod_inner = d_left (dc); 5617 1.1 christos 5618 1.1 christos d_print_comp (dpi, options, mod_inner); 5619 1.1 christos 5620 1.1 christos /* If the modifier didn't get printed by the type, print it 5621 1.1 christos now. */ 5622 1.1 christos if (! dpm.printed) 5623 1.1 christos d_print_mod (dpi, options, dc); 5624 1.1 christos 5625 1.1 christos dpi->modifiers = dpm.next; 5626 1.1 christos 5627 1.3 christos if (need_template_restore) 5628 1.3 christos dpi->templates = saved_templates; 5629 1.3 christos 5630 1.1 christos return; 5631 1.1 christos } 5632 1.1 christos 5633 1.1 christos case DEMANGLE_COMPONENT_BUILTIN_TYPE: 5634 1.1 christos if ((options & DMGL_JAVA) == 0) 5635 1.1 christos d_append_buffer (dpi, dc->u.s_builtin.type->name, 5636 1.1 christos dc->u.s_builtin.type->len); 5637 1.1 christos else 5638 1.1 christos d_append_buffer (dpi, dc->u.s_builtin.type->java_name, 5639 1.1 christos dc->u.s_builtin.type->java_len); 5640 1.1 christos return; 5641 1.1 christos 5642 1.9 christos case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE: 5643 1.9 christos d_append_buffer (dpi, dc->u.s_extended_builtin.type->name, 5644 1.9 christos dc->u.s_extended_builtin.type->len); 5645 1.9 christos d_append_num (dpi, dc->u.s_extended_builtin.arg); 5646 1.9 christos if (dc->u.s_extended_builtin.suffix) 5647 1.9 christos d_append_buffer (dpi, &dc->u.s_extended_builtin.suffix, 1); 5648 1.9 christos return; 5649 1.9 christos 5650 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE: 5651 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5652 1.1 christos return; 5653 1.1 christos 5654 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_TYPE: 5655 1.1 christos { 5656 1.1 christos if ((options & DMGL_RET_POSTFIX) != 0) 5657 1.1 christos d_print_function_type (dpi, 5658 1.1 christos options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), 5659 1.1 christos dc, dpi->modifiers); 5660 1.1 christos 5661 1.1 christos /* Print return type if present */ 5662 1.1 christos if (d_left (dc) != NULL && (options & DMGL_RET_POSTFIX) != 0) 5663 1.1 christos d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), 5664 1.1 christos d_left (dc)); 5665 1.1 christos else if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0) 5666 1.1 christos { 5667 1.1 christos struct d_print_mod dpm; 5668 1.1 christos 5669 1.1 christos /* We must pass this type down as a modifier in order to 5670 1.1 christos print it in the right location. */ 5671 1.1 christos dpm.next = dpi->modifiers; 5672 1.1 christos dpi->modifiers = &dpm; 5673 1.1 christos dpm.mod = dc; 5674 1.1 christos dpm.printed = 0; 5675 1.1 christos dpm.templates = dpi->templates; 5676 1.1 christos 5677 1.1 christos d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), 5678 1.1 christos d_left (dc)); 5679 1.1 christos 5680 1.1 christos dpi->modifiers = dpm.next; 5681 1.1 christos 5682 1.1 christos if (dpm.printed) 5683 1.1 christos return; 5684 1.1 christos 5685 1.1 christos /* In standard prefix notation, there is a space between the 5686 1.1 christos return type and the function signature. */ 5687 1.1 christos if ((options & DMGL_RET_POSTFIX) == 0) 5688 1.1 christos d_append_char (dpi, ' '); 5689 1.1 christos } 5690 1.1 christos 5691 1.1 christos if ((options & DMGL_RET_POSTFIX) == 0) 5692 1.1 christos d_print_function_type (dpi, 5693 1.1 christos options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), 5694 1.1 christos dc, dpi->modifiers); 5695 1.1 christos 5696 1.1 christos return; 5697 1.1 christos } 5698 1.1 christos 5699 1.1 christos case DEMANGLE_COMPONENT_ARRAY_TYPE: 5700 1.1 christos { 5701 1.1 christos struct d_print_mod *hold_modifiers; 5702 1.1 christos struct d_print_mod adpm[4]; 5703 1.1 christos unsigned int i; 5704 1.1 christos struct d_print_mod *pdpm; 5705 1.1 christos 5706 1.1 christos /* We must pass this type down as a modifier in order to print 5707 1.1 christos multi-dimensional arrays correctly. If the array itself is 5708 1.1 christos CV-qualified, we act as though the element type were 5709 1.1 christos CV-qualified. We do this by copying the modifiers down 5710 1.1 christos rather than fiddling pointers, so that we don't wind up 5711 1.1 christos with a d_print_mod higher on the stack pointing into our 5712 1.1 christos stack frame after we return. */ 5713 1.1 christos 5714 1.1 christos hold_modifiers = dpi->modifiers; 5715 1.1 christos 5716 1.1 christos adpm[0].next = hold_modifiers; 5717 1.1 christos dpi->modifiers = &adpm[0]; 5718 1.1 christos adpm[0].mod = dc; 5719 1.1 christos adpm[0].printed = 0; 5720 1.1 christos adpm[0].templates = dpi->templates; 5721 1.1 christos 5722 1.1 christos i = 1; 5723 1.1 christos pdpm = hold_modifiers; 5724 1.1 christos while (pdpm != NULL 5725 1.1 christos && (pdpm->mod->type == DEMANGLE_COMPONENT_RESTRICT 5726 1.1 christos || pdpm->mod->type == DEMANGLE_COMPONENT_VOLATILE 5727 1.1 christos || pdpm->mod->type == DEMANGLE_COMPONENT_CONST)) 5728 1.1 christos { 5729 1.1 christos if (! pdpm->printed) 5730 1.1 christos { 5731 1.1 christos if (i >= sizeof adpm / sizeof adpm[0]) 5732 1.1 christos { 5733 1.1 christos d_print_error (dpi); 5734 1.1 christos return; 5735 1.1 christos } 5736 1.1 christos 5737 1.1 christos adpm[i] = *pdpm; 5738 1.1 christos adpm[i].next = dpi->modifiers; 5739 1.1 christos dpi->modifiers = &adpm[i]; 5740 1.1 christos pdpm->printed = 1; 5741 1.1 christos ++i; 5742 1.1 christos } 5743 1.1 christos 5744 1.1 christos pdpm = pdpm->next; 5745 1.1 christos } 5746 1.1 christos 5747 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5748 1.1 christos 5749 1.1 christos dpi->modifiers = hold_modifiers; 5750 1.1 christos 5751 1.1 christos if (adpm[0].printed) 5752 1.1 christos return; 5753 1.1 christos 5754 1.1 christos while (i > 1) 5755 1.1 christos { 5756 1.1 christos --i; 5757 1.1 christos d_print_mod (dpi, options, adpm[i].mod); 5758 1.1 christos } 5759 1.1 christos 5760 1.1 christos d_print_array_type (dpi, options, dc, dpi->modifiers); 5761 1.1 christos 5762 1.1 christos return; 5763 1.1 christos } 5764 1.1 christos 5765 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 5766 1.1 christos case DEMANGLE_COMPONENT_VECTOR_TYPE: 5767 1.1 christos { 5768 1.1 christos struct d_print_mod dpm; 5769 1.1 christos 5770 1.1 christos dpm.next = dpi->modifiers; 5771 1.1 christos dpi->modifiers = &dpm; 5772 1.1 christos dpm.mod = dc; 5773 1.1 christos dpm.printed = 0; 5774 1.1 christos dpm.templates = dpi->templates; 5775 1.1 christos 5776 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5777 1.1 christos 5778 1.1 christos /* If the modifier didn't get printed by the type, print it 5779 1.1 christos now. */ 5780 1.1 christos if (! dpm.printed) 5781 1.1 christos d_print_mod (dpi, options, dc); 5782 1.1 christos 5783 1.1 christos dpi->modifiers = dpm.next; 5784 1.1 christos 5785 1.1 christos return; 5786 1.1 christos } 5787 1.1 christos 5788 1.1 christos case DEMANGLE_COMPONENT_ARGLIST: 5789 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: 5790 1.1 christos if (d_left (dc) != NULL) 5791 1.1 christos d_print_comp (dpi, options, d_left (dc)); 5792 1.1 christos if (d_right (dc) != NULL) 5793 1.1 christos { 5794 1.1 christos size_t len; 5795 1.1 christos unsigned long int flush_count; 5796 1.1 christos /* Make sure ", " isn't flushed by d_append_string, otherwise 5797 1.1 christos dpi->len -= 2 wouldn't work. */ 5798 1.1 christos if (dpi->len >= sizeof (dpi->buf) - 2) 5799 1.1 christos d_print_flush (dpi); 5800 1.1 christos d_append_string (dpi, ", "); 5801 1.1 christos len = dpi->len; 5802 1.1 christos flush_count = dpi->flush_count; 5803 1.1 christos d_print_comp (dpi, options, d_right (dc)); 5804 1.1 christos /* If that didn't print anything (which can happen with empty 5805 1.1 christos template argument packs), remove the comma and space. */ 5806 1.1 christos if (dpi->flush_count == flush_count && dpi->len == len) 5807 1.1 christos dpi->len -= 2; 5808 1.1 christos } 5809 1.1 christos return; 5810 1.1 christos 5811 1.1 christos case DEMANGLE_COMPONENT_INITIALIZER_LIST: 5812 1.1 christos { 5813 1.1 christos struct demangle_component *type = d_left (dc); 5814 1.1 christos struct demangle_component *list = d_right (dc); 5815 1.1 christos 5816 1.1 christos if (type) 5817 1.1 christos d_print_comp (dpi, options, type); 5818 1.1 christos d_append_char (dpi, '{'); 5819 1.1 christos d_print_comp (dpi, options, list); 5820 1.1 christos d_append_char (dpi, '}'); 5821 1.1 christos } 5822 1.1 christos return; 5823 1.1 christos 5824 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 5825 1.1 christos { 5826 1.1 christos const struct demangle_operator_info *op = dc->u.s_operator.op; 5827 1.1 christos int len = op->len; 5828 1.1 christos 5829 1.1 christos d_append_string (dpi, "operator"); 5830 1.1 christos /* Add a space before new/delete. */ 5831 1.1 christos if (IS_LOWER (op->name[0])) 5832 1.1 christos d_append_char (dpi, ' '); 5833 1.1 christos /* Omit a trailing space. */ 5834 1.1 christos if (op->name[len-1] == ' ') 5835 1.1 christos --len; 5836 1.1 christos d_append_buffer (dpi, op->name, len); 5837 1.1 christos return; 5838 1.1 christos } 5839 1.1 christos 5840 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 5841 1.1 christos d_append_string (dpi, "operator "); 5842 1.1 christos d_print_comp (dpi, options, dc->u.s_extended_operator.name); 5843 1.1 christos return; 5844 1.1 christos 5845 1.5 christos case DEMANGLE_COMPONENT_CONVERSION: 5846 1.1 christos d_append_string (dpi, "operator "); 5847 1.5 christos d_print_conversion (dpi, options, dc); 5848 1.1 christos return; 5849 1.1 christos 5850 1.1 christos case DEMANGLE_COMPONENT_NULLARY: 5851 1.1 christos d_print_expr_op (dpi, options, d_left (dc)); 5852 1.1 christos return; 5853 1.1 christos 5854 1.1 christos case DEMANGLE_COMPONENT_UNARY: 5855 1.1 christos { 5856 1.1 christos struct demangle_component *op = d_left (dc); 5857 1.1 christos struct demangle_component *operand = d_right (dc); 5858 1.1 christos const char *code = NULL; 5859 1.1 christos 5860 1.1 christos if (op->type == DEMANGLE_COMPONENT_OPERATOR) 5861 1.1 christos { 5862 1.1 christos code = op->u.s_operator.op->code; 5863 1.1 christos if (!strcmp (code, "ad")) 5864 1.1 christos { 5865 1.1 christos /* Don't print the argument list for the address of a 5866 1.1 christos function. */ 5867 1.1 christos if (operand->type == DEMANGLE_COMPONENT_TYPED_NAME 5868 1.1 christos && d_left (operand)->type == DEMANGLE_COMPONENT_QUAL_NAME 5869 1.1 christos && d_right (operand)->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) 5870 1.1 christos operand = d_left (operand); 5871 1.1 christos } 5872 1.1 christos if (operand->type == DEMANGLE_COMPONENT_BINARY_ARGS) 5873 1.1 christos { 5874 1.1 christos /* This indicates a suffix operator. */ 5875 1.1 christos operand = d_left (operand); 5876 1.1 christos d_print_subexpr (dpi, options, operand); 5877 1.1 christos d_print_expr_op (dpi, options, op); 5878 1.1 christos return; 5879 1.1 christos } 5880 1.1 christos } 5881 1.1 christos 5882 1.6 christos /* For sizeof..., just print the pack length. */ 5883 1.6 christos if (code && !strcmp (code, "sZ")) 5884 1.6 christos { 5885 1.6 christos struct demangle_component *a = d_find_pack (dpi, operand); 5886 1.6 christos int len = d_pack_length (a); 5887 1.6 christos d_append_num (dpi, len); 5888 1.6 christos return; 5889 1.6 christos } 5890 1.6 christos else if (code && !strcmp (code, "sP")) 5891 1.6 christos { 5892 1.6 christos int len = d_args_length (dpi, operand); 5893 1.6 christos d_append_num (dpi, len); 5894 1.6 christos return; 5895 1.6 christos } 5896 1.6 christos 5897 1.1 christos if (op->type != DEMANGLE_COMPONENT_CAST) 5898 1.1 christos d_print_expr_op (dpi, options, op); 5899 1.1 christos else 5900 1.1 christos { 5901 1.1 christos d_append_char (dpi, '('); 5902 1.1 christos d_print_cast (dpi, options, op); 5903 1.1 christos d_append_char (dpi, ')'); 5904 1.1 christos } 5905 1.1 christos if (code && !strcmp (code, "gs")) 5906 1.1 christos /* Avoid parens after '::'. */ 5907 1.1 christos d_print_comp (dpi, options, operand); 5908 1.9 christos else if (code && (!strcmp (code, "st") || !strcmp (code, "nx"))) 5909 1.9 christos /* Always print parens for sizeof (type) and noexcept(expr). */ 5910 1.1 christos { 5911 1.1 christos d_append_char (dpi, '('); 5912 1.1 christos d_print_comp (dpi, options, operand); 5913 1.1 christos d_append_char (dpi, ')'); 5914 1.1 christos } 5915 1.1 christos else 5916 1.1 christos d_print_subexpr (dpi, options, operand); 5917 1.1 christos } 5918 1.1 christos return; 5919 1.1 christos 5920 1.1 christos case DEMANGLE_COMPONENT_BINARY: 5921 1.1 christos if (d_right (dc)->type != DEMANGLE_COMPONENT_BINARY_ARGS) 5922 1.1 christos { 5923 1.1 christos d_print_error (dpi); 5924 1.1 christos return; 5925 1.1 christos } 5926 1.1 christos 5927 1.1 christos if (op_is_new_cast (d_left (dc))) 5928 1.1 christos { 5929 1.1 christos d_print_expr_op (dpi, options, d_left (dc)); 5930 1.1 christos d_append_char (dpi, '<'); 5931 1.1 christos d_print_comp (dpi, options, d_left (d_right (dc))); 5932 1.1 christos d_append_string (dpi, ">("); 5933 1.1 christos d_print_comp (dpi, options, d_right (d_right (dc))); 5934 1.1 christos d_append_char (dpi, ')'); 5935 1.1 christos return; 5936 1.1 christos } 5937 1.1 christos 5938 1.6 christos if (d_maybe_print_fold_expression (dpi, options, dc)) 5939 1.6 christos return; 5940 1.6 christos 5941 1.8 christos if (d_maybe_print_designated_init (dpi, options, dc)) 5942 1.8 christos return; 5943 1.8 christos 5944 1.1 christos /* We wrap an expression which uses the greater-than operator in 5945 1.1 christos an extra layer of parens so that it does not get confused 5946 1.1 christos with the '>' which ends the template parameters. */ 5947 1.1 christos if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR 5948 1.1 christos && d_left (dc)->u.s_operator.op->len == 1 5949 1.1 christos && d_left (dc)->u.s_operator.op->name[0] == '>') 5950 1.1 christos d_append_char (dpi, '('); 5951 1.1 christos 5952 1.1 christos if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") == 0 5953 1.1 christos && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_TYPED_NAME) 5954 1.1 christos { 5955 1.1 christos /* Function call used in an expression should not have printed types 5956 1.1 christos of the function arguments. Values of the function arguments still 5957 1.1 christos get printed below. */ 5958 1.1 christos 5959 1.1 christos const struct demangle_component *func = d_left (d_right (dc)); 5960 1.1 christos 5961 1.1 christos if (d_right (func)->type != DEMANGLE_COMPONENT_FUNCTION_TYPE) 5962 1.1 christos d_print_error (dpi); 5963 1.1 christos d_print_subexpr (dpi, options, d_left (func)); 5964 1.1 christos } 5965 1.1 christos else 5966 1.1 christos d_print_subexpr (dpi, options, d_left (d_right (dc))); 5967 1.1 christos if (strcmp (d_left (dc)->u.s_operator.op->code, "ix") == 0) 5968 1.1 christos { 5969 1.1 christos d_append_char (dpi, '['); 5970 1.1 christos d_print_comp (dpi, options, d_right (d_right (dc))); 5971 1.1 christos d_append_char (dpi, ']'); 5972 1.1 christos } 5973 1.1 christos else 5974 1.1 christos { 5975 1.1 christos if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0) 5976 1.1 christos d_print_expr_op (dpi, options, d_left (dc)); 5977 1.1 christos d_print_subexpr (dpi, options, d_right (d_right (dc))); 5978 1.1 christos } 5979 1.1 christos 5980 1.1 christos if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR 5981 1.1 christos && d_left (dc)->u.s_operator.op->len == 1 5982 1.1 christos && d_left (dc)->u.s_operator.op->name[0] == '>') 5983 1.1 christos d_append_char (dpi, ')'); 5984 1.1 christos 5985 1.1 christos return; 5986 1.1 christos 5987 1.1 christos case DEMANGLE_COMPONENT_BINARY_ARGS: 5988 1.1 christos /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */ 5989 1.1 christos d_print_error (dpi); 5990 1.1 christos return; 5991 1.1 christos 5992 1.1 christos case DEMANGLE_COMPONENT_TRINARY: 5993 1.1 christos if (d_right (dc)->type != DEMANGLE_COMPONENT_TRINARY_ARG1 5994 1.1 christos || d_right (d_right (dc))->type != DEMANGLE_COMPONENT_TRINARY_ARG2) 5995 1.1 christos { 5996 1.1 christos d_print_error (dpi); 5997 1.1 christos return; 5998 1.1 christos } 5999 1.6 christos if (d_maybe_print_fold_expression (dpi, options, dc)) 6000 1.6 christos return; 6001 1.8 christos if (d_maybe_print_designated_init (dpi, options, dc)) 6002 1.8 christos return; 6003 1.1 christos { 6004 1.1 christos struct demangle_component *op = d_left (dc); 6005 1.1 christos struct demangle_component *first = d_left (d_right (dc)); 6006 1.1 christos struct demangle_component *second = d_left (d_right (d_right (dc))); 6007 1.1 christos struct demangle_component *third = d_right (d_right (d_right (dc))); 6008 1.1 christos 6009 1.1 christos if (!strcmp (op->u.s_operator.op->code, "qu")) 6010 1.1 christos { 6011 1.1 christos d_print_subexpr (dpi, options, first); 6012 1.1 christos d_print_expr_op (dpi, options, op); 6013 1.1 christos d_print_subexpr (dpi, options, second); 6014 1.1 christos d_append_string (dpi, " : "); 6015 1.1 christos d_print_subexpr (dpi, options, third); 6016 1.1 christos } 6017 1.1 christos else 6018 1.1 christos { 6019 1.1 christos d_append_string (dpi, "new "); 6020 1.1 christos if (d_left (first) != NULL) 6021 1.1 christos { 6022 1.1 christos d_print_subexpr (dpi, options, first); 6023 1.1 christos d_append_char (dpi, ' '); 6024 1.1 christos } 6025 1.1 christos d_print_comp (dpi, options, second); 6026 1.1 christos if (third) 6027 1.1 christos d_print_subexpr (dpi, options, third); 6028 1.1 christos } 6029 1.1 christos } 6030 1.1 christos return; 6031 1.1 christos 6032 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG1: 6033 1.1 christos case DEMANGLE_COMPONENT_TRINARY_ARG2: 6034 1.1 christos /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */ 6035 1.1 christos d_print_error (dpi); 6036 1.1 christos return; 6037 1.1 christos 6038 1.1 christos case DEMANGLE_COMPONENT_LITERAL: 6039 1.1 christos case DEMANGLE_COMPONENT_LITERAL_NEG: 6040 1.1 christos { 6041 1.1 christos enum d_builtin_type_print tp; 6042 1.1 christos 6043 1.1 christos /* For some builtin types, produce simpler output. */ 6044 1.1 christos tp = D_PRINT_DEFAULT; 6045 1.1 christos if (d_left (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE) 6046 1.1 christos { 6047 1.1 christos tp = d_left (dc)->u.s_builtin.type->print; 6048 1.1 christos switch (tp) 6049 1.1 christos { 6050 1.1 christos case D_PRINT_INT: 6051 1.1 christos case D_PRINT_UNSIGNED: 6052 1.1 christos case D_PRINT_LONG: 6053 1.1 christos case D_PRINT_UNSIGNED_LONG: 6054 1.1 christos case D_PRINT_LONG_LONG: 6055 1.1 christos case D_PRINT_UNSIGNED_LONG_LONG: 6056 1.1 christos if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME) 6057 1.1 christos { 6058 1.1 christos if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG) 6059 1.1 christos d_append_char (dpi, '-'); 6060 1.1 christos d_print_comp (dpi, options, d_right (dc)); 6061 1.1 christos switch (tp) 6062 1.1 christos { 6063 1.1 christos default: 6064 1.1 christos break; 6065 1.1 christos case D_PRINT_UNSIGNED: 6066 1.1 christos d_append_char (dpi, 'u'); 6067 1.1 christos break; 6068 1.1 christos case D_PRINT_LONG: 6069 1.1 christos d_append_char (dpi, 'l'); 6070 1.1 christos break; 6071 1.1 christos case D_PRINT_UNSIGNED_LONG: 6072 1.1 christos d_append_string (dpi, "ul"); 6073 1.1 christos break; 6074 1.1 christos case D_PRINT_LONG_LONG: 6075 1.1 christos d_append_string (dpi, "ll"); 6076 1.1 christos break; 6077 1.1 christos case D_PRINT_UNSIGNED_LONG_LONG: 6078 1.1 christos d_append_string (dpi, "ull"); 6079 1.1 christos break; 6080 1.1 christos } 6081 1.1 christos return; 6082 1.1 christos } 6083 1.1 christos break; 6084 1.1 christos 6085 1.1 christos case D_PRINT_BOOL: 6086 1.1 christos if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME 6087 1.1 christos && d_right (dc)->u.s_name.len == 1 6088 1.1 christos && dc->type == DEMANGLE_COMPONENT_LITERAL) 6089 1.1 christos { 6090 1.1 christos switch (d_right (dc)->u.s_name.s[0]) 6091 1.1 christos { 6092 1.1 christos case '0': 6093 1.1 christos d_append_string (dpi, "false"); 6094 1.1 christos return; 6095 1.1 christos case '1': 6096 1.1 christos d_append_string (dpi, "true"); 6097 1.1 christos return; 6098 1.1 christos default: 6099 1.1 christos break; 6100 1.1 christos } 6101 1.1 christos } 6102 1.1 christos break; 6103 1.1 christos 6104 1.1 christos default: 6105 1.1 christos break; 6106 1.1 christos } 6107 1.1 christos } 6108 1.1 christos 6109 1.1 christos d_append_char (dpi, '('); 6110 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6111 1.1 christos d_append_char (dpi, ')'); 6112 1.1 christos if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG) 6113 1.1 christos d_append_char (dpi, '-'); 6114 1.1 christos if (tp == D_PRINT_FLOAT) 6115 1.1 christos d_append_char (dpi, '['); 6116 1.1 christos d_print_comp (dpi, options, d_right (dc)); 6117 1.1 christos if (tp == D_PRINT_FLOAT) 6118 1.1 christos d_append_char (dpi, ']'); 6119 1.1 christos } 6120 1.1 christos return; 6121 1.1 christos 6122 1.8 christos case DEMANGLE_COMPONENT_VENDOR_EXPR: 6123 1.8 christos d_print_comp (dpi, options, d_left (dc)); 6124 1.8 christos d_append_char (dpi, '('); 6125 1.8 christos d_print_comp (dpi, options, d_right (dc)); 6126 1.8 christos d_append_char (dpi, ')'); 6127 1.8 christos return; 6128 1.8 christos 6129 1.1 christos case DEMANGLE_COMPONENT_NUMBER: 6130 1.1 christos d_append_num (dpi, dc->u.s_number.number); 6131 1.1 christos return; 6132 1.1 christos 6133 1.1 christos case DEMANGLE_COMPONENT_JAVA_RESOURCE: 6134 1.1 christos d_append_string (dpi, "java resource "); 6135 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6136 1.1 christos return; 6137 1.1 christos 6138 1.1 christos case DEMANGLE_COMPONENT_COMPOUND_NAME: 6139 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6140 1.1 christos d_print_comp (dpi, options, d_right (dc)); 6141 1.1 christos return; 6142 1.1 christos 6143 1.1 christos case DEMANGLE_COMPONENT_CHARACTER: 6144 1.1 christos d_append_char (dpi, dc->u.s_character.character); 6145 1.1 christos return; 6146 1.1 christos 6147 1.1 christos case DEMANGLE_COMPONENT_DECLTYPE: 6148 1.1 christos d_append_string (dpi, "decltype ("); 6149 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6150 1.1 christos d_append_char (dpi, ')'); 6151 1.1 christos return; 6152 1.1 christos 6153 1.1 christos case DEMANGLE_COMPONENT_PACK_EXPANSION: 6154 1.1 christos { 6155 1.9 christos struct demangle_component *a = NULL; 6156 1.9 christos 6157 1.9 christos if (!dpi->lambda_tpl_parms) 6158 1.9 christos a = d_find_pack (dpi, d_left (dc)); 6159 1.1 christos if (a == NULL) 6160 1.1 christos { 6161 1.1 christos /* d_find_pack won't find anything if the only packs involved 6162 1.1 christos in this expansion are function parameter packs; in that 6163 1.1 christos case, just print the pattern and "...". */ 6164 1.1 christos d_print_subexpr (dpi, options, d_left (dc)); 6165 1.1 christos d_append_string (dpi, "..."); 6166 1.1 christos } 6167 1.9 christos else 6168 1.9 christos { 6169 1.9 christos int len = d_pack_length (a); 6170 1.9 christos int i; 6171 1.1 christos 6172 1.9 christos dc = d_left (dc); 6173 1.9 christos for (i = 0; i < len; ++i) 6174 1.9 christos { 6175 1.9 christos if (i) 6176 1.9 christos d_append_string (dpi, ", "); 6177 1.9 christos dpi->pack_index = i; 6178 1.9 christos d_print_comp (dpi, options, dc); 6179 1.9 christos } 6180 1.1 christos } 6181 1.1 christos } 6182 1.1 christos return; 6183 1.1 christos 6184 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_PARAM: 6185 1.1 christos { 6186 1.1 christos long num = dc->u.s_number.number; 6187 1.1 christos if (num == 0) 6188 1.1 christos d_append_string (dpi, "this"); 6189 1.1 christos else 6190 1.1 christos { 6191 1.1 christos d_append_string (dpi, "{parm#"); 6192 1.1 christos d_append_num (dpi, num); 6193 1.1 christos d_append_char (dpi, '}'); 6194 1.1 christos } 6195 1.1 christos } 6196 1.1 christos return; 6197 1.1 christos 6198 1.1 christos case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS: 6199 1.1 christos d_append_string (dpi, "global constructors keyed to "); 6200 1.1 christos d_print_comp (dpi, options, dc->u.s_binary.left); 6201 1.1 christos return; 6202 1.1 christos 6203 1.1 christos case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS: 6204 1.1 christos d_append_string (dpi, "global destructors keyed to "); 6205 1.1 christos d_print_comp (dpi, options, dc->u.s_binary.left); 6206 1.1 christos return; 6207 1.1 christos 6208 1.1 christos case DEMANGLE_COMPONENT_LAMBDA: 6209 1.9 christos { 6210 1.9 christos d_append_string (dpi, "{lambda"); 6211 1.9 christos struct demangle_component *parms = dc->u.s_unary_num.sub; 6212 1.9 christos struct d_print_template dpt; 6213 1.9 christos /* Generic lambda auto parms are mangled as the (synthedic) template 6214 1.9 christos type parm they are. We need to tell the printer that (a) we're in 6215 1.9 christos a lambda, and (b) the number of synthetic parms. */ 6216 1.9 christos int saved_tpl_parms = dpi->lambda_tpl_parms; 6217 1.9 christos dpi->lambda_tpl_parms = 0; 6218 1.9 christos /* Hang any lambda head as-if template args. */ 6219 1.9 christos dpt.template_decl = NULL; 6220 1.9 christos dpt.next = dpi->templates; 6221 1.9 christos dpi->templates = &dpt; 6222 1.9 christos if (parms && parms->type == DEMANGLE_COMPONENT_TEMPLATE_HEAD) 6223 1.9 christos { 6224 1.9 christos dpt.template_decl = parms; 6225 1.9 christos 6226 1.9 christos d_append_char (dpi, '<'); 6227 1.9 christos struct demangle_component *parm; 6228 1.9 christos for (parm = d_left (parms); parm; parm = d_right (parm)) 6229 1.9 christos { 6230 1.9 christos if (dpi->lambda_tpl_parms++) 6231 1.9 christos d_append_string (dpi, ", "); 6232 1.9 christos d_print_comp (dpi, options, parm); 6233 1.9 christos d_append_char (dpi, ' '); 6234 1.9 christos if (parm->type == DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM) 6235 1.9 christos parm = d_left (parm); 6236 1.9 christos d_print_lambda_parm_name (dpi, parm->type, 6237 1.9 christos dpi->lambda_tpl_parms - 1); 6238 1.9 christos } 6239 1.9 christos d_append_char (dpi, '>'); 6240 1.9 christos 6241 1.9 christos parms = d_right (parms); 6242 1.9 christos } 6243 1.9 christos dpi->lambda_tpl_parms++; 6244 1.9 christos 6245 1.9 christos d_append_char (dpi, '('); 6246 1.9 christos d_print_comp (dpi, options, parms); 6247 1.9 christos dpi->lambda_tpl_parms = saved_tpl_parms; 6248 1.9 christos dpi->templates = dpt.next; 6249 1.9 christos d_append_string (dpi, ")#"); 6250 1.9 christos d_append_num (dpi, dc->u.s_unary_num.num + 1); 6251 1.9 christos d_append_char (dpi, '}'); 6252 1.9 christos } 6253 1.1 christos return; 6254 1.1 christos 6255 1.1 christos case DEMANGLE_COMPONENT_UNNAMED_TYPE: 6256 1.1 christos d_append_string (dpi, "{unnamed type#"); 6257 1.1 christos d_append_num (dpi, dc->u.s_number.number + 1); 6258 1.1 christos d_append_char (dpi, '}'); 6259 1.1 christos return; 6260 1.1 christos 6261 1.1 christos case DEMANGLE_COMPONENT_CLONE: 6262 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6263 1.1 christos d_append_string (dpi, " [clone "); 6264 1.1 christos d_print_comp (dpi, options, d_right (dc)); 6265 1.1 christos d_append_char (dpi, ']'); 6266 1.1 christos return; 6267 1.1 christos 6268 1.9 christos case DEMANGLE_COMPONENT_FRIEND: 6269 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6270 1.9 christos d_append_string (dpi, "[friend]"); 6271 1.9 christos return; 6272 1.9 christos 6273 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_HEAD: 6274 1.9 christos { 6275 1.9 christos d_append_char (dpi, '<'); 6276 1.9 christos int count = 0; 6277 1.9 christos struct demangle_component *parm; 6278 1.9 christos for (parm = d_left (dc); parm; parm = d_right (parm)) 6279 1.9 christos { 6280 1.9 christos if (count++) 6281 1.9 christos d_append_string (dpi, ", "); 6282 1.9 christos d_print_comp (dpi, options, parm); 6283 1.9 christos } 6284 1.9 christos d_append_char (dpi, '>'); 6285 1.9 christos } 6286 1.9 christos return; 6287 1.9 christos 6288 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM: 6289 1.9 christos d_append_string (dpi, "typename"); 6290 1.9 christos return; 6291 1.9 christos 6292 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM: 6293 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6294 1.9 christos return; 6295 1.9 christos 6296 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM: 6297 1.9 christos d_append_string (dpi, "template"); 6298 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6299 1.9 christos d_append_string (dpi, " class"); 6300 1.9 christos return; 6301 1.9 christos 6302 1.9 christos case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM: 6303 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6304 1.9 christos d_append_string (dpi, "..."); 6305 1.9 christos return; 6306 1.9 christos 6307 1.9 christos case DEMANGLE_COMPONENT_CONSTRAINTS: 6308 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6309 1.9 christos d_append_string (dpi, " requires "); 6310 1.9 christos d_print_comp (dpi, options, d_right (dc)); 6311 1.9 christos return; 6312 1.9 christos 6313 1.1 christos default: 6314 1.1 christos d_print_error (dpi); 6315 1.1 christos return; 6316 1.1 christos } 6317 1.1 christos } 6318 1.1 christos 6319 1.3 christos static void 6320 1.3 christos d_print_comp (struct d_print_info *dpi, int options, 6321 1.6 christos struct demangle_component *dc) 6322 1.3 christos { 6323 1.3 christos struct d_component_stack self; 6324 1.6 christos if (dc == NULL || dc->d_printing > 1 || dpi->recursion > MAX_RECURSION_COUNT) 6325 1.6 christos { 6326 1.6 christos d_print_error (dpi); 6327 1.6 christos return; 6328 1.6 christos } 6329 1.6 christos 6330 1.6 christos dc->d_printing++; 6331 1.6 christos dpi->recursion++; 6332 1.3 christos 6333 1.3 christos self.dc = dc; 6334 1.3 christos self.parent = dpi->component_stack; 6335 1.3 christos dpi->component_stack = &self; 6336 1.3 christos 6337 1.3 christos d_print_comp_inner (dpi, options, dc); 6338 1.3 christos 6339 1.3 christos dpi->component_stack = self.parent; 6340 1.6 christos dc->d_printing--; 6341 1.6 christos dpi->recursion--; 6342 1.3 christos } 6343 1.3 christos 6344 1.1 christos /* Print a Java dentifier. For Java we try to handle encoded extended 6345 1.1 christos Unicode characters. The C++ ABI doesn't mention Unicode encoding, 6346 1.1 christos so we don't it for C++. Characters are encoded as 6347 1.1 christos __U<hex-char>+_. */ 6348 1.1 christos 6349 1.1 christos static void 6350 1.1 christos d_print_java_identifier (struct d_print_info *dpi, const char *name, int len) 6351 1.1 christos { 6352 1.1 christos const char *p; 6353 1.1 christos const char *end; 6354 1.1 christos 6355 1.1 christos end = name + len; 6356 1.1 christos for (p = name; p < end; ++p) 6357 1.1 christos { 6358 1.1 christos if (end - p > 3 6359 1.1 christos && p[0] == '_' 6360 1.1 christos && p[1] == '_' 6361 1.1 christos && p[2] == 'U') 6362 1.1 christos { 6363 1.1 christos unsigned long c; 6364 1.1 christos const char *q; 6365 1.1 christos 6366 1.1 christos c = 0; 6367 1.1 christos for (q = p + 3; q < end; ++q) 6368 1.1 christos { 6369 1.1 christos int dig; 6370 1.1 christos 6371 1.1 christos if (IS_DIGIT (*q)) 6372 1.1 christos dig = *q - '0'; 6373 1.1 christos else if (*q >= 'A' && *q <= 'F') 6374 1.1 christos dig = *q - 'A' + 10; 6375 1.1 christos else if (*q >= 'a' && *q <= 'f') 6376 1.1 christos dig = *q - 'a' + 10; 6377 1.1 christos else 6378 1.1 christos break; 6379 1.1 christos 6380 1.1 christos c = c * 16 + dig; 6381 1.1 christos } 6382 1.1 christos /* If the Unicode character is larger than 256, we don't try 6383 1.1 christos to deal with it here. FIXME. */ 6384 1.1 christos if (q < end && *q == '_' && c < 256) 6385 1.1 christos { 6386 1.1 christos d_append_char (dpi, c); 6387 1.1 christos p = q; 6388 1.1 christos continue; 6389 1.1 christos } 6390 1.1 christos } 6391 1.1 christos 6392 1.1 christos d_append_char (dpi, *p); 6393 1.1 christos } 6394 1.1 christos } 6395 1.1 christos 6396 1.1 christos /* Print a list of modifiers. SUFFIX is 1 if we are printing 6397 1.1 christos qualifiers on this after printing a function. */ 6398 1.1 christos 6399 1.1 christos static void 6400 1.1 christos d_print_mod_list (struct d_print_info *dpi, int options, 6401 1.1 christos struct d_print_mod *mods, int suffix) 6402 1.1 christos { 6403 1.1 christos struct d_print_template *hold_dpt; 6404 1.1 christos 6405 1.1 christos if (mods == NULL || d_print_saw_error (dpi)) 6406 1.1 christos return; 6407 1.1 christos 6408 1.1 christos if (mods->printed 6409 1.1 christos || (! suffix 6410 1.6 christos && (is_fnqual_component_type (mods->mod->type)))) 6411 1.1 christos { 6412 1.1 christos d_print_mod_list (dpi, options, mods->next, suffix); 6413 1.1 christos return; 6414 1.1 christos } 6415 1.1 christos 6416 1.1 christos mods->printed = 1; 6417 1.1 christos 6418 1.1 christos hold_dpt = dpi->templates; 6419 1.1 christos dpi->templates = mods->templates; 6420 1.1 christos 6421 1.1 christos if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) 6422 1.1 christos { 6423 1.1 christos d_print_function_type (dpi, options, mods->mod, mods->next); 6424 1.1 christos dpi->templates = hold_dpt; 6425 1.1 christos return; 6426 1.1 christos } 6427 1.1 christos else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE) 6428 1.1 christos { 6429 1.1 christos d_print_array_type (dpi, options, mods->mod, mods->next); 6430 1.1 christos dpi->templates = hold_dpt; 6431 1.1 christos return; 6432 1.1 christos } 6433 1.1 christos else if (mods->mod->type == DEMANGLE_COMPONENT_LOCAL_NAME) 6434 1.1 christos { 6435 1.1 christos struct d_print_mod *hold_modifiers; 6436 1.1 christos struct demangle_component *dc; 6437 1.1 christos 6438 1.1 christos /* When this is on the modifier stack, we have pulled any 6439 1.1 christos qualifiers off the right argument already. Otherwise, we 6440 1.1 christos print it as usual, but don't let the left argument see any 6441 1.1 christos modifiers. */ 6442 1.1 christos 6443 1.1 christos hold_modifiers = dpi->modifiers; 6444 1.1 christos dpi->modifiers = NULL; 6445 1.1 christos d_print_comp (dpi, options, d_left (mods->mod)); 6446 1.1 christos dpi->modifiers = hold_modifiers; 6447 1.1 christos 6448 1.1 christos if ((options & DMGL_JAVA) == 0) 6449 1.1 christos d_append_string (dpi, "::"); 6450 1.1 christos else 6451 1.1 christos d_append_char (dpi, '.'); 6452 1.1 christos 6453 1.1 christos dc = d_right (mods->mod); 6454 1.1 christos 6455 1.1 christos if (dc->type == DEMANGLE_COMPONENT_DEFAULT_ARG) 6456 1.1 christos { 6457 1.1 christos d_append_string (dpi, "{default arg#"); 6458 1.1 christos d_append_num (dpi, dc->u.s_unary_num.num + 1); 6459 1.1 christos d_append_string (dpi, "}::"); 6460 1.1 christos dc = dc->u.s_unary_num.sub; 6461 1.1 christos } 6462 1.1 christos 6463 1.6 christos while (is_fnqual_component_type (dc->type)) 6464 1.1 christos dc = d_left (dc); 6465 1.1 christos 6466 1.1 christos d_print_comp (dpi, options, dc); 6467 1.1 christos 6468 1.1 christos dpi->templates = hold_dpt; 6469 1.1 christos return; 6470 1.1 christos } 6471 1.1 christos 6472 1.1 christos d_print_mod (dpi, options, mods->mod); 6473 1.1 christos 6474 1.1 christos dpi->templates = hold_dpt; 6475 1.1 christos 6476 1.1 christos d_print_mod_list (dpi, options, mods->next, suffix); 6477 1.1 christos } 6478 1.1 christos 6479 1.1 christos /* Print a modifier. */ 6480 1.1 christos 6481 1.1 christos static void 6482 1.1 christos d_print_mod (struct d_print_info *dpi, int options, 6483 1.6 christos struct demangle_component *mod) 6484 1.1 christos { 6485 1.1 christos switch (mod->type) 6486 1.1 christos { 6487 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 6488 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 6489 1.1 christos d_append_string (dpi, " restrict"); 6490 1.1 christos return; 6491 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 6492 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 6493 1.1 christos d_append_string (dpi, " volatile"); 6494 1.1 christos return; 6495 1.1 christos case DEMANGLE_COMPONENT_CONST: 6496 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 6497 1.1 christos d_append_string (dpi, " const"); 6498 1.1 christos return; 6499 1.5 christos case DEMANGLE_COMPONENT_TRANSACTION_SAFE: 6500 1.5 christos d_append_string (dpi, " transaction_safe"); 6501 1.5 christos return; 6502 1.6 christos case DEMANGLE_COMPONENT_NOEXCEPT: 6503 1.6 christos d_append_string (dpi, " noexcept"); 6504 1.6 christos if (d_right (mod)) 6505 1.6 christos { 6506 1.6 christos d_append_char (dpi, '('); 6507 1.6 christos d_print_comp (dpi, options, d_right (mod)); 6508 1.6 christos d_append_char (dpi, ')'); 6509 1.6 christos } 6510 1.6 christos return; 6511 1.6 christos case DEMANGLE_COMPONENT_THROW_SPEC: 6512 1.6 christos d_append_string (dpi, " throw"); 6513 1.6 christos if (d_right (mod)) 6514 1.6 christos { 6515 1.6 christos d_append_char (dpi, '('); 6516 1.6 christos d_print_comp (dpi, options, d_right (mod)); 6517 1.6 christos d_append_char (dpi, ')'); 6518 1.6 christos } 6519 1.6 christos return; 6520 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 6521 1.1 christos d_append_char (dpi, ' '); 6522 1.1 christos d_print_comp (dpi, options, d_right (mod)); 6523 1.1 christos return; 6524 1.1 christos case DEMANGLE_COMPONENT_POINTER: 6525 1.1 christos /* There is no pointer symbol in Java. */ 6526 1.1 christos if ((options & DMGL_JAVA) == 0) 6527 1.1 christos d_append_char (dpi, '*'); 6528 1.1 christos return; 6529 1.3 christos case DEMANGLE_COMPONENT_REFERENCE_THIS: 6530 1.3 christos /* For the ref-qualifier, put a space before the &. */ 6531 1.3 christos d_append_char (dpi, ' '); 6532 1.6 christos /* FALLTHRU */ 6533 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 6534 1.1 christos d_append_char (dpi, '&'); 6535 1.1 christos return; 6536 1.3 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: 6537 1.3 christos d_append_char (dpi, ' '); 6538 1.6 christos /* FALLTHRU */ 6539 1.1 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 6540 1.1 christos d_append_string (dpi, "&&"); 6541 1.1 christos return; 6542 1.9 christos case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: 6543 1.9 christos return; 6544 1.1 christos case DEMANGLE_COMPONENT_COMPLEX: 6545 1.7 christos d_append_string (dpi, " _Complex"); 6546 1.1 christos return; 6547 1.1 christos case DEMANGLE_COMPONENT_IMAGINARY: 6548 1.7 christos d_append_string (dpi, " _Imaginary"); 6549 1.1 christos return; 6550 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 6551 1.1 christos if (d_last_char (dpi) != '(') 6552 1.1 christos d_append_char (dpi, ' '); 6553 1.1 christos d_print_comp (dpi, options, d_left (mod)); 6554 1.1 christos d_append_string (dpi, "::*"); 6555 1.1 christos return; 6556 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 6557 1.1 christos d_print_comp (dpi, options, d_left (mod)); 6558 1.1 christos return; 6559 1.1 christos case DEMANGLE_COMPONENT_VECTOR_TYPE: 6560 1.1 christos d_append_string (dpi, " __vector("); 6561 1.1 christos d_print_comp (dpi, options, d_left (mod)); 6562 1.1 christos d_append_char (dpi, ')'); 6563 1.1 christos return; 6564 1.1 christos 6565 1.1 christos default: 6566 1.1 christos /* Otherwise, we have something that won't go back on the 6567 1.1 christos modifier stack, so we can just print it. */ 6568 1.1 christos d_print_comp (dpi, options, mod); 6569 1.1 christos return; 6570 1.1 christos } 6571 1.1 christos } 6572 1.1 christos 6573 1.1 christos /* Print a function type, except for the return type. */ 6574 1.1 christos 6575 1.1 christos static void 6576 1.1 christos d_print_function_type (struct d_print_info *dpi, int options, 6577 1.6 christos struct demangle_component *dc, 6578 1.1 christos struct d_print_mod *mods) 6579 1.1 christos { 6580 1.1 christos int need_paren; 6581 1.1 christos int need_space; 6582 1.9 christos int xobj_memfn; 6583 1.1 christos struct d_print_mod *p; 6584 1.1 christos struct d_print_mod *hold_modifiers; 6585 1.1 christos 6586 1.1 christos need_paren = 0; 6587 1.1 christos need_space = 0; 6588 1.9 christos xobj_memfn = 0; 6589 1.1 christos for (p = mods; p != NULL; p = p->next) 6590 1.1 christos { 6591 1.1 christos if (p->printed) 6592 1.1 christos break; 6593 1.1 christos 6594 1.1 christos switch (p->mod->type) 6595 1.1 christos { 6596 1.1 christos case DEMANGLE_COMPONENT_POINTER: 6597 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 6598 1.1 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 6599 1.1 christos need_paren = 1; 6600 1.1 christos break; 6601 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 6602 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 6603 1.1 christos case DEMANGLE_COMPONENT_CONST: 6604 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 6605 1.1 christos case DEMANGLE_COMPONENT_COMPLEX: 6606 1.1 christos case DEMANGLE_COMPONENT_IMAGINARY: 6607 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 6608 1.1 christos need_space = 1; 6609 1.1 christos need_paren = 1; 6610 1.1 christos break; 6611 1.9 christos case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: 6612 1.9 christos xobj_memfn = 1; 6613 1.1 christos break; 6614 1.1 christos default: 6615 1.1 christos break; 6616 1.1 christos } 6617 1.1 christos if (need_paren) 6618 1.1 christos break; 6619 1.1 christos } 6620 1.1 christos 6621 1.1 christos if (need_paren) 6622 1.1 christos { 6623 1.1 christos if (! need_space) 6624 1.1 christos { 6625 1.1 christos if (d_last_char (dpi) != '(' 6626 1.1 christos && d_last_char (dpi) != '*') 6627 1.1 christos need_space = 1; 6628 1.1 christos } 6629 1.1 christos if (need_space && d_last_char (dpi) != ' ') 6630 1.1 christos d_append_char (dpi, ' '); 6631 1.1 christos d_append_char (dpi, '('); 6632 1.1 christos } 6633 1.1 christos 6634 1.1 christos hold_modifiers = dpi->modifiers; 6635 1.1 christos dpi->modifiers = NULL; 6636 1.1 christos 6637 1.1 christos d_print_mod_list (dpi, options, mods, 0); 6638 1.1 christos 6639 1.1 christos if (need_paren) 6640 1.1 christos d_append_char (dpi, ')'); 6641 1.1 christos 6642 1.1 christos d_append_char (dpi, '('); 6643 1.9 christos if (xobj_memfn) 6644 1.9 christos d_append_string (dpi, "this "); 6645 1.1 christos 6646 1.1 christos if (d_right (dc) != NULL) 6647 1.1 christos d_print_comp (dpi, options, d_right (dc)); 6648 1.1 christos 6649 1.1 christos d_append_char (dpi, ')'); 6650 1.1 christos 6651 1.1 christos d_print_mod_list (dpi, options, mods, 1); 6652 1.1 christos 6653 1.1 christos dpi->modifiers = hold_modifiers; 6654 1.1 christos } 6655 1.1 christos 6656 1.1 christos /* Print an array type, except for the element type. */ 6657 1.1 christos 6658 1.1 christos static void 6659 1.1 christos d_print_array_type (struct d_print_info *dpi, int options, 6660 1.6 christos struct demangle_component *dc, 6661 1.1 christos struct d_print_mod *mods) 6662 1.1 christos { 6663 1.1 christos int need_space; 6664 1.1 christos 6665 1.1 christos need_space = 1; 6666 1.1 christos if (mods != NULL) 6667 1.1 christos { 6668 1.1 christos int need_paren; 6669 1.1 christos struct d_print_mod *p; 6670 1.1 christos 6671 1.1 christos need_paren = 0; 6672 1.1 christos for (p = mods; p != NULL; p = p->next) 6673 1.1 christos { 6674 1.1 christos if (! p->printed) 6675 1.1 christos { 6676 1.1 christos if (p->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE) 6677 1.1 christos { 6678 1.1 christos need_space = 0; 6679 1.1 christos break; 6680 1.1 christos } 6681 1.1 christos else 6682 1.1 christos { 6683 1.1 christos need_paren = 1; 6684 1.1 christos need_space = 1; 6685 1.1 christos break; 6686 1.1 christos } 6687 1.1 christos } 6688 1.1 christos } 6689 1.1 christos 6690 1.1 christos if (need_paren) 6691 1.1 christos d_append_string (dpi, " ("); 6692 1.1 christos 6693 1.1 christos d_print_mod_list (dpi, options, mods, 0); 6694 1.1 christos 6695 1.1 christos if (need_paren) 6696 1.1 christos d_append_char (dpi, ')'); 6697 1.1 christos } 6698 1.1 christos 6699 1.1 christos if (need_space) 6700 1.1 christos d_append_char (dpi, ' '); 6701 1.1 christos 6702 1.1 christos d_append_char (dpi, '['); 6703 1.1 christos 6704 1.1 christos if (d_left (dc) != NULL) 6705 1.1 christos d_print_comp (dpi, options, d_left (dc)); 6706 1.1 christos 6707 1.1 christos d_append_char (dpi, ']'); 6708 1.1 christos } 6709 1.1 christos 6710 1.1 christos /* Print an operator in an expression. */ 6711 1.1 christos 6712 1.1 christos static void 6713 1.1 christos d_print_expr_op (struct d_print_info *dpi, int options, 6714 1.6 christos struct demangle_component *dc) 6715 1.1 christos { 6716 1.1 christos if (dc->type == DEMANGLE_COMPONENT_OPERATOR) 6717 1.1 christos d_append_buffer (dpi, dc->u.s_operator.op->name, 6718 1.1 christos dc->u.s_operator.op->len); 6719 1.1 christos else 6720 1.1 christos d_print_comp (dpi, options, dc); 6721 1.1 christos } 6722 1.1 christos 6723 1.1 christos /* Print a cast. */ 6724 1.1 christos 6725 1.1 christos static void 6726 1.1 christos d_print_cast (struct d_print_info *dpi, int options, 6727 1.6 christos struct demangle_component *dc) 6728 1.5 christos { 6729 1.5 christos d_print_comp (dpi, options, d_left (dc)); 6730 1.5 christos } 6731 1.5 christos 6732 1.5 christos /* Print a conversion operator. */ 6733 1.5 christos 6734 1.5 christos static void 6735 1.5 christos d_print_conversion (struct d_print_info *dpi, int options, 6736 1.6 christos struct demangle_component *dc) 6737 1.1 christos { 6738 1.3 christos struct d_print_template dpt; 6739 1.3 christos 6740 1.5 christos /* For a conversion operator, we need the template parameters from 6741 1.3 christos the enclosing template in scope for processing the type. */ 6742 1.3 christos if (dpi->current_template != NULL) 6743 1.1 christos { 6744 1.1 christos dpt.next = dpi->templates; 6745 1.1 christos dpi->templates = &dpt; 6746 1.3 christos dpt.template_decl = dpi->current_template; 6747 1.3 christos } 6748 1.1 christos 6749 1.9 christos d_print_comp (dpi, options, d_left (dc)); 6750 1.1 christos 6751 1.9 christos if (dpi->current_template != NULL) 6752 1.9 christos dpi->templates = dpt.next; 6753 1.1 christos } 6754 1.1 christos 6755 1.1 christos /* Initialize the information structure we use to pass around 6756 1.1 christos information. */ 6757 1.1 christos 6758 1.1 christos CP_STATIC_IF_GLIBCPP_V3 6759 1.1 christos void 6760 1.1 christos cplus_demangle_init_info (const char *mangled, int options, size_t len, 6761 1.1 christos struct d_info *di) 6762 1.1 christos { 6763 1.1 christos di->s = mangled; 6764 1.1 christos di->send = mangled + len; 6765 1.1 christos di->options = options; 6766 1.1 christos 6767 1.1 christos di->n = mangled; 6768 1.1 christos 6769 1.7 christos /* We cannot need more components than twice the number of chars in 6770 1.1 christos the mangled string. Most components correspond directly to 6771 1.1 christos chars, but the ARGLIST types are exceptions. */ 6772 1.1 christos di->num_comps = 2 * len; 6773 1.1 christos di->next_comp = 0; 6774 1.1 christos 6775 1.7 christos /* Similarly, we cannot need more substitutions than there are 6776 1.1 christos chars in the mangled string. */ 6777 1.1 christos di->num_subs = len; 6778 1.1 christos di->next_sub = 0; 6779 1.1 christos 6780 1.1 christos di->last_name = NULL; 6781 1.1 christos 6782 1.1 christos di->expansion = 0; 6783 1.3 christos di->is_expression = 0; 6784 1.3 christos di->is_conversion = 0; 6785 1.7 christos di->recursion_level = 0; 6786 1.1 christos } 6787 1.1 christos 6788 1.1 christos /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI 6789 1.1 christos mangled name, return strings in repeated callback giving the demangled 6790 1.1 christos name. OPTIONS is the usual libiberty demangler options. On success, 6791 1.1 christos this returns 1. On failure, returns 0. */ 6792 1.1 christos 6793 1.1 christos static int 6794 1.1 christos d_demangle_callback (const char *mangled, int options, 6795 1.1 christos demangle_callbackref callback, void *opaque) 6796 1.1 christos { 6797 1.1 christos enum 6798 1.1 christos { 6799 1.1 christos DCT_TYPE, 6800 1.1 christos DCT_MANGLED, 6801 1.1 christos DCT_GLOBAL_CTORS, 6802 1.1 christos DCT_GLOBAL_DTORS 6803 1.1 christos } 6804 1.1 christos type; 6805 1.1 christos struct d_info di; 6806 1.1 christos struct demangle_component *dc; 6807 1.1 christos int status; 6808 1.1 christos 6809 1.1 christos if (mangled[0] == '_' && mangled[1] == 'Z') 6810 1.1 christos type = DCT_MANGLED; 6811 1.1 christos else if (strncmp (mangled, "_GLOBAL_", 8) == 0 6812 1.1 christos && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$') 6813 1.1 christos && (mangled[9] == 'D' || mangled[9] == 'I') 6814 1.1 christos && mangled[10] == '_') 6815 1.1 christos type = mangled[9] == 'I' ? DCT_GLOBAL_CTORS : DCT_GLOBAL_DTORS; 6816 1.1 christos else 6817 1.1 christos { 6818 1.1 christos if ((options & DMGL_TYPES) == 0) 6819 1.1 christos return 0; 6820 1.1 christos type = DCT_TYPE; 6821 1.1 christos } 6822 1.1 christos 6823 1.8 christos di.unresolved_name_state = 1; 6824 1.8 christos 6825 1.8 christos again: 6826 1.1 christos cplus_demangle_init_info (mangled, options, strlen (mangled), &di); 6827 1.1 christos 6828 1.7 christos /* PR 87675 - Check for a mangled string that is so long 6829 1.7 christos that we do not have enough stack space to demangle it. */ 6830 1.7 christos if (((options & DMGL_NO_RECURSE_LIMIT) == 0) 6831 1.7 christos /* This check is a bit arbitrary, since what we really want to do is to 6832 1.7 christos compare the sizes of the di.comps and di.subs arrays against the 6833 1.7 christos amount of stack space remaining. But there is no portable way to do 6834 1.7 christos this, so instead we use the recursion limit as a guide to the maximum 6835 1.7 christos size of the arrays. */ 6836 1.7 christos && (unsigned long) di.num_comps > DEMANGLE_RECURSION_LIMIT) 6837 1.7 christos { 6838 1.7 christos /* FIXME: We need a way to indicate that a stack limit has been reached. */ 6839 1.7 christos return 0; 6840 1.7 christos } 6841 1.7 christos 6842 1.1 christos { 6843 1.1 christos #ifdef CP_DYNAMIC_ARRAYS 6844 1.1 christos __extension__ struct demangle_component comps[di.num_comps]; 6845 1.1 christos __extension__ struct demangle_component *subs[di.num_subs]; 6846 1.1 christos 6847 1.1 christos di.comps = comps; 6848 1.1 christos di.subs = subs; 6849 1.1 christos #else 6850 1.1 christos di.comps = alloca (di.num_comps * sizeof (*di.comps)); 6851 1.1 christos di.subs = alloca (di.num_subs * sizeof (*di.subs)); 6852 1.1 christos #endif 6853 1.1 christos 6854 1.1 christos switch (type) 6855 1.1 christos { 6856 1.1 christos case DCT_TYPE: 6857 1.1 christos dc = cplus_demangle_type (&di); 6858 1.1 christos break; 6859 1.1 christos case DCT_MANGLED: 6860 1.1 christos dc = cplus_demangle_mangled_name (&di, 1); 6861 1.1 christos break; 6862 1.1 christos case DCT_GLOBAL_CTORS: 6863 1.1 christos case DCT_GLOBAL_DTORS: 6864 1.1 christos d_advance (&di, 11); 6865 1.1 christos dc = d_make_comp (&di, 6866 1.1 christos (type == DCT_GLOBAL_CTORS 6867 1.1 christos ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS 6868 1.1 christos : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS), 6869 1.1 christos d_make_demangle_mangled_name (&di, d_str (&di)), 6870 1.1 christos NULL); 6871 1.1 christos d_advance (&di, strlen (d_str (&di))); 6872 1.1 christos break; 6873 1.3 christos default: 6874 1.3 christos abort (); /* We have listed all the cases. */ 6875 1.1 christos } 6876 1.1 christos 6877 1.1 christos /* If DMGL_PARAMS is set, then if we didn't consume the entire 6878 1.1 christos mangled string, then we didn't successfully demangle it. If 6879 1.1 christos DMGL_PARAMS is not set, we didn't look at the trailing 6880 1.1 christos parameters. */ 6881 1.1 christos if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0') 6882 1.1 christos dc = NULL; 6883 1.1 christos 6884 1.8 christos /* See discussion in d_unresolved_name. */ 6885 1.8 christos if (dc == NULL && di.unresolved_name_state == -1) 6886 1.8 christos { 6887 1.8 christos di.unresolved_name_state = 0; 6888 1.8 christos goto again; 6889 1.8 christos } 6890 1.8 christos 6891 1.1 christos #ifdef CP_DEMANGLE_DEBUG 6892 1.1 christos d_dump (dc, 0); 6893 1.1 christos #endif 6894 1.1 christos 6895 1.1 christos status = (dc != NULL) 6896 1.1 christos ? cplus_demangle_print_callback (options, dc, callback, opaque) 6897 1.1 christos : 0; 6898 1.1 christos } 6899 1.1 christos 6900 1.1 christos return status; 6901 1.1 christos } 6902 1.1 christos 6903 1.1 christos /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled 6904 1.1 christos name, return a buffer allocated with malloc holding the demangled 6905 1.1 christos name. OPTIONS is the usual libiberty demangler options. On 6906 1.1 christos success, this sets *PALC to the allocated size of the returned 6907 1.1 christos buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for 6908 1.1 christos a memory allocation failure, and returns NULL. */ 6909 1.1 christos 6910 1.1 christos static char * 6911 1.1 christos d_demangle (const char *mangled, int options, size_t *palc) 6912 1.1 christos { 6913 1.1 christos struct d_growable_string dgs; 6914 1.1 christos int status; 6915 1.1 christos 6916 1.1 christos d_growable_string_init (&dgs, 0); 6917 1.1 christos 6918 1.1 christos status = d_demangle_callback (mangled, options, 6919 1.1 christos d_growable_string_callback_adapter, &dgs); 6920 1.1 christos if (status == 0) 6921 1.1 christos { 6922 1.1 christos free (dgs.buf); 6923 1.1 christos *palc = 0; 6924 1.1 christos return NULL; 6925 1.1 christos } 6926 1.1 christos 6927 1.1 christos *palc = dgs.allocation_failure ? 1 : dgs.alc; 6928 1.1 christos return dgs.buf; 6929 1.1 christos } 6930 1.1 christos 6931 1.1 christos #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3) 6932 1.1 christos 6933 1.1 christos extern char *__cxa_demangle (const char *, char *, size_t *, int *); 6934 1.1 christos 6935 1.1 christos /* ia64 ABI-mandated entry point in the C++ runtime library for 6936 1.1 christos performing demangling. MANGLED_NAME is a NUL-terminated character 6937 1.1 christos string containing the name to be demangled. 6938 1.1 christos 6939 1.1 christos OUTPUT_BUFFER is a region of memory, allocated with malloc, of 6940 1.1 christos *LENGTH bytes, into which the demangled name is stored. If 6941 1.1 christos OUTPUT_BUFFER is not long enough, it is expanded using realloc. 6942 1.1 christos OUTPUT_BUFFER may instead be NULL; in that case, the demangled name 6943 1.1 christos is placed in a region of memory allocated with malloc. 6944 1.1 christos 6945 1.1 christos If LENGTH is non-NULL, the length of the buffer containing the 6946 1.1 christos demangled name, is placed in *LENGTH. 6947 1.1 christos 6948 1.1 christos The return value is a pointer to the start of the NUL-terminated 6949 1.1 christos demangled name, or NULL if the demangling fails. The caller is 6950 1.1 christos responsible for deallocating this memory using free. 6951 1.1 christos 6952 1.1 christos *STATUS is set to one of the following values: 6953 1.1 christos 0: The demangling operation succeeded. 6954 1.1 christos -1: A memory allocation failure occurred. 6955 1.1 christos -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules. 6956 1.1 christos -3: One of the arguments is invalid. 6957 1.1 christos 6958 1.1 christos The demangling is performed using the C++ ABI mangling rules, with 6959 1.1 christos GNU extensions. */ 6960 1.1 christos 6961 1.1 christos char * 6962 1.1 christos __cxa_demangle (const char *mangled_name, char *output_buffer, 6963 1.1 christos size_t *length, int *status) 6964 1.1 christos { 6965 1.1 christos char *demangled; 6966 1.1 christos size_t alc; 6967 1.1 christos 6968 1.1 christos if (mangled_name == NULL) 6969 1.1 christos { 6970 1.1 christos if (status != NULL) 6971 1.1 christos *status = -3; 6972 1.1 christos return NULL; 6973 1.1 christos } 6974 1.1 christos 6975 1.1 christos if (output_buffer != NULL && length == NULL) 6976 1.1 christos { 6977 1.1 christos if (status != NULL) 6978 1.1 christos *status = -3; 6979 1.1 christos return NULL; 6980 1.1 christos } 6981 1.1 christos 6982 1.1 christos demangled = d_demangle (mangled_name, DMGL_PARAMS | DMGL_TYPES, &alc); 6983 1.1 christos 6984 1.1 christos if (demangled == NULL) 6985 1.1 christos { 6986 1.1 christos if (status != NULL) 6987 1.1 christos { 6988 1.1 christos if (alc == 1) 6989 1.1 christos *status = -1; 6990 1.1 christos else 6991 1.1 christos *status = -2; 6992 1.1 christos } 6993 1.1 christos return NULL; 6994 1.1 christos } 6995 1.1 christos 6996 1.1 christos if (output_buffer == NULL) 6997 1.1 christos { 6998 1.1 christos if (length != NULL) 6999 1.1 christos *length = alc; 7000 1.1 christos } 7001 1.1 christos else 7002 1.1 christos { 7003 1.1 christos if (strlen (demangled) < *length) 7004 1.1 christos { 7005 1.1 christos strcpy (output_buffer, demangled); 7006 1.1 christos free (demangled); 7007 1.1 christos demangled = output_buffer; 7008 1.1 christos } 7009 1.1 christos else 7010 1.1 christos { 7011 1.1 christos free (output_buffer); 7012 1.1 christos *length = alc; 7013 1.1 christos } 7014 1.1 christos } 7015 1.1 christos 7016 1.1 christos if (status != NULL) 7017 1.1 christos *status = 0; 7018 1.1 christos 7019 1.1 christos return demangled; 7020 1.1 christos } 7021 1.1 christos 7022 1.1 christos extern int __gcclibcxx_demangle_callback (const char *, 7023 1.1 christos void (*) 7024 1.1 christos (const char *, size_t, void *), 7025 1.1 christos void *); 7026 1.1 christos 7027 1.1 christos /* Alternative, allocationless entry point in the C++ runtime library 7028 1.1 christos for performing demangling. MANGLED_NAME is a NUL-terminated character 7029 1.1 christos string containing the name to be demangled. 7030 1.1 christos 7031 1.1 christos CALLBACK is a callback function, called with demangled string 7032 1.1 christos segments as demangling progresses; it is called at least once, 7033 1.1 christos but may be called more than once. OPAQUE is a generalized pointer 7034 1.1 christos used as a callback argument. 7035 1.1 christos 7036 1.1 christos The return code is one of the following values, equivalent to 7037 1.1 christos the STATUS values of __cxa_demangle() (excluding -1, since this 7038 1.1 christos function performs no memory allocations): 7039 1.1 christos 0: The demangling operation succeeded. 7040 1.1 christos -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules. 7041 1.1 christos -3: One of the arguments is invalid. 7042 1.1 christos 7043 1.1 christos The demangling is performed using the C++ ABI mangling rules, with 7044 1.1 christos GNU extensions. */ 7045 1.1 christos 7046 1.1 christos int 7047 1.1 christos __gcclibcxx_demangle_callback (const char *mangled_name, 7048 1.1 christos void (*callback) (const char *, size_t, void *), 7049 1.1 christos void *opaque) 7050 1.1 christos { 7051 1.1 christos int status; 7052 1.1 christos 7053 1.1 christos if (mangled_name == NULL || callback == NULL) 7054 1.1 christos return -3; 7055 1.1 christos 7056 1.1 christos status = d_demangle_callback (mangled_name, DMGL_PARAMS | DMGL_TYPES, 7057 1.1 christos callback, opaque); 7058 1.1 christos if (status == 0) 7059 1.1 christos return -2; 7060 1.1 christos 7061 1.1 christos return 0; 7062 1.1 christos } 7063 1.1 christos 7064 1.1 christos #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */ 7065 1.1 christos 7066 1.1 christos /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI 7067 1.1 christos mangled name, return a buffer allocated with malloc holding the 7068 1.1 christos demangled name. Otherwise, return NULL. */ 7069 1.1 christos 7070 1.1 christos char * 7071 1.1 christos cplus_demangle_v3 (const char *mangled, int options) 7072 1.1 christos { 7073 1.1 christos size_t alc; 7074 1.1 christos 7075 1.1 christos return d_demangle (mangled, options, &alc); 7076 1.1 christos } 7077 1.1 christos 7078 1.1 christos int 7079 1.1 christos cplus_demangle_v3_callback (const char *mangled, int options, 7080 1.1 christos demangle_callbackref callback, void *opaque) 7081 1.1 christos { 7082 1.1 christos return d_demangle_callback (mangled, options, callback, opaque); 7083 1.1 christos } 7084 1.1 christos 7085 1.1 christos /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling 7086 1.1 christos conventions, but the output formatting is a little different. 7087 1.1 christos This instructs the C++ demangler not to emit pointer characters ("*"), to 7088 1.1 christos use Java's namespace separator symbol ("." instead of "::"), and to output 7089 1.1 christos JArray<TYPE> as TYPE[]. */ 7090 1.1 christos 7091 1.1 christos char * 7092 1.1 christos java_demangle_v3 (const char *mangled) 7093 1.1 christos { 7094 1.1 christos size_t alc; 7095 1.1 christos 7096 1.1 christos return d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX, &alc); 7097 1.1 christos } 7098 1.1 christos 7099 1.1 christos int 7100 1.1 christos java_demangle_v3_callback (const char *mangled, 7101 1.1 christos demangle_callbackref callback, void *opaque) 7102 1.1 christos { 7103 1.1 christos return d_demangle_callback (mangled, 7104 1.1 christos DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX, 7105 1.1 christos callback, opaque); 7106 1.1 christos } 7107 1.1 christos 7108 1.1 christos #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */ 7109 1.1 christos 7110 1.1 christos #ifndef IN_GLIBCPP_V3 7111 1.1 christos 7112 1.1 christos /* Demangle a string in order to find out whether it is a constructor 7113 1.1 christos or destructor. Return non-zero on success. Set *CTOR_KIND and 7114 1.1 christos *DTOR_KIND appropriately. */ 7115 1.1 christos 7116 1.1 christos static int 7117 1.1 christos is_ctor_or_dtor (const char *mangled, 7118 1.1 christos enum gnu_v3_ctor_kinds *ctor_kind, 7119 1.1 christos enum gnu_v3_dtor_kinds *dtor_kind) 7120 1.1 christos { 7121 1.1 christos struct d_info di; 7122 1.1 christos struct demangle_component *dc; 7123 1.1 christos int ret; 7124 1.1 christos 7125 1.1 christos *ctor_kind = (enum gnu_v3_ctor_kinds) 0; 7126 1.1 christos *dtor_kind = (enum gnu_v3_dtor_kinds) 0; 7127 1.1 christos 7128 1.1 christos cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di); 7129 1.1 christos 7130 1.1 christos { 7131 1.1 christos #ifdef CP_DYNAMIC_ARRAYS 7132 1.1 christos __extension__ struct demangle_component comps[di.num_comps]; 7133 1.1 christos __extension__ struct demangle_component *subs[di.num_subs]; 7134 1.1 christos 7135 1.1 christos di.comps = comps; 7136 1.1 christos di.subs = subs; 7137 1.1 christos #else 7138 1.1 christos di.comps = alloca (di.num_comps * sizeof (*di.comps)); 7139 1.1 christos di.subs = alloca (di.num_subs * sizeof (*di.subs)); 7140 1.1 christos #endif 7141 1.1 christos 7142 1.1 christos dc = cplus_demangle_mangled_name (&di, 1); 7143 1.1 christos 7144 1.1 christos /* Note that because we did not pass DMGL_PARAMS, we don't expect 7145 1.1 christos to demangle the entire string. */ 7146 1.1 christos 7147 1.1 christos ret = 0; 7148 1.1 christos while (dc != NULL) 7149 1.1 christos { 7150 1.1 christos switch (dc->type) 7151 1.1 christos { 7152 1.3 christos /* These cannot appear on a constructor or destructor. */ 7153 1.3 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 7154 1.3 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 7155 1.3 christos case DEMANGLE_COMPONENT_CONST_THIS: 7156 1.3 christos case DEMANGLE_COMPONENT_REFERENCE_THIS: 7157 1.3 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: 7158 1.1 christos default: 7159 1.1 christos dc = NULL; 7160 1.1 christos break; 7161 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 7162 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 7163 1.1 christos dc = d_left (dc); 7164 1.1 christos break; 7165 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 7166 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 7167 1.1 christos dc = d_right (dc); 7168 1.1 christos break; 7169 1.1 christos case DEMANGLE_COMPONENT_CTOR: 7170 1.1 christos *ctor_kind = dc->u.s_ctor.kind; 7171 1.1 christos ret = 1; 7172 1.1 christos dc = NULL; 7173 1.1 christos break; 7174 1.1 christos case DEMANGLE_COMPONENT_DTOR: 7175 1.1 christos *dtor_kind = dc->u.s_dtor.kind; 7176 1.1 christos ret = 1; 7177 1.1 christos dc = NULL; 7178 1.1 christos break; 7179 1.1 christos } 7180 1.1 christos } 7181 1.1 christos } 7182 1.1 christos 7183 1.1 christos return ret; 7184 1.1 christos } 7185 1.1 christos 7186 1.1 christos /* Return whether NAME is the mangled form of a g++ V3 ABI constructor 7187 1.1 christos name. A non-zero return indicates the type of constructor. */ 7188 1.1 christos 7189 1.1 christos enum gnu_v3_ctor_kinds 7190 1.1 christos is_gnu_v3_mangled_ctor (const char *name) 7191 1.1 christos { 7192 1.1 christos enum gnu_v3_ctor_kinds ctor_kind; 7193 1.1 christos enum gnu_v3_dtor_kinds dtor_kind; 7194 1.1 christos 7195 1.1 christos if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind)) 7196 1.1 christos return (enum gnu_v3_ctor_kinds) 0; 7197 1.1 christos return ctor_kind; 7198 1.1 christos } 7199 1.1 christos 7200 1.1 christos 7201 1.1 christos /* Return whether NAME is the mangled form of a g++ V3 ABI destructor 7202 1.1 christos name. A non-zero return indicates the type of destructor. */ 7203 1.1 christos 7204 1.1 christos enum gnu_v3_dtor_kinds 7205 1.1 christos is_gnu_v3_mangled_dtor (const char *name) 7206 1.1 christos { 7207 1.1 christos enum gnu_v3_ctor_kinds ctor_kind; 7208 1.1 christos enum gnu_v3_dtor_kinds dtor_kind; 7209 1.1 christos 7210 1.1 christos if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind)) 7211 1.1 christos return (enum gnu_v3_dtor_kinds) 0; 7212 1.1 christos return dtor_kind; 7213 1.1 christos } 7214 1.1 christos 7215 1.1 christos #endif /* IN_GLIBCPP_V3 */ 7216 1.1 christos 7217 1.1 christos #ifdef STANDALONE_DEMANGLER 7218 1.1 christos 7219 1.1 christos #include "getopt.h" 7220 1.1 christos #include "dyn-string.h" 7221 1.1 christos 7222 1.1 christos static void print_usage (FILE* fp, int exit_value); 7223 1.1 christos 7224 1.1 christos #define IS_ALPHA(CHAR) \ 7225 1.1 christos (((CHAR) >= 'a' && (CHAR) <= 'z') \ 7226 1.1 christos || ((CHAR) >= 'A' && (CHAR) <= 'Z')) 7227 1.1 christos 7228 1.1 christos /* Non-zero if CHAR is a character than can occur in a mangled name. */ 7229 1.1 christos #define is_mangled_char(CHAR) \ 7230 1.1 christos (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \ 7231 1.1 christos || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$') 7232 1.1 christos 7233 1.1 christos /* The name of this program, as invoked. */ 7234 1.1 christos const char* program_name; 7235 1.1 christos 7236 1.1 christos /* Prints usage summary to FP and then exits with EXIT_VALUE. */ 7237 1.1 christos 7238 1.1 christos static void 7239 1.1 christos print_usage (FILE* fp, int exit_value) 7240 1.1 christos { 7241 1.1 christos fprintf (fp, "Usage: %s [options] [names ...]\n", program_name); 7242 1.1 christos fprintf (fp, "Options:\n"); 7243 1.1 christos fprintf (fp, " -h,--help Display this message.\n"); 7244 1.1 christos fprintf (fp, " -p,--no-params Don't display function parameters\n"); 7245 1.1 christos fprintf (fp, " -v,--verbose Produce verbose demanglings.\n"); 7246 1.1 christos fprintf (fp, "If names are provided, they are demangled. Otherwise filters standard input.\n"); 7247 1.1 christos 7248 1.1 christos exit (exit_value); 7249 1.1 christos } 7250 1.1 christos 7251 1.1 christos /* Option specification for getopt_long. */ 7252 1.1 christos static const struct option long_options[] = 7253 1.1 christos { 7254 1.1 christos { "help", no_argument, NULL, 'h' }, 7255 1.1 christos { "no-params", no_argument, NULL, 'p' }, 7256 1.1 christos { "verbose", no_argument, NULL, 'v' }, 7257 1.1 christos { NULL, no_argument, NULL, 0 }, 7258 1.1 christos }; 7259 1.1 christos 7260 1.1 christos /* Main entry for a demangling filter executable. It will demangle 7261 1.1 christos its command line arguments, if any. If none are provided, it will 7262 1.1 christos filter stdin to stdout, replacing any recognized mangled C++ names 7263 1.1 christos with their demangled equivalents. */ 7264 1.1 christos 7265 1.1 christos int 7266 1.1 christos main (int argc, char *argv[]) 7267 1.1 christos { 7268 1.1 christos int i; 7269 1.1 christos int opt_char; 7270 1.1 christos int options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES; 7271 1.1 christos 7272 1.1 christos /* Use the program name of this program, as invoked. */ 7273 1.1 christos program_name = argv[0]; 7274 1.1 christos 7275 1.1 christos /* Parse options. */ 7276 1.1 christos do 7277 1.1 christos { 7278 1.1 christos opt_char = getopt_long (argc, argv, "hpv", long_options, NULL); 7279 1.1 christos switch (opt_char) 7280 1.1 christos { 7281 1.1 christos case '?': /* Unrecognized option. */ 7282 1.1 christos print_usage (stderr, 1); 7283 1.1 christos break; 7284 1.1 christos 7285 1.1 christos case 'h': 7286 1.1 christos print_usage (stdout, 0); 7287 1.1 christos break; 7288 1.1 christos 7289 1.1 christos case 'p': 7290 1.1 christos options &= ~ DMGL_PARAMS; 7291 1.1 christos break; 7292 1.1 christos 7293 1.1 christos case 'v': 7294 1.1 christos options |= DMGL_VERBOSE; 7295 1.1 christos break; 7296 1.1 christos } 7297 1.1 christos } 7298 1.1 christos while (opt_char != -1); 7299 1.1 christos 7300 1.1 christos if (optind == argc) 7301 1.1 christos /* No command line arguments were provided. Filter stdin. */ 7302 1.1 christos { 7303 1.1 christos dyn_string_t mangled = dyn_string_new (3); 7304 1.1 christos char *s; 7305 1.1 christos 7306 1.1 christos /* Read all of input. */ 7307 1.1 christos while (!feof (stdin)) 7308 1.1 christos { 7309 1.1 christos char c; 7310 1.1 christos 7311 1.1 christos /* Pile characters into mangled until we hit one that can't 7312 1.1 christos occur in a mangled name. */ 7313 1.1 christos c = getchar (); 7314 1.1 christos while (!feof (stdin) && is_mangled_char (c)) 7315 1.1 christos { 7316 1.1 christos dyn_string_append_char (mangled, c); 7317 1.1 christos if (feof (stdin)) 7318 1.1 christos break; 7319 1.1 christos c = getchar (); 7320 1.1 christos } 7321 1.1 christos 7322 1.1 christos if (dyn_string_length (mangled) > 0) 7323 1.1 christos { 7324 1.1 christos #ifdef IN_GLIBCPP_V3 7325 1.1 christos s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL); 7326 1.1 christos #else 7327 1.1 christos s = cplus_demangle_v3 (dyn_string_buf (mangled), options); 7328 1.1 christos #endif 7329 1.1 christos 7330 1.1 christos if (s != NULL) 7331 1.1 christos { 7332 1.1 christos fputs (s, stdout); 7333 1.1 christos free (s); 7334 1.1 christos } 7335 1.1 christos else 7336 1.1 christos { 7337 1.1 christos /* It might not have been a mangled name. Print the 7338 1.1 christos original text. */ 7339 1.1 christos fputs (dyn_string_buf (mangled), stdout); 7340 1.1 christos } 7341 1.1 christos 7342 1.1 christos dyn_string_clear (mangled); 7343 1.1 christos } 7344 1.1 christos 7345 1.1 christos /* If we haven't hit EOF yet, we've read one character that 7346 1.1 christos can't occur in a mangled name, so print it out. */ 7347 1.1 christos if (!feof (stdin)) 7348 1.1 christos putchar (c); 7349 1.1 christos } 7350 1.1 christos 7351 1.1 christos dyn_string_delete (mangled); 7352 1.1 christos } 7353 1.1 christos else 7354 1.1 christos /* Demangle command line arguments. */ 7355 1.1 christos { 7356 1.1 christos /* Loop over command line arguments. */ 7357 1.1 christos for (i = optind; i < argc; ++i) 7358 1.1 christos { 7359 1.1 christos char *s; 7360 1.1 christos #ifdef IN_GLIBCPP_V3 7361 1.1 christos int status; 7362 1.1 christos #endif 7363 1.1 christos 7364 1.1 christos /* Attempt to demangle. */ 7365 1.1 christos #ifdef IN_GLIBCPP_V3 7366 1.1 christos s = __cxa_demangle (argv[i], NULL, NULL, &status); 7367 1.1 christos #else 7368 1.1 christos s = cplus_demangle_v3 (argv[i], options); 7369 1.1 christos #endif 7370 1.1 christos 7371 1.1 christos /* If it worked, print the demangled name. */ 7372 1.1 christos if (s != NULL) 7373 1.1 christos { 7374 1.1 christos printf ("%s\n", s); 7375 1.1 christos free (s); 7376 1.1 christos } 7377 1.1 christos else 7378 1.1 christos { 7379 1.1 christos #ifdef IN_GLIBCPP_V3 7380 1.1 christos fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status); 7381 1.1 christos #else 7382 1.1 christos fprintf (stderr, "Failed: %s\n", argv[i]); 7383 1.1 christos #endif 7384 1.1 christos } 7385 1.1 christos } 7386 1.1 christos } 7387 1.1 christos 7388 1.1 christos return 0; 7389 1.1 christos } 7390 1.1 christos 7391 1.1 christos #endif /* STANDALONE_DEMANGLER */ 7392