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