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