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