1 /* Defs for interface to demanglers.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
3 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License
7 as published by the Free Software Foundation; either version 2, or
8 (at your option) any later version.
10 In addition to the permissions in the GNU Library General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file into
13 combinations with other programs, and to distribute those
14 combinations without any restriction coming from the use of this
15 file. (The Library Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into a combined executable.)
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Library General Public License for more details.
24 You should have received a copy of the GNU Library General Public
25 License along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
30 #if !defined (DEMANGLE_H)
33 #include "libiberty.h"
37 #endif /* __cplusplus */
39 /* Options passed to cplus_demangle (in 2nd parameter). */
41 #define DMGL_NO_OPTS 0 /* For readability... */
42 #define DMGL_PARAMS (1 << 0) /* Include function args */
43 #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
44 #define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
45 #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
46 #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
48 #define DMGL_AUTO (1 << 8)
49 #define DMGL_GNU (1 << 9)
50 #define DMGL_LUCID (1 << 10)
51 #define DMGL_ARM (1 << 11)
52 #define DMGL_HP (1 << 12) /* For the HP aCC compiler;
53 same as ARM except for
54 template arguments, etc. */
55 #define DMGL_EDG (1 << 13)
56 #define DMGL_GNU_V3 (1 << 14)
57 #define DMGL_GNAT (1 << 15)
59 /* If none of these are set, use 'current_demangling_style' as the default. */
60 #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
62 /* Enumeration of possible demangling styles.
64 Lucid and ARM styles are still kept logically distinct, even though
65 they now both behave identically. The resulting style is actual the
66 union of both. I.E. either style recognizes both "__pt__" and "__rf__"
67 for operator "->", even though the first is lucid style and the second
68 is ARM style. (FIXME?) */
70 extern enum demangling_styles
73 unknown_demangling
= 0,
74 auto_demangling
= DMGL_AUTO
,
75 gnu_demangling
= DMGL_GNU
,
76 lucid_demangling
= DMGL_LUCID
,
77 arm_demangling
= DMGL_ARM
,
78 hp_demangling
= DMGL_HP
,
79 edg_demangling
= DMGL_EDG
,
80 gnu_v3_demangling
= DMGL_GNU_V3
,
81 java_demangling
= DMGL_JAVA
,
82 gnat_demangling
= DMGL_GNAT
83 } current_demangling_style
;
85 /* Define string names for the various demangling styles. */
87 #define NO_DEMANGLING_STYLE_STRING "none"
88 #define AUTO_DEMANGLING_STYLE_STRING "auto"
89 #define GNU_DEMANGLING_STYLE_STRING "gnu"
90 #define LUCID_DEMANGLING_STYLE_STRING "lucid"
91 #define ARM_DEMANGLING_STYLE_STRING "arm"
92 #define HP_DEMANGLING_STYLE_STRING "hp"
93 #define EDG_DEMANGLING_STYLE_STRING "edg"
94 #define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
95 #define JAVA_DEMANGLING_STYLE_STRING "java"
96 #define GNAT_DEMANGLING_STYLE_STRING "gnat"
98 /* Some macros to test what demangling style is active. */
100 #define CURRENT_DEMANGLING_STYLE current_demangling_style
101 #define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
102 #define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
103 #define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
104 #define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM)
105 #define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
106 #define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
107 #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
108 #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
109 #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
111 /* Provide information about the available demangle styles. This code is
112 pulled from gdb into libiberty because it is useful to binutils also. */
114 extern const struct demangler_engine
116 const char *const demangling_style_name
;
117 const enum demangling_styles demangling_style
;
118 const char *const demangling_style_doc
;
119 } libiberty_demanglers
[];
122 cplus_demangle (const char *mangled
, int options
);
125 cplus_demangle_opname (const char *opname
, char *result
, int options
);
128 cplus_mangle_opname (const char *opname
, int options
);
130 /* Note: This sets global state. FIXME if you care about multi-threading. */
133 set_cplus_marker_for_demangling (int ch
);
135 extern enum demangling_styles
136 cplus_demangle_set_style (enum demangling_styles style
);
138 extern enum demangling_styles
139 cplus_demangle_name_to_style (const char *name
);
141 /* V3 ABI demangling entry points, defined in cp-demangle.c. */
143 cplus_demangle_v3 (const char* mangled
, int options
);
146 java_demangle_v3 (const char* mangled
);
149 enum gnu_v3_ctor_kinds
{
150 gnu_v3_complete_object_ctor
= 1,
151 gnu_v3_base_object_ctor
,
152 gnu_v3_complete_object_allocating_ctor
155 /* Return non-zero iff NAME is the mangled form of a constructor name
156 in the G++ V3 ABI demangling style. Specifically, return an `enum
157 gnu_v3_ctor_kinds' value indicating what kind of constructor
159 extern enum gnu_v3_ctor_kinds
160 is_gnu_v3_mangled_ctor (const char *name
);
163 enum gnu_v3_dtor_kinds
{
164 gnu_v3_deleting_dtor
= 1,
165 gnu_v3_complete_object_dtor
,
166 gnu_v3_base_object_dtor
169 /* Return non-zero iff NAME is the mangled form of a destructor name
170 in the G++ V3 ABI demangling style. Specifically, return an `enum
171 gnu_v3_dtor_kinds' value, indicating what kind of destructor
173 extern enum gnu_v3_dtor_kinds
174 is_gnu_v3_mangled_dtor (const char *name
);
176 /* The V3 demangler works in two passes. The first pass builds a tree
177 representation of the mangled name, and the second pass turns the
178 tree representation into a demangled string. Here we define an
179 interface to permit a caller to build their own tree
180 representation, which they can pass to the demangler to get a
181 demangled string. This can be used to canonicalize user input into
182 something which the demangler might output. It could also be used
183 by other demanglers in the future. */
185 /* These are the component types which may be found in the tree. Many
186 component types have one or two subtrees, referred to as left and
187 right (a component type with only one subtree puts it in the left
190 enum demangle_component_type
192 /* A name, with a length and a pointer to a string. */
193 DEMANGLE_COMPONENT_NAME
,
194 /* A qualified name. The left subtree is a class or namespace or
195 some such thing, and the right subtree is a name qualified by
197 DEMANGLE_COMPONENT_QUAL_NAME
,
198 /* A local name. The left subtree describes a function, and the
199 right subtree is a name which is local to that function. */
200 DEMANGLE_COMPONENT_LOCAL_NAME
,
201 /* A typed name. The left subtree is a name, and the right subtree
202 describes that name as a function. */
203 DEMANGLE_COMPONENT_TYPED_NAME
,
204 /* A template. The left subtree is a template name, and the right
205 subtree is a template argument list. */
206 DEMANGLE_COMPONENT_TEMPLATE
,
207 /* A template parameter. This holds a number, which is the template
209 DEMANGLE_COMPONENT_TEMPLATE_PARAM
,
210 /* A constructor. This holds a name and the kind of
212 DEMANGLE_COMPONENT_CTOR
,
213 /* A destructor. This holds a name and the kind of destructor. */
214 DEMANGLE_COMPONENT_DTOR
,
215 /* A vtable. This has one subtree, the type for which this is a
217 DEMANGLE_COMPONENT_VTABLE
,
218 /* A VTT structure. This has one subtree, the type for which this
220 DEMANGLE_COMPONENT_VTT
,
221 /* A construction vtable. The left subtree is the type for which
222 this is a vtable, and the right subtree is the derived type for
223 which this vtable is built. */
224 DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
225 /* A typeinfo structure. This has one subtree, the type for which
226 this is the tpeinfo structure. */
227 DEMANGLE_COMPONENT_TYPEINFO
,
228 /* A typeinfo name. This has one subtree, the type for which this
229 is the typeinfo name. */
230 DEMANGLE_COMPONENT_TYPEINFO_NAME
,
231 /* A typeinfo function. This has one subtree, the type for which
232 this is the tpyeinfo function. */
233 DEMANGLE_COMPONENT_TYPEINFO_FN
,
234 /* A thunk. This has one subtree, the name for which this is a
236 DEMANGLE_COMPONENT_THUNK
,
237 /* A virtual thunk. This has one subtree, the name for which this
238 is a virtual thunk. */
239 DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
240 /* A covariant thunk. This has one subtree, the name for which this
241 is a covariant thunk. */
242 DEMANGLE_COMPONENT_COVARIANT_THUNK
,
243 /* A Java class. This has one subtree, the type. */
244 DEMANGLE_COMPONENT_JAVA_CLASS
,
245 /* A guard variable. This has one subtree, the name for which this
246 is a guard variable. */
247 DEMANGLE_COMPONENT_GUARD
,
248 /* A reference temporary. This has one subtree, the name for which
249 this is a temporary. */
250 DEMANGLE_COMPONENT_REFTEMP
,
251 /* A hidden alias. This has one subtree, the encoding for which it
252 is providing alternative linkage. */
253 DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
254 /* A standard substitution. This holds the name of the
256 DEMANGLE_COMPONENT_SUB_STD
,
257 /* The restrict qualifier. The one subtree is the type which is
259 DEMANGLE_COMPONENT_RESTRICT
,
260 /* The volatile qualifier. The one subtree is the type which is
262 DEMANGLE_COMPONENT_VOLATILE
,
263 /* The const qualifier. The one subtree is the type which is being
265 DEMANGLE_COMPONENT_CONST
,
266 /* The restrict qualifier modifying a member function. The one
267 subtree is the type which is being qualified. */
268 DEMANGLE_COMPONENT_RESTRICT_THIS
,
269 /* The volatile qualifier modifying a member function. The one
270 subtree is the type which is being qualified. */
271 DEMANGLE_COMPONENT_VOLATILE_THIS
,
272 /* The const qualifier modifying a member function. The one subtree
273 is the type which is being qualified. */
274 DEMANGLE_COMPONENT_CONST_THIS
,
275 /* A vendor qualifier. The left subtree is the type which is being
276 qualified, and the right subtree is the name of the
278 DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
279 /* A pointer. The one subtree is the type which is being pointed
281 DEMANGLE_COMPONENT_POINTER
,
282 /* A reference. The one subtree is the type which is being
284 DEMANGLE_COMPONENT_REFERENCE
,
285 /* A complex type. The one subtree is the base type. */
286 DEMANGLE_COMPONENT_COMPLEX
,
287 /* An imaginary type. The one subtree is the base type. */
288 DEMANGLE_COMPONENT_IMAGINARY
,
289 /* A builtin type. This holds the builtin type information. */
290 DEMANGLE_COMPONENT_BUILTIN_TYPE
,
291 /* A vendor's builtin type. This holds the name of the type. */
292 DEMANGLE_COMPONENT_VENDOR_TYPE
,
293 /* A function type. The left subtree is the return type. The right
294 subtree is a list of ARGLIST nodes. Either or both may be
296 DEMANGLE_COMPONENT_FUNCTION_TYPE
,
297 /* An array type. The left subtree is the dimension, which may be
298 NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
299 expression. The right subtree is the element type. */
300 DEMANGLE_COMPONENT_ARRAY_TYPE
,
301 /* A pointer to member type. The left subtree is the class type,
302 and the right subtree is the member type. CV-qualifiers appear
304 DEMANGLE_COMPONENT_PTRMEM_TYPE
,
305 /* An argument list. The left subtree is the current argument, and
306 the right subtree is either NULL or another ARGLIST node. */
307 DEMANGLE_COMPONENT_ARGLIST
,
308 /* A template argument list. The left subtree is the current
309 template argument, and the right subtree is either NULL or
310 another TEMPLATE_ARGLIST node. */
311 DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
,
312 /* An operator. This holds information about a standard
314 DEMANGLE_COMPONENT_OPERATOR
,
315 /* An extended operator. This holds the number of arguments, and
316 the name of the extended operator. */
317 DEMANGLE_COMPONENT_EXTENDED_OPERATOR
,
318 /* A typecast, represented as a unary operator. The one subtree is
319 the type to which the argument should be cast. */
320 DEMANGLE_COMPONENT_CAST
,
321 /* A unary expression. The left subtree is the operator, and the
322 right subtree is the single argument. */
323 DEMANGLE_COMPONENT_UNARY
,
324 /* A binary expression. The left subtree is the operator, and the
325 right subtree is a BINARY_ARGS. */
326 DEMANGLE_COMPONENT_BINARY
,
327 /* Arguments to a binary expression. The left subtree is the first
328 argument, and the right subtree is the second argument. */
329 DEMANGLE_COMPONENT_BINARY_ARGS
,
330 /* A trinary expression. The left subtree is the operator, and the
331 right subtree is a TRINARY_ARG1. */
332 DEMANGLE_COMPONENT_TRINARY
,
333 /* Arguments to a trinary expression. The left subtree is the first
334 argument, and the right subtree is a TRINARY_ARG2. */
335 DEMANGLE_COMPONENT_TRINARY_ARG1
,
336 /* More arguments to a trinary expression. The left subtree is the
337 second argument, and the right subtree is the third argument. */
338 DEMANGLE_COMPONENT_TRINARY_ARG2
,
339 /* A literal. The left subtree is the type, and the right subtree
340 is the value, represented as a DEMANGLE_COMPONENT_NAME. */
341 DEMANGLE_COMPONENT_LITERAL
,
342 /* A negative literal. Like LITERAL, but the value is negated.
343 This is a minor hack: the NAME used for LITERAL points directly
344 to the mangled string, but since negative numbers are mangled
345 using 'n' instead of '-', we want a way to indicate a negative
346 number which involves neither modifying the mangled string nor
347 allocating a new copy of the literal in memory. */
348 DEMANGLE_COMPONENT_LITERAL_NEG
351 /* Types which are only used internally. */
353 struct demangle_operator_info
;
354 struct demangle_builtin_type_info
;
356 /* A node in the tree representation is an instance of a struct
357 demangle_component. Note that the field names of the struct are
358 not well protected against macros defined by the file including
359 this one. We can fix this if it ever becomes a problem. */
361 struct demangle_component
363 /* The type of this component. */
364 enum demangle_component_type type
;
368 /* For DEMANGLE_COMPONENT_NAME. */
371 /* A pointer to the name (which need not NULL terminated) and
377 /* For DEMANGLE_COMPONENT_OPERATOR. */
381 const struct demangle_operator_info
*op
;
384 /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
387 /* Number of arguments. */
390 struct demangle_component
*name
;
391 } s_extended_operator
;
393 /* For DEMANGLE_COMPONENT_CTOR. */
396 /* Kind of constructor. */
397 enum gnu_v3_ctor_kinds kind
;
399 struct demangle_component
*name
;
402 /* For DEMANGLE_COMPONENT_DTOR. */
405 /* Kind of destructor. */
406 enum gnu_v3_dtor_kinds kind
;
408 struct demangle_component
*name
;
411 /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
415 const struct demangle_builtin_type_info
*type
;
418 /* For DEMANGLE_COMPONENT_SUB_STD. */
421 /* Standard substitution string. */
423 /* Length of string. */
427 /* For DEMANGLE_COMPONENT_TEMPLATE_PARAM. */
430 /* Template parameter index. */
434 /* For other types. */
437 /* Left (or only) subtree. */
438 struct demangle_component
*left
;
440 struct demangle_component
*right
;
446 /* People building mangled trees are expected to allocate instances of
447 struct demangle_component themselves. They can then call one of
448 the following functions to fill them in. */
450 /* Fill in most component types with a left subtree and a right
451 subtree. Returns non-zero on success, zero on failure, such as an
452 unrecognized or inappropriate component type. */
455 cplus_demangle_fill_component (struct demangle_component
*fill
,
456 enum demangle_component_type
,
457 struct demangle_component
*left
,
458 struct demangle_component
*right
);
460 /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
461 zero for bad arguments. */
464 cplus_demangle_fill_name (struct demangle_component
*fill
,
467 /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
468 builtin type (e.g., "int", etc.). Returns non-zero on success,
469 zero if the type is not recognized. */
472 cplus_demangle_fill_builtin_type (struct demangle_component
*fill
,
473 const char *type_name
);
475 /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
476 operator and the number of arguments which it takes (the latter is
477 used to disambiguate operators which can be both binary and unary,
478 such as '-'). Returns non-zero on success, zero if the operator is
482 cplus_demangle_fill_operator (struct demangle_component
*fill
,
483 const char *opname
, int args
);
485 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
486 number of arguments and the name. Returns non-zero on success,
487 zero for bad arguments. */
490 cplus_demangle_fill_extended_operator (struct demangle_component
*fill
,
492 struct demangle_component
*nm
);
494 /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
495 zero for bad arguments. */
498 cplus_demangle_fill_ctor (struct demangle_component
*fill
,
499 enum gnu_v3_ctor_kinds kind
,
500 struct demangle_component
*name
);
502 /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
503 zero for bad arguments. */
506 cplus_demangle_fill_dtor (struct demangle_component
*fill
,
507 enum gnu_v3_dtor_kinds kind
,
508 struct demangle_component
*name
);
510 /* This function translates a mangled name into a struct
511 demangle_component tree. The first argument is the mangled name.
512 The second argument is DMGL_* options. This returns a pointer to a
513 tree on success, or NULL on failure. On success, the third
514 argument is set to a block of memory allocated by malloc. This
515 block should be passed to free when the tree is no longer
518 extern struct demangle_component
*
519 cplus_demangle_v3_components (const char *mangled
, int options
, void **mem
);
521 /* This function takes a struct demangle_component tree and returns
522 the corresponding demangled string. The first argument is DMGL_*
523 options. The second is the tree to demangle. The third is a guess
524 at the length of the demangled string, used to initially allocate
525 the return buffer. The fourth is a pointer to a size_t. On
526 success, this function returns a buffer allocated by malloc(), and
527 sets the size_t pointed to by the fourth argument to the size of
528 the allocated buffer (not the length of the returned string). On
529 failure, this function returns NULL, and sets the size_t pointed to
530 by the fourth argument to 0 for an invalid tree, or to 1 for a
531 memory allocation error. */
534 cplus_demangle_print (int options
,
535 const struct demangle_component
*tree
,
536 int estimated_length
,
537 size_t *p_allocated_size
);
541 #endif /* __cplusplus */
543 #endif /* DEMANGLE_H */