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