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