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