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