]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/demangle.h
[Ada] Fix documentation for GNAT.Command_Line.Exit_From_Command_Line
[thirdparty/gcc.git] / include / demangle.h
CommitLineData
28e9041c 1/* Defs for interface to demanglers.
fbd26352 2 Copyright (C) 1992-2019 Free Software Foundation, Inc.
0215f1b3 3
1846fb72 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.
8
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.)
17
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.
22
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
26 02110-1301, USA. */
28e9041c 27
28
29#if !defined (DEMANGLE_H)
30#define DEMANGLE_H
31
0a48bf84 32#include "libiberty.h"
a2ebbb48 33
12dd9be6 34#ifdef __cplusplus
35extern "C" {
36#endif /* __cplusplus */
37
28e9041c 38/* Options passed to cplus_demangle (in 2nd parameter). */
39
168d63e5 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++. */
c6d86b63 44#define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
45#define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
4c8420c9 46#define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
932501f9 47 present) after function signature.
48 It applies only to the toplevel
49 function type. */
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.
53 */
168d63e5 54
55#define DMGL_AUTO (1 << 8)
ad1dec1f 56#define DMGL_GNU_V3 (1 << 14)
d0518520 57#define DMGL_GNAT (1 << 15)
23c22e01 58#define DMGL_DLANG (1 << 16)
3f6f78bc 59#define DMGL_RUST (1 << 17) /* Rust wraps GNU_V3 style mangling. */
886cb802 60
28e9041c 61/* If none of these are set, use 'current_demangling_style' as the default. */
302c9cee 62#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG|DMGL_RUST)
28e9041c 63
03e51746 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)
69
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. */
ce27f7c1 73#define DEMANGLE_RECURSION_LIMIT 2048
03e51746 74
28e9041c 75/* Enumeration of possible demangling styles.
76
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?) */
82
83extern enum demangling_styles
84{
8d87ccec 85 no_demangling = -1,
28e9041c 86 unknown_demangling = 0,
87 auto_demangling = DMGL_AUTO,
ad1dec1f 88 gnu_v3_demangling = DMGL_GNU_V3,
d0518520 89 java_demangling = DMGL_JAVA,
23c22e01 90 gnat_demangling = DMGL_GNAT,
3f6f78bc 91 dlang_demangling = DMGL_DLANG,
92 rust_demangling = DMGL_RUST
28e9041c 93} current_demangling_style;
94
95/* Define string names for the various demangling styles. */
96
8d87ccec 97#define NO_DEMANGLING_STYLE_STRING "none"
168d63e5 98#define AUTO_DEMANGLING_STYLE_STRING "auto"
ad1dec1f 99#define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
d0518520 100#define JAVA_DEMANGLING_STYLE_STRING "java"
101#define GNAT_DEMANGLING_STYLE_STRING "gnat"
23c22e01 102#define DLANG_DEMANGLING_STYLE_STRING "dlang"
3f6f78bc 103#define RUST_DEMANGLING_STYLE_STRING "rust"
28e9041c 104
105/* Some macros to test what demangling style is active. */
106
107#define CURRENT_DEMANGLING_STYLE current_demangling_style
108#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
ad1dec1f 109#define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
d0518520 110#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
111#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
23c22e01 112#define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
3f6f78bc 113#define RUST_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_RUST)
28e9041c 114
6f572555 115/* Provide information about the available demangle styles. This code is
116 pulled from gdb into libiberty because it is useful to binutils also. */
117
542e9271 118extern const struct demangler_engine
6f572555 119{
542e9271 120 const char *const demangling_style_name;
121 const enum demangling_styles demangling_style;
122 const char *const demangling_style_doc;
6f572555 123} libiberty_demanglers[];
124
28e9041c 125extern char *
d94aaf66 126cplus_demangle (const char *mangled, int options);
28e9041c 127
28e9041c 128/* Note: This sets global state. FIXME if you care about multi-threading. */
129
060d39cd 130extern enum demangling_styles
d94aaf66 131cplus_demangle_set_style (enum demangling_styles style);
6f572555 132
060d39cd 133extern enum demangling_styles
d94aaf66 134cplus_demangle_name_to_style (const char *name);
168d63e5 135
611fc3d0 136/* Callback typedef for allocation-less demangler interfaces. */
137typedef void (*demangle_callbackref) (const char *, size_t, void *);
138
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. */
142extern int
143cplus_demangle_v3_callback (const char *mangled, int options,
144 demangle_callbackref callback, void *opaque);
ddc92013 145
1c1033dd 146extern char*
611fc3d0 147cplus_demangle_v3 (const char *mangled, int options);
1c1033dd 148
611fc3d0 149extern int
150java_demangle_v3_callback (const char *mangled,
151 demangle_callbackref callback, void *opaque);
152
153extern char*
154java_demangle_v3 (const char *mangled);
64388afa 155
10650b19 156char *
157ada_demangle (const char *mangled, int options);
158
23c22e01 159extern char *
160dlang_demangle (const char *mangled, int options);
161
3f6f78bc 162extern char *
163rust_demangle (const char *mangled, int options);
164
64388afa 165enum gnu_v3_ctor_kinds {
166 gnu_v3_complete_object_ctor = 1,
167 gnu_v3_base_object_ctor,
4c0315d0 168 gnu_v3_complete_object_allocating_ctor,
468088ac 169 /* These are not part of the V3 ABI. Unified constructors are generated
170 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
171 is used, and are always internal symbols. */
172 gnu_v3_unified_ctor,
4c0315d0 173 gnu_v3_object_ctor_group
64388afa 174};
175
176/* Return non-zero iff NAME is the mangled form of a constructor name
177 in the G++ V3 ABI demangling style. Specifically, return an `enum
178 gnu_v3_ctor_kinds' value indicating what kind of constructor
179 it is. */
e5f55ef4 180extern enum gnu_v3_ctor_kinds
d94aaf66 181 is_gnu_v3_mangled_ctor (const char *name);
64388afa 182
183
184enum gnu_v3_dtor_kinds {
185 gnu_v3_deleting_dtor = 1,
186 gnu_v3_complete_object_dtor,
4c0315d0 187 gnu_v3_base_object_dtor,
468088ac 188 /* These are not part of the V3 ABI. Unified destructors are generated
189 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
190 is used, and are always internal symbols. */
191 gnu_v3_unified_dtor,
4c0315d0 192 gnu_v3_object_dtor_group
64388afa 193};
194
195/* Return non-zero iff NAME is the mangled form of a destructor name
196 in the G++ V3 ABI demangling style. Specifically, return an `enum
197 gnu_v3_dtor_kinds' value, indicating what kind of destructor
198 it is. */
e5f55ef4 199extern enum gnu_v3_dtor_kinds
d94aaf66 200 is_gnu_v3_mangled_dtor (const char *name);
64388afa 201
f95cb811 202/* The V3 demangler works in two passes. The first pass builds a tree
203 representation of the mangled name, and the second pass turns the
204 tree representation into a demangled string. Here we define an
205 interface to permit a caller to build their own tree
206 representation, which they can pass to the demangler to get a
207 demangled string. This can be used to canonicalize user input into
208 something which the demangler might output. It could also be used
209 by other demanglers in the future. */
210
211/* These are the component types which may be found in the tree. Many
212 component types have one or two subtrees, referred to as left and
213 right (a component type with only one subtree puts it in the left
214 subtree). */
215
216enum demangle_component_type
217{
218 /* A name, with a length and a pointer to a string. */
219 DEMANGLE_COMPONENT_NAME,
220 /* A qualified name. The left subtree is a class or namespace or
221 some such thing, and the right subtree is a name qualified by
222 that class. */
223 DEMANGLE_COMPONENT_QUAL_NAME,
224 /* A local name. The left subtree describes a function, and the
225 right subtree is a name which is local to that function. */
226 DEMANGLE_COMPONENT_LOCAL_NAME,
227 /* A typed name. The left subtree is a name, and the right subtree
228 describes that name as a function. */
229 DEMANGLE_COMPONENT_TYPED_NAME,
230 /* A template. The left subtree is a template name, and the right
231 subtree is a template argument list. */
232 DEMANGLE_COMPONENT_TEMPLATE,
233 /* A template parameter. This holds a number, which is the template
234 parameter index. */
235 DEMANGLE_COMPONENT_TEMPLATE_PARAM,
e92154af 236 /* A function parameter. This holds a number, which is the index. */
237 DEMANGLE_COMPONENT_FUNCTION_PARAM,
f95cb811 238 /* A constructor. This holds a name and the kind of
239 constructor. */
240 DEMANGLE_COMPONENT_CTOR,
241 /* A destructor. This holds a name and the kind of destructor. */
242 DEMANGLE_COMPONENT_DTOR,
243 /* A vtable. This has one subtree, the type for which this is a
244 vtable. */
245 DEMANGLE_COMPONENT_VTABLE,
246 /* A VTT structure. This has one subtree, the type for which this
247 is a VTT. */
248 DEMANGLE_COMPONENT_VTT,
249 /* A construction vtable. The left subtree is the type for which
250 this is a vtable, and the right subtree is the derived type for
251 which this vtable is built. */
252 DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
253 /* A typeinfo structure. This has one subtree, the type for which
254 this is the tpeinfo structure. */
255 DEMANGLE_COMPONENT_TYPEINFO,
256 /* A typeinfo name. This has one subtree, the type for which this
257 is the typeinfo name. */
258 DEMANGLE_COMPONENT_TYPEINFO_NAME,
259 /* A typeinfo function. This has one subtree, the type for which
260 this is the tpyeinfo function. */
261 DEMANGLE_COMPONENT_TYPEINFO_FN,
262 /* A thunk. This has one subtree, the name for which this is a
263 thunk. */
264 DEMANGLE_COMPONENT_THUNK,
265 /* A virtual thunk. This has one subtree, the name for which this
266 is a virtual thunk. */
267 DEMANGLE_COMPONENT_VIRTUAL_THUNK,
268 /* A covariant thunk. This has one subtree, the name for which this
269 is a covariant thunk. */
270 DEMANGLE_COMPONENT_COVARIANT_THUNK,
271 /* A Java class. This has one subtree, the type. */
272 DEMANGLE_COMPONENT_JAVA_CLASS,
273 /* A guard variable. This has one subtree, the name for which this
274 is a guard variable. */
275 DEMANGLE_COMPONENT_GUARD,
462819c8 276 /* The init and wrapper functions for C++11 thread_local variables. */
277 DEMANGLE_COMPONENT_TLS_INIT,
278 DEMANGLE_COMPONENT_TLS_WRAPPER,
f95cb811 279 /* A reference temporary. This has one subtree, the name for which
280 this is a temporary. */
281 DEMANGLE_COMPONENT_REFTEMP,
e63e3841 282 /* A hidden alias. This has one subtree, the encoding for which it
283 is providing alternative linkage. */
284 DEMANGLE_COMPONENT_HIDDEN_ALIAS,
f95cb811 285 /* A standard substitution. This holds the name of the
286 substitution. */
287 DEMANGLE_COMPONENT_SUB_STD,
288 /* The restrict qualifier. The one subtree is the type which is
289 being qualified. */
290 DEMANGLE_COMPONENT_RESTRICT,
291 /* The volatile qualifier. The one subtree is the type which is
292 being qualified. */
293 DEMANGLE_COMPONENT_VOLATILE,
294 /* The const qualifier. The one subtree is the type which is being
295 qualified. */
296 DEMANGLE_COMPONENT_CONST,
297 /* The restrict qualifier modifying a member function. The one
298 subtree is the type which is being qualified. */
299 DEMANGLE_COMPONENT_RESTRICT_THIS,
300 /* The volatile qualifier modifying a member function. The one
301 subtree is the type which is being qualified. */
302 DEMANGLE_COMPONENT_VOLATILE_THIS,
303 /* The const qualifier modifying a member function. The one subtree
304 is the type which is being qualified. */
305 DEMANGLE_COMPONENT_CONST_THIS,
1189258f 306 /* C++11 A reference modifying a member function. The one subtree is the
307 type which is being referenced. */
308 DEMANGLE_COMPONENT_REFERENCE_THIS,
309 /* C++11: An rvalue reference modifying a member function. The one
310 subtree is the type which is being referenced. */
311 DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS,
f95cb811 312 /* A vendor qualifier. The left subtree is the type which is being
313 qualified, and the right subtree is the name of the
314 qualifier. */
315 DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
316 /* A pointer. The one subtree is the type which is being pointed
317 to. */
318 DEMANGLE_COMPONENT_POINTER,
319 /* A reference. The one subtree is the type which is being
320 referenced. */
321 DEMANGLE_COMPONENT_REFERENCE,
c4692e04 322 /* C++0x: An rvalue reference. The one subtree is the type which is
323 being referenced. */
324 DEMANGLE_COMPONENT_RVALUE_REFERENCE,
f95cb811 325 /* A complex type. The one subtree is the base type. */
326 DEMANGLE_COMPONENT_COMPLEX,
327 /* An imaginary type. The one subtree is the base type. */
328 DEMANGLE_COMPONENT_IMAGINARY,
329 /* A builtin type. This holds the builtin type information. */
330 DEMANGLE_COMPONENT_BUILTIN_TYPE,
331 /* A vendor's builtin type. This holds the name of the type. */
332 DEMANGLE_COMPONENT_VENDOR_TYPE,
333 /* A function type. The left subtree is the return type. The right
334 subtree is a list of ARGLIST nodes. Either or both may be
335 NULL. */
336 DEMANGLE_COMPONENT_FUNCTION_TYPE,
337 /* An array type. The left subtree is the dimension, which may be
338 NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
339 expression. The right subtree is the element type. */
340 DEMANGLE_COMPONENT_ARRAY_TYPE,
341 /* A pointer to member type. The left subtree is the class type,
342 and the right subtree is the member type. CV-qualifiers appear
343 on the latter. */
344 DEMANGLE_COMPONENT_PTRMEM_TYPE,
e4583147 345 /* A fixed-point type. */
346 DEMANGLE_COMPONENT_FIXED_TYPE,
29e2e80a 347 /* A vector type. The left subtree is the number of elements,
348 the right subtree is the element type. */
349 DEMANGLE_COMPONENT_VECTOR_TYPE,
f95cb811 350 /* An argument list. The left subtree is the current argument, and
351 the right subtree is either NULL or another ARGLIST node. */
352 DEMANGLE_COMPONENT_ARGLIST,
353 /* A template argument list. The left subtree is the current
354 template argument, and the right subtree is either NULL or
355 another TEMPLATE_ARGLIST node. */
356 DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
95f798aa 357 /* A template parameter object (C++20). The left subtree is the
358 corresponding template argument. */
359 DEMANGLE_COMPONENT_TPARM_OBJ,
2d847c18 360 /* An initializer list. The left subtree is either an explicit type or
361 NULL, and the right subtree is a DEMANGLE_COMPONENT_ARGLIST. */
362 DEMANGLE_COMPONENT_INITIALIZER_LIST,
f95cb811 363 /* An operator. This holds information about a standard
364 operator. */
365 DEMANGLE_COMPONENT_OPERATOR,
366 /* An extended operator. This holds the number of arguments, and
367 the name of the extended operator. */
368 DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
369 /* A typecast, represented as a unary operator. The one subtree is
370 the type to which the argument should be cast. */
371 DEMANGLE_COMPONENT_CAST,
88845c03 372 /* A conversion operator, represented as a unary operator. The one
373 subtree is the type to which the argument should be converted
374 to. */
375 DEMANGLE_COMPONENT_CONVERSION,
2d847c18 376 /* A nullary expression. The left subtree is the operator. */
377 DEMANGLE_COMPONENT_NULLARY,
f95cb811 378 /* A unary expression. The left subtree is the operator, and the
379 right subtree is the single argument. */
380 DEMANGLE_COMPONENT_UNARY,
381 /* A binary expression. The left subtree is the operator, and the
382 right subtree is a BINARY_ARGS. */
383 DEMANGLE_COMPONENT_BINARY,
384 /* Arguments to a binary expression. The left subtree is the first
385 argument, and the right subtree is the second argument. */
386 DEMANGLE_COMPONENT_BINARY_ARGS,
387 /* A trinary expression. The left subtree is the operator, and the
388 right subtree is a TRINARY_ARG1. */
389 DEMANGLE_COMPONENT_TRINARY,
390 /* Arguments to a trinary expression. The left subtree is the first
391 argument, and the right subtree is a TRINARY_ARG2. */
392 DEMANGLE_COMPONENT_TRINARY_ARG1,
393 /* More arguments to a trinary expression. The left subtree is the
394 second argument, and the right subtree is the third argument. */
395 DEMANGLE_COMPONENT_TRINARY_ARG2,
396 /* A literal. The left subtree is the type, and the right subtree
397 is the value, represented as a DEMANGLE_COMPONENT_NAME. */
398 DEMANGLE_COMPONENT_LITERAL,
399 /* A negative literal. Like LITERAL, but the value is negated.
400 This is a minor hack: the NAME used for LITERAL points directly
401 to the mangled string, but since negative numbers are mangled
402 using 'n' instead of '-', we want a way to indicate a negative
403 number which involves neither modifying the mangled string nor
404 allocating a new copy of the literal in memory. */
c8d35c3c 405 DEMANGLE_COMPONENT_LITERAL_NEG,
406 /* A libgcj compiled resource. The left subtree is the name of the
407 resource. */
408 DEMANGLE_COMPONENT_JAVA_RESOURCE,
409 /* A name formed by the concatenation of two parts. The left
410 subtree is the first part and the right subtree the second. */
411 DEMANGLE_COMPONENT_COMPOUND_NAME,
412 /* A name formed by a single character. */
a2ad5e1b 413 DEMANGLE_COMPONENT_CHARACTER,
29e2e80a 414 /* A number. */
415 DEMANGLE_COMPONENT_NUMBER,
a2ad5e1b 416 /* A decltype type. */
4682b6fe 417 DEMANGLE_COMPONENT_DECLTYPE,
7ddff01e 418 /* Global constructors keyed to name. */
419 DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
420 /* Global destructors keyed to name. */
421 DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
a8b75081 422 /* A lambda closure type. */
423 DEMANGLE_COMPONENT_LAMBDA,
424 /* A default argument scope. */
425 DEMANGLE_COMPONENT_DEFAULT_ARG,
426 /* An unnamed type. */
427 DEMANGLE_COMPONENT_UNNAMED_TYPE,
4c0315d0 428 /* A transactional clone. This has one subtree, the encoding for
429 which it is providing alternative linkage. */
430 DEMANGLE_COMPONENT_TRANSACTION_CLONE,
431 /* A non-transactional clone entry point. In the i386/x86_64 abi,
432 the unmangled symbol of a tm_callable becomes a thunk and the
433 non-transactional function version is mangled thus. */
434 DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
4682b6fe 435 /* A pack expansion. */
0d80d940 436 DEMANGLE_COMPONENT_PACK_EXPANSION,
d4701f6c 437 /* A name with an ABI tag. */
438 DEMANGLE_COMPONENT_TAGGED_NAME,
6d02e6b2 439 /* A transaction-safe function type. */
440 DEMANGLE_COMPONENT_TRANSACTION_SAFE,
0d80d940 441 /* A cloned function. */
2e9e9363 442 DEMANGLE_COMPONENT_CLONE,
443 DEMANGLE_COMPONENT_NOEXCEPT,
444 DEMANGLE_COMPONENT_THROW_SPEC
f95cb811 445};
446
447/* Types which are only used internally. */
448
449struct demangle_operator_info;
450struct demangle_builtin_type_info;
451
452/* A node in the tree representation is an instance of a struct
453 demangle_component. Note that the field names of the struct are
454 not well protected against macros defined by the file including
455 this one. We can fix this if it ever becomes a problem. */
456
457struct demangle_component
458{
459 /* The type of this component. */
460 enum demangle_component_type type;
461
a664c62c 462 /* Guard against recursive component printing.
463 Initialize to zero. Private to d_print_comp.
464 All other fields are final after initialization. */
465 int d_printing;
466
f95cb811 467 union
468 {
469 /* For DEMANGLE_COMPONENT_NAME. */
470 struct
471 {
472 /* A pointer to the name (which need not NULL terminated) and
473 its length. */
474 const char *s;
475 int len;
476 } s_name;
477
478 /* For DEMANGLE_COMPONENT_OPERATOR. */
479 struct
480 {
481 /* Operator. */
482 const struct demangle_operator_info *op;
483 } s_operator;
484
485 /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
486 struct
487 {
488 /* Number of arguments. */
489 int args;
490 /* Name. */
491 struct demangle_component *name;
492 } s_extended_operator;
493
e4583147 494 /* For DEMANGLE_COMPONENT_FIXED_TYPE. */
495 struct
496 {
497 /* The length, indicated by a C integer type name. */
498 struct demangle_component *length;
499 /* _Accum or _Fract? */
500 short accum;
501 /* Saturating or not? */
502 short sat;
503 } s_fixed;
504
f95cb811 505 /* For DEMANGLE_COMPONENT_CTOR. */
506 struct
507 {
508 /* Kind of constructor. */
509 enum gnu_v3_ctor_kinds kind;
510 /* Name. */
511 struct demangle_component *name;
512 } s_ctor;
513
514 /* For DEMANGLE_COMPONENT_DTOR. */
515 struct
516 {
517 /* Kind of destructor. */
518 enum gnu_v3_dtor_kinds kind;
519 /* Name. */
520 struct demangle_component *name;
521 } s_dtor;
522
523 /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
524 struct
525 {
526 /* Builtin type. */
527 const struct demangle_builtin_type_info *type;
528 } s_builtin;
529
530 /* For DEMANGLE_COMPONENT_SUB_STD. */
531 struct
532 {
533 /* Standard substitution string. */
534 const char* string;
535 /* Length of string. */
536 int len;
537 } s_string;
538
e92154af 539 /* For DEMANGLE_COMPONENT_*_PARAM. */
f95cb811 540 struct
541 {
e92154af 542 /* Parameter index. */
f95cb811 543 long number;
544 } s_number;
545
c8d35c3c 546 /* For DEMANGLE_COMPONENT_CHARACTER. */
547 struct
548 {
549 int character;
550 } s_character;
551
f95cb811 552 /* For other types. */
553 struct
554 {
555 /* Left (or only) subtree. */
556 struct demangle_component *left;
557 /* Right subtree. */
558 struct demangle_component *right;
559 } s_binary;
560
a8b75081 561 struct
562 {
563 /* subtree, same place as d_left. */
564 struct demangle_component *sub;
565 /* integer. */
566 int num;
567 } s_unary_num;
568
f95cb811 569 } u;
570};
571
572/* People building mangled trees are expected to allocate instances of
573 struct demangle_component themselves. They can then call one of
574 the following functions to fill them in. */
575
576/* Fill in most component types with a left subtree and a right
577 subtree. Returns non-zero on success, zero on failure, such as an
578 unrecognized or inappropriate component type. */
579
580extern int
d94aaf66 581cplus_demangle_fill_component (struct demangle_component *fill,
582 enum demangle_component_type,
583 struct demangle_component *left,
584 struct demangle_component *right);
f95cb811 585
586/* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
587 zero for bad arguments. */
588
589extern int
d94aaf66 590cplus_demangle_fill_name (struct demangle_component *fill,
591 const char *, int);
f95cb811 592
593/* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
594 builtin type (e.g., "int", etc.). Returns non-zero on success,
595 zero if the type is not recognized. */
596
597extern int
d94aaf66 598cplus_demangle_fill_builtin_type (struct demangle_component *fill,
599 const char *type_name);
f95cb811 600
601/* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
602 operator and the number of arguments which it takes (the latter is
603 used to disambiguate operators which can be both binary and unary,
604 such as '-'). Returns non-zero on success, zero if the operator is
605 not recognized. */
606
607extern int
d94aaf66 608cplus_demangle_fill_operator (struct demangle_component *fill,
609 const char *opname, int args);
f95cb811 610
611/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
612 number of arguments and the name. Returns non-zero on success,
613 zero for bad arguments. */
614
615extern int
d94aaf66 616cplus_demangle_fill_extended_operator (struct demangle_component *fill,
617 int numargs,
618 struct demangle_component *nm);
f95cb811 619
620/* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
621 zero for bad arguments. */
622
623extern int
d94aaf66 624cplus_demangle_fill_ctor (struct demangle_component *fill,
625 enum gnu_v3_ctor_kinds kind,
626 struct demangle_component *name);
f95cb811 627
628/* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
629 zero for bad arguments. */
630
631extern int
d94aaf66 632cplus_demangle_fill_dtor (struct demangle_component *fill,
633 enum gnu_v3_dtor_kinds kind,
634 struct demangle_component *name);
f95cb811 635
636/* This function translates a mangled name into a struct
637 demangle_component tree. The first argument is the mangled name.
638 The second argument is DMGL_* options. This returns a pointer to a
639 tree on success, or NULL on failure. On success, the third
640 argument is set to a block of memory allocated by malloc. This
641 block should be passed to free when the tree is no longer
642 needed. */
643
644extern struct demangle_component *
d94aaf66 645cplus_demangle_v3_components (const char *mangled, int options, void **mem);
f95cb811 646
647/* This function takes a struct demangle_component tree and returns
648 the corresponding demangled string. The first argument is DMGL_*
649 options. The second is the tree to demangle. The third is a guess
650 at the length of the demangled string, used to initially allocate
651 the return buffer. The fourth is a pointer to a size_t. On
652 success, this function returns a buffer allocated by malloc(), and
653 sets the size_t pointed to by the fourth argument to the size of
654 the allocated buffer (not the length of the returned string). On
655 failure, this function returns NULL, and sets the size_t pointed to
656 by the fourth argument to 0 for an invalid tree, or to 1 for a
657 memory allocation error. */
658
659extern char *
d94aaf66 660cplus_demangle_print (int options,
a664c62c 661 struct demangle_component *tree,
d94aaf66 662 int estimated_length,
663 size_t *p_allocated_size);
f95cb811 664
611fc3d0 665/* This function takes a struct demangle_component tree and passes back
666 a demangled string in one or more calls to a callback function.
667 The first argument is DMGL_* options. The second is the tree to
668 demangle. The third is a pointer to a callback function; on each call
669 this receives an element of the demangled string, its length, and an
670 opaque value. The fourth is the opaque value passed to the callback.
671 The callback is called once or more to return the full demangled
672 string. The demangled element string is always nul-terminated, though
673 its length is also provided for convenience. In contrast to
674 cplus_demangle_print(), this function does not allocate heap memory
675 to grow output strings (except perhaps where alloca() is implemented
676 by malloc()), and so is normally safe for use where the heap has been
677 corrupted. On success, this function returns 1; on failure, 0. */
678
679extern int
680cplus_demangle_print_callback (int options,
a664c62c 681 struct demangle_component *tree,
611fc3d0 682 demangle_callbackref callback, void *opaque);
683
12dd9be6 684#ifdef __cplusplus
685}
686#endif /* __cplusplus */
687
28e9041c 688#endif /* DEMANGLE_H */