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