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