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