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