1169695Skan/* Defs for interface to demanglers.
2169695Skan   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
3169695Skan   2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4169695Skan
5169695Skan   This program is free software; you can redistribute it and/or
6169695Skan   modify it under the terms of the GNU Library General Public License
7169695Skan   as published by the Free Software Foundation; either version 2, or
8169695Skan   (at your option) any later version.
9169695Skan
10169695Skan   In addition to the permissions in the GNU Library General Public
11169695Skan   License, the Free Software Foundation gives you unlimited
12169695Skan   permission to link the compiled version of this file into
13169695Skan   combinations with other programs, and to distribute those
14169695Skan   combinations without any restriction coming from the use of this
15169695Skan   file.  (The Library Public License restrictions do apply in other
16169695Skan   respects; for example, they cover modification of the file, and
17169695Skan   distribution when not linked into a combined executable.)
18169695Skan
19169695Skan   This program is distributed in the hope that it will be useful, but
20169695Skan   WITHOUT ANY WARRANTY; without even the implied warranty of
21169695Skan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22169695Skan   Library General Public License for more details.
23169695Skan
24169695Skan   You should have received a copy of the GNU Library General Public
25169695Skan   License along with this program; if not, write to the Free Software
26169695Skan   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
27169695Skan   02110-1301, USA.  */
28169695Skan
29169695Skan
30169695Skan#if !defined (DEMANGLE_H)
31169695Skan#define DEMANGLE_H
32169695Skan
33169695Skan#include "libiberty.h"
34169695Skan
35169695Skan#ifdef __cplusplus
36169695Skanextern "C" {
37169695Skan#endif /* __cplusplus */
38169695Skan
39169695Skan/* Options passed to cplus_demangle (in 2nd parameter). */
40169695Skan
41169695Skan#define DMGL_NO_OPTS	 0		/* For readability... */
42169695Skan#define DMGL_PARAMS	 (1 << 0)	/* Include function args */
43169695Skan#define DMGL_ANSI	 (1 << 1)	/* Include const, volatile, etc */
44169695Skan#define DMGL_JAVA	 (1 << 2)	/* Demangle as Java rather than C++. */
45169695Skan#define DMGL_VERBOSE	 (1 << 3)	/* Include implementation details.  */
46169695Skan#define DMGL_TYPES	 (1 << 4)	/* Also try to demangle type encodings.  */
47169695Skan#define DMGL_RET_POSTFIX (1 << 5)       /* Print function return types (when
48169695Skan                                           present) after function signature */
49169695Skan
50169695Skan#define DMGL_AUTO	 (1 << 8)
51169695Skan#define DMGL_GNU	 (1 << 9)
52169695Skan#define DMGL_LUCID	 (1 << 10)
53169695Skan#define DMGL_ARM	 (1 << 11)
54169695Skan#define DMGL_HP 	 (1 << 12)       /* For the HP aCC compiler;
55169695Skan                                            same as ARM except for
56169695Skan                                            template arguments, etc. */
57169695Skan#define DMGL_EDG	 (1 << 13)
58169695Skan#define DMGL_GNU_V3	 (1 << 14)
59169695Skan#define DMGL_GNAT	 (1 << 15)
60169695Skan
61169695Skan/* If none of these are set, use 'current_demangling_style' as the default. */
62169695Skan#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
63169695Skan
64169695Skan/* Enumeration of possible demangling styles.
65169695Skan
66169695Skan   Lucid and ARM styles are still kept logically distinct, even though
67169695Skan   they now both behave identically.  The resulting style is actual the
68169695Skan   union of both.  I.E. either style recognizes both "__pt__" and "__rf__"
69169695Skan   for operator "->", even though the first is lucid style and the second
70169695Skan   is ARM style. (FIXME?) */
71169695Skan
72169695Skanextern enum demangling_styles
73169695Skan{
74169695Skan  no_demangling = -1,
75169695Skan  unknown_demangling = 0,
76169695Skan  auto_demangling = DMGL_AUTO,
77169695Skan  gnu_demangling = DMGL_GNU,
78169695Skan  lucid_demangling = DMGL_LUCID,
79169695Skan  arm_demangling = DMGL_ARM,
80169695Skan  hp_demangling = DMGL_HP,
81169695Skan  edg_demangling = DMGL_EDG,
82169695Skan  gnu_v3_demangling = DMGL_GNU_V3,
83169695Skan  java_demangling = DMGL_JAVA,
84169695Skan  gnat_demangling = DMGL_GNAT
85169695Skan} current_demangling_style;
86169695Skan
87169695Skan/* Define string names for the various demangling styles. */
88169695Skan
89169695Skan#define NO_DEMANGLING_STYLE_STRING            "none"
90169695Skan#define AUTO_DEMANGLING_STYLE_STRING	      "auto"
91169695Skan#define GNU_DEMANGLING_STYLE_STRING    	      "gnu"
92169695Skan#define LUCID_DEMANGLING_STYLE_STRING	      "lucid"
93169695Skan#define ARM_DEMANGLING_STYLE_STRING	      "arm"
94169695Skan#define HP_DEMANGLING_STYLE_STRING	      "hp"
95169695Skan#define EDG_DEMANGLING_STYLE_STRING	      "edg"
96169695Skan#define GNU_V3_DEMANGLING_STYLE_STRING        "gnu-v3"
97169695Skan#define JAVA_DEMANGLING_STYLE_STRING          "java"
98169695Skan#define GNAT_DEMANGLING_STYLE_STRING          "gnat"
99169695Skan
100169695Skan/* Some macros to test what demangling style is active. */
101169695Skan
102169695Skan#define CURRENT_DEMANGLING_STYLE current_demangling_style
103169695Skan#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
104169695Skan#define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
105169695Skan#define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
106169695Skan#define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM)
107169695Skan#define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
108169695Skan#define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
109169695Skan#define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
110169695Skan#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
111169695Skan#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
112169695Skan
113169695Skan/* Provide information about the available demangle styles. This code is
114169695Skan   pulled from gdb into libiberty because it is useful to binutils also.  */
115169695Skan
116169695Skanextern const struct demangler_engine
117169695Skan{
118169695Skan  const char *const demangling_style_name;
119169695Skan  const enum demangling_styles demangling_style;
120169695Skan  const char *const demangling_style_doc;
121169695Skan} libiberty_demanglers[];
122169695Skan
123169695Skanextern char *
124169695Skancplus_demangle (const char *mangled, int options);
125169695Skan
126169695Skanextern int
127169695Skancplus_demangle_opname (const char *opname, char *result, int options);
128169695Skan
129169695Skanextern const char *
130169695Skancplus_mangle_opname (const char *opname, int options);
131169695Skan
132169695Skan/* Note: This sets global state.  FIXME if you care about multi-threading. */
133169695Skan
134169695Skanextern void
135169695Skanset_cplus_marker_for_demangling (int ch);
136169695Skan
137169695Skanextern enum demangling_styles
138169695Skancplus_demangle_set_style (enum demangling_styles style);
139169695Skan
140169695Skanextern enum demangling_styles
141169695Skancplus_demangle_name_to_style (const char *name);
142169695Skan
143169695Skan/* V3 ABI demangling entry points, defined in cp-demangle.c.  */
144169695Skanextern char*
145169695Skancplus_demangle_v3 (const char* mangled, int options);
146169695Skan
147169695Skanextern char*
148169695Skanjava_demangle_v3 (const char* mangled);
149169695Skan
150169695Skan
151169695Skanenum gnu_v3_ctor_kinds {
152169695Skan  gnu_v3_complete_object_ctor = 1,
153169695Skan  gnu_v3_base_object_ctor,
154169695Skan  gnu_v3_complete_object_allocating_ctor
155169695Skan};
156169695Skan
157169695Skan/* Return non-zero iff NAME is the mangled form of a constructor name
158169695Skan   in the G++ V3 ABI demangling style.  Specifically, return an `enum
159169695Skan   gnu_v3_ctor_kinds' value indicating what kind of constructor
160169695Skan   it is.  */
161169695Skanextern enum gnu_v3_ctor_kinds
162169695Skan	is_gnu_v3_mangled_ctor (const char *name);
163169695Skan
164169695Skan
165169695Skanenum gnu_v3_dtor_kinds {
166169695Skan  gnu_v3_deleting_dtor = 1,
167169695Skan  gnu_v3_complete_object_dtor,
168169695Skan  gnu_v3_base_object_dtor
169169695Skan};
170169695Skan
171169695Skan/* Return non-zero iff NAME is the mangled form of a destructor name
172169695Skan   in the G++ V3 ABI demangling style.  Specifically, return an `enum
173169695Skan   gnu_v3_dtor_kinds' value, indicating what kind of destructor
174169695Skan   it is.  */
175169695Skanextern enum gnu_v3_dtor_kinds
176169695Skan	is_gnu_v3_mangled_dtor (const char *name);
177169695Skan
178169695Skan/* The V3 demangler works in two passes.  The first pass builds a tree
179169695Skan   representation of the mangled name, and the second pass turns the
180169695Skan   tree representation into a demangled string.  Here we define an
181169695Skan   interface to permit a caller to build their own tree
182169695Skan   representation, which they can pass to the demangler to get a
183169695Skan   demangled string.  This can be used to canonicalize user input into
184169695Skan   something which the demangler might output.  It could also be used
185169695Skan   by other demanglers in the future.  */
186169695Skan
187169695Skan/* These are the component types which may be found in the tree.  Many
188169695Skan   component types have one or two subtrees, referred to as left and
189169695Skan   right (a component type with only one subtree puts it in the left
190169695Skan   subtree).  */
191169695Skan
192169695Skanenum demangle_component_type
193169695Skan{
194169695Skan  /* A name, with a length and a pointer to a string.  */
195169695Skan  DEMANGLE_COMPONENT_NAME,
196169695Skan  /* A qualified name.  The left subtree is a class or namespace or
197169695Skan     some such thing, and the right subtree is a name qualified by
198169695Skan     that class.  */
199169695Skan  DEMANGLE_COMPONENT_QUAL_NAME,
200169695Skan  /* A local name.  The left subtree describes a function, and the
201169695Skan     right subtree is a name which is local to that function.  */
202169695Skan  DEMANGLE_COMPONENT_LOCAL_NAME,
203169695Skan  /* A typed name.  The left subtree is a name, and the right subtree
204169695Skan     describes that name as a function.  */
205169695Skan  DEMANGLE_COMPONENT_TYPED_NAME,
206169695Skan  /* A template.  The left subtree is a template name, and the right
207169695Skan     subtree is a template argument list.  */
208169695Skan  DEMANGLE_COMPONENT_TEMPLATE,
209169695Skan  /* A template parameter.  This holds a number, which is the template
210169695Skan     parameter index.  */
211169695Skan  DEMANGLE_COMPONENT_TEMPLATE_PARAM,
212169695Skan  /* A constructor.  This holds a name and the kind of
213169695Skan     constructor.  */
214169695Skan  DEMANGLE_COMPONENT_CTOR,
215169695Skan  /* A destructor.  This holds a name and the kind of destructor.  */
216169695Skan  DEMANGLE_COMPONENT_DTOR,
217169695Skan  /* A vtable.  This has one subtree, the type for which this is a
218169695Skan     vtable.  */
219169695Skan  DEMANGLE_COMPONENT_VTABLE,
220169695Skan  /* A VTT structure.  This has one subtree, the type for which this
221169695Skan     is a VTT.  */
222169695Skan  DEMANGLE_COMPONENT_VTT,
223169695Skan  /* A construction vtable.  The left subtree is the type for which
224169695Skan     this is a vtable, and the right subtree is the derived type for
225169695Skan     which this vtable is built.  */
226169695Skan  DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
227169695Skan  /* A typeinfo structure.  This has one subtree, the type for which
228169695Skan     this is the tpeinfo structure.  */
229169695Skan  DEMANGLE_COMPONENT_TYPEINFO,
230169695Skan  /* A typeinfo name.  This has one subtree, the type for which this
231169695Skan     is the typeinfo name.  */
232169695Skan  DEMANGLE_COMPONENT_TYPEINFO_NAME,
233169695Skan  /* A typeinfo function.  This has one subtree, the type for which
234169695Skan     this is the tpyeinfo function.  */
235169695Skan  DEMANGLE_COMPONENT_TYPEINFO_FN,
236169695Skan  /* A thunk.  This has one subtree, the name for which this is a
237169695Skan     thunk.  */
238169695Skan  DEMANGLE_COMPONENT_THUNK,
239169695Skan  /* A virtual thunk.  This has one subtree, the name for which this
240169695Skan     is a virtual thunk.  */
241169695Skan  DEMANGLE_COMPONENT_VIRTUAL_THUNK,
242169695Skan  /* A covariant thunk.  This has one subtree, the name for which this
243169695Skan     is a covariant thunk.  */
244169695Skan  DEMANGLE_COMPONENT_COVARIANT_THUNK,
245169695Skan  /* A Java class.  This has one subtree, the type.  */
246169695Skan  DEMANGLE_COMPONENT_JAVA_CLASS,
247169695Skan  /* A guard variable.  This has one subtree, the name for which this
248169695Skan     is a guard variable.  */
249169695Skan  DEMANGLE_COMPONENT_GUARD,
250169695Skan  /* A reference temporary.  This has one subtree, the name for which
251169695Skan     this is a temporary.  */
252169695Skan  DEMANGLE_COMPONENT_REFTEMP,
253169695Skan  /* A hidden alias.  This has one subtree, the encoding for which it
254169695Skan     is providing alternative linkage.  */
255169695Skan  DEMANGLE_COMPONENT_HIDDEN_ALIAS,
256169695Skan  /* A standard substitution.  This holds the name of the
257169695Skan     substitution.  */
258169695Skan  DEMANGLE_COMPONENT_SUB_STD,
259169695Skan  /* The restrict qualifier.  The one subtree is the type which is
260169695Skan     being qualified.  */
261169695Skan  DEMANGLE_COMPONENT_RESTRICT,
262169695Skan  /* The volatile qualifier.  The one subtree is the type which is
263169695Skan     being qualified.  */
264169695Skan  DEMANGLE_COMPONENT_VOLATILE,
265169695Skan  /* The const qualifier.  The one subtree is the type which is being
266169695Skan     qualified.  */
267169695Skan  DEMANGLE_COMPONENT_CONST,
268169695Skan  /* The restrict qualifier modifying a member function.  The one
269169695Skan     subtree is the type which is being qualified.  */
270169695Skan  DEMANGLE_COMPONENT_RESTRICT_THIS,
271169695Skan  /* The volatile qualifier modifying a member function.  The one
272169695Skan     subtree is the type which is being qualified.  */
273169695Skan  DEMANGLE_COMPONENT_VOLATILE_THIS,
274169695Skan  /* The const qualifier modifying a member function.  The one subtree
275169695Skan     is the type which is being qualified.  */
276169695Skan  DEMANGLE_COMPONENT_CONST_THIS,
277169695Skan  /* A vendor qualifier.  The left subtree is the type which is being
278169695Skan     qualified, and the right subtree is the name of the
279169695Skan     qualifier.  */
280169695Skan  DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
281169695Skan  /* A pointer.  The one subtree is the type which is being pointed
282169695Skan     to.  */
283169695Skan  DEMANGLE_COMPONENT_POINTER,
284169695Skan  /* A reference.  The one subtree is the type which is being
285169695Skan     referenced.  */
286169695Skan  DEMANGLE_COMPONENT_REFERENCE,
287169695Skan  /* A complex type.  The one subtree is the base type.  */
288169695Skan  DEMANGLE_COMPONENT_COMPLEX,
289169695Skan  /* An imaginary type.  The one subtree is the base type.  */
290169695Skan  DEMANGLE_COMPONENT_IMAGINARY,
291169695Skan  /* A builtin type.  This holds the builtin type information.  */
292169695Skan  DEMANGLE_COMPONENT_BUILTIN_TYPE,
293169695Skan  /* A vendor's builtin type.  This holds the name of the type.  */
294169695Skan  DEMANGLE_COMPONENT_VENDOR_TYPE,
295169695Skan  /* A function type.  The left subtree is the return type.  The right
296169695Skan     subtree is a list of ARGLIST nodes.  Either or both may be
297169695Skan     NULL.  */
298169695Skan  DEMANGLE_COMPONENT_FUNCTION_TYPE,
299169695Skan  /* An array type.  The left subtree is the dimension, which may be
300169695Skan     NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
301169695Skan     expression.  The right subtree is the element type.  */
302169695Skan  DEMANGLE_COMPONENT_ARRAY_TYPE,
303169695Skan  /* A pointer to member type.  The left subtree is the class type,
304169695Skan     and the right subtree is the member type.  CV-qualifiers appear
305169695Skan     on the latter.  */
306169695Skan  DEMANGLE_COMPONENT_PTRMEM_TYPE,
307169695Skan  /* An argument list.  The left subtree is the current argument, and
308169695Skan     the right subtree is either NULL or another ARGLIST node.  */
309169695Skan  DEMANGLE_COMPONENT_ARGLIST,
310169695Skan  /* A template argument list.  The left subtree is the current
311169695Skan     template argument, and the right subtree is either NULL or
312169695Skan     another TEMPLATE_ARGLIST node.  */
313169695Skan  DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
314169695Skan  /* An operator.  This holds information about a standard
315169695Skan     operator.  */
316169695Skan  DEMANGLE_COMPONENT_OPERATOR,
317169695Skan  /* An extended operator.  This holds the number of arguments, and
318169695Skan     the name of the extended operator.  */
319169695Skan  DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
320169695Skan  /* A typecast, represented as a unary operator.  The one subtree is
321169695Skan     the type to which the argument should be cast.  */
322169695Skan  DEMANGLE_COMPONENT_CAST,
323169695Skan  /* A unary expression.  The left subtree is the operator, and the
324169695Skan     right subtree is the single argument.  */
325169695Skan  DEMANGLE_COMPONENT_UNARY,
326169695Skan  /* A binary expression.  The left subtree is the operator, and the
327169695Skan     right subtree is a BINARY_ARGS.  */
328169695Skan  DEMANGLE_COMPONENT_BINARY,
329169695Skan  /* Arguments to a binary expression.  The left subtree is the first
330169695Skan     argument, and the right subtree is the second argument.  */
331169695Skan  DEMANGLE_COMPONENT_BINARY_ARGS,
332169695Skan  /* A trinary expression.  The left subtree is the operator, and the
333169695Skan     right subtree is a TRINARY_ARG1.  */
334169695Skan  DEMANGLE_COMPONENT_TRINARY,
335169695Skan  /* Arguments to a trinary expression.  The left subtree is the first
336169695Skan     argument, and the right subtree is a TRINARY_ARG2.  */
337169695Skan  DEMANGLE_COMPONENT_TRINARY_ARG1,
338169695Skan  /* More arguments to a trinary expression.  The left subtree is the
339169695Skan     second argument, and the right subtree is the third argument.  */
340169695Skan  DEMANGLE_COMPONENT_TRINARY_ARG2,
341169695Skan  /* A literal.  The left subtree is the type, and the right subtree
342169695Skan     is the value, represented as a DEMANGLE_COMPONENT_NAME.  */
343169695Skan  DEMANGLE_COMPONENT_LITERAL,
344169695Skan  /* A negative literal.  Like LITERAL, but the value is negated.
345169695Skan     This is a minor hack: the NAME used for LITERAL points directly
346169695Skan     to the mangled string, but since negative numbers are mangled
347169695Skan     using 'n' instead of '-', we want a way to indicate a negative
348169695Skan     number which involves neither modifying the mangled string nor
349169695Skan     allocating a new copy of the literal in memory.  */
350169695Skan  DEMANGLE_COMPONENT_LITERAL_NEG
351169695Skan};
352169695Skan
353169695Skan/* Types which are only used internally.  */
354169695Skan
355169695Skanstruct demangle_operator_info;
356169695Skanstruct demangle_builtin_type_info;
357169695Skan
358169695Skan/* A node in the tree representation is an instance of a struct
359169695Skan   demangle_component.  Note that the field names of the struct are
360169695Skan   not well protected against macros defined by the file including
361169695Skan   this one.  We can fix this if it ever becomes a problem.  */
362169695Skan
363169695Skanstruct demangle_component
364169695Skan{
365169695Skan  /* The type of this component.  */
366169695Skan  enum demangle_component_type type;
367169695Skan
368169695Skan  union
369169695Skan  {
370169695Skan    /* For DEMANGLE_COMPONENT_NAME.  */
371169695Skan    struct
372169695Skan    {
373169695Skan      /* A pointer to the name (which need not NULL terminated) and
374169695Skan	 its length.  */
375169695Skan      const char *s;
376169695Skan      int len;
377169695Skan    } s_name;
378169695Skan
379169695Skan    /* For DEMANGLE_COMPONENT_OPERATOR.  */
380169695Skan    struct
381169695Skan    {
382169695Skan      /* Operator.  */
383169695Skan      const struct demangle_operator_info *op;
384169695Skan    } s_operator;
385169695Skan
386169695Skan    /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR.  */
387169695Skan    struct
388169695Skan    {
389169695Skan      /* Number of arguments.  */
390169695Skan      int args;
391169695Skan      /* Name.  */
392169695Skan      struct demangle_component *name;
393169695Skan    } s_extended_operator;
394169695Skan
395169695Skan    /* For DEMANGLE_COMPONENT_CTOR.  */
396169695Skan    struct
397169695Skan    {
398169695Skan      /* Kind of constructor.  */
399169695Skan      enum gnu_v3_ctor_kinds kind;
400169695Skan      /* Name.  */
401169695Skan      struct demangle_component *name;
402169695Skan    } s_ctor;
403169695Skan
404169695Skan    /* For DEMANGLE_COMPONENT_DTOR.  */
405169695Skan    struct
406169695Skan    {
407169695Skan      /* Kind of destructor.  */
408169695Skan      enum gnu_v3_dtor_kinds kind;
409169695Skan      /* Name.  */
410169695Skan      struct demangle_component *name;
411169695Skan    } s_dtor;
412169695Skan
413169695Skan    /* For DEMANGLE_COMPONENT_BUILTIN_TYPE.  */
414169695Skan    struct
415169695Skan    {
416169695Skan      /* Builtin type.  */
417169695Skan      const struct demangle_builtin_type_info *type;
418169695Skan    } s_builtin;
419169695Skan
420169695Skan    /* For DEMANGLE_COMPONENT_SUB_STD.  */
421169695Skan    struct
422169695Skan    {
423169695Skan      /* Standard substitution string.  */
424169695Skan      const char* string;
425169695Skan      /* Length of string.  */
426169695Skan      int len;
427169695Skan    } s_string;
428169695Skan
429169695Skan    /* For DEMANGLE_COMPONENT_TEMPLATE_PARAM.  */
430169695Skan    struct
431169695Skan    {
432169695Skan      /* Template parameter index.  */
433169695Skan      long number;
434169695Skan    } s_number;
435169695Skan
436169695Skan    /* For other types.  */
437169695Skan    struct
438169695Skan    {
439169695Skan      /* Left (or only) subtree.  */
440169695Skan      struct demangle_component *left;
441169695Skan      /* Right subtree.  */
442169695Skan      struct demangle_component *right;
443169695Skan    } s_binary;
444169695Skan
445169695Skan  } u;
446169695Skan};
447169695Skan
448169695Skan/* People building mangled trees are expected to allocate instances of
449169695Skan   struct demangle_component themselves.  They can then call one of
450169695Skan   the following functions to fill them in.  */
451169695Skan
452169695Skan/* Fill in most component types with a left subtree and a right
453169695Skan   subtree.  Returns non-zero on success, zero on failure, such as an
454169695Skan   unrecognized or inappropriate component type.  */
455169695Skan
456169695Skanextern int
457169695Skancplus_demangle_fill_component (struct demangle_component *fill,
458169695Skan                               enum demangle_component_type,
459169695Skan                               struct demangle_component *left,
460169695Skan                               struct demangle_component *right);
461169695Skan
462169695Skan/* Fill in a DEMANGLE_COMPONENT_NAME.  Returns non-zero on success,
463169695Skan   zero for bad arguments.  */
464169695Skan
465169695Skanextern int
466169695Skancplus_demangle_fill_name (struct demangle_component *fill,
467169695Skan                          const char *, int);
468169695Skan
469169695Skan/* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
470169695Skan   builtin type (e.g., "int", etc.).  Returns non-zero on success,
471169695Skan   zero if the type is not recognized.  */
472169695Skan
473169695Skanextern int
474169695Skancplus_demangle_fill_builtin_type (struct demangle_component *fill,
475169695Skan                                  const char *type_name);
476169695Skan
477169695Skan/* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
478169695Skan   operator and the number of arguments which it takes (the latter is
479169695Skan   used to disambiguate operators which can be both binary and unary,
480169695Skan   such as '-').  Returns non-zero on success, zero if the operator is
481169695Skan   not recognized.  */
482169695Skan
483169695Skanextern int
484169695Skancplus_demangle_fill_operator (struct demangle_component *fill,
485169695Skan                              const char *opname, int args);
486169695Skan
487169695Skan/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
488169695Skan   number of arguments and the name.  Returns non-zero on success,
489169695Skan   zero for bad arguments.  */
490169695Skan
491169695Skanextern int
492169695Skancplus_demangle_fill_extended_operator (struct demangle_component *fill,
493169695Skan                                       int numargs,
494169695Skan                                       struct demangle_component *nm);
495169695Skan
496169695Skan/* Fill in a DEMANGLE_COMPONENT_CTOR.  Returns non-zero on success,
497169695Skan   zero for bad arguments.  */
498169695Skan
499169695Skanextern int
500169695Skancplus_demangle_fill_ctor (struct demangle_component *fill,
501169695Skan                          enum gnu_v3_ctor_kinds kind,
502169695Skan                          struct demangle_component *name);
503169695Skan
504169695Skan/* Fill in a DEMANGLE_COMPONENT_DTOR.  Returns non-zero on success,
505169695Skan   zero for bad arguments.  */
506169695Skan
507169695Skanextern int
508169695Skancplus_demangle_fill_dtor (struct demangle_component *fill,
509169695Skan                          enum gnu_v3_dtor_kinds kind,
510169695Skan                          struct demangle_component *name);
511169695Skan
512169695Skan/* This function translates a mangled name into a struct
513169695Skan   demangle_component tree.  The first argument is the mangled name.
514169695Skan   The second argument is DMGL_* options.  This returns a pointer to a
515169695Skan   tree on success, or NULL on failure.  On success, the third
516169695Skan   argument is set to a block of memory allocated by malloc.  This
517169695Skan   block should be passed to free when the tree is no longer
518169695Skan   needed.  */
519169695Skan
520169695Skanextern struct demangle_component *
521169695Skancplus_demangle_v3_components (const char *mangled, int options, void **mem);
522169695Skan
523169695Skan/* This function takes a struct demangle_component tree and returns
524169695Skan   the corresponding demangled string.  The first argument is DMGL_*
525169695Skan   options.  The second is the tree to demangle.  The third is a guess
526169695Skan   at the length of the demangled string, used to initially allocate
527169695Skan   the return buffer.  The fourth is a pointer to a size_t.  On
528169695Skan   success, this function returns a buffer allocated by malloc(), and
529169695Skan   sets the size_t pointed to by the fourth argument to the size of
530169695Skan   the allocated buffer (not the length of the returned string).  On
531169695Skan   failure, this function returns NULL, and sets the size_t pointed to
532169695Skan   by the fourth argument to 0 for an invalid tree, or to 1 for a
533169695Skan   memory allocation error.  */
534169695Skan
535169695Skanextern char *
536169695Skancplus_demangle_print (int options,
537169695Skan                      const struct demangle_component *tree,
538169695Skan                      int estimated_length,
539169695Skan                      size_t *p_allocated_size);
540169695Skan
541169695Skan#ifdef __cplusplus
542169695Skan}
543169695Skan#endif /* __cplusplus */
544169695Skan
545169695Skan#endif	/* DEMANGLE_H */
546