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