]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/compile/compile-cplus.h
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / compile / compile-cplus.h
CommitLineData
078a0207 1/* Header file for GDB compile C++ language support.
1d506c26 2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
078a0207
KS
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
1a5c2598
TT
17#ifndef COMPILE_COMPILE_CPLUS_H
18#define COMPILE_COMPILE_CPLUS_H
078a0207 19
6ad66f21 20#include "compile/compile.h"
268a13a5 21#include "gdbsupport/enum-flags.h"
078a0207 22#include "gcc-cp-plugin.h"
0d12e84c 23#include "symtab.h"
078a0207
KS
24
25struct type;
26struct block;
27
28/* enum-flags wrapper */
29DEF_ENUM_FLAGS_TYPE (enum gcc_cp_qualifiers, gcc_cp_qualifiers_flags);
30DEF_ENUM_FLAGS_TYPE (enum gcc_cp_ref_qualifiers, gcc_cp_ref_qualifiers_flags);
31DEF_ENUM_FLAGS_TYPE (enum gcc_cp_symbol_kind, gcc_cp_symbol_kind_flags);
32
33class compile_cplus_instance;
34
35/* A single component of a type's scope. Type names are broken into
36 "components," a series of unqualified names comprising the type name,
37 e.g., "namespace1", "namespace2", "myclass". */
38
39struct scope_component
40{
41 /* The unqualified name of this scope. */
42 std::string name;
43
44 /* The block symbol for this type/scope. */
45 struct block_symbol bsymbol;
46};
47
48/* Comparison operators for scope_components. */
49
50bool operator== (const scope_component &lhs, const scope_component &rhs);
51bool operator!= (const scope_component &lhs, const scope_component &rhs);
52
53
54/* A single compiler scope used to define a type.
55
56 A compile_scope is a list of scope_components, where all leading
57 scope_components are namespaces, followed by a single non-namespace
58 type component (the actual type we are converting). */
59
60class compile_scope : private std::vector<scope_component>
61{
62public:
63
64 using std::vector<scope_component>::push_back;
65 using std::vector<scope_component>::pop_back;
66 using std::vector<scope_component>::back;
67 using std::vector<scope_component>::empty;
68 using std::vector<scope_component>::size;
69 using std::vector<scope_component>::begin;
70 using std::vector<scope_component>::end;
71 using std::vector<scope_component>::operator[];
72
73 compile_scope ()
74 : m_nested_type (GCC_TYPE_NONE), m_pushed (false)
75 {
76 }
77
78 /* Return the gcc_type of the type if it is a nested definition.
79 Returns GCC_TYPE_NONE if this type was not nested. */
80 gcc_type nested_type ()
81 {
82 return m_nested_type;
83 }
84
85private:
86
87 /* compile_cplus_instance is a friend class so that it can set the
88 following private members when compile_scopes are created. */
89 friend compile_cplus_instance;
90
91 /* If the type was actually a nested type, this will hold that nested
92 type after the scope is pushed. */
93 gcc_type m_nested_type;
94
95 /* If true, this scope was pushed to the compiler and all namespaces
96 must be popped when leaving the scope. */
97 bool m_pushed;
98};
99
100/* Comparison operators for compile_scopes. */
101
102bool operator== (const compile_scope &lhs, const compile_scope &rhs);
103bool operator!= (const compile_scope &lhs, const compile_scope &rhs);
104
105/* Convert TYPENAME into a vector of namespace and top-most/super
106 composite scopes.
107
108 For example, for the input "Namespace::classB::classInner", the
109 resultant vector will contain the tokens "Namespace" and
110 "classB". */
111
112compile_scope type_name_to_scope (const char *type_name,
113 const struct block *block);
114
115/* A callback suitable for use as the GCC C++ symbol oracle. */
116
117extern gcc_cp_oracle_function gcc_cplus_convert_symbol;
118
119/* A callback suitable for use as the GCC C++ address oracle. */
120
121extern gcc_cp_symbol_address_function gcc_cplus_symbol_address;
122
123/* A subclass of compile_instance that is specific to the C++ front
124 end. */
125
126class compile_cplus_instance : public compile_instance
127{
128public:
129
130 explicit compile_cplus_instance (struct gcc_cp_context *gcc_cp)
131 : compile_instance (&gcc_cp->base, m_default_cflags),
132 m_plugin (gcc_cp)
133 {
134 m_plugin.set_callbacks (gcc_cplus_convert_symbol,
135 gcc_cplus_symbol_address,
136 gcc_cplus_enter_scope, gcc_cplus_leave_scope,
137 this);
138 }
139
140 /* Convert a gdb type, TYPE, to a GCC type.
141
142 If this type was defined in another type, NESTED_ACCESS should indicate
143 the accessibility of this type (or GCC_CP_ACCESS_NONE if not a nested
144 type). GCC_CP_ACCESS_NONE is the default nested access.
145
146 The new GCC type is returned. */
147 gcc_type convert_type
148 (struct type *type,
149 enum gcc_cp_symbol_kind nested_access = GCC_CP_ACCESS_NONE);
150
151 /* Return a handle for the GCC plug-in. */
152 gcc_cp_plugin &plugin () { return m_plugin; }
153
154 /* Factory method to create a new scope based on TYPE with name TYPE_NAME.
155 [TYPE_NAME could be TYPE_NAME or SYMBOL_NATURAL_NAME.]
156
157 If TYPE is a nested or local definition, nested_type () will return
158 the gcc_type of the conversion.
159
160 Otherwise, nested_type () is GCC_TYPE_NONE. */
161 compile_scope new_scope (const char *type_name, struct type *type);
162
163 /* Enter the given NEW_SCOPE. */
d82b3862 164 void enter_scope (compile_scope &&scope);
078a0207
KS
165
166 /* Leave the current scope. */
167 void leave_scope ();
168
169 /* Add the qualifiers given by QUALS to BASE. */
170 gcc_type convert_qualified_base (gcc_type base,
171 gcc_cp_qualifiers_flags quals);
172
173 /* Convert TARGET into a pointer type. */
174 gcc_type convert_pointer_base (gcc_type target);
175
176 /* Convert BASE into a reference type. RQUALS describes the reference. */
177 gcc_type convert_reference_base (gcc_type base,
178 enum gcc_cp_ref_qualifiers rquals);
179
180 /* Return the declaration name of the symbol named NATURAL.
181 This returns a name with no function arguments or template parameters,
182 suitable for passing to the compiler plug-in. */
183 static gdb::unique_xmalloc_ptr<char> decl_name (const char *natural);
184
185private:
186
187 /* Callbacks suitable for use as the GCC C++ enter/leave scope requests. */
188 static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_enter_scope;
189 static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_leave_scope;
190
191 /* Default compiler flags for C++. */
192 static const char *m_default_cflags;
193
194 /* The GCC plug-in. */
195 gcc_cp_plugin m_plugin;
196
197 /* A list of scopes we are processing. */
198 std::vector<compile_scope> m_scopes;
199};
200
201/* Get the access flag for the NUM'th method of TYPE's FNI'th
202 fieldlist. */
203
204enum gcc_cp_symbol_kind get_method_access_flag (const struct type *type,
205 int fni, int num);
206
1a5c2598 207#endif /* COMPILE_COMPILE_CPLUS_H */