LLDB mainline
TypeSystemClang.cpp
Go to the documentation of this file.
1//===-- TypeSystemClang.cpp -----------------------------------------------==='//
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#include "TypeSystemClang.h"
10
11#include "clang/AST/DeclBase.h"
12#include "llvm/Support/Casting.h"
13#include "llvm/Support/FormatAdapters.h"
14#include "llvm/Support/FormatVariadic.h"
15
16#include <mutex>
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "clang/AST/ASTContext.h"
22#include "clang/AST/ASTImporter.h"
23#include "clang/AST/Attr.h"
24#include "clang/AST/CXXInheritance.h"
25#include "clang/AST/DeclObjC.h"
26#include "clang/AST/DeclTemplate.h"
27#include "clang/AST/Mangle.h"
28#include "clang/AST/RecordLayout.h"
29#include "clang/AST/Type.h"
30#include "clang/AST/VTableBuilder.h"
31#include "clang/Basic/Builtins.h"
32#include "clang/Basic/Diagnostic.h"
33#include "clang/Basic/FileManager.h"
34#include "clang/Basic/FileSystemOptions.h"
35#include "clang/Basic/LangStandard.h"
36#include "clang/Basic/SourceManager.h"
37#include "clang/Basic/TargetInfo.h"
38#include "clang/Basic/TargetOptions.h"
39#include "clang/Frontend/FrontendOptions.h"
40#include "clang/Lex/HeaderSearch.h"
41#include "clang/Lex/HeaderSearchOptions.h"
42#include "clang/Lex/ModuleMap.h"
43#include "clang/Sema/Sema.h"
44
45#include "llvm/Support/Signals.h"
46#include "llvm/Support/Threading.h"
47
57#include "lldb/Core/Module.h"
66#include "lldb/Target/Process.h"
67#include "lldb/Target/Target.h"
70#include "lldb/Utility/Flags.h"
74#include "lldb/Utility/Scalar.h"
75
80
81#include <cstdio>
82
83#include <mutex>
84#include <optional>
85
86using namespace lldb;
87using namespace lldb_private;
88using namespace lldb_private::dwarf;
89using namespace clang;
90using llvm::StringSwitch;
91
93
94namespace {
95static void VerifyDecl(clang::Decl *decl) {
96 assert(decl && "VerifyDecl called with nullptr?");
97#ifndef NDEBUG
98 // We don't care about the actual access value here but only want to trigger
99 // that Clang calls its internal Decl::AccessDeclContextCheck validation.
100 decl->getAccess();
101#endif
102}
103
104static inline bool
105TypeSystemClangSupportsLanguage(lldb::LanguageType language) {
106 return language == eLanguageTypeUnknown || // Clang is the default type system
111 // Use Clang for Rust until there is a proper language plugin for it
112 language == eLanguageTypeRust ||
113 // Use Clang for D until there is a proper language plugin for it
114 language == eLanguageTypeD ||
115 // Open Dylan compiler debug info is designed to be Clang-compatible
116 language == eLanguageTypeDylan;
117}
118
119// Checks whether m1 is an overload of m2 (as opposed to an override). This is
120// called by addOverridesForMethod to distinguish overrides (which share a
121// vtable entry) from overloads (which require distinct entries).
122bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
123 // FIXME: This should detect covariant return types, but currently doesn't.
124 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
125 "Methods should have the same AST context");
126 clang::ASTContext &context = m1->getASTContext();
127
128 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
129 context.getCanonicalType(m1->getType()));
130
131 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
132 context.getCanonicalType(m2->getType()));
133
134 auto compareArgTypes = [&context](const clang::QualType &m1p,
135 const clang::QualType &m2p) {
136 return context.hasSameType(m1p.getUnqualifiedType(),
137 m2p.getUnqualifiedType());
138 };
139
140 // FIXME: In C++14 and later, we can just pass m2Type->param_type_end()
141 // as a fourth parameter to std::equal().
142 return (m1->getNumParams() != m2->getNumParams()) ||
143 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
144 m2Type->param_type_begin(), compareArgTypes);
145}
146
147// If decl is a virtual method, walk the base classes looking for methods that
148// decl overrides. This table of overridden methods is used by IRGen to
149// determine the vtable layout for decl's parent class.
150void addOverridesForMethod(clang::CXXMethodDecl *decl) {
151 if (!decl->isVirtual())
152 return;
153
154 clang::CXXBasePaths paths;
155 llvm::SmallVector<clang::NamedDecl *, 4> decls;
156
157 auto find_overridden_methods =
158 [&decls, decl](const clang::CXXBaseSpecifier *specifier,
159 clang::CXXBasePath &path) {
160 if (auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
161 specifier->getType()->castAs<clang::RecordType>()->getDecl())) {
162
163 clang::DeclarationName name = decl->getDeclName();
164
165 // If this is a destructor, check whether the base class destructor is
166 // virtual.
167 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
168 if (auto *baseDtorDecl = base_record->getDestructor()) {
169 if (baseDtorDecl->isVirtual()) {
170 decls.push_back(baseDtorDecl);
171 return true;
172 } else
173 return false;
174 }
175
176 // Otherwise, search for name in the base class.
177 for (path.Decls = base_record->lookup(name).begin();
178 path.Decls != path.Decls.end(); ++path.Decls) {
179 if (auto *method_decl =
180 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
181 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
182 decls.push_back(method_decl);
183 return true;
184 }
185 }
186 }
187
188 return false;
189 };
190
191 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
192 for (auto *overridden_decl : decls)
193 decl->addOverriddenMethod(
194 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
195 }
196}
197}
198
200 VTableContextBase &vtable_ctx,
201 ValueObject &valobj,
202 const ASTRecordLayout &record_layout) {
203 // Retrieve type info
204 CompilerType pointee_type;
205 CompilerType this_type(valobj.GetCompilerType());
206 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
207 if (!type_info)
209
210 // Check if it's a pointer or reference
211 bool ptr_or_ref = false;
212 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
213 ptr_or_ref = true;
214 type_info = pointee_type.GetTypeInfo();
215 }
216
217 // We process only C++ classes
218 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
219 if ((type_info & cpp_class) != cpp_class)
221
222 // Calculate offset to VTable pointer
223 lldb::offset_t vbtable_ptr_offset =
224 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
225 : 0;
226
227 if (ptr_or_ref) {
228 // We have a pointer / ref to object, so read
229 // VTable pointer from process memory
230
233
234 auto vbtable_ptr_addr = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
235 if (vbtable_ptr_addr == LLDB_INVALID_ADDRESS)
237
238 vbtable_ptr_addr += vbtable_ptr_offset;
239
240 Status err;
241 return process.ReadPointerFromMemory(vbtable_ptr_addr, err);
242 }
243
244 // We have an object already read from process memory,
245 // so just extract VTable pointer from it
246
247 DataExtractor data;
248 Status err;
249 auto size = valobj.GetData(data, err);
250 if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size)
252
253 return data.GetAddress(&vbtable_ptr_offset);
254}
255
256static int64_t ReadVBaseOffsetFromVTable(Process &process,
257 VTableContextBase &vtable_ctx,
258 lldb::addr_t vtable_ptr,
259 const CXXRecordDecl *cxx_record_decl,
260 const CXXRecordDecl *base_class_decl) {
261 if (vtable_ctx.isMicrosoft()) {
262 clang::MicrosoftVTableContext &msoft_vtable_ctx =
263 static_cast<clang::MicrosoftVTableContext &>(vtable_ctx);
264
265 // Get the index into the virtual base table. The
266 // index is the index in uint32_t from vbtable_ptr
267 const unsigned vbtable_index =
268 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
269 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
270 Status err;
271 return process.ReadSignedIntegerFromMemory(base_offset_addr, 4, INT64_MAX,
272 err);
273 }
274
275 clang::ItaniumVTableContext &itanium_vtable_ctx =
276 static_cast<clang::ItaniumVTableContext &>(vtable_ctx);
277
278 clang::CharUnits base_offset_offset =
279 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
280 base_class_decl);
281 const lldb::addr_t base_offset_addr =
282 vtable_ptr + base_offset_offset.getQuantity();
283 const uint32_t base_offset_size = process.GetAddressByteSize();
284 Status err;
285 return process.ReadSignedIntegerFromMemory(base_offset_addr, base_offset_size,
286 INT64_MAX, err);
287}
288
289static bool GetVBaseBitOffset(VTableContextBase &vtable_ctx,
290 ValueObject &valobj,
291 const ASTRecordLayout &record_layout,
292 const CXXRecordDecl *cxx_record_decl,
293 const CXXRecordDecl *base_class_decl,
294 int32_t &bit_offset) {
296 Process *process = exe_ctx.GetProcessPtr();
297 if (!process)
298 return false;
299
300 lldb::addr_t vtable_ptr =
301 GetVTableAddress(*process, vtable_ctx, valobj, record_layout);
302 if (vtable_ptr == LLDB_INVALID_ADDRESS)
303 return false;
304
305 auto base_offset = ReadVBaseOffsetFromVTable(
306 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
307 if (base_offset == INT64_MAX)
308 return false;
309
310 bit_offset = base_offset * 8;
311
312 return true;
313}
314
317
319 static ClangASTMap *g_map_ptr = nullptr;
320 static llvm::once_flag g_once_flag;
321 llvm::call_once(g_once_flag, []() {
322 g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins
323 });
324 return *g_map_ptr;
325}
326
328 bool is_complete_objc_class)
329 : m_payload(owning_module.GetValue()) {
330 SetIsCompleteObjCClass(is_complete_objc_class);
331}
332
334 assert(id.GetValue() < ObjCClassBit);
335 bool is_complete = IsCompleteObjCClass();
336 m_payload = id.GetValue();
337 SetIsCompleteObjCClass(is_complete);
338}
339
340static void SetMemberOwningModule(clang::Decl *member,
341 const clang::Decl *parent) {
342 if (!member || !parent)
343 return;
344
345 OptionalClangModuleID id(parent->getOwningModuleID());
346 if (!id.HasValue())
347 return;
348
349 member->setFromASTFile();
350 member->setOwningModuleID(id.GetValue());
351 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
352 if (llvm::isa<clang::NamedDecl>(member))
353 if (auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
354 dc->setHasExternalVisibleStorage(true);
355 // This triggers ExternalASTSource::FindExternalVisibleDeclsByName() to be
356 // called when searching for members.
357 dc->setHasExternalLexicalStorage(true);
358 }
359}
360
362
363bool TypeSystemClang::IsOperator(llvm::StringRef name,
364 clang::OverloadedOperatorKind &op_kind) {
365 // All operators have to start with "operator".
366 if (!name.consume_front("operator"))
367 return false;
368
369 // Remember if there was a space after "operator". This is necessary to
370 // check for collisions with strangely named functions like "operatorint()".
371 bool space_after_operator = name.consume_front(" ");
372
373 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
374 .Case("+", clang::OO_Plus)
375 .Case("+=", clang::OO_PlusEqual)
376 .Case("++", clang::OO_PlusPlus)
377 .Case("-", clang::OO_Minus)
378 .Case("-=", clang::OO_MinusEqual)
379 .Case("--", clang::OO_MinusMinus)
380 .Case("->", clang::OO_Arrow)
381 .Case("->*", clang::OO_ArrowStar)
382 .Case("*", clang::OO_Star)
383 .Case("*=", clang::OO_StarEqual)
384 .Case("/", clang::OO_Slash)
385 .Case("/=", clang::OO_SlashEqual)
386 .Case("%", clang::OO_Percent)
387 .Case("%=", clang::OO_PercentEqual)
388 .Case("^", clang::OO_Caret)
389 .Case("^=", clang::OO_CaretEqual)
390 .Case("&", clang::OO_Amp)
391 .Case("&=", clang::OO_AmpEqual)
392 .Case("&&", clang::OO_AmpAmp)
393 .Case("|", clang::OO_Pipe)
394 .Case("|=", clang::OO_PipeEqual)
395 .Case("||", clang::OO_PipePipe)
396 .Case("~", clang::OO_Tilde)
397 .Case("!", clang::OO_Exclaim)
398 .Case("!=", clang::OO_ExclaimEqual)
399 .Case("=", clang::OO_Equal)
400 .Case("==", clang::OO_EqualEqual)
401 .Case("<", clang::OO_Less)
402 .Case("<<", clang::OO_LessLess)
403 .Case("<<=", clang::OO_LessLessEqual)
404 .Case("<=", clang::OO_LessEqual)
405 .Case(">", clang::OO_Greater)
406 .Case(">>", clang::OO_GreaterGreater)
407 .Case(">>=", clang::OO_GreaterGreaterEqual)
408 .Case(">=", clang::OO_GreaterEqual)
409 .Case("()", clang::OO_Call)
410 .Case("[]", clang::OO_Subscript)
411 .Case(",", clang::OO_Comma)
412 .Default(clang::NUM_OVERLOADED_OPERATORS);
413
414 // We found a fitting operator, so we can exit now.
415 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
416 return true;
417
418 // After the "operator " or "operator" part is something unknown. This means
419 // it's either one of the named operators (new/delete), a conversion operator
420 // (e.g. operator bool) or a function which name starts with "operator"
421 // (e.g. void operatorbool).
422
423 // If it's a function that starts with operator it can't have a space after
424 // "operator" because identifiers can't contain spaces.
425 // E.g. "operator int" (conversion operator)
426 // vs. "operatorint" (function with colliding name).
427 if (!space_after_operator)
428 return false; // not an operator.
429
430 // Now the operator is either one of the named operators or a conversion
431 // operator.
432 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
433 .Case("new", clang::OO_New)
434 .Case("new[]", clang::OO_Array_New)
435 .Case("delete", clang::OO_Delete)
436 .Case("delete[]", clang::OO_Array_Delete)
437 // conversion operators hit this case.
438 .Default(clang::NUM_OVERLOADED_OPERATORS);
439
440 return true;
441}
442
443clang::AccessSpecifier
445 switch (access) {
446 default:
447 break;
448 case eAccessNone:
449 return AS_none;
450 case eAccessPublic:
451 return AS_public;
452 case eAccessPrivate:
453 return AS_private;
454 case eAccessProtected:
455 return AS_protected;
456 }
457 return AS_none;
458}
459
460static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) {
461 // FIXME: Cleanup per-file based stuff.
462
463 // Set some properties which depend solely on the input kind; it would be
464 // nice to move these to the language standard, and have the driver resolve
465 // the input kind + language standard.
466 if (IK.getLanguage() == clang::Language::Asm) {
467 Opts.AsmPreprocessor = 1;
468 } else if (IK.isObjectiveC()) {
469 Opts.ObjC = 1;
470 }
471
472 LangStandard::Kind LangStd = LangStandard::lang_unspecified;
473
474 if (LangStd == LangStandard::lang_unspecified) {
475 // Based on the base language, pick one.
476 switch (IK.getLanguage()) {
477 case clang::Language::Unknown:
478 case clang::Language::LLVM_IR:
479 case clang::Language::RenderScript:
480 llvm_unreachable("Invalid input kind!");
481 case clang::Language::OpenCL:
482 LangStd = LangStandard::lang_opencl10;
483 break;
484 case clang::Language::OpenCLCXX:
485 LangStd = LangStandard::lang_openclcpp10;
486 break;
487 case clang::Language::CUDA:
488 LangStd = LangStandard::lang_cuda;
489 break;
490 case clang::Language::Asm:
491 case clang::Language::C:
492 case clang::Language::ObjC:
493 LangStd = LangStandard::lang_gnu99;
494 break;
495 case clang::Language::CXX:
496 case clang::Language::ObjCXX:
497 LangStd = LangStandard::lang_gnucxx98;
498 break;
499 case clang::Language::HIP:
500 LangStd = LangStandard::lang_hip;
501 break;
502 case clang::Language::HLSL:
503 LangStd = LangStandard::lang_hlsl;
504 break;
505 }
506 }
507
508 const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
509 Opts.LineComment = Std.hasLineComments();
510 Opts.C99 = Std.isC99();
511 Opts.CPlusPlus = Std.isCPlusPlus();
512 Opts.CPlusPlus11 = Std.isCPlusPlus11();
513 Opts.Digraphs = Std.hasDigraphs();
514 Opts.GNUMode = Std.isGNUMode();
515 Opts.GNUInline = !Std.isC99();
516 Opts.HexFloats = Std.hasHexFloats();
517
518 Opts.WChar = true;
519
520 // OpenCL has some additional defaults.
521 if (LangStd == LangStandard::lang_opencl10) {
522 Opts.OpenCL = 1;
523 Opts.AltiVec = 1;
524 Opts.CXXOperatorNames = 1;
525 Opts.setLaxVectorConversions(LangOptions::LaxVectorConversionKind::All);
526 }
527
528 // OpenCL and C++ both have bool, true, false keywords.
529 Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
530
531 Opts.setValueVisibilityMode(DefaultVisibility);
532
533 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs is
534 // specified, or -std is set to a conforming mode.
535 Opts.Trigraphs = !Opts.GNUMode;
536 Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault();
537 Opts.OptimizeSize = 0;
538
539 // FIXME: Eliminate this dependency.
540 // unsigned Opt =
541 // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags);
542 // Opts.Optimize = Opt != 0;
543 unsigned Opt = 0;
544
545 // This is the __NO_INLINE__ define, which just depends on things like the
546 // optimization level and -fno-inline, not actually whether the backend has
547 // inlining enabled.
548 //
549 // FIXME: This is affected by other options (-fno-inline).
550 Opts.NoInlineDefine = !Opt;
551
552 // This is needed to allocate the extra space for the owning module
553 // on each decl.
554 Opts.ModulesLocalVisibility = 1;
555}
556
558 llvm::Triple target_triple) {
559 m_display_name = name.str();
560 if (!target_triple.str().empty())
561 SetTargetTriple(target_triple.str());
562 // The caller didn't pass an ASTContext so create a new one for this
563 // TypeSystemClang.
565}
566
567TypeSystemClang::TypeSystemClang(llvm::StringRef name,
568 ASTContext &existing_ctxt) {
569 m_display_name = name.str();
570 SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
571
572 m_ast_up.reset(&existing_ctxt);
573 GetASTMap().Insert(&existing_ctxt, this);
574}
575
576// Destructor
578
580 lldb_private::Module *module,
581 Target *target) {
582 if (!TypeSystemClangSupportsLanguage(language))
583 return lldb::TypeSystemSP();
584 ArchSpec arch;
585 if (module)
586 arch = module->GetArchitecture();
587 else if (target)
588 arch = target->GetArchitecture();
589
590 if (!arch.IsValid())
591 return lldb::TypeSystemSP();
592
593 llvm::Triple triple = arch.GetTriple();
594 // LLVM wants this to be set to iOS or MacOSX; if we're working on
595 // a bare-boards type image, change the triple for llvm's benefit.
596 if (triple.getVendor() == llvm::Triple::Apple &&
597 triple.getOS() == llvm::Triple::UnknownOS) {
598 if (triple.getArch() == llvm::Triple::arm ||
599 triple.getArch() == llvm::Triple::aarch64 ||
600 triple.getArch() == llvm::Triple::aarch64_32 ||
601 triple.getArch() == llvm::Triple::thumb) {
602 triple.setOS(llvm::Triple::IOS);
603 } else {
604 triple.setOS(llvm::Triple::MacOSX);
605 }
606 }
607
608 if (module) {
609 std::string ast_name =
610 "ASTContext for '" + module->GetFileSpec().GetPath() + "'";
611 return std::make_shared<TypeSystemClang>(ast_name, triple);
612 } else if (target && target->IsValid())
613 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
614 return lldb::TypeSystemSP();
615}
616
618 LanguageSet languages;
620 languages.Insert(lldb::eLanguageTypeC);
630 return languages;
631}
632
634 LanguageSet languages;
640 return languages;
641}
642
645 GetPluginNameStatic(), "clang base AST context plug-in", CreateInstance,
647}
648
651}
652
654 assert(m_ast_up);
655 GetASTMap().Erase(m_ast_up.get());
656 if (!m_ast_owned)
657 m_ast_up.release();
658
659 m_builtins_up.reset();
660 m_selector_table_up.reset();
661 m_identifier_table_up.reset();
662 m_target_info_up.reset();
663 m_target_options_rp.reset();
665 m_source_manager_up.reset();
666 m_language_options_up.reset();
667}
668
670 // Ensure that the new sema actually belongs to our ASTContext.
671 assert(s == nullptr || &s->getASTContext() == m_ast_up.get());
672 m_sema = s;
673}
674
676 return m_target_triple.c_str();
677}
678
679void TypeSystemClang::SetTargetTriple(llvm::StringRef target_triple) {
680 m_target_triple = target_triple.str();
681}
682
684 llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
685 ASTContext &ast = getASTContext();
686 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(true);
687 ast.setExternalSource(ast_source_up);
688}
689
691 assert(m_ast_up);
692 return *m_ast_up;
693}
694
695class NullDiagnosticConsumer : public DiagnosticConsumer {
696public:
697 NullDiagnosticConsumer() { m_log = GetLog(LLDBLog::Expressions); }
698
699 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
700 const clang::Diagnostic &info) override {
701 if (m_log) {
702 llvm::SmallVector<char, 32> diag_str(10);
703 info.FormatDiagnostic(diag_str);
704 diag_str.push_back('\0');
705 LLDB_LOGF(m_log, "Compiler diagnostic: %s\n", diag_str.data());
706 }
707 }
708
709 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
710 return new NullDiagnosticConsumer();
711 }
712
713private:
715};
716
718 assert(!m_ast_up);
719 m_ast_owned = true;
720
721 m_language_options_up = std::make_unique<LangOptions>();
722 ParseLangArgs(*m_language_options_up, clang::Language::ObjCXX,
724
726 std::make_unique<IdentifierTable>(*m_language_options_up, nullptr);
727 m_builtins_up = std::make_unique<Builtin::Context>();
728
729 m_selector_table_up = std::make_unique<SelectorTable>();
730
731 clang::FileSystemOptions file_system_options;
732 m_file_manager_up = std::make_unique<clang::FileManager>(
733 file_system_options, FileSystem::Instance().GetVirtualFileSystem());
734
735 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs());
737 std::make_unique<DiagnosticsEngine>(diag_id_sp, new DiagnosticOptions());
738
739 m_source_manager_up = std::make_unique<clang::SourceManager>(
741 m_ast_up = std::make_unique<ASTContext>(
743 *m_selector_table_up, *m_builtins_up, TU_Complete);
744
745 m_diagnostic_consumer_up = std::make_unique<NullDiagnosticConsumer>();
746 m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
747
748 // This can be NULL if we don't know anything about the architecture or if
749 // the target for an architecture isn't enabled in the llvm/clang that we
750 // built
751 TargetInfo *target_info = getTargetInfo();
752 if (target_info)
753 m_ast_up->InitBuiltinTypes(*target_info);
754
755 GetASTMap().Insert(m_ast_up.get(), this);
756
757 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
759 SetExternalSource(ast_source_up);
760}
761
763 TypeSystemClang *clang_ast = GetASTMap().Lookup(ast);
764 return clang_ast;
765}
766
767clang::MangleContext *TypeSystemClang::getMangleContext() {
768 if (m_mangle_ctx_up == nullptr)
769 m_mangle_ctx_up.reset(getASTContext().createMangleContext());
770 return m_mangle_ctx_up.get();
771}
772
773std::shared_ptr<clang::TargetOptions> &TypeSystemClang::getTargetOptions() {
774 if (m_target_options_rp == nullptr && !m_target_triple.empty()) {
775 m_target_options_rp = std::make_shared<clang::TargetOptions>();
776 if (m_target_options_rp != nullptr)
778 }
779 return m_target_options_rp;
780}
781
783 // target_triple should be something like "x86_64-apple-macosx"
784 if (m_target_info_up == nullptr && !m_target_triple.empty())
785 m_target_info_up.reset(TargetInfo::CreateTargetInfo(
786 getASTContext().getDiagnostics(), getTargetOptions()));
787 return m_target_info_up.get();
788}
789
790#pragma mark Basic Types
791
792static inline bool QualTypeMatchesBitSize(const uint64_t bit_size,
793 ASTContext &ast, QualType qual_type) {
794 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
795 return qual_type_bit_size == bit_size;
796}
797
800 size_t bit_size) {
801 ASTContext &ast = getASTContext();
802 switch (encoding) {
803 case eEncodingInvalid:
804 if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
805 return GetType(ast.VoidPtrTy);
806 break;
807
808 case eEncodingUint:
809 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
810 return GetType(ast.UnsignedCharTy);
811 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
812 return GetType(ast.UnsignedShortTy);
813 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
814 return GetType(ast.UnsignedIntTy);
815 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
816 return GetType(ast.UnsignedLongTy);
817 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
818 return GetType(ast.UnsignedLongLongTy);
819 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
820 return GetType(ast.UnsignedInt128Ty);
821 break;
822
823 case eEncodingSint:
824 if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
825 return GetType(ast.SignedCharTy);
826 if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
827 return GetType(ast.ShortTy);
828 if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
829 return GetType(ast.IntTy);
830 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
831 return GetType(ast.LongTy);
832 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
833 return GetType(ast.LongLongTy);
834 if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
835 return GetType(ast.Int128Ty);
836 break;
837
838 case eEncodingIEEE754:
839 if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
840 return GetType(ast.FloatTy);
841 if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
842 return GetType(ast.DoubleTy);
843 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
844 return GetType(ast.LongDoubleTy);
845 if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
846 return GetType(ast.HalfTy);
847 break;
848
849 case eEncodingVector:
850 // Sanity check that bit_size is a multiple of 8's.
851 if (bit_size && !(bit_size & 0x7u))
852 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
853 break;
854 }
855
856 return CompilerType();
857}
858
861 if (name) {
862 typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
863 static TypeNameToBasicTypeMap g_type_map;
864 static llvm::once_flag g_once_flag;
865 llvm::call_once(g_once_flag, []() {
866 // "void"
867 g_type_map.Append(ConstString("void"), eBasicTypeVoid);
868
869 // "char"
870 g_type_map.Append(ConstString("char"), eBasicTypeChar);
871 g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar);
872 g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar);
873 g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar);
874 g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar);
875 g_type_map.Append(ConstString("unsigned wchar_t"),
877 // "short"
878 g_type_map.Append(ConstString("short"), eBasicTypeShort);
879 g_type_map.Append(ConstString("short int"), eBasicTypeShort);
880 g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort);
881 g_type_map.Append(ConstString("unsigned short int"),
883
884 // "int"
885 g_type_map.Append(ConstString("int"), eBasicTypeInt);
886 g_type_map.Append(ConstString("signed int"), eBasicTypeInt);
887 g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt);
888 g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt);
889
890 // "long"
891 g_type_map.Append(ConstString("long"), eBasicTypeLong);
892 g_type_map.Append(ConstString("long int"), eBasicTypeLong);
893 g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong);
894 g_type_map.Append(ConstString("unsigned long int"),
896
897 // "long long"
898 g_type_map.Append(ConstString("long long"), eBasicTypeLongLong);
899 g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong);
900 g_type_map.Append(ConstString("unsigned long long"),
902 g_type_map.Append(ConstString("unsigned long long int"),
904
905 // "int128"
906 g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128);
907 g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128);
908
909 // Miscellaneous
910 g_type_map.Append(ConstString("bool"), eBasicTypeBool);
911 g_type_map.Append(ConstString("float"), eBasicTypeFloat);
912 g_type_map.Append(ConstString("double"), eBasicTypeDouble);
913 g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble);
914 g_type_map.Append(ConstString("id"), eBasicTypeObjCID);
915 g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel);
916 g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr);
917 g_type_map.Sort();
918 });
919
920 return g_type_map.Find(name, eBasicTypeInvalid);
921 }
922 return eBasicTypeInvalid;
923}
924
926 if (m_pointer_byte_size == 0)
927 if (auto size = GetBasicType(lldb::eBasicTypeVoid)
929 .GetByteSize(nullptr))
930 m_pointer_byte_size = *size;
931 return m_pointer_byte_size;
932}
933
935 clang::ASTContext &ast = getASTContext();
936
938 GetOpaqueCompilerType(&ast, basic_type);
939
940 if (clang_type)
941 return CompilerType(weak_from_this(), clang_type);
942 return CompilerType();
943}
944
946 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
947 ASTContext &ast = getASTContext();
948
949 switch (dw_ate) {
950 default:
951 break;
952
953 case DW_ATE_address:
954 if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
955 return GetType(ast.VoidPtrTy);
956 break;
957
958 case DW_ATE_boolean:
959 if (QualTypeMatchesBitSize(bit_size, ast, ast.BoolTy))
960 return GetType(ast.BoolTy);
961 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
962 return GetType(ast.UnsignedCharTy);
963 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
964 return GetType(ast.UnsignedShortTy);
965 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
966 return GetType(ast.UnsignedIntTy);
967 break;
968
969 case DW_ATE_lo_user:
970 // This has been seen to mean DW_AT_complex_integer
971 if (type_name.contains("complex")) {
972 CompilerType complex_int_clang_type =
973 GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
974 bit_size / 2);
975 return GetType(
976 ast.getComplexType(ClangUtil::GetQualType(complex_int_clang_type)));
977 }
978 break;
979
980 case DW_ATE_complex_float: {
981 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
982 if (QualTypeMatchesBitSize(bit_size, ast, FloatComplexTy))
983 return GetType(FloatComplexTy);
984
985 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
986 if (QualTypeMatchesBitSize(bit_size, ast, DoubleComplexTy))
987 return GetType(DoubleComplexTy);
988
989 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
990 if (QualTypeMatchesBitSize(bit_size, ast, LongDoubleComplexTy))
991 return GetType(LongDoubleComplexTy);
992
993 CompilerType complex_float_clang_type =
994 GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
995 bit_size / 2);
996 return GetType(
997 ast.getComplexType(ClangUtil::GetQualType(complex_float_clang_type)));
998 }
999
1000 case DW_ATE_float:
1001 if (type_name == "float" &&
1002 QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
1003 return GetType(ast.FloatTy);
1004 if (type_name == "double" &&
1005 QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
1006 return GetType(ast.DoubleTy);
1007 if (type_name == "long double" &&
1008 QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
1009 return GetType(ast.LongDoubleTy);
1010 // Fall back to not requiring a name match
1011 if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
1012 return GetType(ast.FloatTy);
1013 if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
1014 return GetType(ast.DoubleTy);
1015 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
1016 return GetType(ast.LongDoubleTy);
1017 if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
1018 return GetType(ast.HalfTy);
1019 break;
1020
1021 case DW_ATE_signed:
1022 if (!type_name.empty()) {
1023 if (type_name == "wchar_t" &&
1024 QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy) &&
1025 (getTargetInfo() &&
1026 TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
1027 return GetType(ast.WCharTy);
1028 if (type_name == "void" &&
1029 QualTypeMatchesBitSize(bit_size, ast, ast.VoidTy))
1030 return GetType(ast.VoidTy);
1031 if (type_name.contains("long long") &&
1032 QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
1033 return GetType(ast.LongLongTy);
1034 if (type_name.contains("long") &&
1035 QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
1036 return GetType(ast.LongTy);
1037 if (type_name.contains("short") &&
1038 QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
1039 return GetType(ast.ShortTy);
1040 if (type_name.contains("char")) {
1041 if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1042 return GetType(ast.CharTy);
1043 if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
1044 return GetType(ast.SignedCharTy);
1045 }
1046 if (type_name.contains("int")) {
1047 if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
1048 return GetType(ast.IntTy);
1049 if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
1050 return GetType(ast.Int128Ty);
1051 }
1052 }
1053 // We weren't able to match up a type name, just search by size
1054 if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1055 return GetType(ast.CharTy);
1056 if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
1057 return GetType(ast.ShortTy);
1058 if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
1059 return GetType(ast.IntTy);
1060 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
1061 return GetType(ast.LongTy);
1062 if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
1063 return GetType(ast.LongLongTy);
1064 if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
1065 return GetType(ast.Int128Ty);
1066 break;
1067
1068 case DW_ATE_signed_char:
1069 if (type_name == "char") {
1070 if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1071 return GetType(ast.CharTy);
1072 }
1073 if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
1074 return GetType(ast.SignedCharTy);
1075 break;
1076
1077 case DW_ATE_unsigned:
1078 if (!type_name.empty()) {
1079 if (type_name == "wchar_t") {
1080 if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) {
1081 if (!(getTargetInfo() &&
1082 TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
1083 return GetType(ast.WCharTy);
1084 }
1085 }
1086 if (type_name.contains("long long")) {
1087 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
1088 return GetType(ast.UnsignedLongLongTy);
1089 } else if (type_name.contains("long")) {
1090 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
1091 return GetType(ast.UnsignedLongTy);
1092 } else if (type_name.contains("short")) {
1093 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1094 return GetType(ast.UnsignedShortTy);
1095 } else if (type_name.contains("char")) {
1096 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1097 return GetType(ast.UnsignedCharTy);
1098 } else if (type_name.contains("int")) {
1099 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
1100 return GetType(ast.UnsignedIntTy);
1101 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
1102 return GetType(ast.UnsignedInt128Ty);
1103 }
1104 }
1105 // We weren't able to match up a type name, just search by size
1106 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1107 return GetType(ast.UnsignedCharTy);
1108 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1109 return GetType(ast.UnsignedShortTy);
1110 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
1111 return GetType(ast.UnsignedIntTy);
1112 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
1113 return GetType(ast.UnsignedLongTy);
1114 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
1115 return GetType(ast.UnsignedLongLongTy);
1116 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
1117 return GetType(ast.UnsignedInt128Ty);
1118 break;
1119
1120 case DW_ATE_unsigned_char:
1121 if (type_name == "char") {
1122 if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
1123 return GetType(ast.CharTy);
1124 }
1125 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
1126 return GetType(ast.UnsignedCharTy);
1127 if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
1128 return GetType(ast.UnsignedShortTy);
1129 break;
1130
1131 case DW_ATE_imaginary_float:
1132 break;
1133
1134 case DW_ATE_UTF:
1135 switch (bit_size) {
1136 case 8:
1137 return GetType(ast.Char8Ty);
1138 case 16:
1139 return GetType(ast.Char16Ty);
1140 case 32:
1141 return GetType(ast.Char32Ty);
1142 default:
1143 if (!type_name.empty()) {
1144 if (type_name == "char16_t")
1145 return GetType(ast.Char16Ty);
1146 if (type_name == "char32_t")
1147 return GetType(ast.Char32Ty);
1148 if (type_name == "char8_t")
1149 return GetType(ast.Char8Ty);
1150 }
1151 }
1152 break;
1153 }
1154
1155 Log *log = GetLog(LLDBLog::Types);
1156 LLDB_LOG(log,
1157 "error: need to add support for DW_TAG_base_type '{0}' "
1158 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1159 type_name, dw_ate, bit_size);
1160 return CompilerType();
1161}
1162
1164 ASTContext &ast = getASTContext();
1165 QualType char_type(ast.CharTy);
1166
1167 if (is_const)
1168 char_type.addConst();
1169
1170 return GetType(ast.getPointerType(char_type));
1171}
1172
1174 bool ignore_qualifiers) {
1175 auto ast = type1.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1176 if (!ast || type1.GetTypeSystem() != type2.GetTypeSystem())
1177 return false;
1178
1179 if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType())
1180 return true;
1181
1182 QualType type1_qual = ClangUtil::GetQualType(type1);
1183 QualType type2_qual = ClangUtil::GetQualType(type2);
1184
1185 if (ignore_qualifiers) {
1186 type1_qual = type1_qual.getUnqualifiedType();
1187 type2_qual = type2_qual.getUnqualifiedType();
1188 }
1189
1190 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1191}
1192
1194 if (!opaque_decl)
1195 return CompilerType();
1196
1197 clang::Decl *decl = static_cast<clang::Decl *>(opaque_decl);
1198 if (auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1199 return GetTypeForDecl(named_decl);
1200 return CompilerType();
1201}
1202
1204 // Check that the DeclContext actually belongs to this ASTContext.
1205 assert(&ctx->getParentASTContext() == &getASTContext());
1206 return CompilerDeclContext(this, ctx);
1207}
1208
1210 if (clang::ObjCInterfaceDecl *interface_decl =
1211 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1212 return GetTypeForDecl(interface_decl);
1213 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1214 return GetTypeForDecl(tag_decl);
1215 return CompilerType();
1216}
1217
1219 return GetType(getASTContext().getTagDeclType(decl));
1220}
1221
1222CompilerType TypeSystemClang::GetTypeForDecl(ObjCInterfaceDecl *decl) {
1223 return GetType(getASTContext().getObjCInterfaceType(decl));
1224}
1225
1226#pragma mark Structure, Unions, Classes
1227
1229 OptionalClangModuleID owning_module) {
1230 if (!decl || !owning_module.HasValue())
1231 return;
1232
1233 decl->setFromASTFile();
1234 decl->setOwningModuleID(owning_module.GetValue());
1235 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1236}
1237
1240 OptionalClangModuleID parent,
1241 bool is_framework, bool is_explicit) {
1242 // Get the external AST source which holds the modules.
1243 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1244 getASTContext().getExternalSource());
1245 assert(ast_source && "external ast source was lost");
1246 if (!ast_source)
1247 return {};
1248
1249 // Lazily initialize the module map.
1250 if (!m_header_search_up) {
1251 auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1252 m_header_search_up = std::make_unique<clang::HeaderSearch>(
1255 m_module_map_up = std::make_unique<clang::ModuleMap>(
1258 }
1259
1260 // Get or create the module context.
1261 bool created;
1262 clang::Module *module;
1263 auto parent_desc = ast_source->getSourceDescriptor(parent.GetValue());
1264 std::tie(module, created) = m_module_map_up->findOrCreateModule(
1265 name, parent_desc ? parent_desc->getModuleOrNull() : nullptr,
1266 is_framework, is_explicit);
1267 if (!created)
1268 return ast_source->GetIDForModule(module);
1269
1270 return ast_source->RegisterModule(module);
1271}
1272
1274 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1275 AccessType access_type, llvm::StringRef name, int kind,
1276 LanguageType language, ClangASTMetadata *metadata, bool exports_symbols) {
1277 ASTContext &ast = getASTContext();
1278
1279 if (decl_ctx == nullptr)
1280 decl_ctx = ast.getTranslationUnitDecl();
1281
1282 if (language == eLanguageTypeObjC ||
1283 language == eLanguageTypeObjC_plus_plus) {
1284 bool isForwardDecl = true;
1285 bool isInternal = false;
1286 return CreateObjCClass(name, decl_ctx, owning_module, isForwardDecl,
1287 isInternal, metadata);
1288 }
1289
1290 // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and
1291 // we will need to update this code. I was told to currently always use the
1292 // CXXRecordDecl class since we often don't know from debug information if
1293 // something is struct or a class, so we default to always use the more
1294 // complete definition just in case.
1295
1296 bool has_name = !name.empty();
1297 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1298 decl->setTagKind(static_cast<TagDecl::TagKind>(kind));
1299 decl->setDeclContext(decl_ctx);
1300 if (has_name)
1301 decl->setDeclName(&ast.Idents.get(name));
1302 SetOwningModule(decl, owning_module);
1303
1304 if (!has_name) {
1305 // In C++ a lambda is also represented as an unnamed class. This is
1306 // different from an *anonymous class* that the user wrote:
1307 //
1308 // struct A {
1309 // // anonymous class (GNU/MSVC extension)
1310 // struct {
1311 // int x;
1312 // };
1313 // // unnamed class within a class
1314 // struct {
1315 // int y;
1316 // } B;
1317 // };
1318 //
1319 // void f() {
1320 // // unammed class outside of a class
1321 // struct {
1322 // int z;
1323 // } C;
1324 // }
1325 //
1326 // Anonymous classes is a GNU/MSVC extension that clang supports. It
1327 // requires the anonymous class be embedded within a class. So the new
1328 // heuristic verifies this condition.
1329 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1330 decl->setAnonymousStructOrUnion(true);
1331 }
1332
1333 if (metadata)
1334 SetMetadata(decl, *metadata);
1335
1336 if (access_type != eAccessNone)
1337 decl->setAccess(ConvertAccessTypeToAccessSpecifier(access_type));
1338
1339 if (decl_ctx)
1340 decl_ctx->addDecl(decl);
1341
1342 return GetType(ast.getTagDeclType(decl));
1343}
1344
1345namespace {
1346/// Returns true iff the given TemplateArgument should be represented as an
1347/// NonTypeTemplateParmDecl in the AST.
1348bool IsValueParam(const clang::TemplateArgument &argument) {
1349 return argument.getKind() == TemplateArgument::Integral;
1350}
1351
1352void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1353 ASTContext &ct,
1354 clang::AccessSpecifier previous_access,
1355 clang::AccessSpecifier access_specifier) {
1356 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1357 return;
1358 if (previous_access != access_specifier) {
1359 // For struct, don't add AS_public if it's the first AccessSpecDecl.
1360 // For class, don't add AS_private if it's the first AccessSpecDecl.
1361 if ((cxx_record_decl->isStruct() &&
1362 previous_access == clang::AccessSpecifier::AS_none &&
1363 access_specifier == clang::AccessSpecifier::AS_public) ||
1364 (cxx_record_decl->isClass() &&
1365 previous_access == clang::AccessSpecifier::AS_none &&
1366 access_specifier == clang::AccessSpecifier::AS_private)) {
1367 return;
1368 }
1369 cxx_record_decl->addDecl(
1370 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1371 SourceLocation(), SourceLocation()));
1372 }
1373}
1374} // namespace
1375
1376static TemplateParameterList *CreateTemplateParameterList(
1377 ASTContext &ast,
1378 const TypeSystemClang::TemplateParameterInfos &template_param_infos,
1379 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1380 const bool parameter_pack = false;
1381 const bool is_typename = false;
1382 const unsigned depth = 0;
1383 const size_t num_template_params = template_param_infos.Size();
1384 DeclContext *const decl_context =
1385 ast.getTranslationUnitDecl(); // Is this the right decl context?,
1386
1387 auto const &args = template_param_infos.GetArgs();
1388 auto const &names = template_param_infos.GetNames();
1389 for (size_t i = 0; i < num_template_params; ++i) {
1390 const char *name = names[i];
1391
1392 IdentifierInfo *identifier_info = nullptr;
1393 if (name && name[0])
1394 identifier_info = &ast.Idents.get(name);
1395 TemplateArgument const &targ = args[i];
1396 if (IsValueParam(targ)) {
1397 QualType template_param_type = targ.getIntegralType();
1398 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1399 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1400 identifier_info, template_param_type, parameter_pack,
1401 ast.getTrivialTypeSourceInfo(template_param_type)));
1402 } else {
1403 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1404 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1405 identifier_info, is_typename, parameter_pack));
1406 }
1407 }
1408
1409 if (template_param_infos.hasParameterPack()) {
1410 IdentifierInfo *identifier_info = nullptr;
1411 if (template_param_infos.HasPackName())
1412 identifier_info = &ast.Idents.get(template_param_infos.GetPackName());
1413 const bool parameter_pack_true = true;
1414
1415 if (!template_param_infos.GetParameterPack().IsEmpty() &&
1416 IsValueParam(template_param_infos.GetParameterPack().Front())) {
1417 QualType template_param_type =
1418 template_param_infos.GetParameterPack().Front().getIntegralType();
1419 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1420 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1421 num_template_params, identifier_info, template_param_type,
1422 parameter_pack_true,
1423 ast.getTrivialTypeSourceInfo(template_param_type)));
1424 } else {
1425 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1426 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1427 num_template_params, identifier_info, is_typename,
1428 parameter_pack_true));
1429 }
1430 }
1431 clang::Expr *const requires_clause = nullptr; // TODO: Concepts
1432 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1433 ast, SourceLocation(), SourceLocation(), template_param_decls,
1434 SourceLocation(), requires_clause);
1435 return template_param_list;
1436}
1437
1439 const TemplateParameterInfos &template_param_infos) {
1440 llvm::SmallVector<NamedDecl *, 8> ignore;
1441 clang::TemplateParameterList *template_param_list =
1442 CreateTemplateParameterList(getASTContext(), template_param_infos,
1443 ignore);
1444 llvm::SmallVector<clang::TemplateArgument, 2> args(
1445 template_param_infos.GetArgs());
1446 if (template_param_infos.hasParameterPack()) {
1447 llvm::ArrayRef<TemplateArgument> pack_args =
1448 template_param_infos.GetParameterPackArgs();
1449 args.append(pack_args.begin(), pack_args.end());
1450 }
1451 std::string str;
1452 llvm::raw_string_ostream os(str);
1453 clang::printTemplateArgumentList(os, args, GetTypePrintingPolicy(),
1454 template_param_list);
1455 return str;
1456}
1457
1459 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1460 clang::FunctionDecl *func_decl,
1461 const TemplateParameterInfos &template_param_infos) {
1462 // /// Create a function template node.
1463 ASTContext &ast = getASTContext();
1464
1465 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1466 TemplateParameterList *template_param_list = CreateTemplateParameterList(
1467 ast, template_param_infos, template_param_decls);
1468 FunctionTemplateDecl *func_tmpl_decl =
1469 FunctionTemplateDecl::CreateDeserialized(ast, 0);
1470 func_tmpl_decl->setDeclContext(decl_ctx);
1471 func_tmpl_decl->setLocation(func_decl->getLocation());
1472 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1473 func_tmpl_decl->setTemplateParameters(template_param_list);
1474 func_tmpl_decl->init(func_decl);
1475 SetOwningModule(func_tmpl_decl, owning_module);
1476
1477 for (size_t i = 0, template_param_decl_count = template_param_decls.size();
1478 i < template_param_decl_count; ++i) {
1479 // TODO: verify which decl context we should put template_param_decls into..
1480 template_param_decls[i]->setDeclContext(func_decl);
1481 }
1482 // Function templates inside a record need to have an access specifier.
1483 // It doesn't matter what access specifier we give the template as LLDB
1484 // anyway allows accessing everything inside a record.
1485 if (decl_ctx->isRecord())
1486 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1487
1488 return func_tmpl_decl;
1489}
1490
1492 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1493 const TemplateParameterInfos &infos) {
1494 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1495 func_decl->getASTContext(), infos.GetArgs());
1496
1497 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1498 template_args_ptr, nullptr);
1499}
1500
1501/// Returns true if the given template parameter can represent the given value.
1502/// For example, `typename T` can represent `int` but not integral values such
1503/// as `int I = 3`.
1504static bool TemplateParameterAllowsValue(NamedDecl *param,
1505 const TemplateArgument &value) {
1506 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1507 // Compare the argument kind, i.e. ensure that <typename> != <int>.
1508 if (value.getKind() != TemplateArgument::Type)
1509 return false;
1510 } else if (auto *type_param =
1511 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1512 // Compare the argument kind, i.e. ensure that <typename> != <int>.
1513 if (!IsValueParam(value))
1514 return false;
1515 // Compare the integral type, i.e. ensure that <int> != <char>.
1516 if (type_param->getType() != value.getIntegralType())
1517 return false;
1518 } else {
1519 // There is no way to create other parameter decls at the moment, so we
1520 // can't reach this case during normal LLDB usage. Log that this happened
1521 // and assert.
1523 LLDB_LOG(log,
1524 "Don't know how to compare template parameter to passed"
1525 " value. Decl kind of parameter is: {0}",
1526 param->getDeclKindName());
1527 lldbassert(false && "Can't compare this TemplateParmDecl subclass");
1528 // In release builds just fall back to marking the parameter as not
1529 // accepting the value so that we don't try to fit an instantiation to a
1530 // template that doesn't fit. E.g., avoid that `S<1>` is being connected to
1531 // `template<typename T> struct S;`.
1532 return false;
1533 }
1534 return true;
1535}
1536
1537/// Returns true if the given class template declaration could produce an
1538/// instantiation with the specified values.
1539/// For example, `<typename T>` allows the arguments `float`, but not for
1540/// example `bool, float` or `3` (as an integer parameter value).
1542 ClassTemplateDecl *class_template_decl,
1543 const TypeSystemClang::TemplateParameterInfos &instantiation_values) {
1544
1545 TemplateParameterList &params = *class_template_decl->getTemplateParameters();
1546
1547 // Save some work by iterating only once over the found parameters and
1548 // calculate the information related to parameter packs.
1549
1550 // Contains the first pack parameter (or non if there are none).
1551 std::optional<NamedDecl *> pack_parameter;
1552 // Contains the number of non-pack parameters.
1553 size_t non_pack_params = params.size();
1554 for (size_t i = 0; i < params.size(); ++i) {
1555 NamedDecl *param = params.getParam(i);
1556 if (param->isParameterPack()) {
1557 pack_parameter = param;
1558 non_pack_params = i;
1559 break;
1560 }
1561 }
1562
1563 // The found template needs to have compatible non-pack template arguments.
1564 // E.g., ensure that <typename, typename> != <typename>.
1565 // The pack parameters are compared later.
1566 if (non_pack_params != instantiation_values.Size())
1567 return false;
1568
1569 // Ensure that <typename...> != <typename>.
1570 if (pack_parameter.has_value() != instantiation_values.hasParameterPack())
1571 return false;
1572
1573 // Compare the first pack parameter that was found with the first pack
1574 // parameter value. The special case of having an empty parameter pack value
1575 // always fits to a pack parameter.
1576 // E.g., ensure that <int...> != <typename...>.
1577 if (pack_parameter && !instantiation_values.GetParameterPack().IsEmpty() &&
1579 *pack_parameter, instantiation_values.GetParameterPack().Front()))
1580 return false;
1581
1582 // Compare all the non-pack parameters now.
1583 // E.g., ensure that <int> != <long>.
1584 for (const auto pair :
1585 llvm::zip_first(instantiation_values.GetArgs(), params)) {
1586 const TemplateArgument &passed_arg = std::get<0>(pair);
1587 NamedDecl *found_param = std::get<1>(pair);
1588 if (!TemplateParameterAllowsValue(found_param, passed_arg))
1589 return false;
1590 }
1591
1592 return class_template_decl;
1593}
1594
1596 DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1597 lldb::AccessType access_type, llvm::StringRef class_name, int kind,
1598 const TemplateParameterInfos &template_param_infos) {
1599 ASTContext &ast = getASTContext();
1600
1601 ClassTemplateDecl *class_template_decl = nullptr;
1602 if (decl_ctx == nullptr)
1603 decl_ctx = ast.getTranslationUnitDecl();
1604
1605 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1606 DeclarationName decl_name(&identifier_info);
1607
1608 // Search the AST for an existing ClassTemplateDecl that could be reused.
1609 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1610 for (NamedDecl *decl : result) {
1611 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1612 if (!class_template_decl)
1613 continue;
1614 // The class template has to be able to represents the instantiation
1615 // values we received. Without this we might end up putting an instantiation
1616 // with arguments such as <int, int> to a template such as:
1617 // template<typename T> struct S;
1618 // Connecting the instantiation to an incompatible template could cause
1619 // problems later on.
1620 if (!ClassTemplateAllowsToInstantiationArgs(class_template_decl,
1621 template_param_infos))
1622 continue;
1623 return class_template_decl;
1624 }
1625
1626 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1627
1628 TemplateParameterList *template_param_list = CreateTemplateParameterList(
1629 ast, template_param_infos, template_param_decls);
1630
1631 CXXRecordDecl *template_cxx_decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1632 template_cxx_decl->setTagKind(static_cast<TagDecl::TagKind>(kind));
1633 // What decl context do we use here? TU? The actual decl context?
1634 template_cxx_decl->setDeclContext(decl_ctx);
1635 template_cxx_decl->setDeclName(decl_name);
1636 SetOwningModule(template_cxx_decl, owning_module);
1637
1638 for (size_t i = 0, template_param_decl_count = template_param_decls.size();
1639 i < template_param_decl_count; ++i) {
1640 template_param_decls[i]->setDeclContext(template_cxx_decl);
1641 }
1642
1643 // With templated classes, we say that a class is templated with
1644 // specializations, but that the bare class has no functions.
1645 // template_cxx_decl->startDefinition();
1646 // template_cxx_decl->completeDefinition();
1647
1648 class_template_decl = ClassTemplateDecl::CreateDeserialized(ast, 0);
1649 // What decl context do we use here? TU? The actual decl context?
1650 class_template_decl->setDeclContext(decl_ctx);
1651 class_template_decl->setDeclName(decl_name);
1652 class_template_decl->setTemplateParameters(template_param_list);
1653 class_template_decl->init(template_cxx_decl);
1654 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1655 SetOwningModule(class_template_decl, owning_module);
1656
1657 if (access_type != eAccessNone)
1658 class_template_decl->setAccess(
1660
1661 decl_ctx->addDecl(class_template_decl);
1662
1663 VerifyDecl(class_template_decl);
1664
1665 return class_template_decl;
1666}
1667
1668TemplateTemplateParmDecl *
1670 ASTContext &ast = getASTContext();
1671
1672 auto *decl_ctx = ast.getTranslationUnitDecl();
1673
1674 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1675 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1676
1677 TypeSystemClang::TemplateParameterInfos template_param_infos;
1678 TemplateParameterList *template_param_list = CreateTemplateParameterList(
1679 ast, template_param_infos, template_param_decls);
1680
1681 // LLDB needs to create those decls only to be able to display a
1682 // type that includes a template template argument. Only the name matters for
1683 // this purpose, so we use dummy values for the other characteristics of the
1684 // type.
1685 return TemplateTemplateParmDecl::Create(
1686 ast, decl_ctx, SourceLocation(),
1687 /*Depth*/ 0, /*Position*/ 0,
1688 /*IsParameterPack*/ false, &identifier_info, template_param_list);
1689}
1690
1691ClassTemplateSpecializationDecl *
1693 DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1694 ClassTemplateDecl *class_template_decl, int kind,
1695 const TemplateParameterInfos &template_param_infos) {
1696 ASTContext &ast = getASTContext();
1697 llvm::SmallVector<clang::TemplateArgument, 2> args(
1698 template_param_infos.Size() +
1699 (template_param_infos.hasParameterPack() ? 1 : 0));
1700
1701 auto const &orig_args = template_param_infos.GetArgs();
1702 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1703 if (template_param_infos.hasParameterPack()) {
1704 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1705 ast, template_param_infos.GetParameterPackArgs());
1706 }
1707 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1708 ClassTemplateSpecializationDecl::CreateDeserialized(ast, 0);
1709 class_template_specialization_decl->setTagKind(
1710 static_cast<TagDecl::TagKind>(kind));
1711 class_template_specialization_decl->setDeclContext(decl_ctx);
1712 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1713 class_template_specialization_decl->setTemplateArgs(
1714 TemplateArgumentList::CreateCopy(ast, args));
1715 ast.getTypeDeclType(class_template_specialization_decl, nullptr);
1716 class_template_specialization_decl->setDeclName(
1717 class_template_decl->getDeclName());
1718 SetOwningModule(class_template_specialization_decl, owning_module);
1719 decl_ctx->addDecl(class_template_specialization_decl);
1720
1721 class_template_specialization_decl->setSpecializationKind(
1722 TSK_ExplicitSpecialization);
1723
1724 return class_template_specialization_decl;
1725}
1726
1728 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1729 if (class_template_specialization_decl) {
1730 ASTContext &ast = getASTContext();
1731 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1732 }
1733 return CompilerType();
1734}
1735
1736static inline bool check_op_param(bool is_method,
1737 clang::OverloadedOperatorKind op_kind,
1738 bool unary, bool binary,
1739 uint32_t num_params) {
1740 // Special-case call since it can take any number of operands
1741 if (op_kind == OO_Call)
1742 return true;
1743
1744 // The parameter count doesn't include "this"
1745 if (is_method)
1746 ++num_params;
1747 if (num_params == 1)
1748 return unary;
1749 if (num_params == 2)
1750 return binary;
1751 else
1752 return false;
1753}
1754
1756 bool is_method, clang::OverloadedOperatorKind op_kind,
1757 uint32_t num_params) {
1758 switch (op_kind) {
1759 default:
1760 break;
1761 // C++ standard allows any number of arguments to new/delete
1762 case OO_New:
1763 case OO_Array_New:
1764 case OO_Delete:
1765 case OO_Array_Delete:
1766 return true;
1767 }
1768
1769#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1770 case OO_##Name: \
1771 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1772 switch (op_kind) {
1773#include "clang/Basic/OperatorKinds.def"
1774 default:
1775 break;
1776 }
1777 return false;
1778}
1779
1780clang::AccessSpecifier
1782 clang::AccessSpecifier rhs) {
1783 // Make the access equal to the stricter of the field and the nested field's
1784 // access
1785 if (lhs == AS_none || rhs == AS_none)
1786 return AS_none;
1787 if (lhs == AS_private || rhs == AS_private)
1788 return AS_private;
1789 if (lhs == AS_protected || rhs == AS_protected)
1790 return AS_protected;
1791 return AS_public;
1792}
1793
1795 uint32_t &bitfield_bit_size) {
1796 ASTContext &ast = getASTContext();
1797 if (field == nullptr)
1798 return false;
1799
1800 if (field->isBitField()) {
1801 Expr *bit_width_expr = field->getBitWidth();
1802 if (bit_width_expr) {
1803 if (std::optional<llvm::APSInt> bit_width_apsint =
1804 bit_width_expr->getIntegerConstantExpr(ast)) {
1805 bitfield_bit_size = bit_width_apsint->getLimitedValue(UINT32_MAX);
1806 return true;
1807 }
1808 }
1809 }
1810 return false;
1811}
1812
1813bool TypeSystemClang::RecordHasFields(const RecordDecl *record_decl) {
1814 if (record_decl == nullptr)
1815 return false;
1816
1817 if (!record_decl->field_empty())
1818 return true;
1819
1820 // No fields, lets check this is a CXX record and check the base classes
1821 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1822 if (cxx_record_decl) {
1823 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1824 for (base_class = cxx_record_decl->bases_begin(),
1825 base_class_end = cxx_record_decl->bases_end();
1826 base_class != base_class_end; ++base_class) {
1827 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1828 base_class->getType()->getAs<RecordType>()->getDecl());
1829 if (RecordHasFields(base_class_decl))
1830 return true;
1831 }
1832 }
1833
1834 // We always want forcefully completed types to show up so we can print a
1835 // message in the summary that indicates that the type is incomplete.
1836 // This will help users know when they are running into issues with
1837 // -flimit-debug-info instead of just seeing nothing if this is a base class
1838 // (since we were hiding empty base classes), or nothing when you turn open
1839 // an valiable whose type was incomplete.
1840 ClangASTMetadata *meta_data = GetMetadata(record_decl);
1841 if (meta_data && meta_data->IsForcefullyCompleted())
1842 return true;
1843
1844 return false;
1845}
1846
1847#pragma mark Objective-C Classes
1848
1850 llvm::StringRef name, clang::DeclContext *decl_ctx,
1851 OptionalClangModuleID owning_module, bool isForwardDecl, bool isInternal,
1852 ClangASTMetadata *metadata) {
1853 ASTContext &ast = getASTContext();
1854 assert(!name.empty());
1855 if (!decl_ctx)
1856 decl_ctx = ast.getTranslationUnitDecl();
1857
1858 ObjCInterfaceDecl *decl = ObjCInterfaceDecl::CreateDeserialized(ast, 0);
1859 decl->setDeclContext(decl_ctx);
1860 decl->setDeclName(&ast.Idents.get(name));
1861 /*isForwardDecl,*/
1862 decl->setImplicit(isInternal);
1863 SetOwningModule(decl, owning_module);
1864
1865 if (metadata)
1866 SetMetadata(decl, *metadata);
1867
1868 return GetType(ast.getObjCInterfaceType(decl));
1869}
1870
1871bool TypeSystemClang::BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) {
1872 return !TypeSystemClang::RecordHasFields(b->getType()->getAsCXXRecordDecl());
1873}
1874
1876TypeSystemClang::GetNumBaseClasses(const CXXRecordDecl *cxx_record_decl,
1877 bool omit_empty_base_classes) {
1878 uint32_t num_bases = 0;
1879 if (cxx_record_decl) {
1880 if (omit_empty_base_classes) {
1881 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1882 for (base_class = cxx_record_decl->bases_begin(),
1883 base_class_end = cxx_record_decl->bases_end();
1884 base_class != base_class_end; ++base_class) {
1885 // Skip empty base classes
1886 if (BaseSpecifierIsEmpty(base_class))
1887 continue;
1888 ++num_bases;
1889 }
1890 } else
1891 num_bases = cxx_record_decl->getNumBases();
1892 }
1893 return num_bases;
1894}
1895
1896#pragma mark Namespace Declarations
1897
1899 const char *name, clang::DeclContext *decl_ctx,
1900 OptionalClangModuleID owning_module, bool is_inline) {
1901 NamespaceDecl *namespace_decl = nullptr;
1902 ASTContext &ast = getASTContext();
1903 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1904 if (!decl_ctx)
1905 decl_ctx = translation_unit_decl;
1906
1907 if (name) {
1908 IdentifierInfo &identifier_info = ast.Idents.get(name);
1909 DeclarationName decl_name(&identifier_info);
1910 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1911 for (NamedDecl *decl : result) {
1912 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1913 if (namespace_decl)
1914 return namespace_decl;
1915 }
1916
1917 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1918 SourceLocation(), SourceLocation(),
1919 &identifier_info, nullptr, false);
1920
1921 decl_ctx->addDecl(namespace_decl);
1922 } else {
1923 if (decl_ctx == translation_unit_decl) {
1924 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1925 if (namespace_decl)
1926 return namespace_decl;
1927
1928 namespace_decl =
1929 NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
1930 SourceLocation(), nullptr, nullptr, false);
1931 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1932 translation_unit_decl->addDecl(namespace_decl);
1933 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1934 } else {
1935 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1936 if (parent_namespace_decl) {
1937 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1938 if (namespace_decl)
1939 return namespace_decl;
1940 namespace_decl =
1941 NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
1942 SourceLocation(), nullptr, nullptr, false);
1943 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1944 parent_namespace_decl->addDecl(namespace_decl);
1945 assert(namespace_decl ==
1946 parent_namespace_decl->getAnonymousNamespace());
1947 } else {
1948 assert(false && "GetUniqueNamespaceDeclaration called with no name and "
1949 "no namespace as decl_ctx");
1950 }
1951 }
1952 }
1953 // Note: namespaces can span multiple modules, so perhaps this isn't a good
1954 // idea.
1955 SetOwningModule(namespace_decl, owning_module);
1956
1957 VerifyDecl(namespace_decl);
1958 return namespace_decl;
1959}
1960
1961clang::BlockDecl *
1963 OptionalClangModuleID owning_module) {
1964 if (ctx) {
1965 clang::BlockDecl *decl =
1966 clang::BlockDecl::CreateDeserialized(getASTContext(), 0);
1967 decl->setDeclContext(ctx);
1968 ctx->addDecl(decl);
1969 SetOwningModule(decl, owning_module);
1970 return decl;
1971 }
1972 return nullptr;
1973}
1974
1975clang::DeclContext *FindLCABetweenDecls(clang::DeclContext *left,
1976 clang::DeclContext *right,
1977 clang::DeclContext *root) {
1978 if (root == nullptr)
1979 return nullptr;
1980
1981 std::set<clang::DeclContext *> path_left;
1982 for (clang::DeclContext *d = left; d != nullptr; d = d->getParent())
1983 path_left.insert(d);
1984
1985 for (clang::DeclContext *d = right; d != nullptr; d = d->getParent())
1986 if (path_left.find(d) != path_left.end())
1987 return d;
1988
1989 return nullptr;
1990}
1991
1993 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
1994 clang::NamespaceDecl *ns_decl) {
1995 if (decl_ctx && ns_decl) {
1996 auto *translation_unit = getASTContext().getTranslationUnitDecl();
1997 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1998 getASTContext(), decl_ctx, clang::SourceLocation(),
1999 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
2000 clang::SourceLocation(), ns_decl,
2001 FindLCABetweenDecls(decl_ctx, ns_decl,
2002 translation_unit));
2003 decl_ctx->addDecl(using_decl);
2004 SetOwningModule(using_decl, owning_module);
2005 return using_decl;
2006 }
2007 return nullptr;
2008}
2009
2010clang::UsingDecl *
2011TypeSystemClang::CreateUsingDeclaration(clang::DeclContext *current_decl_ctx,
2012 OptionalClangModuleID owning_module,
2013 clang::NamedDecl *target) {
2014 if (current_decl_ctx && target) {
2015 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
2016 getASTContext(), current_decl_ctx, clang::SourceLocation(),
2017 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(), false);
2018 SetOwningModule(using_decl, owning_module);
2019 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
2020 getASTContext(), current_decl_ctx, clang::SourceLocation(),
2021 target->getDeclName(), using_decl, target);
2022 SetOwningModule(shadow_decl, owning_module);
2023 using_decl->addShadowDecl(shadow_decl);
2024 current_decl_ctx->addDecl(using_decl);
2025 return using_decl;
2026 }
2027 return nullptr;
2028}
2029
2031 clang::DeclContext *decl_context, OptionalClangModuleID owning_module,
2032 const char *name, clang::QualType type) {
2033 if (decl_context) {
2034 clang::VarDecl *var_decl =
2035 clang::VarDecl::CreateDeserialized(getASTContext(), 0);
2036 var_decl->setDeclContext(decl_context);
2037 if (name && name[0])
2038 var_decl->setDeclName(&getASTContext().Idents.getOwn(name));
2039 var_decl->setType(type);
2040 SetOwningModule(var_decl, owning_module);
2041 var_decl->setAccess(clang::AS_public);
2042 decl_context->addDecl(var_decl);
2043 return var_decl;
2044 }
2045 return nullptr;
2046}
2047
2050 lldb::BasicType basic_type) {
2051 switch (basic_type) {
2052 case eBasicTypeVoid:
2053 return ast->VoidTy.getAsOpaquePtr();
2054 case eBasicTypeChar:
2055 return ast->CharTy.getAsOpaquePtr();
2057 return ast->SignedCharTy.getAsOpaquePtr();
2059 return ast->UnsignedCharTy.getAsOpaquePtr();
2060 case eBasicTypeWChar:
2061 return ast->getWCharType().getAsOpaquePtr();
2063 return ast->getSignedWCharType().getAsOpaquePtr();
2065 return ast->getUnsignedWCharType().getAsOpaquePtr();
2066 case eBasicTypeChar8:
2067 return ast->Char8Ty.getAsOpaquePtr();
2068 case eBasicTypeChar16:
2069 return ast->Char16Ty.getAsOpaquePtr();
2070 case eBasicTypeChar32:
2071 return ast->Char32Ty.getAsOpaquePtr();
2072 case eBasicTypeShort:
2073 return ast->ShortTy.getAsOpaquePtr();
2075 return ast->UnsignedShortTy.getAsOpaquePtr();
2076 case eBasicTypeInt:
2077 return ast->IntTy.getAsOpaquePtr();
2079 return ast->UnsignedIntTy.getAsOpaquePtr();
2080 case eBasicTypeLong:
2081 return ast->LongTy.getAsOpaquePtr();
2083 return ast->UnsignedLongTy.getAsOpaquePtr();
2084 case eBasicTypeLongLong:
2085 return ast->LongLongTy.getAsOpaquePtr();
2087 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2088 case eBasicTypeInt128:
2089 return ast->Int128Ty.getAsOpaquePtr();
2091 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2092 case eBasicTypeBool:
2093 return ast->BoolTy.getAsOpaquePtr();
2094 case eBasicTypeHalf:
2095 return ast->HalfTy.getAsOpaquePtr();
2096 case eBasicTypeFloat:
2097 return ast->FloatTy.getAsOpaquePtr();
2098 case eBasicTypeDouble:
2099 return ast->DoubleTy.getAsOpaquePtr();
2101 return ast->LongDoubleTy.getAsOpaquePtr();
2103 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2105 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2107 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2108 case eBasicTypeObjCID:
2109 return ast->getObjCIdType().getAsOpaquePtr();
2111 return ast->getObjCClassType().getAsOpaquePtr();
2112 case eBasicTypeObjCSel:
2113 return ast->getObjCSelType().getAsOpaquePtr();
2114 case eBasicTypeNullPtr:
2115 return ast->NullPtrTy.getAsOpaquePtr();
2116 default:
2117 return nullptr;
2118 }
2119}
2120
2121#pragma mark Function Types
2122
2123clang::DeclarationName
2125 const CompilerType &function_clang_type) {
2126 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2127 if (!IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2128 return DeclarationName(&getASTContext().Idents.get(
2129 name)); // Not operator, but a regular function.
2130
2131 // Check the number of operator parameters. Sometimes we have seen bad DWARF
2132 // that doesn't correctly describe operators and if we try to create a method
2133 // and add it to the class, clang will assert and crash, so we need to make
2134 // sure things are acceptable.
2135 clang::QualType method_qual_type(ClangUtil::GetQualType(function_clang_type));
2136 const clang::FunctionProtoType *function_type =
2137 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2138 if (function_type == nullptr)
2139 return clang::DeclarationName();
2140
2141 const bool is_method = false;
2142 const unsigned int num_params = function_type->getNumParams();
2144 is_method, op_kind, num_params))
2145 return clang::DeclarationName();
2146
2147 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2148}
2149
2151 clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
2152 printing_policy.SuppressTagKeyword = true;
2153 // Inline namespaces are important for some type formatters (e.g., libc++
2154 // and libstdc++ are differentiated by their inline namespaces).
2155 printing_policy.SuppressInlineNamespace = false;
2156 printing_policy.SuppressUnwrittenScope = false;
2157 // Default arguments are also always important for type formatters. Otherwise
2158 // we would need to always specify two type names for the setups where we do
2159 // know the default arguments and where we don't know default arguments.
2160 //
2161 // For example, without this we would need to have formatters for both:
2162 // std::basic_string<char>
2163 // and
2164 // std::basic_string<char, std::char_traits<char>, std::allocator<char> >
2165 // to support setups where LLDB was able to reconstruct default arguments
2166 // (and we then would have suppressed them from the type name) and also setups
2167 // where LLDB wasn't able to reconstruct the default arguments.
2168 printing_policy.SuppressDefaultTemplateArgs = false;
2169 return printing_policy;
2170}
2171
2172std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl,
2173 bool qualified) {
2174 clang::PrintingPolicy printing_policy = GetTypePrintingPolicy();
2175 std::string result;
2176 llvm::raw_string_ostream os(result);
2177 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2178 return result;
2179}
2180
2182 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
2183 llvm::StringRef name, const CompilerType &function_clang_type,
2184 clang::StorageClass storage, bool is_inline) {
2185 FunctionDecl *func_decl = nullptr;
2186 ASTContext &ast = getASTContext();
2187 if (!decl_ctx)
2188 decl_ctx = ast.getTranslationUnitDecl();
2189
2190 const bool hasWrittenPrototype = true;
2191 const bool isConstexprSpecified = false;
2192
2193 clang::DeclarationName declarationName =
2194 GetDeclarationName(name, function_clang_type);
2195 func_decl = FunctionDecl::CreateDeserialized(ast, 0);
2196 func_decl->setDeclContext(decl_ctx);
2197 func_decl->setDeclName(declarationName);
2198 func_decl->setType(ClangUtil::GetQualType(function_clang_type));
2199 func_decl->setStorageClass(storage);
2200 func_decl->setInlineSpecified(is_inline);
2201 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2202 func_decl->setConstexprKind(isConstexprSpecified
2203 ? ConstexprSpecKind::Constexpr
2204 : ConstexprSpecKind::Unspecified);
2205 SetOwningModule(func_decl, owning_module);
2206 decl_ctx->addDecl(func_decl);
2207
2208 VerifyDecl(func_decl);
2209
2210 return func_decl;
2211}
2212
2214 const CompilerType &result_type, const CompilerType *args,
2215 unsigned num_args, bool is_variadic, unsigned type_quals,
2216 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2217 if (!result_type || !ClangUtil::IsClangType(result_type))
2218 return CompilerType(); // invalid return type
2219
2220 std::vector<QualType> qual_type_args;
2221 if (num_args > 0 && args == nullptr)
2222 return CompilerType(); // invalid argument array passed in
2223
2224 // Verify that all arguments are valid and the right type
2225 for (unsigned i = 0; i < num_args; ++i) {
2226 if (args[i]) {
2227 // Make sure we have a clang type in args[i] and not a type from another
2228 // language whose name might match
2229 const bool is_clang_type = ClangUtil::IsClangType(args[i]);
2230 lldbassert(is_clang_type);
2231 if (is_clang_type)
2232 qual_type_args.push_back(ClangUtil::GetQualType(args[i]));
2233 else
2234 return CompilerType(); // invalid argument type (must be a clang type)
2235 } else
2236 return CompilerType(); // invalid argument type (empty)
2237 }
2238
2239 // TODO: Detect calling convention in DWARF?
2240 FunctionProtoType::ExtProtoInfo proto_info;
2241 proto_info.ExtInfo = cc;
2242 proto_info.Variadic = is_variadic;
2243 proto_info.ExceptionSpec = EST_None;
2244 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2245 proto_info.RefQualifier = ref_qual;
2246
2247 return GetType(getASTContext().getFunctionType(
2248 ClangUtil::GetQualType(result_type), qual_type_args, proto_info));
2249}
2250
2252 clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
2253 const char *name, const CompilerType &param_type, int storage,
2254 bool add_decl) {
2255 ASTContext &ast = getASTContext();
2256 auto *decl = ParmVarDecl::CreateDeserialized(ast, 0);
2257 decl->setDeclContext(decl_ctx);
2258 if (name && name[0])
2259 decl->setDeclName(&ast.Idents.get(name));
2260 decl->setType(ClangUtil::GetQualType(param_type));
2261 decl->setStorageClass(static_cast<clang::StorageClass>(storage));
2262 SetOwningModule(decl, owning_module);
2263 if (add_decl)
2264 decl_ctx->addDecl(decl);
2265
2266 return decl;
2267}
2268
2270 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2271 if (function_decl)
2272 function_decl->setParams(params);
2273}
2274
2277 QualType block_type = m_ast_up->getBlockPointerType(
2278 clang::QualType::getFromOpaquePtr(function_type.GetOpaqueQualType()));
2279
2280 return GetType(block_type);
2281}
2282
2283#pragma mark Array Types
2284
2286 size_t element_count,
2287 bool is_vector) {
2288 if (element_type.IsValid()) {
2289 ASTContext &ast = getASTContext();
2290
2291 if (is_vector) {
2292 return GetType(ast.getExtVectorType(ClangUtil::GetQualType(element_type),
2293 element_count));
2294 } else {
2295
2296 llvm::APInt ap_element_count(64, element_count);
2297 if (element_count == 0) {
2298 return GetType(ast.getIncompleteArrayType(
2299 ClangUtil::GetQualType(element_type), clang::ArrayType::Normal, 0));
2300 } else {
2301 return GetType(ast.getConstantArrayType(
2302 ClangUtil::GetQualType(element_type), ap_element_count, nullptr,
2303 clang::ArrayType::Normal, 0));
2304 }
2305 }
2306 }
2307 return CompilerType();
2308}
2309
2311 ConstString type_name,
2312 const std::initializer_list<std::pair<const char *, CompilerType>>
2313 &type_fields,
2314 bool packed) {
2315 CompilerType type;
2316 if (!type_name.IsEmpty() &&
2317 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2318 .IsValid()) {
2319 lldbassert(0 && "Trying to create a type for an existing name");
2320 return type;
2321 }
2322
2324 type_name.GetCString(), clang::TTK_Struct,
2327 for (const auto &field : type_fields)
2328 AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic,
2329 0);
2330 if (packed)
2331 SetIsPacked(type);
2333 return type;
2334}
2335
2337 ConstString type_name,
2338 const std::initializer_list<std::pair<const char *, CompilerType>>
2339 &type_fields,
2340 bool packed) {
2341 CompilerType type;
2342 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2343 return type;
2344
2345 return CreateStructForIdentifier(type_name, type_fields, packed);
2346}
2347
2348#pragma mark Enumeration Types
2349
2351 llvm::StringRef name, clang::DeclContext *decl_ctx,
2352 OptionalClangModuleID owning_module, const Declaration &decl,
2353 const CompilerType &integer_clang_type, bool is_scoped) {
2354 // TODO: Do something intelligent with the Declaration object passed in
2355 // like maybe filling in the SourceLocation with it...
2356 ASTContext &ast = getASTContext();
2357
2358 // TODO: ask about these...
2359 // const bool IsFixed = false;
2360 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, 0);
2361 enum_decl->setDeclContext(decl_ctx);
2362 if (!name.empty())
2363 enum_decl->setDeclName(&ast.Idents.get(name));
2364 enum_decl->setScoped(is_scoped);
2365 enum_decl->setScopedUsingClassTag(is_scoped);
2366 enum_decl->setFixed(false);
2367 SetOwningModule(enum_decl, owning_module);
2368 if (decl_ctx)
2369 decl_ctx->addDecl(enum_decl);
2370
2371 // TODO: check if we should be setting the promotion type too?
2372 enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type));
2373
2374 enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
2375
2376 return GetType(ast.getTagDeclType(enum_decl));
2377}
2378
2380 bool is_signed) {
2381 clang::ASTContext &ast = getASTContext();
2382
2383 if (is_signed) {
2384 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2385 return GetType(ast.SignedCharTy);
2386
2387 if (bit_size == ast.getTypeSize(ast.ShortTy))
2388 return GetType(ast.ShortTy);
2389
2390 if (bit_size == ast.getTypeSize(ast.IntTy))
2391 return GetType(ast.IntTy);
2392
2393 if (bit_size == ast.getTypeSize(ast.LongTy))
2394 return GetType(ast.LongTy);
2395
2396 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2397 return GetType(ast.LongLongTy);
2398
2399 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2400 return GetType(ast.Int128Ty);
2401 } else {
2402 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2403 return GetType(ast.UnsignedCharTy);
2404
2405 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2406 return GetType(ast.UnsignedShortTy);
2407
2408 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2409 return GetType(ast.UnsignedIntTy);
2410
2411 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2412 return GetType(ast.UnsignedLongTy);
2413
2414 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2415 return GetType(ast.UnsignedLongLongTy);
2416
2417 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2418 return GetType(ast.UnsignedInt128Ty);
2419 }
2420 return CompilerType();
2421}
2422
2424 return GetIntTypeFromBitSize(
2425 getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed);
2426}
2427
2428void TypeSystemClang::DumpDeclContextHiearchy(clang::DeclContext *decl_ctx) {
2429 if (decl_ctx) {
2430 DumpDeclContextHiearchy(decl_ctx->getParent());
2431
2432 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2433 if (named_decl) {
2434 printf("%20s: %s\n", decl_ctx->getDeclKindName(),
2435 named_decl->getDeclName().getAsString().c_str());
2436 } else {
2437 printf("%20s\n", decl_ctx->getDeclKindName());
2438 }
2439 }
2440}
2441
2442void TypeSystemClang::DumpDeclHiearchy(clang::Decl *decl) {
2443 if (decl == nullptr)
2444 return;
2445 DumpDeclContextHiearchy(decl->getDeclContext());
2446
2447 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2448 if (record_decl) {
2449 printf("%20s: %s%s\n", decl->getDeclKindName(),
2450 record_decl->getDeclName().getAsString().c_str(),
2451 record_decl->isInjectedClassName() ? " (injected class name)" : "");
2452
2453 } else {
2454 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2455 if (named_decl) {
2456 printf("%20s: %s\n", decl->getDeclKindName(),
2457 named_decl->getDeclName().getAsString().c_str());
2458 } else {
2459 printf("%20s\n", decl->getDeclKindName());
2460 }
2461 }
2462}
2463
2464bool TypeSystemClang::DeclsAreEquivalent(clang::Decl *lhs_decl,
2465 clang::Decl *rhs_decl) {
2466 if (lhs_decl && rhs_decl) {
2467 // Make sure the decl kinds match first
2468 const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind();
2469 const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind();
2470
2471 if (lhs_decl_kind == rhs_decl_kind) {
2472 // Now check that the decl contexts kinds are all equivalent before we
2473 // have to check any names of the decl contexts...
2474 clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext();
2475 clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext();
2476 if (lhs_decl_ctx && rhs_decl_ctx) {
2477 while (true) {
2478 if (lhs_decl_ctx && rhs_decl_ctx) {
2479 const clang::Decl::Kind lhs_decl_ctx_kind =
2480 lhs_decl_ctx->getDeclKind();
2481 const clang::Decl::Kind rhs_decl_ctx_kind =
2482 rhs_decl_ctx->getDeclKind();
2483 if (lhs_decl_ctx_kind == rhs_decl_ctx_kind) {
2484 lhs_decl_ctx = lhs_decl_ctx->getParent();
2485 rhs_decl_ctx = rhs_decl_ctx->getParent();
2486
2487 if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr)
2488 break;
2489 } else
2490 return false;
2491 } else
2492 return false;
2493 }
2494
2495 // Now make sure the name of the decls match
2496 clang::NamedDecl *lhs_named_decl =
2497 llvm::dyn_cast<clang::NamedDecl>(lhs_decl);
2498 clang::NamedDecl *rhs_named_decl =
2499 llvm::dyn_cast<clang::NamedDecl>(rhs_decl);
2500 if (lhs_named_decl && rhs_named_decl) {
2501 clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
2502 clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
2503 if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) {
2504 if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2505 return false;
2506 } else
2507 return false;
2508 } else
2509 return false;
2510
2511 // We know that the decl context kinds all match, so now we need to
2512 // make sure the names match as well
2513 lhs_decl_ctx = lhs_decl->getDeclContext();
2514 rhs_decl_ctx = rhs_decl->getDeclContext();
2515 while (true) {
2516 switch (lhs_decl_ctx->getDeclKind()) {
2517 case clang::Decl::TranslationUnit:
2518 // We don't care about the translation unit names
2519 return true;
2520 default: {
2521 clang::NamedDecl *lhs_named_decl =
2522 llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx);
2523 clang::NamedDecl *rhs_named_decl =
2524 llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx);
2525 if (lhs_named_decl && rhs_named_decl) {
2526 clang::DeclarationName lhs_decl_name =
2527 lhs_named_decl->getDeclName();
2528 clang::DeclarationName rhs_decl_name =
2529 rhs_named_decl->getDeclName();
2530 if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) {
2531 if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2532 return false;
2533 } else
2534 return false;
2535 } else
2536 return false;
2537 } break;
2538 }
2539 lhs_decl_ctx = lhs_decl_ctx->getParent();
2540 rhs_decl_ctx = rhs_decl_ctx->getParent();
2541 }
2542 }
2543 }
2544 }
2545 return false;
2546}
2547bool TypeSystemClang::GetCompleteDecl(clang::ASTContext *ast,
2548 clang::Decl *decl) {
2549 if (!decl)
2550 return false;
2551
2552 ExternalASTSource *ast_source = ast->getExternalSource();
2553
2554 if (!ast_source)
2555 return false;
2556
2557 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2558 if (tag_decl->isCompleteDefinition())
2559 return true;
2560
2561 if (!tag_decl->hasExternalLexicalStorage())
2562 return false;
2563
2564 ast_source->CompleteType(tag_decl);
2565
2566 return !tag_decl->getTypeForDecl()->isIncompleteType();
2567 } else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2568 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2569 if (objc_interface_decl->getDefinition())
2570 return true;
2571
2572 if (!objc_interface_decl->hasExternalLexicalStorage())
2573 return false;
2574
2575 ast_source->CompleteType(objc_interface_decl);
2576
2577 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2578 } else {
2579 return false;
2580 }
2581}
2582
2583void TypeSystemClang::SetMetadataAsUserID(const clang::Decl *decl,
2584 user_id_t user_id) {
2585 ClangASTMetadata meta_data;
2586 meta_data.SetUserID(user_id);
2587 SetMetadata(decl, meta_data);
2588}
2589
2590void TypeSystemClang::SetMetadataAsUserID(const clang::Type *type,
2591 user_id_t user_id) {
2592 ClangASTMetadata meta_data;
2593 meta_data.SetUserID(user_id);
2594 SetMetadata(type, meta_data);
2595}
2596
2597void TypeSystemClang::SetMetadata(const clang::Decl *object,
2598 ClangASTMetadata &metadata) {
2599 m_decl_metadata[object] = metadata;
2600}
2601
2602void TypeSystemClang::SetMetadata(const clang::Type *object,
2603 ClangASTMetadata &metadata) {
2604 m_type_metadata[object] = metadata;
2605}
2606
2608 auto It = m_decl_metadata.find(object);
2609 if (It != m_decl_metadata.end())
2610 return &It->second;
2611 return nullptr;
2612}
2613
2615 auto It = m_type_metadata.find(object);
2616 if (It != m_type_metadata.end())
2617 return &It->second;
2618 return nullptr;
2619}
2620
2621void TypeSystemClang::SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object,
2622 clang::AccessSpecifier access) {
2623 if (access == clang::AccessSpecifier::AS_none)
2624 m_cxx_record_decl_access.erase(object);
2625 else
2626 m_cxx_record_decl_access[object] = access;
2627}
2628
2629clang::AccessSpecifier
2630TypeSystemClang::GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object) {
2631 auto It = m_cxx_record_decl_access.find(object);
2632 if (It != m_cxx_record_decl_access.end())
2633 return It->second;
2634 return clang::AccessSpecifier::AS_none;
2635}
2636
2637clang::DeclContext *
2640}
2641
2642/// Aggressively desugar the provided type, skipping past various kinds of
2643/// syntactic sugar and other constructs one typically wants to ignore.
2644/// The \p mask argument allows one to skip certain kinds of simplifications,
2645/// when one wishes to handle a certain kind of type directly.
2646static QualType
2647RemoveWrappingTypes(QualType type, ArrayRef<clang::Type::TypeClass> mask = {}) {
2648 while (true) {
2649 if (find(mask, type->getTypeClass()) != mask.end())
2650 return type;
2651 switch (type->getTypeClass()) {
2652 // This is not fully correct as _Atomic is more than sugar, but it is
2653 // sufficient for the purposes we care about.
2654 case clang::Type::Atomic:
2655 type = cast<clang::AtomicType>(type)->getValueType();
2656 break;
2657 case clang::Type::Auto:
2658 case clang::Type::Decltype:
2659 case clang::Type::Elaborated:
2660 case clang::Type::Paren:
2661 case clang::Type::SubstTemplateTypeParm:
2662 case clang::Type::TemplateSpecialization:
2663 case clang::Type::Typedef:
2664 case clang::Type::TypeOf:
2665 case clang::Type::TypeOfExpr:
2666 case clang::Type::Using:
2667 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2668 break;
2669 default:
2670 return type;
2671 }
2672 }
2673}
2674
2675clang::DeclContext *
2677 if (type.isNull())
2678 return nullptr;
2679
2680 clang::QualType qual_type = RemoveWrappingTypes(type.getCanonicalType());
2681 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2682 switch (type_class) {
2683 case clang::Type::ObjCInterface:
2684 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2685 ->getInterface();
2686 case clang::Type::ObjCObjectPointer:
2687 return GetDeclContextForType(
2688 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2689 ->getPointeeType());
2690 case clang::Type::Record:
2691 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2692 case clang::Type::Enum:
2693 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2694 default:
2695 break;
2696 }
2697 // No DeclContext in this type...
2698 return nullptr;
2699}
2700
2701static bool GetCompleteQualType(clang::ASTContext *ast,
2702 clang::QualType qual_type,
2703 bool allow_completion = true) {
2704 qual_type = RemoveWrappingTypes(qual_type);
2705 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2706 switch (type_class) {
2707 case clang::Type::ConstantArray:
2708 case clang::Type::IncompleteArray:
2709 case clang::Type::VariableArray: {
2710 const clang::ArrayType *array_type =
2711 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2712
2713 if (array_type)
2714 return GetCompleteQualType(ast, array_type->getElementType(),
2715 allow_completion);
2716 } break;
2717 case clang::Type::Record: {
2718 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2719 if (cxx_record_decl) {
2720 if (cxx_record_decl->hasExternalLexicalStorage()) {
2721 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2722 const bool fields_loaded =
2723 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2724 if (is_complete && fields_loaded)
2725 return true;
2726
2727 if (!allow_completion)
2728 return false;
2729
2730 // Call the field_begin() accessor to for it to use the external source
2731 // to load the fields...
2732 clang::ExternalASTSource *external_ast_source =
2733 ast->getExternalSource();
2734 if (external_ast_source) {
2735 external_ast_source->CompleteType(cxx_record_decl);
2736 if (cxx_record_decl->isCompleteDefinition()) {
2737 cxx_record_decl->field_begin();
2738 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
2739 }
2740 }
2741 }
2742 }
2743 const clang::TagType *tag_type =
2744 llvm::cast<clang::TagType>(qual_type.getTypePtr());
2745 return !tag_type->isIncompleteType();
2746 } break;
2747
2748 case clang::Type::Enum: {
2749 const clang::TagType *tag_type =
2750 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
2751 if (tag_type) {
2752 clang::TagDecl *tag_decl = tag_type->getDecl();
2753 if (tag_decl) {
2754 if (tag_decl->getDefinition())
2755 return true;
2756
2757 if (!allow_completion)
2758 return false;
2759
2760 if (tag_decl->hasExternalLexicalStorage()) {
2761 if (ast) {
2762 clang::ExternalASTSource *external_ast_source =
2763 ast->getExternalSource();
2764 if (external_ast_source) {
2765 external_ast_source->CompleteType(tag_decl);
2766 return !tag_type->isIncompleteType();
2767 }
2768 }
2769 }
2770 return false;
2771 }
2772 }
2773
2774 } break;
2775 case clang::Type::ObjCObject:
2776 case clang::Type::ObjCInterface: {
2777 const clang::ObjCObjectType *objc_class_type =
2778 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2779 if (objc_class_type) {
2780 clang::ObjCInterfaceDecl *class_interface_decl =
2781 objc_class_type->getInterface();
2782 // We currently can't complete objective C types through the newly added
2783 // ASTContext because it only supports TagDecl objects right now...
2784 if (class_interface_decl) {
2785 if (class_interface_decl->getDefinition())
2786 return true;
2787
2788 if (!allow_completion)
2789 return false;
2790
2791 if (class_interface_decl->hasExternalLexicalStorage()) {
2792 if (ast) {
2793 clang::ExternalASTSource *external_ast_source =
2794 ast->getExternalSource();
2795 if (external_ast_source) {
2796 external_ast_source->CompleteType(class_interface_decl);
2797 return !objc_class_type->isIncompleteType();
2798 }
2799 }
2800 }
2801 return false;
2802 }
2803 }
2804 } break;
2805
2806 case clang::Type::Attributed:
2807 return GetCompleteQualType(
2808 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2809 allow_completion);
2810
2811 default:
2812 break;
2813 }
2814
2815 return true;
2816}
2817
2818static clang::ObjCIvarDecl::AccessControl
2820 switch (access) {
2821 case eAccessNone:
2822 return clang::ObjCIvarDecl::None;
2823 case eAccessPublic:
2824 return clang::ObjCIvarDecl::Public;
2825 case eAccessPrivate:
2826 return clang::ObjCIvarDecl::Private;
2827 case eAccessProtected:
2828 return clang::ObjCIvarDecl::Protected;
2829 case eAccessPackage:
2830 return clang::ObjCIvarDecl::Package;
2831 }
2832 return clang::ObjCIvarDecl::None;
2833}
2834
2835// Tests
2836
2837#ifndef NDEBUG
2839 return !type || llvm::isa<clang::Type>(GetQualType(type).getTypePtr());
2840}
2841#endif
2842
2844 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2845
2846 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2847 switch (type_class) {
2848 case clang::Type::IncompleteArray:
2849 case clang::Type::VariableArray:
2850 case clang::Type::ConstantArray:
2851 case clang::Type::ExtVector:
2852 case clang::Type::Vector:
2853 case clang::Type::Record:
2854 case clang::Type::ObjCObject:
2855 case clang::Type::ObjCInterface:
2856 return true;
2857 default:
2858 break;
2859 }
2860 // The clang type does have a value
2861 return false;
2862}
2863
2865 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2866
2867 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2868 switch (type_class) {
2869 case clang::Type::Record: {
2870 if (const clang::RecordType *record_type =
2871 llvm::dyn_cast_or_null<clang::RecordType>(
2872 qual_type.getTypePtrOrNull())) {
2873 if (const clang::RecordDecl *record_decl = record_type->getDecl()) {
2874 return record_decl->isAnonymousStructOrUnion();
2875 }
2876 }
2877 break;
2878 }
2879 default:
2880 break;
2881 }
2882 // The clang type does have a value
2883 return false;
2884}
2885
2887 CompilerType *element_type_ptr,
2888 uint64_t *size, bool *is_incomplete) {
2889 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
2890
2891 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2892 switch (type_class) {
2893 default:
2894 break;
2895
2896 case clang::Type::ConstantArray:
2897 if (element_type_ptr)
2898 element_type_ptr->SetCompilerType(
2899 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2900 ->getElementType()
2901 .getAsOpaquePtr());
2902 if (size)
2903 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2904 ->getSize()
2905 .getLimitedValue(ULLONG_MAX);
2906 if (is_incomplete)
2907 *is_incomplete = false;
2908 return true;
2909
2910 case clang::Type::IncompleteArray:
2911 if (element_type_ptr)
2912 element_type_ptr->SetCompilerType(
2913 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2914 ->getElementType()
2915 .getAsOpaquePtr());
2916 if (size)
2917 *size = 0;
2918 if (is_incomplete)
2919 *is_incomplete = true;
2920 return true;
2921
2922 case clang::Type::VariableArray:
2923 if (element_type_ptr)
2924 element_type_ptr->SetCompilerType(
2925 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2926 ->getElementType()
2927 .getAsOpaquePtr());
2928 if (size)
2929 *size = 0;
2930 if (is_incomplete)
2931 *is_incomplete = false;
2932 return true;
2933
2934 case clang::Type::DependentSizedArray:
2935 if (element_type_ptr)
2936 element_type_ptr->SetCompilerType(
2937 weak_from_this(),
2938 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2939 ->getElementType()
2940 .getAsOpaquePtr());
2941 if (size)
2942 *size = 0;
2943 if (is_incomplete)
2944 *is_incomplete = false;
2945 return true;
2946 }
2947 if (element_type_ptr)
2948 element_type_ptr->Clear();
2949 if (size)
2950 *size = 0;
2951 if (is_incomplete)
2952 *is_incomplete = false;
2953 return false;
2954}
2955
2957 CompilerType *element_type, uint64_t *size) {
2958 clang::QualType qual_type(GetCanonicalQualType(type));
2959
2960 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2961 switch (type_class) {
2962 case clang::Type::Vector: {
2963 const clang::VectorType *vector_type =
2964 qual_type->getAs<clang::VectorType>();
2965 if (vector_type) {
2966 if (size)
2967 *size = vector_type->getNumElements();
2968 if (element_type)
2969 *element_type = GetType(vector_type->getElementType());
2970 }
2971 return true;
2972 } break;
2973 case clang::Type::ExtVector: {
2974 const clang::ExtVectorType *ext_vector_type =
2975 qual_type->getAs<clang::ExtVectorType>();
2976 if (ext_vector_type) {
2977 if (size)
2978 *size = ext_vector_type->getNumElements();
2979 if (element_type)
2980 *element_type =
2981 CompilerType(weak_from_this(),
2982 ext_vector_type->getElementType().getAsOpaquePtr());
2983 }
2984 return true;
2985 }
2986 default:
2987 break;
2988 }
2989 return false;
2990}
2991
2994 clang::DeclContext *decl_ctx = GetDeclContextForType(GetQualType(type));
2995 if (!decl_ctx)
2996 return false;
2997
2998 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2999 return false;
3000
3001 clang::ObjCInterfaceDecl *result_iface_decl =
3002 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
3003
3004 ClangASTMetadata *ast_metadata = GetMetadata(result_iface_decl);
3005 if (!ast_metadata)
3006 return false;
3007 return (ast_metadata->GetISAPtr() != 0);
3008}
3009
3011 return GetQualType(type).getUnqualifiedType()->isCharType();
3012}
3013
3015 // If the type hasn't been lazily completed yet, complete it now so that we
3016 // can give the caller an accurate answer whether the type actually has a
3017 // definition. Without completing the type now we would just tell the user
3018 // the current (internal) completeness state of the type and most users don't
3019 // care (or even know) about this behavior.
3020 const bool allow_completion = true;
3022 allow_completion);
3023}
3024
3026 return GetQualType(type).isConstQualified();
3027}
3028
3030 uint32_t &length) {
3031 CompilerType pointee_or_element_clang_type;
3032 length = 0;
3033 Flags type_flags(GetTypeInfo(type, &pointee_or_element_clang_type));
3034
3035 if (!pointee_or_element_clang_type.IsValid())
3036 return false;
3037
3038 if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer)) {
3039 if (pointee_or_element_clang_type.IsCharType()) {
3040 if (type_flags.Test(eTypeIsArray)) {
3041 // We know the size of the array and it could be a C string since it is
3042 // an array of characters
3043 length = llvm::cast<clang::ConstantArrayType>(
3044 GetCanonicalQualType(type).getTypePtr())
3045 ->getSize()
3046 .getLimitedValue();
3047 }
3048 return true;
3049 }
3050 }
3051 return false;
3052}
3053
3055 auto isFunctionType = [&](clang::QualType qual_type) {
3056 return qual_type->isFunctionType();
3057 };
3058
3059 return IsTypeImpl(type, isFunctionType);
3060}
3061
3062// Used to detect "Homogeneous Floating-point Aggregates"
3065 CompilerType *base_type_ptr) {
3066 if (!type)
3067 return 0;
3068
3069 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
3070 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3071 switch (type_class) {
3072 case clang::Type::Record:
3073 if (GetCompleteType(type)) {
3074 const clang::CXXRecordDecl *cxx_record_decl =
3075 qual_type->getAsCXXRecordDecl();
3076 if (cxx_record_decl) {
3077 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3078 return 0;
3079 }
3080 const clang::RecordType *record_type =
3081 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3082 if (record_type) {
3083 const clang::RecordDecl *record_decl = record_type->getDecl();
3084 if (record_decl) {
3085 // We are looking for a structure that contains only floating point
3086 // types
3087 clang::RecordDecl::field_iterator field_pos,
3088 field_end = record_decl->field_end();
3089 uint32_t num_fields = 0;
3090 bool is_hva = false;
3091 bool is_hfa = false;
3092 clang::QualType base_qual_type;
3093 uint64_t base_bitwidth = 0;
3094 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3095 ++field_pos) {
3096 clang::QualType field_qual_type = field_pos->getType();
3097 uint64_t field_bitwidth = getASTContext().getTypeSize(qual_type);
3098 if (field_qual_type->isFloatingType()) {
3099 if (field_qual_type->isComplexType())
3100 return 0;
3101 else {
3102 if (num_fields == 0)
3103 base_qual_type = field_qual_type;
3104 else {
3105 if (is_hva)
3106 return 0;
3107 is_hfa = true;
3108 if (field_qual_type.getTypePtr() !=
3109 base_qual_type.getTypePtr())
3110 return 0;
3111 }
3112 }
3113 } else if (field_qual_type->isVectorType() ||
3114 field_qual_type->isExtVectorType()) {
3115 if (num_fields == 0) {
3116 base_qual_type = field_qual_type;
3117 base_bitwidth = field_bitwidth;
3118 } else {
3119 if (is_hfa)
3120 return 0;
3121 is_hva = true;
3122 if (base_bitwidth != field_bitwidth)
3123 return 0;
3124 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3125 return 0;
3126 }
3127 } else
3128 return 0;
3129 ++num_fields;
3130 }
3131 if (base_type_ptr)
3132 *base_type_ptr =
3133 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3134 return num_fields;
3135 }
3136 }
3137 }
3138 break;
3139
3140 default:
3141 break;
3142 }
3143 return 0;
3144}
3145
3148 if (type) {
3149 clang::QualType qual_type(GetCanonicalQualType(type));
3150 const clang::FunctionProtoType *func =
3151 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3152 if (func)
3153 return func->getNumParams();
3154 }
3155 return 0;
3156}
3157
3160 const size_t index) {
3161 if (type) {
3162 clang::QualType qual_type(GetQualType(type));
3163 const clang::FunctionProtoType *func =
3164 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3165 if (func) {
3166 if (index < func->getNumParams())
3167 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3168 }
3169 }
3170 return CompilerType();
3171}
3172
3175 llvm::function_ref<bool(clang::QualType)> predicate) const {
3176 if (type) {
3177 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3178
3179 if (predicate(qual_type))
3180 return true;
3181
3182 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3183 switch (type_class) {
3184 default:
3185 break;
3186
3187 case clang::Type::LValueReference:
3188 case clang::Type::RValueReference: {
3189 const clang::ReferenceType *reference_type =
3190 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3191 if (reference_type)
3192 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3193 } break;
3194 }
3195 }
3196 return false;
3197}
3198
3201 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3202 return qual_type->isMemberFunctionPointerType();
3203 };
3204
3205 return IsTypeImpl(type, isMemberFunctionPointerType);
3206}
3207
3209 auto isFunctionPointerType = [](clang::QualType qual_type) {
3210 return qual_type->isFunctionPointerType();
3211 };
3212
3213 return IsTypeImpl(type, isFunctionPointerType);
3214}
3215
3218 CompilerType *function_pointer_type_ptr) {
3219 auto isBlockPointerType = [&](clang::QualType qual_type) {
3220 if (qual_type->isBlockPointerType()) {
3221 if (function_pointer_type_ptr) {
3222 const clang::BlockPointerType *block_pointer_type =
3223 qual_type->castAs<clang::BlockPointerType>();
3224 QualType pointee_type = block_pointer_type->getPointeeType();
3225 QualType function_pointer_type = m_ast_up->getPointerType(pointee_type);
3226 *function_pointer_type_ptr = CompilerType(
3227 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3228 }
3229 return true;
3230 }
3231
3232 return false;
3233 };
3234
3235 return IsTypeImpl(type, isBlockPointerType);
3236}
3237
3239 bool &is_signed) {
3240 if (!type)
3241 return false;
3242
3243 clang::QualType qual_type(GetCanonicalQualType(type));
3244 const clang::BuiltinType *builtin_type =
3245 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3246
3247 if (builtin_type) {
3248 if (builtin_type->isInteger()) {
3249 is_signed = builtin_type->isSignedInteger();
3250 return true;
3251 }
3252 }
3253
3254 return false;
3255}
3256
3258 bool &is_signed) {
3259 if (type) {
3260 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3261 GetCanonicalQualType(type)->getCanonicalTypeInternal());
3262
3263 if (enum_type) {
3264 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3265 is_signed);
3266 return true;
3267 }
3268 }
3269
3270 return false;
3271}
3272
3275 if (type) {
3276 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3277 GetCanonicalQualType(type)->getCanonicalTypeInternal());
3278
3279 if (enum_type) {
3280 return enum_type->isScopedEnumeralType();
3281 }
3282 }
3283
3284 return false;
3285}
3286
3288 CompilerType *pointee_type) {
3289 if (type) {
3290 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3291 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3292 switch (type_class) {
3293 case clang::Type::Builtin:
3294 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3295 default:
3296 break;
3297 case clang::BuiltinType::ObjCId:
3298 case clang::BuiltinType::ObjCClass:
3299 return true;
3300 }
3301 return false;
3302 case clang::Type::ObjCObjectPointer:
3303 if (pointee_type)
3304 pointee_type->SetCompilerType(
3305 weak_from_this(),
3306 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3307 ->getPointeeType()
3308 .getAsOpaquePtr());
3309 return true;
3310 case clang::Type::BlockPointer:
3311 if (pointee_type)
3312 pointee_type->SetCompilerType(
3313 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3314 ->getPointeeType()
3315 .getAsOpaquePtr());
3316 return true;
3317 case clang::Type::Pointer:
3318 if (pointee_type)
3319 pointee_type->SetCompilerType(weak_from_this(),
3320 llvm::cast<clang::PointerType>(qual_type)
3321 ->getPointeeType()
3322 .getAsOpaquePtr());
3323 return true;
3324 case clang::Type::MemberPointer:
3325 if (pointee_type)
3326 pointee_type->SetCompilerType(
3327 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3328 ->getPointeeType()
3329 .getAsOpaquePtr());
3330 return true;
3331 default:
3332 break;
3333 }
3334 }
3335 if (pointee_type)
3336 pointee_type->Clear();
3337 return false;
3338}
3339
3341 lldb::opaque_compiler_type_t type, CompilerType *pointee_type) {
3342 if (type) {
3343 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3344 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3345 switch (type_class) {
3346 case clang::Type::Builtin:
3347 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3348 default:
3349 break;
3350 case clang::BuiltinType::ObjCId:
3351 case clang::BuiltinType::ObjCClass:
3352 return true;
3353 }
3354 return false;
3355 case clang::Type::ObjCObjectPointer:
3356 if (pointee_type)
3357 pointee_type->SetCompilerType(
3358 weak_from_this(),
3359 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3360 ->getPointeeType()
3361 .getAsOpaquePtr());
3362 return true;
3363 case clang::Type::BlockPointer:
3364 if (pointee_type)
3365 pointee_type->SetCompilerType(
3366 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3367 ->getPointeeType()
3368 .getAsOpaquePtr());
3369 return true;
3370 case clang::Type::Pointer:
3371 if (pointee_type)
3372 pointee_type->SetCompilerType(weak_from_this(),
3373 llvm::cast<clang::PointerType>(qual_type)
3374 ->getPointeeType()
3375 .getAsOpaquePtr());
3376 return true;
3377 case clang::Type::MemberPointer:
3378 if (pointee_type)
3379 pointee_type->SetCompilerType(
3380 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3381 ->getPointeeType()
3382 .getAsOpaquePtr());
3383 return true;
3384 case clang::Type::LValueReference:
3385 if (pointee_type)
3386 pointee_type->SetCompilerType(
3387 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3388 ->desugar()
3389 .getAsOpaquePtr());
3390 return true;
3391 case clang::Type::RValueReference:
3392 if (pointee_type)
3393 pointee_type->SetCompilerType(
3394 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3395 ->desugar()
3396 .getAsOpaquePtr());
3397 return true;
3398 default:
3399 break;
3400 }
3401 }
3402 if (pointee_type)
3403 pointee_type->Clear();
3404 return false;
3405}
3406
3408 CompilerType *pointee_type,
3409 bool *is_rvalue) {
3410 if (type) {
3411 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3412 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3413
3414 switch (type_class) {
3415 case clang::Type::LValueReference:
3416 if (pointee_type)
3417 pointee_type->SetCompilerType(
3418 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3419 ->desugar()
3420 .getAsOpaquePtr());
3421 if (is_rvalue)
3422 *is_rvalue = false;
3423 return true;
3424 case clang::Type::RValueReference:
3425 if (pointee_type)
3426 pointee_type->SetCompilerType(
3427 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3428 ->desugar()
3429 .getAsOpaquePtr());
3430 if (is_rvalue)
3431 *is_rvalue = true;
3432 return true;
3433
3434 default:
3435 break;
3436 }
3437 }
3438 if (pointee_type)
3439 pointee_type->Clear();
3440 return false;
3441}
3442
3444 uint32_t &count, bool &is_complex) {
3445 if (type) {
3446 clang::QualType qual_type(GetCanonicalQualType(type));
3447
3448 if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3449 qual_type->getCanonicalTypeInternal())) {
3450 clang::BuiltinType::Kind kind = BT->getKind();
3451 if (kind >= clang::BuiltinType::Float &&
3452 kind <= clang::BuiltinType::LongDouble) {
3453 count = 1;
3454 is_complex = false;
3455 return true;
3456 }
3457 } else if (const clang::ComplexType *CT =
3458 llvm::dyn_cast<clang::ComplexType>(
3459 qual_type->getCanonicalTypeInternal())) {
3460 if (IsFloatingPointType(CT->getElementType().getAsOpaquePtr(), count,
3461 is_complex)) {
3462 count = 2;
3463 is_complex = true;
3464 return true;
3465 }
3466 } else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3467 qual_type->getCanonicalTypeInternal())) {
3468 if (IsFloatingPointType(VT->getElementType().getAsOpaquePtr(), count,
3469 is_complex)) {
3470 count = VT->getNumElements();
3471 is_complex = false;
3472 return true;
3473 }
3474 }
3475 }
3476 count = 0;
3477 is_complex = false;
3478 return false;
3479}
3480
3482 if (!type)
3483 return false;
3484
3485 clang::QualType qual_type(GetQualType(type));
3486 const clang::TagType *tag_type =
3487 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3488 if (tag_type) {
3489 clang::TagDecl *tag_decl = tag_type->getDecl();
3490 if (tag_decl)
3491 return tag_decl->isCompleteDefinition();
3492 return false;
3493 } else {
3494 const clang::ObjCObjectType *objc_class_type =
3495 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3496 if (objc_class_type) {
3497 clang::ObjCInterfaceDecl *class_interface_decl =
3498 objc_class_type->getInterface();
3499 if (class_interface_decl)
3500 return class_interface_decl->getDefinition() != nullptr;
3501 return false;
3502 }
3503 }
3504 return true;
3505}
3506
3508 if (ClangUtil::IsClangType(type)) {
3509 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3510
3511 const clang::ObjCObjectPointerType *obj_pointer_type =
3512 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3513
3514 if (obj_pointer_type)
3515 return obj_pointer_type->isObjCClassType();
3516 }
3517 return false;
3518}
3519
3521 if (ClangUtil::IsClangType(type))
3522 return ClangUtil::GetCanonicalQualType(type)->isObjCObjectOrInterfaceType();
3523 return false;
3524}
3525
3527 if (!type)
3528 return false;
3529 clang::QualType qual_type(GetCanonicalQualType(type));
3530 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3531 return (type_class == clang::Type::Record);
3532}
3533
3535 if (!type)
3536 return false;
3537 clang::QualType qual_type(GetCanonicalQualType(type));
3538 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3539 return (type_class == clang::Type::Enum);
3540}
3541
3543 if (type) {
3544 clang::QualType qual_type(GetCanonicalQualType(type));
3545 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3546 switch (type_class) {
3547 case clang::Type::Record:
3548 if (GetCompleteType(type)) {
3549 const clang::RecordType *record_type =
3550 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3551 const clang::RecordDecl *record_decl = record_type->getDecl();
3552 if (record_decl) {
3553 const clang::CXXRecordDecl *cxx_record_decl =
3554 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3555 if (cxx_record_decl)
3556 return cxx_record_decl->isPolymorphic();
3557 }
3558 }
3559 break;
3560
3561 default:
3562 break;
3563 }
3564 }
3565 return false;
3566}
3567
3569 CompilerType *dynamic_pointee_type,
3570 bool check_cplusplus,
3571 bool check_objc) {
3572 clang::QualType pointee_qual_type;
3573 if (type) {
3574 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3575 bool success = false;
3576 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3577 switch (type_class) {
3578 case clang::Type::Builtin:
3579 if (check_objc &&
3580 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3581 clang::BuiltinType::ObjCId) {
3582 if (dynamic_pointee_type)
3583 dynamic_pointee_type->SetCompilerType(weak_from_this(), type);
3584 return true;
3585 }
3586 break;
3587
3588 case clang::Type::ObjCObjectPointer:
3589 if (check_objc) {
3590 if (const auto *objc_pointee_type =
3591 qual_type->getPointeeType().getTypePtrOrNull()) {
3592 if (const auto *objc_object_type =
3593 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3594 objc_pointee_type)) {
3595 if (objc_object_type->isObjCClass())
3596 return false;
3597 }
3598 }
3599 if (dynamic_pointee_type)
3600 dynamic_pointee_type->SetCompilerType(
3601 weak_from_this(),
3602 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3603 ->getPointeeType()
3604 .getAsOpaquePtr());
3605 return true;
3606 }
3607 break;
3608
3609 case clang::Type::Pointer:
3610 pointee_qual_type =
3611 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3612 success = true;
3613 break;
3614
3615 case clang::Type::LValueReference:
3616 case clang::Type::RValueReference:
3617 pointee_qual_type =
3618 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3619 success = true;
3620 break;
3621
3622 default:
3623 break;
3624 }
3625
3626 if (success) {
3627 // Check to make sure what we are pointing too is a possible dynamic C++
3628 // type We currently accept any "void *" (in case we have a class that
3629 // has been watered down to an opaque pointer) and virtual C++ classes.
3630 const clang::Type::TypeClass pointee_type_class =
3631 pointee_qual_type.getCanonicalType()->getTypeClass();
3632 switch (pointee_type_class) {
3633 case clang::Type::Builtin:
3634 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3635 case clang::BuiltinType::UnknownAny:
3636 case clang::BuiltinType::Void:
3637 if (dynamic_pointee_type)
3638 dynamic_pointee_type->SetCompilerType(
3639 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3640 return true;
3641 default:
3642 break;
3643 }
3644 break;
3645
3646 case clang::Type::Record:
3647 if (check_cplusplus) {
3648 clang::CXXRecordDecl *cxx_record_decl =
3649 pointee_qual_type->getAsCXXRecordDecl();
3650 if (cxx_record_decl) {
3651 bool is_complete = cxx_record_decl->isCompleteDefinition();
3652
3653 if (is_complete)
3654 success = cxx_record_decl->isDynamicClass();
3655 else {
3656 ClangASTMetadata *metadata = GetMetadata(cxx_record_decl);
3657 if (metadata)
3658 success = metadata->GetIsDynamicCXXType();
3659 else {
3660 is_complete = GetType(pointee_qual_type).GetCompleteType();
3661 if (is_complete)
3662 success = cxx_record_decl->isDynamicClass();
3663 else
3664 success = false;
3665 }
3666 }
3667
3668 if (success) {
3669 if (dynamic_pointee_type)
3670 dynamic_pointee_type->SetCompilerType(
3671 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3672 return true;
3673 }
3674 }
3675 }
3676 break;
3677
3678 case clang::Type::ObjCObject:
3679 case clang::Type::ObjCInterface:
3680 if (check_objc) {
3681 if (dynamic_pointee_type)
3682 dynamic_pointee_type->SetCompilerType(
3683 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3684 return true;
3685 }
3686 break;
3687
3688 default:
3689 break;
3690 }
3691 }
3692 }
3693 if (dynamic_pointee_type)
3694 dynamic_pointee_type->Clear();
3695 return false;
3696}
3697
3699 if (!type)
3700 return false;
3701
3702 return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
3703}
3704
3706 if (!type)
3707 return false;
3708 return RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef})
3709 ->getTypeClass() == clang::Type::Typedef;
3710}
3711
3713 if (!type)
3714 return false;
3715 return GetCanonicalQualType(type)->isVoidType();
3716}
3717
3719 if (auto *record_decl =
3721 return record_decl->canPassInRegisters();
3722 }
3723 return false;
3724}
3725
3727 return TypeSystemClangSupportsLanguage(language);
3728}
3729
3732 switch (language) {
3733 case LanguageType::eLanguageTypeC_plus_plus:
3734 case LanguageType::eLanguageTypeC_plus_plus_03:
3735 case LanguageType::eLanguageTypeC_plus_plus_11:
3736 case LanguageType::eLanguageTypeC_plus_plus_14:
3737 return ConstString("this");
3738 case LanguageType::eLanguageTypeObjC:
3739 case LanguageType::eLanguageTypeObjC_plus_plus:
3740 return ConstString("self");
3741 default:
3742 return {};
3743 }
3744}
3745
3746std::optional<std::string>
3748 if (!type)
3749 return std::nullopt;
3750
3751 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3752 if (qual_type.isNull())
3753 return std::nullopt;
3754
3755 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3756 if (!cxx_record_decl)
3757 return std::nullopt;
3758
3759 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3760}
3761
3763 if (!type)
3764 return false;
3765
3766 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3767 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr;
3768}
3769
3771 if (!type)
3772 return false;
3773 clang::QualType qual_type(GetCanonicalQualType(type));
3774 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3775 if (tag_type)
3776 return tag_type->isBeingDefined();
3777 return false;
3778}
3779
3781 CompilerType *class_type_ptr) {
3782 if (!ClangUtil::IsClangType(type))
3783 return false;
3784
3785 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3786
3787 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3788 if (class_type_ptr) {
3789 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3790 const clang::ObjCObjectPointerType *obj_pointer_type =
3791 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3792 if (obj_pointer_type == nullptr)
3793 class_type_ptr->Clear();
3794 else
3795 class_type_ptr->SetCompilerType(
3796 type.GetTypeSystem(),
3797 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3798 .getAsOpaquePtr());
3799 }
3800 }
3801 return true;
3802 }
3803 if (class_type_ptr)
3804 class_type_ptr->Clear();
3805 return false;
3806}
3807
3808// Type Completion
3809
3811 if (!type)
3812 return false;
3813 const bool allow_completion = true;
3815 allow_completion);
3816}
3817
3819 bool base_only) {
3820 if (!type)
3821 return ConstString();
3822
3823 clang::QualType qual_type(GetQualType(type));
3824
3825 // Remove certain type sugar from the name. Sugar such as elaborated types
3826 // or template types which only serve to improve diagnostics shouldn't
3827 // act as their own types from the user's perspective (e.g., formatter
3828 // shouldn't format a variable differently depending on how the ser has
3829 // specified the type. '::Type' and 'Type' should behave the same).
3830 // Typedefs and atomic derived types are not removed as they are actually
3831 // useful for identifiying specific types.
3832 qual_type = RemoveWrappingTypes(qual_type,
3833 {clang::Type::Typedef, clang::Type::Atomic});
3834
3835 // For a typedef just return the qualified name.
3836 if (const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3837 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3838 return ConstString(GetTypeNameForDecl(typedef_decl));
3839 }
3840
3841 // For consistency, this follows the same code path that clang uses to emit
3842 // debug info. This also handles when we don't want any scopes preceding the
3843 // name.
3844 if (auto *named_decl = qual_type->getAsTagDecl())
3845 return ConstString(GetTypeNameForDecl(named_decl, !base_only));
3846
3847 return ConstString(qual_type.getAsString(GetTypePrintingPolicy()));
3848}
3849
3852 if (!type)
3853 return ConstString();
3854
3855 clang::QualType qual_type(GetQualType(type));
3856 clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
3857 printing_policy.SuppressTagKeyword = true;
3858 printing_policy.SuppressScope = false;
3859 printing_policy.SuppressUnwrittenScope = true;
3860 printing_policy.SuppressInlineNamespace = true;
3861 return ConstString(qual_type.getAsString(printing_policy));
3862}
3863
3866 CompilerType *pointee_or_element_clang_type) {
3867 if (!type)
3868 return 0;
3869
3870 if (pointee_or_element_clang_type)
3871 pointee_or_element_clang_type->Clear();
3872
3873 clang::QualType qual_type =
3874 RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef});
3875
3876 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3877 switch (type_class) {
3878 case clang::Type::Attributed:
3879 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3880 ->getModifiedType()
3881 .getAsOpaquePtr(),
3882 pointee_or_element_clang_type);
3883 case clang::Type::Builtin: {
3884 const clang::BuiltinType *builtin_type =
3885 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3886
3887 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3888 switch (builtin_type->getKind()) {
3889 case clang::BuiltinType::ObjCId:
3890 case clang::BuiltinType::ObjCClass:
3891 if (pointee_or_element_clang_type)
3892 pointee_or_element_clang_type->SetCompilerType(
3893 weak_from_this(),
3894 getASTContext().ObjCBuiltinClassTy.getAsOpaquePtr());
3895 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3896 break;
3897
3898 case clang::BuiltinType::ObjCSel:
3899 if (pointee_or_element_clang_type)
3900 pointee_or_element_clang_type->SetCompilerType(
3901 weak_from_this(), getASTContext().CharTy.getAsOpaquePtr());
3902 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3903 break;
3904
3905 case clang::BuiltinType::Bool:
3906 case clang::BuiltinType::Char_U:
3907 case clang::BuiltinType::UChar:
3908 case clang::BuiltinType::WChar_U:
3909 case clang::BuiltinType::Char16:
3910 case clang::BuiltinType::Char32:
3911 case clang::BuiltinType::UShort:
3912 case clang::BuiltinType::UInt:
3913 case clang::BuiltinType::ULong:
3914 case clang::BuiltinType::ULongLong:
3915 case clang::BuiltinType::UInt128:
3916 case clang::BuiltinType::Char_S:
3917 case clang::BuiltinType::SChar:
3918 case clang::BuiltinType::WChar_S:
3919 case clang::BuiltinType::Short:
3920 case clang::BuiltinType::Int:
3921 case clang::BuiltinType::Long:
3922 case clang::BuiltinType::LongLong:
3923 case clang::BuiltinType::Int128:
3924 case clang::BuiltinType::Float:
3925 case clang::BuiltinType::Double:
3926 case clang::BuiltinType::LongDouble:
3927 builtin_type_flags |= eTypeIsScalar;
3928 if (builtin_type->isInteger()) {
3929 builtin_type_flags |= eTypeIsInteger;
3930 if (builtin_type->isSignedInteger())
3931 builtin_type_flags |= eTypeIsSigned;
3932 } else if (builtin_type->isFloatingPoint())
3933 builtin_type_flags |= eTypeIsFloat;
3934 break;
3935 default:
3936 break;
3937 }
3938 return builtin_type_flags;
3939 }
3940
3941 case clang::Type::BlockPointer:
3942 if (pointee_or_element_clang_type)
3943 pointee_or_element_clang_type->SetCompilerType(
3944 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3945 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3946
3947 case clang::Type::Complex: {
3948 uint32_t complex_type_flags =
3949 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3950 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3951 qual_type->getCanonicalTypeInternal());
3952 if (complex_type) {
3953 clang::QualType complex_element_type(complex_type->getElementType());
3954 if (complex_element_type->isIntegerType())
3955 complex_type_flags |= eTypeIsFloat;
3956 else if (complex_element_type->isFloatingType())
3957 complex_type_flags |= eTypeIsInteger;
3958 }
3959 return complex_type_flags;
3960 } break;
3961
3962 case clang::Type::ConstantArray:
3963 case clang::Type::DependentSizedArray:
3964 case clang::Type::IncompleteArray:
3965 case clang::Type::VariableArray:
3966 if (pointee_or_element_clang_type)
3967 pointee_or_element_clang_type->SetCompilerType(
3968 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3969 ->getElementType()
3970 .getAsOpaquePtr());
3971 return eTypeHasChildren | eTypeIsArray;
3972
3973 case clang::Type::DependentName:
3974 return 0;
3975 case clang::Type::DependentSizedExtVector:
3976 return eTypeHasChildren | eTypeIsVector;
3977 case clang::Type::DependentTemplateSpecialization:
3978 return eTypeIsTemplate;
3979
3980 case clang::Type::Enum:
3981 if (pointee_or_element_clang_type)
3982 pointee_or_element_clang_type->SetCompilerType(
3983 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3984 ->getDecl()
3985 ->getIntegerType()
3986 .getAsOpaquePtr());
3987 return eTypeIsEnumeration | eTypeHasValue;
3988
3989 case clang::Type::FunctionProto:
3990 return eTypeIsFuncPrototype | eTypeHasValue;
3991 case clang::Type::FunctionNoProto:
3992 return eTypeIsFuncPrototype | eTypeHasValue;
3993 case clang::Type::InjectedClassName:
3994 return 0;
3995
3996 case clang::Type::LValueReference:
3997 case clang::Type::RValueReference:
3998 if (pointee_or_element_clang_type)
3999 pointee_or_element_clang_type->SetCompilerType(
4000 weak_from_this(),
4001 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
4002 ->getPointeeType()
4003 .getAsOpaquePtr());
4004 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
4005
4006 case clang::Type::MemberPointer:
4007 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
4008
4009 case clang::Type::ObjCObjectPointer:
4010 if (pointee_or_element_clang_type)
4011 pointee_or_element_clang_type->SetCompilerType(
4012 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
4013 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
4014 eTypeHasValue;
4015
4016 case clang::Type::ObjCObject:
4017 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
4018 case clang::Type::ObjCInterface:
4019 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
4020
4021 case clang::Type::Pointer:
4022 if (pointee_or_element_clang_type)
4023 pointee_or_element_clang_type->SetCompilerType(
4024 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
4025 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
4026
4027 case clang::Type::Record:
4028 if (qual_type->getAsCXXRecordDecl())
4029 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
4030 else
4031 return eTypeHasChildren | eTypeIsStructUnion;
4032 break;
4033 case clang::Type::SubstTemplateTypeParm:
4034 return eTypeIsTemplate;
4035 case clang::Type::TemplateTypeParm:
4036 return eTypeIsTemplate;
4037 case clang::Type::TemplateSpecialization:
4038 return eTypeIsTemplate;
4039
4040 case clang::Type::Typedef:
4041 return eTypeIsTypedef | GetType(llvm::cast<clang::TypedefType>(qual_type)
4042 ->getDecl()
4043 ->getUnderlyingType())
4044 .GetTypeInfo(pointee_or_element_clang_type);
4045 case clang::Type::UnresolvedUsing:
4046 return 0;
4047
4048 case clang::Type::ExtVector:
4049 case clang::Type::Vector: {
4050 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4051 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
4052 qual_type->getCanonicalTypeInternal());
4053 if (vector_type) {
4054 if (vector_type->isIntegerType())
4055 vector_type_flags |= eTypeIsFloat;
4056 else if (vector_type->isFloatingType())
4057 vector_type_flags |= eTypeIsInteger;
4058 }
4059 return vector_type_flags;
4060 }
4061 default:
4062 return 0;
4063 }
4064 return 0;
4065}
4066
4069 if (!type)
4070 return lldb::eLanguageTypeC;
4071
4072 // If the type is a reference, then resolve it to what it refers to first:
4073 clang::QualType qual_type(GetCanonicalQualType(type).getNonReferenceType());
4074 if (qual_type->isAnyPointerType()) {
4075 if (qual_type->isObjCObjectPointerType())
4077 if (qual_type->getPointeeCXXRecordDecl())
4079
4080 clang::QualType pointee_type(qual_type->getPointeeType());
4081 if (pointee_type->getPointeeCXXRecordDecl())
4083 if (pointee_type->isObjCObjectOrInterfaceType())
4085 if (pointee_type->isObjCClassType())
4087 if (pointee_type.getTypePtr() ==
4088 getASTContext().ObjCBuiltinIdTy.getTypePtr())
4090 } else {
4091 if (qual_type->isObjCObjectOrInterfaceType())
4093 if (qual_type->getAsCXXRecordDecl())
4095 switch (qual_type->getTypeClass()) {
4096 default:
4097 break;
4098 case clang::Type::Builtin:
4099 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4100 default:
4101 case clang::BuiltinType::Void:
4102 case clang::BuiltinType::Bool:
4103 case clang::BuiltinType::Char_U:
4104 case clang::BuiltinType::UChar:
4105 case clang::BuiltinType::WChar_U:
4106 case clang::BuiltinType::Char16:
4107 case clang::BuiltinType::Char32:
4108 case clang::BuiltinType::UShort:
4109 case clang::BuiltinType::UInt:
4110 case clang::BuiltinType::ULong:
4111 case clang::BuiltinType::ULongLong:
4112 case clang::BuiltinType::UInt128:
4113 case clang::BuiltinType::Char_S:
4114 case clang::BuiltinType::SChar:
4115 case clang::BuiltinType::WChar_S:
4116 case clang::BuiltinType::Short:
4117 case clang::BuiltinType::Int:
4118 case clang::BuiltinType::Long:
4119 case clang::BuiltinType::LongLong:
4120 case clang::BuiltinType::Int128:
4121 case clang::BuiltinType::Float:
4122 case clang::BuiltinType::Double:
4123 case clang::BuiltinType::LongDouble:
4124 break;
4125
4126 case clang::BuiltinType::NullPtr:
4128
4129 case clang::BuiltinType::ObjCId:
4130 case clang::BuiltinType::ObjCClass:
4131 case clang::BuiltinType::ObjCSel:
4132 return eLanguageTypeObjC;
4133
4134 case clang::BuiltinType::Dependent:
4135 case clang::BuiltinType::Overload:
4136 case clang::BuiltinType::BoundMember:
4137 case clang::BuiltinType::UnknownAny:
4138 break;
4139 }
4140 break;
4141 case clang::Type::Typedef:
4142 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4143 ->getDecl()
4144 ->getUnderlyingType())
4146 }
4147 }
4148 return lldb::eLanguageTypeC;
4149}
4150
4151lldb::TypeClass
4153 if (!type)
4154 return lldb::eTypeClassInvalid;
4155
4156 clang::QualType qual_type =
4157 RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef});
4158
4159 switch (qual_type->getTypeClass()) {
4160 case clang::Type::Atomic:
4161 case clang::Type::Auto:
4162 case clang::Type::Decltype:
4163 case clang::Type::Elaborated:
4164 case clang::Type::Paren:
4165 case clang::Type::TypeOf:
4166 case clang::Type::TypeOfExpr:
4167 case clang::Type::Using:
4168 llvm_unreachable("Handled in RemoveWrappingTypes!");
4169 case clang::Type::UnaryTransform:
4170 break;
4171 case clang::Type::FunctionNoProto:
4172 return lldb::eTypeClassFunction;
4173 case clang::Type::FunctionProto:
4174 return lldb::eTypeClassFunction;
4175 case clang::Type::IncompleteArray:
4176 return lldb::eTypeClassArray;
4177 case clang::Type::VariableArray:
4178 return lldb::eTypeClassArray;
4179 case clang::Type::ConstantArray:
4180 return lldb::eTypeClassArray;
4181 case clang::Type::DependentSizedArray:
4182 return lldb::eTypeClassArray;
4183 case clang::Type::DependentSizedExtVector:
4184 return lldb::eTypeClassVector;
4185 case clang::Type::DependentVector:
4186 return lldb::eTypeClassVector;
4187 case clang::Type::ExtVector:
4188 return lldb::eTypeClassVector;
4189 case clang::Type::Vector:
4190 return lldb::eTypeClassVector;
4191 case clang::Type::Builtin:
4192 // Ext-Int is just an integer type.
4193 case clang::Type::BitInt:
4194 case clang::Type::DependentBitInt:
4195 return lldb::eTypeClassBuiltin;
4196 case clang::Type::ObjCObjectPointer:
4197 return lldb::eTypeClassObjCObjectPointer;
4198 case clang::Type::BlockPointer:
4199 return lldb::eTypeClassBlockPointer;
4200 case clang::Type::Pointer:
4201 return lldb::eTypeClassPointer;
4202 case clang::Type::LValueReference:
4203 return lldb::eTypeClassReference;
4204 case clang::Type::RValueReference:
4205 return lldb::eTypeClassReference;
4206 case clang::Type::MemberPointer:
4207 return lldb::eTypeClassMemberPointer;
4208 case clang::Type::Complex:
4209 if (qual_type->isComplexType())
4210 return lldb::eTypeClassComplexFloat;
4211 else
4212 return lldb::eTypeClassComplexInteger;
4213 case clang::Type::ObjCObject:
4214 return lldb::eTypeClassObjCObject;
4215 case clang::Type::ObjCInterface:
4216 return lldb::eTypeClassObjCInterface;
4217 case clang::Type::Record: {
4218 const clang::RecordType *record_type =
4219 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4220 const clang::RecordDecl *record_decl = record_type->getDecl();
4221 if (record_decl->isUnion())
4222 return lldb::eTypeClassUnion;
4223 else if (record_decl->isStruct())
4224 return lldb::eTypeClassStruct;
4225 else
4226 return lldb::eTypeClassClass;
4227 } break;
4228 case clang::Type::Enum:
4229 return lldb::eTypeClassEnumeration;
4230 case clang::Type::Typedef:
4231 return lldb::eTypeClassTypedef;
4232 case clang::Type::UnresolvedUsing:
4233 break;
4234
4235 case clang::Type::Attributed:
4236 case clang::Type::BTFTagAttributed:
4237 break;
4238 case clang::Type::TemplateTypeParm:
4239 break;
4240 case clang::Type::SubstTemplateTypeParm:
4241 break;
4242 case clang::Type::SubstTemplateTypeParmPack:
4243 break;
4244 case clang::Type::InjectedClassName:
4245 break;
4246 case clang::Type::DependentName:
4247 break;
4248 case clang::Type::DependentTemplateSpecialization:
4249 break;
4250 case clang::Type::PackExpansion:
4251 break;
4252
4253 case clang::Type::TemplateSpecialization:
4254 break;
4255 case clang::Type::DeducedTemplateSpecialization:
4256 break;
4257 case clang::Type::Pipe:
4258 break;
4259
4260 // pointer type decayed from an array or function type.
4261 case clang::Type::Decayed:
4262 break;
4263 case clang::Type::Adjusted:
4264 break;
4265 case clang::Type::ObjCTypeParam:
4266 break;
4267
4268 case clang::Type::DependentAddressSpace:
4269 break;
4270 case clang::Type::MacroQualified:
4271 break;
4272
4273 // Matrix types that we're not sure how to display at the moment.
4274 case clang::Type::ConstantMatrix:
4275 case clang::Type::DependentSizedMatrix:
4276 break;
4277 }
4278 // We don't know hot to display this type...
4279 return lldb::eTypeClassOther;
4280}
4281
4283 if (type)
4284 return GetQualType(type).getQualifiers().getCVRQualifiers();
4285 return 0;
4286}
4287
4288// Creating related types
4289
4292 ExecutionContextScope *exe_scope) {
4293 if (type) {
4294 clang::QualType qual_type(GetQualType(type));
4295
4296 const clang::Type *array_eletype =
4297 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4298
4299 if (!array_eletype)
4300 return CompilerType();
4301
4302 return GetType(clang::QualType(array_eletype, 0));
4303 }
4304 return CompilerType();
4305}
4306
4308 uint64_t size) {
4309 if (type) {
4310 clang::QualType qual_type(GetCanonicalQualType(type));
4311 clang::ASTContext &ast_ctx = getASTContext();
4312 if (size != 0)
4313 return GetType(ast_ctx.getConstantArrayType(
4314 qual_type, llvm::APInt(64, size), nullptr,
4315 clang::ArrayType::ArraySizeModifier::Normal, 0));
4316 else
4317 return GetType(ast_ctx.getIncompleteArrayType(
4318 qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0));
4319 }
4320
4321 return CompilerType();
4322}
4323
4326 if (type)
4327 return GetType(GetCanonicalQualType(type));
4328 return CompilerType();
4329}
4330
4331static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast,
4332 clang::QualType qual_type) {
4333 if (qual_type->isPointerType())
4334 qual_type = ast->getPointerType(
4335 GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
4336 else if (const ConstantArrayType *arr =
4337 ast->getAsConstantArrayType(qual_type)) {
4338 qual_type = ast->getConstantArrayType(
4339 GetFullyUnqualifiedType_Impl(ast, arr->getElementType()),
4340 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4341 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4342 } else
4343 qual_type = qual_type.getUnqualifiedType();
4344 qual_type.removeLocalConst();
4345 qual_type.removeLocalRestrict();
4346 qual_type.removeLocalVolatile();
4347 return qual_type;
4348}
4349
4352 if (type)
4353 return GetType(
4355 return CompilerType();
4356}
4357
4360 if (type)
4362 return CompilerType();
4363}
4364
4367 if (type) {
4368 const clang::FunctionProtoType *func =
4369 llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type));
4370 if (func)
4371 return func->getNumParams();
4372 }
4373 return -1;
4374}
4375
4377 lldb::opaque_compiler_type_t type, size_t idx) {
4378 if (type) {
4379 const clang::FunctionProtoType *func =
4380 llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type));
4381 if (func) {
4382 const uint32_t num_args = func->getNumParams();
4383 if (idx < num_args)
4384 return GetType(func->getParamType(idx));
4385 }
4386 }
4387 return CompilerType();
4388}
4389
4392 if (type) {
4393 clang::QualType qual_type(GetQualType(type));
4394 const clang::FunctionProtoType *func =
4395 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4396 if (func)
4397 return GetType(func->getReturnType());
4398 }
4399 return CompilerType();
4400}
4401
4402size_t
4404 size_t num_functions = 0;
4405 if (type) {
4406 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4407 switch (qual_type->getTypeClass()) {
4408 case clang::Type::Record:
4409 if (GetCompleteQualType(&getASTContext(), qual_type)) {
4410 const clang::RecordType *record_type =
4411 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4412 const clang::RecordDecl *record_decl = record_type->getDecl();
4413 assert(record_decl);
4414 const clang::CXXRecordDecl *cxx_record_decl =
4415 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4416 if (cxx_record_decl)
4417 num_functions = std::distance(cxx_record_decl->method_begin(),
4418 cxx_record_decl->method_end());
4419 }
4420 break;
4421
4422 case clang::Type::ObjCObjectPointer: {
4423 const clang::ObjCObjectPointerType *objc_class_type =
4424 qual_type->castAs<clang::ObjCObjectPointerType>();
4425 const clang::ObjCInterfaceType *objc_interface_type =
4426 objc_class_type->getInterfaceType();
4427 if (objc_interface_type &&
4429 const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) {
4430 clang::ObjCInterfaceDecl *class_interface_decl =
4431 objc_interface_type->getDecl();
4432 if (class_interface_decl) {
4433 num_functions = std::distance(class_interface_decl->meth_begin(),
4434 class_interface_decl->meth_end());
4435 }
4436 }
4437 break;
4438 }
4439
4440 case clang::Type::ObjCObject:
4441 case clang::Type::ObjCInterface:
4442 if (GetCompleteType(type)) {
4443 const clang::ObjCObjectType *objc_class_type =
4444 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4445 if (objc_class_type) {
4446 clang::ObjCInterfaceDecl *class_interface_decl =
4447 objc_class_type->getInterface();
4448 if (class_interface_decl)
4449 num_functions = std::distance(class_interface_decl->meth_begin(),
4450 class_interface_decl->meth_end());
4451 }
4452 }
4453 break;
4454
4455 default:
4456 break;
4457 }
4458 }
4459 return num_functions;
4460}
4461
4464 size_t idx) {
4465 std::string name;
4466 MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown);
4467 CompilerType clang_type;
4468 CompilerDecl clang_decl;
4469 if (type) {
4470 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4471 switch (qual_type->getTypeClass()) {
4472 case clang::Type::Record:
4473 if (GetCompleteQualType(&getASTContext(), qual_type)) {
4474 const clang::RecordType *record_type =
4475 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4476 const clang::RecordDecl *record_decl = record_type->getDecl();
4477 assert(record_decl);
4478 const clang::CXXRecordDecl *cxx_record_decl =
4479 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4480 if (cxx_record_decl) {
4481 auto method_iter = cxx_record_decl->method_begin();
4482 auto method_end = cxx_record_decl->method_end();
4483 if (idx <
4484 static_cast<size_t>(std::distance(method_iter, method_end))) {
4485 std::advance(method_iter, idx);
4486 clang::CXXMethodDecl *cxx_method_decl =
4487 method_iter->getCanonicalDecl();
4488 if (cxx_method_decl) {
4489 name = cxx_method_decl->getDeclName().getAsString();
4490 if (cxx_method_decl->isStatic())
4492 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4494 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4496 else
4498 clang_type = GetType(cxx_method_decl->getType());
4499 clang_decl = GetCompilerDecl(cxx_method_decl);
4500 }
4501 }
4502 }
4503 }
4504 break;
4505
4506 case clang::Type::ObjCObjectPointer: {
4507 const clang::ObjCObjectPointerType *objc_class_type =
4508 qual_type->castAs<clang::ObjCObjectPointerType>();
4509 const clang::ObjCInterfaceType *objc_interface_type =
4510 objc_class_type->getInterfaceType();
4511 if (objc_interface_type &&
4513 const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) {
4514 clang::ObjCInterfaceDecl *class_interface_decl =
4515 objc_interface_type->getDecl();
4516 if (class_interface_decl) {
4517 auto method_iter = class_interface_decl->meth_begin();
4518 auto method_end = class_interface_decl->meth_end();
4519 if (idx <
4520 static_cast<size_t>(std::distance(method_iter, method_end))) {
4521 std::advance(method_iter, idx);
4522 clang::ObjCMethodDecl *objc_method_decl =
4523 method_iter->getCanonicalDecl();
4524 if (objc_method_decl) {
4525 clang_decl = GetCompilerDecl(objc_method_decl);
4526 name = objc_method_decl->getSelector().getAsString();
4527 if (objc_method_decl->isClassMethod())
4529 else
4531 }
4532 }
4533 }
4534 }
4535 break;
4536 }
4537
4538 case clang::Type::ObjCObject:
4539 case clang::Type::ObjCInterface:
4540 if (GetCompleteType(type)) {
4541 const clang::ObjCObjectType *objc_class_type =
4542 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4543 if (objc_class_type) {
4544 clang::ObjCInterfaceDecl *class_interface_decl =
4545 objc_class_type->getInterface();
4546 if (class_interface_decl) {
4547 auto method_iter = class_interface_decl->meth_begin();
4548 auto method_end = class_interface_decl->meth_end();
4549 if (idx <
4550 static_cast<size_t>(std::distance(method_iter, method_end))) {
4551 std::advance(method_iter, idx);
4552 clang::ObjCMethodDecl *objc_method_decl =
4553 method_iter->getCanonicalDecl();
4554 if (objc_method_decl) {
4555 clang_decl = GetCompilerDecl(objc_method_decl);
4556 name = objc_method_decl->getSelector().getAsString();
4557 if (objc_method_decl->isClassMethod())
4559 else
4561 }
4562 }
4563 }
4564 }
4565 }
4566 break;
4567
4568 default:
4569 break;
4570 }
4571 }
4572
4573 if (kind == eMemberFunctionKindUnknown)
4574 return TypeMemberFunctionImpl();
4575 else
4576 return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind);
4577}
4578
4581 if (type)
4582 return GetType(GetQualType(type).getNonReferenceType());
4583 return CompilerType();
4584}
4585
4588 if (type) {
4589 clang::QualType qual_type(GetQualType(type));
4590 return GetType(qual_type.getTypePtr()->getPointeeType());
4591 }
4592 return CompilerType();
4593}
4594
4597 if (type) {
4598 clang::QualType qual_type(GetQualType(type));
4599
4600 switch (qual_type.getDesugaredType(getASTContext())->getTypeClass()) {
4601 case clang::Type::ObjCObject:
4602 case clang::Type::ObjCInterface:
4603 return GetType(getASTContext().getObjCObjectPointerType(qual_type));
4604
4605 default:
4606 return GetType(getASTContext().getPointerType(qual_type));
4607 }
4608 }
4609 return CompilerType();
4610}
4611
4614 if (type)
4615 return GetType(getASTContext().getLValueReferenceType(GetQualType(type)));
4616 else
4617 return CompilerType();
4618}
4619
4622 if (type)
4623 return GetType(getASTContext().getRValueReferenceType(GetQualType(type)));
4624 else
4625 return CompilerType();
4626}
4627
4629 if (!type)
4630 return CompilerType();
4631 return GetType(getASTContext().getAtomicType(GetQualType(type)));
4632}
4633
4636 if (type) {
4637 clang::QualType result(GetQualType(type));
4638 result.addConst();
4639 return GetType(result);
4640 }
4641 return CompilerType();
4642}
4643
4646 if (type) {
4647 clang::QualType result(GetQualType(type));
4648 result.addVolatile();
4649 return GetType(result);
4650 }
4651 return CompilerType();
4652}
4653
4656 if (type) {
4657 clang::QualType result(GetQualType(type));
4658 result.addRestrict();
4659 return GetType(result);
4660 }
4661 return CompilerType();
4662}
4663
4665 lldb::opaque_compiler_type_t type, const char *typedef_name,
4666 const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) {
4667 if (type && typedef_name && typedef_name[0]) {
4668 clang::ASTContext &clang_ast = getASTContext();
4669 clang::QualType qual_type(GetQualType(type));
4670
4671 clang::DeclContext *decl_ctx =
4673 if (!decl_ctx)
4674 decl_ctx = getASTContext().getTranslationUnitDecl();
4675
4676 clang::TypedefDecl *decl =
4677 clang::TypedefDecl::CreateDeserialized(clang_ast, 0);
4678 decl->setDeclContext(decl_ctx);
4679 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4680 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4681 decl_ctx->addDecl(decl);
4682 SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule());
4683
4684 clang::TagDecl *tdecl = nullptr;
4685 if (!qual_type.isNull()) {
4686 if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4687 tdecl = rt->getDecl();
4688 if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4689 tdecl = et->getDecl();
4690 }
4691
4692 // Check whether this declaration is an anonymous struct, union, or enum,
4693 // hidden behind a typedef. If so, we try to check whether we have a
4694 // typedef tag to attach to the original record declaration
4695 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4696 tdecl->setTypedefNameForAnonDecl(decl);
4697
4698 decl->setAccess(clang::AS_public); // TODO respect proper access specifier
4699
4700 // Get a uniqued clang::QualType for the typedef decl type
4701 return GetType(clang_ast.getTypedefType(decl));
4702 }
4703 return CompilerType();
4704}
4705
4708 if (type) {
4709 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4710 RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef}));
4711 if (typedef_type)
4712 return GetType(typedef_type->getDecl()->getUnderlyingType());
4713 }
4714 return CompilerType();
4715}
4716
4717// Create related types using the current type's AST
4718
4720 return TypeSystemClang::GetBasicType(basic_type);
4721}
4722// Exploring the type
4723
4724const llvm::fltSemantics &
4726 clang::ASTContext &ast = getASTContext();
4727 const size_t bit_size = byte_size * 8;
4728 if (bit_size == ast.getTypeSize(ast.FloatTy))
4729 return ast.getFloatTypeSemantics(ast.FloatTy);
4730 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4731 return ast.getFloatTypeSemantics(ast.DoubleTy);
4732 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4733 bit_size == llvm::APFloat::semanticsSizeInBits(
4734 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4735 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4736 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4737 return ast.getFloatTypeSemantics(ast.HalfTy);
4738 return llvm::APFloatBase::Bogus();
4739}
4740
4741std::optional<uint64_t>
4743 ExecutionContextScope *exe_scope) {
4744 if (GetCompleteType(type)) {
4745 clang::QualType qual_type(GetCanonicalQualType(type));
4746 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4747 switch (type_class) {
4748 case clang::Type::Record:
4749 if (GetCompleteType(type))
4750 return getASTContext().getTypeSize(qual_type);
4751 else
4752 return std::nullopt;
4753 break;
4754
4755 case clang::Type::ObjCInterface:
4756 case clang::Type::ObjCObject: {
4757 ExecutionContext exe_ctx(exe_scope);
4758 Process *process = exe_ctx.GetProcessPtr();
4759 if (process) {
4760 ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
4761 if (objc_runtime) {
4762 uint64_t bit_size = 0;
4763 if (objc_runtime->GetTypeBitSize(GetType(qual_type), bit_size))
4764 return bit_size;
4765 }
4766 } else {
4767 static bool g_printed = false;
4768 if (!g_printed) {
4769 StreamString s;
4770 DumpTypeDescription(type, &s);
4771
4772 llvm::outs() << "warning: trying to determine the size of type ";
4773 llvm::outs() << s.GetString() << "\n";
4774 llvm::outs() << "without a valid ExecutionContext. this is not "
4775 "reliable. please file a bug against LLDB.\n";
4776 llvm::outs() << "backtrace:\n";
4777 llvm::sys::PrintStackTrace(llvm::outs());
4778 llvm::outs() << "\n";
4779 g_printed = true;
4780 }
4781 }
4782 }
4783 [[fallthrough]];
4784 default:
4785 const uint32_t bit_size = getASTContext().getTypeSize(qual_type);
4786 if (bit_size == 0) {
4787 if (qual_type->isIncompleteArrayType())
4788 return getASTContext().getTypeSize(
4789 qual_type->getArrayElementTypeNoTypeQual()
4790 ->getCanonicalTypeUnqualified());
4791 }
4792 if (qual_type->isObjCObjectOrInterfaceType())
4793 return bit_size +
4794 getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy);
4795 // Function types actually have a size of 0, that's not an error.
4796 if (qual_type->isFunctionProtoType())
4797 return bit_size;
4798 if (bit_size)
4799 return bit_size;
4800 }
4801 }
4802 return std::nullopt;
4803}
4804
4805std::optional<size_t>
4807 ExecutionContextScope *exe_scope) {
4808 if (GetCompleteType(type))
4809 return getASTContext().getTypeAlign(GetQualType(type));
4810 return {};
4811}
4812
4814 uint64_t &count) {
4815 if (!type)
4817
4818 count = 1;
4819 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
4820
4821 switch (qual_type->getTypeClass()) {
4822 case clang::Type::Atomic:
4823 case clang::Type::Auto:
4824 case clang::Type::Decltype:
4825 case clang::Type::Elaborated:
4826 case clang::Type::Paren:
4827 case clang::Type::Typedef:
4828 case clang::Type::TypeOf:
4829 case clang::Type::TypeOfExpr:
4830 case clang::Type::Using:
4831 llvm_unreachable("Handled in RemoveWrappingTypes!");
4832
4833 case clang::Type::UnaryTransform:
4834 break;
4835
4836 case clang::Type::FunctionNoProto:
4837 case clang::Type::FunctionProto:
4838 break;
4839
4840 case clang::Type::IncompleteArray:
4841 case clang::Type::VariableArray:
4842 break;
4843
4844 case clang::Type::ConstantArray:
4845 break;
4846
4847 case clang::Type::DependentVector:
4848 case clang::Type::ExtVector:
4849 case clang::Type::Vector:
4850 // TODO: Set this to more than one???
4851 break;
4852
4853 case clang::Type::BitInt:
4854 case clang::Type::DependentBitInt:
4855 return qual_type->isUnsignedIntegerType() ? lldb::eEncodingUint
4857
4858 case clang::Type::Builtin:
4859 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4860 case clang::BuiltinType::Void:
4861 break;
4862
4863 case clang::BuiltinType::Char_S:
4864 case clang::BuiltinType::SChar:
4865 case clang::BuiltinType::WChar_S:
4866 case clang::BuiltinType::Short:
4867 case clang::BuiltinType::Int:
4868 case clang::BuiltinType::Long:
4869 case clang::BuiltinType::LongLong:
4870 case clang::BuiltinType::Int128:
4871 return lldb::eEncodingSint;
4872
4873 case clang::BuiltinType::Bool:
4874 case clang::BuiltinType::Char_U:
4875 case clang::BuiltinType::UChar:
4876 case clang::BuiltinType::WChar_U:
4877 case clang::BuiltinType::Char8:
4878 case clang::BuiltinType::Char16:
4879 case clang::BuiltinType::Char32:
4880 case clang::BuiltinType::UShort:
4881 case clang::BuiltinType::UInt:
4882 case clang::BuiltinType::ULong:
4883 case clang::BuiltinType::ULongLong:
4884 case clang::BuiltinType::UInt128:
4885 return lldb::eEncodingUint;
4886
4887 // Fixed point types. Note that they are currently ignored.
4888 case clang::BuiltinType::ShortAccum:
4889 case clang::BuiltinType::Accum:
4890 case clang::BuiltinType::LongAccum:
4891 case clang::BuiltinType::UShortAccum:
4892 case clang::BuiltinType::UAccum:
4893 case clang::BuiltinType::ULongAccum:
4894 case clang::BuiltinType::ShortFract:
4895 case clang::BuiltinType::Fract:
4896 case clang::BuiltinType::LongFract:
4897 case clang::BuiltinType::UShortFract:
4898 case clang::BuiltinType::UFract:
4899 case clang::BuiltinType::ULongFract:
4900 case clang::BuiltinType::SatShortAccum:
4901 case clang::BuiltinType::SatAccum:
4902 case clang::BuiltinType::SatLongAccum:
4903 case clang::BuiltinType::SatUShortAccum:
4904 case clang::BuiltinType::SatUAccum:
4905 case clang::BuiltinType::SatULongAccum:
4906 case clang::BuiltinType::SatShortFract:
4907 case clang::BuiltinType::SatFract:
4908 case clang::BuiltinType::SatLongFract:
4909 case clang::BuiltinType::SatUShortFract:
4910 case clang::BuiltinType::SatUFract:
4911 case clang::BuiltinType::SatULongFract:
4912 break;
4913
4914 case clang::BuiltinType::Half:
4915 case clang::BuiltinType::Float:
4916 case clang::BuiltinType::Float16:
4917 case clang::BuiltinType::Float128:
4918 case clang::BuiltinType::Double:
4919 case clang::BuiltinType::LongDouble:
4920 case clang::BuiltinType::BFloat16:
4921 case clang::BuiltinType::Ibm128:
4923
4924 case clang::BuiltinType::ObjCClass:
4925 case clang::BuiltinType::ObjCId:
4926 case clang::BuiltinType::ObjCSel:
4927 return lldb::eEncodingUint;
4928
4929 case clang::BuiltinType::NullPtr:
4930 return lldb::eEncodingUint;
4931
4932 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4933 case clang::BuiltinType::Kind::BoundMember:
4934 case clang::BuiltinType::Kind::BuiltinFn:
4935 case clang::BuiltinType::Kind::Dependent:
4936 case clang::BuiltinType::Kind::OCLClkEvent:
4937 case clang::BuiltinType::Kind::OCLEvent:
4938 case clang::BuiltinType::Kind::OCLImage1dRO:
4939 case clang::BuiltinType::Kind::OCLImage1dWO:
4940 case clang::BuiltinType::Kind::OCLImage1dRW:
4941 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4942 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4943 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4944 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4945 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4946 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4947 case clang::BuiltinType::Kind::OCLImage2dRO:
4948 case clang::BuiltinType::Kind::OCLImage2dWO:
4949 case clang::BuiltinType::Kind::OCLImage2dRW:
4950 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4951 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4952 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4953 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4954 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4955 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4956 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4957 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4958 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4959 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4960 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4961 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4962 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4963 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4964 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4965 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4966 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4967 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4968 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4969 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4970 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4971 case clang::BuiltinType::Kind::OCLImage3dRO:
4972 case clang::BuiltinType::Kind::OCLImage3dWO:
4973 case clang::BuiltinType::Kind::OCLImage3dRW:
4974 case clang::BuiltinType::Kind::OCLQueue:
4975 case clang::BuiltinType::Kind::OCLReserveID:
4976 case clang::BuiltinType::Kind::OCLSampler:
4977 case clang::BuiltinType::Kind::OMPArraySection:
4978 case clang::BuiltinType::Kind::OMPArrayShaping:
4979 case clang::BuiltinType::Kind::OMPIterator:
4980 case clang::BuiltinType::Kind::Overload:
4981 case clang::BuiltinType::Kind::PseudoObject:
4982 case clang::BuiltinType::Kind::UnknownAny:
4983 break;
4984
4985 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4986 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4987 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4988 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4989 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4990 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4991 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4992 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4993 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4994 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4995 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4996 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4997 break;
4998
4999 // PowerPC -- Matrix Multiply Assist
5000 case clang::BuiltinType::VectorPair:
5001 case clang::BuiltinType::VectorQuad:
5002 break;
5003
5004 // ARM -- Scalable Vector Extension
5005 case clang::BuiltinType::SveBool:
5006 case clang::BuiltinType::SveBoolx2:
5007 case clang::BuiltinType::SveBoolx4:
5008 case clang::BuiltinType::SveCount:
5009 case clang::BuiltinType::SveInt8:
5010 case clang::BuiltinType::SveInt8x2:
5011 case clang::BuiltinType::SveInt8x3:
5012 case clang::BuiltinType::SveInt8x4:
5013 case clang::BuiltinType::SveInt16:
5014 case clang::BuiltinType::SveInt16x2:
5015 case clang::BuiltinType::SveInt16x3:
5016 case clang::BuiltinType::SveInt16x4:
5017 case clang::BuiltinType::SveInt32:
5018 case clang::BuiltinType::SveInt32x2:
5019 case clang::BuiltinType::SveInt32x3:
5020 case clang::BuiltinType::SveInt32x4:
5021 case clang::BuiltinType::SveInt64:
5022 case clang::BuiltinType::SveInt64x2:
5023 case clang::BuiltinType::SveInt64x3:
5024 case clang::BuiltinType::SveInt64x4:
5025 case clang::BuiltinType::SveUint8:
5026 case clang::BuiltinType::SveUint8x2:
5027 case clang::BuiltinType::SveUint8x3:
5028 case clang::BuiltinType::SveUint8x4:
5029 case clang::BuiltinType::SveUint16:
5030 case clang::BuiltinType::SveUint16x2:
5031 case clang::BuiltinType::SveUint16x3:
5032 case clang::BuiltinType::SveUint16x4:
5033 case clang::BuiltinType::SveUint32:
5034 case clang::BuiltinType::SveUint32x2:
5035 case clang::BuiltinType::SveUint32x3:
5036 case clang::BuiltinType::SveUint32x4:
5037 case clang::BuiltinType::SveUint64:
5038 case clang::BuiltinType::SveUint64x2:
5039 case clang::BuiltinType::SveUint64x3:
5040 case clang::BuiltinType::SveUint64x4:
5041 case clang::BuiltinType::SveFloat16:
5042 case clang::BuiltinType::SveBFloat16:
5043 case clang::BuiltinType::SveBFloat16x2:
5044 case clang::BuiltinType::SveBFloat16x3:
5045 case clang::BuiltinType::SveBFloat16x4:
5046 case clang::BuiltinType::SveFloat16x2:
5047 case clang::BuiltinType::SveFloat16x3:
5048 case clang::BuiltinType::SveFloat16x4:
5049 case clang::BuiltinType::SveFloat32:
5050 case clang::BuiltinType::SveFloat32x2:
5051 case clang::BuiltinType::SveFloat32x3:
5052 case clang::BuiltinType::SveFloat32x4:
5053 case clang::BuiltinType::SveFloat64:
5054 case clang::BuiltinType::SveFloat64x2:
5055 case clang::BuiltinType::SveFloat64x3:
5056 case clang::BuiltinType::SveFloat64x4:
5057 break;
5058
5059 // RISC-V V builtin types.
5060 case clang::BuiltinType::RvvInt8mf8:
5061 case clang::BuiltinType::RvvInt8mf4:
5062 case clang::BuiltinType::RvvInt8mf2:
5063 case clang::BuiltinType::RvvInt8m1:
5064 case clang::BuiltinType::RvvInt8m2:
5065 case clang::BuiltinType::RvvInt8m4:
5066 case clang::BuiltinType::RvvInt8m8:
5067 case clang::BuiltinType::RvvUint8mf8:
5068 case clang::BuiltinType::RvvUint8mf4:
5069 case clang::BuiltinType::RvvUint8mf2:
5070 case clang::BuiltinType::RvvUint8m1:
5071 case clang::BuiltinType::RvvUint8m2:
5072 case clang::BuiltinType::RvvUint8m4:
5073 case clang::BuiltinType::RvvUint8m8:
5074 case clang::BuiltinType::RvvInt16mf4:
5075 case clang::BuiltinType::RvvInt16mf2:
5076 case clang::BuiltinType::RvvInt16m1:
5077 case clang::BuiltinType::RvvInt16m2:
5078 case clang::BuiltinType::RvvInt16m4:
5079 case clang::BuiltinType::RvvInt16m8:
5080 case clang::BuiltinType::RvvUint16mf4:
5081 case clang::BuiltinType::RvvUint16mf2:
5082 case clang::BuiltinType::RvvUint16m1:
5083 case clang::BuiltinType::RvvUint16m2:
5084 case clang::BuiltinType::RvvUint16m4:
5085 case clang::BuiltinType::RvvUint16m8:
5086 case clang::BuiltinType::RvvInt32mf2:
5087 case clang::BuiltinType::RvvInt32m1:
5088 case clang::BuiltinType::RvvInt32m2:
5089 case clang::BuiltinType::RvvInt32m4:
5090 case clang::BuiltinType::RvvInt32m8:
5091 case clang::BuiltinType::RvvUint32mf2:
5092 case clang::BuiltinType::RvvUint32m1:
5093 case clang::BuiltinType::RvvUint32m2:
5094 case clang::BuiltinType::RvvUint32m4:
5095 case clang::BuiltinType::RvvUint32m8:
5096 case clang::BuiltinType::RvvInt64m1:
5097 case clang::BuiltinType::RvvInt64m2:
5098 case clang::BuiltinType::RvvInt64m4:
5099 case clang::BuiltinType::RvvInt64m8:
5100 case clang::BuiltinType::RvvUint64m1:
5101 case clang::BuiltinType::RvvUint64m2:
5102 case clang::BuiltinType::RvvUint64m4:
5103 case clang::BuiltinType::RvvUint64m8:
5104 case clang::BuiltinType::RvvFloat16mf4:
5105 case clang::BuiltinType::RvvFloat16mf2:
5106 case clang::BuiltinType::RvvFloat16m1:
5107 case clang::BuiltinType::RvvFloat16m2:
5108 case clang::BuiltinType::RvvFloat16m4:
5109 case clang::BuiltinType::RvvFloat16m8:
5110 case clang::BuiltinType::RvvFloat32mf2:
5111 case clang::BuiltinType::RvvFloat32m1:
5112 case clang::BuiltinType::RvvFloat32m2:
5113 case clang::BuiltinType::RvvFloat32m4:
5114 case clang::BuiltinType::RvvFloat32m8:
5115 case clang::BuiltinType::RvvFloat64m1:
5116 case clang::BuiltinType::RvvFloat64m2:
5117 case clang::BuiltinType::RvvFloat64m4:
5118 case clang::BuiltinType::RvvFloat64m8:
5119 case clang::BuiltinType::RvvBool1:
5120 case clang::BuiltinType::RvvBool2:
5121 case clang::BuiltinType::RvvBool4:
5122 case clang::BuiltinType::RvvBool8:
5123 case clang::BuiltinType::RvvBool16:
5124 case clang::BuiltinType::RvvBool32:
5125 case clang::BuiltinType::RvvBool64:
5126 break;
5127
5128 // WebAssembly builtin types.
5129 case clang::BuiltinType::WasmExternRef:
5130 break;
5131
5132 case clang::BuiltinType::IncompleteMatrixIdx:
5133 break;
5134 }
5135 break;
5136 // All pointer types are represented as unsigned integer encodings. We may
5137 // nee to add a eEncodingPointer if we ever need to know the difference
5138 case clang::Type::ObjCObjectPointer:
5139 case clang::Type::BlockPointer:
5140 case clang::Type::Pointer:
5141 case clang::Type::LValueReference:
5142 case clang::Type::RValueReference:
5143 case clang::Type::MemberPointer:
5144 return lldb::eEncodingUint;
5145 case clang::Type::Complex: {
5147 if (qual_type->isComplexType())
5148 encoding = lldb::eEncodingIEEE754;
5149 else {
5150 const clang::ComplexType *complex_type =
5151 qual_type->getAsComplexIntegerType();
5152 if (complex_type)
5153 encoding = GetType(complex_type->getElementType()).GetEncoding(count);
5154 else
5155 encoding = lldb::eEncodingSint;
5156 }
5157 count = 2;
5158 return encoding;
5159 }
5160
5161 case clang::Type::ObjCInterface:
5162 break;
5163 case clang::Type::Record:
5164 break;
5165 case clang::Type::Enum:
5166 return qual_type->isUnsignedIntegerOrEnumerationType()
5169 case clang::Type::DependentSizedArray:
5170 case clang::Type::DependentSizedExtVector:
5171 case clang::Type::UnresolvedUsing:
5172 case clang::Type::Attributed:
5173 case clang::Type::BTFTagAttributed:
5174 case clang::Type::TemplateTypeParm:
5175 case clang::Type::SubstTemplateTypeParm:
5176 case clang::Type::SubstTemplateTypeParmPack:
5177 case clang::Type::InjectedClassName:
5178 case clang::Type::DependentName:
5179 case clang::Type::DependentTemplateSpecialization:
5180 case clang::Type::PackExpansion:
5181 case clang::Type::ObjCObject:
5182
5183 case clang::Type::TemplateSpecialization:
5184 case clang::Type::DeducedTemplateSpecialization:
5185 case clang::Type::Adjusted:
5186 case clang::Type::Pipe:
5187 break;
5188
5189 // pointer type decayed from an array or function type.
5190 case clang::Type::Decayed:
5191 break;
5192 case clang::Type::ObjCTypeParam:
5193 break;
5194
5195 case clang::Type::DependentAddressSpace:
5196 break;
5197 case clang::Type::MacroQualified:
5198 break;
5199
5200 case clang::Type::ConstantMatrix:
5201 case clang::Type::DependentSizedMatrix:
5202 break;
5203 }
5204 count = 0;
5206}
5207
5209 if (!type)
5210 return lldb::eFormatDefault;
5211
5212 clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
5213
5214 switch (qual_type->getTypeClass()) {
5215 case clang::Type::Atomic:
5216 case clang::Type::Auto:
5217 case clang::Type::Decltype:
5218 case clang::Type::Elaborated:
5219 case clang::Type::Paren:
5220 case clang::Type::Typedef:
5221 case clang::Type::TypeOf:
5222 case clang::Type::TypeOfExpr:
5223 case clang::Type::Using:
5224 llvm_unreachable("Handled in RemoveWrappingTypes!");
5225 case clang::Type::UnaryTransform:
5226 break;
5227
5228 case clang::Type::FunctionNoProto:
5229 case clang::Type::FunctionProto:
5230 break;
5231
5232 case clang::Type::IncompleteArray:
5233 case clang::Type::VariableArray:
5234 break;
5235
5236 case clang::Type::ConstantArray:
5237 return lldb::eFormatVoid; // no value
5238
5239 case clang::Type::DependentVector:
5240 case clang::Type::ExtVector:
5241 case clang::Type::Vector:
5242 break;
5243
5244 case clang::Type::BitInt:
5245 case clang::Type::DependentBitInt:
5246 return qual_type->isUnsignedIntegerType() ? lldb::eFormatUnsigned
5248
5249 case clang::Type::Builtin:
5250 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5251 case clang::BuiltinType::UnknownAny:
5252 case clang::BuiltinType::Void:
5253 case clang::BuiltinType::BoundMember:
5254 break;
5255
5256 case clang::BuiltinType::Bool:
5257 return lldb::eFormatBoolean;
5258 case clang::BuiltinType::Char_S:
5259 case clang::BuiltinType::SChar:
5260 case clang::BuiltinType::WChar_S:
5261 case clang::BuiltinType::Char_U:
5262 case clang::BuiltinType::UChar:
5263 case clang::BuiltinType::WChar_U:
5264 return lldb::eFormatChar;
5265 case clang::BuiltinType::Char8:
5266 return lldb::eFormatUnicode8;
5267 case clang::BuiltinType::Char16:
5269 case clang::BuiltinType::Char32:
5271 case clang::BuiltinType::UShort:
5272 return lldb::eFormatUnsigned;
5273 case clang::BuiltinType::Short:
5274 return lldb::eFormatDecimal;
5275 case clang::BuiltinType::UInt:
5276 return lldb::eFormatUnsigned;
5277 case clang::BuiltinType::Int:
5278 return lldb::eFormatDecimal;
5279 case clang::BuiltinType::ULong:
5280 return lldb::eFormatUnsigned;
5281 case clang::BuiltinType::Long:
5282 return lldb::eFormatDecimal;
5283 case clang::BuiltinType::ULongLong:
5284 return lldb::eFormatUnsigned;
5285 case clang::BuiltinType::LongLong:
5286 return lldb::eFormatDecimal;
5287 case clang::BuiltinType::UInt128:
5288 return lldb::eFormatUnsigned;
5289 case clang::BuiltinType::Int128:
5290 return lldb::eFormatDecimal;
5291 case clang::BuiltinType::Half:
5292 case clang::BuiltinType::Float:
5293 case clang::BuiltinType::Double:
5294 case clang::BuiltinType::LongDouble:
5295 return lldb::eFormatFloat;
5296 default:
5297 return lldb::eFormatHex;
5298 }
5299 break;
5300 case clang::Type::ObjCObjectPointer:
5301 return lldb::eFormatHex;
5302 case clang::Type::BlockPointer:
5303 return lldb::eFormatHex;
5304 case clang::Type::Pointer:
5305 return lldb::eFormatHex;
5306 case clang::Type::LValueReference:
5307 case clang::Type::RValueReference:
5308 return lldb::eFormatHex;
5309 case clang::Type::MemberPointer:
5310 return lldb::eFormatHex;
5311 case clang::Type::Complex: {
5312 if (qual_type->isComplexType())
5313 return lldb::eFormatComplex;
5314 else
5316 }
5317 case clang::Type::ObjCInterface:
5318 break;
5319 case clang::Type::Record:
5320 break;
5321 case clang::Type::Enum:
5322 return lldb::eFormatEnum;
5323 case clang::Type::DependentSizedArray:
5324 case clang::Type::DependentSizedExtVector:
5325 case clang::Type::UnresolvedUsing:
5326 case clang::Type::Attributed:
5327 case clang::Type::BTFTagAttributed:
5328 case clang::Type::TemplateTypeParm:
5329 case clang::Type::SubstTemplateTypeParm:
5330 case clang::Type::SubstTemplateTypeParmPack:
5331 case clang::Type::InjectedClassName:
5332 case clang::Type::DependentName:
5333 case clang::Type::DependentTemplateSpecialization:
5334 case clang::Type::PackExpansion:
5335 case clang::Type::ObjCObject:
5336
5337 case clang::Type::TemplateSpecialization:
5338 case clang::Type::DeducedTemplateSpecialization:
5339 case clang::Type::Adjusted:
5340 case clang::Type::Pipe:
5341 break;
5342
5343 // pointer type decayed from an array or function type.
5344 case clang::Type::Decayed:
5345 break;
5346 case clang::Type::ObjCTypeParam:
5347 break;
5348
5349 case clang::Type::DependentAddressSpace:
5350 break;
5351 case clang::Type::MacroQualified:
5352 break;
5353
5354 // Matrix types we're not sure how to display yet.
5355 case clang::Type::ConstantMatrix:
5356 case clang::Type::DependentSizedMatrix:
5357 break;
5358 }
5359 // We don't know hot to display this type...
5360 return lldb::eFormatBytes;
5361}
5362
5363static bool ObjCDeclHasIVars(clang::ObjCInterfaceDecl *class_interface_decl,
5364 bool check_superclass) {
5365 while (class_interface_decl) {
5366 if (class_interface_decl->ivar_size() > 0)
5367 return true;
5368
5369 if (check_superclass)
5370 class_interface_decl = class_interface_decl->getSuperClass();
5371 else
5372 break;
5373 }
5374 return false;
5375}
5376
5377static std::optional<SymbolFile::ArrayInfo>
5379 clang::QualType qual_type,
5380 const ExecutionContext *exe_ctx) {
5381 if (qual_type->isIncompleteArrayType())
5382 if (auto *metadata = ast.GetMetadata(qual_type.getTypePtr()))
5383 return sym_file->GetDynamicArrayInfoForUID(metadata->GetUserID(),
5384 exe_ctx);
5385 return std::nullopt;
5386}
5387
5389 bool omit_empty_base_classes,
5390 const ExecutionContext *exe_ctx) {
5391 if (!type)
5392 return 0;
5393
5394 uint32_t num_children = 0;
5395 clang::QualType qual_type(RemoveWrappingTypes(GetQualType(type)));
5396 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5397 switch (type_class) {
5398 case clang::Type::Builtin:
5399 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5400 case clang::BuiltinType::ObjCId: // child is Class
5401 case clang::BuiltinType::ObjCClass: // child is Class
5402 num_children = 1;
5403 break;
5404
5405 default:
5406 break;
5407 }
5408 break;
5409
5410 case clang::Type::Complex:
5411 return 0;
5412 case clang::Type::Record:
5413 if (GetCompleteQualType(&getASTContext(), qual_type)) {
5414 const clang::RecordType *record_type =
5415 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5416 const clang::RecordDecl *record_decl = record_type->getDecl();
5417 assert(record_decl);
5418 const clang::CXXRecordDecl *cxx_record_decl =
5419 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5420 if (cxx_record_decl) {
5421 if (omit_empty_base_classes) {
5422 // Check each base classes to see if it or any of its base classes
5423 // contain any fields. This can help limit the noise in variable
5424 // views by not having to show base classes that contain no members.
5425 clang::CXXRecordDecl::base_class_const_iterator base_class,
5426 base_class_end;
5427 for (base_class = cxx_record_decl->bases_begin(),
5428 base_class_end = cxx_record_decl->bases_end();
5429 base_class != base_class_end; ++base_class) {
5430 const clang::CXXRecordDecl *base_class_decl =
5431 llvm::cast<clang::CXXRecordDecl>(
5432 base_class->getType()
5433 ->getAs<clang::RecordType>()
5434 ->getDecl());
5435
5436 // Skip empty base classes
5437 if (!TypeSystemClang::RecordHasFields(base_class_decl))
5438 continue;
5439
5440 num_children++;
5441 }
5442 } else {
5443 // Include all base classes
5444 num_children += cxx_record_decl->getNumBases();
5445 }
5446 }
5447 clang::RecordDecl::field_iterator field, field_end;
5448 for (field = record_decl->field_begin(),
5449 field_end = record_decl->field_end();
5450 field != field_end; ++field)
5451 ++num_children;
5452 }
5453 break;
5454
5455 case clang::Type::ObjCObject:
5456 case clang::Type::ObjCInterface:
5457 if (GetCompleteQualType(&getASTContext(), qual_type)) {
5458 const clang::ObjCObjectType *objc_class_type =
5459 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5460 assert(objc_class_type);
5461 if (objc_class_type) {
5462 clang::ObjCInterfaceDecl *class_interface_decl =
5463 objc_class_type->getInterface();
5464
5465 if (class_interface_decl) {
5466
5467 clang::ObjCInterfaceDecl *superclass_interface_decl =
5468 class_interface_decl->getSuperClass();
5469 if (superclass_interface_decl) {
5470 if (omit_empty_base_classes) {
5471 if (ObjCDeclHasIVars(superclass_interface_decl, true))
5472 ++num_children;
5473 } else
5474 ++num_children;
5475 }
5476
5477 num_children += class_interface_decl->ivar_size();
5478 }
5479 }
5480 }
5481 break;
5482
5483 case clang::Type::LValueReference:
5484 case clang::Type::RValueReference:
5485 case clang::Type::ObjCObjectPointer: {
5486 CompilerType pointee_clang_type(GetPointeeType(type));
5487
5488 uint32_t num_pointee_children = 0;
5489 if (pointee_clang_type.IsAggregateType())
5490 num_pointee_children =
5491 pointee_clang_type.GetNumChildren(omit_empty_base_classes, exe_ctx);
5492 // If this type points to a simple type, then it has 1 child
5493 if (num_pointee_children == 0)
5494 num_children = 1;
5495 else
5496 num_children = num_pointee_children;
5497 } break;
5498
5499 case clang::Type::Vector:
5500 case clang::Type::ExtVector:
5501 num_children =
5502 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5503 break;
5504
5505 case clang::Type::ConstantArray:
5506 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5507 ->getSize()
5508 .getLimitedValue();
5509 break;
5510 case clang::Type::IncompleteArray:
5511 if (auto array_info =
5512 GetDynamicArrayInfo(*this, GetSymbolFile(), qual_type, exe_ctx))
5513 // Only 1-dimensional arrays are supported.
5514 num_children = array_info->element_orders.size()
5515 ? array_info->element_orders.back()
5516 : 0;
5517 break;
5518
5519 case clang::Type::Pointer: {
5520 const clang::PointerType *pointer_type =
5521 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5522 clang::QualType pointee_type(pointer_type->getPointeeType());
5523 CompilerType pointee_clang_type(GetType(pointee_type));
5524 uint32_t num_pointee_children = 0;
5525 if (pointee_clang_type.IsAggregateType())
5526 num_pointee_children =
5527 pointee_clang_type.GetNumChildren(omit_empty_base_classes, exe_ctx);
5528 if (num_pointee_children == 0) {
5529 // We have a pointer to a pointee type that claims it has no children. We
5530 // will want to look at
5531 num_children = GetNumPointeeChildren(pointee_type);
5532 } else
5533 num_children = num_pointee_children;
5534 } break;
5535
5536 default:
5537 break;
5538 }
5539 return num_children;
5540}
5541
5544}
5545
5548 if (type) {
5549 clang::QualType qual_type(GetQualType(type));
5550 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5551 if (type_class == clang::Type::Builtin) {
5552 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5553 case clang::BuiltinType::Void:
5554 return eBasicTypeVoid;
5555 case clang::BuiltinType::Bool:
5556 return eBasicTypeBool;
5557 case clang::BuiltinType::Char_S:
5558 return eBasicTypeSignedChar;
5559 case clang::BuiltinType::Char_U:
5561 case clang::BuiltinType::Char8:
5562 return eBasicTypeChar8;
5563 case clang::BuiltinType::Char16:
5564 return eBasicTypeChar16;
5565 case clang::BuiltinType::Char32:
5566 return eBasicTypeChar32;
5567 case clang::BuiltinType::UChar:
5569 case clang::BuiltinType::SChar:
5570 return eBasicTypeSignedChar;
5571 case clang::BuiltinType::WChar_S:
5572 return eBasicTypeSignedWChar;
5573 case clang::BuiltinType::WChar_U:
5575 case clang::BuiltinType::Short:
5576 return eBasicTypeShort;
5577 case clang::BuiltinType::UShort:
5579 case clang::BuiltinType::Int:
5580 return eBasicTypeInt;
5581 case clang::BuiltinType::UInt:
5582 return eBasicTypeUnsignedInt;
5583 case clang::BuiltinType::Long:
5584 return eBasicTypeLong;
5585 case clang::BuiltinType::ULong:
5587 case clang::BuiltinType::LongLong:
5588 return eBasicTypeLongLong;
5589 case clang::BuiltinType::ULongLong:
5591 case clang::BuiltinType::Int128:
5592 return eBasicTypeInt128;
5593 case clang::BuiltinType::UInt128:
5595
5596 case clang::BuiltinType::Half:
5597 return eBasicTypeHalf;
5598 case clang::BuiltinType::Float:
5599 return eBasicTypeFloat;
5600 case clang::BuiltinType::Double:
5601 return eBasicTypeDouble;
5602 case clang::BuiltinType::LongDouble:
5603 return eBasicTypeLongDouble;
5604
5605 case clang::BuiltinType::NullPtr:
5606 return eBasicTypeNullPtr;
5607 case clang::BuiltinType::ObjCId:
5608 return eBasicTypeObjCID;
5609 case clang::BuiltinType::ObjCClass:
5610 return eBasicTypeObjCClass;
5611 case clang::BuiltinType::ObjCSel:
5612 return eBasicTypeObjCSel;
5613 default:
5614 return eBasicTypeOther;
5615 }
5616 }
5617 }
5618 return eBasicTypeInvalid;
5619}
5620
5623 std::function<bool(const CompilerType &integer_type,
5624 ConstString name,
5625 const llvm::APSInt &value)> const &callback) {
5626 const clang::EnumType *enum_type =
5627 llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type));
5628 if (enum_type) {
5629 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5630 if (enum_decl) {
5631 CompilerType integer_type = GetType(enum_decl->getIntegerType());
5632
5633 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5634 for (enum_pos = enum_decl->enumerator_begin(),
5635 enum_end_pos = enum_decl->enumerator_end();
5636 enum_pos != enum_end_pos; ++enum_pos) {
5637 ConstString name(enum_pos->getNameAsString().c_str());
5638 if (!callback(integer_type, name, enum_pos->getInitVal()))
5639 break;
5640 }
5641 }
5642 }
5643}
5644
5645#pragma mark Aggregate Types
5646
5648 if (!type)
5649 return 0;
5650
5651 uint32_t count = 0;
5652 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
5653 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5654 switch (type_class) {
5655 case clang::Type::Record:
5656 if (GetCompleteType(type)) {
5657 const clang::RecordType *record_type =
5658 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5659 if (record_type) {
5660 clang::RecordDecl *record_decl = record_type->getDecl();
5661 if (record_decl) {
5662 uint32_t field_idx = 0;
5663 clang::RecordDecl::field_iterator field, field_end;
5664 for (field = record_decl->field_begin(),
5665 field_end = record_decl->field_end();
5666 field != field_end; ++field)
5667 ++field_idx;
5668 count = field_idx;
5669 }
5670 }
5671 }
5672 break;
5673
5674 case clang::Type::ObjCObjectPointer: {
5675 const clang::ObjCObjectPointerType *objc_class_type =
5676 qual_type->castAs<clang::ObjCObjectPointerType>();
5677 const clang::ObjCInterfaceType *objc_interface_type =
5678 objc_class_type->getInterfaceType();
5679 if (objc_interface_type &&
5681 const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) {
5682 clang::ObjCInterfaceDecl *class_interface_decl =
5683 objc_interface_type->getDecl();
5684 if (class_interface_decl) {
5685 count = class_interface_decl->ivar_size();
5686 }
5687 }
5688 break;
5689 }
5690
5691 case clang::Type::ObjCObject:
5692 case clang::Type::ObjCInterface:
5693 if (GetCompleteType(type)) {
5694 const clang::ObjCObjectType *objc_class_type =
5695 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5696 if (objc_class_type) {
5697 clang::ObjCInterfaceDecl *class_interface_decl =
5698 objc_class_type->getInterface();
5699
5700 if (class_interface_decl)
5701 count = class_interface_decl->ivar_size();
5702 }
5703 }
5704 break;
5705
5706 default:
5707 break;
5708 }
5709 return count;
5710}
5711
5713GetObjCFieldAtIndex(clang::ASTContext *ast,
5714 clang::ObjCInterfaceDecl *class_interface_decl, size_t idx,
5715 std::string &name, uint64_t *bit_offset_ptr,
5716 uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) {
5717 if (class_interface_decl) {
5718 if (idx < (class_interface_decl->ivar_size())) {
5719 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5720 ivar_end = class_interface_decl->ivar_end();
5721 uint32_t ivar_idx = 0;
5722
5723 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5724 ++ivar_pos, ++ivar_idx) {
5725 if (ivar_idx == idx) {
5726 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5727
5728 clang::QualType ivar_qual_type(ivar_decl->getType());
5729
5730 name.assign(ivar_decl->getNameAsString());
5731
5732 if (bit_offset_ptr) {
5733 const clang::ASTRecordLayout &interface_layout =
5734 ast->getASTObjCInterfaceLayout(class_interface_decl);
5735 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5736 }
5737
5738 const bool is_bitfield = ivar_pos->isBitField();
5739
5740 if (bitfield_bit_size_ptr) {
5741 *bitfield_bit_size_ptr = 0;
5742
5743 if (is_bitfield && ast) {
5744 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5745 clang::Expr::EvalResult result;
5746 if (bitfield_bit_size_expr &&
5747 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5748 llvm::APSInt bitfield_apsint = result.Val.getInt();
5749 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5750 }
5751 }
5752 }
5753 if (is_bitfield_ptr)
5754 *is_bitfield_ptr = is_bitfield;
5755
5756 return ivar_qual_type.getAsOpaquePtr();
5757 }
5758 }
5759 }
5760 }
5761 return nullptr;
5762}
5763
5765 size_t idx, std::string &name,
5766 uint64_t *bit_offset_ptr,
5767 uint32_t *bitfield_bit_size_ptr,
5768 bool *is_bitfield_ptr) {
5769 if (!type)
5770 return CompilerType();
5771
5772 clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
5773 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5774 switch (type_class) {
5775 case clang::Type::Record:
5776 if (GetCompleteType(type)) {
5777 const clang::RecordType *record_type =
5778 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5779 const clang::RecordDecl *record_decl = record_type->getDecl();
5780 uint32_t field_idx = 0;
5781 clang::RecordDecl::field_iterator field, field_end;
5782 for (field = record_decl->field_begin(),
5783 field_end = record_decl->field_end();
5784 field != field_end; ++field, ++field_idx) {
5785 if (idx == field_idx) {
5786 // Print the member type if requested
5787 // Print the member name and equal sign
5788 name.assign(field->getNameAsString());
5789
5790 // Figure out the type byte size (field_type_info.first) and
5791 // alignment (field_type_info.second) from the AST context.
<