]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/demangle.h
Add nios2*-*-* to the list of obsolete targets
[thirdparty/gcc.git] / include / demangle.h
CommitLineData
6599da04 1/* Defs for interface to demanglers.
a945c346 2 Copyright (C) 1992-2024 Free Software Foundation, Inc.
9cefc856 3
289c40ed
MM
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. */
6599da04
JM
27
28
29#if !defined (DEMANGLE_H)
30#define DEMANGLE_H
31
d051dc88 32#include "libiberty.h"
e4a32afb 33
513dab32
L
34#ifdef __cplusplus
35extern "C" {
36#endif /* __cplusplus */
37
6599da04
JM
38/* Options passed to cplus_demangle (in 2nd parameter). */
39
69afa80d
AS
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++. */
c13db5d1
JM
44#define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
45#define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
92aed1cb 46#define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
f019462c
JK
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 */
69afa80d
AS
54
55#define DMGL_AUTO (1 << 8)
675ad22c 56#define DMGL_GNU_V3 (1 << 14)
7ecdd10b 57#define DMGL_GNAT (1 << 15)
43b1b9ed 58#define DMGL_DLANG (1 << 16)
10d48c59 59#define DMGL_RUST (1 << 17) /* Rust wraps GNU_V3 style mangling. */
63684e63 60
6599da04 61/* If none of these are set, use 'current_demangling_style' as the default. */
6c8120c5 62#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG|DMGL_RUST)
6599da04 63
e96d1d8c
NC
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. */
921a4c30 73#define DEMANGLE_RECURSION_LIMIT 2048
e96d1d8c 74
6599da04
JM
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{
d06ba3c7 85 no_demangling = -1,
6599da04
JM
86 unknown_demangling = 0,
87 auto_demangling = DMGL_AUTO,
675ad22c 88 gnu_v3_demangling = DMGL_GNU_V3,
7ecdd10b 89 java_demangling = DMGL_JAVA,
43b1b9ed 90 gnat_demangling = DMGL_GNAT,
10d48c59
DT
91 dlang_demangling = DMGL_DLANG,
92 rust_demangling = DMGL_RUST
6599da04
JM
93} current_demangling_style;
94
95/* Define string names for the various demangling styles. */
96
d06ba3c7 97#define NO_DEMANGLING_STYLE_STRING "none"
69afa80d 98#define AUTO_DEMANGLING_STYLE_STRING "auto"
675ad22c 99#define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
7ecdd10b
KB
100#define JAVA_DEMANGLING_STYLE_STRING "java"
101#define GNAT_DEMANGLING_STYLE_STRING "gnat"
43b1b9ed 102#define DLANG_DEMANGLING_STYLE_STRING "dlang"
10d48c59 103#define RUST_DEMANGLING_STYLE_STRING "rust"
6599da04
JM
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)
675ad22c 109#define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
7ecdd10b
KB
110#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
111#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
43b1b9ed 112#define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
10d48c59 113#define RUST_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_RUST)
6599da04 114
24eaa47a
KB
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
0be6abca 118extern const struct demangler_engine
24eaa47a 119{
0be6abca
KG
120 const char *const demangling_style_name;
121 const enum demangling_styles demangling_style;
122 const char *const demangling_style_doc;
24eaa47a
KB
123} libiberty_demanglers[];
124
6599da04 125extern char *
9486db4f 126cplus_demangle (const char *mangled, int options);
6599da04 127
6599da04
JM
128/* Note: This sets global state. FIXME if you care about multi-threading. */
129
721c8251 130extern enum demangling_styles
9486db4f 131cplus_demangle_set_style (enum demangling_styles style);
24eaa47a 132
721c8251 133extern enum demangling_styles
9486db4f 134cplus_demangle_name_to_style (const char *name);
69afa80d 135
456cc5cf
SB
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);
4437e4d4 145
3b60dd8e 146extern char*
456cc5cf 147cplus_demangle_v3 (const char *mangled, int options);
3b60dd8e 148
456cc5cf
SB
149extern int
150java_demangle_v3_callback (const char *mangled,
151 demangle_callbackref callback, void *opaque);
152
153extern char*
154java_demangle_v3 (const char *mangled);
2d32013f 155
5b40c067
TG
156char *
157ada_demangle (const char *mangled, int options);
158
43b1b9ed
IB
159extern char *
160dlang_demangle (const char *mangled, int options);
161
32fc3719
EMB
162extern int
163rust_demangle_callback (const char *mangled, int options,
164 demangle_callbackref callback, void *opaque);
165
166
10d48c59
DT
167extern char *
168rust_demangle (const char *mangled, int options);
169
2d32013f
JB
170enum gnu_v3_ctor_kinds {
171 gnu_v3_complete_object_ctor = 1,
172 gnu_v3_base_object_ctor,
0a35513e 173 gnu_v3_complete_object_allocating_ctor,
1f26ac87
JM
174 /* These are not part of the V3 ABI. Unified constructors are generated
175 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
176 is used, and are always internal symbols. */
177 gnu_v3_unified_ctor,
0a35513e 178 gnu_v3_object_ctor_group
2d32013f
JB
179};
180
181/* Return non-zero iff NAME is the mangled form of a constructor name
182 in the G++ V3 ABI demangling style. Specifically, return an `enum
183 gnu_v3_ctor_kinds' value indicating what kind of constructor
184 it is. */
641b2721 185extern enum gnu_v3_ctor_kinds
9486db4f 186 is_gnu_v3_mangled_ctor (const char *name);
2d32013f
JB
187
188
189enum gnu_v3_dtor_kinds {
190 gnu_v3_deleting_dtor = 1,
191 gnu_v3_complete_object_dtor,
0a35513e 192 gnu_v3_base_object_dtor,
1f26ac87
JM
193 /* These are not part of the V3 ABI. Unified destructors are generated
194 as a speed-for-space optimization when the -fdeclone-ctor-dtor option
195 is used, and are always internal symbols. */
196 gnu_v3_unified_dtor,
0a35513e 197 gnu_v3_object_dtor_group
2d32013f
JB
198};
199
200/* Return non-zero iff NAME is the mangled form of a destructor name
201 in the G++ V3 ABI demangling style. Specifically, return an `enum
202 gnu_v3_dtor_kinds' value, indicating what kind of destructor
203 it is. */
641b2721 204extern enum gnu_v3_dtor_kinds
9486db4f 205 is_gnu_v3_mangled_dtor (const char *name);
2d32013f 206
5e777af5
ILT
207/* The V3 demangler works in two passes. The first pass builds a tree
208 representation of the mangled name, and the second pass turns the
209 tree representation into a demangled string. Here we define an
210 interface to permit a caller to build their own tree
211 representation, which they can pass to the demangler to get a
212 demangled string. This can be used to canonicalize user input into
213 something which the demangler might output. It could also be used
214 by other demanglers in the future. */
215
216/* These are the component types which may be found in the tree. Many
217 component types have one or two subtrees, referred to as left and
218 right (a component type with only one subtree puts it in the left
219 subtree). */
220
221enum demangle_component_type
222{
223 /* A name, with a length and a pointer to a string. */
224 DEMANGLE_COMPONENT_NAME,
225 /* A qualified name. The left subtree is a class or namespace or
226 some such thing, and the right subtree is a name qualified by
227 that class. */
228 DEMANGLE_COMPONENT_QUAL_NAME,
229 /* A local name. The left subtree describes a function, and the
230 right subtree is a name which is local to that function. */
231 DEMANGLE_COMPONENT_LOCAL_NAME,
232 /* A typed name. The left subtree is a name, and the right subtree
233 describes that name as a function. */
234 DEMANGLE_COMPONENT_TYPED_NAME,
235 /* A template. The left subtree is a template name, and the right
236 subtree is a template argument list. */
237 DEMANGLE_COMPONENT_TEMPLATE,
238 /* A template parameter. This holds a number, which is the template
239 parameter index. */
240 DEMANGLE_COMPONENT_TEMPLATE_PARAM,
448545cb
JM
241 /* A function parameter. This holds a number, which is the index. */
242 DEMANGLE_COMPONENT_FUNCTION_PARAM,
5e777af5
ILT
243 /* A constructor. This holds a name and the kind of
244 constructor. */
245 DEMANGLE_COMPONENT_CTOR,
246 /* A destructor. This holds a name and the kind of destructor. */
247 DEMANGLE_COMPONENT_DTOR,
248 /* A vtable. This has one subtree, the type for which this is a
249 vtable. */
250 DEMANGLE_COMPONENT_VTABLE,
251 /* A VTT structure. This has one subtree, the type for which this
252 is a VTT. */
253 DEMANGLE_COMPONENT_VTT,
254 /* A construction vtable. The left subtree is the type for which
255 this is a vtable, and the right subtree is the derived type for
256 which this vtable is built. */
257 DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
258 /* A typeinfo structure. This has one subtree, the type for which
259 this is the tpeinfo structure. */
260 DEMANGLE_COMPONENT_TYPEINFO,
261 /* A typeinfo name. This has one subtree, the type for which this
262 is the typeinfo name. */
263 DEMANGLE_COMPONENT_TYPEINFO_NAME,
264 /* A typeinfo function. This has one subtree, the type for which
265 this is the tpyeinfo function. */
266 DEMANGLE_COMPONENT_TYPEINFO_FN,
267 /* A thunk. This has one subtree, the name for which this is a
268 thunk. */
269 DEMANGLE_COMPONENT_THUNK,
270 /* A virtual thunk. This has one subtree, the name for which this
271 is a virtual thunk. */
272 DEMANGLE_COMPONENT_VIRTUAL_THUNK,
273 /* A covariant thunk. This has one subtree, the name for which this
274 is a covariant thunk. */
275 DEMANGLE_COMPONENT_COVARIANT_THUNK,
276 /* A Java class. This has one subtree, the type. */
277 DEMANGLE_COMPONENT_JAVA_CLASS,
278 /* A guard variable. This has one subtree, the name for which this
279 is a guard variable. */
280 DEMANGLE_COMPONENT_GUARD,
7c424acd
JM
281 /* The init and wrapper functions for C++11 thread_local variables. */
282 DEMANGLE_COMPONENT_TLS_INIT,
283 DEMANGLE_COMPONENT_TLS_WRAPPER,
5e777af5
ILT
284 /* A reference temporary. This has one subtree, the name for which
285 this is a temporary. */
286 DEMANGLE_COMPONENT_REFTEMP,
15da2806
RH
287 /* A hidden alias. This has one subtree, the encoding for which it
288 is providing alternative linkage. */
289 DEMANGLE_COMPONENT_HIDDEN_ALIAS,
5e777af5
ILT
290 /* A standard substitution. This holds the name of the
291 substitution. */
292 DEMANGLE_COMPONENT_SUB_STD,
293 /* The restrict qualifier. The one subtree is the type which is
294 being qualified. */
295 DEMANGLE_COMPONENT_RESTRICT,
296 /* The volatile qualifier. The one subtree is the type which is
297 being qualified. */
298 DEMANGLE_COMPONENT_VOLATILE,
299 /* The const qualifier. The one subtree is the type which is being
300 qualified. */
301 DEMANGLE_COMPONENT_CONST,
302 /* The restrict qualifier modifying a member function. The one
303 subtree is the type which is being qualified. */
304 DEMANGLE_COMPONENT_RESTRICT_THIS,
305 /* The volatile qualifier modifying a member function. The one
306 subtree is the type which is being qualified. */
307 DEMANGLE_COMPONENT_VOLATILE_THIS,
308 /* The const qualifier modifying a member function. The one subtree
309 is the type which is being qualified. */
310 DEMANGLE_COMPONENT_CONST_THIS,
9eb85f27
JM
311 /* C++11 A reference modifying a member function. The one subtree is the
312 type which is being referenced. */
313 DEMANGLE_COMPONENT_REFERENCE_THIS,
314 /* C++11: An rvalue reference modifying a member function. The one
315 subtree is the type which is being referenced. */
316 DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS,
65388b28
JJ
317 /* C++23: A member function with explict object parameter. */
318 DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION,
5e777af5
ILT
319 /* A vendor qualifier. The left subtree is the type which is being
320 qualified, and the right subtree is the name of the
321 qualifier. */
322 DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
323 /* A pointer. The one subtree is the type which is being pointed
324 to. */
325 DEMANGLE_COMPONENT_POINTER,
326 /* A reference. The one subtree is the type which is being
327 referenced. */
328 DEMANGLE_COMPONENT_REFERENCE,
1ab28be5
DG
329 /* C++0x: An rvalue reference. The one subtree is the type which is
330 being referenced. */
331 DEMANGLE_COMPONENT_RVALUE_REFERENCE,
5e777af5
ILT
332 /* A complex type. The one subtree is the base type. */
333 DEMANGLE_COMPONENT_COMPLEX,
334 /* An imaginary type. The one subtree is the base type. */
335 DEMANGLE_COMPONENT_IMAGINARY,
336 /* A builtin type. This holds the builtin type information. */
337 DEMANGLE_COMPONENT_BUILTIN_TYPE,
338 /* A vendor's builtin type. This holds the name of the type. */
339 DEMANGLE_COMPONENT_VENDOR_TYPE,
340 /* A function type. The left subtree is the return type. The right
341 subtree is a list of ARGLIST nodes. Either or both may be
342 NULL. */
343 DEMANGLE_COMPONENT_FUNCTION_TYPE,
344 /* An array type. The left subtree is the dimension, which may be
345 NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
346 expression. The right subtree is the element type. */
347 DEMANGLE_COMPONENT_ARRAY_TYPE,
348 /* A pointer to member type. The left subtree is the class type,
349 and the right subtree is the member type. CV-qualifiers appear
350 on the latter. */
351 DEMANGLE_COMPONENT_PTRMEM_TYPE,
07523e7c
JM
352 /* A fixed-point type. */
353 DEMANGLE_COMPONENT_FIXED_TYPE,
abfe01ce
JM
354 /* A vector type. The left subtree is the number of elements,
355 the right subtree is the element type. */
356 DEMANGLE_COMPONENT_VECTOR_TYPE,
5e777af5
ILT
357 /* An argument list. The left subtree is the current argument, and
358 the right subtree is either NULL or another ARGLIST node. */
359 DEMANGLE_COMPONENT_ARGLIST,
360 /* A template argument list. The left subtree is the current
361 template argument, and the right subtree is either NULL or
362 another TEMPLATE_ARGLIST node. */
363 DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
4be5c72c
JM
364 /* A template parameter object (C++20). The left subtree is the
365 corresponding template argument. */
366 DEMANGLE_COMPONENT_TPARM_OBJ,
4b6aaa99
JM
367 /* An initializer list. The left subtree is either an explicit type or
368 NULL, and the right subtree is a DEMANGLE_COMPONENT_ARGLIST. */
369 DEMANGLE_COMPONENT_INITIALIZER_LIST,
5e777af5
ILT
370 /* An operator. This holds information about a standard
371 operator. */
372 DEMANGLE_COMPONENT_OPERATOR,
373 /* An extended operator. This holds the number of arguments, and
374 the name of the extended operator. */
375 DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
376 /* A typecast, represented as a unary operator. The one subtree is
377 the type to which the argument should be cast. */
378 DEMANGLE_COMPONENT_CAST,
921da198
PA
379 /* A conversion operator, represented as a unary operator. The one
380 subtree is the type to which the argument should be converted
381 to. */
382 DEMANGLE_COMPONENT_CONVERSION,
4b6aaa99
JM
383 /* A nullary expression. The left subtree is the operator. */
384 DEMANGLE_COMPONENT_NULLARY,
5e777af5
ILT
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. */
e5df4fb1 412 DEMANGLE_COMPONENT_LITERAL_NEG,
a3bf6ce7
PP
413 /* A vendor's builtin expression. The left subtree holds the
414 expression's name, and the right subtree is a argument list. */
415 DEMANGLE_COMPONENT_VENDOR_EXPR,
e5df4fb1
DD
416 /* A libgcj compiled resource. The left subtree is the name of the
417 resource. */
418 DEMANGLE_COMPONENT_JAVA_RESOURCE,
419 /* A name formed by the concatenation of two parts. The left
420 subtree is the first part and the right subtree the second. */
421 DEMANGLE_COMPONENT_COMPOUND_NAME,
422 /* A name formed by a single character. */
5a3d7e74 423 DEMANGLE_COMPONENT_CHARACTER,
abfe01ce
JM
424 /* A number. */
425 DEMANGLE_COMPONENT_NUMBER,
5a3d7e74 426 /* A decltype type. */
38179091 427 DEMANGLE_COMPONENT_DECLTYPE,
23b1a789
JK
428 /* Global constructors keyed to name. */
429 DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
430 /* Global destructors keyed to name. */
431 DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
d5f4eddd
JM
432 /* A lambda closure type. */
433 DEMANGLE_COMPONENT_LAMBDA,
434 /* A default argument scope. */
435 DEMANGLE_COMPONENT_DEFAULT_ARG,
436 /* An unnamed type. */
437 DEMANGLE_COMPONENT_UNNAMED_TYPE,
0a35513e
AH
438 /* A transactional clone. This has one subtree, the encoding for
439 which it is providing alternative linkage. */
440 DEMANGLE_COMPONENT_TRANSACTION_CLONE,
441 /* A non-transactional clone entry point. In the i386/x86_64 abi,
442 the unmangled symbol of a tm_callable becomes a thunk and the
443 non-transactional function version is mangled thus. */
444 DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
38179091 445 /* A pack expansion. */
2d2b02c4 446 DEMANGLE_COMPONENT_PACK_EXPANSION,
7dbb85a7
JM
447 /* A name with an ABI tag. */
448 DEMANGLE_COMPONENT_TAGGED_NAME,
b8fd7909
JM
449 /* A transaction-safe function type. */
450 DEMANGLE_COMPONENT_TRANSACTION_SAFE,
2d2b02c4 451 /* A cloned function. */
51dc6603 452 DEMANGLE_COMPONENT_CLONE,
810bcc00
JM
453 /* A member-like friend function. */
454 DEMANGLE_COMPONENT_FRIEND,
51dc6603 455 DEMANGLE_COMPONENT_NOEXCEPT,
451894ca
NS
456 DEMANGLE_COMPONENT_THROW_SPEC,
457
b7feb71d
NS
458 DEMANGLE_COMPONENT_STRUCTURED_BINDING,
459
460 DEMANGLE_COMPONENT_MODULE_NAME,
461 DEMANGLE_COMPONENT_MODULE_PARTITION,
462 DEMANGLE_COMPONENT_MODULE_ENTITY,
463 DEMANGLE_COMPONENT_MODULE_INIT,
b0420889 464
46c3d9c8
NS
465 DEMANGLE_COMPONENT_TEMPLATE_HEAD,
466 DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM,
467 DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM,
468 DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM,
469 DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM,
470
c3f281a0
JM
471 DEMANGLE_COMPONENT_CONSTRAINTS,
472
b0420889
JJ
473 /* A builtin type with argument. This holds the builtin type
474 information. */
475 DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
476
5e777af5
ILT
477};
478
479/* Types which are only used internally. */
480
481struct demangle_operator_info;
482struct demangle_builtin_type_info;
483
484/* A node in the tree representation is an instance of a struct
485 demangle_component. Note that the field names of the struct are
486 not well protected against macros defined by the file including
487 this one. We can fix this if it ever becomes a problem. */
488
489struct demangle_component
490{
491 /* The type of this component. */
492 enum demangle_component_type type;
493
a46586c3
MW
494 /* Guard against recursive component printing.
495 Initialize to zero. Private to d_print_comp.
496 All other fields are final after initialization. */
497 int d_printing;
513e0aa0 498 int d_counting;
a46586c3 499
5e777af5
ILT
500 union
501 {
502 /* For DEMANGLE_COMPONENT_NAME. */
503 struct
504 {
505 /* A pointer to the name (which need not NULL terminated) and
506 its length. */
507 const char *s;
508 int len;
509 } s_name;
510
511 /* For DEMANGLE_COMPONENT_OPERATOR. */
512 struct
513 {
514 /* Operator. */
515 const struct demangle_operator_info *op;
516 } s_operator;
517
518 /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
519 struct
520 {
521 /* Number of arguments. */
522 int args;
523 /* Name. */
524 struct demangle_component *name;
525 } s_extended_operator;
526
07523e7c
JM
527 /* For DEMANGLE_COMPONENT_FIXED_TYPE. */
528 struct
529 {
530 /* The length, indicated by a C integer type name. */
531 struct demangle_component *length;
532 /* _Accum or _Fract? */
533 short accum;
534 /* Saturating or not? */
535 short sat;
536 } s_fixed;
537
5e777af5
ILT
538 /* For DEMANGLE_COMPONENT_CTOR. */
539 struct
540 {
541 /* Kind of constructor. */
542 enum gnu_v3_ctor_kinds kind;
543 /* Name. */
544 struct demangle_component *name;
545 } s_ctor;
546
547 /* For DEMANGLE_COMPONENT_DTOR. */
548 struct
549 {
550 /* Kind of destructor. */
551 enum gnu_v3_dtor_kinds kind;
552 /* Name. */
553 struct demangle_component *name;
554 } s_dtor;
555
556 /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
557 struct
558 {
559 /* Builtin type. */
560 const struct demangle_builtin_type_info *type;
561 } s_builtin;
562
b0420889
JJ
563 /* For DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. */
564 struct
565 {
566 /* Builtin type. */
567 const struct demangle_builtin_type_info *type;
568 short arg;
569 char suffix;
570 } s_extended_builtin;
571
5e777af5
ILT
572 /* For DEMANGLE_COMPONENT_SUB_STD. */
573 struct
574 {
575 /* Standard substitution string. */
576 const char* string;
577 /* Length of string. */
578 int len;
579 } s_string;
580
448545cb 581 /* For DEMANGLE_COMPONENT_*_PARAM. */
5e777af5
ILT
582 struct
583 {
448545cb 584 /* Parameter index. */
5e777af5
ILT
585 long number;
586 } s_number;
587
e5df4fb1
DD
588 /* For DEMANGLE_COMPONENT_CHARACTER. */
589 struct
590 {
591 int character;
592 } s_character;
593
5e777af5
ILT
594 /* For other types. */
595 struct
596 {
597 /* Left (or only) subtree. */
598 struct demangle_component *left;
599 /* Right subtree. */
600 struct demangle_component *right;
601 } s_binary;
602
d5f4eddd
JM
603 struct
604 {
605 /* subtree, same place as d_left. */
606 struct demangle_component *sub;
607 /* integer. */
608 int num;
609 } s_unary_num;
610
5e777af5
ILT
611 } u;
612};
613
614/* People building mangled trees are expected to allocate instances of
615 struct demangle_component themselves. They can then call one of
616 the following functions to fill them in. */
617
618/* Fill in most component types with a left subtree and a right
619 subtree. Returns non-zero on success, zero on failure, such as an
620 unrecognized or inappropriate component type. */
621
622extern int
9486db4f
GDR
623cplus_demangle_fill_component (struct demangle_component *fill,
624 enum demangle_component_type,
625 struct demangle_component *left,
626 struct demangle_component *right);
5e777af5
ILT
627
628/* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
629 zero for bad arguments. */
630
631extern int
9486db4f
GDR
632cplus_demangle_fill_name (struct demangle_component *fill,
633 const char *, int);
5e777af5
ILT
634
635/* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
636 builtin type (e.g., "int", etc.). Returns non-zero on success,
637 zero if the type is not recognized. */
638
639extern int
9486db4f
GDR
640cplus_demangle_fill_builtin_type (struct demangle_component *fill,
641 const char *type_name);
5e777af5
ILT
642
643/* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
644 operator and the number of arguments which it takes (the latter is
645 used to disambiguate operators which can be both binary and unary,
646 such as '-'). Returns non-zero on success, zero if the operator is
647 not recognized. */
648
649extern int
9486db4f
GDR
650cplus_demangle_fill_operator (struct demangle_component *fill,
651 const char *opname, int args);
5e777af5
ILT
652
653/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
654 number of arguments and the name. Returns non-zero on success,
655 zero for bad arguments. */
656
657extern int
9486db4f
GDR
658cplus_demangle_fill_extended_operator (struct demangle_component *fill,
659 int numargs,
660 struct demangle_component *nm);
5e777af5
ILT
661
662/* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
663 zero for bad arguments. */
664
665extern int
9486db4f
GDR
666cplus_demangle_fill_ctor (struct demangle_component *fill,
667 enum gnu_v3_ctor_kinds kind,
668 struct demangle_component *name);
5e777af5
ILT
669
670/* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
671 zero for bad arguments. */
672
673extern int
9486db4f
GDR
674cplus_demangle_fill_dtor (struct demangle_component *fill,
675 enum gnu_v3_dtor_kinds kind,
676 struct demangle_component *name);
5e777af5
ILT
677
678/* This function translates a mangled name into a struct
679 demangle_component tree. The first argument is the mangled name.
680 The second argument is DMGL_* options. This returns a pointer to a
681 tree on success, or NULL on failure. On success, the third
682 argument is set to a block of memory allocated by malloc. This
683 block should be passed to free when the tree is no longer
684 needed. */
685
686extern struct demangle_component *
9486db4f 687cplus_demangle_v3_components (const char *mangled, int options, void **mem);
5e777af5
ILT
688
689/* This function takes a struct demangle_component tree and returns
690 the corresponding demangled string. The first argument is DMGL_*
691 options. The second is the tree to demangle. The third is a guess
692 at the length of the demangled string, used to initially allocate
693 the return buffer. The fourth is a pointer to a size_t. On
694 success, this function returns a buffer allocated by malloc(), and
695 sets the size_t pointed to by the fourth argument to the size of
696 the allocated buffer (not the length of the returned string). On
697 failure, this function returns NULL, and sets the size_t pointed to
698 by the fourth argument to 0 for an invalid tree, or to 1 for a
699 memory allocation error. */
700
701extern char *
9486db4f 702cplus_demangle_print (int options,
a46586c3 703 struct demangle_component *tree,
9486db4f
GDR
704 int estimated_length,
705 size_t *p_allocated_size);
5e777af5 706
456cc5cf
SB
707/* This function takes a struct demangle_component tree and passes back
708 a demangled string in one or more calls to a callback function.
709 The first argument is DMGL_* options. The second is the tree to
710 demangle. The third is a pointer to a callback function; on each call
711 this receives an element of the demangled string, its length, and an
712 opaque value. The fourth is the opaque value passed to the callback.
713 The callback is called once or more to return the full demangled
714 string. The demangled element string is always nul-terminated, though
715 its length is also provided for convenience. In contrast to
716 cplus_demangle_print(), this function does not allocate heap memory
717 to grow output strings (except perhaps where alloca() is implemented
718 by malloc()), and so is normally safe for use where the heap has been
719 corrupted. On success, this function returns 1; on failure, 0. */
720
721extern int
722cplus_demangle_print_callback (int options,
a46586c3 723 struct demangle_component *tree,
456cc5cf
SB
724 demangle_callbackref callback, void *opaque);
725
513dab32
L
726#ifdef __cplusplus
727}
728#endif /* __cplusplus */
729
6599da04 730#endif /* DEMANGLE_H */