2
* This file is a concatenation of the files
9
* all taken from libiberty in binutils v. 2.16. After this concatenation
10
* many calls to other functions in libiberty were replaced by calls to
11
* similar functions in glib. Also global entry points that we don't need
12
* in sysprof were made static or removed.
14
* Let's hope that no bugs are ever found in this file!
16
* Maybe someday look at what can be deleted from this file
18
* - "mini string library" can be replaced with GString
19
* - "option" parameter to cplus_demangle can be deleted
20
* - demangling is always "auto"
25
* Demangler for g++ V3 ABI.
26
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
27
* Written by Ian Lance Taylor <ian@wasabisystems.com>.
29
* This file is part of the libiberty library, which is part of GCC.
31
Defs for interface to demanglers.
32
Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
33
2003, 2004 Free Software Foundation, Inc.
35
Internal demangler interface for g++ V3 ABI.
36
Copyright (C) 2003, 2004 Free Software Foundation, Inc.
37
Written by Ian Lance Taylor <ian@wasabisystems.com>.
40
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
41
2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
43
Written by James Clark (jjc@jclark.uucp)
44
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
45
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
47
This file is free software; you can redistribute it and/or modify
48
it under the terms of the GNU General Public License as published by
49
the Free Software Foundation; either version 2, or (at your option)
52
This program is distributed in the hope that it will be useful,
53
but WITHOUT ANY WARRANTY; without even the implied warranty of
54
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
GNU General Public License for more details.
57
You should have received a copy of the GNU General Public License
58
along with this program; if not, write to the Free Software
59
Foundation, Inc., 59 Temple Place - Suite 330,
60
Boston, MA 02111-1307, USA.
63
/* This code implements a demangler for the g++ V3 ABI. The ABI is
64
described on this web page:
65
http://www.codesourcery.com/cxx-abi/abi.html#mangling
67
This code was written while looking at the demangler written by
68
Alex Samuel <samuel@codesourcery.com>.
70
This code first pulls the mangled name apart into a list of
71
components, and then walks the list generating the demangled
74
This file will normally define the following functions, q.v.:
75
char *cplus_demangle_v3(const char *mangled, int options)
76
char *java_demangle_v3(const char *mangled)
77
enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
78
enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
80
Also, the interface to the component list is public, and defined in
81
demangle.h. The interface consists of these types, which are
82
defined in demangle.h:
83
enum demangle_component_type
84
struct demangle_component
85
and these functions defined in this file:
86
cplus_demangle_fill_name
87
cplus_demangle_fill_extended_operator
88
cplus_demangle_fill_ctor
89
cplus_demangle_fill_dtor
91
and other functions defined in the file cp-demint.c.
93
This file also defines some other functions and variables which are
94
only to be used by the file cp-demint.c.
96
Preprocessor macros you can define while compiling this file:
99
If defined, this file defines the following function, q.v.:
100
char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
102
instead of cplus_demangle_v3() and java_demangle_v3().
105
If defined, this file defines only __cxa_demangle(), and no other
106
publically visible functions or variables.
109
If defined, turns on debugging mode, which prints information on
110
stdout about the mangled string. This is not generally useful.
117
#include <sys/types.h>
118
/* Defs for interface to demanglers.
119
Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
120
2003, 2004 Free Software Foundation, Inc.
122
This program is free software; you can redistribute it and/or modify
123
it under the terms of the GNU General Public License as published by
124
the Free Software Foundation; either version 2, or (at your option)
127
This program is distributed in the hope that it will be useful,
128
but WITHOUT ANY WARRANTY; without even the implied warranty of
129
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130
GNU General Public License for more details.
132
You should have received a copy of the GNU General Public License
133
along with this program; if not, write to the Free Software
134
Foundation, Inc., 59 Temple Place - Suite 330,
135
Boston, MA 02111-1307, USA. */
138
#if !defined (DEMANGLE_H)
145
#endif /* __cplusplus */
147
/* Options passed to cplus_demangle (in 2nd parameter). */
149
#define DMGL_NO_OPTS 0 /* For readability... */
150
#define DMGL_PARAMS (1 << 0) /* Include function args */
151
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
152
#define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
153
#define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
154
#define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
156
#define DMGL_AUTO (1 << 8)
157
#define DMGL_GNU (1 << 9)
158
#define DMGL_LUCID (1 << 10)
159
#define DMGL_ARM (1 << 11)
160
#define DMGL_HP (1 << 12) /* For the HP aCC compiler;
161
same as ARM except for
162
template arguments, etc. */
163
#define DMGL_EDG (1 << 13)
164
#define DMGL_GNU_V3 (1 << 14)
165
#define DMGL_GNAT (1 << 15)
167
/* If none of these are set, use 'current_demangling_style' as the default. */
168
#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
170
/* Enumeration of possible demangling styles.
172
Lucid and ARM styles are still kept logically distinct, even though
173
they now both behave identically. The resulting style is actual the
174
union of both. I.E. either style recognizes both "__pt__" and "__rf__"
175
for operator "->", even though the first is lucid style and the second
176
is ARM style. (FIXME?) */
178
enum demangling_styles
181
unknown_demangling = 0,
182
auto_demangling = DMGL_AUTO,
183
gnu_demangling = DMGL_GNU,
184
lucid_demangling = DMGL_LUCID,
185
arm_demangling = DMGL_ARM,
186
hp_demangling = DMGL_HP,
187
edg_demangling = DMGL_EDG,
188
gnu_v3_demangling = DMGL_GNU_V3,
189
java_demangling = DMGL_JAVA,
190
gnat_demangling = DMGL_GNAT
193
/* Define string names for the various demangling styles. */
195
#define NO_DEMANGLING_STYLE_STRING "none"
196
#define AUTO_DEMANGLING_STYLE_STRING "auto"
197
#define GNU_DEMANGLING_STYLE_STRING "gnu"
198
#define LUCID_DEMANGLING_STYLE_STRING "lucid"
199
#define ARM_DEMANGLING_STYLE_STRING "arm"
200
#define HP_DEMANGLING_STYLE_STRING "hp"
201
#define EDG_DEMANGLING_STYLE_STRING "edg"
202
#define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
203
#define JAVA_DEMANGLING_STYLE_STRING "java"
204
#define GNAT_DEMANGLING_STYLE_STRING "gnat"
206
/* Some macros to test what demangling style is active. */
208
#define CURRENT_DEMANGLING_STYLE current_demangling_style
209
#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
210
#define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
211
#define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
212
#define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM)
213
#define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
214
#define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
215
#define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
216
#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
217
#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
219
/* Provide information about the available demangle styles. This code is
220
pulled from gdb into libiberty because it is useful to binutils also. */
224
#define ATTRIBUTE_NORETURN G_GNUC_NORETURN
225
#define ATTRIBUTE_UNUSED G_GNUC_UNUSED
227
static const struct demangler_engine
229
const char *const demangling_style_name;
230
const enum demangling_styles demangling_style;
231
const char *const demangling_style_doc;
232
} libiberty_demanglers[];
236
cplus_demangle PARAMS ((const char *mangled, int options));
241
cplus_demangle_opname PARAMS ((const char *opname, char *result, int options));
244
cplus_mangle_opname PARAMS ((const char *opname, int options));
247
/* Note: This sets global state. FIXME if you care about multi-threading. */
249
enum gnu_v3_ctor_kinds {
250
gnu_v3_complete_object_ctor = 1,
251
gnu_v3_base_object_ctor,
252
gnu_v3_complete_object_allocating_ctor
255
/* Return non-zero iff NAME is the mangled form of a constructor name
256
in the G++ V3 ABI demangling style. Specifically, return an `enum
257
gnu_v3_ctor_kinds' value indicating what kind of constructor
259
extern enum gnu_v3_ctor_kinds
260
is_gnu_v3_mangled_ctor PARAMS ((const char *name));
263
enum gnu_v3_dtor_kinds {
264
gnu_v3_deleting_dtor = 1,
265
gnu_v3_complete_object_dtor,
266
gnu_v3_base_object_dtor
269
/* Return non-zero iff NAME is the mangled form of a destructor name
270
in the G++ V3 ABI demangling style. Specifically, return an `enum
271
gnu_v3_dtor_kinds' value, indicating what kind of destructor
273
extern enum gnu_v3_dtor_kinds
274
is_gnu_v3_mangled_dtor PARAMS ((const char *name));
276
/* The V3 demangler works in two passes. The first pass builds a tree
277
representation of the mangled name, and the second pass turns the
278
tree representation into a demangled string. Here we define an
279
interface to permit a caller to build their own tree
280
representation, which they can pass to the demangler to get a
281
demangled string. This can be used to canonicalize user input into
282
something which the demangler might output. It could also be used
283
by other demanglers in the future. */
285
/* These are the component types which may be found in the tree. Many
286
component types have one or two subtrees, referred to as left and
287
right (a component type with only one subtree puts it in the left
290
enum demangle_component_type
292
/* A name, with a length and a pointer to a string. */
293
DEMANGLE_COMPONENT_NAME,
294
/* A qualified name. The left subtree is a class or namespace or
295
some such thing, and the right subtree is a name qualified by
297
DEMANGLE_COMPONENT_QUAL_NAME,
298
/* A local name. The left subtree describes a function, and the
299
right subtree is a name which is local to that function. */
300
DEMANGLE_COMPONENT_LOCAL_NAME,
301
/* A typed name. The left subtree is a name, and the right subtree
302
describes that name as a function. */
303
DEMANGLE_COMPONENT_TYPED_NAME,
304
/* A template. The left subtree is a template name, and the right
305
subtree is a template argument list. */
306
DEMANGLE_COMPONENT_TEMPLATE,
307
/* A template parameter. This holds a number, which is the template
309
DEMANGLE_COMPONENT_TEMPLATE_PARAM,
310
/* A constructor. This holds a name and the kind of
312
DEMANGLE_COMPONENT_CTOR,
313
/* A destructor. This holds a name and the kind of destructor. */
314
DEMANGLE_COMPONENT_DTOR,
315
/* A vtable. This has one subtree, the type for which this is a
317
DEMANGLE_COMPONENT_VTABLE,
318
/* A VTT structure. This has one subtree, the type for which this
320
DEMANGLE_COMPONENT_VTT,
321
/* A construction vtable. The left subtree is the type for which
322
this is a vtable, and the right subtree is the derived type for
323
which this vtable is built. */
324
DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
325
/* A typeinfo structure. This has one subtree, the type for which
326
this is the tpeinfo structure. */
327
DEMANGLE_COMPONENT_TYPEINFO,
328
/* A typeinfo name. This has one subtree, the type for which this
329
is the typeinfo name. */
330
DEMANGLE_COMPONENT_TYPEINFO_NAME,
331
/* A typeinfo function. This has one subtree, the type for which
332
this is the tpyeinfo function. */
333
DEMANGLE_COMPONENT_TYPEINFO_FN,
334
/* A thunk. This has one subtree, the name for which this is a
336
DEMANGLE_COMPONENT_THUNK,
337
/* A virtual thunk. This has one subtree, the name for which this
338
is a virtual thunk. */
339
DEMANGLE_COMPONENT_VIRTUAL_THUNK,
340
/* A covariant thunk. This has one subtree, the name for which this
341
is a covariant thunk. */
342
DEMANGLE_COMPONENT_COVARIANT_THUNK,
343
/* A Java class. This has one subtree, the type. */
344
DEMANGLE_COMPONENT_JAVA_CLASS,
345
/* A guard variable. This has one subtree, the name for which this
346
is a guard variable. */
347
DEMANGLE_COMPONENT_GUARD,
348
/* A reference temporary. This has one subtree, the name for which
349
this is a temporary. */
350
DEMANGLE_COMPONENT_REFTEMP,
351
/* A standard substitution. This holds the name of the
353
DEMANGLE_COMPONENT_SUB_STD,
354
/* The restrict qualifier. The one subtree is the type which is
356
DEMANGLE_COMPONENT_RESTRICT,
357
/* The volatile qualifier. The one subtree is the type which is
359
DEMANGLE_COMPONENT_VOLATILE,
360
/* The const qualifier. The one subtree is the type which is being
362
DEMANGLE_COMPONENT_CONST,
363
/* The restrict qualifier modifying a member function. The one
364
subtree is the type which is being qualified. */
365
DEMANGLE_COMPONENT_RESTRICT_THIS,
366
/* The volatile qualifier modifying a member function. The one
367
subtree is the type which is being qualified. */
368
DEMANGLE_COMPONENT_VOLATILE_THIS,
369
/* The const qualifier modifying a member function. The one subtree
370
is the type which is being qualified. */
371
DEMANGLE_COMPONENT_CONST_THIS,
372
/* A vendor qualifier. The left subtree is the type which is being
373
qualified, and the right subtree is the name of the
375
DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
376
/* A pointer. The one subtree is the type which is being pointed
378
DEMANGLE_COMPONENT_POINTER,
379
/* A reference. The one subtree is the type which is being
381
DEMANGLE_COMPONENT_REFERENCE,
382
/* A complex type. The one subtree is the base type. */
383
DEMANGLE_COMPONENT_COMPLEX,
384
/* An imaginary type. The one subtree is the base type. */
385
DEMANGLE_COMPONENT_IMAGINARY,
386
/* A builtin type. This holds the builtin type information. */
387
DEMANGLE_COMPONENT_BUILTIN_TYPE,
388
/* A vendor's builtin type. This holds the name of the type. */
389
DEMANGLE_COMPONENT_VENDOR_TYPE,
390
/* A function type. The left subtree is the return type. The right
391
subtree is a list of ARGLIST nodes. Either or both may be
393
DEMANGLE_COMPONENT_FUNCTION_TYPE,
394
/* An array type. The left subtree is the dimension, which may be
395
NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
396
expression. The right subtree is the element type. */
397
DEMANGLE_COMPONENT_ARRAY_TYPE,
398
/* A pointer to member type. The left subtree is the class type,
399
and the right subtree is the member type. CV-qualifiers appear
401
DEMANGLE_COMPONENT_PTRMEM_TYPE,
402
/* An argument list. The left subtree is the current argument, and
403
the right subtree is either NULL or another ARGLIST node. */
404
DEMANGLE_COMPONENT_ARGLIST,
405
/* A template argument list. The left subtree is the current
406
template argument, and the right subtree is either NULL or
407
another TEMPLATE_ARGLIST node. */
408
DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
409
/* An operator. This holds information about a standard
411
DEMANGLE_COMPONENT_OPERATOR,
412
/* An extended operator. This holds the number of arguments, and
413
the name of the extended operator. */
414
DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
415
/* A typecast, represented as a unary operator. The one subtree is
416
the type to which the argument should be cast. */
417
DEMANGLE_COMPONENT_CAST,
418
/* A unary expression. The left subtree is the operator, and the
419
right subtree is the single argument. */
420
DEMANGLE_COMPONENT_UNARY,
421
/* A binary expression. The left subtree is the operator, and the
422
right subtree is a BINARY_ARGS. */
423
DEMANGLE_COMPONENT_BINARY,
424
/* Arguments to a binary expression. The left subtree is the first
425
argument, and the right subtree is the second argument. */
426
DEMANGLE_COMPONENT_BINARY_ARGS,
427
/* A trinary expression. The left subtree is the operator, and the
428
right subtree is a TRINARY_ARG1. */
429
DEMANGLE_COMPONENT_TRINARY,
430
/* Arguments to a trinary expression. The left subtree is the first
431
argument, and the right subtree is a TRINARY_ARG2. */
432
DEMANGLE_COMPONENT_TRINARY_ARG1,
433
/* More arguments to a trinary expression. The left subtree is the
434
second argument, and the right subtree is the third argument. */
435
DEMANGLE_COMPONENT_TRINARY_ARG2,
436
/* A literal. The left subtree is the type, and the right subtree
437
is the value, represented as a DEMANGLE_COMPONENT_NAME. */
438
DEMANGLE_COMPONENT_LITERAL,
439
/* A negative literal. Like LITERAL, but the value is negated.
440
This is a minor hack: the NAME used for LITERAL points directly
441
to the mangled string, but since negative numbers are mangled
442
using 'n' instead of '-', we want a way to indicate a negative
443
number which involves neither modifying the mangled string nor
444
allocating a new copy of the literal in memory. */
445
DEMANGLE_COMPONENT_LITERAL_NEG
448
/* Types which are only used internally. */
450
struct demangle_operator_info;
451
struct demangle_builtin_type_info;
453
/* A node in the tree representation is an instance of a struct
454
demangle_component. Note that the field names of the struct are
455
not well protected against macros defined by the file including
456
this one. We can fix this if it ever becomes a problem. */
458
struct demangle_component
460
/* The type of this component. */
461
enum demangle_component_type type;
465
/* For DEMANGLE_COMPONENT_NAME. */
468
/* A pointer to the name (which need not NULL terminated) and
474
/* For DEMANGLE_COMPONENT_OPERATOR. */
478
const struct demangle_operator_info *op;
481
/* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
484
/* Number of arguments. */
487
struct demangle_component *name;
488
} s_extended_operator;
490
/* For DEMANGLE_COMPONENT_CTOR. */
493
/* Kind of constructor. */
494
enum gnu_v3_ctor_kinds kind;
496
struct demangle_component *name;
499
/* For DEMANGLE_COMPONENT_DTOR. */
502
/* Kind of destructor. */
503
enum gnu_v3_dtor_kinds kind;
505
struct demangle_component *name;
508
/* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
512
const struct demangle_builtin_type_info *type;
515
/* For DEMANGLE_COMPONENT_SUB_STD. */
518
/* Standard substitution string. */
520
/* Length of string. */
524
/* For DEMANGLE_COMPONENT_TEMPLATE_PARAM. */
527
/* Template parameter index. */
531
/* For other types. */
534
/* Left (or only) subtree. */
535
struct demangle_component *left;
537
struct demangle_component *right;
543
/* People building mangled trees are expected to allocate instances of
544
struct demangle_component themselves. They can then call one of
545
the following functions to fill them in. */
547
/* Fill in most component types with a left subtree and a right
548
subtree. Returns non-zero on success, zero on failure, such as an
549
unrecognized or inappropriate component type. */
552
cplus_demangle_fill_component PARAMS ((struct demangle_component *fill,
553
enum demangle_component_type,
554
struct demangle_component *left,
555
struct demangle_component *right));
557
/* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
558
zero for bad arguments. */
561
cplus_demangle_fill_name PARAMS ((struct demangle_component *fill,
564
/* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
565
builtin type (e.g., "int", etc.). Returns non-zero on success,
566
zero if the type is not recognized. */
569
cplus_demangle_fill_builtin_type PARAMS ((struct demangle_component *fill,
570
const char *type_name));
572
/* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
573
operator and the number of arguments which it takes (the latter is
574
used to disambiguate operators which can be both binary and unary,
575
such as '-'). Returns non-zero on success, zero if the operator is
579
cplus_demangle_fill_operator PARAMS ((struct demangle_component *fill,
580
const char *opname, int args));
582
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
583
number of arguments and the name. Returns non-zero on success,
584
zero for bad arguments. */
587
cplus_demangle_fill_extended_operator PARAMS ((struct demangle_component *fill,
589
struct demangle_component *nm));
591
/* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
592
zero for bad arguments. */
595
cplus_demangle_fill_ctor PARAMS ((struct demangle_component *fill,
596
enum gnu_v3_ctor_kinds kind,
597
struct demangle_component *name));
599
/* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
600
zero for bad arguments. */
603
cplus_demangle_fill_dtor PARAMS ((struct demangle_component *fill,
604
enum gnu_v3_dtor_kinds kind,
605
struct demangle_component *name));
607
/* This function translates a mangled name into a struct
608
demangle_component tree. The first argument is the mangled name.
609
The second argument is DMGL_* options. This returns a pointer to a
610
tree on success, or NULL on failure. On success, the third
611
argument is set to a block of memory allocated by malloc. This
612
block should be passed to free when the tree is no longer
615
extern struct demangle_component *
616
cplus_demangle_v3_components PARAMS ((const char *mangled,
620
/* This function takes a struct demangle_component tree and returns
621
the corresponding demangled string. The first argument is DMGL_*
622
options. The second is the tree to demangle. The third is a guess
623
at the length of the demangled string, used to initially allocate
624
the return buffer. The fourth is a pointer to a size_t. On
625
success, this function returns a buffer allocated by malloc(), and
626
sets the size_t pointed to by the fourth argument to the size of
627
the allocated buffer (not the length of the returned string). On
628
failure, this function returns NULL, and sets the size_t pointed to
629
by the fourth argument to 0 for an invalid tree, or to 1 for a
630
memory allocation error. */
633
cplus_demangle_print PARAMS ((int options,
634
const struct demangle_component *tree,
635
int estimated_length,
636
size_t *p_allocated_size));
640
#endif /* __cplusplus */
642
#endif /* DEMANGLE_H */
645
/* V3 ABI demangling entry points, defined in cp-demangle.c. */
646
static char* cplus_demangle_v3 PARAMS ((const char* mangled, int options));
648
static char* java_demangle_v3 PARAMS ((const char* mangled));
650
/* Internal demangler interface for g++ V3 ABI.
651
Copyright (C) 2003, 2004 Free Software Foundation, Inc.
652
Written by Ian Lance Taylor <ian@wasabisystems.com>.
654
This file is part of the libiberty library, which is part of GCC.
656
This file is free software; you can redistribute it and/or modify
657
it under the terms of the GNU General Public License as published by
658
the Free Software Foundation; either version 2 of the License, or
659
(at your option) any later version.
661
In addition to the permissions in the GNU General Public License, the
662
Free Software Foundation gives you unlimited permission to link the
663
compiled version of this file into combinations with other programs,
664
and to distribute those combinations without any restriction coming
665
from the use of this file. (The General Public License restrictions
666
do apply in other respects; for example, they cover modification of
667
the file, and distribution when not linked into a combined
670
This program is distributed in the hope that it will be useful,
671
but WITHOUT ANY WARRANTY; without even the implied warranty of
672
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
673
GNU General Public License for more details.
675
You should have received a copy of the GNU General Public License
676
along with this program; if not, write to the Free Software
677
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
680
/* This file provides some definitions shared by cp-demangle.c and
681
cp-demint.c. It should not be included by any other files. */
683
/* Information we keep for operators. */
685
struct demangle_operator_info
691
/* Length of real name. */
693
/* Number of arguments. */
697
/* How to print the value of a builtin type. */
699
enum d_builtin_type_print
701
/* Print as (type)val. */
703
/* Print as integer. */
705
/* Print as unsigned integer, with trailing "u". */
707
/* Print as long, with trailing "l". */
709
/* Print as unsigned long, with trailing "ul". */
710
D_PRINT_UNSIGNED_LONG,
711
/* Print as long long, with trailing "ll". */
713
/* Print as unsigned long long, with trailing "ull". */
714
D_PRINT_UNSIGNED_LONG_LONG,
717
/* Print as float--put value in square brackets. */
719
/* Print in usual way, but here to detect void. */
723
/* Information we keep for a builtin type. */
725
struct demangle_builtin_type_info
729
/* Length of type name. */
731
/* Type name when using Java. */
732
const char *java_name;
733
/* Length of java name. */
735
/* How to print a value of this type. */
736
enum d_builtin_type_print print;
739
/* The information structure we pass around. */
743
/* The string we are demangling. */
745
/* The end of the string we are demangling. */
747
/* The options passed to the demangler. */
749
/* The next character in the string to consider. */
751
/* The array of components. */
752
struct demangle_component *comps;
753
/* The index of the next available component. */
755
/* The number of available component structures. */
757
/* The array of substitutions. */
758
struct demangle_component **subs;
759
/* The index of the next substitution. */
761
/* The number of available entries in the subs array. */
763
/* The number of substitutions which we actually made from the subs
764
array, plus the number of template parameter references we
767
/* The last name we saw, for constructors and destructors. */
768
struct demangle_component *last_name;
769
/* A running total of the length of large expansions from the
770
mangled name to the demangled name, such as standard
771
substitutions and builtin types. */
775
#define d_peek_char(di) (*((di)->n))
776
#define d_peek_next_char(di) ((di)->n[1])
777
#define d_advance(di, i) ((di)->n += (i))
778
#define d_next_char(di) (*((di)->n++))
779
#define d_str(di) ((di)->n)
781
/* Functions and arrays in cp-demangle.c which are referenced by
782
functions in cp-demint.c. */
783
#define CP_STATIC_IF_GLIBCPP_V3 static
785
#define D_BUILTIN_TYPE_COUNT (26)
788
static struct demangle_component *
789
cplus_demangle_mangled_name PARAMS ((struct d_info *, int));
793
static struct demangle_component *
794
cplus_demangle_type PARAMS ((struct d_info *));
798
cplus_demangle_init_info PARAMS ((const char *, int, size_t, struct d_info *));
801
/* cp-demangle.c needs to define this a little differently */
802
#undef CP_STATIC_IF_GLIBCPP_V3
804
#define IN_GLIBCPP_V3
806
/* If IN_GLIBCPP_V3 is defined, some functions are made static. We
807
also rename them via #define to avoid compiler errors when the
808
static definition conflicts with the extern declaration in a header
812
#define CP_STATIC_IF_GLIBCPP_V3 static
814
#define cplus_demangle_fill_name d_fill_name
816
d_fill_name PARAMS ((struct demangle_component *, const char *, int));
818
#define cplus_demangle_fill_extended_operator d_fill_extended_operator
820
d_fill_extended_operator PARAMS ((struct demangle_component *, int,
821
struct demangle_component *));
823
#define cplus_demangle_fill_ctor d_fill_ctor
825
d_fill_ctor PARAMS ((struct demangle_component *, enum gnu_v3_ctor_kinds,
826
struct demangle_component *));
828
#define cplus_demangle_fill_dtor d_fill_dtor
830
d_fill_dtor PARAMS ((struct demangle_component *, enum gnu_v3_dtor_kinds,
831
struct demangle_component *));
833
#define cplus_demangle_mangled_name d_mangled_name
834
static struct demangle_component *
835
d_mangled_name PARAMS ((struct d_info *, int));
837
#define cplus_demangle_type d_type
838
static struct demangle_component *
839
d_type PARAMS ((struct d_info *));
841
#define cplus_demangle_print d_print
843
d_print PARAMS ((int, const struct demangle_component *, int, size_t *));
845
#define cplus_demangle_init_info d_init_info
847
d_init_info PARAMS ((const char *, int, size_t, struct d_info *));
849
#else /* ! defined(IN_GLIBCPP_V3) */
850
#define CP_STATIC_IF_GLIBCPP_V3
851
#endif /* ! defined(IN_GLIBCPP_V3) */
853
/* See if the compiler supports dynamic arrays. */
856
#define CP_DYNAMIC_ARRAYS
859
#ifdef __STDC_VERSION__
860
#if __STDC_VERSION__ >= 199901L
861
#define CP_DYNAMIC_ARRAYS
862
#endif /* __STDC__VERSION >= 199901L */
863
#endif /* defined (__STDC_VERSION__) */
864
#endif /* defined (__STDC__) */
865
#endif /* ! defined (__GNUC__) */
867
/* We avoid pulling in the ctype tables, to prevent pulling in
868
additional unresolved symbols when this code is used in a library.
869
FIXME: Is this really a valid reason? This comes from the original
872
As of this writing this file has the following undefined references
873
when compiled with -DIN_GLIBCPP_V3: malloc, realloc, free, memcpy,
874
strcpy, strcat, strlen. */
876
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
877
#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
878
#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
880
/* The prefix prepended by GCC to an identifier represnting the
881
anonymous namespace. */
882
#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
883
#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
884
(sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
886
/* Information we keep for the standard substitutions. */
888
struct d_standard_sub_info
890
/* The code for this substitution. */
892
/* The simple string it expands to. */
893
const char *simple_expansion;
894
/* The length of the simple expansion. */
896
/* The results of a full, verbose, expansion. This is used when
897
qualifying a constructor/destructor, or when in verbose mode. */
898
const char *full_expansion;
899
/* The length of the full expansion. */
901
/* What to set the last_name field of d_info to; NULL if we should
902
not set it. This is only relevant when qualifying a
903
constructor/destructor. */
904
const char *set_last_name;
905
/* The length of set_last_name. */
906
int set_last_name_len;
909
/* Accessors for subtrees of struct demangle_component. */
911
#define d_left(dc) ((dc)->u.s_binary.left)
912
#define d_right(dc) ((dc)->u.s_binary.right)
914
/* A list of templates. This is used while printing. */
916
struct d_print_template
918
/* Next template on the list. */
919
struct d_print_template *next;
921
const struct demangle_component *template;
924
/* A list of type modifiers. This is used while printing. */
928
/* Next modifier on the list. These are in the reverse of the order
929
in which they appeared in the mangled string. */
930
struct d_print_mod *next;
932
const struct demangle_component *mod;
933
/* Whether this modifier was printed. */
935
/* The list of templates which applies to this modifier. */
936
struct d_print_template *templates;
939
/* We use this structure to hold information during printing. */
943
/* The options passed to the demangler. */
945
/* Buffer holding the result. */
947
/* Current length of data in buffer. */
949
/* Allocated size of buffer. */
951
/* The current list of templates, if any. */
952
struct d_print_template *templates;
953
/* The current list of modifiers (e.g., pointer, reference, etc.),
955
struct d_print_mod *modifiers;
956
/* Set to 1 if we had a memory allocation failure. */
957
int allocation_failure;
960
#define d_print_saw_error(dpi) ((dpi)->buf == NULL)
962
#define d_append_char(dpi, c) \
965
if ((dpi)->buf != NULL && (dpi)->len < (dpi)->alc) \
966
(dpi)->buf[(dpi)->len++] = (c); \
968
d_print_append_char ((dpi), (c)); \
972
#define d_append_buffer(dpi, s, l) \
975
if ((dpi)->buf != NULL && (dpi)->len + (l) <= (dpi)->alc) \
977
memcpy ((dpi)->buf + (dpi)->len, (s), (l)); \
981
d_print_append_buffer ((dpi), (s), (l)); \
985
#define d_append_string_constant(dpi, s) \
986
d_append_buffer (dpi, (s), sizeof (s) - 1)
988
#define d_last_char(dpi) \
989
((dpi)->buf == NULL || (dpi)->len == 0 ? '\0' : (dpi)->buf[(dpi)->len - 1])
991
#ifdef CP_DEMANGLE_DEBUG
993
d_dump PARAMS ((struct demangle_component *, int));
996
static struct demangle_component *
997
d_make_empty PARAMS ((struct d_info *));
999
static struct demangle_component *
1000
d_make_comp PARAMS ((struct d_info *, enum demangle_component_type,
1001
struct demangle_component *,
1002
struct demangle_component *));
1004
static struct demangle_component *
1005
d_make_name PARAMS ((struct d_info *, const char *, int));
1007
static struct demangle_component *
1008
d_make_builtin_type PARAMS ((struct d_info *,
1009
const struct demangle_builtin_type_info *));
1011
static struct demangle_component *
1012
d_make_operator PARAMS ((struct d_info *,
1013
const struct demangle_operator_info *));
1015
static struct demangle_component *
1016
d_make_extended_operator PARAMS ((struct d_info *, int,
1017
struct demangle_component *));
1019
static struct demangle_component *
1020
d_make_ctor PARAMS ((struct d_info *, enum gnu_v3_ctor_kinds,
1021
struct demangle_component *));
1023
static struct demangle_component *
1024
d_make_dtor PARAMS ((struct d_info *, enum gnu_v3_dtor_kinds,
1025
struct demangle_component *));
1027
static struct demangle_component *
1028
d_make_template_param PARAMS ((struct d_info *, long));
1030
static struct demangle_component *
1031
d_make_sub PARAMS ((struct d_info *, const char *, int));
1034
has_return_type PARAMS ((struct demangle_component *));
1037
is_ctor_dtor_or_conversion PARAMS ((struct demangle_component *));
1039
static struct demangle_component *
1040
d_encoding PARAMS ((struct d_info *, int));
1042
static struct demangle_component *
1043
d_name PARAMS ((struct d_info *));
1045
static struct demangle_component *
1046
d_nested_name PARAMS ((struct d_info *));
1048
static struct demangle_component *
1049
d_prefix PARAMS ((struct d_info *));
1051
static struct demangle_component *
1052
d_unqualified_name PARAMS ((struct d_info *));
1054
static struct demangle_component *
1055
d_source_name PARAMS ((struct d_info *));
1058
d_number PARAMS ((struct d_info *));
1060
static struct demangle_component *
1061
d_identifier PARAMS ((struct d_info *, int));
1063
static struct demangle_component *
1064
d_operator_name PARAMS ((struct d_info *));
1066
static struct demangle_component *
1067
d_special_name PARAMS ((struct d_info *));
1070
d_call_offset PARAMS ((struct d_info *, int));
1072
static struct demangle_component *
1073
d_ctor_dtor_name PARAMS ((struct d_info *));
1075
static struct demangle_component **
1076
d_cv_qualifiers PARAMS ((struct d_info *, struct demangle_component **, int));
1078
static struct demangle_component *
1079
d_function_type PARAMS ((struct d_info *));
1081
static struct demangle_component *
1082
d_bare_function_type PARAMS ((struct d_info *, int));
1084
static struct demangle_component *
1085
d_class_enum_type PARAMS ((struct d_info *));
1087
static struct demangle_component *
1088
d_array_type PARAMS ((struct d_info *));
1090
static struct demangle_component *
1091
d_pointer_to_member_type PARAMS ((struct d_info *));
1093
static struct demangle_component *
1094
d_template_param PARAMS ((struct d_info *));
1096
static struct demangle_component *
1097
d_template_args PARAMS ((struct d_info *));
1099
static struct demangle_component *
1100
d_template_arg PARAMS ((struct d_info *));
1102
static struct demangle_component *
1103
d_expression PARAMS ((struct d_info *));
1105
static struct demangle_component *
1106
d_expr_primary PARAMS ((struct d_info *));
1108
static struct demangle_component *
1109
d_local_name PARAMS ((struct d_info *));
1112
d_discriminator PARAMS ((struct d_info *));
1115
d_add_substitution PARAMS ((struct d_info *, struct demangle_component *));
1117
static struct demangle_component *
1118
d_substitution PARAMS ((struct d_info *, int));
1121
d_print_resize PARAMS ((struct d_print_info *, size_t));
1124
d_print_append_char PARAMS ((struct d_print_info *, int));
1127
d_print_append_buffer PARAMS ((struct d_print_info *, const char *, size_t));
1130
d_print_error PARAMS ((struct d_print_info *));
1133
d_print_comp PARAMS ((struct d_print_info *,
1134
const struct demangle_component *));
1137
d_print_java_identifier PARAMS ((struct d_print_info *, const char *, int));
1140
d_print_mod_list PARAMS ((struct d_print_info *, struct d_print_mod *, int));
1143
d_print_mod PARAMS ((struct d_print_info *,
1144
const struct demangle_component *));
1147
d_print_function_type PARAMS ((struct d_print_info *,
1148
const struct demangle_component *,
1149
struct d_print_mod *));
1152
d_print_array_type PARAMS ((struct d_print_info *,
1153
const struct demangle_component *,
1154
struct d_print_mod *));
1157
d_print_expr_op PARAMS ((struct d_print_info *,
1158
const struct demangle_component *));
1161
d_print_cast PARAMS ((struct d_print_info *,
1162
const struct demangle_component *));
1165
d_demangle PARAMS ((const char *, int, size_t *));
1167
#ifdef CP_DEMANGLE_DEBUG
1171
struct demangle_component *dc;
1179
for (i = 0; i < indent; ++i)
1184
case DEMANGLE_COMPONENT_NAME:
1185
printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
1187
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
1188
printf ("template parameter %ld\n", dc->u.s_number.number);
1190
case DEMANGLE_COMPONENT_CTOR:
1191
printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
1192
d_dump (dc->u.s_ctor.name, indent + 2);
1194
case DEMANGLE_COMPONENT_DTOR:
1195
printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
1196
d_dump (dc->u.s_dtor.name, indent + 2);
1198
case DEMANGLE_COMPONENT_SUB_STD:
1199
printf ("standard substitution %s\n", dc->u.s_string.string);
1201
case DEMANGLE_COMPONENT_BUILTIN_TYPE:
1202
printf ("builtin type %s\n", dc->u.s_builtin.type->name);
1204
case DEMANGLE_COMPONENT_OPERATOR:
1205
printf ("operator %s\n", dc->u.s_operator.op->name);
1207
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
1208
printf ("extended operator with %d args\n",
1209
dc->u.s_extended_operator.args);
1210
d_dump (dc->u.s_extended_operator.name, indent + 2);
1213
case DEMANGLE_COMPONENT_QUAL_NAME:
1214
printf ("qualified name\n");
1216
case DEMANGLE_COMPONENT_LOCAL_NAME:
1217
printf ("local name\n");
1219
case DEMANGLE_COMPONENT_TYPED_NAME:
1220
printf ("typed name\n");
1222
case DEMANGLE_COMPONENT_TEMPLATE:
1223
printf ("template\n");
1225
case DEMANGLE_COMPONENT_VTABLE:
1226
printf ("vtable\n");
1228
case DEMANGLE_COMPONENT_VTT:
1231
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
1232
printf ("construction vtable\n");
1234
case DEMANGLE_COMPONENT_TYPEINFO:
1235
printf ("typeinfo\n");
1237
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
1238
printf ("typeinfo name\n");
1240
case DEMANGLE_COMPONENT_TYPEINFO_FN:
1241
printf ("typeinfo function\n");
1243
case DEMANGLE_COMPONENT_THUNK:
1246
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
1247
printf ("virtual thunk\n");
1249
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
1250
printf ("covariant thunk\n");
1252
case DEMANGLE_COMPONENT_JAVA_CLASS:
1253
printf ("java class\n");
1255
case DEMANGLE_COMPONENT_GUARD:
1258
case DEMANGLE_COMPONENT_REFTEMP:
1259
printf ("reference temporary\n");
1261
case DEMANGLE_COMPONENT_RESTRICT:
1262
printf ("restrict\n");
1264
case DEMANGLE_COMPONENT_VOLATILE:
1265
printf ("volatile\n");
1267
case DEMANGLE_COMPONENT_CONST:
1270
case DEMANGLE_COMPONENT_RESTRICT_THIS:
1271
printf ("restrict this\n");
1273
case DEMANGLE_COMPONENT_VOLATILE_THIS:
1274
printf ("volatile this\n");
1276
case DEMANGLE_COMPONENT_CONST_THIS:
1277
printf ("const this\n");
1279
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
1280
printf ("vendor type qualifier\n");
1282
case DEMANGLE_COMPONENT_POINTER:
1283
printf ("pointer\n");
1285
case DEMANGLE_COMPONENT_REFERENCE:
1286
printf ("reference\n");
1288
case DEMANGLE_COMPONENT_COMPLEX:
1289
printf ("complex\n");
1291
case DEMANGLE_COMPONENT_IMAGINARY:
1292
printf ("imaginary\n");
1294
case DEMANGLE_COMPONENT_VENDOR_TYPE:
1295
printf ("vendor type\n");
1297
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
1298
printf ("function type\n");
1300
case DEMANGLE_COMPONENT_ARRAY_TYPE:
1301
printf ("array type\n");
1303
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
1304
printf ("pointer to member type\n");
1306
case DEMANGLE_COMPONENT_ARGLIST:
1307
printf ("argument list\n");
1309
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
1310
printf ("template argument list\n");
1312
case DEMANGLE_COMPONENT_CAST:
1315
case DEMANGLE_COMPONENT_UNARY:
1316
printf ("unary operator\n");
1318
case DEMANGLE_COMPONENT_BINARY:
1319
printf ("binary operator\n");
1321
case DEMANGLE_COMPONENT_BINARY_ARGS:
1322
printf ("binary operator arguments\n");
1324
case DEMANGLE_COMPONENT_TRINARY:
1325
printf ("trinary operator\n");
1327
case DEMANGLE_COMPONENT_TRINARY_ARG1:
1328
printf ("trinary operator arguments 1\n");
1330
case DEMANGLE_COMPONENT_TRINARY_ARG2:
1331
printf ("trinary operator arguments 1\n");
1333
case DEMANGLE_COMPONENT_LITERAL:
1334
printf ("literal\n");
1336
case DEMANGLE_COMPONENT_LITERAL_NEG:
1337
printf ("negative literal\n");
1341
d_dump (d_left (dc), indent + 2);
1342
d_dump (d_right (dc), indent + 2);
1345
#endif /* CP_DEMANGLE_DEBUG */
1347
/* Fill in a DEMANGLE_COMPONENT_NAME. */
1349
CP_STATIC_IF_GLIBCPP_V3
1351
cplus_demangle_fill_name (p, s, len)
1352
struct demangle_component *p;
1356
if (p == NULL || s == NULL || len == 0)
1358
p->type = DEMANGLE_COMPONENT_NAME;
1360
p->u.s_name.len = len;
1364
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
1366
CP_STATIC_IF_GLIBCPP_V3
1368
cplus_demangle_fill_extended_operator (p, args, name)
1369
struct demangle_component *p;
1371
struct demangle_component *name;
1373
if (p == NULL || args < 0 || name == NULL)
1375
p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
1376
p->u.s_extended_operator.args = args;
1377
p->u.s_extended_operator.name = name;
1381
/* Fill in a DEMANGLE_COMPONENT_CTOR. */
1383
CP_STATIC_IF_GLIBCPP_V3
1385
cplus_demangle_fill_ctor (p, kind, name)
1386
struct demangle_component *p;
1387
enum gnu_v3_ctor_kinds kind;
1388
struct demangle_component *name;
1392
|| (kind < gnu_v3_complete_object_ctor
1393
&& kind > gnu_v3_complete_object_allocating_ctor))
1395
p->type = DEMANGLE_COMPONENT_CTOR;
1396
p->u.s_ctor.kind = kind;
1397
p->u.s_ctor.name = name;
1401
/* Fill in a DEMANGLE_COMPONENT_DTOR. */
1403
CP_STATIC_IF_GLIBCPP_V3
1405
cplus_demangle_fill_dtor (p, kind, name)
1406
struct demangle_component *p;
1407
enum gnu_v3_dtor_kinds kind;
1408
struct demangle_component *name;
1412
|| (kind < gnu_v3_deleting_dtor
1413
&& kind > gnu_v3_base_object_dtor))
1415
p->type = DEMANGLE_COMPONENT_DTOR;
1416
p->u.s_dtor.kind = kind;
1417
p->u.s_dtor.name = name;
1421
/* Add a new component. */
1423
static struct demangle_component *
1427
struct demangle_component *p;
1429
if (di->next_comp >= di->num_comps)
1431
p = &di->comps[di->next_comp];
1436
/* Add a new generic component. */
1438
static struct demangle_component *
1439
d_make_comp (di, type, left, right)
1441
enum demangle_component_type type;
1442
struct demangle_component *left;
1443
struct demangle_component *right;
1445
struct demangle_component *p;
1447
/* We check for errors here. A typical error would be a NULL return
1448
from a subroutine. We catch those here, and return NULL
1452
/* These types require two parameters. */
1453
case DEMANGLE_COMPONENT_QUAL_NAME:
1454
case DEMANGLE_COMPONENT_LOCAL_NAME:
1455
case DEMANGLE_COMPONENT_TYPED_NAME:
1456
case DEMANGLE_COMPONENT_TEMPLATE:
1457
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
1458
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
1459
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
1460
case DEMANGLE_COMPONENT_UNARY:
1461
case DEMANGLE_COMPONENT_BINARY:
1462
case DEMANGLE_COMPONENT_BINARY_ARGS:
1463
case DEMANGLE_COMPONENT_TRINARY:
1464
case DEMANGLE_COMPONENT_TRINARY_ARG1:
1465
case DEMANGLE_COMPONENT_TRINARY_ARG2:
1466
case DEMANGLE_COMPONENT_LITERAL:
1467
case DEMANGLE_COMPONENT_LITERAL_NEG:
1468
if (left == NULL || right == NULL)
1472
/* These types only require one parameter. */
1473
case DEMANGLE_COMPONENT_VTABLE:
1474
case DEMANGLE_COMPONENT_VTT:
1475
case DEMANGLE_COMPONENT_TYPEINFO:
1476
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
1477
case DEMANGLE_COMPONENT_TYPEINFO_FN:
1478
case DEMANGLE_COMPONENT_THUNK:
1479
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
1480
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
1481
case DEMANGLE_COMPONENT_JAVA_CLASS:
1482
case DEMANGLE_COMPONENT_GUARD:
1483
case DEMANGLE_COMPONENT_REFTEMP:
1484
case DEMANGLE_COMPONENT_POINTER:
1485
case DEMANGLE_COMPONENT_REFERENCE:
1486
case DEMANGLE_COMPONENT_COMPLEX:
1487
case DEMANGLE_COMPONENT_IMAGINARY:
1488
case DEMANGLE_COMPONENT_VENDOR_TYPE:
1489
case DEMANGLE_COMPONENT_ARGLIST:
1490
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
1491
case DEMANGLE_COMPONENT_CAST:
1496
/* This needs a right parameter, but the left parameter can be
1498
case DEMANGLE_COMPONENT_ARRAY_TYPE:
1503
/* These are allowed to have no parameters--in some cases they
1504
will be filled in later. */
1505
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
1506
case DEMANGLE_COMPONENT_RESTRICT:
1507
case DEMANGLE_COMPONENT_VOLATILE:
1508
case DEMANGLE_COMPONENT_CONST:
1509
case DEMANGLE_COMPONENT_RESTRICT_THIS:
1510
case DEMANGLE_COMPONENT_VOLATILE_THIS:
1511
case DEMANGLE_COMPONENT_CONST_THIS:
1514
/* Other types should not be seen here. */
1519
p = d_make_empty (di);
1523
p->u.s_binary.left = left;
1524
p->u.s_binary.right = right;
1529
/* Add a new name component. */
1531
static struct demangle_component *
1532
d_make_name (di, s, len)
1537
struct demangle_component *p;
1539
p = d_make_empty (di);
1540
if (! cplus_demangle_fill_name (p, s, len))
1545
/* Add a new builtin type component. */
1547
static struct demangle_component *
1548
d_make_builtin_type (di, type)
1550
const struct demangle_builtin_type_info *type;
1552
struct demangle_component *p;
1556
p = d_make_empty (di);
1559
p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
1560
p->u.s_builtin.type = type;
1565
/* Add a new operator component. */
1567
static struct demangle_component *
1568
d_make_operator (di, op)
1570
const struct demangle_operator_info *op;
1572
struct demangle_component *p;
1574
p = d_make_empty (di);
1577
p->type = DEMANGLE_COMPONENT_OPERATOR;
1578
p->u.s_operator.op = op;
1583
/* Add a new extended operator component. */
1585
static struct demangle_component *
1586
d_make_extended_operator (di, args, name)
1589
struct demangle_component *name;
1591
struct demangle_component *p;
1593
p = d_make_empty (di);
1594
if (! cplus_demangle_fill_extended_operator (p, args, name))
1599
/* Add a new constructor component. */
1601
static struct demangle_component *
1602
d_make_ctor (di, kind, name)
1604
enum gnu_v3_ctor_kinds kind;
1605
struct demangle_component *name;
1607
struct demangle_component *p;
1609
p = d_make_empty (di);
1610
if (! cplus_demangle_fill_ctor (p, kind, name))
1615
/* Add a new destructor component. */
1617
static struct demangle_component *
1618
d_make_dtor (di, kind, name)
1620
enum gnu_v3_dtor_kinds kind;
1621
struct demangle_component *name;
1623
struct demangle_component *p;
1625
p = d_make_empty (di);
1626
if (! cplus_demangle_fill_dtor (p, kind, name))
1631
/* Add a new template parameter. */
1633
static struct demangle_component *
1634
d_make_template_param (di, i)
1638
struct demangle_component *p;
1640
p = d_make_empty (di);
1643
p->type = DEMANGLE_COMPONENT_TEMPLATE_PARAM;
1644
p->u.s_number.number = i;
1649
/* Add a new standard substitution component. */
1651
static struct demangle_component *
1652
d_make_sub (di, name, len)
1657
struct demangle_component *p;
1659
p = d_make_empty (di);
1662
p->type = DEMANGLE_COMPONENT_SUB_STD;
1663
p->u.s_string.string = name;
1664
p->u.s_string.len = len;
1669
/* <mangled-name> ::= _Z <encoding>
1671
TOP_LEVEL is non-zero when called at the top level. */
1673
CP_STATIC_IF_GLIBCPP_V3
1674
struct demangle_component *
1675
cplus_demangle_mangled_name (di, top_level)
1679
if (d_next_char (di) != '_')
1681
if (d_next_char (di) != 'Z')
1683
return d_encoding (di, top_level);
1686
/* Return whether a function should have a return type. The argument
1687
is the function name, which may be qualified in various ways. The
1688
rules are that template functions have return types with some
1689
exceptions, function types which are not part of a function name
1690
mangling have return types with some exceptions, and non-template
1691
function names do not have return types. The exceptions are that
1692
constructors, destructors, and conversion operators do not have
1696
has_return_type (dc)
1697
struct demangle_component *dc;
1705
case DEMANGLE_COMPONENT_TEMPLATE:
1706
return ! is_ctor_dtor_or_conversion (d_left (dc));
1707
case DEMANGLE_COMPONENT_RESTRICT_THIS:
1708
case DEMANGLE_COMPONENT_VOLATILE_THIS:
1709
case DEMANGLE_COMPONENT_CONST_THIS:
1710
return has_return_type (d_left (dc));
1714
/* Return whether a name is a constructor, a destructor, or a
1715
conversion operator. */
1718
is_ctor_dtor_or_conversion (dc)
1719
struct demangle_component *dc;
1727
case DEMANGLE_COMPONENT_QUAL_NAME:
1728
case DEMANGLE_COMPONENT_LOCAL_NAME:
1729
return is_ctor_dtor_or_conversion (d_right (dc));
1730
case DEMANGLE_COMPONENT_CTOR:
1731
case DEMANGLE_COMPONENT_DTOR:
1732
case DEMANGLE_COMPONENT_CAST:
1737
/* <encoding> ::= <(function) name> <bare-function-type>
1741
TOP_LEVEL is non-zero when called at the top level, in which case
1742
if DMGL_PARAMS is not set we do not demangle the function
1743
parameters. We only set this at the top level, because otherwise
1744
we would not correctly demangle names in local scopes. */
1746
static struct demangle_component *
1747
d_encoding (di, top_level)
1751
char peek = d_peek_char (di);
1753
if (peek == 'G' || peek == 'T')
1754
return d_special_name (di);
1757
struct demangle_component *dc;
1761
if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
1763
/* Strip off any initial CV-qualifiers, as they really apply
1764
to the `this' parameter, and they were not output by the
1765
v2 demangler without DMGL_PARAMS. */
1766
while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1767
|| dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1768
|| dc->type == DEMANGLE_COMPONENT_CONST_THIS)
1771
/* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1772
there may be CV-qualifiers on its right argument which
1773
really apply here; this happens when parsing a class
1774
which is local to a function. */
1775
if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
1777
struct demangle_component *dcr;
1780
while (dcr->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1781
|| dcr->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1782
|| dcr->type == DEMANGLE_COMPONENT_CONST_THIS)
1784
dc->u.s_binary.right = dcr;
1790
peek = d_peek_char (di);
1791
if (peek == '\0' || peek == 'E')
1793
return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,
1794
d_bare_function_type (di, has_return_type (dc)));
1798
/* <name> ::= <nested-name>
1800
::= <unscoped-template-name> <template-args>
1803
<unscoped-name> ::= <unqualified-name>
1804
::= St <unqualified-name>
1806
<unscoped-template-name> ::= <unscoped-name>
1810
static struct demangle_component *
1814
char peek = d_peek_char (di);
1815
struct demangle_component *dc;
1820
return d_nested_name (di);
1823
return d_local_name (di);
1829
if (d_peek_next_char (di) != 't')
1831
dc = d_substitution (di, 0);
1837
dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
1838
d_make_name (di, "std", 3),
1839
d_unqualified_name (di));
1844
if (d_peek_char (di) != 'I')
1846
/* The grammar does not permit this case to occur if we
1847
called d_substitution() above (i.e., subst == 1). We
1848
don't bother to check. */
1852
/* This is <template-args>, which means that we just saw
1853
<unscoped-template-name>, which is a substitution
1854
candidate if we didn't just get it from a
1858
if (! d_add_substitution (di, dc))
1861
dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1862
d_template_args (di));
1869
dc = d_unqualified_name (di);
1870
if (d_peek_char (di) == 'I')
1872
/* This is <template-args>, which means that we just saw
1873
<unscoped-template-name>, which is a substitution
1875
if (! d_add_substitution (di, dc))
1877
dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1878
d_template_args (di));
1884
/* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1885
::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1888
static struct demangle_component *
1892
struct demangle_component *ret;
1893
struct demangle_component **pret;
1895
if (d_next_char (di) != 'N')
1898
pret = d_cv_qualifiers (di, &ret, 1);
1902
*pret = d_prefix (di);
1906
if (d_next_char (di) != 'E')
1912
/* <prefix> ::= <prefix> <unqualified-name>
1913
::= <template-prefix> <template-args>
1914
::= <template-param>
1918
<template-prefix> ::= <prefix> <(template) unqualified-name>
1919
::= <template-param>
1923
static struct demangle_component *
1927
struct demangle_component *ret = NULL;
1932
enum demangle_component_type comb_type;
1933
struct demangle_component *dc;
1935
peek = d_peek_char (di);
1939
/* The older code accepts a <local-name> here, but I don't see
1940
that in the grammar. The older code does not accept a
1941
<template-param> here. */
1943
comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
1949
dc = d_unqualified_name (di);
1950
else if (peek == 'S')
1951
dc = d_substitution (di, 1);
1952
else if (peek == 'I')
1956
comb_type = DEMANGLE_COMPONENT_TEMPLATE;
1957
dc = d_template_args (di);
1959
else if (peek == 'T')
1960
dc = d_template_param (di);
1961
else if (peek == 'E')
1969
ret = d_make_comp (di, comb_type, ret, dc);
1971
if (peek != 'S' && d_peek_char (di) != 'E')
1973
if (! d_add_substitution (di, ret))
1979
/* <unqualified-name> ::= <operator-name>
1980
::= <ctor-dtor-name>
1982
::= <local-source-name>
1984
<local-source-anem> ::= L <source-name><discriminator>
1987
static struct demangle_component *
1988
d_unqualified_name (di)
1993
peek = d_peek_char (di);
1994
if (IS_DIGIT (peek))
1995
return d_source_name (di);
1996
else if (IS_LOWER (peek))
1998
struct demangle_component *ret;
2000
ret = d_operator_name (di);
2001
if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
2002
di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
2005
else if (peek == 'C' || peek == 'D')
2006
return d_ctor_dtor_name (di);
2007
else if (peek == 'L')
2009
struct demangle_component * ret;
2013
ret = d_source_name (di);
2016
if (! d_discriminator (di))
2024
/* <source-name> ::= <(positive length) number> <identifier> */
2026
static struct demangle_component *
2031
struct demangle_component *ret;
2033
len = d_number (di);
2036
ret = d_identifier (di, len);
2037
di->last_name = ret;
2041
/* number ::= [n] <(non-negative decimal integer)> */
2052
peek = d_peek_char (di);
2057
peek = d_peek_char (di);
2063
if (! IS_DIGIT (peek))
2069
ret = ret * 10 + peek - '0';
2071
peek = d_peek_char (di);
2075
/* identifier ::= <(unqualified source code identifier)> */
2077
static struct demangle_component *
2078
d_identifier (di, len)
2086
if (di->send - name < len)
2089
d_advance (di, len);
2091
/* A Java mangled name may have a trailing '$' if it is a C++
2092
keyword. This '$' is not included in the length count. We just
2094
if ((di->options & DMGL_JAVA) != 0
2095
&& d_peek_char (di) == '$')
2098
/* Look for something which looks like a gcc encoding of an
2099
anonymous namespace, and replace it with a more user friendly
2101
if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2
2102
&& memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,
2103
ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)
2107
s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;
2108
if ((*s == '.' || *s == '_' || *s == '$')
2111
di->expansion -= len - sizeof "(anonymous namespace)";
2112
return d_make_name (di, "(anonymous namespace)",
2113
sizeof "(anonymous namespace)" - 1);
2117
return d_make_name (di, name, len);
2120
/* operator_name ::= many different two character encodings.
2122
::= v <digit> <source-name>
2125
#define NL(s) s, (sizeof s) - 1
2127
CP_STATIC_IF_GLIBCPP_V3
2128
const struct demangle_operator_info cplus_demangle_operators[] =
2130
{ "aN", NL ("&="), 2 },
2131
{ "aS", NL ("="), 2 },
2132
{ "aa", NL ("&&"), 2 },
2133
{ "ad", NL ("&"), 1 },
2134
{ "an", NL ("&"), 2 },
2135
{ "cl", NL ("()"), 0 },
2136
{ "cm", NL (","), 2 },
2137
{ "co", NL ("~"), 1 },
2138
{ "dV", NL ("/="), 2 },
2139
{ "da", NL ("delete[]"), 1 },
2140
{ "de", NL ("*"), 1 },
2141
{ "dl", NL ("delete"), 1 },
2142
{ "dv", NL ("/"), 2 },
2143
{ "eO", NL ("^="), 2 },
2144
{ "eo", NL ("^"), 2 },
2145
{ "eq", NL ("=="), 2 },
2146
{ "ge", NL (">="), 2 },
2147
{ "gt", NL (">"), 2 },
2148
{ "ix", NL ("[]"), 2 },
2149
{ "lS", NL ("<<="), 2 },
2150
{ "le", NL ("<="), 2 },
2151
{ "ls", NL ("<<"), 2 },
2152
{ "lt", NL ("<"), 2 },
2153
{ "mI", NL ("-="), 2 },
2154
{ "mL", NL ("*="), 2 },
2155
{ "mi", NL ("-"), 2 },
2156
{ "ml", NL ("*"), 2 },
2157
{ "mm", NL ("--"), 1 },
2158
{ "na", NL ("new[]"), 1 },
2159
{ "ne", NL ("!="), 2 },
2160
{ "ng", NL ("-"), 1 },
2161
{ "nt", NL ("!"), 1 },
2162
{ "nw", NL ("new"), 1 },
2163
{ "oR", NL ("|="), 2 },
2164
{ "oo", NL ("||"), 2 },
2165
{ "or", NL ("|"), 2 },
2166
{ "pL", NL ("+="), 2 },
2167
{ "pl", NL ("+"), 2 },
2168
{ "pm", NL ("->*"), 2 },
2169
{ "pp", NL ("++"), 1 },
2170
{ "ps", NL ("+"), 1 },
2171
{ "pt", NL ("->"), 2 },
2172
{ "qu", NL ("?"), 3 },
2173
{ "rM", NL ("%="), 2 },
2174
{ "rS", NL (">>="), 2 },
2175
{ "rm", NL ("%"), 2 },
2176
{ "rs", NL (">>"), 2 },
2177
{ "st", NL ("sizeof "), 1 },
2178
{ "sz", NL ("sizeof "), 1 },
2179
{ NULL, NULL, 0, 0 }
2182
static struct demangle_component *
2183
d_operator_name (di)
2189
c1 = d_next_char (di);
2190
c2 = d_next_char (di);
2191
if (c1 == 'v' && IS_DIGIT (c2))
2192
return d_make_extended_operator (di, c2 - '0', d_source_name (di));
2193
else if (c1 == 'c' && c2 == 'v')
2194
return d_make_comp (di, DEMANGLE_COMPONENT_CAST,
2195
cplus_demangle_type (di), NULL);
2198
/* LOW is the inclusive lower bound. */
2200
/* HIGH is the exclusive upper bound. We subtract one to ignore
2201
the sentinel at the end of the array. */
2202
int high = ((sizeof (cplus_demangle_operators)
2203
/ sizeof (cplus_demangle_operators[0]))
2209
const struct demangle_operator_info *p;
2211
i = low + (high - low) / 2;
2212
p = cplus_demangle_operators + i;
2214
if (c1 == p->code[0] && c2 == p->code[1])
2215
return d_make_operator (di, p);
2217
if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1]))
2227
/* <special-name> ::= TV <type>
2231
::= GV <(object) name>
2232
::= T <call-offset> <(base) encoding>
2233
::= Tc <call-offset> <call-offset> <(base) encoding>
2234
Also g++ extensions:
2235
::= TC <type> <(offset) number> _ <(base) type>
2241
static struct demangle_component *
2247
di->expansion += 20;
2248
c = d_next_char (di);
2251
switch (d_next_char (di))
2255
return d_make_comp (di, DEMANGLE_COMPONENT_VTABLE,
2256
cplus_demangle_type (di), NULL);
2258
di->expansion -= 10;
2259
return d_make_comp (di, DEMANGLE_COMPONENT_VTT,
2260
cplus_demangle_type (di), NULL);
2262
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO,
2263
cplus_demangle_type (di), NULL);
2265
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_NAME,
2266
cplus_demangle_type (di), NULL);
2269
if (! d_call_offset (di, 'h'))
2271
return d_make_comp (di, DEMANGLE_COMPONENT_THUNK,
2272
d_encoding (di, 0), NULL);
2275
if (! d_call_offset (di, 'v'))
2277
return d_make_comp (di, DEMANGLE_COMPONENT_VIRTUAL_THUNK,
2278
d_encoding (di, 0), NULL);
2281
if (! d_call_offset (di, '\0'))
2283
if (! d_call_offset (di, '\0'))
2285
return d_make_comp (di, DEMANGLE_COMPONENT_COVARIANT_THUNK,
2286
d_encoding (di, 0), NULL);
2290
struct demangle_component *derived_type;
2292
struct demangle_component *base_type;
2294
derived_type = cplus_demangle_type (di);
2295
offset = d_number (di);
2298
if (d_next_char (di) != '_')
2300
base_type = cplus_demangle_type (di);
2301
/* We don't display the offset. FIXME: We should display
2302
it in verbose mode. */
2304
return d_make_comp (di, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
2305
base_type, derived_type);
2309
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_FN,
2310
cplus_demangle_type (di), NULL);
2312
return d_make_comp (di, DEMANGLE_COMPONENT_JAVA_CLASS,
2313
cplus_demangle_type (di), NULL);
2321
switch (d_next_char (di))
2324
return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL);
2327
return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, d_name (di),
2338
/* <call-offset> ::= h <nv-offset> _
2341
<nv-offset> ::= <(offset) number>
2343
<v-offset> ::= <(offset) number> _ <(virtual offset) number>
2345
The C parameter, if not '\0', is a character we just read which is
2346
the start of the <call-offset>.
2348
We don't display the offset information anywhere. FIXME: We should
2349
display it in verbose mode. */
2352
d_call_offset (di, c)
2357
c = d_next_char (di);
2364
if (d_next_char (di) != '_')
2371
if (d_next_char (di) != '_')
2377
/* <ctor-dtor-name> ::= C1
2385
static struct demangle_component *
2386
d_ctor_dtor_name (di)
2389
if (di->last_name != NULL)
2391
if (di->last_name->type == DEMANGLE_COMPONENT_NAME)
2392
di->expansion += di->last_name->u.s_name.len;
2393
else if (di->last_name->type == DEMANGLE_COMPONENT_SUB_STD)
2394
di->expansion += di->last_name->u.s_string.len;
2396
switch (d_next_char (di))
2400
enum gnu_v3_ctor_kinds kind;
2402
switch (d_next_char (di))
2405
kind = gnu_v3_complete_object_ctor;
2408
kind = gnu_v3_base_object_ctor;
2411
kind = gnu_v3_complete_object_allocating_ctor;
2416
return d_make_ctor (di, kind, di->last_name);
2421
enum gnu_v3_dtor_kinds kind;
2423
switch (d_next_char (di))
2426
kind = gnu_v3_deleting_dtor;
2429
kind = gnu_v3_complete_object_dtor;
2432
kind = gnu_v3_base_object_dtor;
2437
return d_make_dtor (di, kind, di->last_name);
2445
/* <type> ::= <builtin-type>
2447
::= <class-enum-type>
2449
::= <pointer-to-member-type>
2450
::= <template-param>
2451
::= <template-template-param> <template-args>
2453
::= <CV-qualifiers> <type>
2458
::= U <source-name> <type>
2460
<builtin-type> ::= various one letter codes
2464
CP_STATIC_IF_GLIBCPP_V3
2465
const struct demangle_builtin_type_info
2466
cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
2468
/* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT },
2469
/* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL },
2470
/* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT },
2471
/* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT },
2472
/* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT },
2473
/* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT },
2474
/* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT },
2475
/* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT },
2476
/* i */ { NL ("int"), NL ("int"), D_PRINT_INT },
2477
/* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED },
2478
/* k */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
2479
/* l */ { NL ("long"), NL ("long"), D_PRINT_LONG },
2480
/* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG },
2481
/* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT },
2482
/* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2484
/* p */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
2485
/* q */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
2486
/* r */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
2487
/* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT },
2488
/* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT },
2489
/* u */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
2490
/* v */ { NL ("void"), NL ("void"), D_PRINT_VOID },
2491
/* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT },
2492
/* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG },
2493
/* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2494
D_PRINT_UNSIGNED_LONG_LONG },
2495
/* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT },
2498
CP_STATIC_IF_GLIBCPP_V3
2499
struct demangle_component *
2500
cplus_demangle_type (di)
2504
struct demangle_component *ret;
2507
/* The ABI specifies that when CV-qualifiers are used, the base type
2508
is substitutable, and the fully qualified type is substitutable,
2509
but the base type with a strict subset of the CV-qualifiers is
2510
not substitutable. The natural recursive implementation of the
2511
CV-qualifiers would cause subsets to be substitutable, so instead
2512
we pull them all off now.
2514
FIXME: The ABI says that order-insensitive vendor qualifiers
2515
should be handled in the same way, but we have no way to tell
2516
which vendor qualifiers are order-insensitive and which are
2517
order-sensitive. So we just assume that they are all
2518
order-sensitive. g++ 3.4 supports only one vendor qualifier,
2519
__vector, and it treats it as order-sensitive when mangling
2522
peek = d_peek_char (di);
2523
if (peek == 'r' || peek == 'V' || peek == 'K')
2525
struct demangle_component **pret;
2527
pret = d_cv_qualifiers (di, &ret, 0);
2530
*pret = cplus_demangle_type (di);
2531
if (! d_add_substitution (di, ret))
2540
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2541
case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2542
case 'o': case 's': case 't':
2543
case 'v': case 'w': case 'x': case 'y': case 'z':
2544
ret = d_make_builtin_type (di,
2545
&cplus_demangle_builtin_types[peek - 'a']);
2546
di->expansion += ret->u.s_builtin.type->len;
2553
ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE,
2554
d_source_name (di), NULL);
2558
ret = d_function_type (di);
2561
case '0': case '1': case '2': case '3': case '4':
2562
case '5': case '6': case '7': case '8': case '9':
2565
ret = d_class_enum_type (di);
2569
ret = d_array_type (di);
2573
ret = d_pointer_to_member_type (di);
2577
ret = d_template_param (di);
2578
if (d_peek_char (di) == 'I')
2580
/* This is <template-template-param> <template-args>. The
2581
<template-template-param> part is a substitution
2583
if (! d_add_substitution (di, ret))
2585
ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2586
d_template_args (di));
2591
/* If this is a special substitution, then it is the start of
2592
<class-enum-type>. */
2596
peek_next = d_peek_next_char (di);
2597
if (IS_DIGIT (peek_next)
2599
|| IS_UPPER (peek_next))
2601
ret = d_substitution (di, 0);
2602
/* The substituted name may have been a template name and
2603
may be followed by tepmlate args. */
2604
if (d_peek_char (di) == 'I')
2605
ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2606
d_template_args (di));
2612
ret = d_class_enum_type (di);
2613
/* If the substitution was a complete type, then it is not
2614
a new substitution candidate. However, if the
2615
substitution was followed by template arguments, then
2616
the whole thing is a substitution candidate. */
2617
if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
2625
ret = d_make_comp (di, DEMANGLE_COMPONENT_POINTER,
2626
cplus_demangle_type (di), NULL);
2631
ret = d_make_comp (di, DEMANGLE_COMPONENT_REFERENCE,
2632
cplus_demangle_type (di), NULL);
2637
ret = d_make_comp (di, DEMANGLE_COMPONENT_COMPLEX,
2638
cplus_demangle_type (di), NULL);
2643
ret = d_make_comp (di, DEMANGLE_COMPONENT_IMAGINARY,
2644
cplus_demangle_type (di), NULL);
2649
ret = d_source_name (di);
2650
ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
2651
cplus_demangle_type (di), ret);
2660
if (! d_add_substitution (di, ret))
2667
/* <CV-qualifiers> ::= [r] [V] [K] */
2669
static struct demangle_component **
2670
d_cv_qualifiers (di, pret, member_fn)
2672
struct demangle_component **pret;
2677
peek = d_peek_char (di);
2678
while (peek == 'r' || peek == 'V' || peek == 'K')
2680
enum demangle_component_type t;
2686
? DEMANGLE_COMPONENT_RESTRICT_THIS
2687
: DEMANGLE_COMPONENT_RESTRICT);
2688
di->expansion += sizeof "restrict";
2690
else if (peek == 'V')
2693
? DEMANGLE_COMPONENT_VOLATILE_THIS
2694
: DEMANGLE_COMPONENT_VOLATILE);
2695
di->expansion += sizeof "volatile";
2700
? DEMANGLE_COMPONENT_CONST_THIS
2701
: DEMANGLE_COMPONENT_CONST);
2702
di->expansion += sizeof "const";
2705
*pret = d_make_comp (di, t, NULL, NULL);
2708
pret = &d_left (*pret);
2710
peek = d_peek_char (di);
2716
/* <function-type> ::= F [Y] <bare-function-type> E */
2718
static struct demangle_component *
2719
d_function_type (di)
2722
struct demangle_component *ret;
2724
if (d_next_char (di) != 'F')
2726
if (d_peek_char (di) == 'Y')
2728
/* Function has C linkage. We don't print this information.
2729
FIXME: We should print it in verbose mode. */
2732
ret = d_bare_function_type (di, 1);
2733
if (d_next_char (di) != 'E')
2738
/* <bare-function-type> ::= <type>+ */
2740
static struct demangle_component *
2741
d_bare_function_type (di, has_return_type)
2743
int has_return_type;
2745
struct demangle_component *return_type;
2746
struct demangle_component *tl;
2747
struct demangle_component **ptl;
2755
struct demangle_component *type;
2757
peek = d_peek_char (di);
2758
if (peek == '\0' || peek == 'E')
2760
type = cplus_demangle_type (di);
2763
if (has_return_type)
2766
has_return_type = 0;
2770
*ptl = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, type, NULL);
2773
ptl = &d_right (*ptl);
2777
/* There should be at least one parameter type besides the optional
2778
return type. A function which takes no arguments will have a
2779
single parameter type void. */
2783
/* If we have a single parameter type void, omit it. */
2784
if (d_right (tl) == NULL
2785
&& d_left (tl)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
2786
&& d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID)
2788
di->expansion -= d_left (tl)->u.s_builtin.type->len;
2792
return d_make_comp (di, DEMANGLE_COMPONENT_FUNCTION_TYPE, return_type, tl);
2795
/* <class-enum-type> ::= <name> */
2797
static struct demangle_component *
2798
d_class_enum_type (di)
2804
/* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2805
::= A [<(dimension) expression>] _ <(element) type>
2808
static struct demangle_component *
2813
struct demangle_component *dim;
2815
if (d_next_char (di) != 'A')
2818
peek = d_peek_char (di);
2821
else if (IS_DIGIT (peek))
2829
peek = d_peek_char (di);
2831
while (IS_DIGIT (peek));
2832
dim = d_make_name (di, s, d_str (di) - s);
2838
dim = d_expression (di);
2843
if (d_next_char (di) != '_')
2846
return d_make_comp (di, DEMANGLE_COMPONENT_ARRAY_TYPE, dim,
2847
cplus_demangle_type (di));
2850
/* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2852
static struct demangle_component *
2853
d_pointer_to_member_type (di)
2856
struct demangle_component *cl;
2857
struct demangle_component *mem;
2858
struct demangle_component **pmem;
2860
if (d_next_char (di) != 'M')
2863
cl = cplus_demangle_type (di);
2865
/* The ABI specifies that any type can be a substitution source, and
2866
that M is followed by two types, and that when a CV-qualified
2867
type is seen both the base type and the CV-qualified types are
2868
substitution sources. The ABI also specifies that for a pointer
2869
to a CV-qualified member function, the qualifiers are attached to
2870
the second type. Given the grammar, a plain reading of the ABI
2871
suggests that both the CV-qualified member function and the
2872
non-qualified member function are substitution sources. However,
2873
g++ does not work that way. g++ treats only the CV-qualified
2874
member function as a substitution source. FIXME. So to work
2875
with g++, we need to pull off the CV-qualifiers here, in order to
2876
avoid calling add_substitution() in cplus_demangle_type(). */
2878
pmem = d_cv_qualifiers (di, &mem, 1);
2881
*pmem = cplus_demangle_type (di);
2883
return d_make_comp (di, DEMANGLE_COMPONENT_PTRMEM_TYPE, cl, mem);
2886
/* <template-param> ::= T_
2887
::= T <(parameter-2 non-negative) number> _
2890
static struct demangle_component *
2891
d_template_param (di)
2896
if (d_next_char (di) != 'T')
2899
if (d_peek_char (di) == '_')
2903
param = d_number (di);
2909
if (d_next_char (di) != '_')
2914
return d_make_template_param (di, param);
2917
/* <template-args> ::= I <template-arg>+ E */
2919
static struct demangle_component *
2920
d_template_args (di)
2923
struct demangle_component *hold_last_name;
2924
struct demangle_component *al;
2925
struct demangle_component **pal;
2927
/* Preserve the last name we saw--don't let the template arguments
2928
clobber it, as that would give us the wrong name for a subsequent
2929
constructor or destructor. */
2930
hold_last_name = di->last_name;
2932
if (d_next_char (di) != 'I')
2939
struct demangle_component *a;
2941
a = d_template_arg (di);
2945
*pal = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, a, NULL);
2948
pal = &d_right (*pal);
2950
if (d_peek_char (di) == 'E')
2957
di->last_name = hold_last_name;
2962
/* <template-arg> ::= <type>
2963
::= X <expression> E
2967
static struct demangle_component *
2971
struct demangle_component *ret;
2973
switch (d_peek_char (di))
2977
ret = d_expression (di);
2978
if (d_next_char (di) != 'E')
2983
return d_expr_primary (di);
2986
return cplus_demangle_type (di);
2990
/* <expression> ::= <(unary) operator-name> <expression>
2991
::= <(binary) operator-name> <expression> <expression>
2992
::= <(trinary) operator-name> <expression> <expression> <expression>
2994
::= <template-param>
2995
::= sr <type> <unqualified-name>
2996
::= sr <type> <unqualified-name> <template-args>
3000
static struct demangle_component *
3006
peek = d_peek_char (di);
3008
return d_expr_primary (di);
3009
else if (peek == 'T')
3010
return d_template_param (di);
3011
else if (peek == 's' && d_peek_next_char (di) == 'r')
3013
struct demangle_component *type;
3014
struct demangle_component *name;
3017
type = cplus_demangle_type (di);
3018
name = d_unqualified_name (di);
3019
if (d_peek_char (di) != 'I')
3020
return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
3022
return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type,
3023
d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3024
d_template_args (di)));
3028
struct demangle_component *op;
3031
op = d_operator_name (di);
3035
if (op->type == DEMANGLE_COMPONENT_OPERATOR)
3036
di->expansion += op->u.s_operator.op->len - 2;
3038
if (op->type == DEMANGLE_COMPONENT_OPERATOR
3039
&& strcmp (op->u.s_operator.op->code, "st") == 0)
3040
return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3041
cplus_demangle_type (di));
3047
case DEMANGLE_COMPONENT_OPERATOR:
3048
args = op->u.s_operator.op->args;
3050
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
3051
args = op->u.s_extended_operator.args;
3053
case DEMANGLE_COMPONENT_CAST:
3061
return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3065
struct demangle_component *left;
3067
left = d_expression (di);
3068
return d_make_comp (di, DEMANGLE_COMPONENT_BINARY, op,
3070
DEMANGLE_COMPONENT_BINARY_ARGS,
3072
d_expression (di)));
3076
struct demangle_component *first;
3077
struct demangle_component *second;
3079
first = d_expression (di);
3080
second = d_expression (di);
3081
return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op,
3083
DEMANGLE_COMPONENT_TRINARY_ARG1,
3086
DEMANGLE_COMPONENT_TRINARY_ARG2,
3088
d_expression (di))));
3096
/* <expr-primary> ::= L <type> <(value) number> E
3097
::= L <type> <(value) float> E
3098
::= L <mangled-name> E
3101
static struct demangle_component *
3105
struct demangle_component *ret;
3107
if (d_next_char (di) != 'L')
3109
if (d_peek_char (di) == '_')
3110
ret = cplus_demangle_mangled_name (di, 0);
3113
struct demangle_component *type;
3114
enum demangle_component_type t;
3117
type = cplus_demangle_type (di);
3121
/* If we have a type we know how to print, we aren't going to
3122
print the type name itself. */
3123
if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
3124
&& type->u.s_builtin.type->print != D_PRINT_DEFAULT)
3125
di->expansion -= type->u.s_builtin.type->len;
3127
/* Rather than try to interpret the literal value, we just
3128
collect it as a string. Note that it's possible to have a
3129
floating point literal here. The ABI specifies that the
3130
format of such literals is machine independent. That's fine,
3131
but what's not fine is that versions of g++ up to 3.2 with
3132
-fabi-version=1 used upper case letters in the hex constant,
3133
and dumped out gcc's internal representation. That makes it
3134
hard to tell where the constant ends, and hard to dump the
3135
constant in any readable form anyhow. We don't attempt to
3136
handle these cases. */
3138
t = DEMANGLE_COMPONENT_LITERAL;
3139
if (d_peek_char (di) == 'n')
3141
t = DEMANGLE_COMPONENT_LITERAL_NEG;
3145
while (d_peek_char (di) != 'E')
3147
ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
3149
if (d_next_char (di) != 'E')
3154
/* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3155
::= Z <(function) encoding> E s [<discriminator>]
3158
static struct demangle_component *
3162
struct demangle_component *function;
3164
if (d_next_char (di) != 'Z')
3167
function = d_encoding (di, 0);
3169
if (d_next_char (di) != 'E')
3172
if (d_peek_char (di) == 's')
3175
if (! d_discriminator (di))
3177
return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function,
3178
d_make_name (di, "string literal",
3179
sizeof "string literal" - 1));
3183
struct demangle_component *name;
3186
if (! d_discriminator (di))
3188
return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
3192
/* <discriminator> ::= _ <(non-negative) number>
3194
We demangle the discriminator, but we don't print it out. FIXME:
3195
We should print it out in verbose mode. */
3198
d_discriminator (di)
3203
if (d_peek_char (di) != '_')
3206
discrim = d_number (di);
3212
/* Add a new substitution. */
3215
d_add_substitution (di, dc)
3217
struct demangle_component *dc;
3221
if (di->next_sub >= di->num_subs)
3223
di->subs[di->next_sub] = dc;
3228
/* <substitution> ::= S <seq-id> _
3238
If PREFIX is non-zero, then this type is being used as a prefix in
3239
a qualified name. In this case, for the standard substitutions, we
3240
need to check whether we are being used as a prefix for a
3241
constructor or destructor, and return a full template name.
3242
Otherwise we will get something like std::iostream::~iostream()
3243
which does not correspond particularly well to any function which
3244
actually appears in the source.
3247
static const struct d_standard_sub_info standard_subs[] =
3252
{ 'a', NL ("std::allocator"),
3253
NL ("std::allocator"),
3255
{ 'b', NL ("std::basic_string"),
3256
NL ("std::basic_string"),
3257
NL ("basic_string") },
3258
{ 's', NL ("std::string"),
3259
NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3260
NL ("basic_string") },
3261
{ 'i', NL ("std::istream"),
3262
NL ("std::basic_istream<char, std::char_traits<char> >"),
3263
NL ("basic_istream") },
3264
{ 'o', NL ("std::ostream"),
3265
NL ("std::basic_ostream<char, std::char_traits<char> >"),
3266
NL ("basic_ostream") },
3267
{ 'd', NL ("std::iostream"),
3268
NL ("std::basic_iostream<char, std::char_traits<char> >"),
3269
NL ("basic_iostream") }
3272
static struct demangle_component *
3273
d_substitution (di, prefix)
3279
if (d_next_char (di) != 'S')
3282
c = d_next_char (di);
3283
if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
3293
id = id * 36 + c - '0';
3294
else if (IS_UPPER (c))
3295
id = id * 36 + c - 'A' + 10;
3298
c = d_next_char (di);
3305
if (id >= di->next_sub)
3310
return di->subs[id];
3315
const struct d_standard_sub_info *p;
3316
const struct d_standard_sub_info *pend;
3318
verbose = (di->options & DMGL_VERBOSE) != 0;
3319
if (! verbose && prefix)
3323
peek = d_peek_char (di);
3324
if (peek == 'C' || peek == 'D')
3328
pend = (&standard_subs[0]
3329
+ sizeof standard_subs / sizeof standard_subs[0]);
3330
for (p = &standard_subs[0]; p < pend; ++p)
3337
if (p->set_last_name != NULL)
3338
di->last_name = d_make_sub (di, p->set_last_name,
3339
p->set_last_name_len);
3342
s = p->full_expansion;
3347
s = p->simple_expansion;
3348
len = p->simple_len;
3350
di->expansion += len;
3351
return d_make_sub (di, s, len);
3359
/* Resize the print buffer. */
3362
d_print_resize (dpi, add)
3363
struct d_print_info *dpi;
3368
if (dpi->buf == NULL)
3370
need = dpi->len + add;
3371
while (need > dpi->alc)
3376
newalc = dpi->alc * 2;
3377
newbuf = realloc (dpi->buf, newalc);
3382
dpi->allocation_failure = 1;
3390
/* Append a character to the print buffer. */
3393
d_print_append_char (dpi, c)
3394
struct d_print_info *dpi;
3397
if (dpi->buf != NULL)
3399
if (dpi->len >= dpi->alc)
3401
d_print_resize (dpi, 1);
3402
if (dpi->buf == NULL)
3406
dpi->buf[dpi->len] = c;
3411
/* Append a buffer to the print buffer. */
3414
d_print_append_buffer (dpi, s, l)
3415
struct d_print_info *dpi;
3419
if (dpi->buf != NULL)
3421
if (dpi->len + l > dpi->alc)
3423
d_print_resize (dpi, l);
3424
if (dpi->buf == NULL)
3428
memcpy (dpi->buf + dpi->len, s, l);
3433
/* Indicate that an error occurred during printing. */
3437
struct d_print_info *dpi;
3443
/* Turn components into a human readable string. OPTIONS is the
3444
options bits passed to the demangler. DC is the tree to print.
3445
ESTIMATE is a guess at the length of the result. This returns a
3446
string allocated by malloc, or NULL on error. On success, this
3447
sets *PALC to the size of the allocated buffer. On failure, this
3448
sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3451
CP_STATIC_IF_GLIBCPP_V3
3453
cplus_demangle_print (options, dc, estimate, palc)
3455
const struct demangle_component *dc;
3459
struct d_print_info dpi;
3461
dpi.options = options;
3463
dpi.alc = estimate + 1;
3464
dpi.buf = malloc (dpi.alc);
3465
if (dpi.buf == NULL)
3472
dpi.templates = NULL;
3473
dpi.modifiers = NULL;
3475
dpi.allocation_failure = 0;
3477
d_print_comp (&dpi, dc);
3479
d_append_char (&dpi, '\0');
3481
if (dpi.buf != NULL)
3484
*palc = dpi.allocation_failure;
3489
/* Subroutine to handle components. */
3492
d_print_comp (dpi, dc)
3493
struct d_print_info *dpi;
3494
const struct demangle_component *dc;
3498
d_print_error (dpi);
3501
if (d_print_saw_error (dpi))
3506
case DEMANGLE_COMPONENT_NAME:
3507
if ((dpi->options & DMGL_JAVA) == 0)
3508
d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len);
3510
d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
3513
case DEMANGLE_COMPONENT_QUAL_NAME:
3514
case DEMANGLE_COMPONENT_LOCAL_NAME:
3515
d_print_comp (dpi, d_left (dc));
3516
if ((dpi->options & DMGL_JAVA) == 0)
3517
d_append_string_constant (dpi, "::");
3519
d_append_char (dpi, '.');
3520
d_print_comp (dpi, d_right (dc));
3523
case DEMANGLE_COMPONENT_TYPED_NAME:
3525
struct d_print_mod *hold_modifiers;
3526
struct demangle_component *typed_name;
3527
struct d_print_mod adpm[4];
3529
struct d_print_template dpt;
3531
/* Pass the name down to the type so that it can be printed in
3532
the right place for the type. We also have to pass down
3533
any CV-qualifiers, which apply to the this parameter. */
3534
hold_modifiers = dpi->modifiers;
3536
typed_name = d_left (dc);
3537
while (typed_name != NULL)
3539
if (i >= sizeof adpm / sizeof adpm[0])
3541
d_print_error (dpi);
3545
adpm[i].next = dpi->modifiers;
3546
dpi->modifiers = &adpm[i];
3547
adpm[i].mod = typed_name;
3548
adpm[i].printed = 0;
3549
adpm[i].templates = dpi->templates;
3552
if (typed_name->type != DEMANGLE_COMPONENT_RESTRICT_THIS
3553
&& typed_name->type != DEMANGLE_COMPONENT_VOLATILE_THIS
3554
&& typed_name->type != DEMANGLE_COMPONENT_CONST_THIS)
3557
typed_name = d_left (typed_name);
3560
/* If typed_name is a template, then it applies to the
3561
function type as well. */
3562
if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
3564
dpt.next = dpi->templates;
3565
dpi->templates = &dpt;
3566
dpt.template = typed_name;
3569
/* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3570
there may be CV-qualifiers on its right argument which
3571
really apply here; this happens when parsing a class which
3572
is local to a function. */
3573
if (typed_name->type == DEMANGLE_COMPONENT_LOCAL_NAME)
3575
struct demangle_component *local_name;
3577
local_name = d_right (typed_name);
3578
while (local_name->type == DEMANGLE_COMPONENT_RESTRICT_THIS
3579
|| local_name->type == DEMANGLE_COMPONENT_VOLATILE_THIS
3580
|| local_name->type == DEMANGLE_COMPONENT_CONST_THIS)
3582
if (i >= sizeof adpm / sizeof adpm[0])
3584
d_print_error (dpi);
3588
adpm[i] = adpm[i - 1];
3589
adpm[i].next = &adpm[i - 1];
3590
dpi->modifiers = &adpm[i];
3592
adpm[i - 1].mod = local_name;
3593
adpm[i - 1].printed = 0;
3594
adpm[i - 1].templates = dpi->templates;
3597
local_name = d_left (local_name);
3601
d_print_comp (dpi, d_right (dc));
3603
if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
3604
dpi->templates = dpt.next;
3606
/* If the modifiers didn't get printed by the type, print them
3611
if (! adpm[i].printed)
3613
d_append_char (dpi, ' ');
3614
d_print_mod (dpi, adpm[i].mod);
3618
dpi->modifiers = hold_modifiers;
3623
case DEMANGLE_COMPONENT_TEMPLATE:
3625
struct d_print_mod *hold_dpm;
3627
/* Don't push modifiers into a template definition. Doing so
3628
could give the wrong definition for a template argument.
3629
Instead, treat the template essentially as a name. */
3631
hold_dpm = dpi->modifiers;
3632
dpi->modifiers = NULL;
3634
d_print_comp (dpi, d_left (dc));
3635
if (d_last_char (dpi) == '<')
3636
d_append_char (dpi, ' ');
3637
d_append_char (dpi, '<');
3638
d_print_comp (dpi, d_right (dc));
3639
/* Avoid generating two consecutive '>' characters, to avoid
3640
the C++ syntactic ambiguity. */
3641
if (d_last_char (dpi) == '>')
3642
d_append_char (dpi, ' ');
3643
d_append_char (dpi, '>');
3645
dpi->modifiers = hold_dpm;
3650
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
3653
struct demangle_component *a;
3654
struct d_print_template *hold_dpt;
3656
if (dpi->templates == NULL)
3658
d_print_error (dpi);
3661
i = dc->u.s_number.number;
3662
for (a = d_right (dpi->templates->template);
3666
if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
3668
d_print_error (dpi);
3675
if (i != 0 || a == NULL)
3677
d_print_error (dpi);
3681
/* While processing this parameter, we need to pop the list of
3682
templates. This is because the template parameter may
3683
itself be a reference to a parameter of an outer
3686
hold_dpt = dpi->templates;
3687
dpi->templates = hold_dpt->next;
3689
d_print_comp (dpi, d_left (a));
3691
dpi->templates = hold_dpt;
3696
case DEMANGLE_COMPONENT_CTOR:
3697
d_print_comp (dpi, dc->u.s_ctor.name);
3700
case DEMANGLE_COMPONENT_DTOR:
3701
d_append_char (dpi, '~');
3702
d_print_comp (dpi, dc->u.s_dtor.name);
3705
case DEMANGLE_COMPONENT_VTABLE:
3706
d_append_string_constant (dpi, "vtable for ");
3707
d_print_comp (dpi, d_left (dc));
3710
case DEMANGLE_COMPONENT_VTT:
3711
d_append_string_constant (dpi, "VTT for ");
3712
d_print_comp (dpi, d_left (dc));
3715
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
3716
d_append_string_constant (dpi, "construction vtable for ");
3717
d_print_comp (dpi, d_left (dc));
3718
d_append_string_constant (dpi, "-in-");
3719
d_print_comp (dpi, d_right (dc));
3722
case DEMANGLE_COMPONENT_TYPEINFO:
3723
d_append_string_constant (dpi, "typeinfo for ");
3724
d_print_comp (dpi, d_left (dc));
3727
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
3728
d_append_string_constant (dpi, "typeinfo name for ");
3729
d_print_comp (dpi, d_left (dc));
3732
case DEMANGLE_COMPONENT_TYPEINFO_FN:
3733
d_append_string_constant (dpi, "typeinfo fn for ");
3734
d_print_comp (dpi, d_left (dc));
3737
case DEMANGLE_COMPONENT_THUNK:
3738
d_append_string_constant (dpi, "non-virtual thunk to ");
3739
d_print_comp (dpi, d_left (dc));
3742
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
3743
d_append_string_constant (dpi, "virtual thunk to ");
3744
d_print_comp (dpi, d_left (dc));
3747
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
3748
d_append_string_constant (dpi, "covariant return thunk to ");
3749
d_print_comp (dpi, d_left (dc));
3752
case DEMANGLE_COMPONENT_JAVA_CLASS:
3753
d_append_string_constant (dpi, "java Class for ");
3754
d_print_comp (dpi, d_left (dc));
3757
case DEMANGLE_COMPONENT_GUARD:
3758
d_append_string_constant (dpi, "guard variable for ");
3759
d_print_comp (dpi, d_left (dc));
3762
case DEMANGLE_COMPONENT_REFTEMP:
3763
d_append_string_constant (dpi, "reference temporary for ");
3764
d_print_comp (dpi, d_left (dc));
3767
case DEMANGLE_COMPONENT_SUB_STD:
3768
d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);
3771
case DEMANGLE_COMPONENT_RESTRICT:
3772
case DEMANGLE_COMPONENT_VOLATILE:
3773
case DEMANGLE_COMPONENT_CONST:
3775
struct d_print_mod *pdpm;
3777
/* When printing arrays, it's possible to have cases where the
3778
same CV-qualifier gets pushed on the stack multiple times.
3779
We only need to print it once. */
3781
for (pdpm = dpi->modifiers; pdpm != NULL; pdpm = pdpm->next)
3783
if (! pdpm->printed)
3785
if (pdpm->mod->type != DEMANGLE_COMPONENT_RESTRICT
3786
&& pdpm->mod->type != DEMANGLE_COMPONENT_VOLATILE
3787
&& pdpm->mod->type != DEMANGLE_COMPONENT_CONST)
3789
if (pdpm->mod->type == dc->type)
3791
d_print_comp (dpi, d_left (dc));
3798
case DEMANGLE_COMPONENT_RESTRICT_THIS:
3799
case DEMANGLE_COMPONENT_VOLATILE_THIS:
3800
case DEMANGLE_COMPONENT_CONST_THIS:
3801
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
3802
case DEMANGLE_COMPONENT_POINTER:
3803
case DEMANGLE_COMPONENT_REFERENCE:
3804
case DEMANGLE_COMPONENT_COMPLEX:
3805
case DEMANGLE_COMPONENT_IMAGINARY:
3807
/* We keep a list of modifiers on the stack. */
3808
struct d_print_mod dpm;
3810
dpm.next = dpi->modifiers;
3811
dpi->modifiers = &dpm;
3814
dpm.templates = dpi->templates;
3816
d_print_comp (dpi, d_left (dc));
3818
/* If the modifier didn't get printed by the type, print it
3821
d_print_mod (dpi, dc);
3823
dpi->modifiers = dpm.next;
3828
case DEMANGLE_COMPONENT_BUILTIN_TYPE:
3829
if ((dpi->options & DMGL_JAVA) == 0)
3830
d_append_buffer (dpi, dc->u.s_builtin.type->name,
3831
dc->u.s_builtin.type->len);
3833
d_append_buffer (dpi, dc->u.s_builtin.type->java_name,
3834
dc->u.s_builtin.type->java_len);
3837
case DEMANGLE_COMPONENT_VENDOR_TYPE:
3838
d_print_comp (dpi, d_left (dc));
3841
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
3843
if (d_left (dc) != NULL)
3845
struct d_print_mod dpm;
3847
/* We must pass this type down as a modifier in order to
3848
print it in the right location. */
3850
dpm.next = dpi->modifiers;
3851
dpi->modifiers = &dpm;
3854
dpm.templates = dpi->templates;
3856
d_print_comp (dpi, d_left (dc));
3858
dpi->modifiers = dpm.next;
3863
d_append_char (dpi, ' ');
3866
d_print_function_type (dpi, dc, dpi->modifiers);
3871
case DEMANGLE_COMPONENT_ARRAY_TYPE:
3873
struct d_print_mod *hold_modifiers;
3874
struct d_print_mod adpm[4];
3876
struct d_print_mod *pdpm;
3878
/* We must pass this type down as a modifier in order to print
3879
multi-dimensional arrays correctly. If the array itself is
3880
CV-qualified, we act as though the element type were
3881
CV-qualified. We do this by copying the modifiers down
3882
rather than fiddling pointers, so that we don't wind up
3883
with a d_print_mod higher on the stack pointing into our
3884
stack frame after we return. */
3886
hold_modifiers = dpi->modifiers;
3888
adpm[0].next = hold_modifiers;
3889
dpi->modifiers = &adpm[0];
3891
adpm[0].printed = 0;
3892
adpm[0].templates = dpi->templates;
3895
pdpm = hold_modifiers;
3897
&& (pdpm->mod->type == DEMANGLE_COMPONENT_RESTRICT
3898
|| pdpm->mod->type == DEMANGLE_COMPONENT_VOLATILE
3899
|| pdpm->mod->type == DEMANGLE_COMPONENT_CONST))
3901
if (! pdpm->printed)
3903
if (i >= sizeof adpm / sizeof adpm[0])
3905
d_print_error (dpi);
3910
adpm[i].next = dpi->modifiers;
3911
dpi->modifiers = &adpm[i];
3919
d_print_comp (dpi, d_right (dc));
3921
dpi->modifiers = hold_modifiers;
3923
if (adpm[0].printed)
3929
d_print_mod (dpi, adpm[i].mod);
3932
d_print_array_type (dpi, dc, dpi->modifiers);
3937
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
3939
struct d_print_mod dpm;
3941
dpm.next = dpi->modifiers;
3942
dpi->modifiers = &dpm;
3945
dpm.templates = dpi->templates;
3947
d_print_comp (dpi, d_right (dc));
3949
/* If the modifier didn't get printed by the type, print it
3953
d_append_char (dpi, ' ');
3954
d_print_comp (dpi, d_left (dc));
3955
d_append_string_constant (dpi, "::*");
3958
dpi->modifiers = dpm.next;
3963
case DEMANGLE_COMPONENT_ARGLIST:
3964
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
3965
d_print_comp (dpi, d_left (dc));
3966
if (d_right (dc) != NULL)
3968
d_append_string_constant (dpi, ", ");
3969
d_print_comp (dpi, d_right (dc));
3973
case DEMANGLE_COMPONENT_OPERATOR:
3977
d_append_string_constant (dpi, "operator");
3978
c = dc->u.s_operator.op->name[0];
3980
d_append_char (dpi, ' ');
3981
d_append_buffer (dpi, dc->u.s_operator.op->name,
3982
dc->u.s_operator.op->len);
3986
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
3987
d_append_string_constant (dpi, "operator ");
3988
d_print_comp (dpi, dc->u.s_extended_operator.name);
3991
case DEMANGLE_COMPONENT_CAST:
3992
d_append_string_constant (dpi, "operator ");
3993
d_print_cast (dpi, dc);
3996
case DEMANGLE_COMPONENT_UNARY:
3997
if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST)
3998
d_print_expr_op (dpi, d_left (dc));
4001
d_append_char (dpi, '(');
4002
d_print_cast (dpi, d_left (dc));
4003
d_append_char (dpi, ')');
4005
d_append_char (dpi, '(');
4006
d_print_comp (dpi, d_right (dc));
4007
d_append_char (dpi, ')');
4010
case DEMANGLE_COMPONENT_BINARY:
4011
if (d_right (dc)->type != DEMANGLE_COMPONENT_BINARY_ARGS)
4013
d_print_error (dpi);
4017
/* We wrap an expression which uses the greater-than operator in
4018
an extra layer of parens so that it does not get confused
4019
with the '>' which ends the template parameters. */
4020
if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
4021
&& d_left (dc)->u.s_operator.op->len == 1
4022
&& d_left (dc)->u.s_operator.op->name[0] == '>')
4023
d_append_char (dpi, '(');
4025
d_append_char (dpi, '(');
4026
d_print_comp (dpi, d_left (d_right (dc)));
4027
d_append_string_constant (dpi, ") ");
4028
d_print_expr_op (dpi, d_left (dc));
4029
d_append_string_constant (dpi, " (");
4030
d_print_comp (dpi, d_right (d_right (dc)));
4031
d_append_char (dpi, ')');
4033
if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
4034
&& d_left (dc)->u.s_operator.op->len == 1
4035
&& d_left (dc)->u.s_operator.op->name[0] == '>')
4036
d_append_char (dpi, ')');
4040
case DEMANGLE_COMPONENT_BINARY_ARGS:
4041
/* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4042
d_print_error (dpi);
4045
case DEMANGLE_COMPONENT_TRINARY:
4046
if (d_right (dc)->type != DEMANGLE_COMPONENT_TRINARY_ARG1
4047
|| d_right (d_right (dc))->type != DEMANGLE_COMPONENT_TRINARY_ARG2)
4049
d_print_error (dpi);
4052
d_append_char (dpi, '(');
4053
d_print_comp (dpi, d_left (d_right (dc)));
4054
d_append_string_constant (dpi, ") ");
4055
d_print_expr_op (dpi, d_left (dc));
4056
d_append_string_constant (dpi, " (");
4057
d_print_comp (dpi, d_left (d_right (d_right (dc))));
4058
d_append_string_constant (dpi, ") : (");
4059
d_print_comp (dpi, d_right (d_right (d_right (dc))));
4060
d_append_char (dpi, ')');
4063
case DEMANGLE_COMPONENT_TRINARY_ARG1:
4064
case DEMANGLE_COMPONENT_TRINARY_ARG2:
4065
/* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4066
d_print_error (dpi);
4069
case DEMANGLE_COMPONENT_LITERAL:
4070
case DEMANGLE_COMPONENT_LITERAL_NEG:
4072
enum d_builtin_type_print tp;
4074
/* For some builtin types, produce simpler output. */
4075
tp = D_PRINT_DEFAULT;
4076
if (d_left (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)
4078
tp = d_left (dc)->u.s_builtin.type->print;
4082
case D_PRINT_UNSIGNED:
4084
case D_PRINT_UNSIGNED_LONG:
4085
case D_PRINT_LONG_LONG:
4086
case D_PRINT_UNSIGNED_LONG_LONG:
4087
if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME)
4089
if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
4090
d_append_char (dpi, '-');
4091
d_print_comp (dpi, d_right (dc));
4096
case D_PRINT_UNSIGNED:
4097
d_append_char (dpi, 'u');
4100
d_append_char (dpi, 'l');
4102
case D_PRINT_UNSIGNED_LONG:
4103
d_append_string_constant (dpi, "ul");
4105
case D_PRINT_LONG_LONG:
4106
d_append_string_constant (dpi, "ll");
4108
case D_PRINT_UNSIGNED_LONG_LONG:
4109
d_append_string_constant (dpi, "ull");
4117
if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME
4118
&& d_right (dc)->u.s_name.len == 1
4119
&& dc->type == DEMANGLE_COMPONENT_LITERAL)
4121
switch (d_right (dc)->u.s_name.s[0])
4124
d_append_string_constant (dpi, "false");
4127
d_append_string_constant (dpi, "true");
4140
d_append_char (dpi, '(');
4141
d_print_comp (dpi, d_left (dc));
4142
d_append_char (dpi, ')');
4143
if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
4144
d_append_char (dpi, '-');
4145
if (tp == D_PRINT_FLOAT)
4146
d_append_char (dpi, '[');
4147
d_print_comp (dpi, d_right (dc));
4148
if (tp == D_PRINT_FLOAT)
4149
d_append_char (dpi, ']');
4154
d_print_error (dpi);
4159
/* Print a Java dentifier. For Java we try to handle encoded extended
4160
Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4161
so we don't it for C++. Characters are encoded as
4165
d_print_java_identifier (dpi, name, len)
4166
struct d_print_info *dpi;
4174
for (p = name; p < end; ++p)
4185
for (q = p + 3; q < end; ++q)
4191
else if (*q >= 'A' && *q <= 'F')
4192
dig = *q - 'A' + 10;
4193
else if (*q >= 'a' && *q <= 'f')
4194
dig = *q - 'a' + 10;
4200
/* If the Unicode character is larger than 256, we don't try
4201
to deal with it here. FIXME. */
4202
if (q < end && *q == '_' && c < 256)
4204
d_append_char (dpi, c);
4210
d_append_char (dpi, *p);
4214
/* Print a list of modifiers. SUFFIX is 1 if we are printing
4215
qualifiers on this after printing a function. */
4218
d_print_mod_list (dpi, mods, suffix)
4219
struct d_print_info *dpi;
4220
struct d_print_mod *mods;
4223
struct d_print_template *hold_dpt;
4225
if (mods == NULL || d_print_saw_error (dpi))
4230
&& (mods->mod->type == DEMANGLE_COMPONENT_RESTRICT_THIS
4231
|| mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS
4232
|| mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS)))
4234
d_print_mod_list (dpi, mods->next, suffix);
4240
hold_dpt = dpi->templates;
4241
dpi->templates = mods->templates;
4243
if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
4245
d_print_function_type (dpi, mods->mod, mods->next);
4246
dpi->templates = hold_dpt;
4249
else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
4251
d_print_array_type (dpi, mods->mod, mods->next);
4252
dpi->templates = hold_dpt;
4255
else if (mods->mod->type == DEMANGLE_COMPONENT_LOCAL_NAME)
4257
struct d_print_mod *hold_modifiers;
4258
struct demangle_component *dc;
4260
/* When this is on the modifier stack, we have pulled any
4261
qualifiers off the right argument already. Otherwise, we
4262
print it as usual, but don't let the left argument see any
4265
hold_modifiers = dpi->modifiers;
4266
dpi->modifiers = NULL;
4267
d_print_comp (dpi, d_left (mods->mod));
4268
dpi->modifiers = hold_modifiers;
4270
if ((dpi->options & DMGL_JAVA) == 0)
4271
d_append_string_constant (dpi, "::");
4273
d_append_char (dpi, '.');
4275
dc = d_right (mods->mod);
4276
while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
4277
|| dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
4278
|| dc->type == DEMANGLE_COMPONENT_CONST_THIS)
4281
d_print_comp (dpi, dc);
4283
dpi->templates = hold_dpt;
4287
d_print_mod (dpi, mods->mod);
4289
dpi->templates = hold_dpt;
4291
d_print_mod_list (dpi, mods->next, suffix);
4294
/* Print a modifier. */
4297
d_print_mod (dpi, mod)
4298
struct d_print_info *dpi;
4299
const struct demangle_component *mod;
4303
case DEMANGLE_COMPONENT_RESTRICT:
4304
case DEMANGLE_COMPONENT_RESTRICT_THIS:
4305
d_append_string_constant (dpi, " restrict");
4307
case DEMANGLE_COMPONENT_VOLATILE:
4308
case DEMANGLE_COMPONENT_VOLATILE_THIS:
4309
d_append_string_constant (dpi, " volatile");
4311
case DEMANGLE_COMPONENT_CONST:
4312
case DEMANGLE_COMPONENT_CONST_THIS:
4313
d_append_string_constant (dpi, " const");
4315
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
4316
d_append_char (dpi, ' ');
4317
d_print_comp (dpi, d_right (mod));
4319
case DEMANGLE_COMPONENT_POINTER:
4320
/* There is no pointer symbol in Java. */
4321
if ((dpi->options & DMGL_JAVA) == 0)
4322
d_append_char (dpi, '*');
4324
case DEMANGLE_COMPONENT_REFERENCE:
4325
d_append_char (dpi, '&');
4327
case DEMANGLE_COMPONENT_COMPLEX:
4328
d_append_string_constant (dpi, "complex ");
4330
case DEMANGLE_COMPONENT_IMAGINARY:
4331
d_append_string_constant (dpi, "imaginary ");
4333
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
4334
if (d_last_char (dpi) != '(')
4335
d_append_char (dpi, ' ');
4336
d_print_comp (dpi, d_left (mod));
4337
d_append_string_constant (dpi, "::*");
4339
case DEMANGLE_COMPONENT_TYPED_NAME:
4340
d_print_comp (dpi, d_left (mod));
4343
/* Otherwise, we have something that won't go back on the
4344
modifier stack, so we can just print it. */
4345
d_print_comp (dpi, mod);
4350
/* Print a function type, except for the return type. */
4353
d_print_function_type (dpi, dc, mods)
4354
struct d_print_info *dpi;
4355
const struct demangle_component *dc;
4356
struct d_print_mod *mods;
4361
struct d_print_mod *p;
4362
struct d_print_mod *hold_modifiers;
4367
for (p = mods; p != NULL; p = p->next)
4373
switch (p->mod->type)
4375
case DEMANGLE_COMPONENT_POINTER:
4376
case DEMANGLE_COMPONENT_REFERENCE:
4379
case DEMANGLE_COMPONENT_RESTRICT:
4380
case DEMANGLE_COMPONENT_VOLATILE:
4381
case DEMANGLE_COMPONENT_CONST:
4382
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
4383
case DEMANGLE_COMPONENT_COMPLEX:
4384
case DEMANGLE_COMPONENT_IMAGINARY:
4385
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
4389
case DEMANGLE_COMPONENT_RESTRICT_THIS:
4390
case DEMANGLE_COMPONENT_VOLATILE_THIS:
4391
case DEMANGLE_COMPONENT_CONST_THIS:
4400
if (d_left (dc) != NULL && ! saw_mod)
4407
if (d_last_char (dpi) != '('
4408
&& d_last_char (dpi) != '*')
4411
if (need_space && d_last_char (dpi) != ' ')
4412
d_append_char (dpi, ' ');
4413
d_append_char (dpi, '(');
4416
hold_modifiers = dpi->modifiers;
4417
dpi->modifiers = NULL;
4419
d_print_mod_list (dpi, mods, 0);
4422
d_append_char (dpi, ')');
4424
d_append_char (dpi, '(');
4426
if (d_right (dc) != NULL)
4427
d_print_comp (dpi, d_right (dc));
4429
d_append_char (dpi, ')');
4431
d_print_mod_list (dpi, mods, 1);
4433
dpi->modifiers = hold_modifiers;
4436
/* Print an array type, except for the element type. */
4439
d_print_array_type (dpi, dc, mods)
4440
struct d_print_info *dpi;
4441
const struct demangle_component *dc;
4442
struct d_print_mod *mods;
4450
struct d_print_mod *p;
4453
for (p = mods; p != NULL; p = p->next)
4457
if (p->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
4472
d_append_string_constant (dpi, " (");
4474
d_print_mod_list (dpi, mods, 0);
4477
d_append_char (dpi, ')');
4481
d_append_char (dpi, ' ');
4483
d_append_char (dpi, '[');
4485
if (d_left (dc) != NULL)
4486
d_print_comp (dpi, d_left (dc));
4488
d_append_char (dpi, ']');
4491
/* Print an operator in an expression. */
4494
d_print_expr_op (dpi, dc)
4495
struct d_print_info *dpi;
4496
const struct demangle_component *dc;
4498
if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
4499
d_append_buffer (dpi, dc->u.s_operator.op->name,
4500
dc->u.s_operator.op->len);
4502
d_print_comp (dpi, dc);
4508
d_print_cast (dpi, dc)
4509
struct d_print_info *dpi;
4510
const struct demangle_component *dc;
4512
if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
4513
d_print_comp (dpi, d_left (dc));
4516
struct d_print_mod *hold_dpm;
4517
struct d_print_template dpt;
4519
/* It appears that for a templated cast operator, we need to put
4520
the template parameters in scope for the operator name, but
4521
not for the parameters. The effect is that we need to handle
4522
the template printing here. */
4524
hold_dpm = dpi->modifiers;
4525
dpi->modifiers = NULL;
4527
dpt.next = dpi->templates;
4528
dpi->templates = &dpt;
4529
dpt.template = d_left (dc);
4531
d_print_comp (dpi, d_left (d_left (dc)));
4533
dpi->templates = dpt.next;
4535
if (d_last_char (dpi) == '<')
4536
d_append_char (dpi, ' ');
4537
d_append_char (dpi, '<');
4538
d_print_comp (dpi, d_right (d_left (dc)));
4539
/* Avoid generating two consecutive '>' characters, to avoid
4540
the C++ syntactic ambiguity. */
4541
if (d_last_char (dpi) == '>')
4542
d_append_char (dpi, ' ');
4543
d_append_char (dpi, '>');
4545
dpi->modifiers = hold_dpm;
4549
/* Initialize the information structure we use to pass around
4552
CP_STATIC_IF_GLIBCPP_V3
4554
cplus_demangle_init_info (mangled, options, len, di)
4555
const char *mangled;
4561
di->send = mangled + len;
4562
di->options = options;
4566
/* We can not need more components than twice the number of chars in
4567
the mangled string. Most components correspond directly to
4568
chars, but the ARGLIST types are exceptions. */
4569
di->num_comps = 2 * len;
4572
/* Similarly, we can not need more substitutions than there are
4573
chars in the mangled string. */
4578
di->last_name = NULL;
4583
/* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4584
name, return a buffer allocated with malloc holding the demangled
4585
name. OPTIONS is the usual libiberty demangler options. On
4586
success, this sets *PALC to the allocated size of the returned
4587
buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4588
a memory allocation failure. On failure, this returns NULL. */
4591
d_demangle (mangled, options, palc)
4592
const char* mangled;
4599
struct demangle_component *dc;
4605
len = strlen (mangled);
4607
if (mangled[0] == '_' && mangled[1] == 'Z')
4609
else if (strncmp (mangled, "_GLOBAL_", 8) == 0
4610
&& (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
4611
&& (mangled[9] == 'D' || mangled[9] == 'I')
4612
&& mangled[10] == '_')
4616
r = malloc (40 + len - 11);
4621
if (mangled[9] == 'I')
4622
strcpy (r, "global constructors keyed to ");
4624
strcpy (r, "global destructors keyed to ");
4625
strcat (r, mangled + 11);
4631
if ((options & DMGL_TYPES) == 0)
4636
cplus_demangle_init_info (mangled, options, len, &di);
4639
#ifdef CP_DYNAMIC_ARRAYS
4640
__extension__ struct demangle_component comps[di.num_comps];
4641
__extension__ struct demangle_component *subs[di.num_subs];
4643
di.comps = &comps[0];
4646
di.comps = ((struct demangle_component *)
4647
malloc (di.num_comps * sizeof (struct demangle_component)));
4648
di.subs = ((struct demangle_component **)
4649
malloc (di.num_subs * sizeof (struct demangle_component *)));
4650
if (di.comps == NULL || di.subs == NULL)
4652
if (di.comps != NULL)
4654
if (di.subs != NULL)
4662
dc = cplus_demangle_mangled_name (&di, 1);
4664
dc = cplus_demangle_type (&di);
4666
/* If DMGL_PARAMS is set, then if we didn't consume the entire
4667
mangled string, then we didn't successfully demangle it. If
4668
DMGL_PARAMS is not set, we didn't look at the trailing
4670
if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0')
4673
#ifdef CP_DEMANGLE_DEBUG
4675
printf ("failed demangling\n");
4680
/* We try to guess the length of the demangled string, to minimize
4681
calls to realloc during demangling. */
4682
estimate = len + di.expansion + 10 * di.did_subs;
4683
estimate += estimate / 8;
4687
ret = cplus_demangle_print (options, dc, estimate, palc);
4689
#ifndef CP_DYNAMIC_ARRAYS
4694
#ifdef CP_DEMANGLE_DEBUG
4699
rlen = strlen (ret);
4700
if (rlen > 2 * estimate)
4701
printf ("*** Length %d much greater than estimate %d\n",
4703
else if (rlen > estimate)
4704
printf ("*** Length %d greater than estimate %d\n",
4706
else if (rlen < estimate / 2)
4707
printf ("*** Length %d much less than estimate %d\n",
4717
cplus_demangle_v3 (mangled, options)
4718
const char* mangled;
4723
return d_demangle (mangled, options, &alc);
4726
/* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
4727
conventions, but the output formatting is a little different.
4728
This instructs the C++ demangler not to emit pointer characters ("*"), and
4729
to use Java's namespace separator symbol ("." instead of "::"). It then
4730
does an additional pass over the demangled output to replace instances
4731
of JArray<TYPE> with TYPE[]. */
4734
java_demangle_v3 (mangled)
4735
const char* mangled;
4743
demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS, &alc);
4745
if (demangled == NULL)
4751
while (*from != '\0')
4753
if (strncmp (from, "JArray<", 7) == 0)
4758
else if (nesting > 0 && *from == '>')
4760
while (to > demangled && to[-1] == ' ')
4776
#ifndef IN_GLIBCPP_V3
4778
/* Demangle a string in order to find out whether it is a constructor
4779
or destructor. Return non-zero on success. Set *CTOR_KIND and
4780
*DTOR_KIND appropriately. */
4783
is_ctor_or_dtor (mangled, ctor_kind, dtor_kind)
4784
const char *mangled;
4785
enum gnu_v3_ctor_kinds *ctor_kind;
4786
enum gnu_v3_dtor_kinds *dtor_kind;
4789
struct demangle_component *dc;
4792
*ctor_kind = (enum gnu_v3_ctor_kinds) 0;
4793
*dtor_kind = (enum gnu_v3_dtor_kinds) 0;
4795
cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di);
4798
#ifdef CP_DYNAMIC_ARRAYS
4799
__extension__ struct demangle_component comps[di.num_comps];
4800
__extension__ struct demangle_component *subs[di.num_subs];
4802
di.comps = &comps[0];
4805
di.comps = ((struct demangle_component *)
4806
malloc (di.num_comps * sizeof (struct demangle_component)));
4807
di.subs = ((struct demangle_component **)
4808
malloc (di.num_subs * sizeof (struct demangle_component *)));
4809
if (di.comps == NULL || di.subs == NULL)
4811
if (di.comps != NULL)
4813
if (di.subs != NULL)
4819
dc = cplus_demangle_mangled_name (&di, 1);
4821
/* Note that because we did not pass DMGL_PARAMS, we don't expect
4822
to demangle the entire string. */
4832
case DEMANGLE_COMPONENT_TYPED_NAME:
4833
case DEMANGLE_COMPONENT_TEMPLATE:
4834
case DEMANGLE_COMPONENT_RESTRICT_THIS:
4835
case DEMANGLE_COMPONENT_VOLATILE_THIS:
4836
case DEMANGLE_COMPONENT_CONST_THIS:
4839
case DEMANGLE_COMPONENT_QUAL_NAME:
4840
case DEMANGLE_COMPONENT_LOCAL_NAME:
4843
case DEMANGLE_COMPONENT_CTOR:
4844
*ctor_kind = dc->u.s_ctor.kind;
4848
case DEMANGLE_COMPONENT_DTOR:
4849
*dtor_kind = dc->u.s_dtor.kind;
4856
#ifndef CP_DYNAMIC_ARRAYS
4865
/* Return whether NAME is the mangled form of a g++ V3 ABI constructor
4866
name. A non-zero return indicates the type of constructor. */
4868
enum gnu_v3_ctor_kinds
4869
is_gnu_v3_mangled_ctor (name)
4872
enum gnu_v3_ctor_kinds ctor_kind;
4873
enum gnu_v3_dtor_kinds dtor_kind;
4875
if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
4876
return (enum gnu_v3_ctor_kinds) 0;
4881
/* Return whether NAME is the mangled form of a g++ V3 ABI destructor
4882
name. A non-zero return indicates the type of destructor. */
4884
enum gnu_v3_dtor_kinds
4885
is_gnu_v3_mangled_dtor (name)
4888
enum gnu_v3_ctor_kinds ctor_kind;
4889
enum gnu_v3_dtor_kinds dtor_kind;
4891
if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
4892
return (enum gnu_v3_dtor_kinds) 0;
4896
#endif /* IN_GLIBCPP_V3 */
4897
/* Demangler for GNU C++
4898
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
4899
2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4900
Written by James Clark (jjc@jclark.uucp)
4901
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
4902
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
4904
This file is part of the libiberty library.
4905
Libiberty is free software; you can redistribute it and/or
4906
modify it under the terms of the GNU Library General Public
4907
License as published by the Free Software Foundation; either
4908
version 2 of the License, or (at your option) any later version.
4910
In addition to the permissions in the GNU Library General Public
4911
License, the Free Software Foundation gives you unlimited permission
4912
to link the compiled version of this file into combinations with other
4913
programs, and to distribute those combinations without any restriction
4914
coming from the use of this file. (The Library Public License
4915
restrictions do apply in other respects; for example, they cover
4916
modification of the file, and distribution when not linked into a
4917
combined executable.)
4919
Libiberty is distributed in the hope that it will be useful,
4920
but WITHOUT ANY WARRANTY; without even the implied warranty of
4921
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4922
Library General Public License for more details.
4924
You should have received a copy of the GNU Library General Public
4925
License along with libiberty; see the file COPYING.LIB. If
4926
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4927
Boston, MA 02111-1307, USA. */
4929
/* This file exports two functions; cplus_mangle_opname and cplus_demangle.
4931
This file imports xmalloc and g_realloc, which are like malloc and
4932
realloc except that they generate a fatal error if there is no
4933
available memory. */
4935
/* This file lives in both GCC and libiberty. When making changes, please
4936
try not to break either. */
4938
#undef CURRENT_DEMANGLING_STYLE
4939
#define CURRENT_DEMANGLING_STYLE work->options
4941
static char *ada_demangle PARAMS ((const char *, int));
4943
#define min(X,Y) (((X) < (Y)) ? (X) : (Y))
4945
/* A value at least one greater than the maximum number of characters
4946
that will be output when using the `%d' format with `printf'. */
4947
#define INTBUF_SIZE 32
4949
extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
4951
/* In order to allow a single demangler executable to demangle strings
4952
using various common values of CPLUS_MARKER, as well as any specific
4953
one set at compile time, we maintain a string containing all the
4954
commonly used ones, and check to see if the marker we are looking for
4955
is in that string. CPLUS_MARKER is usually '$' on systems where the
4956
assembler can deal with that. Where the assembler can't, it's usually
4957
'.' (but on many systems '.' is used for other things). We put the
4958
current defined CPLUS_MARKER first (which defaults to '$'), followed
4959
by the next most common value, followed by an explicit '$' in case
4960
the value of CPLUS_MARKER is not '$'.
4962
We could avoid this if we could just get g++ to tell us what the actual
4963
cplus marker character is as part of the debug information, perhaps by
4964
ensuring that it is the character that terminates the gcc<n>_compiled
4965
marker symbol (FIXME). */
4967
#if !defined (CPLUS_MARKER)
4968
#define CPLUS_MARKER '$'
4971
static enum demangling_styles current_demangling_style = auto_demangling;
4973
static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' };
4975
static char char_str[2] = { '\000', '\000' };
4977
typedef struct string /* Beware: these aren't required to be */
4978
{ /* '\0' terminated. */
4979
char *b; /* pointer to start of string */
4980
char *p; /* pointer after last character */
4981
char *e; /* pointer after end of allocated space */
4984
/* Stuff that is shared between sub-routines.
4985
Using a shared structure allows cplus_demangle to be reentrant. */
5001
int static_type; /* A static member function */
5002
int temp_start; /* index in demangled to start of template args */
5003
int type_quals; /* The type qualifiers. */
5004
int dllimported; /* Symbol imported from a PE DLL */
5005
char **tmpl_argvec; /* Template function arguments. */
5006
int ntmpl_args; /* The number of template function arguments. */
5007
int forgetting_types; /* Nonzero if we are not remembering the types
5009
string* previous_argument; /* The last function argument demangled. */
5010
int nrepeats; /* The number of times to repeat the previous
5014
#define PRINT_ANSI_QUALIFIERS (work -> options & DMGL_ANSI)
5015
#define PRINT_ARG_TYPES (work -> options & DMGL_PARAMS)
5017
static const struct optable
5019
const char *const in;
5020
const char *const out;
5023
{"nw", " new", DMGL_ANSI}, /* new (1.92, ansi) */
5024
{"dl", " delete", DMGL_ANSI}, /* new (1.92, ansi) */
5025
{"new", " new", 0}, /* old (1.91, and 1.x) */
5026
{"delete", " delete", 0}, /* old (1.91, and 1.x) */
5027
{"vn", " new []", DMGL_ANSI}, /* GNU, pending ansi */
5028
{"vd", " delete []", DMGL_ANSI}, /* GNU, pending ansi */
5029
{"as", "=", DMGL_ANSI}, /* ansi */
5030
{"ne", "!=", DMGL_ANSI}, /* old, ansi */
5031
{"eq", "==", DMGL_ANSI}, /* old, ansi */
5032
{"ge", ">=", DMGL_ANSI}, /* old, ansi */
5033
{"gt", ">", DMGL_ANSI}, /* old, ansi */
5034
{"le", "<=", DMGL_ANSI}, /* old, ansi */
5035
{"lt", "<", DMGL_ANSI}, /* old, ansi */
5036
{"plus", "+", 0}, /* old */
5037
{"pl", "+", DMGL_ANSI}, /* ansi */
5038
{"apl", "+=", DMGL_ANSI}, /* ansi */
5039
{"minus", "-", 0}, /* old */
5040
{"mi", "-", DMGL_ANSI}, /* ansi */
5041
{"ami", "-=", DMGL_ANSI}, /* ansi */
5042
{"mult", "*", 0}, /* old */
5043
{"ml", "*", DMGL_ANSI}, /* ansi */
5044
{"amu", "*=", DMGL_ANSI}, /* ansi (ARM/Lucid) */
5045
{"aml", "*=", DMGL_ANSI}, /* ansi (GNU/g++) */
5046
{"convert", "+", 0}, /* old (unary +) */
5047
{"negate", "-", 0}, /* old (unary -) */
5048
{"trunc_mod", "%", 0}, /* old */
5049
{"md", "%", DMGL_ANSI}, /* ansi */
5050
{"amd", "%=", DMGL_ANSI}, /* ansi */
5051
{"trunc_div", "/", 0}, /* old */
5052
{"dv", "/", DMGL_ANSI}, /* ansi */
5053
{"adv", "/=", DMGL_ANSI}, /* ansi */
5054
{"truth_andif", "&&", 0}, /* old */
5055
{"aa", "&&", DMGL_ANSI}, /* ansi */
5056
{"truth_orif", "||", 0}, /* old */
5057
{"oo", "||", DMGL_ANSI}, /* ansi */
5058
{"truth_not", "!", 0}, /* old */
5059
{"nt", "!", DMGL_ANSI}, /* ansi */
5060
{"postincrement","++", 0}, /* old */
5061
{"pp", "++", DMGL_ANSI}, /* ansi */
5062
{"postdecrement","--", 0}, /* old */
5063
{"mm", "--", DMGL_ANSI}, /* ansi */
5064
{"bit_ior", "|", 0}, /* old */
5065
{"or", "|", DMGL_ANSI}, /* ansi */
5066
{"aor", "|=", DMGL_ANSI}, /* ansi */
5067
{"bit_xor", "^", 0}, /* old */
5068
{"er", "^", DMGL_ANSI}, /* ansi */
5069
{"aer", "^=", DMGL_ANSI}, /* ansi */
5070
{"bit_and", "&", 0}, /* old */
5071
{"ad", "&", DMGL_ANSI}, /* ansi */
5072
{"aad", "&=", DMGL_ANSI}, /* ansi */
5073
{"bit_not", "~", 0}, /* old */
5074
{"co", "~", DMGL_ANSI}, /* ansi */
5075
{"call", "()", 0}, /* old */
5076
{"cl", "()", DMGL_ANSI}, /* ansi */
5077
{"alshift", "<<", 0}, /* old */
5078
{"ls", "<<", DMGL_ANSI}, /* ansi */
5079
{"als", "<<=", DMGL_ANSI}, /* ansi */
5080
{"arshift", ">>", 0}, /* old */
5081
{"rs", ">>", DMGL_ANSI}, /* ansi */
5082
{"ars", ">>=", DMGL_ANSI}, /* ansi */
5083
{"component", "->", 0}, /* old */
5084
{"pt", "->", DMGL_ANSI}, /* ansi; Lucid C++ form */
5085
{"rf", "->", DMGL_ANSI}, /* ansi; ARM/GNU form */
5086
{"indirect", "*", 0}, /* old */
5087
{"method_call", "->()", 0}, /* old */
5088
{"addr", "&", 0}, /* old (unary &) */
5089
{"array", "[]", 0}, /* old */
5090
{"vc", "[]", DMGL_ANSI}, /* ansi */
5091
{"compound", ", ", 0}, /* old */
5092
{"cm", ", ", DMGL_ANSI}, /* ansi */
5093
{"cond", "?:", 0}, /* old */
5094
{"cn", "?:", DMGL_ANSI}, /* pseudo-ansi */
5095
{"max", ">?", 0}, /* old */
5096
{"mx", ">?", DMGL_ANSI}, /* pseudo-ansi */
5097
{"min", "<?", 0}, /* old */
5098
{"mn", "<?", DMGL_ANSI}, /* pseudo-ansi */
5099
{"nop", "", 0}, /* old (for operator=) */
5100
{"rm", "->*", DMGL_ANSI}, /* ansi */
5101
{"sz", "sizeof ", DMGL_ANSI} /* pseudo-ansi */
5104
/* These values are used to indicate the various type varieties.
5105
They are all non-zero so that they can be used as `success'
5107
typedef enum type_kind_t
5118
static const struct demangler_engine libiberty_demanglers[] =
5121
NO_DEMANGLING_STYLE_STRING,
5123
"Demangling disabled"
5127
AUTO_DEMANGLING_STYLE_STRING,
5129
"Automatic selection based on executable"
5133
GNU_DEMANGLING_STYLE_STRING,
5135
"GNU (g++) style demangling"
5139
LUCID_DEMANGLING_STYLE_STRING,
5141
"Lucid (lcc) style demangling"
5145
ARM_DEMANGLING_STYLE_STRING,
5147
"ARM style demangling"
5151
HP_DEMANGLING_STYLE_STRING,
5153
"HP (aCC) style demangling"
5157
EDG_DEMANGLING_STYLE_STRING,
5159
"EDG style demangling"
5163
GNU_V3_DEMANGLING_STYLE_STRING,
5165
"GNU (g++) V3 ABI-style demangling"
5169
JAVA_DEMANGLING_STYLE_STRING,
5171
"Java style demangling"
5175
GNAT_DEMANGLING_STYLE_STRING,
5177
"GNAT style demangling"
5181
NULL, unknown_demangling, NULL
5185
#define STRING_EMPTY(str) ((str) -> b == (str) -> p)
5186
#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \
5187
string_append(str, " ");}
5188
#define LEN_STRING(str) ( (STRING_EMPTY(str))?0:((str)->p - (str)->b))
5190
/* The scope separator appropriate for the language being demangled. */
5192
#define SCOPE_STRING(work) ((work->options & DMGL_JAVA) ? "." : "::")
5194
#define ARM_VTABLE_STRING "__vtbl__" /* Lucid/ARM virtual table prefix */
5195
#define ARM_VTABLE_STRLEN 8 /* strlen (ARM_VTABLE_STRING) */
5197
/* Prototypes for local functions */
5200
delete_work_stuff PARAMS ((struct work_stuff *));
5203
delete_non_B_K_work_stuff PARAMS ((struct work_stuff *));
5206
mop_up PARAMS ((struct work_stuff *, string *, int));
5209
squangle_mop_up PARAMS ((struct work_stuff *));
5212
work_stuff_copy_to_from PARAMS ((struct work_stuff *, struct work_stuff *));
5216
demangle_method_args PARAMS ((struct work_stuff *, const char **, string *));
5220
internal_cplus_demangle PARAMS ((struct work_stuff *, const char *));
5223
demangle_template_template_parm PARAMS ((struct work_stuff *work,
5224
const char **, string *));
5227
demangle_template PARAMS ((struct work_stuff *work, const char **, string *,
5228
string *, int, int));
5231
arm_pt PARAMS ((struct work_stuff *, const char *, int, const char **,
5235
demangle_class_name PARAMS ((struct work_stuff *, const char **, string *));
5238
demangle_qualified PARAMS ((struct work_stuff *, const char **, string *,
5242
demangle_class PARAMS ((struct work_stuff *, const char **, string *));
5245
demangle_fund_type PARAMS ((struct work_stuff *, const char **, string *));
5248
demangle_signature PARAMS ((struct work_stuff *, const char **, string *));
5251
demangle_prefix PARAMS ((struct work_stuff *, const char **, string *));
5254
gnu_special PARAMS ((struct work_stuff *, const char **, string *));
5257
arm_special PARAMS ((const char **, string *));
5260
string_need PARAMS ((string *, int));
5263
string_delete PARAMS ((string *));
5266
string_init PARAMS ((string *));
5269
string_clear PARAMS ((string *));
5273
string_empty PARAMS ((string *));
5277
string_append PARAMS ((string *, const char *));
5280
string_appends PARAMS ((string *, string *));
5283
string_appendn PARAMS ((string *, const char *, int));
5286
string_prepend PARAMS ((string *, const char *));
5289
string_prependn PARAMS ((string *, const char *, int));
5292
string_append_template_idx PARAMS ((string *, int));
5295
get_count PARAMS ((const char **, int *));
5298
consume_count PARAMS ((const char **));
5301
consume_count_with_underscores PARAMS ((const char**));
5304
demangle_args PARAMS ((struct work_stuff *, const char **, string *));
5307
demangle_nested_args PARAMS ((struct work_stuff*, const char**, string*));
5310
do_type PARAMS ((struct work_stuff *, const char **, string *));
5313
do_arg PARAMS ((struct work_stuff *, const char **, string *));
5316
demangle_function_name PARAMS ((struct work_stuff *, const char **, string *,
5320
iterate_demangle_function PARAMS ((struct work_stuff *,
5321
const char **, string *, const char *));
5324
remember_type PARAMS ((struct work_stuff *, const char *, int));
5327
remember_Btype PARAMS ((struct work_stuff *, const char *, int, int));
5330
register_Btype PARAMS ((struct work_stuff *));
5333
remember_Ktype PARAMS ((struct work_stuff *, const char *, int));
5336
forget_types PARAMS ((struct work_stuff *));
5339
forget_B_and_K_types PARAMS ((struct work_stuff *));
5342
string_prepends PARAMS ((string *, string *));
5345
demangle_template_value_parm PARAMS ((struct work_stuff*, const char**,
5346
string*, type_kind_t));
5349
do_hpacc_template_const_value PARAMS ((struct work_stuff *, const char **, string *));
5352
do_hpacc_template_literal PARAMS ((struct work_stuff *, const char **, string *));
5355
snarf_numeric_literal PARAMS ((const char **, string *));
5357
/* There is a TYPE_QUAL value for each type qualifier. They can be
5358
combined by bitwise-or to form the complete set of qualifiers for a
5361
#define TYPE_UNQUALIFIED 0x0
5362
#define TYPE_QUAL_CONST 0x1
5363
#define TYPE_QUAL_VOLATILE 0x2
5364
#define TYPE_QUAL_RESTRICT 0x4
5367
code_for_qualifier PARAMS ((int));
5370
qualifier_string PARAMS ((int));
5373
demangle_qualifier PARAMS ((int));
5376
demangle_expression PARAMS ((struct work_stuff *, const char **, string *,
5380
demangle_integral_value PARAMS ((struct work_stuff *, const char **,
5384
demangle_real_value PARAMS ((struct work_stuff *, const char **, string *));
5387
demangle_arm_hp_template PARAMS ((struct work_stuff *, const char **, int,
5391
recursively_demangle PARAMS ((struct work_stuff *, const char **, string *,
5395
grow_vect PARAMS ((char **, size_t *, size_t, int));
5397
/* Translate count to integer, consuming tokens in the process.
5398
Conversion terminates on the first non-digit character.
5400
Trying to consume something that isn't a count results in no
5401
consumption of input and a return of -1.
5403
Overflow consumes the rest of the digits, and returns -1. */
5406
consume_count (type)
5411
if (! g_ascii_isdigit ((unsigned char)**type))
5414
while (g_ascii_isdigit ((unsigned char)**type))
5418
/* Check for overflow.
5419
We assume that count is represented using two's-complement;
5420
no power of two is divisible by ten, so if an overflow occurs
5421
when multiplying by ten, the result will not be a multiple of
5423
if ((count % 10) != 0)
5425
while (g_ascii_isdigit ((unsigned char) **type))
5430
count += **type - '0';
5441
/* Like consume_count, but for counts that are preceded and followed
5442
by '_' if they are greater than 10. Also, -1 is returned for
5443
failure, since 0 can be a valid value. */
5446
consume_count_with_underscores (mangled)
5447
const char **mangled;
5451
if (**mangled == '_')
5454
if (!g_ascii_isdigit ((unsigned char)**mangled))
5457
idx = consume_count (mangled);
5458
if (**mangled != '_')
5459
/* The trailing underscore was missing. */
5466
if (**mangled < '0' || **mangled > '9')
5469
idx = **mangled - '0';
5476
/* C is the code for a type-qualifier. Return the TYPE_QUAL
5477
corresponding to this qualifier. */
5480
code_for_qualifier (c)
5486
return TYPE_QUAL_CONST;
5489
return TYPE_QUAL_VOLATILE;
5492
return TYPE_QUAL_RESTRICT;
5498
/* C was an invalid qualifier. */
5502
/* Return the string corresponding to the qualifiers given by
5506
qualifier_string (type_quals)
5511
case TYPE_UNQUALIFIED:
5514
case TYPE_QUAL_CONST:
5517
case TYPE_QUAL_VOLATILE:
5520
case TYPE_QUAL_RESTRICT:
5521
return "__restrict";
5523
case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE:
5524
return "const volatile";
5526
case TYPE_QUAL_CONST | TYPE_QUAL_RESTRICT:
5527
return "const __restrict";
5529
case TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
5530
return "volatile __restrict";
5532
case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
5533
return "const volatile __restrict";
5539
/* TYPE_QUALS was an invalid qualifier set. */
5543
/* C is the code for a type-qualifier. Return the string
5544
corresponding to this qualifier. This function should only be
5545
called with a valid qualifier code. */
5548
demangle_qualifier (c)
5551
return qualifier_string (code_for_qualifier (c));
5554
/* Takes operator name as e.g. "++" and returns mangled
5555
operator name (e.g. "postincrement_expr"), or NULL if not found.
5557
If OPTIONS & DMGL_ANSI == 1, return the ANSI name;
5558
if OPTIONS & DMGL_ANSI == 0, return the old GNU name. */
5560
/* Add a routine to set the demangling style to be sure it is valid and
5561
allow for any demangler initialization that maybe necessary. */
5563
/* Do string name to style translation */
5565
/* char *cplus_demangle (const char *mangled, int options)
5567
If MANGLED is a mangled function name produced by GNU C++, then
5568
a pointer to a @code{malloc}ed string giving a C++ representation
5569
of the name will be returned; otherwise NULL will be returned.
5570
It is the caller's responsibility to free the string which
5573
The OPTIONS arg may contain one or more of the following bits:
5575
DMGL_ANSI ANSI qualifiers such as `const' and `void' are
5577
DMGL_PARAMS Function parameters are included.
5581
cplus_demangle ("foo__1Ai", DMGL_PARAMS) => "A::foo(int)"
5582
cplus_demangle ("foo__1Ai", DMGL_PARAMS | DMGL_ANSI) => "A::foo(int)"
5583
cplus_demangle ("foo__1Ai", 0) => "A::foo"
5585
cplus_demangle ("foo__1Afe", DMGL_PARAMS) => "A::foo(float,...)"
5586
cplus_demangle ("foo__1Afe", DMGL_PARAMS | DMGL_ANSI)=> "A::foo(float,...)"
5587
cplus_demangle ("foo__1Afe", 0) => "A::foo"
5589
Note that any leading underscores, or other such characters prepended by
5590
the compilation system, are presumed to have already been stripped from
5594
sysprof_cplus_demangle (mangled, options)
5595
const char *mangled;
5599
struct work_stuff work[1];
5601
if (current_demangling_style == no_demangling)
5602
return g_strdup (mangled);
5604
memset ((char *) work, 0, sizeof (work));
5605
work->options = options;
5606
if ((work->options & DMGL_STYLE_MASK) == 0)
5607
work->options |= (int) current_demangling_style & DMGL_STYLE_MASK;
5609
/* The V3 ABI demangling is implemented elsewhere. */
5610
if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
5612
ret = cplus_demangle_v3 (mangled, work->options);
5613
if (ret || GNU_V3_DEMANGLING)
5617
if (JAVA_DEMANGLING)
5619
ret = java_demangle_v3 (mangled);
5624
if (GNAT_DEMANGLING)
5625
return ada_demangle(mangled,options);
5627
ret = internal_cplus_demangle (work, mangled);
5628
squangle_mop_up (work);
5633
/* Assuming *OLD_VECT points to an array of *SIZE objects of size
5634
ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
5635
updating *OLD_VECT and *SIZE as necessary. */
5638
grow_vect (old_vect, size, min_size, element_size)
5644
if (*size < min_size)
5647
if (*size < min_size)
5649
*old_vect = (void *) g_realloc (*old_vect, *size * element_size);
5653
/* Demangle ada names:
5654
1. Discard final __{DIGIT}+ or ${DIGIT}+
5655
2. Convert other instances of embedded "__" to `.'.
5656
3. Discard leading _ada_.
5657
4. Remove everything after first ___ if it is followed by 'X'.
5658
5. Put symbols that should be suppressed in <...> brackets.
5659
The resulting string is valid until the next call of ada_demangle. */
5662
ada_demangle (mangled, option)
5663
const char *mangled;
5664
int option ATTRIBUTE_UNUSED;
5669
char *demangled = NULL;
5671
size_t demangled_size = 0;
5675
if (strncmp (mangled, "_ada_", 5) == 0)
5681
if (mangled[0] == '_' || mangled[0] == '<')
5684
p = strstr (mangled, "___");
5686
len0 = strlen (mangled);
5698
/* Make demangled big enough for possible expansion by operator name. */
5699
grow_vect (&demangled,
5700
&demangled_size, 2 * len0 + 1,
5703
if (g_ascii_isdigit ((unsigned char) mangled[len0 - 1])) {
5704
for (i = len0 - 2; i >= 0 && g_ascii_isdigit ((unsigned char) mangled[i]); i -= 1)
5706
if (i > 1 && mangled[i] == '_' && mangled[i - 1] == '_')
5711
else if (mangled[i] == '$')
5718
for (i = 0, j = 0; i < len0 && ! g_ascii_isalpha ((unsigned char)mangled[i]);
5720
demangled[j] = mangled[i];
5724
if (i < len0 - 2 && mangled[i] == '_' && mangled[i + 1] == '_')
5732
demangled[j] = mangled[i];
5736
demangled[j] = '\000';
5738
for (i = 0; demangled[i] != '\0'; i += 1)
5739
if (g_ascii_isupper ((unsigned char)demangled[i]) || demangled[i] == ' ')
5748
grow_vect (&demangled,
5749
&demangled_size, strlen (mangled) + 3,
5752
if (mangled[0] == '<')
5753
strcpy (demangled, mangled);
5755
sprintf (demangled, "<%s>", mangled);
5760
/* This function performs most of what cplus_demangle use to do, but
5761
to be able to demangle a name with a B, K or n code, we need to
5762
have a longer term memory of what types have been seen. The original
5763
now initializes and cleans up the squangle code info, while internal
5764
calls go directly to this routine to avoid resetting that info. */
5767
internal_cplus_demangle (work, mangled)
5768
struct work_stuff *work;
5769
const char *mangled;
5774
char *demangled = NULL;
5776
s1 = work->constructor;
5777
s2 = work->destructor;
5778
s3 = work->static_type;
5779
s4 = work->type_quals;
5780
work->constructor = work->destructor = 0;
5781
work->type_quals = TYPE_UNQUALIFIED;
5782
work->dllimported = 0;
5784
if ((mangled != NULL) && (*mangled != '\0'))
5786
string_init (&decl);
5788
/* First check to see if gnu style demangling is active and if the
5789
string to be demangled contains a CPLUS_MARKER. If so, attempt to
5790
recognize one of the gnu special forms rather than looking for a
5791
standard prefix. In particular, don't worry about whether there
5792
is a "__" string in the mangled string. Consider "_$_5__foo" for
5795
if ((AUTO_DEMANGLING || GNU_DEMANGLING))
5797
success = gnu_special (work, &mangled, &decl);
5801
success = demangle_prefix (work, &mangled, &decl);
5803
if (success && (*mangled != '\0'))
5805
success = demangle_signature (work, &mangled, &decl);
5807
if (work->constructor == 2)
5809
string_prepend (&decl, "global constructors keyed to ");
5810
work->constructor = 0;
5812
else if (work->destructor == 2)
5814
string_prepend (&decl, "global destructors keyed to ");
5815
work->destructor = 0;
5817
else if (work->dllimported == 1)
5819
string_prepend (&decl, "import stub for ");
5820
work->dllimported = 0;
5822
demangled = mop_up (work, &decl, success);
5824
work->constructor = s1;
5825
work->destructor = s2;
5826
work->static_type = s3;
5827
work->type_quals = s4;
5832
/* Clear out and squangling related storage */
5834
squangle_mop_up (work)
5835
struct work_stuff *work;
5837
/* clean up the B and K type mangling types. */
5838
forget_B_and_K_types (work);
5839
if (work -> btypevec != NULL)
5841
g_free ((char *) work -> btypevec);
5843
if (work -> ktypevec != NULL)
5845
g_free ((char *) work -> ktypevec);
5850
/* Copy the work state and storage. */
5853
work_stuff_copy_to_from (to, from)
5854
struct work_stuff *to;
5855
struct work_stuff *from;
5859
delete_work_stuff (to);
5861
/* Shallow-copy scalars. */
5862
memcpy (to, from, sizeof (*to));
5864
/* Deep-copy dynamic storage. */
5865
if (from->typevec_size)
5867
= (char **) g_malloc (from->typevec_size * sizeof (to->typevec[0]));
5869
for (i = 0; i < from->ntypes; i++)
5871
int len = strlen (from->typevec[i]) + 1;
5873
to->typevec[i] = g_malloc (len);
5874
memcpy (to->typevec[i], from->typevec[i], len);
5879
= (char **) g_malloc (from->ksize * sizeof (to->ktypevec[0]));
5881
for (i = 0; i < from->numk; i++)
5883
int len = strlen (from->ktypevec[i]) + 1;
5885
to->ktypevec[i] = g_malloc (len);
5886
memcpy (to->ktypevec[i], from->ktypevec[i], len);
5891
= (char **) g_malloc (from->bsize * sizeof (to->btypevec[0]));
5893
for (i = 0; i < from->numb; i++)
5895
int len = strlen (from->btypevec[i]) + 1;
5897
to->btypevec[i] = g_malloc (len);
5898
memcpy (to->btypevec[i], from->btypevec[i], len);
5901
if (from->ntmpl_args)
5903
= (char **) g_malloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
5905
for (i = 0; i < from->ntmpl_args; i++)
5907
int len = strlen (from->tmpl_argvec[i]) + 1;
5909
to->tmpl_argvec[i] = g_malloc (len);
5910
memcpy (to->tmpl_argvec[i], from->tmpl_argvec[i], len);
5913
if (from->previous_argument)
5915
to->previous_argument = (string*) g_malloc (sizeof (string));
5916
string_init (to->previous_argument);
5917
string_appends (to->previous_argument, from->previous_argument);
5922
/* Delete dynamic stuff in work_stuff that is not to be re-used. */
5925
delete_non_B_K_work_stuff (work)
5926
struct work_stuff *work;
5928
/* Discard the remembered types, if any. */
5930
forget_types (work);
5931
if (work -> typevec != NULL)
5933
g_free ((char *) work -> typevec);
5934
work -> typevec = NULL;
5935
work -> typevec_size = 0;
5937
if (work->tmpl_argvec)
5941
for (i = 0; i < work->ntmpl_args; i++)
5942
if (work->tmpl_argvec[i])
5943
g_free ((char*) work->tmpl_argvec[i]);
5945
g_free ((char*) work->tmpl_argvec);
5946
work->tmpl_argvec = NULL;
5948
if (work->previous_argument)
5950
string_delete (work->previous_argument);
5951
g_free ((char*) work->previous_argument);
5952
work->previous_argument = NULL;
5957
/* Delete all dynamic storage in work_stuff. */
5959
delete_work_stuff (work)
5960
struct work_stuff *work;
5962
delete_non_B_K_work_stuff (work);
5963
squangle_mop_up (work);
5967
/* Clear out any mangled storage */
5970
mop_up (work, declp, success)
5971
struct work_stuff *work;
5975
char *demangled = NULL;
5977
delete_non_B_K_work_stuff (work);
5979
/* If demangling was successful, ensure that the demangled string is null
5980
terminated and return it. Otherwise, free the demangling decl. */
5984
string_delete (declp);
5988
string_appendn (declp, "", 1);
5989
demangled = declp->b;
5998
demangle_signature -- demangle the signature part of a mangled name
6003
demangle_signature (struct work_stuff *work, const char **mangled,
6008
Consume and demangle the signature portion of the mangled name.
6010
DECLP is the string where demangled output is being built. At
6011
entry it contains the demangled root name from the mangled name
6012
prefix. I.E. either a demangled operator name or the root function
6013
name. In some special cases, it may contain nothing.
6015
*MANGLED points to the current unconsumed location in the mangled
6016
name. As tokens are consumed and demangling is performed, the
6017
pointer is updated to continuously point at the next token to
6020
Demangling GNU style mangled names is nasty because there is no
6021
explicit token that marks the start of the outermost function
6025
demangle_signature (work, mangled, declp)
6026
struct work_stuff *work;
6027
const char **mangled;
6032
int expect_func = 0;
6033
int expect_return_type = 0;
6034
const char *oldmangled = NULL;
6038
while (success && (**mangled != '\0'))
6043
oldmangled = *mangled;
6044
success = demangle_qualified (work, mangled, declp, 1, 0);
6046
remember_type (work, oldmangled, *mangled - oldmangled);
6047
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6053
oldmangled = *mangled;
6054
success = demangle_qualified (work, mangled, declp, 1, 0);
6055
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6063
/* Static member function */
6064
if (oldmangled == NULL)
6066
oldmangled = *mangled;
6069
work -> static_type = 1;
6075
work->type_quals |= code_for_qualifier (**mangled);
6077
/* a qualified member function */
6078
if (oldmangled == NULL)
6079
oldmangled = *mangled;
6084
/* Local class name follows after "Lnnn_" */
6087
while (**mangled && (**mangled != '_'))
6098
case '0': case '1': case '2': case '3': case '4':
6099
case '5': case '6': case '7': case '8': case '9':
6100
if (oldmangled == NULL)
6102
oldmangled = *mangled;
6104
work->temp_start = -1; /* uppermost call to demangle_class */
6105
success = demangle_class (work, mangled, declp);
6108
remember_type (work, oldmangled, *mangled - oldmangled);
6110
if (AUTO_DEMANGLING || GNU_DEMANGLING || EDG_DEMANGLING)
6112
/* EDG and others will have the "F", so we let the loop cycle
6113
if we are looking at one. */
6114
if (**mangled != 'F')
6123
success = do_type (work, mangled, &s);
6126
string_append (&s, SCOPE_STRING (work));
6127
string_prepends (declp, &s);
6137
/* ARM/HP style demangling includes a specific 'F' character after
6138
the class name. For GNU style, it is just implied. So we can
6139
safely just consume any 'F' at this point and be compatible
6140
with either style. */
6146
/* For lucid/ARM/HP style we have to forget any types we might
6147
have remembered up to this point, since they were not argument
6148
types. GNU style considers all types seen as available for
6149
back references. See comment in demangle_args() */
6151
if (LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING)
6153
forget_types (work);
6155
success = demangle_args (work, mangled, declp);
6156
/* After picking off the function args, we expect to either
6157
find the function return type (preceded by an '_') or the
6158
end of the string. */
6159
if (success && (AUTO_DEMANGLING || EDG_DEMANGLING) && **mangled == '_')
6162
/* At this level, we do not care about the return type. */
6163
success = do_type (work, mangled, &tname);
6164
string_delete (&tname);
6171
string_init(&trawname);
6172
string_init(&tname);
6173
if (oldmangled == NULL)
6175
oldmangled = *mangled;
6177
success = demangle_template (work, mangled, &tname,
6181
remember_type (work, oldmangled, *mangled - oldmangled);
6183
string_append (&tname, SCOPE_STRING (work));
6185
string_prepends(declp, &tname);
6186
if (work -> destructor & 1)
6188
string_prepend (&trawname, "~");
6189
string_appends (declp, &trawname);
6190
work->destructor -= 1;
6192
if ((work->constructor & 1) || (work->destructor & 1))
6194
string_appends (declp, &trawname);
6195
work->constructor -= 1;
6197
string_delete(&trawname);
6198
string_delete(&tname);
6204
if ((AUTO_DEMANGLING || GNU_DEMANGLING) && expect_return_type)
6206
/* Read the return type. */
6210
success = do_type (work, mangled, &return_type);
6211
APPEND_BLANK (&return_type);
6213
string_prepends (declp, &return_type);
6214
string_delete (&return_type);
6218
/* At the outermost level, we cannot have a return type specified,
6219
so if we run into another '_' at this point we are dealing with
6220
a mangled name that is either bogus, or has been mangled by
6221
some algorithm we don't know how to deal with. So just
6222
reject the entire demangling. */
6223
/* However, "_nnn" is an expected suffix for alternate entry point
6224
numbered nnn for a function, with HP aCC, so skip over that
6225
without reporting failure. pai/1997-09-04 */
6229
while (**mangled && g_ascii_isdigit ((unsigned char)**mangled))
6237
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6239
/* A G++ template function. Read the template arguments. */
6240
success = demangle_template (work, mangled, declp, 0, 0,
6242
if (!(work->constructor & 1))
6243
expect_return_type = 1;
6252
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6254
/* Assume we have stumbled onto the first outermost function
6255
argument token, and start processing args. */
6257
success = demangle_args (work, mangled, declp);
6261
/* Non-GNU demanglers use a specific token to mark the start
6262
of the outermost function argument tokens. Typically 'F',
6263
for ARM/HP-demangling, for example. So if we find something
6264
we are not prepared for, it must be an error. */
6270
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6273
if (success && expect_func)
6276
if (LUCID_DEMANGLING || ARM_DEMANGLING || EDG_DEMANGLING)
6278
forget_types (work);
6280
success = demangle_args (work, mangled, declp);
6281
/* Since template include the mangling of their return types,
6282
we must set expect_func to 0 so that we don't try do
6283
demangle more arguments the next time we get here. */
6288
if (success && !func_done)
6290
if (AUTO_DEMANGLING || GNU_DEMANGLING)
6292
/* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
6293
bar__3fooi is 'foo::bar(int)'. We get here when we find the
6294
first case, and need to ensure that the '(void)' gets added to
6295
the current declp. Note that with ARM/HP, the first case
6296
represents the name of a static data member 'foo::bar',
6297
which is in the current declp, so we leave it alone. */
6298
success = demangle_args (work, mangled, declp);
6301
if (success && PRINT_ARG_TYPES)
6303
if (work->static_type)
6304
string_append (declp, " static");
6305
if (work->type_quals != TYPE_UNQUALIFIED)
6307
APPEND_BLANK (declp);
6308
string_append (declp, qualifier_string (work->type_quals));
6318
demangle_method_args (work, mangled, declp)
6319
struct work_stuff *work;
6320
const char **mangled;
6325
if (work -> static_type)
6327
string_append (declp, *mangled + 1);
6328
*mangled += strlen (*mangled);
6333
success = demangle_args (work, mangled, declp);
6341
demangle_template_template_parm (work, mangled, tname)
6342
struct work_stuff *work;
6343
const char **mangled;
6352
string_append (tname, "template <");
6353
/* get size of template parameter list */
6354
if (get_count (mangled, &r))
6356
for (i = 0; i < r; i++)
6360
string_append (tname, ", ");
6363
/* Z for type parameters */
6364
if (**mangled == 'Z')
6367
string_append (tname, "class");
6369
/* z for template parameters */
6370
else if (**mangled == 'z')
6374
demangle_template_template_parm (work, mangled, tname);
6382
/* temp is initialized in do_type */
6383
success = do_type (work, mangled, &temp);
6386
string_appends (tname, &temp);
6388
string_delete(&temp);
6398
if (tname->p[-1] == '>')
6399
string_append (tname, " ");
6400
string_append (tname, "> class");
6405
demangle_expression (work, mangled, s, tk)
6406
struct work_stuff *work;
6407
const char** mangled;
6411
int need_operator = 0;
6415
string_appendn (s, "(", 1);
6417
while (success && **mangled != 'W' && **mangled != '\0')
6426
len = strlen (*mangled);
6428
for (i = 0; i < G_N_ELEMENTS (optable); ++i)
6430
size_t l = strlen (optable[i].in);
6433
&& memcmp (optable[i].in, *mangled, l) == 0)
6435
string_appendn (s, " ", 1);
6436
string_append (s, optable[i].out);
6437
string_appendn (s, " ", 1);
6450
success = demangle_template_value_parm (work, mangled, s, tk);
6453
if (**mangled != 'W')
6457
string_appendn (s, ")", 1);
6465
demangle_integral_value (work, mangled, s)
6466
struct work_stuff *work;
6467
const char** mangled;
6472
if (**mangled == 'E')
6473
success = demangle_expression (work, mangled, s, tk_integral);
6474
else if (**mangled == 'Q' || **mangled == 'K')
6475
success = demangle_qualified (work, mangled, s, 0, 1);
6480
/* By default, we let the number decide whether we shall consume an
6482
int multidigit_without_leading_underscore = 0;
6483
int leave_following_underscore = 0;
6487
if (**mangled == '_')
6489
if (mangled[0][1] == 'm')
6491
/* Since consume_count_with_underscores does not handle the
6492
`m'-prefix we must do it here, using consume_count and
6493
adjusting underscores: we have to consume the underscore
6494
matching the prepended one. */
6495
multidigit_without_leading_underscore = 1;
6496
string_appendn (s, "-", 1);
6501
/* Do not consume a following underscore;
6502
consume_count_with_underscores will consume what
6503
should be consumed. */
6504
leave_following_underscore = 1;
6509
/* Negative numbers are indicated with a leading `m'. */
6510
if (**mangled == 'm')
6512
string_appendn (s, "-", 1);
6515
/* Since consume_count_with_underscores does not handle
6516
multi-digit numbers that do not start with an underscore,
6517
and this number can be an integer template parameter,
6518
we have to call consume_count. */
6519
multidigit_without_leading_underscore = 1;
6520
/* These multi-digit numbers never end on an underscore,
6521
so if there is one then don't eat it. */
6522
leave_following_underscore = 1;
6525
/* We must call consume_count if we expect to remove a trailing
6526
underscore, since consume_count_with_underscores expects
6527
the leading underscore (that we consumed) if it is to handle
6528
multi-digit numbers. */
6529
if (multidigit_without_leading_underscore)
6530
value = consume_count (mangled);
6532
value = consume_count_with_underscores (mangled);
6536
char buf[INTBUF_SIZE];
6537
sprintf (buf, "%d", value);
6538
string_append (s, buf);
6540
/* Numbers not otherwise delimited, might have an underscore
6541
appended as a delimeter, which we should skip.
6543
??? This used to always remove a following underscore, which
6544
is wrong. If other (arbitrary) cases are followed by an
6545
underscore, we need to do something more radical. */
6547
if ((value > 9 || multidigit_without_leading_underscore)
6548
&& ! leave_following_underscore
6549
&& **mangled == '_')
6560
/* Demangle the real value in MANGLED. */
6563
demangle_real_value (work, mangled, s)
6564
struct work_stuff *work;
6565
const char **mangled;
6568
if (**mangled == 'E')
6569
return demangle_expression (work, mangled, s, tk_real);
6571
if (**mangled == 'm')
6573
string_appendn (s, "-", 1);
6576
while (g_ascii_isdigit ((unsigned char)**mangled))
6578
string_appendn (s, *mangled, 1);
6581
if (**mangled == '.') /* fraction */
6583
string_appendn (s, ".", 1);
6585
while (g_ascii_isdigit ((unsigned char)**mangled))
6587
string_appendn (s, *mangled, 1);
6591
if (**mangled == 'e') /* exponent */
6593
string_appendn (s, "e", 1);
6595
while (g_ascii_isdigit ((unsigned char)**mangled))
6597
string_appendn (s, *mangled, 1);
6606
demangle_template_value_parm (work, mangled, s, tk)
6607
struct work_stuff *work;
6608
const char **mangled;
6614
if (**mangled == 'Y')
6616
/* The next argument is a template parameter. */
6620
idx = consume_count_with_underscores (mangled);
6622
|| (work->tmpl_argvec && idx >= work->ntmpl_args)
6623
|| consume_count_with_underscores (mangled) == -1)
6625
if (work->tmpl_argvec)
6626
string_append (s, work->tmpl_argvec[idx]);
6628
string_append_template_idx (s, idx);
6630
else if (tk == tk_integral)
6631
success = demangle_integral_value (work, mangled, s);
6632
else if (tk == tk_char)
6636
if (**mangled == 'm')
6638
string_appendn (s, "-", 1);
6641
string_appendn (s, "'", 1);
6642
val = consume_count(mangled);
6649
string_appendn (s, &tmp[0], 1);
6650
string_appendn (s, "'", 1);
6653
else if (tk == tk_bool)
6655
int val = consume_count (mangled);
6657
string_appendn (s, "false", 5);
6659
string_appendn (s, "true", 4);
6663
else if (tk == tk_real)
6664
success = demangle_real_value (work, mangled, s);
6665
else if (tk == tk_pointer || tk == tk_reference)
6667
if (**mangled == 'Q')
6668
success = demangle_qualified (work, mangled, s,
6673
int symbol_len = consume_count (mangled);
6674
if (symbol_len == -1)
6676
if (symbol_len == 0)
6677
string_appendn (s, "0", 1);
6680
char *p = g_malloc (symbol_len + 1), *q;
6681
strncpy (p, *mangled, symbol_len);
6682
p [symbol_len] = '\0';
6683
/* We use cplus_demangle here, rather than
6684
internal_cplus_demangle, because the name of the entity
6685
mangled here does not make use of any of the squangling
6686
or type-code information we have built up thus far; it is
6687
mangled independently. */
6688
q = sysprof_cplus_demangle (p, work->options);
6689
if (tk == tk_pointer)
6690
string_appendn (s, "&", 1);
6691
/* FIXME: Pointer-to-member constants should get a
6692
qualifying class name here. */
6695
string_append (s, q);
6699
string_append (s, p);
6702
*mangled += symbol_len;
6709
/* Demangle the template name in MANGLED. The full name of the
6710
template (e.g., S<int>) is placed in TNAME. The name without the
6711
template parameters (e.g. S) is placed in TRAWNAME if TRAWNAME is
6712
non-NULL. If IS_TYPE is nonzero, this template is a type template,
6713
not a function template. If both IS_TYPE and REMEMBER are nonzero,
6714
the template is remembered in the list of back-referenceable
6718
demangle_template (work, mangled, tname, trawname, is_type, remember)
6719
struct work_stuff *work;
6720
const char **mangled;
6730
int is_java_array = 0;
6736
/* get template name */
6737
if (**mangled == 'z')
6743
idx = consume_count_with_underscores (mangled);
6745
|| (work->tmpl_argvec && idx >= work->ntmpl_args)
6746
|| consume_count_with_underscores (mangled) == -1)
6749
if (work->tmpl_argvec)
6751
string_append (tname, work->tmpl_argvec[idx]);
6753
string_append (trawname, work->tmpl_argvec[idx]);
6757
string_append_template_idx (tname, idx);
6759
string_append_template_idx (trawname, idx);
6764
if ((r = consume_count (mangled)) <= 0
6765
|| (int) strlen (*mangled) < r)
6769
is_java_array = (work -> options & DMGL_JAVA)
6770
&& strncmp (*mangled, "JArray1Z", 8) == 0;
6771
if (! is_java_array)
6773
string_appendn (tname, *mangled, r);
6776
string_appendn (trawname, *mangled, r);
6781
string_append (tname, "<");
6782
/* get size of template parameter list */
6783
if (!get_count (mangled, &r))
6789
/* Create an array for saving the template argument values. */
6790
work->tmpl_argvec = (char**) g_malloc (r * sizeof (char *));
6791
work->ntmpl_args = r;
6792
for (i = 0; i < r; i++)
6793
work->tmpl_argvec[i] = 0;
6795
for (i = 0; i < r; i++)
6799
string_append (tname, ", ");
6801
/* Z for type parameters */
6802
if (**mangled == 'Z')
6805
/* temp is initialized in do_type */
6806
success = do_type (work, mangled, &temp);
6809
string_appends (tname, &temp);
6813
/* Save the template argument. */
6814
int len = temp.p - temp.b;
6815
work->tmpl_argvec[i] = g_malloc (len + 1);
6816
memcpy (work->tmpl_argvec[i], temp.b, len);
6817
work->tmpl_argvec[i][len] = '\0';
6820
string_delete(&temp);
6826
/* z for template parameters */
6827
else if (**mangled == 'z')
6831
success = demangle_template_template_parm (work, mangled, tname);
6834
&& (r2 = consume_count (mangled)) > 0
6835
&& (int) strlen (*mangled) >= r2)
6837
string_append (tname, " ");
6838
string_appendn (tname, *mangled, r2);
6841
/* Save the template argument. */
6843
work->tmpl_argvec[i] = g_malloc (len + 1);
6844
memcpy (work->tmpl_argvec[i], *mangled, len);
6845
work->tmpl_argvec[i][len] = '\0';
6859
/* otherwise, value parameter */
6861
/* temp is initialized in do_type */
6862
success = do_type (work, mangled, &temp);
6863
string_delete(&temp);
6875
success = demangle_template_value_parm (work, mangled, s,
6876
(type_kind_t) success);
6888
int len = s->p - s->b;
6889
work->tmpl_argvec[i] = g_malloc (len + 1);
6890
memcpy (work->tmpl_argvec[i], s->b, len);
6891
work->tmpl_argvec[i][len] = '\0';
6893
string_appends (tname, s);
6901
string_append (tname, "[]");
6905
if (tname->p[-1] == '>')
6906
string_append (tname, " ");
6907
string_append (tname, ">");
6910
if (is_type && remember)
6912
const int bindex = register_Btype (work);
6913
remember_Btype (work, tname->b, LEN_STRING (tname), bindex);
6917
if (work -> static_type)
6919
string_append (declp, *mangled + 1);
6920
*mangled += strlen (*mangled);
6925
success = demangle_args (work, mangled, declp);
6933
arm_pt (work, mangled, n, anchor, args)
6934
struct work_stuff *work;
6935
const char *mangled;
6937
const char **anchor, **args;
6939
/* Check if ARM template with "__pt__" in it ("parameterized type") */
6940
/* Allow HP also here, because HP's cfront compiler follows ARM to some extent */
6941
if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = strstr (mangled, "__pt__")))
6944
*args = *anchor + 6;
6945
len = consume_count (args);
6948
if (*args + len == mangled + n && **args == '_')
6954
if (AUTO_DEMANGLING || EDG_DEMANGLING)
6956
if ((*anchor = strstr (mangled, "__tm__"))
6957
|| (*anchor = strstr (mangled, "__ps__"))
6958
|| (*anchor = strstr (mangled, "__pt__")))
6961
*args = *anchor + 6;
6962
len = consume_count (args);
6965
if (*args + len == mangled + n && **args == '_')
6971
else if ((*anchor = strstr (mangled, "__S")))
6974
*args = *anchor + 3;
6975
len = consume_count (args);
6978
if (*args + len == mangled + n && **args == '_')
6990
demangle_arm_hp_template (work, mangled, n, declp)
6991
struct work_stuff *work;
6992
const char **mangled;
6998
const char *e = *mangled + n;
7001
/* Check for HP aCC template spec: classXt1t2 where t1, t2 are
7003
if (HP_DEMANGLING && ((*mangled)[n] == 'X'))
7005
char *start_spec_args = NULL;
7008
/* First check for and omit template specialization pseudo-arguments,
7009
such as in "Spec<#1,#1.*>" */
7010
start_spec_args = strchr (*mangled, '<');
7011
if (start_spec_args && (start_spec_args - *mangled < n))
7012
string_appendn (declp, *mangled, start_spec_args - *mangled);
7014
string_appendn (declp, *mangled, n);
7015
(*mangled) += n + 1;
7017
if (work->temp_start == -1) /* non-recursive call */
7018
work->temp_start = declp->p - declp->b;
7020
/* We want to unconditionally demangle parameter types in
7021
template parameters. */
7022
hold_options = work->options;
7023
work->options |= DMGL_PARAMS;
7025
string_append (declp, "<");
7028
string_delete (&arg);
7032
/* 'T' signals a type parameter */
7034
if (!do_type (work, mangled, &arg))
7035
goto hpacc_template_args_done;
7040
/* 'U' or 'S' signals an integral value */
7041
if (!do_hpacc_template_const_value (work, mangled, &arg))
7042
goto hpacc_template_args_done;
7046
/* 'A' signals a named constant expression (literal) */
7047
if (!do_hpacc_template_literal (work, mangled, &arg))
7048
goto hpacc_template_args_done;
7052
/* Today, 1997-09-03, we have only the above types
7053
of template parameters */
7054
/* FIXME: maybe this should fail and return null */
7055
goto hpacc_template_args_done;
7057
string_appends (declp, &arg);
7058
/* Check if we're at the end of template args.
7059
0 if at end of static member of template class,
7060
_ if done with template args for a function */
7061
if ((**mangled == '\000') || (**mangled == '_'))
7064
string_append (declp, ",");
7066
hpacc_template_args_done:
7067
string_append (declp, ">");
7068
string_delete (&arg);
7069
if (**mangled == '_')
7071
work->options = hold_options;
7074
/* ARM template? (Also handles HP cfront extensions) */
7075
else if (arm_pt (work, *mangled, n, &p, &args))
7081
string_appendn (declp, *mangled, p - *mangled);
7082
if (work->temp_start == -1) /* non-recursive call */
7083
work->temp_start = declp->p - declp->b;
7085
/* We want to unconditionally demangle parameter types in
7086
template parameters. */
7087
hold_options = work->options;
7088
work->options |= DMGL_PARAMS;
7090
string_append (declp, "<");
7091
/* should do error checking here */
7093
string_delete (&arg);
7095
/* Check for type or literal here */
7098
/* HP cfront extensions to ARM for template args */
7099
/* spec: Xt1Lv1 where t1 is a type, v1 is a literal value */
7100
/* FIXME: We handle only numeric literals for HP cfront */
7102
/* A typed constant value follows */
7104
if (!do_type (work, &args, &type_str))
7105
goto cfront_template_args_done;
7106
string_append (&arg, "(");
7107
string_appends (&arg, &type_str);
7108
string_delete (&type_str);
7109
string_append (&arg, ")");
7111
goto cfront_template_args_done;
7113
/* Now snarf a literal value following 'L' */
7114
if (!snarf_numeric_literal (&args, &arg))
7115
goto cfront_template_args_done;
7119
/* Snarf a literal following 'L' */
7121
if (!snarf_numeric_literal (&args, &arg))
7122
goto cfront_template_args_done;
7125
/* Not handling other HP cfront stuff */
7127
const char* old_args = args;
7128
if (!do_type (work, &args, &arg))
7129
goto cfront_template_args_done;
7131
/* Fail if we didn't make any progress: prevent infinite loop. */
7132
if (args == old_args)
7134
work->options = hold_options;
7139
string_appends (declp, &arg);
7140
string_append (declp, ",");
7142
cfront_template_args_done:
7143
string_delete (&arg);
7145
--declp->p; /* remove extra comma */
7146
string_append (declp, ">");
7147
work->options = hold_options;
7149
else if (n>10 && strncmp (*mangled, "_GLOBAL_", 8) == 0
7150
&& (*mangled)[9] == 'N'
7151
&& (*mangled)[8] == (*mangled)[10]
7152
&& strchr (cplus_markers, (*mangled)[8]))
7154
/* A member of the anonymous namespace. */
7155
string_append (declp, "{anonymous}");
7159
if (work->temp_start == -1) /* non-recursive call only */
7160
work->temp_start = 0; /* disable in recursive calls */
7161
string_appendn (declp, *mangled, n);
7166
/* Extract a class name, possibly a template with arguments, from the
7167
mangled string; qualifiers, local class indicators, etc. have
7168
already been dealt with */
7171
demangle_class_name (work, mangled, declp)
7172
struct work_stuff *work;
7173
const char **mangled;
7179
n = consume_count (mangled);
7182
if ((int) strlen (*mangled) >= n)
7184
demangle_arm_hp_template (work, mangled, n, declp);
7195
demangle_class -- demangle a mangled class sequence
7200
demangle_class (struct work_stuff *work, const char **mangled,
7205
DECLP points to the buffer into which demangling is being done.
7207
*MANGLED points to the current token to be demangled. On input,
7208
it points to a mangled class (I.E. "3foo", "13verylongclass", etc.)
7209
On exit, it points to the next token after the mangled class on
7210
success, or the first unconsumed token on failure.
7212
If the CONSTRUCTOR or DESTRUCTOR flags are set in WORK, then
7213
we are demangling a constructor or destructor. In this case
7214
we prepend "class::class" or "class::~class" to DECLP.
7216
Otherwise, we prepend "class::" to the current DECLP.
7218
Reset the constructor/destructor flags once they have been
7219
"consumed". This allows demangle_class to be called later during
7220
the same demangling, to do normal class demangling.
7222
Returns 1 if demangling is successful, 0 otherwise.
7227
demangle_class (work, mangled, declp)
7228
struct work_stuff *work;
7229
const char **mangled;
7235
char *save_class_name_end = 0;
7237
string_init (&class_name);
7238
btype = register_Btype (work);
7239
if (demangle_class_name (work, mangled, &class_name))
7241
save_class_name_end = class_name.p;
7242
if ((work->constructor & 1) || (work->destructor & 1))
7244
/* adjust so we don't include template args */
7245
if (work->temp_start && (work->temp_start != -1))
7247
class_name.p = class_name.b + work->temp_start;
7249
string_prepends (declp, &class_name);
7250
if (work -> destructor & 1)
7252
string_prepend (declp, "~");
7253
work -> destructor -= 1;
7257
work -> constructor -= 1;
7260
class_name.p = save_class_name_end;
7261
remember_Ktype (work, class_name.b, LEN_STRING(&class_name));
7262
remember_Btype (work, class_name.b, LEN_STRING(&class_name), btype);
7263
string_prepend (declp, SCOPE_STRING (work));
7264
string_prepends (declp, &class_name);
7267
string_delete (&class_name);
7272
/* Called when there's a "__" in the mangled name, with `scan' pointing to
7273
the rightmost guess.
7275
Find the correct "__"-sequence where the function name ends and the
7276
signature starts, which is ambiguous with GNU mangling.
7277
Call demangle_signature here, so we can make sure we found the right
7278
one; *mangled will be consumed so caller will not make further calls to
7279
demangle_signature. */
7282
iterate_demangle_function (work, mangled, declp, scan)
7283
struct work_stuff *work;
7284
const char **mangled;
7288
const char *mangle_init = *mangled;
7291
struct work_stuff work_init;
7293
if (*(scan + 2) == '\0')
7296
/* Do not iterate for some demangling modes, or if there's only one
7297
"__"-sequence. This is the normal case. */
7298
if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
7299
|| strstr (scan + 2, "__") == NULL)
7301
demangle_function_name (work, mangled, declp, scan);
7305
/* Save state so we can restart if the guess at the correct "__" was
7307
string_init (&decl_init);
7308
string_appends (&decl_init, declp);
7309
memset (&work_init, 0, sizeof work_init);
7310
work_stuff_copy_to_from (&work_init, work);
7312
/* Iterate over occurrences of __, allowing names and types to have a
7313
"__" sequence in them. We must start with the first (not the last)
7314
occurrence, since "__" most often occur between independent mangled
7315
parts, hence starting at the last occurence inside a signature
7316
might get us a "successful" demangling of the signature. */
7320
demangle_function_name (work, mangled, declp, scan);
7321
success = demangle_signature (work, mangled, declp);
7325
/* Reset demangle state for the next round. */
7326
*mangled = mangle_init;
7327
string_clear (declp);
7328
string_appends (declp, &decl_init);
7329
work_stuff_copy_to_from (work, &work_init);
7331
/* Leave this underscore-sequence. */
7334
/* Scan for the next "__" sequence. */
7335
while (*scan && (scan[0] != '_' || scan[1] != '_'))
7338
/* Move to last "__" in this sequence. */
7339
while (*scan && *scan == '_')
7344
/* Delete saved state. */
7345
delete_work_stuff (&work_init);
7346
string_delete (&decl_init);
7355
demangle_prefix -- consume the mangled name prefix and find signature
7360
demangle_prefix (struct work_stuff *work, const char **mangled,
7365
Consume and demangle the prefix of the mangled name.
7366
While processing the function name root, arrange to call
7367
demangle_signature if the root is ambiguous.
7369
DECLP points to the string buffer into which demangled output is
7370
placed. On entry, the buffer is empty. On exit it contains
7371
the root function name, the demangled operator name, or in some
7372
special cases either nothing or the completely demangled result.
7374
MANGLED points to the current pointer into the mangled name. As each
7375
token of the mangled name is consumed, it is updated. Upon entry
7376
the current mangled name pointer points to the first character of
7377
the mangled name. Upon exit, it should point to the first character
7378
of the signature if demangling was successful, or to the first
7379
unconsumed character if demangling of the prefix was unsuccessful.
7381
Returns 1 on success, 0 otherwise.
7385
demangle_prefix (work, mangled, declp)
7386
struct work_stuff *work;
7387
const char **mangled;
7394
if (strlen(*mangled) > 6
7395
&& (strncmp(*mangled, "_imp__", 6) == 0
7396
|| strncmp(*mangled, "__imp_", 6) == 0))
7398
/* it's a symbol imported from a PE dynamic library. Check for both
7399
new style prefix _imp__ and legacy __imp_ used by older versions
7402
work->dllimported = 1;
7404
else if (strlen(*mangled) >= 11 && strncmp(*mangled, "_GLOBAL_", 8) == 0)
7406
char *marker = strchr (cplus_markers, (*mangled)[8]);
7407
if (marker != NULL && *marker == (*mangled)[10])
7409
if ((*mangled)[9] == 'D')
7411
/* it's a GNU global destructor to be executed at program exit */
7413
work->destructor = 2;
7414
if (gnu_special (work, mangled, declp))
7417
else if ((*mangled)[9] == 'I')
7419
/* it's a GNU global constructor to be executed at program init */
7421
work->constructor = 2;
7422
if (gnu_special (work, mangled, declp))
7427
else if ((ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING) && strncmp(*mangled, "__std__", 7) == 0)
7429
/* it's a ARM global destructor to be executed at program exit */
7431
work->destructor = 2;
7433
else if ((ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING) && strncmp(*mangled, "__sti__", 7) == 0)
7435
/* it's a ARM global constructor to be executed at program initial */
7437
work->constructor = 2;
7440
/* This block of code is a reduction in strength time optimization
7442
scan = strstr (*mangled, "__"); */
7448
scan = strchr (scan, '_');
7449
} while (scan != NULL && *++scan != '_');
7451
if (scan != NULL) --scan;
7456
/* We found a sequence of two or more '_', ensure that we start at
7457
the last pair in the sequence. */
7458
i = strspn (scan, "_");
7469
else if (work -> static_type)
7471
if (!g_ascii_isdigit ((unsigned char)scan[0]) && (scan[0] != 't'))
7476
else if ((scan == *mangled)
7477
&& (g_ascii_isdigit ((unsigned char)scan[2]) || (scan[2] == 'Q')
7478
|| (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H')))
7480
/* The ARM says nothing about the mangling of local variables.
7481
But cfront mangles local variables by prepending __<nesting_level>
7482
to them. As an extension to ARM demangling we handle this case. */
7483
if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
7484
&& g_ascii_isdigit ((unsigned char)scan[2]))
7486
*mangled = scan + 2;
7487
consume_count (mangled);
7488
string_append (declp, *mangled);
7489
*mangled += strlen (*mangled);
7494
/* A GNU style constructor starts with __[0-9Qt]. But cfront uses
7495
names like __Q2_3foo3bar for nested type names. So don't accept
7496
this style of constructor for cfront demangling. A GNU
7497
style member-template constructor starts with 'H'. */
7498
if (!(LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING))
7499
work -> constructor += 1;
7500
*mangled = scan + 2;
7503
else if (ARM_DEMANGLING && scan[2] == 'p' && scan[3] == 't')
7505
/* Cfront-style parameterized type. Handled later as a signature. */
7509
demangle_arm_hp_template (work, mangled, strlen (*mangled), declp);
7511
else if (EDG_DEMANGLING && ((scan[2] == 't' && scan[3] == 'm')
7512
|| (scan[2] == 'p' && scan[3] == 's')
7513
|| (scan[2] == 'p' && scan[3] == 't')))
7515
/* EDG-style parameterized type. Handled later as a signature. */
7519
demangle_arm_hp_template (work, mangled, strlen (*mangled), declp);
7521
else if ((scan == *mangled) && !g_ascii_isdigit ((unsigned char)scan[2])
7522
&& (scan[2] != 't'))
7524
/* Mangled name starts with "__". Skip over any leading '_' characters,
7525
then find the next "__" that separates the prefix from the signature.
7527
if (!(ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING)
7528
|| (arm_special (mangled, declp) == 0))
7530
while (*scan == '_')
7534
if ((scan = strstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
7536
/* No separator (I.E. "__not_mangled"), or empty signature
7537
(I.E. "__not_mangled_either__") */
7541
return iterate_demangle_function (work, mangled, declp, scan);
7544
else if (*(scan + 2) != '\0')
7546
/* Mangled name does not start with "__" but does have one somewhere
7547
in there with non empty stuff after it. Looks like a global
7548
function name. Iterate over all "__":s until the right
7550
return iterate_demangle_function (work, mangled, declp, scan);
7554
/* Doesn't look like a mangled name */
7558
if (!success && (work->constructor == 2 || work->destructor == 2))
7560
string_append (declp, *mangled);
7561
*mangled += strlen (*mangled);
7571
gnu_special -- special handling of gnu mangled strings
7576
gnu_special (struct work_stuff *work, const char **mangled,
7582
Process some special GNU style mangling forms that don't fit
7583
the normal pattern. For example:
7585
_$_3foo (destructor for class foo)
7586
_vt$foo (foo virtual table)
7587
_vt$foo$bar (foo::bar virtual table)
7588
__vt_foo (foo virtual table, new style with thunks)
7589
_3foo$varname (static data member)
7590
_Q22rs2tu$vw (static data member)
7591
__t6vector1Zii (constructor with template)
7592
__thunk_4__$_7ostream (virtual function thunk)
7596
gnu_special (work, mangled, declp)
7597
struct work_stuff *work;
7598
const char **mangled;
7605
if ((*mangled)[0] == '_'
7606
&& strchr (cplus_markers, (*mangled)[1]) != NULL
7607
&& (*mangled)[2] == '_')
7609
/* Found a GNU style destructor, get past "_<CPLUS_MARKER>_" */
7611
work -> destructor += 1;
7613
else if ((*mangled)[0] == '_'
7614
&& (((*mangled)[1] == '_'
7615
&& (*mangled)[2] == 'v'
7616
&& (*mangled)[3] == 't'
7617
&& (*mangled)[4] == '_')
7618
|| ((*mangled)[1] == 'v'
7619
&& (*mangled)[2] == 't'
7620
&& strchr (cplus_markers, (*mangled)[3]) != NULL)))
7622
/* Found a GNU style virtual table, get past "_vt<CPLUS_MARKER>"
7623
and create the decl. Note that we consume the entire mangled
7624
input string, which means that demangle_signature has no work
7626
if ((*mangled)[2] == 'v')
7627
(*mangled) += 5; /* New style, with thunks: "__vt_" */
7629
(*mangled) += 4; /* Old style, no thunks: "_vt<CPLUS_MARKER>" */
7630
while (**mangled != '\0')
7636
success = demangle_qualified (work, mangled, declp, 0, 1);
7639
success = demangle_template (work, mangled, declp, 0, 1,
7643
if (g_ascii_isdigit((unsigned char)*mangled[0]))
7645
n = consume_count(mangled);
7646
/* We may be seeing a too-large size, or else a
7647
".<digits>" indicating a static local symbol. In
7648
any case, declare victory and move on; *don't* try
7649
to use n to allocate. */
7650
if (n > (int) strlen (*mangled))
7658
n = strcspn (*mangled, cplus_markers);
7660
string_appendn (declp, *mangled, n);
7664
p = strpbrk (*mangled, cplus_markers);
7665
if (success && ((p == NULL) || (p == *mangled)))
7669
string_append (declp, SCOPE_STRING (work));
7680
string_append (declp, " virtual table");
7682
else if ((*mangled)[0] == '_'
7683
&& (strchr("0123456789Qt", (*mangled)[1]) != NULL)
7684
&& (p = strpbrk (*mangled, cplus_markers)) != NULL)
7686
/* static data member, "_3foo$varname" for example */
7692
success = demangle_qualified (work, mangled, declp, 0, 1);
7695
success = demangle_template (work, mangled, declp, 0, 1, 1);
7698
n = consume_count (mangled);
7699
if (n < 0 || n > (long) strlen (*mangled))
7705
if (n > 10 && strncmp (*mangled, "_GLOBAL_", 8) == 0
7706
&& (*mangled)[9] == 'N'
7707
&& (*mangled)[8] == (*mangled)[10]
7708
&& strchr (cplus_markers, (*mangled)[8]))
7710
/* A member of the anonymous namespace. There's information
7711
about what identifier or filename it was keyed to, but
7712
it's just there to make the mangled name unique; we just
7714
string_append (declp, "{anonymous}");
7717
/* Now p points to the marker before the N, so we need to
7718
update it to the first marker after what we consumed. */
7719
p = strpbrk (*mangled, cplus_markers);
7723
string_appendn (declp, *mangled, n);
7726
if (success && (p == *mangled))
7728
/* Consumed everything up to the cplus_marker, append the
7731
string_append (declp, SCOPE_STRING (work));
7732
n = strlen (*mangled);
7733
string_appendn (declp, *mangled, n);
7741
else if (strncmp (*mangled, "__thunk_", 8) == 0)
7746
delta = consume_count (mangled);
7751
char *method = internal_cplus_demangle (work, ++*mangled);
7756
sprintf (buf, "virtual function thunk (delta:%d) for ", -delta);
7757
string_append (declp, buf);
7758
string_append (declp, method);
7760
n = strlen (*mangled);
7769
else if (strncmp (*mangled, "__t", 3) == 0
7770
&& ((*mangled)[3] == 'i' || (*mangled)[3] == 'f'))
7772
p = (*mangled)[3] == 'i' ? " type_info node" : " type_info function";
7778
success = demangle_qualified (work, mangled, declp, 0, 1);
7781
success = demangle_template (work, mangled, declp, 0, 1, 1);
7784
success = do_type (work, mangled, declp);
7787
if (success && **mangled != '\0')
7790
string_append (declp, p);
7800
recursively_demangle(work, mangled, result, namelength)
7801
struct work_stuff *work;
7802
const char **mangled;
7806
char * recurse = (char *)NULL;
7807
char * recurse_dem = (char *)NULL;
7809
recurse = (char *) g_malloc (namelength + 1);
7810
memcpy (recurse, *mangled, namelength);
7811
recurse[namelength] = '\000';
7813
recurse_dem = sysprof_cplus_demangle (recurse, work->options);
7817
string_append (result, recurse_dem);
7818
g_free (recurse_dem);
7822
string_appendn (result, *mangled, namelength);
7825
*mangled += namelength;
7832
arm_special -- special handling of ARM/lucid mangled strings
7837
arm_special (const char **mangled,
7843
Process some special ARM style mangling forms that don't fit
7844
the normal pattern. For example:
7846
__vtbl__3foo (foo virtual table)
7847
__vtbl__3foo__3bar (bar::foo virtual table)
7852
arm_special (mangled, declp)
7853
const char **mangled;
7860
if (strncmp (*mangled, ARM_VTABLE_STRING, ARM_VTABLE_STRLEN) == 0)
7862
/* Found a ARM style virtual table, get past ARM_VTABLE_STRING
7863
and create the decl. Note that we consume the entire mangled
7864
input string, which means that demangle_signature has no work
7866
scan = *mangled + ARM_VTABLE_STRLEN;
7867
while (*scan != '\0') /* first check it can be demangled */
7869
n = consume_count (&scan);
7872
return (0); /* no good */
7875
if (scan[0] == '_' && scan[1] == '_')
7880
(*mangled) += ARM_VTABLE_STRLEN;
7881
while (**mangled != '\0')
7883
n = consume_count (mangled);
7885
|| n > (long) strlen (*mangled))
7887
string_prependn (declp, *mangled, n);
7889
if ((*mangled)[0] == '_' && (*mangled)[1] == '_')
7891
string_prepend (declp, "::");
7895
string_append (declp, " virtual table");
7908
demangle_qualified -- demangle 'Q' qualified name strings
7913
demangle_qualified (struct work_stuff *, const char *mangled,
7914
string *result, int isfuncname, int append);
7918
Demangle a qualified name, such as "Q25Outer5Inner" which is
7919
the mangled form of "Outer::Inner". The demangled output is
7920
prepended or appended to the result string according to the
7921
state of the append flag.
7923
If isfuncname is nonzero, then the qualified name we are building
7924
is going to be used as a member function name, so if it is a
7925
constructor or destructor function, append an appropriate
7926
constructor or destructor name. I.E. for the above example,
7927
the result for use as a constructor is "Outer::Inner::Inner"
7928
and the result for use as a destructor is "Outer::Inner::~Inner".
7932
Numeric conversion is ASCII dependent (FIXME).
7937
demangle_qualified (work, mangled, result, isfuncname, append)
7938
struct work_stuff *work;
7939
const char **mangled;
7949
int bindex = register_Btype (work);
7951
/* We only make use of ISFUNCNAME if the entity is a constructor or
7953
isfuncname = (isfuncname
7954
&& ((work->constructor & 1) || (work->destructor & 1)));
7956
string_init (&temp);
7957
string_init (&last_name);
7959
if ((*mangled)[0] == 'K')
7961
/* Squangling qualified name reuse */
7964
idx = consume_count_with_underscores (mangled);
7965
if (idx == -1 || idx >= work -> numk)
7968
string_append (&temp, work -> ktypevec[idx]);
7971
switch ((*mangled)[1])
7974
/* GNU mangled name with more than 9 classes. The count is preceded
7975
by an underscore (to distinguish it from the <= 9 case) and followed
7976
by an underscore. */
7978
qualifiers = consume_count_with_underscores (mangled);
7979
if (qualifiers == -1)
7992
/* The count is in a single digit. */
7993
num[0] = (*mangled)[1];
7995
qualifiers = atoi (num);
7997
/* If there is an underscore after the digit, skip it. This is
7998
said to be for ARM-qualified names, but the ARM makes no
7999
mention of such an underscore. Perhaps cfront uses one. */
8000
if ((*mangled)[2] == '_')
8015
/* Pick off the names and collect them in the temp buffer in the order
8016
in which they are found, separated by '::'. */
8018
while (qualifiers-- > 0)
8021
string_clear (&last_name);
8023
if (*mangled[0] == '_')
8026
if (*mangled[0] == 't')
8028
/* Here we always append to TEMP since we will want to use
8029
the template name without the template parameters as a
8030
constructor or destructor name. The appropriate
8031
(parameter-less) value is returned by demangle_template
8032
in LAST_NAME. We do not remember the template type here,
8033
in order to match the G++ mangling algorithm. */
8034
success = demangle_template(work, mangled, &temp,
8039
else if (*mangled[0] == 'K')
8043
idx = consume_count_with_underscores (mangled);
8044
if (idx == -1 || idx >= work->numk)
8047
string_append (&temp, work->ktypevec[idx]);
8050
if (!success) break;
8057
/* Now recursively demangle the qualifier
8058
* This is necessary to deal with templates in
8059
* mangling styles like EDG */
8060
namelength = consume_count (mangled);
8061
if (namelength == -1)
8066
recursively_demangle(work, mangled, &temp, namelength);
8070
string_delete (&last_name);
8071
success = do_type (work, mangled, &last_name);
8074
string_appends (&temp, &last_name);
8079
remember_Ktype (work, temp.b, LEN_STRING (&temp));
8082
string_append (&temp, SCOPE_STRING (work));
8085
remember_Btype (work, temp.b, LEN_STRING (&temp), bindex);
8087
/* If we are using the result as a function name, we need to append
8088
the appropriate '::' separated constructor or destructor name.
8089
We do this here because this is the most convenient place, where
8090
we already have a pointer to the name and the length of the name. */
8094
string_append (&temp, SCOPE_STRING (work));
8095
if (work -> destructor & 1)
8096
string_append (&temp, "~");
8097
string_appends (&temp, &last_name);
8100
/* Now either prepend the temp buffer to the result, or append it,
8101
depending upon the state of the append flag. */
8104
string_appends (result, &temp);
8107
if (!STRING_EMPTY (result))
8108
string_append (&temp, SCOPE_STRING (work));
8109
string_prepends (result, &temp);
8112
string_delete (&last_name);
8113
string_delete (&temp);
8121
get_count -- convert an ascii count to integer, consuming tokens
8126
get_count (const char **type, int *count)
8130
Assume that *type points at a count in a mangled name; set
8131
*count to its value, and set *type to the next character after
8132
the count. There are some weird rules in effect here.
8134
If *type does not point at a string of digits, return zero.
8136
If *type points at a string of digits followed by an
8137
underscore, set *count to their value as an integer, advance
8138
*type to point *after the underscore, and return 1.
8140
If *type points at a string of digits not followed by an
8141
underscore, consume only the first digit. Set *count to its
8142
value as an integer, leave *type pointing after that digit,
8145
The excuse for this odd behavior: in the ARM and HP demangling
8146
styles, a type can be followed by a repeat count of the form
8149
`x' is a single digit specifying how many additional copies
8150
of the type to append to the argument list, and
8152
`y' is one or more digits, specifying the zero-based index of
8153
the first repeated argument in the list. Yes, as you're
8154
unmangling the name you can figure this out yourself, but
8157
So, for example, in `bar__3fooFPiN51', the first argument is a
8158
pointer to an integer (`Pi'), and then the next five arguments
8159
are the same (`N5'), and the first repeat is the function's
8160
second argument (`1').
8164
get_count (type, count)
8171
if (!g_ascii_isdigit ((unsigned char)**type))
8175
*count = **type - '0';
8177
if (g_ascii_isdigit ((unsigned char)**type))
8187
while (g_ascii_isdigit ((unsigned char)*p));
8198
/* RESULT will be initialised here; it will be freed on failure. The
8199
value returned is really a type_kind_t. */
8202
do_type (work, mangled, result)
8203
struct work_stuff *work;
8204
const char **mangled;
8211
const char *remembered_type;
8213
type_kind_t tk = tk_none;
8215
string_init (&decl);
8216
string_init (result);
8220
while (success && !done)
8226
/* A pointer type */
8230
if (! (work -> options & DMGL_JAVA))
8231
string_prepend (&decl, "*");
8236
/* A reference type */
8239
string_prepend (&decl, "&");
8248
if (!STRING_EMPTY (&decl)
8249
&& (decl.b[0] == '*' || decl.b[0] == '&'))
8251
string_prepend (&decl, "(");
8252
string_append (&decl, ")");
8254
string_append (&decl, "[");
8255
if (**mangled != '_')
8256
success = demangle_template_value_parm (work, mangled, &decl,
8258
if (**mangled == '_')
8260
string_append (&decl, "]");
8264
/* A back reference to a previously seen type */
8267
if (!get_count (mangled, &n) || n >= work -> ntypes)
8273
remembered_type = work -> typevec[n];
8274
mangled = &remembered_type;
8281
if (!STRING_EMPTY (&decl)
8282
&& (decl.b[0] == '*' || decl.b[0] == '&'))
8284
string_prepend (&decl, "(");
8285
string_append (&decl, ")");
8287
/* After picking off the function args, we expect to either find the
8288
function return type (preceded by an '_') or the end of the
8290
if (!demangle_nested_args (work, mangled, &decl)
8291
|| (**mangled != '_' && **mangled != '\0'))
8296
if (success && (**mangled == '_'))
8303
type_quals = TYPE_UNQUALIFIED;
8305
member = **mangled == 'M';
8308
string_append (&decl, ")");
8310
/* We don't need to prepend `::' for a qualified name;
8311
demangle_qualified will do that for us. */
8312
if (**mangled != 'Q')
8313
string_prepend (&decl, SCOPE_STRING (work));
8315
if (g_ascii_isdigit ((unsigned char)**mangled))
8317
n = consume_count (mangled);
8319
|| (int) strlen (*mangled) < n)
8324
string_prependn (&decl, *mangled, n);
8327
else if (**mangled == 'X' || **mangled == 'Y')
8330
do_type (work, mangled, &temp);
8331
string_prepends (&decl, &temp);
8332
string_delete (&temp);
8334
else if (**mangled == 't')
8337
string_init (&temp);
8338
success = demangle_template (work, mangled, &temp,
8342
string_prependn (&decl, temp.b, temp.p - temp.b);
8343
string_delete (&temp);
8348
else if (**mangled == 'Q')
8350
success = demangle_qualified (work, mangled, &decl,
8362
string_prepend (&decl, "(");
8370
type_quals |= code_for_qualifier (**mangled);
8378
if (*(*mangled)++ != 'F')
8384
if ((member && !demangle_nested_args (work, mangled, &decl))
8385
|| **mangled != '_')
8391
if (! PRINT_ANSI_QUALIFIERS)
8395
if (type_quals != TYPE_UNQUALIFIED)
8397
APPEND_BLANK (&decl);
8398
string_append (&decl, qualifier_string (type_quals));
8409
if (PRINT_ANSI_QUALIFIERS)
8411
if (!STRING_EMPTY (&decl))
8412
string_prepend (&decl, " ");
8414
string_prepend (&decl, demangle_qualifier (**mangled));
8429
if (success) switch (**mangled)
8431
/* A qualified name, such as "Outer::Inner". */
8435
success = demangle_qualified (work, mangled, result, 0, 1);
8439
/* A back reference to a previously seen squangled type */
8442
if (!get_count (mangled, &n) || n >= work -> numb)
8445
string_append (result, work->btypevec[n]);
8450
/* A template parm. We substitute the corresponding argument. */
8455
idx = consume_count_with_underscores (mangled);
8458
|| (work->tmpl_argvec && idx >= work->ntmpl_args)
8459
|| consume_count_with_underscores (mangled) == -1)
8465
if (work->tmpl_argvec)
8466
string_append (result, work->tmpl_argvec[idx]);
8468
string_append_template_idx (result, idx);
8475
success = demangle_fund_type (work, mangled, result);
8477
tk = (type_kind_t) success;
8483
if (!STRING_EMPTY (&decl))
8485
string_append (result, " ");
8486
string_appends (result, &decl);
8490
string_delete (result);
8491
string_delete (&decl);
8494
/* Assume an integral type, if we're not sure. */
8495
return (int) ((tk == tk_none) ? tk_integral : tk);
8500
/* Given a pointer to a type string that represents a fundamental type
8501
argument (int, long, unsigned int, etc) in TYPE, a pointer to the
8502
string in which the demangled output is being built in RESULT, and
8503
the WORK structure, decode the types and add them to the result.
8508
"Sl" => "signed long"
8509
"CUs" => "const unsigned short"
8511
The value returned is really a type_kind_t. */
8514
demangle_fund_type (work, mangled, result)
8515
struct work_stuff *work;
8516
const char **mangled;
8522
unsigned int dec = 0;
8523
type_kind_t tk = tk_integral;
8525
/* First pick off any type qualifiers. There can be more than one. */
8534
if (PRINT_ANSI_QUALIFIERS)
8536
if (!STRING_EMPTY (result))
8537
string_prepend (result, " ");
8538
string_prepend (result, demangle_qualifier (**mangled));
8544
APPEND_BLANK (result);
8545
string_append (result, "unsigned");
8547
case 'S': /* signed char only */
8549
APPEND_BLANK (result);
8550
string_append (result, "signed");
8554
APPEND_BLANK (result);
8555
string_append (result, "__complex");
8563
/* Now pick off the fundamental type. There can be only one. */
8572
APPEND_BLANK (result);
8573
string_append (result, "void");
8577
APPEND_BLANK (result);
8578
string_append (result, "long long");
8582
APPEND_BLANK (result);
8583
string_append (result, "long");
8587
APPEND_BLANK (result);
8588
string_append (result, "int");
8592
APPEND_BLANK (result);
8593
string_append (result, "short");
8597
APPEND_BLANK (result);
8598
string_append (result, "bool");
8603
APPEND_BLANK (result);
8604
string_append (result, "char");
8609
APPEND_BLANK (result);
8610
string_append (result, "wchar_t");
8615
APPEND_BLANK (result);
8616
string_append (result, "long double");
8621
APPEND_BLANK (result);
8622
string_append (result, "double");
8627
APPEND_BLANK (result);
8628
string_append (result, "float");
8633
if (!g_ascii_isdigit ((unsigned char)**mangled))
8640
if (**mangled == '_')
8645
i < (long) sizeof (buf) - 1 && **mangled && **mangled != '_';
8648
if (**mangled != '_')
8658
strncpy (buf, *mangled, 2);
8660
*mangled += min (strlen (*mangled), 2);
8662
sscanf (buf, "%x", &dec);
8663
sprintf (buf, "int%u_t", dec);
8664
APPEND_BLANK (result);
8665
string_append (result, buf);
8669
/* An explicit type, such as "6mytype" or "7integer" */
8681
int bindex = register_Btype (work);
8683
string_init (&btype);
8684
if (demangle_class_name (work, mangled, &btype)) {
8685
remember_Btype (work, btype.b, LEN_STRING (&btype), bindex);
8686
APPEND_BLANK (result);
8687
string_appends (result, &btype);
8691
string_delete (&btype);
8697
string_init (&btype);
8698
success = demangle_template (work, mangled, &btype, 0, 1, 1);
8699
string_appends (result, &btype);
8700
string_delete (&btype);
8708
return success ? ((int) tk) : 0;
8712
/* Handle a template's value parameter for HP aCC (extension from ARM)
8713
**mangled points to 'S' or 'U' */
8716
do_hpacc_template_const_value (work, mangled, result)
8717
struct work_stuff *work ATTRIBUTE_UNUSED;
8718
const char **mangled;
8723
if (**mangled != 'U' && **mangled != 'S')
8726
unsigned_const = (**mangled == 'U');
8733
string_append (result, "-");
8739
/* special case for -2^31 */
8740
string_append (result, "-2147483648");
8747
/* We have to be looking at an integer now */
8748
if (!(g_ascii_isdigit ((unsigned char)**mangled)))
8751
/* We only deal with integral values for template
8752
parameters -- so it's OK to look only for digits */
8753
while (g_ascii_isdigit ((unsigned char)**mangled))
8755
char_str[0] = **mangled;
8756
string_append (result, char_str);
8761
string_append (result, "U");
8763
/* FIXME? Some day we may have 64-bit (or larger :-) ) constants
8764
with L or LL suffixes. pai/1997-09-03 */
8766
return 1; /* success */
8769
/* Handle a template's literal parameter for HP aCC (extension from ARM)
8770
**mangled is pointing to the 'A' */
8773
do_hpacc_template_literal (work, mangled, result)
8774
struct work_stuff *work;
8775
const char **mangled;
8778
int literal_len = 0;
8782
if (**mangled != 'A')
8787
literal_len = consume_count (mangled);
8789
if (literal_len <= 0)
8792
/* Literal parameters are names of arrays, functions, etc. and the
8793
canonical representation uses the address operator */
8794
string_append (result, "&");
8796
/* Now recursively demangle the literal name */
8797
recurse = (char *) g_malloc (literal_len + 1);
8798
memcpy (recurse, *mangled, literal_len);
8799
recurse[literal_len] = '\000';
8801
recurse_dem = sysprof_cplus_demangle (recurse, work->options);
8805
string_append (result, recurse_dem);
8806
g_free (recurse_dem);
8810
string_appendn (result, *mangled, literal_len);
8812
(*mangled) += literal_len;
8819
snarf_numeric_literal (args, arg)
8826
string_append (arg, char_str);
8829
else if (**args == '+')
8832
if (!g_ascii_isdigit ((unsigned char)**args))
8835
while (g_ascii_isdigit ((unsigned char)**args))
8837
char_str[0] = **args;
8838
string_append (arg, char_str);
8845
/* Demangle the next argument, given by MANGLED into RESULT, which
8846
*should be an uninitialized* string. It will be initialized here,
8847
and free'd should anything go wrong. */
8850
do_arg (work, mangled, result)
8851
struct work_stuff *work;
8852
const char **mangled;
8855
/* Remember where we started so that we can record the type, for
8856
non-squangling type remembering. */
8857
const char *start = *mangled;
8859
string_init (result);
8861
if (work->nrepeats > 0)
8865
if (work->previous_argument == 0)
8868
/* We want to reissue the previous type in this argument list. */
8869
string_appends (result, work->previous_argument);
8873
if (**mangled == 'n')
8875
/* A squangling-style repeat. */
8877
work->nrepeats = consume_count(mangled);
8879
if (work->nrepeats <= 0)
8880
/* This was not a repeat count after all. */
8883
if (work->nrepeats > 9)
8885
if (**mangled != '_')
8886
/* The repeat count should be followed by an '_' in this
8893
/* Now, the repeat is all set up. */
8894
return do_arg (work, mangled, result);
8897
/* Save the result in WORK->previous_argument so that we can find it
8898
if it's repeated. Note that saving START is not good enough: we
8899
do not want to add additional types to the back-referenceable
8900
type vector when processing a repeated type. */
8901
if (work->previous_argument)
8902
string_delete (work->previous_argument);
8904
work->previous_argument = (string*) g_malloc (sizeof (string));
8906
if (!do_type (work, mangled, work->previous_argument))
8909
string_appends (result, work->previous_argument);
8911
remember_type (work, start, *mangled - start);
8916
remember_type (work, start, len)
8917
struct work_stuff *work;
8923
if (work->forgetting_types)
8926
if (work -> ntypes >= work -> typevec_size)
8928
if (work -> typevec_size == 0)
8930
work -> typevec_size = 3;
8932
= (char **) g_malloc (sizeof (char *) * work -> typevec_size);
8936
work -> typevec_size *= 2;
8938
= (char **) g_realloc ((char *)work -> typevec,
8939
sizeof (char *) * work -> typevec_size);
8942
tem = g_malloc (len + 1);
8943
memcpy (tem, start, len);
8945
work -> typevec[work -> ntypes++] = tem;
8949
/* Remember a K type class qualifier. */
8951
remember_Ktype (work, start, len)
8952
struct work_stuff *work;
8958
if (work -> numk >= work -> ksize)
8960
if (work -> ksize == 0)
8964
= (char **) g_malloc (sizeof (char *) * work -> ksize);
8970
= (char **) g_realloc ((char *)work -> ktypevec,
8971
sizeof (char *) * work -> ksize);
8974
tem = g_malloc (len + 1);
8975
memcpy (tem, start, len);
8977
work -> ktypevec[work -> numk++] = tem;
8980
/* Register a B code, and get an index for it. B codes are registered
8981
as they are seen, rather than as they are completed, so map<temp<char> >
8982
registers map<temp<char> > as B0, and temp<char> as B1 */
8985
register_Btype (work)
8986
struct work_stuff *work;
8990
if (work -> numb >= work -> bsize)
8992
if (work -> bsize == 0)
8996
= (char **) g_malloc (sizeof (char *) * work -> bsize);
9002
= (char **) g_realloc ((char *)work -> btypevec,
9003
sizeof (char *) * work -> bsize);
9006
ret = work -> numb++;
9007
work -> btypevec[ret] = NULL;
9011
/* Store a value into a previously registered B code type. */
9014
remember_Btype (work, start, len, index)
9015
struct work_stuff *work;
9021
tem = g_malloc (len + 1);
9022
memcpy (tem, start, len);
9024
work -> btypevec[index] = tem;
9027
/* Lose all the info related to B and K type codes. */
9029
forget_B_and_K_types (work)
9030
struct work_stuff *work;
9034
while (work -> numk > 0)
9036
i = --(work -> numk);
9037
if (work -> ktypevec[i] != NULL)
9039
g_free (work -> ktypevec[i]);
9040
work -> ktypevec[i] = NULL;
9044
while (work -> numb > 0)
9046
i = --(work -> numb);
9047
if (work -> btypevec[i] != NULL)
9049
g_free (work -> btypevec[i]);
9050
work -> btypevec[i] = NULL;
9054
/* Forget the remembered types, but not the type vector itself. */
9058
struct work_stuff *work;
9062
while (work -> ntypes > 0)
9064
i = --(work -> ntypes);
9065
if (work -> typevec[i] != NULL)
9067
g_free (work -> typevec[i]);
9068
work -> typevec[i] = NULL;
9073
/* Process the argument list part of the signature, after any class spec
9074
has been consumed, as well as the first 'F' character (if any). For
9077
"__als__3fooRT0" => process "RT0"
9078
"complexfunc5__FPFPc_PFl_i" => process "PFPc_PFl_i"
9080
DECLP must be already initialised, usually non-empty. It won't be freed
9083
Note that g++ differs significantly from ARM and lucid style mangling
9084
with regards to references to previously seen types. For example, given
9085
the source fragment:
9089
foo::foo (int, foo &ia, int, foo &ib, int, foo &ic);
9092
foo::foo (int, foo &ia, int, foo &ib, int, foo &ic) { ia = ib = ic; }
9093
void foo (int, foo &ia, int, foo &ib, int, foo &ic) { ia = ib = ic; }
9095
g++ produces the names:
9100
while lcc (and presumably other ARM style compilers as well) produces:
9102
foo__FiR3fooT1T2T1T2
9103
__ct__3fooFiR3fooT1T2T1T2
9105
Note that g++ bases its type numbers starting at zero and counts all
9106
previously seen types, while lucid/ARM bases its type numbers starting
9107
at one and only considers types after it has seen the 'F' character
9108
indicating the start of the function args. For lucid/ARM style, we
9109
account for this difference by discarding any previously seen types when
9110
we see the 'F' character, and subtracting one from the type number
9116
demangle_args (work, mangled, declp)
9117
struct work_stuff *work;
9118
const char **mangled;
9128
if (PRINT_ARG_TYPES)
9130
string_append (declp, "(");
9131
if (**mangled == '\0')
9133
string_append (declp, "void");
9137
while ((**mangled != '_' && **mangled != '\0' && **mangled != 'e')
9138
|| work->nrepeats > 0)
9140
if ((**mangled == 'N') || (**mangled == 'T'))
9142
temptype = *(*mangled)++;
9144
if (temptype == 'N')
9146
if (!get_count (mangled, &r))
9155
if ((HP_DEMANGLING || ARM_DEMANGLING || EDG_DEMANGLING) && work -> ntypes >= 10)
9157
/* If we have 10 or more types we might have more than a 1 digit
9158
index so we'll have to consume the whole count here. This
9159
will lose if the next thing is a type name preceded by a
9160
count but it's impossible to demangle that case properly
9161
anyway. Eg if we already have 12 types is T12Pc "(..., type1,
9162
Pc, ...)" or "(..., type12, char *, ...)" */
9163
if ((t = consume_count(mangled)) <= 0)
9170
if (!get_count (mangled, &t))
9175
if (LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING)
9179
/* Validate the type index. Protect against illegal indices from
9180
malformed type strings. */
9181
if ((t < 0) || (t >= work -> ntypes))
9185
while (work->nrepeats > 0 || --r >= 0)
9187
tem = work -> typevec[t];
9188
if (need_comma && PRINT_ARG_TYPES)
9190
string_append (declp, ", ");
9192
if (!do_arg (work, &tem, &arg))
9196
if (PRINT_ARG_TYPES)
9198
string_appends (declp, &arg);
9200
string_delete (&arg);
9206
if (need_comma && PRINT_ARG_TYPES)
9207
string_append (declp, ", ");
9208
if (!do_arg (work, mangled, &arg))
9210
if (PRINT_ARG_TYPES)
9211
string_appends (declp, &arg);
9212
string_delete (&arg);
9217
if (**mangled == 'e')
9220
if (PRINT_ARG_TYPES)
9224
string_append (declp, ",");
9226
string_append (declp, "...");
9230
if (PRINT_ARG_TYPES)
9232
string_append (declp, ")");
9237
/* Like demangle_args, but for demangling the argument lists of function
9238
and method pointers or references, not top-level declarations. */
9241
demangle_nested_args (work, mangled, declp)
9242
struct work_stuff *work;
9243
const char **mangled;
9246
string* saved_previous_argument;
9250
/* The G++ name-mangling algorithm does not remember types on nested
9251
argument lists, unless -fsquangling is used, and in that case the
9252
type vector updated by remember_type is not used. So, we turn
9253
off remembering of types here. */
9254
++work->forgetting_types;
9256
/* For the repeat codes used with -fsquangling, we must keep track of
9257
the last argument. */
9258
saved_previous_argument = work->previous_argument;
9259
saved_nrepeats = work->nrepeats;
9260
work->previous_argument = 0;
9263
/* Actually demangle the arguments. */
9264
result = demangle_args (work, mangled, declp);
9266
/* Restore the previous_argument field. */
9267
if (work->previous_argument)
9269
string_delete (work->previous_argument);
9270
g_free ((char *) work->previous_argument);
9272
work->previous_argument = saved_previous_argument;
9273
--work->forgetting_types;
9274
work->nrepeats = saved_nrepeats;
9280
demangle_function_name (work, mangled, declp, scan)
9281
struct work_stuff *work;
9282
const char **mangled;
9290
string_appendn (declp, (*mangled), scan - (*mangled));
9291
string_need (declp, 1);
9292
*(declp -> p) = '\0';
9294
/* Consume the function name, including the "__" separating the name
9295
from the signature. We are guaranteed that SCAN points to the
9298
(*mangled) = scan + 2;
9299
/* We may be looking at an instantiation of a template function:
9300
foo__Xt1t2_Ft3t4, where t1, t2, ... are template arguments and a
9301
following _F marks the start of the function arguments. Handle
9302
the template arguments first. */
9304
if (HP_DEMANGLING && (**mangled == 'X'))
9306
demangle_arm_hp_template (work, mangled, 0, declp);
9307
/* This leaves MANGLED pointing to the 'F' marking func args */
9310
if (LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING)
9313
/* See if we have an ARM style constructor or destructor operator.
9314
If so, then just record it, clear the decl, and return.
9315
We can't build the actual constructor/destructor decl until later,
9316
when we recover the class name from the signature. */
9318
if (strcmp (declp -> b, "__ct") == 0)
9320
work -> constructor += 1;
9321
string_clear (declp);
9324
else if (strcmp (declp -> b, "__dt") == 0)
9326
work -> destructor += 1;
9327
string_clear (declp);
9332
if (declp->p - declp->b >= 3
9333
&& declp->b[0] == 'o'
9334
&& declp->b[1] == 'p'
9335
&& strchr (cplus_markers, declp->b[2]) != NULL)
9337
/* see if it's an assignment expression */
9338
if (declp->p - declp->b >= 10 /* op$assign_ */
9339
&& memcmp (declp->b + 3, "assign_", 7) == 0)
9341
for (i = 0; i < G_N_ELEMENTS (optable); i++)
9343
int len = declp->p - declp->b - 10;
9344
if ((int) strlen (optable[i].in) == len
9345
&& memcmp (optable[i].in, declp->b + 10, len) == 0)
9347
string_clear (declp);
9348
string_append (declp, "operator");
9349
string_append (declp, optable[i].out);
9350
string_append (declp, "=");
9357
for (i = 0; i < G_N_ELEMENTS (optable); i++)
9359
int len = declp->p - declp->b - 3;
9360
if ((int) strlen (optable[i].in) == len
9361
&& memcmp (optable[i].in, declp->b + 3, len) == 0)
9363
string_clear (declp);
9364
string_append (declp, "operator");
9365
string_append (declp, optable[i].out);
9371
else if (declp->p - declp->b >= 5 && memcmp (declp->b, "type", 4) == 0
9372
&& strchr (cplus_markers, declp->b[4]) != NULL)
9374
/* type conversion operator */
9376
if (do_type (work, &tem, &type))
9378
string_clear (declp);
9379
string_append (declp, "operator ");
9380
string_appends (declp, &type);
9381
string_delete (&type);
9384
else if (declp->b[0] == '_' && declp->b[1] == '_'
9385
&& declp->b[2] == 'o' && declp->b[3] == 'p')
9388
/* type conversion operator. */
9390
if (do_type (work, &tem, &type))
9392
string_clear (declp);
9393
string_append (declp, "operator ");
9394
string_appends (declp, &type);
9395
string_delete (&type);
9398
else if (declp->b[0] == '_' && declp->b[1] == '_'
9399
&& g_ascii_islower((unsigned char)declp->b[2])
9400
&& g_ascii_islower((unsigned char)declp->b[3]))
9402
if (declp->b[4] == '\0')
9405
for (i = 0; i < G_N_ELEMENTS (optable); i++)
9407
if (strlen (optable[i].in) == 2
9408
&& memcmp (optable[i].in, declp->b + 2, 2) == 0)
9410
string_clear (declp);
9411
string_append (declp, "operator");
9412
string_append (declp, optable[i].out);
9419
if (declp->b[2] == 'a' && declp->b[5] == '\0')
9422
for (i = 0; i < G_N_ELEMENTS (optable); i++)
9424
if (strlen (optable[i].in) == 3
9425
&& memcmp (optable[i].in, declp->b + 2, 3) == 0)
9427
string_clear (declp);
9428
string_append (declp, "operator");
9429
string_append (declp, optable[i].out);
9438
/* a mini string-handling package */
9453
s->p = s->b = g_malloc (n);
9456
else if (s->e - s->p < n)
9461
s->b = g_realloc (s->b, n);
9474
s->b = s->e = s->p = NULL;
9482
s->b = s->p = s->e = NULL;
9498
return (s->b == s->p);
9504
string_append (p, s)
9509
if (s == NULL || *s == '\0')
9513
memcpy (p->p, s, n);
9518
string_appends (p, s)
9527
memcpy (p->p, s->b, n);
9533
string_appendn (p, s, n)
9541
memcpy (p->p, s, n);
9547
string_prepend (p, s)
9551
if (s != NULL && *s != '\0')
9553
string_prependn (p, s, strlen (s));
9558
string_prepends (p, s)
9563
string_prependn (p, s->b, s->p - s->b);
9568
string_prependn (p, s, n)
9578
for (q = p->p - 1; q >= p->b; q--)
9582
memcpy (p->b, s, n);
9588
string_append_template_idx (s, idx)
9592
char buf[INTBUF_SIZE + 1 /* 'T' */];
9593
sprintf(buf, "T%d", idx);
9594
string_append (s, buf);