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