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