1 /* Defs for interface to demanglers.
2 Copyright (C) 1992-2019 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 #include "libiberty.h"
36 #endif /* __cplusplus */
38 /* Options passed to cplus_demangle (in 2nd parameter). */
40 #define DMGL_NO_OPTS 0 /* For readability... */
41 #define DMGL_PARAMS (1 << 0) /* Include function args */
42 #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
43 #define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
44 #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
45 #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
46 #define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
47 present) after function signature.
48 It applies only to the toplevel
50 #define DMGL_RET_DROP (1 << 6) /* Suppress printing function return
51 types, even if present. It applies
52 only to the toplevel function type.
55 #define DMGL_AUTO (1 << 8)
56 #define DMGL_GNU_V3 (1 << 14)
57 #define DMGL_GNAT (1 << 15)
58 #define DMGL_DLANG (1 << 16)
59 #define DMGL_RUST (1 << 17) /* Rust wraps GNU_V3 style mangling. */
61 /* If none of these are set, use 'current_demangling_style' as the default. */
62 #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG|DMGL_RUST)
64 /* Disable a limit on the depth of recursion in mangled strings.
65 Note if this limit is disabled then stack exhaustion is possible when
66 demangling pathologically complicated strings. Bug reports about stack
67 exhaustion when the option is enabled will be rejected. */
68 #define DMGL_NO_RECURSE_LIMIT (1 << 18)
70 /* If DMGL_NO_RECURSE_LIMIT is not enabled, then this is the value used as
71 the maximum depth of recursion allowed. It should be enough for any
72 real-world mangled name. */
73 #define DEMANGLE_RECURSION_LIMIT 2048
75 /* Enumeration of possible demangling styles.
77 Lucid and ARM styles are still kept logically distinct, even though
78 they now both behave identically. The resulting style is actual the
79 union of both. I.E. either style recognizes both "__pt__" and "__rf__"
80 for operator "->", even though the first is lucid style and the second
81 is ARM style. (FIXME?) */
83 extern enum demangling_styles
86 unknown_demangling = 0,
87 auto_demangling = DMGL_AUTO,
88 gnu_v3_demangling = DMGL_GNU_V3,
89 java_demangling = DMGL_JAVA,
90 gnat_demangling = DMGL_GNAT,
91 dlang_demangling = DMGL_DLANG,
92 rust_demangling = DMGL_RUST
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_V3_DEMANGLING_STYLE_STRING "gnu-v3"
100 #define JAVA_DEMANGLING_STYLE_STRING "java"
101 #define GNAT_DEMANGLING_STYLE_STRING "gnat"
102 #define DLANG_DEMANGLING_STYLE_STRING "dlang"
103 #define RUST_DEMANGLING_STYLE_STRING "rust"
105 /* Some macros to test what demangling style is active. */
107 #define CURRENT_DEMANGLING_STYLE current_demangling_style
108 #define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
109 #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
110 #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
111 #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
112 #define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
113 #define RUST_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_RUST)
115 /* Provide information about the available demangle styles. This code is
116 pulled from gdb into libiberty because it is useful to binutils also. */
118 extern const struct demangler_engine
120 const char *const demangling_style_name;
121 const enum demangling_styles demangling_style;
122 const char *const demangling_style_doc;
123 } libiberty_demanglers[];
126 cplus_demangle (const char *mangled, int options);
128 /* Note: This sets global state. FIXME if you care about multi-threading. */
130 extern enum demangling_styles
131 cplus_demangle_set_style (enum demangling_styles style);
133 extern enum demangling_styles
134 cplus_demangle_name_to_style (const char *name);
136 /* Callback typedef for allocation-less demangler interfaces. */
137 typedef void (*demangle_callbackref) (const char *, size_t, void *);
139 /* V3 ABI demangling entry points, defined in cp-demangle.c. Callback
140 variants return non-zero on success, zero on error. char* variants
141 return a string allocated by malloc on success, NULL on error. */
143 cplus_demangle_v3_callback (const char *mangled, int options,
144 demangle_callbackref callback, void *opaque);
147 cplus_demangle_v3 (const char *mangled, int options);
150 java_demangle_v3_callback (const char *mangled,
151 demangle_callbackref callback, void *opaque);
154 java_demangle_v3 (const char *mangled);
157 ada_demangle (const char *mangled, int options);
160 dlang_demangle (const char *mangled, int options);
162 /* Returns non-zero iff MANGLED is a rust mangled symbol. MANGLED must
163 already have been demangled through cplus_demangle_v3. If this function
164 returns non-zero then MANGLED can be demangled (in-place) using
165 RUST_DEMANGLE_SYM. */
167 rust_is_mangled (const char *mangled);
169 /* Demangles SYM (in-place) if RUST_IS_MANGLED returned non-zero for SYM.
170 If RUST_IS_MANGLED returned zero for SYM then RUST_DEMANGLE_SYM might
171 replace characters that cannot be demangled with '?' and might truncate
172 SYM. After calling RUST_DEMANGLE_SYM SYM might be shorter, but never
175 rust_demangle_sym (char *sym);
177 /* Demangles MANGLED if it was GNU_V3 and then RUST mangled, otherwise
178 returns NULL. Uses CPLUS_DEMANGLE_V3, RUST_IS_MANGLED and
179 RUST_DEMANGLE_SYM. Returns a new string that is owned by the caller. */
181 rust_demangle (const char *mangled, int options);
183 enum gnu_v3_ctor_kinds {
184 gnu_v3_complete_object_ctor = 1,
185 gnu_v3_base_object_ctor,
186 gnu_v3_complete_object_allocating_ctor,
187 /* These are not part of the V3 ABI. Unified constructors are generated
188 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
189 is used, and are always internal symbols. */
191 gnu_v3_object_ctor_group
194 /* Return non-zero iff NAME is the mangled form of a constructor name
195 in the G++ V3 ABI demangling style. Specifically, return an `enum
196 gnu_v3_ctor_kinds' value indicating what kind of constructor
198 extern enum gnu_v3_ctor_kinds
199 is_gnu_v3_mangled_ctor (const char *name);
202 enum gnu_v3_dtor_kinds {
203 gnu_v3_deleting_dtor = 1,
204 gnu_v3_complete_object_dtor,
205 gnu_v3_base_object_dtor,
206 /* These are not part of the V3 ABI. Unified destructors are generated
207 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
208 is used, and are always internal symbols. */
210 gnu_v3_object_dtor_group
213 /* Return non-zero iff NAME is the mangled form of a destructor name
214 in the G++ V3 ABI demangling style. Specifically, return an `enum
215 gnu_v3_dtor_kinds' value, indicating what kind of destructor
217 extern enum gnu_v3_dtor_kinds
218 is_gnu_v3_mangled_dtor (const char *name);
220 /* The V3 demangler works in two passes. The first pass builds a tree
221 representation of the mangled name, and the second pass turns the
222 tree representation into a demangled string. Here we define an
223 interface to permit a caller to build their own tree
224 representation, which they can pass to the demangler to get a
225 demangled string. This can be used to canonicalize user input into
226 something which the demangler might output. It could also be used
227 by other demanglers in the future. */
229 /* These are the component types which may be found in the tree. Many
230 component types have one or two subtrees, referred to as left and
231 right (a component type with only one subtree puts it in the left
234 enum demangle_component_type
236 /* A name, with a length and a pointer to a string. */
237 DEMANGLE_COMPONENT_NAME,
238 /* A qualified name. The left subtree is a class or namespace or
239 some such thing, and the right subtree is a name qualified by
241 DEMANGLE_COMPONENT_QUAL_NAME,
242 /* A local name. The left subtree describes a function, and the
243 right subtree is a name which is local to that function. */
244 DEMANGLE_COMPONENT_LOCAL_NAME,
245 /* A typed name. The left subtree is a name, and the right subtree
246 describes that name as a function. */
247 DEMANGLE_COMPONENT_TYPED_NAME,
248 /* A template. The left subtree is a template name, and the right
249 subtree is a template argument list. */
250 DEMANGLE_COMPONENT_TEMPLATE,
251 /* A template parameter. This holds a number, which is the template
253 DEMANGLE_COMPONENT_TEMPLATE_PARAM,
254 /* A function parameter. This holds a number, which is the index. */
255 DEMANGLE_COMPONENT_FUNCTION_PARAM,
256 /* A constructor. This holds a name and the kind of
258 DEMANGLE_COMPONENT_CTOR,
259 /* A destructor. This holds a name and the kind of destructor. */
260 DEMANGLE_COMPONENT_DTOR,
261 /* A vtable. This has one subtree, the type for which this is a
263 DEMANGLE_COMPONENT_VTABLE,
264 /* A VTT structure. This has one subtree, the type for which this
266 DEMANGLE_COMPONENT_VTT,
267 /* A construction vtable. The left subtree is the type for which
268 this is a vtable, and the right subtree is the derived type for
269 which this vtable is built. */
270 DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
271 /* A typeinfo structure. This has one subtree, the type for which
272 this is the tpeinfo structure. */
273 DEMANGLE_COMPONENT_TYPEINFO,
274 /* A typeinfo name. This has one subtree, the type for which this
275 is the typeinfo name. */
276 DEMANGLE_COMPONENT_TYPEINFO_NAME,
277 /* A typeinfo function. This has one subtree, the type for which
278 this is the tpyeinfo function. */
279 DEMANGLE_COMPONENT_TYPEINFO_FN,
280 /* A thunk. This has one subtree, the name for which this is a
282 DEMANGLE_COMPONENT_THUNK,
283 /* A virtual thunk. This has one subtree, the name for which this
284 is a virtual thunk. */
285 DEMANGLE_COMPONENT_VIRTUAL_THUNK,
286 /* A covariant thunk. This has one subtree, the name for which this
287 is a covariant thunk. */
288 DEMANGLE_COMPONENT_COVARIANT_THUNK,
289 /* A Java class. This has one subtree, the type. */
290 DEMANGLE_COMPONENT_JAVA_CLASS,
291 /* A guard variable. This has one subtree, the name for which this
292 is a guard variable. */
293 DEMANGLE_COMPONENT_GUARD,
294 /* The init and wrapper functions for C++11 thread_local variables. */
295 DEMANGLE_COMPONENT_TLS_INIT,
296 DEMANGLE_COMPONENT_TLS_WRAPPER,
297 /* A reference temporary. This has one subtree, the name for which
298 this is a temporary. */
299 DEMANGLE_COMPONENT_REFTEMP,
300 /* A hidden alias. This has one subtree, the encoding for which it
301 is providing alternative linkage. */
302 DEMANGLE_COMPONENT_HIDDEN_ALIAS,
303 /* A standard substitution. This holds the name of the
305 DEMANGLE_COMPONENT_SUB_STD,
306 /* The restrict qualifier. The one subtree is the type which is
308 DEMANGLE_COMPONENT_RESTRICT,
309 /* The volatile qualifier. The one subtree is the type which is
311 DEMANGLE_COMPONENT_VOLATILE,
312 /* The const qualifier. The one subtree is the type which is being
314 DEMANGLE_COMPONENT_CONST,
315 /* The restrict qualifier modifying a member function. The one
316 subtree is the type which is being qualified. */
317 DEMANGLE_COMPONENT_RESTRICT_THIS,
318 /* The volatile qualifier modifying a member function. The one
319 subtree is the type which is being qualified. */
320 DEMANGLE_COMPONENT_VOLATILE_THIS,
321 /* The const qualifier modifying a member function. The one subtree
322 is the type which is being qualified. */
323 DEMANGLE_COMPONENT_CONST_THIS,
324 /* C++11 A reference modifying a member function. The one subtree is the
325 type which is being referenced. */
326 DEMANGLE_COMPONENT_REFERENCE_THIS,
327 /* C++11: An rvalue reference modifying a member function. The one
328 subtree is the type which is being referenced. */
329 DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS,
330 /* A vendor qualifier. The left subtree is the type which is being
331 qualified, and the right subtree is the name of the
333 DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
334 /* A pointer. The one subtree is the type which is being pointed
336 DEMANGLE_COMPONENT_POINTER,
337 /* A reference. The one subtree is the type which is being
339 DEMANGLE_COMPONENT_REFERENCE,
340 /* C++0x: An rvalue reference. The one subtree is the type which is
342 DEMANGLE_COMPONENT_RVALUE_REFERENCE,
343 /* A complex type. The one subtree is the base type. */
344 DEMANGLE_COMPONENT_COMPLEX,
345 /* An imaginary type. The one subtree is the base type. */
346 DEMANGLE_COMPONENT_IMAGINARY,
347 /* A builtin type. This holds the builtin type information. */
348 DEMANGLE_COMPONENT_BUILTIN_TYPE,
349 /* A vendor's builtin type. This holds the name of the type. */
350 DEMANGLE_COMPONENT_VENDOR_TYPE,
351 /* A function type. The left subtree is the return type. The right
352 subtree is a list of ARGLIST nodes. Either or both may be
354 DEMANGLE_COMPONENT_FUNCTION_TYPE,
355 /* An array type. The left subtree is the dimension, which may be
356 NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
357 expression. The right subtree is the element type. */
358 DEMANGLE_COMPONENT_ARRAY_TYPE,
359 /* A pointer to member type. The left subtree is the class type,
360 and the right subtree is the member type. CV-qualifiers appear
362 DEMANGLE_COMPONENT_PTRMEM_TYPE,
363 /* A fixed-point type. */
364 DEMANGLE_COMPONENT_FIXED_TYPE,
365 /* A vector type. The left subtree is the number of elements,
366 the right subtree is the element type. */
367 DEMANGLE_COMPONENT_VECTOR_TYPE,
368 /* An argument list. The left subtree is the current argument, and
369 the right subtree is either NULL or another ARGLIST node. */
370 DEMANGLE_COMPONENT_ARGLIST,
371 /* A template argument list. The left subtree is the current
372 template argument, and the right subtree is either NULL or
373 another TEMPLATE_ARGLIST node. */
374 DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
375 /* A template parameter object (C++20). The left subtree is the
376 corresponding template argument. */
377 DEMANGLE_COMPONENT_TPARM_OBJ,
378 /* An initializer list. The left subtree is either an explicit type or
379 NULL, and the right subtree is a DEMANGLE_COMPONENT_ARGLIST. */
380 DEMANGLE_COMPONENT_INITIALIZER_LIST,
381 /* An operator. This holds information about a standard
383 DEMANGLE_COMPONENT_OPERATOR,
384 /* An extended operator. This holds the number of arguments, and
385 the name of the extended operator. */
386 DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
387 /* A typecast, represented as a unary operator. The one subtree is
388 the type to which the argument should be cast. */
389 DEMANGLE_COMPONENT_CAST,
390 /* A conversion operator, represented as a unary operator. The one
391 subtree is the type to which the argument should be converted
393 DEMANGLE_COMPONENT_CONVERSION,
394 /* A nullary expression. The left subtree is the operator. */
395 DEMANGLE_COMPONENT_NULLARY,
396 /* A unary expression. The left subtree is the operator, and the
397 right subtree is the single argument. */
398 DEMANGLE_COMPONENT_UNARY,
399 /* A binary expression. The left subtree is the operator, and the
400 right subtree is a BINARY_ARGS. */
401 DEMANGLE_COMPONENT_BINARY,
402 /* Arguments to a binary expression. The left subtree is the first
403 argument, and the right subtree is the second argument. */
404 DEMANGLE_COMPONENT_BINARY_ARGS,
405 /* A trinary expression. The left subtree is the operator, and the
406 right subtree is a TRINARY_ARG1. */
407 DEMANGLE_COMPONENT_TRINARY,
408 /* Arguments to a trinary expression. The left subtree is the first
409 argument, and the right subtree is a TRINARY_ARG2. */
410 DEMANGLE_COMPONENT_TRINARY_ARG1,
411 /* More arguments to a trinary expression. The left subtree is the
412 second argument, and the right subtree is the third argument. */
413 DEMANGLE_COMPONENT_TRINARY_ARG2,
414 /* A literal. The left subtree is the type, and the right subtree
415 is the value, represented as a DEMANGLE_COMPONENT_NAME. */
416 DEMANGLE_COMPONENT_LITERAL,
417 /* A negative literal. Like LITERAL, but the value is negated.
418 This is a minor hack: the NAME used for LITERAL points directly
419 to the mangled string, but since negative numbers are mangled
420 using 'n' instead of '-', we want a way to indicate a negative
421 number which involves neither modifying the mangled string nor
422 allocating a new copy of the literal in memory. */
423 DEMANGLE_COMPONENT_LITERAL_NEG,
424 /* A libgcj compiled resource. The left subtree is the name of the
426 DEMANGLE_COMPONENT_JAVA_RESOURCE,
427 /* A name formed by the concatenation of two parts. The left
428 subtree is the first part and the right subtree the second. */
429 DEMANGLE_COMPONENT_COMPOUND_NAME,
430 /* A name formed by a single character. */
431 DEMANGLE_COMPONENT_CHARACTER,
433 DEMANGLE_COMPONENT_NUMBER,
434 /* A decltype type. */
435 DEMANGLE_COMPONENT_DECLTYPE,
436 /* Global constructors keyed to name. */
437 DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
438 /* Global destructors keyed to name. */
439 DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
440 /* A lambda closure type. */
441 DEMANGLE_COMPONENT_LAMBDA,
442 /* A default argument scope. */
443 DEMANGLE_COMPONENT_DEFAULT_ARG,
444 /* An unnamed type. */
445 DEMANGLE_COMPONENT_UNNAMED_TYPE,
446 /* A transactional clone. This has one subtree, the encoding for
447 which it is providing alternative linkage. */
448 DEMANGLE_COMPONENT_TRANSACTION_CLONE,
449 /* A non-transactional clone entry point. In the i386/x86_64 abi,
450 the unmangled symbol of a tm_callable becomes a thunk and the
451 non-transactional function version is mangled thus. */
452 DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
453 /* A pack expansion. */
454 DEMANGLE_COMPONENT_PACK_EXPANSION,
455 /* A name with an ABI tag. */
456 DEMANGLE_COMPONENT_TAGGED_NAME,
457 /* A transaction-safe function type. */
458 DEMANGLE_COMPONENT_TRANSACTION_SAFE,
459 /* A cloned function. */
460 DEMANGLE_COMPONENT_CLONE,
461 DEMANGLE_COMPONENT_NOEXCEPT,
462 DEMANGLE_COMPONENT_THROW_SPEC
465 /* Types which are only used internally. */
467 struct demangle_operator_info;
468 struct demangle_builtin_type_info;
470 /* A node in the tree representation is an instance of a struct
471 demangle_component. Note that the field names of the struct are
472 not well protected against macros defined by the file including
473 this one. We can fix this if it ever becomes a problem. */
475 struct demangle_component
477 /* The type of this component. */
478 enum demangle_component_type type;
480 /* Guard against recursive component printing.
481 Initialize to zero. Private to d_print_comp.
482 All other fields are final after initialization. */
487 /* For DEMANGLE_COMPONENT_NAME. */
490 /* A pointer to the name (which need not NULL terminated) and
496 /* For DEMANGLE_COMPONENT_OPERATOR. */
500 const struct demangle_operator_info *op;
503 /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
506 /* Number of arguments. */
509 struct demangle_component *name;
510 } s_extended_operator;
512 /* For DEMANGLE_COMPONENT_FIXED_TYPE. */
515 /* The length, indicated by a C integer type name. */
516 struct demangle_component *length;
517 /* _Accum or _Fract? */
519 /* Saturating or not? */
523 /* For DEMANGLE_COMPONENT_CTOR. */
526 /* Kind of constructor. */
527 enum gnu_v3_ctor_kinds kind;
529 struct demangle_component *name;
532 /* For DEMANGLE_COMPONENT_DTOR. */
535 /* Kind of destructor. */
536 enum gnu_v3_dtor_kinds kind;
538 struct demangle_component *name;
541 /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
545 const struct demangle_builtin_type_info *type;
548 /* For DEMANGLE_COMPONENT_SUB_STD. */
551 /* Standard substitution string. */
553 /* Length of string. */
557 /* For DEMANGLE_COMPONENT_*_PARAM. */
560 /* Parameter index. */
564 /* For DEMANGLE_COMPONENT_CHARACTER. */
570 /* For other types. */
573 /* Left (or only) subtree. */
574 struct demangle_component *left;
576 struct demangle_component *right;
581 /* subtree, same place as d_left. */
582 struct demangle_component *sub;
590 /* People building mangled trees are expected to allocate instances of
591 struct demangle_component themselves. They can then call one of
592 the following functions to fill them in. */
594 /* Fill in most component types with a left subtree and a right
595 subtree. Returns non-zero on success, zero on failure, such as an
596 unrecognized or inappropriate component type. */
599 cplus_demangle_fill_component (struct demangle_component *fill,
600 enum demangle_component_type,
601 struct demangle_component *left,
602 struct demangle_component *right);
604 /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
605 zero for bad arguments. */
608 cplus_demangle_fill_name (struct demangle_component *fill,
611 /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
612 builtin type (e.g., "int", etc.). Returns non-zero on success,
613 zero if the type is not recognized. */
616 cplus_demangle_fill_builtin_type (struct demangle_component *fill,
617 const char *type_name);
619 /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
620 operator and the number of arguments which it takes (the latter is
621 used to disambiguate operators which can be both binary and unary,
622 such as '-'). Returns non-zero on success, zero if the operator is
626 cplus_demangle_fill_operator (struct demangle_component *fill,
627 const char *opname, int args);
629 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
630 number of arguments and the name. Returns non-zero on success,
631 zero for bad arguments. */
634 cplus_demangle_fill_extended_operator (struct demangle_component *fill,
636 struct demangle_component *nm);
638 /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
639 zero for bad arguments. */
642 cplus_demangle_fill_ctor (struct demangle_component *fill,
643 enum gnu_v3_ctor_kinds kind,
644 struct demangle_component *name);
646 /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
647 zero for bad arguments. */
650 cplus_demangle_fill_dtor (struct demangle_component *fill,
651 enum gnu_v3_dtor_kinds kind,
652 struct demangle_component *name);
654 /* This function translates a mangled name into a struct
655 demangle_component tree. The first argument is the mangled name.
656 The second argument is DMGL_* options. This returns a pointer to a
657 tree on success, or NULL on failure. On success, the third
658 argument is set to a block of memory allocated by malloc. This
659 block should be passed to free when the tree is no longer
662 extern struct demangle_component *
663 cplus_demangle_v3_components (const char *mangled, int options, void **mem);
665 /* This function takes a struct demangle_component tree and returns
666 the corresponding demangled string. The first argument is DMGL_*
667 options. The second is the tree to demangle. The third is a guess
668 at the length of the demangled string, used to initially allocate
669 the return buffer. The fourth is a pointer to a size_t. On
670 success, this function returns a buffer allocated by malloc(), and
671 sets the size_t pointed to by the fourth argument to the size of
672 the allocated buffer (not the length of the returned string). On
673 failure, this function returns NULL, and sets the size_t pointed to
674 by the fourth argument to 0 for an invalid tree, or to 1 for a
675 memory allocation error. */
678 cplus_demangle_print (int options,
679 struct demangle_component *tree,
680 int estimated_length,
681 size_t *p_allocated_size);
683 /* This function takes a struct demangle_component tree and passes back
684 a demangled string in one or more calls to a callback function.
685 The first argument is DMGL_* options. The second is the tree to
686 demangle. The third is a pointer to a callback function; on each call
687 this receives an element of the demangled string, its length, and an
688 opaque value. The fourth is the opaque value passed to the callback.
689 The callback is called once or more to return the full demangled
690 string. The demangled element string is always nul-terminated, though
691 its length is also provided for convenience. In contrast to
692 cplus_demangle_print(), this function does not allocate heap memory
693 to grow output strings (except perhaps where alloca() is implemented
694 by malloc()), and so is normally safe for use where the heap has been
695 corrupted. On success, this function returns 1; on failure, 0. */
698 cplus_demangle_print_callback (int options,
699 struct demangle_component *tree,
700 demangle_callbackref callback, void *opaque);
704 #endif /* __cplusplus */
706 #endif /* DEMANGLE_H */