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