1 /* Defs for interface to demanglers. 2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 3 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public License 7 as published by the Free Software Foundation; either version 2, or 8 (at your option) any later version. 9 10 In addition to the permissions in the GNU Library General Public 11 License, the Free Software Foundation gives you unlimited 12 permission to link the compiled version of this file into 13 combinations with other programs, and to distribute those 14 combinations without any restriction coming from the use of this 15 file. (The Library Public License restrictions do apply in other 16 respects; for example, they cover modification of the file, and 17 distribution when not linked into a combined executable.) 18 19 This program is distributed in the hope that it will be useful, but 20 WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 Library General Public License for more details. 23 24 You should have received a copy of the GNU Library General Public 25 License along with this program; if not, write to the Free Software 26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 27 02110-1301, USA. */ 28 29 30 #if !defined (DEMANGLE_H) 31 #define DEMANGLE_H 32 33 #if 0 /* in valgrind */ 34 #include "libiberty.h" 35 #endif /* ! in valgrind */ 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif /* __cplusplus */ 40 41 /* Options passed to cplus_demangle (in 2nd parameter). */ 42 43 #define DMGL_NO_OPTS 0 /* For readability... */ 44 #define DMGL_PARAMS (1 << 0) /* Include function args */ 45 #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ 46 #define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */ 47 #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */ 48 #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */ 49 #define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when 50 present) after function signature. 51 It applies only to the toplevel 52 function type. */ 53 #define DMGL_RET_DROP (1 << 6) /* Suppress printing function return 54 types, even if present. It applies 55 only to the toplevel function type. 56 */ 57 58 #define DMGL_AUTO (1 << 8) 59 #define DMGL_GNU (1 << 9) 60 #define DMGL_LUCID (1 << 10) 61 #define DMGL_ARM (1 << 11) 62 #define DMGL_HP (1 << 12) /* For the HP aCC compiler; 63 same as ARM except for 64 template arguments, etc. */ 65 #define DMGL_EDG (1 << 13) 66 #define DMGL_GNU_V3 (1 << 14) 67 #define DMGL_GNAT (1 << 15) 68 69 /* If none of these are set, use 'current_demangling_style' as the default. */ 70 #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT) 71 72 /* Enumeration of possible demangling styles. 73 74 Lucid and ARM styles are still kept logically distinct, even though 75 they now both behave identically. The resulting style is actual the 76 union of both. I.E. either style recognizes both "__pt__" and "__rf__" 77 for operator "->", even though the first is lucid style and the second 78 is ARM style. (FIXME?) */ 79 80 extern enum demangling_styles 81 { 82 no_demangling = -1, 83 unknown_demangling = 0, 84 auto_demangling = DMGL_AUTO, 85 gnu_demangling = DMGL_GNU, 86 lucid_demangling = DMGL_LUCID, 87 arm_demangling = DMGL_ARM, 88 hp_demangling = DMGL_HP, 89 edg_demangling = DMGL_EDG, 90 gnu_v3_demangling = DMGL_GNU_V3, 91 java_demangling = DMGL_JAVA, 92 gnat_demangling = DMGL_GNAT 93 } current_demangling_style; 94 95 /* Define string names for the various demangling styles. */ 96 97 #define NO_DEMANGLING_STYLE_STRING "none" 98 #define AUTO_DEMANGLING_STYLE_STRING "auto" 99 #define GNU_DEMANGLING_STYLE_STRING "gnu" 100 #define LUCID_DEMANGLING_STYLE_STRING "lucid" 101 #define ARM_DEMANGLING_STYLE_STRING "arm" 102 #define HP_DEMANGLING_STYLE_STRING "hp" 103 #define EDG_DEMANGLING_STYLE_STRING "edg" 104 #define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3" 105 #define JAVA_DEMANGLING_STYLE_STRING "java" 106 #define GNAT_DEMANGLING_STYLE_STRING "gnat" 107 108 /* Some macros to test what demangling style is active. */ 109 110 #define CURRENT_DEMANGLING_STYLE current_demangling_style 111 #define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO) 112 #define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU) 113 #define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID) 114 #define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM) 115 #define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP) 116 #define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG) 117 #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3) 118 #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA) 119 #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT) 120 121 /* Provide information about the available demangle styles. This code is 122 pulled from gdb into libiberty because it is useful to binutils also. */ 123 124 extern const struct demangler_engine 125 { 126 const char *const demangling_style_name; 127 const enum demangling_styles demangling_style; 128 const char *const demangling_style_doc; 129 } libiberty_demanglers[]; 130 131 extern char * 132 ML_(cplus_demangle) (const char *mangled, int options); 133 134 extern int 135 cplus_demangle_opname (const char *opname, char *result, int options); 136 137 extern const char * 138 cplus_mangle_opname (const char *opname, int options); 139 140 /* Note: This sets global state. FIXME if you care about multi-threading. */ 141 142 extern void 143 set_cplus_marker_for_demangling (int ch); 144 145 extern enum demangling_styles 146 cplus_demangle_set_style (enum demangling_styles style); 147 148 extern enum demangling_styles 149 cplus_demangle_name_to_style (const char *name); 150 151 /* Callback typedef for allocation-less demangler interfaces. */ 152 typedef void (*demangle_callbackref) (const char *, size_t, void *); 153 154 /* V3 ABI demangling entry points, defined in cp-demangle.c. Callback 155 variants return non-zero on success, zero on error. char* variants 156 return a string allocated by malloc on success, NULL on error. */ 157 extern int 158 cplus_demangle_v3_callback (const char *mangled, int options, 159 demangle_callbackref callback, void *opaque); 160 161 extern char* 162 cplus_demangle_v3 (const char *mangled, int options); 163 164 extern int 165 java_demangle_v3_callback (const char *mangled, 166 demangle_callbackref callback, void *opaque); 167 168 extern char* 169 java_demangle_v3 (const char *mangled); 170 171 char * 172 ada_demangle (const char *mangled, int options); 173 174 enum gnu_v3_ctor_kinds { 175 gnu_v3_complete_object_ctor = 1, 176 gnu_v3_base_object_ctor, 177 gnu_v3_complete_object_allocating_ctor, 178 gnu_v3_object_ctor_group 179 }; 180 181 /* Return non-zero iff NAME is the mangled form of a constructor name 182 in the G++ V3 ABI demangling style. Specifically, return an `enum 183 gnu_v3_ctor_kinds' value indicating what kind of constructor 184 it is. */ 185 extern enum gnu_v3_ctor_kinds 186 is_gnu_v3_mangled_ctor (const char *name); 187 188 189 enum gnu_v3_dtor_kinds { 190 gnu_v3_deleting_dtor = 1, 191 gnu_v3_complete_object_dtor, 192 gnu_v3_base_object_dtor, 193 gnu_v3_object_dtor_group 194 }; 195 196 /* Return non-zero iff NAME is the mangled form of a destructor name 197 in the G++ V3 ABI demangling style. Specifically, return an `enum 198 gnu_v3_dtor_kinds' value, indicating what kind of destructor 199 it is. */ 200 extern enum gnu_v3_dtor_kinds 201 is_gnu_v3_mangled_dtor (const char *name); 202 203 /* The V3 demangler works in two passes. The first pass builds a tree 204 representation of the mangled name, and the second pass turns the 205 tree representation into a demangled string. Here we define an 206 interface to permit a caller to build their own tree 207 representation, which they can pass to the demangler to get a 208 demangled string. This can be used to canonicalize user input into 209 something which the demangler might output. It could also be used 210 by other demanglers in the future. */ 211 212 /* These are the component types which may be found in the tree. Many 213 component types have one or two subtrees, referred to as left and 214 right (a component type with only one subtree puts it in the left 215 subtree). */ 216 217 enum demangle_component_type 218 { 219 /* A name, with a length and a pointer to a string. */ 220 DEMANGLE_COMPONENT_NAME, 221 /* A qualified name. The left subtree is a class or namespace or 222 some such thing, and the right subtree is a name qualified by 223 that class. */ 224 DEMANGLE_COMPONENT_QUAL_NAME, 225 /* A local name. The left subtree describes a function, and the 226 right subtree is a name which is local to that function. */ 227 DEMANGLE_COMPONENT_LOCAL_NAME, 228 /* A typed name. The left subtree is a name, and the right subtree 229 describes that name as a function. */ 230 DEMANGLE_COMPONENT_TYPED_NAME, 231 /* A template. The left subtree is a template name, and the right 232 subtree is a template argument list. */ 233 DEMANGLE_COMPONENT_TEMPLATE, 234 /* A template parameter. This holds a number, which is the template 235 parameter index. */ 236 DEMANGLE_COMPONENT_TEMPLATE_PARAM, 237 /* A function parameter. This holds a number, which is the index. */ 238 DEMANGLE_COMPONENT_FUNCTION_PARAM, 239 /* A constructor. This holds a name and the kind of 240 constructor. */ 241 DEMANGLE_COMPONENT_CTOR, 242 /* A destructor. This holds a name and the kind of destructor. */ 243 DEMANGLE_COMPONENT_DTOR, 244 /* A vtable. This has one subtree, the type for which this is a 245 vtable. */ 246 DEMANGLE_COMPONENT_VTABLE, 247 /* A VTT structure. This has one subtree, the type for which this 248 is a VTT. */ 249 DEMANGLE_COMPONENT_VTT, 250 /* A construction vtable. The left subtree is the type for which 251 this is a vtable, and the right subtree is the derived type for 252 which this vtable is built. */ 253 DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, 254 /* A typeinfo structure. This has one subtree, the type for which 255 this is the tpeinfo structure. */ 256 DEMANGLE_COMPONENT_TYPEINFO, 257 /* A typeinfo name. This has one subtree, the type for which this 258 is the typeinfo name. */ 259 DEMANGLE_COMPONENT_TYPEINFO_NAME, 260 /* A typeinfo function. This has one subtree, the type for which 261 this is the tpyeinfo function. */ 262 DEMANGLE_COMPONENT_TYPEINFO_FN, 263 /* A thunk. This has one subtree, the name for which this is a 264 thunk. */ 265 DEMANGLE_COMPONENT_THUNK, 266 /* A virtual thunk. This has one subtree, the name for which this 267 is a virtual thunk. */ 268 DEMANGLE_COMPONENT_VIRTUAL_THUNK, 269 /* A covariant thunk. This has one subtree, the name for which this 270 is a covariant thunk. */ 271 DEMANGLE_COMPONENT_COVARIANT_THUNK, 272 /* A Java class. This has one subtree, the type. */ 273 DEMANGLE_COMPONENT_JAVA_CLASS, 274 /* A guard variable. This has one subtree, the name for which this 275 is a guard variable. */ 276 DEMANGLE_COMPONENT_GUARD, 277 /* A reference temporary. This has one subtree, the name for which 278 this is a temporary. */ 279 DEMANGLE_COMPONENT_REFTEMP, 280 /* A hidden alias. This has one subtree, the encoding for which it 281 is providing alternative linkage. */ 282 DEMANGLE_COMPONENT_HIDDEN_ALIAS, 283 /* A standard substitution. This holds the name of the 284 substitution. */ 285 DEMANGLE_COMPONENT_SUB_STD, 286 /* The restrict qualifier. The one subtree is the type which is 287 being qualified. */ 288 DEMANGLE_COMPONENT_RESTRICT, 289 /* The volatile qualifier. The one subtree is the type which is 290 being qualified. */ 291 DEMANGLE_COMPONENT_VOLATILE, 292 /* The const qualifier. The one subtree is the type which is being 293 qualified. */ 294 DEMANGLE_COMPONENT_CONST, 295 /* The restrict qualifier modifying a member function. The one 296 subtree is the type which is being qualified. */ 297 DEMANGLE_COMPONENT_RESTRICT_THIS, 298 /* The volatile qualifier modifying a member function. The one 299 subtree is the type which is being qualified. */ 300 DEMANGLE_COMPONENT_VOLATILE_THIS, 301 /* The const qualifier modifying a member function. The one subtree 302 is the type which is being qualified. */ 303 DEMANGLE_COMPONENT_CONST_THIS, 304 /* A vendor qualifier. The left subtree is the type which is being 305 qualified, and the right subtree is the name of the 306 qualifier. */ 307 DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL, 308 /* A pointer. The one subtree is the type which is being pointed 309 to. */ 310 DEMANGLE_COMPONENT_POINTER, 311 /* A reference. The one subtree is the type which is being 312 referenced. */ 313 DEMANGLE_COMPONENT_REFERENCE, 314 /* C++0x: An rvalue reference. The one subtree is the type which is 315 being referenced. */ 316 DEMANGLE_COMPONENT_RVALUE_REFERENCE, 317 /* A complex type. The one subtree is the base type. */ 318 DEMANGLE_COMPONENT_COMPLEX, 319 /* An imaginary type. The one subtree is the base type. */ 320 DEMANGLE_COMPONENT_IMAGINARY, 321 /* A builtin type. This holds the builtin type information. */ 322 DEMANGLE_COMPONENT_BUILTIN_TYPE, 323 /* A vendor's builtin type. This holds the name of the type. */ 324 DEMANGLE_COMPONENT_VENDOR_TYPE, 325 /* A function type. The left subtree is the return type. The right 326 subtree is a list of ARGLIST nodes. Either or both may be 327 NULL. */ 328 DEMANGLE_COMPONENT_FUNCTION_TYPE, 329 /* An array type. The left subtree is the dimension, which may be 330 NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an 331 expression. The right subtree is the element type. */ 332 DEMANGLE_COMPONENT_ARRAY_TYPE, 333 /* A pointer to member type. The left subtree is the class type, 334 and the right subtree is the member type. CV-qualifiers appear 335 on the latter. */ 336 DEMANGLE_COMPONENT_PTRMEM_TYPE, 337 /* A fixed-point type. */ 338 DEMANGLE_COMPONENT_FIXED_TYPE, 339 /* A vector type. The left subtree is the number of elements, 340 the right subtree is the element type. */ 341 DEMANGLE_COMPONENT_VECTOR_TYPE, 342 /* An argument list. The left subtree is the current argument, and 343 the right subtree is either NULL or another ARGLIST node. */ 344 DEMANGLE_COMPONENT_ARGLIST, 345 /* A template argument list. The left subtree is the current 346 template argument, and the right subtree is either NULL or 347 another TEMPLATE_ARGLIST node. */ 348 DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, 349 /* An operator. This holds information about a standard 350 operator. */ 351 DEMANGLE_COMPONENT_OPERATOR, 352 /* An extended operator. This holds the number of arguments, and 353 the name of the extended operator. */ 354 DEMANGLE_COMPONENT_EXTENDED_OPERATOR, 355 /* A typecast, represented as a unary operator. The one subtree is 356 the type to which the argument should be cast. */ 357 DEMANGLE_COMPONENT_CAST, 358 /* A unary expression. The left subtree is the operator, and the 359 right subtree is the single argument. */ 360 DEMANGLE_COMPONENT_UNARY, 361 /* A binary expression. The left subtree is the operator, and the 362 right subtree is a BINARY_ARGS. */ 363 DEMANGLE_COMPONENT_BINARY, 364 /* Arguments to a binary expression. The left subtree is the first 365 argument, and the right subtree is the second argument. */ 366 DEMANGLE_COMPONENT_BINARY_ARGS, 367 /* A trinary expression. The left subtree is the operator, and the 368 right subtree is a TRINARY_ARG1. */ 369 DEMANGLE_COMPONENT_TRINARY, 370 /* Arguments to a trinary expression. The left subtree is the first 371 argument, and the right subtree is a TRINARY_ARG2. */ 372 DEMANGLE_COMPONENT_TRINARY_ARG1, 373 /* More arguments to a trinary expression. The left subtree is the 374 second argument, and the right subtree is the third argument. */ 375 DEMANGLE_COMPONENT_TRINARY_ARG2, 376 /* A literal. The left subtree is the type, and the right subtree 377 is the value, represented as a DEMANGLE_COMPONENT_NAME. */ 378 DEMANGLE_COMPONENT_LITERAL, 379 /* A negative literal. Like LITERAL, but the value is negated. 380 This is a minor hack: the NAME used for LITERAL points directly 381 to the mangled string, but since negative numbers are mangled 382 using 'n' instead of '-', we want a way to indicate a negative 383 number which involves neither modifying the mangled string nor 384 allocating a new copy of the literal in memory. */ 385 DEMANGLE_COMPONENT_LITERAL_NEG, 386 /* A libgcj compiled resource. The left subtree is the name of the 387 resource. */ 388 DEMANGLE_COMPONENT_JAVA_RESOURCE, 389 /* A name formed by the concatenation of two parts. The left 390 subtree is the first part and the right subtree the second. */ 391 DEMANGLE_COMPONENT_COMPOUND_NAME, 392 /* A name formed by a single character. */ 393 DEMANGLE_COMPONENT_CHARACTER, 394 /* A number. */ 395 DEMANGLE_COMPONENT_NUMBER, 396 /* A decltype type. */ 397 DEMANGLE_COMPONENT_DECLTYPE, 398 /* Global constructors keyed to name. */ 399 DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS, 400 /* Global destructors keyed to name. */ 401 DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS, 402 /* A lambda closure type. */ 403 DEMANGLE_COMPONENT_LAMBDA, 404 /* A default argument scope. */ 405 DEMANGLE_COMPONENT_DEFAULT_ARG, 406 /* An unnamed type. */ 407 DEMANGLE_COMPONENT_UNNAMED_TYPE, 408 /* A transactional clone. This has one subtree, the encoding for 409 which it is providing alternative linkage. */ 410 DEMANGLE_COMPONENT_TRANSACTION_CLONE, 411 /* A non-transactional clone entry point. In the i386/x86_64 abi, 412 the unmangled symbol of a tm_callable becomes a thunk and the 413 non-transactional function version is mangled thus. */ 414 DEMANGLE_COMPONENT_NONTRANSACTION_CLONE, 415 /* A pack expansion. */ 416 DEMANGLE_COMPONENT_PACK_EXPANSION, 417 /* A cloned function. */ 418 DEMANGLE_COMPONENT_CLONE 419 }; 420 421 /* Types which are only used internally. */ 422 423 struct demangle_operator_info; 424 struct demangle_builtin_type_info; 425 426 /* A node in the tree representation is an instance of a struct 427 demangle_component. Note that the field names of the struct are 428 not well protected against macros defined by the file including 429 this one. We can fix this if it ever becomes a problem. */ 430 431 struct demangle_component 432 { 433 /* The type of this component. */ 434 enum demangle_component_type type; 435 436 union 437 { 438 /* For DEMANGLE_COMPONENT_NAME. */ 439 struct 440 { 441 /* A pointer to the name (which need not NULL terminated) and 442 its length. */ 443 const char *s; 444 int len; 445 } s_name; 446 447 /* For DEMANGLE_COMPONENT_OPERATOR. */ 448 struct 449 { 450 /* Operator. */ 451 const struct demangle_operator_info *op; 452 } s_operator; 453 454 /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */ 455 struct 456 { 457 /* Number of arguments. */ 458 int args; 459 /* Name. */ 460 struct demangle_component *name; 461 } s_extended_operator; 462 463 /* For DEMANGLE_COMPONENT_FIXED_TYPE. */ 464 struct 465 { 466 /* The length, indicated by a C integer type name. */ 467 struct demangle_component *length; 468 /* _Accum or _Fract? */ 469 short accum; 470 /* Saturating or not? */ 471 short sat; 472 } s_fixed; 473 474 /* For DEMANGLE_COMPONENT_CTOR. */ 475 struct 476 { 477 /* Kind of constructor. */ 478 enum gnu_v3_ctor_kinds kind; 479 /* Name. */ 480 struct demangle_component *name; 481 } s_ctor; 482 483 /* For DEMANGLE_COMPONENT_DTOR. */ 484 struct 485 { 486 /* Kind of destructor. */ 487 enum gnu_v3_dtor_kinds kind; 488 /* Name. */ 489 struct demangle_component *name; 490 } s_dtor; 491 492 /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */ 493 struct 494 { 495 /* Builtin type. */ 496 const struct demangle_builtin_type_info *type; 497 } s_builtin; 498 499 /* For DEMANGLE_COMPONENT_SUB_STD. */ 500 struct 501 { 502 /* Standard substitution string. */ 503 const char* string; 504 /* Length of string. */ 505 int len; 506 } s_string; 507 508 /* For DEMANGLE_COMPONENT_*_PARAM. */ 509 struct 510 { 511 /* Parameter index. */ 512 long number; 513 } s_number; 514 515 /* For DEMANGLE_COMPONENT_CHARACTER. */ 516 struct 517 { 518 int character; 519 } s_character; 520 521 /* For other types. */ 522 struct 523 { 524 /* Left (or only) subtree. */ 525 struct demangle_component *left; 526 /* Right subtree. */ 527 struct demangle_component *right; 528 } s_binary; 529 530 struct 531 { 532 /* subtree, same place as d_left. */ 533 struct demangle_component *sub; 534 /* integer. */ 535 int num; 536 } s_unary_num; 537 538 } u; 539 }; 540 541 /* People building mangled trees are expected to allocate instances of 542 struct demangle_component themselves. They can then call one of 543 the following functions to fill them in. */ 544 545 /* Fill in most component types with a left subtree and a right 546 subtree. Returns non-zero on success, zero on failure, such as an 547 unrecognized or inappropriate component type. */ 548 549 extern int 550 cplus_demangle_fill_component (struct demangle_component *fill, 551 enum demangle_component_type, 552 struct demangle_component *left, 553 struct demangle_component *right); 554 555 /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success, 556 zero for bad arguments. */ 557 558 extern int 559 cplus_demangle_fill_name (struct demangle_component *fill, 560 const char *, int); 561 562 /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the 563 builtin type (e.g., "int", etc.). Returns non-zero on success, 564 zero if the type is not recognized. */ 565 566 extern int 567 cplus_demangle_fill_builtin_type (struct demangle_component *fill, 568 const char *type_name); 569 570 /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the 571 operator and the number of arguments which it takes (the latter is 572 used to disambiguate operators which can be both binary and unary, 573 such as '-'). Returns non-zero on success, zero if the operator is 574 not recognized. */ 575 576 extern int 577 cplus_demangle_fill_operator (struct demangle_component *fill, 578 const char *opname, int args); 579 580 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the 581 number of arguments and the name. Returns non-zero on success, 582 zero for bad arguments. */ 583 584 extern int 585 cplus_demangle_fill_extended_operator (struct demangle_component *fill, 586 int numargs, 587 struct demangle_component *nm); 588 589 /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success, 590 zero for bad arguments. */ 591 592 extern int 593 cplus_demangle_fill_ctor (struct demangle_component *fill, 594 enum gnu_v3_ctor_kinds kind, 595 struct demangle_component *name); 596 597 /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success, 598 zero for bad arguments. */ 599 600 extern int 601 cplus_demangle_fill_dtor (struct demangle_component *fill, 602 enum gnu_v3_dtor_kinds kind, 603 struct demangle_component *name); 604 605 /* This function translates a mangled name into a struct 606 demangle_component tree. The first argument is the mangled name. 607 The second argument is DMGL_* options. This returns a pointer to a 608 tree on success, or NULL on failure. On success, the third 609 argument is set to a block of memory allocated by malloc. This 610 block should be passed to free when the tree is no longer 611 needed. */ 612 613 extern struct demangle_component * 614 cplus_demangle_v3_components (const char *mangled, int options, void **mem); 615 616 /* This function takes a struct demangle_component tree and returns 617 the corresponding demangled string. The first argument is DMGL_* 618 options. The second is the tree to demangle. The third is a guess 619 at the length of the demangled string, used to initially allocate 620 the return buffer. The fourth is a pointer to a size_t. On 621 success, this function returns a buffer allocated by malloc(), and 622 sets the size_t pointed to by the fourth argument to the size of 623 the allocated buffer (not the length of the returned string). On 624 failure, this function returns NULL, and sets the size_t pointed to 625 by the fourth argument to 0 for an invalid tree, or to 1 for a 626 memory allocation error. */ 627 628 extern char * 629 cplus_demangle_print (int options, 630 const struct demangle_component *tree, 631 int estimated_length, 632 size_t *p_allocated_size); 633 634 /* This function takes a struct demangle_component tree and passes back 635 a demangled string in one or more calls to a callback function. 636 The first argument is DMGL_* options. The second is the tree to 637 demangle. The third is a pointer to a callback function; on each call 638 this receives an element of the demangled string, its length, and an 639 opaque value. The fourth is the opaque value passed to the callback. 640 The callback is called once or more to return the full demangled 641 string. The demangled element string is always nul-terminated, though 642 its length is also provided for convenience. In contrast to 643 cplus_demangle_print(), this function does not allocate heap memory 644 to grow output strings (except perhaps where alloca() is implemented 645 by malloc()), and so is normally safe for use where the heap has been 646 corrupted. On success, this function returns 1; on failure, 0. */ 647 648 extern int 649 cplus_demangle_print_callback (int options, 650 const struct demangle_component *tree, 651 demangle_callbackref callback, void *opaque); 652 653 #ifdef __cplusplus 654 } 655 #endif /* __cplusplus */ 656 657 #endif /* DEMANGLE_H */ 658