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