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