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