/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- TypeSystemClang.h ---------------------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_TYPESYSTEMCLANG_H |
10 | | #define LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_TYPESYSTEMCLANG_H |
11 | | |
12 | | #include <cstdint> |
13 | | |
14 | | #include <functional> |
15 | | #include <initializer_list> |
16 | | #include <memory> |
17 | | #include <optional> |
18 | | #include <set> |
19 | | #include <string> |
20 | | #include <utility> |
21 | | #include <vector> |
22 | | |
23 | | #include "clang/AST/ASTContext.h" |
24 | | #include "clang/AST/ASTFwd.h" |
25 | | #include "clang/AST/TemplateBase.h" |
26 | | #include "clang/AST/Type.h" |
27 | | #include "clang/Basic/TargetInfo.h" |
28 | | #include "llvm/ADT/APSInt.h" |
29 | | #include "llvm/ADT/SmallVector.h" |
30 | | |
31 | | #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" |
32 | | #include "lldb/Expression/ExpressionVariable.h" |
33 | | #include "lldb/Symbol/CompilerType.h" |
34 | | #include "lldb/Symbol/TypeSystem.h" |
35 | | #include "lldb/Target/Target.h" |
36 | | #include "lldb/Utility/ConstString.h" |
37 | | #include "lldb/Utility/Flags.h" |
38 | | #include "lldb/Utility/Log.h" |
39 | | #include "lldb/lldb-enumerations.h" |
40 | | |
41 | | class DWARFASTParserClang; |
42 | | class PDBASTParser; |
43 | | |
44 | | namespace clang { |
45 | | class FileManager; |
46 | | class HeaderSearch; |
47 | | class ModuleMap; |
48 | | } // namespace clang |
49 | | |
50 | | namespace lldb_private { |
51 | | |
52 | | class ClangASTMetadata; |
53 | | class ClangASTSource; |
54 | | class Declaration; |
55 | | |
56 | | /// A Clang module ID. |
57 | | class OptionalClangModuleID { |
58 | | unsigned m_id = 0; |
59 | | |
60 | | public: |
61 | 138k | OptionalClangModuleID() = default; |
62 | 71.2k | explicit OptionalClangModuleID(unsigned id) : m_id(id) {} |
63 | 155k | bool HasValue() const { return m_id != 0; } |
64 | 54.8k | unsigned GetValue() const { return m_id; } |
65 | | }; |
66 | | |
67 | | /// The implementation of lldb::Type's m_payload field for TypeSystemClang. |
68 | | class TypePayloadClang { |
69 | | /// The Layout is as follows: |
70 | | /// \verbatim |
71 | | /// bit 0..30 ... Owning Module ID. |
72 | | /// bit 31 ...... IsCompleteObjCClass. |
73 | | /// \endverbatim |
74 | | Type::Payload m_payload = 0; |
75 | | |
76 | | public: |
77 | | TypePayloadClang() = default; |
78 | | explicit TypePayloadClang(OptionalClangModuleID owning_module, |
79 | | bool is_complete_objc_class = false); |
80 | 11.0k | explicit TypePayloadClang(uint32_t opaque_payload) : m_payload(opaque_payload) {} |
81 | 53.7k | operator Type::Payload() { return m_payload; } |
82 | | |
83 | | static constexpr unsigned ObjCClassBit = 1 << 31; |
84 | 183 | bool IsCompleteObjCClass() { return Flags(m_payload).Test(ObjCClassBit); } |
85 | 53.7k | void SetIsCompleteObjCClass(bool is_complete_objc_class) { |
86 | 53.7k | m_payload = is_complete_objc_class ? Flags(m_payload).Set(ObjCClassBit)203 |
87 | 53.7k | : Flags(m_payload).Clear(ObjCClassBit)53.5k ; |
88 | 53.7k | } |
89 | 10.8k | OptionalClangModuleID GetOwningModule() { |
90 | 10.8k | return OptionalClangModuleID(Flags(m_payload).Clear(ObjCClassBit)); |
91 | 10.8k | } |
92 | | void SetOwningModule(OptionalClangModuleID id); |
93 | | /// \} |
94 | | }; |
95 | | |
96 | | /// A TypeSystem implementation based on Clang. |
97 | | /// |
98 | | /// This class uses a single clang::ASTContext as the backend for storing |
99 | | /// its types and declarations. Every clang::ASTContext should also just have |
100 | | /// a single associated TypeSystemClang instance that manages it. |
101 | | /// |
102 | | /// The clang::ASTContext instance can either be created by TypeSystemClang |
103 | | /// itself or it can adopt an existing clang::ASTContext (for example, when |
104 | | /// it is necessary to provide a TypeSystem interface for an existing |
105 | | /// clang::ASTContext that was created by clang::CompilerInstance). |
106 | | class TypeSystemClang : public TypeSystem { |
107 | | // LLVM RTTI support |
108 | | static char ID; |
109 | | |
110 | | public: |
111 | | typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *); |
112 | | typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, |
113 | | clang::ObjCInterfaceDecl *); |
114 | | |
115 | | // llvm casting support |
116 | 2.66M | bool isA(const void *ClassID) const override { return ClassID == &ID; } |
117 | 2.66M | static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } |
118 | | |
119 | | /// Constructs a TypeSystemClang with an ASTContext using the given triple. |
120 | | /// |
121 | | /// \param name The name for the TypeSystemClang (for logging purposes) |
122 | | /// \param triple The llvm::Triple used for the ASTContext. The triple defines |
123 | | /// certain characteristics of the ASTContext and its types |
124 | | /// (e.g., whether certain primitive types exist or what their |
125 | | /// signedness is). |
126 | | explicit TypeSystemClang(llvm::StringRef name, llvm::Triple triple); |
127 | | |
128 | | /// Constructs a TypeSystemClang that uses an existing ASTContext internally. |
129 | | /// Useful when having an existing ASTContext created by Clang. |
130 | | /// |
131 | | /// \param name The name for the TypeSystemClang (for logging purposes) |
132 | | /// \param existing_ctxt An existing ASTContext. |
133 | | explicit TypeSystemClang(llvm::StringRef name, |
134 | | clang::ASTContext &existing_ctxt); |
135 | | |
136 | | ~TypeSystemClang() override; |
137 | | |
138 | | void Finalize() override; |
139 | | |
140 | | // PluginInterface functions |
141 | 0 | llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } |
142 | | |
143 | 3.96k | static llvm::StringRef GetPluginNameStatic() { return "clang"; } |
144 | | |
145 | | static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, |
146 | | Module *module, Target *target); |
147 | | |
148 | | static LanguageSet GetSupportedLanguagesForTypes(); |
149 | | static LanguageSet GetSupportedLanguagesForExpressions(); |
150 | | |
151 | | static void Initialize(); |
152 | | |
153 | | static void Terminate(); |
154 | | |
155 | | static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx); |
156 | | |
157 | | /// Returns the display name of this TypeSystemClang that indicates what |
158 | | /// purpose it serves in LLDB. Used for example in logs. |
159 | 84 | llvm::StringRef getDisplayName() const { return m_display_name; } |
160 | | |
161 | | /// Returns the clang::ASTContext instance managed by this TypeSystemClang. |
162 | | clang::ASTContext &getASTContext(); |
163 | | |
164 | | clang::MangleContext *getMangleContext(); |
165 | | |
166 | | std::shared_ptr<clang::TargetOptions> &getTargetOptions(); |
167 | | |
168 | | clang::TargetInfo *getTargetInfo(); |
169 | | |
170 | | void setSema(clang::Sema *s); |
171 | 140k | clang::Sema *getSema() { return m_sema; } |
172 | | |
173 | | const char *GetTargetTriple(); |
174 | | |
175 | | void SetExternalSource( |
176 | | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> &ast_source_up); |
177 | | |
178 | 0 | bool GetCompleteDecl(clang::Decl *decl) { |
179 | 0 | return TypeSystemClang::GetCompleteDecl(&getASTContext(), decl); |
180 | 0 | } |
181 | | |
182 | | static void DumpDeclHiearchy(clang::Decl *decl); |
183 | | |
184 | | static void DumpDeclContextHiearchy(clang::DeclContext *decl_ctx); |
185 | | |
186 | | static bool DeclsAreEquivalent(clang::Decl *lhs_decl, clang::Decl *rhs_decl); |
187 | | |
188 | | static bool GetCompleteDecl(clang::ASTContext *ast, clang::Decl *decl); |
189 | | |
190 | | void SetMetadataAsUserID(const clang::Decl *decl, lldb::user_id_t user_id); |
191 | | void SetMetadataAsUserID(const clang::Type *type, lldb::user_id_t user_id); |
192 | | |
193 | | void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data); |
194 | | |
195 | | void SetMetadata(const clang::Type *object, ClangASTMetadata &meta_data); |
196 | | ClangASTMetadata *GetMetadata(const clang::Decl *object); |
197 | | ClangASTMetadata *GetMetadata(const clang::Type *object); |
198 | | |
199 | | void SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object, |
200 | | clang::AccessSpecifier access); |
201 | | clang::AccessSpecifier |
202 | | GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object); |
203 | | |
204 | | // Basic Types |
205 | | CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, |
206 | | size_t bit_size) override; |
207 | | |
208 | | CompilerType GetBasicType(lldb::BasicType type); |
209 | | |
210 | | static lldb::BasicType GetBasicTypeEnumeration(llvm::StringRef name); |
211 | | |
212 | | CompilerType |
213 | | GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name, |
214 | | uint32_t dw_ate, uint32_t bit_size); |
215 | | |
216 | | CompilerType GetCStringType(bool is_const); |
217 | | |
218 | | static clang::DeclContext *GetDeclContextForType(clang::QualType type); |
219 | | |
220 | | static clang::DeclContext *GetDeclContextForType(const CompilerType &type); |
221 | | |
222 | | uint32_t GetPointerByteSize() override; |
223 | | |
224 | 5.56k | clang::TranslationUnitDecl *GetTranslationUnitDecl() { |
225 | 5.56k | return getASTContext().getTranslationUnitDecl(); |
226 | 5.56k | } |
227 | | |
228 | | static bool AreTypesSame(CompilerType type1, CompilerType type2, |
229 | | bool ignore_qualifiers = false); |
230 | | |
231 | | /// Creates a CompilerType from the given QualType with the current |
232 | | /// TypeSystemClang instance as the CompilerType's typesystem. |
233 | | /// \param qt The QualType for a type that belongs to the ASTContext of this |
234 | | /// TypeSystemClang. |
235 | | /// \return The CompilerType representing the given QualType. If the |
236 | | /// QualType's type pointer is a nullptr then the function returns an |
237 | | /// invalid CompilerType. |
238 | 513k | CompilerType GetType(clang::QualType qt) { |
239 | 513k | if (qt.getTypePtrOrNull() == nullptr) |
240 | 1.82k | return CompilerType(); |
241 | | // Check that the type actually belongs to this TypeSystemClang. |
242 | 511k | assert(qt->getAsTagDecl() == nullptr || |
243 | 511k | &qt->getAsTagDecl()->getASTContext() == &getASTContext()); |
244 | 511k | return CompilerType(weak_from_this(), qt.getAsOpaquePtr()); |
245 | 511k | } |
246 | | |
247 | | CompilerType GetTypeForDecl(clang::NamedDecl *decl); |
248 | | |
249 | | CompilerType GetTypeForDecl(clang::TagDecl *decl); |
250 | | |
251 | | CompilerType GetTypeForDecl(clang::ObjCInterfaceDecl *objc_decl); |
252 | | |
253 | | template <typename RecordDeclType> |
254 | | CompilerType |
255 | | GetTypeForIdentifier(llvm::StringRef type_name, |
256 | 83 | clang::DeclContext *decl_context = nullptr) { |
257 | 83 | CompilerType compiler_type; |
258 | 83 | if (type_name.empty()) |
259 | 0 | return compiler_type; |
260 | | |
261 | 83 | clang::ASTContext &ast = getASTContext(); |
262 | 83 | if (!decl_context) |
263 | 83 | decl_context = ast.getTranslationUnitDecl(); |
264 | | |
265 | 83 | clang::IdentifierInfo &myIdent = ast.Idents.get(type_name); |
266 | 83 | clang::DeclarationName myName = |
267 | 83 | ast.DeclarationNames.getIdentifier(&myIdent); |
268 | 83 | clang::DeclContext::lookup_result result = decl_context->lookup(myName); |
269 | 83 | if (result.empty()) |
270 | 47 | return compiler_type; |
271 | | |
272 | 36 | clang::NamedDecl *named_decl = *result.begin(); |
273 | 36 | if (const RecordDeclType *record_decl = |
274 | 36 | llvm::dyn_cast<RecordDeclType>(named_decl)) |
275 | 36 | compiler_type = CompilerType( |
276 | 36 | weak_from_this(), |
277 | 36 | clang::QualType(record_decl->getTypeForDecl(), 0).getAsOpaquePtr()); |
278 | | |
279 | 36 | return compiler_type; |
280 | 83 | } lldb_private::CompilerType lldb_private::TypeSystemClang::GetTypeForIdentifier<clang::CXXRecordDecl>(llvm::StringRef, clang::DeclContext*) Line | Count | Source | 256 | 83 | clang::DeclContext *decl_context = nullptr) { | 257 | 83 | CompilerType compiler_type; | 258 | 83 | if (type_name.empty()) | 259 | 0 | return compiler_type; | 260 | | | 261 | 83 | clang::ASTContext &ast = getASTContext(); | 262 | 83 | if (!decl_context) | 263 | 83 | decl_context = ast.getTranslationUnitDecl(); | 264 | | | 265 | 83 | clang::IdentifierInfo &myIdent = ast.Idents.get(type_name); | 266 | 83 | clang::DeclarationName myName = | 267 | 83 | ast.DeclarationNames.getIdentifier(&myIdent); | 268 | 83 | clang::DeclContext::lookup_result result = decl_context->lookup(myName); | 269 | 83 | if (result.empty()) | 270 | 47 | return compiler_type; | 271 | | | 272 | 36 | clang::NamedDecl *named_decl = *result.begin(); | 273 | 36 | if (const RecordDeclType *record_decl = | 274 | 36 | llvm::dyn_cast<RecordDeclType>(named_decl)) | 275 | 36 | compiler_type = CompilerType( | 276 | 36 | weak_from_this(), | 277 | 36 | clang::QualType(record_decl->getTypeForDecl(), 0).getAsOpaquePtr()); | 278 | | | 279 | 36 | return compiler_type; | 280 | 83 | } |
Unexecuted instantiation: lldb_private::CompilerType lldb_private::TypeSystemClang::GetTypeForIdentifier<clang::EnumDecl>(llvm::StringRef, clang::DeclContext*) Unexecuted instantiation: lldb_private::CompilerType lldb_private::TypeSystemClang::GetTypeForIdentifier<clang::TypedefNameDecl>(llvm::StringRef, clang::DeclContext*) |
281 | | |
282 | | CompilerType CreateStructForIdentifier( |
283 | | llvm::StringRef type_name, |
284 | | const std::initializer_list<std::pair<const char *, CompilerType>> |
285 | | &type_fields, |
286 | | bool packed = false); |
287 | | |
288 | | CompilerType GetOrCreateStructForIdentifier( |
289 | | llvm::StringRef type_name, |
290 | | const std::initializer_list<std::pair<const char *, CompilerType>> |
291 | | &type_fields, |
292 | | bool packed = false); |
293 | | |
294 | | static bool IsOperator(llvm::StringRef name, |
295 | | clang::OverloadedOperatorKind &op_kind); |
296 | | |
297 | | // Structure, Unions, Classes |
298 | | |
299 | | static clang::AccessSpecifier |
300 | | ConvertAccessTypeToAccessSpecifier(lldb::AccessType access); |
301 | | |
302 | | static clang::AccessSpecifier |
303 | | UnifyAccessSpecifiers(clang::AccessSpecifier lhs, clang::AccessSpecifier rhs); |
304 | | |
305 | | uint32_t GetNumBaseClasses(const clang::CXXRecordDecl *cxx_record_decl, |
306 | | bool omit_empty_base_classes); |
307 | | |
308 | | uint32_t GetIndexForRecordChild(const clang::RecordDecl *record_decl, |
309 | | clang::NamedDecl *canonical_decl, |
310 | | bool omit_empty_base_classes); |
311 | | |
312 | | uint32_t GetIndexForRecordBase(const clang::RecordDecl *record_decl, |
313 | | const clang::CXXBaseSpecifier *base_spec, |
314 | | bool omit_empty_base_classes); |
315 | | |
316 | | /// Synthesize a clang::Module and return its ID or a default-constructed ID. |
317 | | OptionalClangModuleID GetOrCreateClangModule(llvm::StringRef name, |
318 | | OptionalClangModuleID parent, |
319 | | bool is_framework = false, |
320 | | bool is_explicit = false); |
321 | | |
322 | | CompilerType CreateRecordType(clang::DeclContext *decl_ctx, |
323 | | OptionalClangModuleID owning_module, |
324 | | lldb::AccessType access_type, |
325 | | llvm::StringRef name, int kind, |
326 | | lldb::LanguageType language, |
327 | | ClangASTMetadata *metadata = nullptr, |
328 | | bool exports_symbols = false); |
329 | | |
330 | | class TemplateParameterInfos { |
331 | | public: |
332 | 17.6k | TemplateParameterInfos() = default; |
333 | | TemplateParameterInfos(llvm::ArrayRef<const char *> names_in, |
334 | | llvm::ArrayRef<clang::TemplateArgument> args_in) |
335 | | : names(names_in), args(args_in) { |
336 | | assert(names.size() == args_in.size()); |
337 | | } |
338 | | |
339 | | TemplateParameterInfos(TemplateParameterInfos const &) = delete; |
340 | | TemplateParameterInfos(TemplateParameterInfos &&) = delete; |
341 | | |
342 | | TemplateParameterInfos &operator=(TemplateParameterInfos const &) = delete; |
343 | | TemplateParameterInfos &operator=(TemplateParameterInfos &&) = delete; |
344 | | |
345 | 17.6k | ~TemplateParameterInfos() = default; |
346 | | |
347 | 6.02k | bool IsValid() const { |
348 | | // Having a pack name but no packed args doesn't make sense, so mark |
349 | | // these template parameters as invalid. |
350 | 6.02k | if (pack_name && !packed_args819 ) |
351 | 1 | return false; |
352 | 6.02k | return args.size() == names.size() && |
353 | 6.02k | (!packed_args || !packed_args->packed_args888 ); |
354 | 6.02k | } |
355 | | |
356 | 17.5k | bool IsEmpty() const { return args.empty(); } |
357 | 13.9k | size_t Size() const { return args.size(); } |
358 | | |
359 | 16.6k | llvm::ArrayRef<clang::TemplateArgument> GetArgs() const { return args; } |
360 | 4.31k | llvm::ArrayRef<const char *> GetNames() const { return names; } |
361 | | |
362 | 1.42k | clang::TemplateArgument const &Front() const { |
363 | 1.42k | assert(!args.empty()); |
364 | 1.42k | return args.front(); |
365 | 1.42k | } |
366 | | |
367 | 106k | void InsertArg(char const *name, clang::TemplateArgument arg) { |
368 | 106k | args.emplace_back(std::move(arg)); |
369 | 106k | names.push_back(name); |
370 | 106k | } |
371 | | |
372 | | // Parameter pack related |
373 | | |
374 | 28.6k | bool hasParameterPack() const { return static_cast<bool>(packed_args); } |
375 | | |
376 | 2.98k | TemplateParameterInfos const &GetParameterPack() const { |
377 | 2.98k | assert(packed_args != nullptr); |
378 | 2.98k | return *packed_args; |
379 | 2.98k | } |
380 | | |
381 | 93.9k | TemplateParameterInfos &GetParameterPack() { |
382 | 93.9k | assert(packed_args != nullptr); |
383 | 93.9k | return *packed_args; |
384 | 93.9k | } |
385 | | |
386 | 902 | llvm::ArrayRef<clang::TemplateArgument> GetParameterPackArgs() const { |
387 | 902 | assert(packed_args != nullptr); |
388 | 902 | return packed_args->GetArgs(); |
389 | 902 | } |
390 | | |
391 | 1.52k | bool HasPackName() const { return pack_name && pack_name[0]1.48k ; } |
392 | | |
393 | 742 | llvm::StringRef GetPackName() const { |
394 | 742 | assert(HasPackName()); |
395 | 742 | return pack_name; |
396 | 742 | } |
397 | | |
398 | 1.57k | void SetPackName(char const *name) { pack_name = name; } |
399 | | |
400 | 1.65k | void SetParameterPack(std::unique_ptr<TemplateParameterInfos> args) { |
401 | 1.65k | packed_args = std::move(args); |
402 | 1.65k | } |
403 | | |
404 | | private: |
405 | | /// Element 'names[i]' holds the template argument name |
406 | | /// of 'args[i]' |
407 | | llvm::SmallVector<const char *, 2> names; |
408 | | llvm::SmallVector<clang::TemplateArgument, 2> args; |
409 | | |
410 | | const char * pack_name = nullptr; |
411 | | std::unique_ptr<TemplateParameterInfos> packed_args; |
412 | | }; |
413 | | |
414 | | clang::FunctionTemplateDecl *CreateFunctionTemplateDecl( |
415 | | clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, |
416 | | clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos); |
417 | | |
418 | | void CreateFunctionTemplateSpecializationInfo( |
419 | | clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template, |
420 | | const TemplateParameterInfos &infos); |
421 | | |
422 | | clang::ClassTemplateDecl *CreateClassTemplateDecl( |
423 | | clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, |
424 | | lldb::AccessType access_type, llvm::StringRef class_name, int kind, |
425 | | const TemplateParameterInfos &infos); |
426 | | |
427 | | clang::TemplateTemplateParmDecl * |
428 | | CreateTemplateTemplateParmDecl(const char *template_name); |
429 | | |
430 | | clang::ClassTemplateSpecializationDecl *CreateClassTemplateSpecializationDecl( |
431 | | clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, |
432 | | clang::ClassTemplateDecl *class_template_decl, int kind, |
433 | | const TemplateParameterInfos &infos); |
434 | | |
435 | | CompilerType |
436 | | CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl * |
437 | | class_template_specialization_decl); |
438 | | |
439 | | static clang::DeclContext * |
440 | | GetAsDeclContext(clang::FunctionDecl *function_decl); |
441 | | |
442 | | static bool CheckOverloadedOperatorKindParameterCount( |
443 | | bool is_method, clang::OverloadedOperatorKind op_kind, |
444 | | uint32_t num_params); |
445 | | |
446 | | bool FieldIsBitfield(clang::FieldDecl *field, uint32_t &bitfield_bit_size); |
447 | | |
448 | | bool RecordHasFields(const clang::RecordDecl *record_decl); |
449 | | |
450 | | bool BaseSpecifierIsEmpty(const clang::CXXBaseSpecifier *b); |
451 | | |
452 | | CompilerType CreateObjCClass(llvm::StringRef name, |
453 | | clang::DeclContext *decl_ctx, |
454 | | OptionalClangModuleID owning_module, |
455 | | bool isForwardDecl, bool isInternal, |
456 | | ClangASTMetadata *metadata = nullptr); |
457 | | |
458 | | // Returns a mask containing bits from the TypeSystemClang::eTypeXXX |
459 | | // enumerations |
460 | | |
461 | | // Namespace Declarations |
462 | | |
463 | | clang::NamespaceDecl * |
464 | | GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, |
465 | | OptionalClangModuleID owning_module, |
466 | | bool is_inline = false); |
467 | | |
468 | | // Function Types |
469 | | |
470 | | clang::FunctionDecl *CreateFunctionDeclaration( |
471 | | clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, |
472 | | llvm::StringRef name, const CompilerType &function_Type, |
473 | | clang::StorageClass storage, bool is_inline); |
474 | | |
475 | | CompilerType |
476 | | CreateFunctionType(const CompilerType &result_type, const CompilerType *args, |
477 | | unsigned num_args, bool is_variadic, unsigned type_quals, |
478 | | clang::CallingConv cc = clang::CC_C, |
479 | | clang::RefQualifierKind ref_qual = clang::RQ_None); |
480 | | |
481 | | clang::ParmVarDecl * |
482 | | CreateParameterDeclaration(clang::DeclContext *decl_ctx, |
483 | | OptionalClangModuleID owning_module, |
484 | | const char *name, const CompilerType ¶m_type, |
485 | | int storage, bool add_decl = false); |
486 | | |
487 | | void SetFunctionParameters(clang::FunctionDecl *function_decl, |
488 | | llvm::ArrayRef<clang::ParmVarDecl *> params); |
489 | | |
490 | | CompilerType CreateBlockPointerType(const CompilerType &function_type); |
491 | | |
492 | | // Array Types |
493 | | |
494 | | CompilerType CreateArrayType(const CompilerType &element_type, |
495 | | size_t element_count, bool is_vector); |
496 | | |
497 | | // Enumeration Types |
498 | | CompilerType CreateEnumerationType(llvm::StringRef name, |
499 | | clang::DeclContext *decl_ctx, |
500 | | OptionalClangModuleID owning_module, |
501 | | const Declaration &decl, |
502 | | const CompilerType &integer_qual_type, |
503 | | bool is_scoped); |
504 | | |
505 | | // Integer type functions |
506 | | |
507 | | CompilerType GetIntTypeFromBitSize(size_t bit_size, bool is_signed); |
508 | | |
509 | | CompilerType GetPointerSizedIntType(bool is_signed); |
510 | | |
511 | | // Floating point functions |
512 | | |
513 | | static CompilerType GetFloatTypeFromBitSize(clang::ASTContext *ast, |
514 | | size_t bit_size); |
515 | | |
516 | | // TypeSystem methods |
517 | | DWARFASTParser *GetDWARFParser() override; |
518 | | PDBASTParser *GetPDBParser() override; |
519 | | npdb::PdbAstBuilder *GetNativePDBParser() override; |
520 | | |
521 | | // TypeSystemClang callbacks for external source lookups. |
522 | | void CompleteTagDecl(clang::TagDecl *); |
523 | | |
524 | | void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *); |
525 | | |
526 | | bool LayoutRecordType( |
527 | | const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, |
528 | | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
529 | | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
530 | | &base_offsets, |
531 | | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
532 | | &vbase_offsets); |
533 | | |
534 | | /// Creates a CompilerDecl from the given Decl with the current |
535 | | /// TypeSystemClang instance as its typesystem. |
536 | | /// The Decl has to come from the ASTContext of this |
537 | | /// TypeSystemClang. |
538 | 334k | CompilerDecl GetCompilerDecl(clang::Decl *decl) { |
539 | 334k | assert(&decl->getASTContext() == &getASTContext() && |
540 | 334k | "CreateCompilerDecl for Decl from wrong ASTContext?"); |
541 | 334k | return CompilerDecl(this, decl); |
542 | 334k | } |
543 | | |
544 | | // CompilerDecl override functions |
545 | | ConstString DeclGetName(void *opaque_decl) override; |
546 | | |
547 | | ConstString DeclGetMangledName(void *opaque_decl) override; |
548 | | |
549 | | CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override; |
550 | | |
551 | | CompilerType DeclGetFunctionReturnType(void *opaque_decl) override; |
552 | | |
553 | | size_t DeclGetFunctionNumArguments(void *opaque_decl) override; |
554 | | |
555 | | CompilerType DeclGetFunctionArgumentType(void *opaque_decl, |
556 | | size_t arg_idx) override; |
557 | | |
558 | | CompilerType GetTypeForDecl(void *opaque_decl) override; |
559 | | |
560 | | // CompilerDeclContext override functions |
561 | | |
562 | | /// Creates a CompilerDeclContext from the given DeclContext |
563 | | /// with the current TypeSystemClang instance as its typesystem. |
564 | | /// The DeclContext has to come from the ASTContext of this |
565 | | /// TypeSystemClang. |
566 | | CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx); |
567 | | |
568 | | /// Set the owning module for \p decl. |
569 | | static void SetOwningModule(clang::Decl *decl, |
570 | | OptionalClangModuleID owning_module); |
571 | | |
572 | | std::vector<CompilerDecl> |
573 | | DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, |
574 | | const bool ignore_using_decls) override; |
575 | | |
576 | | ConstString DeclContextGetName(void *opaque_decl_ctx) override; |
577 | | |
578 | | ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override; |
579 | | |
580 | | bool DeclContextIsClassMethod(void *opaque_decl_ctx) override; |
581 | | |
582 | | bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, |
583 | | void *other_opaque_decl_ctx) override; |
584 | | |
585 | | lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) override; |
586 | | |
587 | | // Clang specific clang::DeclContext functions |
588 | | |
589 | | static clang::DeclContext * |
590 | | DeclContextGetAsDeclContext(const CompilerDeclContext &dc); |
591 | | |
592 | | static clang::ObjCMethodDecl * |
593 | | DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc); |
594 | | |
595 | | static clang::CXXMethodDecl * |
596 | | DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc); |
597 | | |
598 | | static clang::FunctionDecl * |
599 | | DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc); |
600 | | |
601 | | static clang::NamespaceDecl * |
602 | | DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc); |
603 | | |
604 | | static ClangASTMetadata *DeclContextGetMetaData(const CompilerDeclContext &dc, |
605 | | const clang::Decl *object); |
606 | | |
607 | | static clang::ASTContext * |
608 | | DeclContextGetTypeSystemClang(const CompilerDeclContext &dc); |
609 | | |
610 | | // Tests |
611 | | |
612 | | #ifndef NDEBUG |
613 | | bool Verify(lldb::opaque_compiler_type_t type) override; |
614 | | #endif |
615 | | |
616 | | bool IsArrayType(lldb::opaque_compiler_type_t type, |
617 | | CompilerType *element_type, uint64_t *size, |
618 | | bool *is_incomplete) override; |
619 | | |
620 | | bool IsVectorType(lldb::opaque_compiler_type_t type, |
621 | | CompilerType *element_type, uint64_t *size) override; |
622 | | |
623 | | bool IsAggregateType(lldb::opaque_compiler_type_t type) override; |
624 | | |
625 | | bool IsAnonymousType(lldb::opaque_compiler_type_t type) override; |
626 | | |
627 | | bool IsBeingDefined(lldb::opaque_compiler_type_t type) override; |
628 | | |
629 | | bool IsCharType(lldb::opaque_compiler_type_t type) override; |
630 | | |
631 | | bool IsCompleteType(lldb::opaque_compiler_type_t type) override; |
632 | | |
633 | | bool IsConst(lldb::opaque_compiler_type_t type) override; |
634 | | |
635 | | bool IsCStringType(lldb::opaque_compiler_type_t type, |
636 | | uint32_t &length) override; |
637 | | |
638 | | static bool IsCXXClassType(const CompilerType &type); |
639 | | |
640 | | bool IsDefined(lldb::opaque_compiler_type_t type) override; |
641 | | |
642 | | bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, |
643 | | bool &is_complex) override; |
644 | | |
645 | | bool IsFunctionType(lldb::opaque_compiler_type_t type) override; |
646 | | |
647 | | uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, |
648 | | CompilerType *base_type_ptr) override; |
649 | | |
650 | | size_t |
651 | | GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override; |
652 | | |
653 | | CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, |
654 | | const size_t index) override; |
655 | | |
656 | | bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override; |
657 | | |
658 | | bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override; |
659 | | |
660 | | bool IsBlockPointerType(lldb::opaque_compiler_type_t type, |
661 | | CompilerType *function_pointer_type_ptr) override; |
662 | | |
663 | | bool IsIntegerType(lldb::opaque_compiler_type_t type, |
664 | | bool &is_signed) override; |
665 | | |
666 | | bool IsEnumerationType(lldb::opaque_compiler_type_t type, |
667 | | bool &is_signed) override; |
668 | | |
669 | | bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override; |
670 | | |
671 | | static bool IsObjCClassType(const CompilerType &type); |
672 | | |
673 | | static bool IsObjCClassTypeAndHasIVars(const CompilerType &type, |
674 | | bool check_superclass); |
675 | | |
676 | | static bool IsObjCObjectOrInterfaceType(const CompilerType &type); |
677 | | |
678 | | static bool IsObjCObjectPointerType(const CompilerType &type, |
679 | | CompilerType *target_type = nullptr); |
680 | | |
681 | | bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override; |
682 | | |
683 | | static bool IsClassType(lldb::opaque_compiler_type_t type); |
684 | | |
685 | | static bool IsEnumType(lldb::opaque_compiler_type_t type); |
686 | | |
687 | | bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, |
688 | | CompilerType *target_type, // Can pass nullptr |
689 | | bool check_cplusplus, bool check_objc) override; |
690 | | |
691 | | bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override; |
692 | | |
693 | | bool IsPointerType(lldb::opaque_compiler_type_t type, |
694 | | CompilerType *pointee_type) override; |
695 | | |
696 | | bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, |
697 | | CompilerType *pointee_type) override; |
698 | | |
699 | | bool IsReferenceType(lldb::opaque_compiler_type_t type, |
700 | | CompilerType *pointee_type, bool *is_rvalue) override; |
701 | | |
702 | | bool IsScalarType(lldb::opaque_compiler_type_t type) override; |
703 | | |
704 | | bool IsTypedefType(lldb::opaque_compiler_type_t type) override; |
705 | | |
706 | | bool IsVoidType(lldb::opaque_compiler_type_t type) override; |
707 | | |
708 | | bool CanPassInRegisters(const CompilerType &type) override; |
709 | | |
710 | | bool SupportsLanguage(lldb::LanguageType language) override; |
711 | | |
712 | | static std::optional<std::string> GetCXXClassName(const CompilerType &type); |
713 | | |
714 | | // Type Completion |
715 | | |
716 | | bool GetCompleteType(lldb::opaque_compiler_type_t type) override; |
717 | | |
718 | | bool IsForcefullyCompleted(lldb::opaque_compiler_type_t type) override; |
719 | | |
720 | | // Accessors |
721 | | |
722 | | ConstString GetTypeName(lldb::opaque_compiler_type_t type, |
723 | | bool base_only) override; |
724 | | |
725 | | ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override; |
726 | | |
727 | | uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, |
728 | | CompilerType *pointee_or_element_compiler_type) override; |
729 | | |
730 | | lldb::LanguageType |
731 | | GetMinimumLanguage(lldb::opaque_compiler_type_t type) override; |
732 | | |
733 | | lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override; |
734 | | |
735 | | unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override; |
736 | | |
737 | | // Creating related types |
738 | | |
739 | | CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, |
740 | | ExecutionContextScope *exe_scope) override; |
741 | | |
742 | | CompilerType GetArrayType(lldb::opaque_compiler_type_t type, |
743 | | uint64_t size) override; |
744 | | |
745 | | CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override; |
746 | | |
747 | | CompilerType |
748 | | GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override; |
749 | | |
750 | | CompilerType |
751 | | GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override; |
752 | | |
753 | | // Returns -1 if this isn't a function of if the function doesn't have a |
754 | | // prototype Returns a value >= 0 if there is a prototype. |
755 | | int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override; |
756 | | |
757 | | CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, |
758 | | size_t idx) override; |
759 | | |
760 | | CompilerType |
761 | | GetFunctionReturnType(lldb::opaque_compiler_type_t type) override; |
762 | | |
763 | | size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override; |
764 | | |
765 | | TypeMemberFunctionImpl |
766 | | GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, |
767 | | size_t idx) override; |
768 | | |
769 | | CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override; |
770 | | |
771 | | CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override; |
772 | | |
773 | | CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override; |
774 | | |
775 | | CompilerType |
776 | | GetLValueReferenceType(lldb::opaque_compiler_type_t type) override; |
777 | | |
778 | | CompilerType |
779 | | GetRValueReferenceType(lldb::opaque_compiler_type_t type) override; |
780 | | |
781 | | CompilerType GetAtomicType(lldb::opaque_compiler_type_t type) override; |
782 | | |
783 | | CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override; |
784 | | |
785 | | CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override; |
786 | | |
787 | | CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override; |
788 | | |
789 | | /// Using the current type, create a new typedef to that type using |
790 | | /// "typedef_name" as the name and "decl_ctx" as the decl context. |
791 | | /// \param opaque_payload is an opaque TypePayloadClang. |
792 | | CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, |
793 | | const char *name, |
794 | | const CompilerDeclContext &decl_ctx, |
795 | | uint32_t opaque_payload) override; |
796 | | |
797 | | // If the current object represents a typedef type, get the underlying type |
798 | | CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override; |
799 | | |
800 | | // Create related types using the current type's AST |
801 | | CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override; |
802 | | |
803 | | // Exploring the type |
804 | | |
805 | | const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override; |
806 | | |
807 | | std::optional<uint64_t> GetByteSize(lldb::opaque_compiler_type_t type, |
808 | 0 | ExecutionContextScope *exe_scope) { |
809 | 0 | if (std::optional<uint64_t> bit_size = GetBitSize(type, exe_scope)) |
810 | 0 | return (*bit_size + 7) / 8; |
811 | 0 | return std::nullopt; |
812 | 0 | } |
813 | | |
814 | | std::optional<uint64_t> GetBitSize(lldb::opaque_compiler_type_t type, |
815 | | ExecutionContextScope *exe_scope) override; |
816 | | |
817 | | lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, |
818 | | uint64_t &count) override; |
819 | | |
820 | | lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override; |
821 | | |
822 | | std::optional<size_t> |
823 | | GetTypeBitAlign(lldb::opaque_compiler_type_t type, |
824 | | ExecutionContextScope *exe_scope) override; |
825 | | |
826 | | uint32_t GetNumChildren(lldb::opaque_compiler_type_t type, |
827 | | bool omit_empty_base_classes, |
828 | | const ExecutionContext *exe_ctx) override; |
829 | | |
830 | | CompilerType GetBuiltinTypeByName(ConstString name) override; |
831 | | |
832 | | lldb::BasicType |
833 | | GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override; |
834 | | |
835 | | void ForEachEnumerator( |
836 | | lldb::opaque_compiler_type_t type, |
837 | | std::function<bool(const CompilerType &integer_type, |
838 | | ConstString name, |
839 | | const llvm::APSInt &value)> const &callback) override; |
840 | | |
841 | | uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override; |
842 | | |
843 | | CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, |
844 | | std::string &name, uint64_t *bit_offset_ptr, |
845 | | uint32_t *bitfield_bit_size_ptr, |
846 | | bool *is_bitfield_ptr) override; |
847 | | |
848 | | uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override; |
849 | | |
850 | | uint32_t GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override; |
851 | | |
852 | | CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, |
853 | | size_t idx, |
854 | | uint32_t *bit_offset_ptr) override; |
855 | | |
856 | | CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, |
857 | | size_t idx, |
858 | | uint32_t *bit_offset_ptr) override; |
859 | | |
860 | | static uint32_t GetNumPointeeChildren(clang::QualType type); |
861 | | |
862 | | CompilerType GetChildCompilerTypeAtIndex( |
863 | | lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, |
864 | | bool transparent_pointers, bool omit_empty_base_classes, |
865 | | bool ignore_array_bounds, std::string &child_name, |
866 | | uint32_t &child_byte_size, int32_t &child_byte_offset, |
867 | | uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, |
868 | | bool &child_is_base_class, bool &child_is_deref_of_parent, |
869 | | ValueObject *valobj, uint64_t &language_flags) override; |
870 | | |
871 | | // Lookup a child given a name. This function will match base class names and |
872 | | // member member names in "clang_type" only, not descendants. |
873 | | uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, |
874 | | llvm::StringRef name, |
875 | | bool omit_empty_base_classes) override; |
876 | | |
877 | | // Lookup a child member given a name. This function will match member names |
878 | | // only and will descend into "clang_type" children in search for the first |
879 | | // member in this class, or any base class that matches "name". |
880 | | // TODO: Return all matches for a given name by returning a |
881 | | // vector<vector<uint32_t>> |
882 | | // so we catch all names that match a given child name, not just the first. |
883 | | size_t |
884 | | GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, |
885 | | llvm::StringRef name, |
886 | | bool omit_empty_base_classes, |
887 | | std::vector<uint32_t> &child_indexes) override; |
888 | | |
889 | | bool IsTemplateType(lldb::opaque_compiler_type_t type) override; |
890 | | |
891 | | size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type, |
892 | | bool expand_pack) override; |
893 | | |
894 | | lldb::TemplateArgumentKind |
895 | | GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx, |
896 | | bool expand_pack) override; |
897 | | CompilerType GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, |
898 | | size_t idx, bool expand_pack) override; |
899 | | std::optional<CompilerType::IntegralTemplateArgument> |
900 | | GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, |
901 | | bool expand_pack) override; |
902 | | |
903 | | CompilerType GetTypeForFormatters(void *type) override; |
904 | | |
905 | 397 | #define LLDB_INVALID_DECL_LEVEL UINT32_MAX |
906 | | // LLDB_INVALID_DECL_LEVEL is returned by CountDeclLevels if child_decl_ctx |
907 | | // could not be found in decl_ctx. |
908 | | uint32_t CountDeclLevels(clang::DeclContext *frame_decl_ctx, |
909 | | clang::DeclContext *child_decl_ctx, |
910 | | ConstString *child_name = nullptr, |
911 | | CompilerType *child_type = nullptr); |
912 | | |
913 | | // Modifying RecordType |
914 | | static clang::FieldDecl *AddFieldToRecordType(const CompilerType &type, |
915 | | llvm::StringRef name, |
916 | | const CompilerType &field_type, |
917 | | lldb::AccessType access, |
918 | | uint32_t bitfield_bit_size); |
919 | | |
920 | | static void BuildIndirectFields(const CompilerType &type); |
921 | | |
922 | | static void SetIsPacked(const CompilerType &type); |
923 | | |
924 | | static clang::VarDecl *AddVariableToRecordType(const CompilerType &type, |
925 | | llvm::StringRef name, |
926 | | const CompilerType &var_type, |
927 | | lldb::AccessType access); |
928 | | |
929 | | /// Initializes a variable with an integer value. |
930 | | /// \param var The variable to initialize. Must not already have an |
931 | | /// initializer and must have an integer or enum type. |
932 | | /// \param init_value The integer value that the variable should be |
933 | | /// initialized to. Has to match the bit width of the |
934 | | /// variable type. |
935 | | static void SetIntegerInitializerForVariable(clang::VarDecl *var, |
936 | | const llvm::APInt &init_value); |
937 | | |
938 | | /// Initializes a variable with a floating point value. |
939 | | /// \param var The variable to initialize. Must not already have an |
940 | | /// initializer and must have a floating point type. |
941 | | /// \param init_value The float value that the variable should be |
942 | | /// initialized to. |
943 | | static void |
944 | | SetFloatingInitializerForVariable(clang::VarDecl *var, |
945 | | const llvm::APFloat &init_value); |
946 | | |
947 | | clang::CXXMethodDecl *AddMethodToCXXRecordType( |
948 | | lldb::opaque_compiler_type_t type, llvm::StringRef name, |
949 | | const char *mangled_name, const CompilerType &method_type, |
950 | | lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, |
951 | | bool is_explicit, bool is_attr_used, bool is_artificial); |
952 | | |
953 | | void AddMethodOverridesForCXXRecordType(lldb::opaque_compiler_type_t type); |
954 | | |
955 | | // C++ Base Classes |
956 | | std::unique_ptr<clang::CXXBaseSpecifier> |
957 | | CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, |
958 | | lldb::AccessType access, bool is_virtual, |
959 | | bool base_of_class); |
960 | | |
961 | | bool TransferBaseClasses( |
962 | | lldb::opaque_compiler_type_t type, |
963 | | std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases); |
964 | | |
965 | | static bool SetObjCSuperClass(const CompilerType &type, |
966 | | const CompilerType &superclass_compiler_type); |
967 | | |
968 | | static bool AddObjCClassProperty(const CompilerType &type, |
969 | | const char *property_name, |
970 | | const CompilerType &property_compiler_type, |
971 | | clang::ObjCIvarDecl *ivar_decl, |
972 | | const char *property_setter_name, |
973 | | const char *property_getter_name, |
974 | | uint32_t property_attributes, |
975 | | ClangASTMetadata *metadata); |
976 | | |
977 | | static clang::ObjCMethodDecl *AddMethodToObjCObjectType( |
978 | | const CompilerType &type, |
979 | | const char *name, // the full symbol name as seen in the symbol table |
980 | | // (lldb::opaque_compiler_type_t type, "-[NString |
981 | | // stringWithCString:]") |
982 | | const CompilerType &method_compiler_type, lldb::AccessType access, |
983 | | bool is_artificial, bool is_variadic, bool is_objc_direct_call); |
984 | | |
985 | | static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, |
986 | | bool has_extern); |
987 | | |
988 | | // Tag Declarations |
989 | | static bool StartTagDeclarationDefinition(const CompilerType &type); |
990 | | |
991 | | static bool CompleteTagDeclarationDefinition(const CompilerType &type); |
992 | | |
993 | | // Modifying Enumeration types |
994 | | clang::EnumConstantDecl *AddEnumerationValueToEnumerationType( |
995 | | const CompilerType &enum_type, const Declaration &decl, const char *name, |
996 | | int64_t enum_value, uint32_t enum_value_bit_size); |
997 | | clang::EnumConstantDecl *AddEnumerationValueToEnumerationType( |
998 | | const CompilerType &enum_type, const Declaration &decl, const char *name, |
999 | | const llvm::APSInt &value); |
1000 | | |
1001 | | /// Returns the underlying integer type for an enum type. If the given type |
1002 | | /// is invalid or not an enum-type, the function returns an invalid |
1003 | | /// CompilerType. |
1004 | | CompilerType GetEnumerationIntegerType(CompilerType type); |
1005 | | |
1006 | | // Pointers & References |
1007 | | |
1008 | | // Call this function using the class type when you want to make a member |
1009 | | // pointer type to pointee_type. |
1010 | | static CompilerType CreateMemberPointerType(const CompilerType &type, |
1011 | | const CompilerType &pointee_type); |
1012 | | |
1013 | | // Dumping types |
1014 | | #ifndef NDEBUG |
1015 | | /// Convenience LLVM-style dump method for use in the debugger only. |
1016 | | /// In contrast to the other \p Dump() methods this directly invokes |
1017 | | /// \p clang::QualType::dump(). |
1018 | | LLVM_DUMP_METHOD void dump(lldb::opaque_compiler_type_t type) const override; |
1019 | | #endif |
1020 | | |
1021 | | /// \see lldb_private::TypeSystem::Dump |
1022 | | void Dump(llvm::raw_ostream &output) override; |
1023 | | |
1024 | | /// Dump clang AST types from the symbol file. |
1025 | | /// |
1026 | | /// \param[in] s |
1027 | | /// A stream to send the dumped AST node(s) to |
1028 | | /// \param[in] symbol_name |
1029 | | /// The name of the symbol to dump, if it is empty dump all the symbols |
1030 | | void DumpFromSymbolFile(Stream &s, llvm::StringRef symbol_name); |
1031 | | |
1032 | | void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
1033 | | Stream &s, lldb::Format format, const DataExtractor &data, |
1034 | | lldb::offset_t data_offset, size_t data_byte_size, |
1035 | | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, |
1036 | | bool show_types, bool show_summary, bool verbose, |
1037 | | uint32_t depth) override; |
1038 | | |
1039 | | bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s, |
1040 | | lldb::Format format, const DataExtractor &data, |
1041 | | lldb::offset_t data_offset, size_t data_byte_size, |
1042 | | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, |
1043 | | ExecutionContextScope *exe_scope) override; |
1044 | | |
1045 | | void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
1046 | | Stream &s, const DataExtractor &data, |
1047 | | lldb::offset_t data_offset, size_t data_byte_size) override; |
1048 | | |
1049 | | void DumpTypeDescription( |
1050 | | lldb::opaque_compiler_type_t type, |
1051 | | lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; |
1052 | | |
1053 | | void DumpTypeDescription( |
1054 | | lldb::opaque_compiler_type_t type, Stream &s, |
1055 | | lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override; |
1056 | | |
1057 | | static void DumpTypeName(const CompilerType &type); |
1058 | | |
1059 | | static clang::EnumDecl *GetAsEnumDecl(const CompilerType &type); |
1060 | | |
1061 | | static clang::RecordDecl *GetAsRecordDecl(const CompilerType &type); |
1062 | | |
1063 | | static clang::TagDecl *GetAsTagDecl(const CompilerType &type); |
1064 | | |
1065 | | static clang::TypedefNameDecl *GetAsTypedefDecl(const CompilerType &type); |
1066 | | |
1067 | | static clang::CXXRecordDecl * |
1068 | | GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type); |
1069 | | |
1070 | | static clang::ObjCInterfaceDecl * |
1071 | | GetAsObjCInterfaceDecl(const CompilerType &type); |
1072 | | |
1073 | | clang::ClassTemplateDecl *ParseClassTemplateDecl( |
1074 | | clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, |
1075 | | lldb::AccessType access_type, const char *parent_name, int tag_decl_kind, |
1076 | | const TypeSystemClang::TemplateParameterInfos &template_param_infos); |
1077 | | |
1078 | | clang::BlockDecl *CreateBlockDeclaration(clang::DeclContext *ctx, |
1079 | | OptionalClangModuleID owning_module); |
1080 | | |
1081 | | clang::UsingDirectiveDecl * |
1082 | | CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx, |
1083 | | OptionalClangModuleID owning_module, |
1084 | | clang::NamespaceDecl *ns_decl); |
1085 | | |
1086 | | clang::UsingDecl *CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, |
1087 | | OptionalClangModuleID owning_module, |
1088 | | clang::NamedDecl *target); |
1089 | | |
1090 | | clang::VarDecl *CreateVariableDeclaration(clang::DeclContext *decl_context, |
1091 | | OptionalClangModuleID owning_module, |
1092 | | const char *name, |
1093 | | clang::QualType type); |
1094 | | |
1095 | | static lldb::opaque_compiler_type_t |
1096 | | GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type); |
1097 | | |
1098 | 2.52M | static clang::QualType GetQualType(lldb::opaque_compiler_type_t type) { |
1099 | 2.52M | if (type) |
1100 | 2.52M | return clang::QualType::getFromOpaquePtr(type); |
1101 | 0 | return clang::QualType(); |
1102 | 2.52M | } |
1103 | | |
1104 | | static clang::QualType |
1105 | 2.71M | GetCanonicalQualType(lldb::opaque_compiler_type_t type) { |
1106 | 2.71M | if (type) |
1107 | 2.71M | return clang::QualType::getFromOpaquePtr(type).getCanonicalType(); |
1108 | 0 | return clang::QualType(); |
1109 | 2.71M | } |
1110 | | |
1111 | | clang::DeclarationName |
1112 | | GetDeclarationName(llvm::StringRef name, |
1113 | | const CompilerType &function_clang_type); |
1114 | | |
1115 | 0 | clang::LangOptions *GetLangOpts() const { |
1116 | 0 | return m_language_options_up.get(); |
1117 | 0 | } |
1118 | 0 | clang::SourceManager *GetSourceMgr() const { |
1119 | 0 | return m_source_manager_up.get(); |
1120 | 0 | } |
1121 | | |
1122 | | /// Complete a type from debug info, or mark it as forcefully completed if |
1123 | | /// there is no definition of the type in the current Module. Call this |
1124 | | /// function in contexts where the usual C++ rules require a type to be |
1125 | | /// complete (base class, member, etc.). |
1126 | | static void RequireCompleteType(CompilerType type); |
1127 | | |
1128 | | bool SetDeclIsForcefullyCompleted(const clang::TagDecl *td); |
1129 | | |
1130 | | /// Return the template parameters (including surrounding <>) in string form. |
1131 | | std::string |
1132 | | PrintTemplateParams(const TemplateParameterInfos &template_param_infos); |
1133 | | |
1134 | | private: |
1135 | | /// Returns the PrintingPolicy used when generating the internal type names. |
1136 | | /// These type names are mostly used for the formatter selection. |
1137 | | clang::PrintingPolicy GetTypePrintingPolicy(); |
1138 | | /// Returns the internal type name for the given NamedDecl using the |
1139 | | /// type printing policy. |
1140 | | std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl, |
1141 | | bool qualified = true); |
1142 | | |
1143 | | const clang::ClassTemplateSpecializationDecl * |
1144 | | GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type); |
1145 | | |
1146 | | bool IsTypeImpl(lldb::opaque_compiler_type_t type, |
1147 | | llvm::function_ref<bool(clang::QualType)> predicate) const; |
1148 | | |
1149 | | // Classes that inherit from TypeSystemClang can see and modify these |
1150 | | std::string m_target_triple; |
1151 | | std::unique_ptr<clang::ASTContext> m_ast_up; |
1152 | | std::unique_ptr<clang::LangOptions> m_language_options_up; |
1153 | | std::unique_ptr<clang::FileManager> m_file_manager_up; |
1154 | | std::unique_ptr<clang::SourceManager> m_source_manager_up; |
1155 | | std::unique_ptr<clang::DiagnosticsEngine> m_diagnostics_engine_up; |
1156 | | std::unique_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_up; |
1157 | | std::shared_ptr<clang::TargetOptions> m_target_options_rp; |
1158 | | std::unique_ptr<clang::TargetInfo> m_target_info_up; |
1159 | | std::unique_ptr<clang::IdentifierTable> m_identifier_table_up; |
1160 | | std::unique_ptr<clang::SelectorTable> m_selector_table_up; |
1161 | | std::unique_ptr<clang::Builtin::Context> m_builtins_up; |
1162 | | std::unique_ptr<clang::HeaderSearch> m_header_search_up; |
1163 | | std::unique_ptr<clang::ModuleMap> m_module_map_up; |
1164 | | std::unique_ptr<DWARFASTParserClang> m_dwarf_ast_parser_up; |
1165 | | std::unique_ptr<PDBASTParser> m_pdb_ast_parser_up; |
1166 | | std::unique_ptr<npdb::PdbAstBuilder> m_native_pdb_ast_parser_up; |
1167 | | std::unique_ptr<clang::MangleContext> m_mangle_ctx_up; |
1168 | | uint32_t m_pointer_byte_size = 0; |
1169 | | bool m_ast_owned = false; |
1170 | | /// A string describing what this TypeSystemClang represents (e.g., |
1171 | | /// AST for debug information, an expression, some other utility ClangAST). |
1172 | | /// Useful for logging and debugging. |
1173 | | std::string m_display_name; |
1174 | | |
1175 | | typedef llvm::DenseMap<const clang::Decl *, ClangASTMetadata> DeclMetadataMap; |
1176 | | /// Maps Decls to their associated ClangASTMetadata. |
1177 | | DeclMetadataMap m_decl_metadata; |
1178 | | |
1179 | | typedef llvm::DenseMap<const clang::Type *, ClangASTMetadata> TypeMetadataMap; |
1180 | | /// Maps Types to their associated ClangASTMetadata. |
1181 | | TypeMetadataMap m_type_metadata; |
1182 | | |
1183 | | typedef llvm::DenseMap<const clang::CXXRecordDecl *, clang::AccessSpecifier> |
1184 | | CXXRecordDeclAccessMap; |
1185 | | /// Maps CXXRecordDecl to their most recent added method/field's |
1186 | | /// AccessSpecifier. |
1187 | | CXXRecordDeclAccessMap m_cxx_record_decl_access; |
1188 | | |
1189 | | /// The sema associated that is currently used to build this ASTContext. |
1190 | | /// May be null if we are already done parsing this ASTContext or the |
1191 | | /// ASTContext wasn't created by parsing source code. |
1192 | | clang::Sema *m_sema = nullptr; |
1193 | | |
1194 | | // For TypeSystemClang only |
1195 | | TypeSystemClang(const TypeSystemClang &); |
1196 | | const TypeSystemClang &operator=(const TypeSystemClang &); |
1197 | | /// Creates the internal ASTContext. |
1198 | | void CreateASTContext(); |
1199 | | void SetTargetTriple(llvm::StringRef target_triple); |
1200 | | }; |
1201 | | |
1202 | | /// The TypeSystemClang instance used for the scratch ASTContext in a |
1203 | | /// lldb::Target. |
1204 | | class ScratchTypeSystemClang : public TypeSystemClang { |
1205 | | /// LLVM RTTI support |
1206 | | static char ID; |
1207 | | |
1208 | | public: |
1209 | | ScratchTypeSystemClang(Target &target, llvm::Triple triple); |
1210 | | |
1211 | 2.03k | ~ScratchTypeSystemClang() override = default; |
1212 | | |
1213 | | void Finalize() override; |
1214 | | |
1215 | | /// The different kinds of isolated ASTs within the scratch TypeSystem. |
1216 | | /// |
1217 | | /// These ASTs are isolated from the main scratch AST and are each |
1218 | | /// dedicated to a special language option/feature that makes the contained |
1219 | | /// AST nodes incompatible with other AST nodes. |
1220 | | enum IsolatedASTKind { |
1221 | | /// The isolated AST for declarations/types from expressions that imported |
1222 | | /// type information from a C++ module. The templates from a C++ module |
1223 | | /// often conflict with the templates we generate from debug information, |
1224 | | /// so we put these types in their own AST. |
1225 | | CppModules |
1226 | | }; |
1227 | | |
1228 | | /// Alias for requesting the default scratch TypeSystemClang in GetForTarget. |
1229 | | // This isn't constexpr as gtest/std::optional comparison logic is trying |
1230 | | // to get the address of this for pretty-printing. |
1231 | | static const std::nullopt_t DefaultAST; |
1232 | | |
1233 | | /// Infers the appropriate sub-AST from Clang's LangOptions. |
1234 | | static std::optional<IsolatedASTKind> |
1235 | 20.7k | InferIsolatedASTKindFromLangOpts(const clang::LangOptions &l) { |
1236 | | // If modules are activated we want the dedicated C++ module AST. |
1237 | | // See IsolatedASTKind::CppModules for more info. |
1238 | 20.7k | if (l.Modules) |
1239 | 1.00k | return IsolatedASTKind::CppModules; |
1240 | 19.7k | return DefaultAST; |
1241 | 20.7k | } |
1242 | | |
1243 | | /// Returns the scratch TypeSystemClang for the given target. |
1244 | | /// \param target The Target which scratch TypeSystemClang should be returned. |
1245 | | /// \param ast_kind Allows requesting a specific sub-AST instead of the |
1246 | | /// default scratch AST. See also `IsolatedASTKind`. |
1247 | | /// \param create_on_demand If the scratch TypeSystemClang instance can be |
1248 | | /// created by this call if it doesn't exist yet. If it doesn't exist yet and |
1249 | | /// this parameter is false, this function returns a nullptr. |
1250 | | /// \return The scratch type system of the target or a nullptr in case an |
1251 | | /// error occurred. |
1252 | | static lldb::TypeSystemClangSP |
1253 | | GetForTarget(Target &target, |
1254 | | std::optional<IsolatedASTKind> ast_kind = DefaultAST, |
1255 | | bool create_on_demand = true); |
1256 | | |
1257 | | /// Returns the scratch TypeSystemClang for the given target. The returned |
1258 | | /// TypeSystemClang will be the scratch AST or a sub-AST, depending on which |
1259 | | /// fits best to the passed LangOptions. |
1260 | | /// \param target The Target which scratch TypeSystemClang should be returned. |
1261 | | /// \param lang_opts The LangOptions of a clang ASTContext that the caller |
1262 | | /// wants to export type information from. This is used to |
1263 | | /// find the best matching sub-AST that will be returned. |
1264 | | static lldb::TypeSystemClangSP |
1265 | 20.7k | GetForTarget(Target &target, const clang::LangOptions &lang_opts) { |
1266 | 20.7k | return GetForTarget(target, InferIsolatedASTKindFromLangOpts(lang_opts)); |
1267 | 20.7k | } |
1268 | | |
1269 | | /// \see lldb_private::TypeSystem::Dump |
1270 | | void Dump(llvm::raw_ostream &output) override; |
1271 | | |
1272 | | UserExpression * |
1273 | | GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix, |
1274 | | lldb::LanguageType language, |
1275 | | Expression::ResultType desired_type, |
1276 | | const EvaluateExpressionOptions &options, |
1277 | | ValueObject *ctx_obj) override; |
1278 | | |
1279 | | FunctionCaller *GetFunctionCaller(const CompilerType &return_type, |
1280 | | const Address &function_address, |
1281 | | const ValueList &arg_value_list, |
1282 | | const char *name) override; |
1283 | | |
1284 | | std::unique_ptr<UtilityFunction> |
1285 | | CreateUtilityFunction(std::string text, std::string name) override; |
1286 | | |
1287 | | PersistentExpressionState *GetPersistentExpressionState() override; |
1288 | | |
1289 | | /// Unregisters the given ASTContext as a source from the scratch AST (and |
1290 | | /// all sub-ASTs). |
1291 | | /// \see ClangASTImporter::ForgetSource |
1292 | | void ForgetSource(clang::ASTContext *src_ctx, ClangASTImporter &importer); |
1293 | | |
1294 | | // llvm casting support |
1295 | 160k | bool isA(const void *ClassID) const override { |
1296 | 160k | return ClassID == &ID || TypeSystemClang::isA(ClassID)70.1k ; |
1297 | 160k | } |
1298 | 90.3k | static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } |
1299 | | |
1300 | | private: |
1301 | | std::unique_ptr<ClangASTSource> CreateASTSource(); |
1302 | | /// Returns the requested sub-AST. |
1303 | | /// Will lazily create the sub-AST if it hasn't been created before. |
1304 | | TypeSystemClang &GetIsolatedAST(IsolatedASTKind feature); |
1305 | | |
1306 | | /// The target triple. |
1307 | | /// This was potentially adjusted and might not be identical to the triple |
1308 | | /// of `m_target_wp`. |
1309 | | llvm::Triple m_triple; |
1310 | | lldb::TargetWP m_target_wp; |
1311 | | /// The persistent variables associated with this process for the expression |
1312 | | /// parser. |
1313 | | std::unique_ptr<ClangPersistentVariables> m_persistent_variables; |
1314 | | /// The ExternalASTSource that performs lookups and completes minimally |
1315 | | /// imported types. |
1316 | | std::unique_ptr<ClangASTSource> m_scratch_ast_source_up; |
1317 | | |
1318 | | // FIXME: GCC 5.x doesn't support enum as map keys. |
1319 | | typedef int IsolatedASTKey; |
1320 | | |
1321 | | /// Map from IsolatedASTKind to their actual TypeSystemClang instance. |
1322 | | /// This map is lazily filled with sub-ASTs and should be accessed via |
1323 | | /// `GetSubAST` (which lazily fills this map). |
1324 | | llvm::DenseMap<IsolatedASTKey, std::shared_ptr<TypeSystemClang>> |
1325 | | m_isolated_asts; |
1326 | | }; |
1327 | | |
1328 | | } // namespace lldb_private |
1329 | | |
1330 | | #endif // LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_TYPESYSTEMCLANG_H |