| 1 |
/* Internal demangler interface for g++ V3 ABI. |
| 2 |
Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 3 |
Written by Ian Lance Taylor <[email protected]>. |
| 4 |
|
| 5 |
This file is part of the libiberty library, which is part of GCC. |
| 6 |
|
| 7 |
This file is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
In addition to the permissions in the GNU General Public License, the |
| 13 |
Free Software Foundation gives you unlimited permission to link the |
| 14 |
compiled version of this file into combinations with other programs, |
| 15 |
and to distribute those combinations without any restriction coming |
| 16 |
from the use of this file. (The General Public License restrictions |
| 17 |
do apply in other respects; for example, they cover modification of |
| 18 |
the file, and distribution when not linked into a combined |
| 19 |
executable.) |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program; if not, write to the Free Software |
| 28 |
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
| 29 |
*/ |
| 30 |
|
| 31 |
/* This file provides some definitions shared by cp-demangle.c and |
| 32 |
cp-demint.c. It should not be included by any other files. */ |
| 33 |
|
| 34 |
/* Information we keep for operators. */ |
| 35 |
|
| 36 |
struct demangle_operator_info |
| 37 |
{ |
| 38 |
/* Mangled name. */ |
| 39 |
const char *code; |
| 40 |
/* Real name. */ |
| 41 |
const char *name; |
| 42 |
/* Length of real name. */ |
| 43 |
int len; |
| 44 |
/* Number of arguments. */ |
| 45 |
int args; |
| 46 |
}; |
| 47 |
|
| 48 |
/* How to print the value of a builtin type. */ |
| 49 |
|
| 50 |
enum d_builtin_type_print |
| 51 |
{ |
| 52 |
/* Print as (type)val. */ |
| 53 |
D_PRINT_DEFAULT, |
| 54 |
/* Print as integer. */ |
| 55 |
D_PRINT_INT, |
| 56 |
/* Print as unsigned integer, with trailing "u". */ |
| 57 |
D_PRINT_UNSIGNED, |
| 58 |
/* Print as long, with trailing "l". */ |
| 59 |
D_PRINT_LONG, |
| 60 |
/* Print as unsigned long, with trailing "ul". */ |
| 61 |
D_PRINT_UNSIGNED_LONG, |
| 62 |
/* Print as long long, with trailing "ll". */ |
| 63 |
D_PRINT_LONG_LONG, |
| 64 |
/* Print as unsigned long long, with trailing "ull". */ |
| 65 |
D_PRINT_UNSIGNED_LONG_LONG, |
| 66 |
/* Print as bool. */ |
| 67 |
D_PRINT_BOOL, |
| 68 |
/* Print as float--put value in square brackets. */ |
| 69 |
D_PRINT_FLOAT, |
| 70 |
/* Print in usual way, but here to detect void. */ |
| 71 |
D_PRINT_VOID |
| 72 |
}; |
| 73 |
|
| 74 |
/* Information we keep for a builtin type. */ |
| 75 |
|
| 76 |
struct demangle_builtin_type_info |
| 77 |
{ |
| 78 |
/* Type name. */ |
| 79 |
const char *name; |
| 80 |
/* Length of type name. */ |
| 81 |
int len; |
| 82 |
/* Type name when using Java. */ |
| 83 |
const char *java_name; |
| 84 |
/* Length of java name. */ |
| 85 |
int java_len; |
| 86 |
/* How to print a value of this type. */ |
| 87 |
enum d_builtin_type_print print; |
| 88 |
}; |
| 89 |
|
| 90 |
/* The information structure we pass around. */ |
| 91 |
|
| 92 |
struct d_info |
| 93 |
{ |
| 94 |
/* The string we are demangling. */ |
| 95 |
const char *s; |
| 96 |
/* The end of the string we are demangling. */ |
| 97 |
const char *send; |
| 98 |
/* The options passed to the demangler. */ |
| 99 |
int options; |
| 100 |
/* The next character in the string to consider. */ |
| 101 |
const char *n; |
| 102 |
/* The array of components. */ |
| 103 |
struct demangle_component *comps; |
| 104 |
/* The index of the next available component. */ |
| 105 |
int next_comp; |
| 106 |
/* The number of available component structures. */ |
| 107 |
int num_comps; |
| 108 |
/* The array of substitutions. */ |
| 109 |
struct demangle_component **subs; |
| 110 |
/* The index of the next substitution. */ |
| 111 |
int next_sub; |
| 112 |
/* The number of available entries in the subs array. */ |
| 113 |
int num_subs; |
| 114 |
/* The last name we saw, for constructors and destructors. */ |
| 115 |
struct demangle_component *last_name; |
| 116 |
/* A running total of the length of large expansions from the |
| 117 |
mangled name to the demangled name, such as standard |
| 118 |
substitutions and builtin types. */ |
| 119 |
int expansion; |
| 120 |
/* Non-zero if we are parsing an expression. */ |
| 121 |
int is_expression; |
| 122 |
/* Non-zero if we are parsing the type operand of a conversion |
| 123 |
operator, but not when in an expression. */ |
| 124 |
int is_conversion; |
| 125 |
/* 1: using new unresolved-name grammar. |
| 126 |
-1: using new unresolved-name grammar and saw an unresolved-name. |
| 127 |
0: using old unresolved-name grammar. */ |
| 128 |
int unresolved_name_state; |
| 129 |
/* If DMGL_NO_RECURSE_LIMIT is not active then this is set to |
| 130 |
the current recursion level. */ |
| 131 |
unsigned int recursion_level; |
| 132 |
}; |
| 133 |
|
| 134 |
/* To avoid running past the ending '\0', don't: |
| 135 |
- call d_peek_next_char if d_peek_char returned '\0' |
| 136 |
- call d_advance with an 'i' that is too large |
| 137 |
- call d_check_char(di, '\0') |
| 138 |
Everything else is safe. */ |
| 139 |
#define d_peek_char(di) (*((di)->n)) |
| 140 |
#ifndef CHECK_DEMANGLER |
| 141 |
# define d_peek_next_char(di) ((di)->n[1]) |
| 142 |
# define d_advance(di, i) ((di)->n += (i)) |
| 143 |
#endif |
| 144 |
#define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0) |
| 145 |
#define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++)) |
| 146 |
#define d_str(di) ((di)->n) |
| 147 |
|
| 148 |
#ifdef CHECK_DEMANGLER |
| 149 |
static inline char |
| 150 |
d_peek_next_char (const struct d_info *di) |
| 151 |
{ |
| 152 |
if (!di->n[0]) |
| 153 |
abort (); |
| 154 |
return di->n[1]; |
| 155 |
} |
| 156 |
|
| 157 |
static inline void |
| 158 |
d_advance (struct d_info *di, int i) |
| 159 |
{ |
| 160 |
if (i < 0) |
| 161 |
abort (); |
| 162 |
while (i--) |
| 163 |
{ |
| 164 |
if (!di->n[0]) |
| 165 |
abort (); |
| 166 |
di->n++; |
| 167 |
} |
| 168 |
} |
| 169 |
#endif |
| 170 |
|
| 171 |
/* Functions and arrays in cp-demangle.c which are referenced by |
| 172 |
functions in cp-demint.c. */ |
| 173 |
#ifdef IN_GLIBCPP_V3 |
| 174 |
#define CP_STATIC_IF_GLIBCPP_V3 static |
| 175 |
#else |
| 176 |
#define CP_STATIC_IF_GLIBCPP_V3 extern |
| 177 |
#endif |
| 178 |
|
| 179 |
#ifndef IN_GLIBCPP_V3 |
| 180 |
extern const struct demangle_operator_info cplus_demangle_operators[]; |
| 181 |
#endif |
| 182 |
|
| 183 |
#define D_BUILTIN_TYPE_COUNT (36) |
| 184 |
|
| 185 |
CP_STATIC_IF_GLIBCPP_V3 |
| 186 |
const struct demangle_builtin_type_info |
| 187 |
cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT]; |
| 188 |
|
| 189 |
CP_STATIC_IF_GLIBCPP_V3 |
| 190 |
struct demangle_component * |
| 191 |
cplus_demangle_mangled_name (struct d_info *, int); |
| 192 |
|
| 193 |
CP_STATIC_IF_GLIBCPP_V3 |
| 194 |
struct demangle_component * |
| 195 |
cplus_demangle_type (struct d_info *); |
| 196 |
|
| 197 |
extern void |
| 198 |
cplus_demangle_init_info (const char *, int, size_t, struct d_info *); |
| 199 |
|
| 200 |
/* cp-demangle.c needs to define this a little differently */ |
| 201 |
#undef CP_STATIC_IF_GLIBCPP_V3 |