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