11#include "clang/AST/DeclBase.h"
12#include "clang/AST/ExprCXX.h"
13#include "llvm/Support/Casting.h"
14#include "llvm/Support/FormatAdapters.h"
15#include "llvm/Support/FormatVariadic.h"
22#include "clang/AST/ASTContext.h"
23#include "clang/AST/ASTImporter.h"
24#include "clang/AST/Attr.h"
25#include "clang/AST/CXXInheritance.h"
26#include "clang/AST/DeclObjC.h"
27#include "clang/AST/DeclTemplate.h"
28#include "clang/AST/Mangle.h"
29#include "clang/AST/RecordLayout.h"
30#include "clang/AST/Type.h"
31#include "clang/AST/VTableBuilder.h"
32#include "clang/Basic/Builtins.h"
33#include "clang/Basic/Diagnostic.h"
34#include "clang/Basic/FileManager.h"
35#include "clang/Basic/FileSystemOptions.h"
36#include "clang/Basic/LangStandard.h"
37#include "clang/Basic/SourceManager.h"
38#include "clang/Basic/TargetInfo.h"
39#include "clang/Basic/TargetOptions.h"
40#include "clang/Frontend/FrontendOptions.h"
41#include "clang/Lex/HeaderSearch.h"
42#include "clang/Lex/HeaderSearchOptions.h"
43#include "clang/Lex/ModuleMap.h"
44#include "clang/Sema/Sema.h"
46#include "llvm/Support/Signals.h"
47#include "llvm/Support/Threading.h"
93using llvm::StringSwitch;
98static void VerifyDecl(clang::Decl *decl) {
99 assert(decl &&
"VerifyDecl called with nullptr?");
125bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
127 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
128 "Methods should have the same AST context");
129 clang::ASTContext &context = m1->getASTContext();
131 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
132 context.getCanonicalType(m1->getType()));
134 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
135 context.getCanonicalType(m2->getType()));
137 auto compareArgTypes = [&context](
const clang::QualType &m1p,
138 const clang::QualType &m2p) {
139 return context.hasSameType(m1p.getUnqualifiedType(),
140 m2p.getUnqualifiedType());
145 return (m1->getNumParams() != m2->getNumParams()) ||
146 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
147 m2Type->param_type_begin(), compareArgTypes);
153void addOverridesForMethod(clang::CXXMethodDecl *decl) {
154 if (!decl->isVirtual())
157 clang::CXXBasePaths paths;
158 llvm::SmallVector<clang::NamedDecl *, 4> decls;
160 auto find_overridden_methods =
161 [&decls, decl](
const clang::CXXBaseSpecifier *specifier,
162 clang::CXXBasePath &path) {
163 if (
auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
164 specifier->getType()->castAs<clang::RecordType>()->getDecl())) {
166 clang::DeclarationName name = decl->getDeclName();
170 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
171 if (
auto *baseDtorDecl = base_record->getDestructor()) {
172 if (baseDtorDecl->isVirtual()) {
173 decls.push_back(baseDtorDecl);
180 for (path.Decls = base_record->lookup(name).begin();
181 path.Decls != path.Decls.end(); ++path.Decls) {
182 if (
auto *method_decl =
183 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
184 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
185 decls.push_back(method_decl);
194 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
195 for (
auto *overridden_decl : decls)
196 decl->addOverriddenMethod(
197 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
203 VTableContextBase &vtable_ctx,
205 const ASTRecordLayout &record_layout) {
209 uint32_t type_info = this_type.
GetTypeInfo(&pointee_type);
214 bool ptr_or_ref =
false;
215 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
221 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
222 if ((type_info & cpp_class) != cpp_class)
227 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
241 vbtable_ptr_addr += vbtable_ptr_offset;
252 auto size = valobj.
GetData(data, err);
260 VTableContextBase &vtable_ctx,
262 const CXXRecordDecl *cxx_record_decl,
263 const CXXRecordDecl *base_class_decl) {
264 if (vtable_ctx.isMicrosoft()) {
265 clang::MicrosoftVTableContext &msoft_vtable_ctx =
266 static_cast<clang::MicrosoftVTableContext &
>(vtable_ctx);
270 const unsigned vbtable_index =
271 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
272 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
278 clang::ItaniumVTableContext &itanium_vtable_ctx =
279 static_cast<clang::ItaniumVTableContext &
>(vtable_ctx);
281 clang::CharUnits base_offset_offset =
282 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
285 vtable_ptr + base_offset_offset.getQuantity();
294 const ASTRecordLayout &record_layout,
295 const CXXRecordDecl *cxx_record_decl,
296 const CXXRecordDecl *base_class_decl,
297 int32_t &bit_offset) {
309 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
310 if (base_offset == INT64_MAX)
313 bit_offset = base_offset * 8;
323 static llvm::once_flag g_once_flag;
324 llvm::call_once(g_once_flag, []() {
331 bool is_complete_objc_class)
332 : m_payload(owning_module.GetValue()) {
344 const clang::Decl *parent) {
345 if (!member || !parent)
352 member->setFromASTFile();
353 member->setOwningModuleID(
id.GetValue());
354 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
355 if (llvm::isa<clang::NamedDecl>(member))
356 if (
auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
357 dc->setHasExternalVisibleStorage(
true);
360 dc->setHasExternalLexicalStorage(
true);
367 clang::OverloadedOperatorKind &op_kind) {
369 if (!name.consume_front(
"operator"))
374 bool space_after_operator = name.consume_front(
" ");
376 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
377 .Case(
"+", clang::OO_Plus)
378 .Case(
"+=", clang::OO_PlusEqual)
379 .Case(
"++", clang::OO_PlusPlus)
380 .Case(
"-", clang::OO_Minus)
381 .Case(
"-=", clang::OO_MinusEqual)
382 .Case(
"--", clang::OO_MinusMinus)
383 .Case(
"->", clang::OO_Arrow)
384 .Case(
"->*", clang::OO_ArrowStar)
385 .Case(
"*", clang::OO_Star)
386 .Case(
"*=", clang::OO_StarEqual)
387 .Case(
"/", clang::OO_Slash)
388 .Case(
"/=", clang::OO_SlashEqual)
389 .Case(
"%", clang::OO_Percent)
390 .Case(
"%=", clang::OO_PercentEqual)
391 .Case(
"^", clang::OO_Caret)
392 .Case(
"^=", clang::OO_CaretEqual)
393 .Case(
"&", clang::OO_Amp)
394 .Case(
"&=", clang::OO_AmpEqual)
395 .Case(
"&&", clang::OO_AmpAmp)
396 .Case(
"|", clang::OO_Pipe)
397 .Case(
"|=", clang::OO_PipeEqual)
398 .Case(
"||", clang::OO_PipePipe)
399 .Case(
"~", clang::OO_Tilde)
400 .Case(
"!", clang::OO_Exclaim)
401 .Case(
"!=", clang::OO_ExclaimEqual)
402 .Case(
"=", clang::OO_Equal)
403 .Case(
"==", clang::OO_EqualEqual)
404 .Case(
"<", clang::OO_Less)
405 .Case(
"<=>", clang::OO_Spaceship)
406 .Case(
"<<", clang::OO_LessLess)
407 .Case(
"<<=", clang::OO_LessLessEqual)
408 .Case(
"<=", clang::OO_LessEqual)
409 .Case(
">", clang::OO_Greater)
410 .Case(
">>", clang::OO_GreaterGreater)
411 .Case(
">>=", clang::OO_GreaterGreaterEqual)
412 .Case(
">=", clang::OO_GreaterEqual)
413 .Case(
"()", clang::OO_Call)
414 .Case(
"[]", clang::OO_Subscript)
415 .Case(
",", clang::OO_Comma)
416 .Default(clang::NUM_OVERLOADED_OPERATORS);
419 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
431 if (!space_after_operator)
436 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
437 .Case(
"new", clang::OO_New)
438 .Case(
"new[]", clang::OO_Array_New)
439 .Case(
"delete", clang::OO_Delete)
440 .Case(
"delete[]", clang::OO_Array_Delete)
442 .Default(clang::NUM_OVERLOADED_OPERATORS);
447clang::AccessSpecifier
467 std::vector<std::string> Includes;
468 LangOptions::setLangDefaults(Opts, clang::Language::ObjCXX, arch.
GetTriple(),
469 Includes, clang::LangStandard::lang_gnucxx98);
471 Opts.setValueVisibilityMode(DefaultVisibility);
475 Opts.Trigraphs = !Opts.GNUMode;
477 Opts.OptimizeSize = 0;
490 Opts.NoInlineDefine = !Opt;
494 Opts.ModulesLocalVisibility = 1;
498 llvm::Triple target_triple) {
500 if (!target_triple.str().empty())
510 ASTContext &existing_ctxt) {
526 if (!TypeSystemClangSupportsLanguage(language))
540 if (triple.getVendor() == llvm::Triple::Apple &&
541 triple.getOS() == llvm::Triple::UnknownOS) {
542 if (triple.getArch() == llvm::Triple::arm ||
543 triple.getArch() == llvm::Triple::aarch64 ||
544 triple.getArch() == llvm::Triple::aarch64_32 ||
545 triple.getArch() == llvm::Triple::thumb) {
546 triple.setOS(llvm::Triple::IOS);
548 triple.setOS(llvm::Triple::MacOSX);
553 std::string ast_name =
555 return std::make_shared<TypeSystemClang>(ast_name, triple);
556 }
else if (target && target->
IsValid())
557 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
619 assert(s ==
nullptr || &s->getASTContext() ==
m_ast_up.get());
632 llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
634 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(
true);
635 ast.setExternalSource(ast_source_up);
648 const clang::Diagnostic &info)
override {
650 llvm::SmallVector<char, 32> diag_str(10);
651 info.FormatDiagnostic(diag_str);
652 diag_str.push_back(
'\0');
653 LLDB_LOGF(m_log,
"Compiler diagnostic: %s\n", diag_str.data());
657 DiagnosticConsumer *
clone(DiagnosticsEngine &Diags)
const {
678 clang::FileSystemOptions file_system_options;
682 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(
new DiagnosticIDs());
684 std::make_unique<DiagnosticsEngine>(diag_id_sp,
new DiagnosticOptions());
688 m_ast_up = std::make_unique<ASTContext>(
700 m_ast_up->InitBuiltinTypes(*target_info);
704 "Failed to initialize builtin ASTContext types for target '{0}'. "
705 "Printing variables may behave unexpectedly.",
711 static std::once_flag s_uninitialized_target_warning;
713 &s_uninitialized_target_warning);
718 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
751#pragma mark Basic Types
754 ASTContext &ast, QualType qual_type) {
755 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
756 return qual_type_bit_size == bit_size;
775 return GetType(ast.UnsignedCharTy);
777 return GetType(ast.UnsignedShortTy);
779 return GetType(ast.UnsignedIntTy);
781 return GetType(ast.UnsignedLongTy);
783 return GetType(ast.UnsignedLongLongTy);
785 return GetType(ast.UnsignedInt128Ty);
790 return GetType(ast.SignedCharTy);
798 return GetType(ast.LongLongTy);
809 return GetType(ast.LongDoubleTy);
816 if (bit_size && !(bit_size & 0x7u))
817 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
825 static const llvm::StringMap<lldb::BasicType> g_type_map = {
878 auto iter = g_type_map.find(name);
879 if (iter == g_type_map.end())
906 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
925 return GetType(ast.UnsignedCharTy);
927 return GetType(ast.UnsignedShortTy);
929 return GetType(ast.UnsignedIntTy);
934 if (type_name.contains(
"complex")) {
943 case DW_ATE_complex_float: {
944 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
946 return GetType(FloatComplexTy);
948 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
950 return GetType(DoubleComplexTy);
952 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
954 return GetType(LongDoubleComplexTy);
964 if (type_name ==
"float" &&
967 if (type_name ==
"double" &&
970 if (type_name ==
"long double" &&
972 return GetType(ast.LongDoubleTy);
979 return GetType(ast.LongDoubleTy);
985 if (!type_name.empty()) {
986 if (type_name ==
"wchar_t" &&
991 if (type_name ==
"void" &&
994 if (type_name.contains(
"long long") &&
996 return GetType(ast.LongLongTy);
997 if (type_name.contains(
"long") &&
1000 if (type_name.contains(
"short") &&
1003 if (type_name.contains(
"char")) {
1007 return GetType(ast.SignedCharTy);
1009 if (type_name.contains(
"int")) {
1026 return GetType(ast.LongLongTy);
1031 case DW_ATE_signed_char:
1032 if (type_name ==
"char") {
1037 return GetType(ast.SignedCharTy);
1040 case DW_ATE_unsigned:
1041 if (!type_name.empty()) {
1042 if (type_name ==
"wchar_t") {
1049 if (type_name.contains(
"long long")) {
1051 return GetType(ast.UnsignedLongLongTy);
1052 }
else if (type_name.contains(
"long")) {
1054 return GetType(ast.UnsignedLongTy);
1055 }
else if (type_name.contains(
"short")) {
1057 return GetType(ast.UnsignedShortTy);
1058 }
else if (type_name.contains(
"char")) {
1060 return GetType(ast.UnsignedCharTy);
1061 }
else if (type_name.contains(
"int")) {
1063 return GetType(ast.UnsignedIntTy);
1065 return GetType(ast.UnsignedInt128Ty);
1070 return GetType(ast.UnsignedCharTy);
1072 return GetType(ast.UnsignedShortTy);
1074 return GetType(ast.UnsignedIntTy);
1076 return GetType(ast.UnsignedLongTy);
1078 return GetType(ast.UnsignedLongLongTy);
1080 return GetType(ast.UnsignedInt128Ty);
1083 case DW_ATE_unsigned_char:
1084 if (type_name ==
"char") {
1089 return GetType(ast.UnsignedCharTy);
1091 return GetType(ast.UnsignedShortTy);
1094 case DW_ATE_imaginary_float:
1106 if (!type_name.empty()) {
1107 if (type_name ==
"char16_t")
1109 if (type_name ==
"char32_t")
1111 if (type_name ==
"char8_t")
1120 "error: need to add support for DW_TAG_base_type '{0}' "
1121 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1122 type_name, dw_ate, bit_size);
1128 QualType char_type(ast.CharTy);
1131 char_type.addConst();
1133 return GetType(ast.getPointerType(char_type));
1137 bool ignore_qualifiers) {
1148 if (ignore_qualifiers) {
1149 type1_qual = type1_qual.getUnqualifiedType();
1150 type2_qual = type2_qual.getUnqualifiedType();
1153 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1160 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
1161 if (
auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1173 if (clang::ObjCInterfaceDecl *interface_decl =
1174 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1176 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1178 if (clang::ValueDecl *value_decl = llvm::dyn_cast<clang::ValueDecl>(decl))
1192 return GetType(value_decl->getType());
1195#pragma mark Structure, Unions, Classes
1199 if (!decl || !owning_module.
HasValue())
1202 decl->setFromASTFile();
1203 decl->setOwningModuleID(owning_module.
GetValue());
1204 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1210 bool is_framework,
bool is_explicit) {
1212 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1214 assert(ast_source &&
"external ast source was lost");
1220 auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1231 clang::Module *module;
1232 auto parent_desc = ast_source->getSourceDescriptor(parent.
GetValue());
1234 name, parent_desc ? parent_desc->getModuleOrNull() :
nullptr,
1235 is_framework, is_explicit);
1237 return ast_source->GetIDForModule(module);
1239 return ast_source->RegisterModule(module);
1244 AccessType access_type, llvm::StringRef name,
int kind,
1245 LanguageType language, std::optional<ClangASTMetadata> metadata,
1246 bool exports_symbols) {
1249 if (decl_ctx ==
nullptr)
1250 decl_ctx = ast.getTranslationUnitDecl();
1254 bool isInternal =
false;
1255 return CreateObjCClass(name, decl_ctx, owning_module, isInternal, metadata);
1264 bool has_name = !name.empty();
1265 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1266 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1267 decl->setDeclContext(decl_ctx);
1269 decl->setDeclName(&ast.Idents.get(name));
1297 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1298 decl->setAnonymousStructOrUnion(
true);
1308 decl_ctx->addDecl(decl);
1310 return GetType(ast.getTagDeclType(decl));
1316bool IsValueParam(
const clang::TemplateArgument &argument) {
1317 return argument.getKind() == TemplateArgument::Integral;
1320void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1322 clang::AccessSpecifier previous_access,
1323 clang::AccessSpecifier access_specifier) {
1324 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1326 if (previous_access != access_specifier) {
1329 if ((cxx_record_decl->isStruct() &&
1330 previous_access == clang::AccessSpecifier::AS_none &&
1331 access_specifier == clang::AccessSpecifier::AS_public) ||
1332 (cxx_record_decl->isClass() &&
1333 previous_access == clang::AccessSpecifier::AS_none &&
1334 access_specifier == clang::AccessSpecifier::AS_private)) {
1337 cxx_record_decl->addDecl(
1338 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1339 SourceLocation(), SourceLocation()));
1347 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1348 const bool parameter_pack =
false;
1349 const bool is_typename =
false;
1350 const unsigned depth = 0;
1351 const size_t num_template_params = template_param_infos.
Size();
1352 DeclContext *
const decl_context =
1353 ast.getTranslationUnitDecl();
1355 auto const &args = template_param_infos.
GetArgs();
1356 auto const &names = template_param_infos.
GetNames();
1357 for (
size_t i = 0; i < num_template_params; ++i) {
1358 const char *name = names[i];
1360 IdentifierInfo *identifier_info =
nullptr;
1361 if (name && name[0])
1362 identifier_info = &ast.Idents.get(name);
1363 TemplateArgument
const &targ = args[i];
1364 if (IsValueParam(targ)) {
1365 QualType template_param_type = targ.getIntegralType();
1366 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1367 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1368 identifier_info, template_param_type, parameter_pack,
1369 ast.getTrivialTypeSourceInfo(template_param_type)));
1371 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1372 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1373 identifier_info, is_typename, parameter_pack));
1378 IdentifierInfo *identifier_info =
nullptr;
1380 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1381 const bool parameter_pack_true =
true;
1385 QualType template_param_type =
1387 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1388 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1389 num_template_params, identifier_info, template_param_type,
1390 parameter_pack_true,
1391 ast.getTrivialTypeSourceInfo(template_param_type)));
1393 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1394 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1395 num_template_params, identifier_info, is_typename,
1396 parameter_pack_true));
1399 clang::Expr *
const requires_clause =
nullptr;
1400 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1401 ast, SourceLocation(), SourceLocation(), template_param_decls,
1402 SourceLocation(), requires_clause);
1403 return template_param_list;
1408 clang::FunctionDecl *func_decl,
1413 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1415 ast, template_param_infos, template_param_decls);
1416 FunctionTemplateDecl *func_tmpl_decl =
1417 FunctionTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1418 func_tmpl_decl->setDeclContext(decl_ctx);
1419 func_tmpl_decl->setLocation(func_decl->getLocation());
1420 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1421 func_tmpl_decl->setTemplateParameters(template_param_list);
1422 func_tmpl_decl->init(func_decl);
1425 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1426 i < template_param_decl_count; ++i) {
1428 template_param_decls[i]->setDeclContext(func_decl);
1433 if (decl_ctx->isRecord())
1434 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1436 return func_tmpl_decl;
1440 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1442 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1443 func_decl->getASTContext(), infos.
GetArgs());
1445 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1446 template_args_ptr,
nullptr);
1453 const TemplateArgument &value) {
1454 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1456 if (value.getKind() != TemplateArgument::Type)
1458 }
else if (
auto *type_param =
1459 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1461 if (!IsValueParam(value))
1464 if (type_param->getType() != value.getIntegralType())
1472 "Don't know how to compare template parameter to passed"
1473 " value. Decl kind of parameter is: {0}",
1474 param->getDeclKindName());
1475 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1490 ClassTemplateDecl *class_template_decl,
1493 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1499 std::optional<NamedDecl *> pack_parameter;
1501 size_t non_pack_params = params.size();
1502 for (
size_t i = 0; i < params.size(); ++i) {
1503 NamedDecl *param = params.getParam(i);
1504 if (param->isParameterPack()) {
1505 pack_parameter = param;
1506 non_pack_params = i;
1514 if (non_pack_params != instantiation_values.
Size())
1532 for (
const auto pair :
1533 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1534 const TemplateArgument &passed_arg = std::get<0>(pair);
1535 NamedDecl *found_param = std::get<1>(pair);
1540 return class_template_decl;
1549 ClassTemplateDecl *class_template_decl =
nullptr;
1550 if (decl_ctx ==
nullptr)
1551 decl_ctx = ast.getTranslationUnitDecl();
1553 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1554 DeclarationName decl_name(&identifier_info);
1557 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1558 for (NamedDecl *decl : result) {
1559 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1560 if (!class_template_decl)
1569 template_param_infos))
1571 return class_template_decl;
1574 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1577 ast, template_param_infos, template_param_decls);
1579 CXXRecordDecl *template_cxx_decl =
1580 CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1581 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1583 template_cxx_decl->setDeclContext(decl_ctx);
1584 template_cxx_decl->setDeclName(decl_name);
1587 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1588 i < template_param_decl_count; ++i) {
1589 template_param_decls[i]->setDeclContext(template_cxx_decl);
1597 class_template_decl =
1598 ClassTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1600 class_template_decl->setDeclContext(decl_ctx);
1601 class_template_decl->setDeclName(decl_name);
1602 class_template_decl->setTemplateParameters(template_param_list);
1603 class_template_decl->init(template_cxx_decl);
1604 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1608 class_template_decl->setAccess(
1611 decl_ctx->addDecl(class_template_decl);
1613 VerifyDecl(class_template_decl);
1615 return class_template_decl;
1618TemplateTemplateParmDecl *
1622 auto *decl_ctx = ast.getTranslationUnitDecl();
1624 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1625 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1629 ast, template_param_infos, template_param_decls);
1635 return TemplateTemplateParmDecl::Create(ast, decl_ctx, SourceLocation(),
1638 &identifier_info,
false,
1639 template_param_list);
1642ClassTemplateSpecializationDecl *
1645 ClassTemplateDecl *class_template_decl,
int kind,
1648 llvm::SmallVector<clang::TemplateArgument, 2> args(
1649 template_param_infos.
Size() +
1652 auto const &orig_args = template_param_infos.
GetArgs();
1653 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1655 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1658 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1659 ClassTemplateSpecializationDecl::CreateDeserialized(ast, GlobalDeclID());
1660 class_template_specialization_decl->setTagKind(
1661 static_cast<TagDecl::TagKind
>(kind));
1662 class_template_specialization_decl->setDeclContext(decl_ctx);
1663 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1664 class_template_specialization_decl->setTemplateArgs(
1665 TemplateArgumentList::CreateCopy(ast, args));
1666 ast.getTypeDeclType(class_template_specialization_decl,
nullptr);
1667 class_template_specialization_decl->setDeclName(
1668 class_template_decl->getDeclName());
1670 decl_ctx->addDecl(class_template_specialization_decl);
1672 class_template_specialization_decl->setSpecializationKind(
1673 TSK_ExplicitSpecialization);
1675 return class_template_specialization_decl;
1679 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1680 if (class_template_specialization_decl) {
1682 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1688 clang::OverloadedOperatorKind op_kind,
1689 bool unary,
bool binary,
1690 uint32_t num_params) {
1692 if (op_kind == OO_Call)
1698 if (num_params == 1)
1700 if (num_params == 2)
1707 bool is_method, clang::OverloadedOperatorKind op_kind,
1708 uint32_t num_params) {
1716 case OO_Array_Delete:
1720#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1722 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1724#include "clang/Basic/OperatorKinds.def"
1731clang::AccessSpecifier
1733 clang::AccessSpecifier rhs) {
1736 if (lhs == AS_none || rhs == AS_none)
1738 if (lhs == AS_private || rhs == AS_private)
1740 if (lhs == AS_protected || rhs == AS_protected)
1741 return AS_protected;
1746 uint32_t &bitfield_bit_size) {
1748 if (field ==
nullptr)
1751 if (field->isBitField()) {
1752 Expr *bit_width_expr = field->getBitWidth();
1753 if (bit_width_expr) {
1754 if (std::optional<llvm::APSInt> bit_width_apsint =
1755 bit_width_expr->getIntegerConstantExpr(ast)) {
1756 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1765 if (record_decl ==
nullptr)
1768 if (!record_decl->field_empty())
1772 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1773 if (cxx_record_decl) {
1774 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1775 for (base_class = cxx_record_decl->bases_begin(),
1776 base_class_end = cxx_record_decl->bases_end();
1777 base_class != base_class_end; ++base_class) {
1778 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1779 base_class->getType()->getAs<RecordType>()->getDecl());
1791 if (std::optional<ClangASTMetadata> meta_data =
GetMetadata(record_decl);
1792 meta_data && meta_data->IsForcefullyCompleted())
1798#pragma mark Objective-C Classes
1801 llvm::StringRef name, clang::DeclContext *decl_ctx,
1803 std::optional<ClangASTMetadata> metadata) {
1805 assert(!name.empty());
1807 decl_ctx = ast.getTranslationUnitDecl();
1809 ObjCInterfaceDecl *decl =
1810 ObjCInterfaceDecl::CreateDeserialized(ast, GlobalDeclID());
1811 decl->setDeclContext(decl_ctx);
1812 decl->setDeclName(&ast.Idents.get(name));
1813 decl->setImplicit(isInternal);
1819 return GetType(ast.getObjCInterfaceType(decl));
1828 bool omit_empty_base_classes) {
1829 uint32_t num_bases = 0;
1830 if (cxx_record_decl) {
1831 if (omit_empty_base_classes) {
1832 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1833 for (base_class = cxx_record_decl->bases_begin(),
1834 base_class_end = cxx_record_decl->bases_end();
1835 base_class != base_class_end; ++base_class) {
1842 num_bases = cxx_record_decl->getNumBases();
1847#pragma mark Namespace Declarations
1850 const char *name, clang::DeclContext *decl_ctx,
1852 NamespaceDecl *namespace_decl =
nullptr;
1854 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1856 decl_ctx = translation_unit_decl;
1859 IdentifierInfo &identifier_info = ast.Idents.get(name);
1860 DeclarationName decl_name(&identifier_info);
1861 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1862 for (NamedDecl *decl : result) {
1863 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1865 return namespace_decl;
1868 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1869 SourceLocation(), SourceLocation(),
1870 &identifier_info,
nullptr,
false);
1872 decl_ctx->addDecl(namespace_decl);
1874 if (decl_ctx == translation_unit_decl) {
1875 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1877 return namespace_decl;
1880 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1881 SourceLocation(),
nullptr,
nullptr,
false);
1882 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1883 translation_unit_decl->addDecl(namespace_decl);
1884 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1886 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1887 if (parent_namespace_decl) {
1888 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1890 return namespace_decl;
1892 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1893 SourceLocation(),
nullptr,
nullptr,
false);
1894 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1895 parent_namespace_decl->addDecl(namespace_decl);
1896 assert(namespace_decl ==
1897 parent_namespace_decl->getAnonymousNamespace());
1899 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1900 "no namespace as decl_ctx");
1908 VerifyDecl(namespace_decl);
1909 return namespace_decl;
1916 clang::BlockDecl *decl =
1917 clang::BlockDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1918 decl->setDeclContext(ctx);
1927 clang::DeclContext *right,
1928 clang::DeclContext *root) {
1929 if (root ==
nullptr)
1932 std::set<clang::DeclContext *> path_left;
1933 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1934 path_left.insert(d);
1936 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1937 if (path_left.find(d) != path_left.end())
1945 clang::NamespaceDecl *ns_decl) {
1946 if (decl_ctx && ns_decl) {
1947 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1948 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1950 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1951 clang::SourceLocation(), ns_decl,
1954 decl_ctx->addDecl(using_decl);
1964 clang::NamedDecl *target) {
1965 if (current_decl_ctx && target) {
1966 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1968 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1970 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1972 target->getDeclName(), using_decl, target);
1974 using_decl->addShadowDecl(shadow_decl);
1975 current_decl_ctx->addDecl(using_decl);
1983 const char *name, clang::QualType type) {
1985 clang::VarDecl *var_decl =
1986 clang::VarDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1987 var_decl->setDeclContext(decl_context);
1988 if (name && name[0])
1989 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1990 var_decl->setType(type);
1992 var_decl->setAccess(clang::AS_public);
1993 decl_context->addDecl(var_decl);
2002 switch (basic_type) {
2004 return ast->VoidTy.getAsOpaquePtr();
2006 return ast->CharTy.getAsOpaquePtr();
2008 return ast->SignedCharTy.getAsOpaquePtr();
2010 return ast->UnsignedCharTy.getAsOpaquePtr();
2012 return ast->getWCharType().getAsOpaquePtr();
2014 return ast->getSignedWCharType().getAsOpaquePtr();
2016 return ast->getUnsignedWCharType().getAsOpaquePtr();
2018 return ast->Char8Ty.getAsOpaquePtr();
2020 return ast->Char16Ty.getAsOpaquePtr();
2022 return ast->Char32Ty.getAsOpaquePtr();
2024 return ast->ShortTy.getAsOpaquePtr();
2026 return ast->UnsignedShortTy.getAsOpaquePtr();
2028 return ast->IntTy.getAsOpaquePtr();
2030 return ast->UnsignedIntTy.getAsOpaquePtr();
2032 return ast->LongTy.getAsOpaquePtr();
2034 return ast->UnsignedLongTy.getAsOpaquePtr();
2036 return ast->LongLongTy.getAsOpaquePtr();
2038 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2040 return ast->Int128Ty.getAsOpaquePtr();
2042 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2044 return ast->BoolTy.getAsOpaquePtr();
2046 return ast->HalfTy.getAsOpaquePtr();
2048 return ast->FloatTy.getAsOpaquePtr();
2050 return ast->DoubleTy.getAsOpaquePtr();
2052 return ast->LongDoubleTy.getAsOpaquePtr();
2054 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2056 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2058 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2060 return ast->getObjCIdType().getAsOpaquePtr();
2062 return ast->getObjCClassType().getAsOpaquePtr();
2064 return ast->getObjCSelType().getAsOpaquePtr();
2066 return ast->NullPtrTy.getAsOpaquePtr();
2072#pragma mark Function Types
2074clang::DeclarationName
2077 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2078 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2087 const clang::FunctionProtoType *function_type =
2088 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2089 if (function_type ==
nullptr)
2090 return clang::DeclarationName();
2092 const bool is_method =
false;
2093 const unsigned int num_params = function_type->getNumParams();
2095 is_method, op_kind, num_params))
2096 return clang::DeclarationName();
2098 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2102 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2103 printing_policy.SuppressTagKeyword =
true;
2106 printing_policy.SuppressInlineNamespace =
false;
2107 printing_policy.SuppressUnwrittenScope =
false;
2119 printing_policy.SuppressDefaultTemplateArgs =
false;
2120 return printing_policy;
2127 llvm::raw_string_ostream os(result);
2128 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2134 llvm::StringRef name,
const CompilerType &function_clang_type,
2135 clang::StorageClass storage,
bool is_inline) {
2136 FunctionDecl *func_decl =
nullptr;
2139 decl_ctx = ast.getTranslationUnitDecl();
2141 const bool hasWrittenPrototype =
true;
2142 const bool isConstexprSpecified =
false;
2144 clang::DeclarationName declarationName =
2146 func_decl = FunctionDecl::CreateDeserialized(ast, GlobalDeclID());
2147 func_decl->setDeclContext(decl_ctx);
2148 func_decl->setDeclName(declarationName);
2150 func_decl->setStorageClass(storage);
2151 func_decl->setInlineSpecified(is_inline);
2152 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2153 func_decl->setConstexprKind(isConstexprSpecified
2154 ? ConstexprSpecKind::Constexpr
2155 : ConstexprSpecKind::Unspecified);
2157 decl_ctx->addDecl(func_decl);
2159 VerifyDecl(func_decl);
2166 unsigned num_args,
bool is_variadic,
unsigned type_quals,
2167 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2171 std::vector<QualType> qual_type_args;
2172 if (num_args > 0 && args ==
nullptr)
2176 for (
unsigned i = 0; i < num_args; ++i) {
2191 FunctionProtoType::ExtProtoInfo proto_info;
2192 proto_info.ExtInfo = cc;
2193 proto_info.Variadic = is_variadic;
2194 proto_info.ExceptionSpec = EST_None;
2195 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2196 proto_info.RefQualifier = ref_qual;
2204 const char *name,
const CompilerType ¶m_type,
int storage,
2207 auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
2208 decl->setDeclContext(decl_ctx);
2209 if (name && name[0])
2210 decl->setDeclName(&ast.Idents.get(name));
2212 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2215 decl_ctx->addDecl(decl);
2221 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2223 function_decl->setParams(params);
2228 QualType block_type =
m_ast_up->getBlockPointerType(
2234#pragma mark Array Types
2238 std::optional<size_t> element_count,
2251 clang::ArraySizeModifier::Normal, 0));
2257 llvm::APInt ap_element_count(64, *element_count);
2259 ap_element_count,
nullptr,
2260 clang::ArraySizeModifier::Normal, 0));
2264 llvm::StringRef type_name,
2265 const std::initializer_list<std::pair<const char *, CompilerType>>
2269 if (!type_name.empty() &&
2270 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2272 lldbassert(0 &&
"Trying to create a type for an existing name");
2280 for (
const auto &field : type_fields)
2290 llvm::StringRef type_name,
2291 const std::initializer_list<std::pair<const char *, CompilerType>>
2295 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2301#pragma mark Enumeration Types
2304 llvm::StringRef name, clang::DeclContext *decl_ctx,
2306 const CompilerType &integer_clang_type,
bool is_scoped) {
2313 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
2314 enum_decl->setDeclContext(decl_ctx);
2316 enum_decl->setDeclName(&ast.Idents.get(name));
2317 enum_decl->setScoped(is_scoped);
2318 enum_decl->setScopedUsingClassTag(is_scoped);
2319 enum_decl->setFixed(
false);
2322 decl_ctx->addDecl(enum_decl);
2327 enum_decl->setAccess(AS_public);
2329 return GetType(ast.getTagDeclType(enum_decl));
2340 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2341 return GetType(ast.SignedCharTy);
2343 if (bit_size == ast.getTypeSize(ast.ShortTy))
2346 if (bit_size == ast.getTypeSize(ast.IntTy))
2349 if (bit_size == ast.getTypeSize(ast.LongTy))
2352 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2353 return GetType(ast.LongLongTy);
2355 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2358 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2359 return GetType(ast.UnsignedCharTy);
2361 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2362 return GetType(ast.UnsignedShortTy);
2364 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2365 return GetType(ast.UnsignedIntTy);
2367 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2368 return GetType(ast.UnsignedLongTy);
2370 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2371 return GetType(ast.UnsignedLongLongTy);
2373 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2374 return GetType(ast.UnsignedInt128Ty);
2391 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2393 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2394 named_decl->getDeclName().getAsString().c_str());
2396 printf(
"%20s\n", decl_ctx->getDeclKindName());
2402 if (decl ==
nullptr)
2406 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2408 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2409 record_decl->getDeclName().getAsString().c_str(),
2410 record_decl->isInjectedClassName() ?
" (injected class name)" :
"");
2413 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2415 printf(
"%20s: %s\n", decl->getDeclKindName(),
2416 named_decl->getDeclName().getAsString().c_str());
2418 printf(
"%20s\n", decl->getDeclKindName());
2424 clang::Decl *decl) {
2428 ExternalASTSource *ast_source = ast->getExternalSource();
2433 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2434 if (tag_decl->isCompleteDefinition())
2437 if (!tag_decl->hasExternalLexicalStorage())
2440 ast_source->CompleteType(tag_decl);
2442 return !tag_decl->getTypeForDecl()->isIncompleteType();
2443 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2444 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2445 if (objc_interface_decl->getDefinition())
2448 if (!objc_interface_decl->hasExternalLexicalStorage())
2451 ast_source->CompleteType(objc_interface_decl);
2453 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2483std::optional<ClangASTMetadata>
2489 return std::nullopt;
2492std::optional<ClangASTMetadata>
2498 return std::nullopt;
2502 clang::AccessSpecifier access) {
2503 if (access == clang::AccessSpecifier::AS_none)
2509clang::AccessSpecifier
2514 return clang::AccessSpecifier::AS_none;
2536 if (find(mask, type->getTypeClass()) != mask.end())
2538 switch (type->getTypeClass()) {
2541 case clang::Type::Atomic:
2542 type = cast<clang::AtomicType>(type)->getValueType();
2544 case clang::Type::Auto:
2545 case clang::Type::Decltype:
2546 case clang::Type::Elaborated:
2547 case clang::Type::Paren:
2548 case clang::Type::SubstTemplateTypeParm:
2549 case clang::Type::TemplateSpecialization:
2550 case clang::Type::Typedef:
2551 case clang::Type::TypeOf:
2552 case clang::Type::TypeOfExpr:
2553 case clang::Type::Using:
2554 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2568 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2569 switch (type_class) {
2570 case clang::Type::ObjCInterface:
2571 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2573 case clang::Type::ObjCObjectPointer:
2575 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2576 ->getPointeeType());
2577 case clang::Type::Record:
2578 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2579 case clang::Type::Enum:
2580 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2593 clang::QualType qual_type,
2594 bool allow_completion) {
2595 assert(qual_type->isRecordType());
2597 const auto *tag_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2599 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2603 if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
2606 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2607 const bool fields_loaded =
2608 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2611 if (is_complete && fields_loaded)
2614 if (!allow_completion)
2622 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2623 if (external_ast_source) {
2624 external_ast_source->CompleteType(cxx_record_decl);
2625 if (cxx_record_decl->isCompleteDefinition()) {
2626 cxx_record_decl->field_begin();
2627 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2639 clang::QualType qual_type,
2640 bool allow_completion) {
2641 assert(qual_type->isEnumeralType());
2644 const clang::EnumType *enum_type =
2645 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
2647 auto *tag_decl = enum_type->getAsTagDecl();
2651 if (tag_decl->getDefinition())
2654 if (!allow_completion)
2658 if (!tag_decl->hasExternalLexicalStorage())
2662 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2663 if (!external_ast_source)
2666 external_ast_source->CompleteType(tag_decl);
2674static const clang::ObjCObjectType *
2676 bool allow_completion) {
2677 assert(qual_type->isObjCObjectType());
2680 const clang::ObjCObjectType *objc_class_type =
2681 llvm::cast<clang::ObjCObjectType>(qual_type);
2683 clang::ObjCInterfaceDecl *class_interface_decl =
2684 objc_class_type->getInterface();
2687 if (!class_interface_decl)
2688 return objc_class_type;
2691 if (class_interface_decl->getDefinition())
2692 return objc_class_type;
2694 if (!allow_completion)
2698 if (!class_interface_decl->hasExternalLexicalStorage())
2702 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2703 if (!external_ast_source)
2706 external_ast_source->CompleteType(class_interface_decl);
2707 return objc_class_type;
2711 clang::QualType qual_type,
2712 bool allow_completion =
true) {
2714 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2715 switch (type_class) {
2716 case clang::Type::ConstantArray:
2717 case clang::Type::IncompleteArray:
2718 case clang::Type::VariableArray: {
2719 const clang::ArrayType *array_type =
2720 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2726 case clang::Type::Record: {
2727 if (
const auto *RT =
2729 return !RT->isIncompleteType();
2734 case clang::Type::Enum: {
2736 return !ET->isIncompleteType();
2740 case clang::Type::ObjCObject:
2741 case clang::Type::ObjCInterface: {
2742 if (
const auto *OT =
2744 return !OT->isIncompleteType();
2749 case clang::Type::Attributed:
2751 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2754 case clang::Type::MemberPointer:
2757 if (ast->getTargetInfo().getCXXABI().isMicrosoft()) {
2758 auto *MPT = qual_type.getTypePtr()->castAs<clang::MemberPointerType>();
2759 if (MPT->getClass()->isRecordType())
2763 return !qual_type.getTypePtr()->isIncompleteType();
2774static clang::ObjCIvarDecl::AccessControl
2778 return clang::ObjCIvarDecl::None;
2780 return clang::ObjCIvarDecl::Public;
2782 return clang::ObjCIvarDecl::Private;
2784 return clang::ObjCIvarDecl::Protected;
2786 return clang::ObjCIvarDecl::Package;
2788 return clang::ObjCIvarDecl::None;
2795 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2802 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2803 switch (type_class) {
2804 case clang::Type::IncompleteArray:
2805 case clang::Type::VariableArray:
2806 case clang::Type::ConstantArray:
2807 case clang::Type::ExtVector:
2808 case clang::Type::Vector:
2809 case clang::Type::Record:
2810 case clang::Type::ObjCObject:
2811 case clang::Type::ObjCInterface:
2823 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2824 switch (type_class) {
2825 case clang::Type::Record: {
2826 if (
const clang::RecordType *record_type =
2827 llvm::dyn_cast_or_null<clang::RecordType>(
2828 qual_type.getTypePtrOrNull())) {
2829 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2830 return record_decl->isAnonymousStructOrUnion();
2844 uint64_t *size,
bool *is_incomplete) {
2847 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2848 switch (type_class) {
2852 case clang::Type::ConstantArray:
2853 if (element_type_ptr)
2855 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2859 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2861 .getLimitedValue(ULLONG_MAX);
2863 *is_incomplete =
false;
2866 case clang::Type::IncompleteArray:
2867 if (element_type_ptr)
2869 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2875 *is_incomplete =
true;
2878 case clang::Type::VariableArray:
2879 if (element_type_ptr)
2881 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2887 *is_incomplete =
false;
2890 case clang::Type::DependentSizedArray:
2891 if (element_type_ptr)
2894 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2900 *is_incomplete =
false;
2903 if (element_type_ptr)
2904 element_type_ptr->
Clear();
2908 *is_incomplete =
false;
2916 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2917 switch (type_class) {
2918 case clang::Type::Vector: {
2919 const clang::VectorType *vector_type =
2920 qual_type->getAs<clang::VectorType>();
2923 *size = vector_type->getNumElements();
2925 *element_type =
GetType(vector_type->getElementType());
2929 case clang::Type::ExtVector: {
2930 const clang::ExtVectorType *ext_vector_type =
2931 qual_type->getAs<clang::ExtVectorType>();
2932 if (ext_vector_type) {
2934 *size = ext_vector_type->getNumElements();
2938 ext_vector_type->getElementType().getAsOpaquePtr());
2954 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2957 clang::ObjCInterfaceDecl *result_iface_decl =
2958 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2960 std::optional<ClangASTMetadata> ast_metadata =
GetMetadata(result_iface_decl);
2964 return (ast_metadata->GetISAPtr() != 0);
2968 return GetQualType(type).getUnqualifiedType()->isCharType();
2977 const bool allow_completion =
true;
2992 if (!pointee_or_element_clang_type.
IsValid())
2995 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2996 if (pointee_or_element_clang_type.
IsCharType()) {
2997 if (type_flags.
Test(eTypeIsArray)) {
3000 length = llvm::cast<clang::ConstantArrayType>(
3014 if (
auto pointer_auth = qual_type.getPointerAuth())
3015 return pointer_auth.getKey();
3024 if (
auto pointer_auth = qual_type.getPointerAuth())
3025 return pointer_auth.getExtraDiscriminator();
3034 if (
auto pointer_auth = qual_type.getPointerAuth())
3035 return pointer_auth.isAddressDiscriminated();
3041 auto isFunctionType = [&](clang::QualType qual_type) {
3042 return qual_type->isFunctionType();
3056 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3057 switch (type_class) {
3058 case clang::Type::Record:
3060 const clang::CXXRecordDecl *cxx_record_decl =
3061 qual_type->getAsCXXRecordDecl();
3062 if (cxx_record_decl) {
3063 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3066 const clang::RecordType *record_type =
3067 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3069 const clang::RecordDecl *record_decl = record_type->getDecl();
3073 clang::RecordDecl::field_iterator field_pos,
3074 field_end = record_decl->field_end();
3075 uint32_t num_fields = 0;
3076 bool is_hva =
false;
3077 bool is_hfa =
false;
3078 clang::QualType base_qual_type;
3079 uint64_t base_bitwidth = 0;
3080 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3082 clang::QualType field_qual_type = field_pos->getType();
3083 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
3084 if (field_qual_type->isFloatingType()) {
3085 if (field_qual_type->isComplexType())
3088 if (num_fields == 0)
3089 base_qual_type = field_qual_type;
3094 if (field_qual_type.getTypePtr() !=
3095 base_qual_type.getTypePtr())
3099 }
else if (field_qual_type->isVectorType() ||
3100 field_qual_type->isExtVectorType()) {
3101 if (num_fields == 0) {
3102 base_qual_type = field_qual_type;
3103 base_bitwidth = field_bitwidth;
3108 if (base_bitwidth != field_bitwidth)
3110 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3119 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3136 const clang::FunctionProtoType *func =
3137 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3139 return func->getNumParams();
3146 const size_t index) {
3149 const clang::FunctionProtoType *func =
3150 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3152 if (index < func->getNumParams())
3153 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3161 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3165 if (predicate(qual_type))
3168 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3169 switch (type_class) {
3173 case clang::Type::LValueReference:
3174 case clang::Type::RValueReference: {
3175 const clang::ReferenceType *reference_type =
3176 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3178 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3187 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3188 return qual_type->isMemberFunctionPointerType();
3191 return IsTypeImpl(type, isMemberFunctionPointerType);
3195 auto isFunctionPointerType = [](clang::QualType qual_type) {
3196 return qual_type->isFunctionPointerType();
3199 return IsTypeImpl(type, isFunctionPointerType);
3205 auto isBlockPointerType = [&](clang::QualType qual_type) {
3206 if (qual_type->isBlockPointerType()) {
3207 if (function_pointer_type_ptr) {
3208 const clang::BlockPointerType *block_pointer_type =
3209 qual_type->castAs<clang::BlockPointerType>();
3210 QualType pointee_type = block_pointer_type->getPointeeType();
3211 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3213 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3230 const clang::BuiltinType *builtin_type =
3231 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3234 if (builtin_type->isInteger()) {
3235 is_signed = builtin_type->isSignedInteger();
3246 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3250 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3262 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3266 return enum_type->isScopedEnumeralType();
3277 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3278 switch (type_class) {
3279 case clang::Type::Builtin:
3280 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3283 case clang::BuiltinType::ObjCId:
3284 case clang::BuiltinType::ObjCClass:
3288 case clang::Type::ObjCObjectPointer:
3292 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3296 case clang::Type::BlockPointer:
3299 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3303 case clang::Type::Pointer:
3306 llvm::cast<clang::PointerType>(qual_type)
3310 case clang::Type::MemberPointer:
3313 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3322 pointee_type->
Clear();
3330 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3331 switch (type_class) {
3332 case clang::Type::Builtin:
3333 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3336 case clang::BuiltinType::ObjCId:
3337 case clang::BuiltinType::ObjCClass:
3341 case clang::Type::ObjCObjectPointer:
3345 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3349 case clang::Type::BlockPointer:
3352 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3356 case clang::Type::Pointer:
3359 llvm::cast<clang::PointerType>(qual_type)
3363 case clang::Type::MemberPointer:
3366 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3370 case clang::Type::LValueReference:
3373 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3377 case clang::Type::RValueReference:
3380 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3389 pointee_type->
Clear();
3398 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3400 switch (type_class) {
3401 case clang::Type::LValueReference:
3404 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3410 case clang::Type::RValueReference:
3413 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3425 pointee_type->
Clear();
3430 uint32_t &count,
bool &is_complex) {
3434 if (
const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3435 qual_type->getCanonicalTypeInternal())) {
3436 clang::BuiltinType::Kind kind = BT->getKind();
3437 if (kind >= clang::BuiltinType::Float &&
3438 kind <= clang::BuiltinType::LongDouble) {
3443 }
else if (
const clang::ComplexType *CT =
3444 llvm::dyn_cast<clang::ComplexType>(
3445 qual_type->getCanonicalTypeInternal())) {
3452 }
else if (
const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3453 qual_type->getCanonicalTypeInternal())) {
3456 count = VT->getNumElements();
3472 const clang::TagType *tag_type =
3473 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3475 clang::TagDecl *tag_decl = tag_type->getDecl();
3477 return tag_decl->isCompleteDefinition();
3480 const clang::ObjCObjectType *objc_class_type =
3481 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3482 if (objc_class_type) {
3483 clang::ObjCInterfaceDecl *class_interface_decl =
3484 objc_class_type->getInterface();
3485 if (class_interface_decl)
3486 return class_interface_decl->getDefinition() !=
nullptr;
3497 const clang::ObjCObjectPointerType *obj_pointer_type =
3498 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3500 if (obj_pointer_type)
3501 return obj_pointer_type->isObjCClassType();
3516 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3517 return (type_class == clang::Type::Record);
3524 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3525 return (type_class == clang::Type::Enum);
3531 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3532 switch (type_class) {
3533 case clang::Type::Record:
3535 const clang::RecordType *record_type =
3536 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3537 const clang::RecordDecl *record_decl = record_type->getDecl();
3539 const clang::CXXRecordDecl *cxx_record_decl =
3540 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3541 if (cxx_record_decl) {
3548 return cxx_record_decl->isDynamicClass();
3563 bool check_cplusplus,
3565 clang::QualType pointee_qual_type;
3568 bool success =
false;
3569 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3570 switch (type_class) {
3571 case clang::Type::Builtin:
3573 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3574 clang::BuiltinType::ObjCId) {
3575 if (dynamic_pointee_type)
3581 case clang::Type::ObjCObjectPointer:
3583 if (
const auto *objc_pointee_type =
3584 qual_type->getPointeeType().getTypePtrOrNull()) {
3585 if (
const auto *objc_object_type =
3586 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3587 objc_pointee_type)) {
3588 if (objc_object_type->isObjCClass())
3592 if (dynamic_pointee_type)
3595 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3602 case clang::Type::Pointer:
3604 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3608 case clang::Type::LValueReference:
3609 case clang::Type::RValueReference:
3611 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3623 const clang::Type::TypeClass pointee_type_class =
3624 pointee_qual_type.getCanonicalType()->getTypeClass();
3625 switch (pointee_type_class) {
3626 case clang::Type::Builtin:
3627 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3628 case clang::BuiltinType::UnknownAny:
3629 case clang::BuiltinType::Void:
3630 if (dynamic_pointee_type)
3632 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3639 case clang::Type::Record:
3640 if (check_cplusplus) {
3641 clang::CXXRecordDecl *cxx_record_decl =
3642 pointee_qual_type->getAsCXXRecordDecl();
3643 if (cxx_record_decl) {
3644 bool is_complete = cxx_record_decl->isCompleteDefinition();
3647 success = cxx_record_decl->isDynamicClass();
3649 if (std::optional<ClangASTMetadata> metadata =
3651 success = metadata->GetIsDynamicCXXType();
3655 success = cxx_record_decl->isDynamicClass();
3662 if (dynamic_pointee_type)
3664 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3671 case clang::Type::ObjCObject:
3672 case clang::Type::ObjCInterface:
3674 if (dynamic_pointee_type)
3676 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3686 if (dynamic_pointee_type)
3687 dynamic_pointee_type->
Clear();
3695 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3702 ->getTypeClass() == clang::Type::Typedef;
3712 if (
auto *record_decl =
3714 return record_decl->canPassInRegisters();
3720 return TypeSystemClangSupportsLanguage(language);
3723std::optional<std::string>
3726 return std::nullopt;
3729 if (qual_type.isNull())
3730 return std::nullopt;
3732 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3733 if (!cxx_record_decl)
3734 return std::nullopt;
3736 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3744 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3751 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3753 return tag_type->isBeingDefined();
3764 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3765 if (class_type_ptr) {
3766 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3767 const clang::ObjCObjectPointerType *obj_pointer_type =
3768 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3769 if (obj_pointer_type ==
nullptr)
3770 class_type_ptr->
Clear();
3774 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3781 class_type_ptr->
Clear();
3790 const bool allow_completion =
true;
3810 {clang::Type::Typedef, clang::Type::Atomic});
3813 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3814 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3821 if (
auto *named_decl = qual_type->getAsTagDecl())
3833 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3834 printing_policy.SuppressTagKeyword =
true;
3835 printing_policy.SuppressScope =
false;
3836 printing_policy.SuppressUnwrittenScope =
true;
3837 printing_policy.SuppressInlineNamespace =
true;
3838 return ConstString(qual_type.getAsString(printing_policy));
3847 if (pointee_or_element_clang_type)
3848 pointee_or_element_clang_type->
Clear();
3850 clang::QualType qual_type =
3853 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3854 switch (type_class) {
3855 case clang::Type::Attributed:
3856 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3859 pointee_or_element_clang_type);
3860 case clang::Type::Builtin: {
3861 const clang::BuiltinType *builtin_type =
3862 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3864 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3865 switch (builtin_type->getKind()) {
3866 case clang::BuiltinType::ObjCId:
3867 case clang::BuiltinType::ObjCClass:
3868 if (pointee_or_element_clang_type)
3872 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3875 case clang::BuiltinType::ObjCSel:
3876 if (pointee_or_element_clang_type)
3879 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3882 case clang::BuiltinType::Bool:
3883 case clang::BuiltinType::Char_U:
3884 case clang::BuiltinType::UChar:
3885 case clang::BuiltinType::WChar_U:
3886 case clang::BuiltinType::Char16:
3887 case clang::BuiltinType::Char32:
3888 case clang::BuiltinType::UShort:
3889 case clang::BuiltinType::UInt:
3890 case clang::BuiltinType::ULong:
3891 case clang::BuiltinType::ULongLong:
3892 case clang::BuiltinType::UInt128:
3893 case clang::BuiltinType::Char_S:
3894 case clang::BuiltinType::SChar:
3895 case clang::BuiltinType::WChar_S:
3896 case clang::BuiltinType::Short:
3897 case clang::BuiltinType::Int:
3898 case clang::BuiltinType::Long:
3899 case clang::BuiltinType::LongLong:
3900 case clang::BuiltinType::Int128:
3901 case clang::BuiltinType::Float:
3902 case clang::BuiltinType::Double:
3903 case clang::BuiltinType::LongDouble:
3904 builtin_type_flags |= eTypeIsScalar;
3905 if (builtin_type->isInteger()) {
3906 builtin_type_flags |= eTypeIsInteger;
3907 if (builtin_type->isSignedInteger())
3908 builtin_type_flags |= eTypeIsSigned;
3909 }
else if (builtin_type->isFloatingPoint())
3910 builtin_type_flags |= eTypeIsFloat;
3915 return builtin_type_flags;
3918 case clang::Type::BlockPointer:
3919 if (pointee_or_element_clang_type)
3921 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3922 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3924 case clang::Type::Complex: {
3925 uint32_t complex_type_flags =
3926 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3927 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3928 qual_type->getCanonicalTypeInternal());
3930 clang::QualType complex_element_type(complex_type->getElementType());
3931 if (complex_element_type->isIntegerType())
3932 complex_type_flags |= eTypeIsFloat;
3933 else if (complex_element_type->isFloatingType())
3934 complex_type_flags |= eTypeIsInteger;
3936 return complex_type_flags;
3939 case clang::Type::ConstantArray:
3940 case clang::Type::DependentSizedArray:
3941 case clang::Type::IncompleteArray:
3942 case clang::Type::VariableArray:
3943 if (pointee_or_element_clang_type)
3945 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3948 return eTypeHasChildren | eTypeIsArray;
3950 case clang::Type::DependentName:
3952 case clang::Type::DependentSizedExtVector:
3953 return eTypeHasChildren | eTypeIsVector;
3954 case clang::Type::DependentTemplateSpecialization:
3955 return eTypeIsTemplate;
3957 case clang::Type::Enum:
3958 if (pointee_or_element_clang_type)
3960 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3964 return eTypeIsEnumeration | eTypeHasValue;
3966 case clang::Type::FunctionProto:
3967 return eTypeIsFuncPrototype | eTypeHasValue;
3968 case clang::Type::FunctionNoProto:
3969 return eTypeIsFuncPrototype | eTypeHasValue;
3970 case clang::Type::InjectedClassName:
3973 case clang::Type::LValueReference:
3974 case clang::Type::RValueReference:
3975 if (pointee_or_element_clang_type)
3978 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3981 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3983 case clang::Type::MemberPointer:
3984 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3986 case clang::Type::ObjCObjectPointer:
3987 if (pointee_or_element_clang_type)
3989 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3990 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3993 case clang::Type::ObjCObject:
3994 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3995 case clang::Type::ObjCInterface:
3996 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3998 case clang::Type::Pointer:
3999 if (pointee_or_element_clang_type)
4001 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
4002 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
4004 case clang::Type::Record:
4005 if (qual_type->getAsCXXRecordDecl())
4006 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
4008 return eTypeHasChildren | eTypeIsStructUnion;
4010 case clang::Type::SubstTemplateTypeParm:
4011 return eTypeIsTemplate;
4012 case clang::Type::TemplateTypeParm:
4013 return eTypeIsTemplate;
4014 case clang::Type::TemplateSpecialization:
4015 return eTypeIsTemplate;
4017 case clang::Type::Typedef:
4018 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
4020 ->getUnderlyingType())
4022 case clang::Type::UnresolvedUsing:
4025 case clang::Type::ExtVector:
4026 case clang::Type::Vector: {
4027 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4028 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
4029 qual_type->getCanonicalTypeInternal());
4031 if (vector_type->isIntegerType())
4032 vector_type_flags |= eTypeIsFloat;
4033 else if (vector_type->isFloatingType())
4034 vector_type_flags |= eTypeIsInteger;
4036 return vector_type_flags;
4051 if (qual_type->isAnyPointerType()) {
4052 if (qual_type->isObjCObjectPointerType())
4054 if (qual_type->getPointeeCXXRecordDecl())
4057 clang::QualType pointee_type(qual_type->getPointeeType());
4058 if (pointee_type->getPointeeCXXRecordDecl())
4060 if (pointee_type->isObjCObjectOrInterfaceType())
4062 if (pointee_type->isObjCClassType())
4064 if (pointee_type.getTypePtr() ==
4068 if (qual_type->isObjCObjectOrInterfaceType())
4070 if (qual_type->getAsCXXRecordDecl())
4072 switch (qual_type->getTypeClass()) {
4075 case clang::Type::Builtin:
4076 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4078 case clang::BuiltinType::Void:
4079 case clang::BuiltinType::Bool:
4080 case clang::BuiltinType::Char_U:
4081 case clang::BuiltinType::UChar:
4082 case clang::BuiltinType::WChar_U:
4083 case clang::BuiltinType::Char16:
4084 case clang::BuiltinType::Char32:
4085 case clang::BuiltinType::UShort:
4086 case clang::BuiltinType::UInt:
4087 case clang::BuiltinType::ULong:
4088 case clang::BuiltinType::ULongLong:
4089 case clang::BuiltinType::UInt128:
4090 case clang::BuiltinType::Char_S:
4091 case clang::BuiltinType::SChar:
4092 case clang::BuiltinType::WChar_S:
4093 case clang::BuiltinType::Short:
4094 case clang::BuiltinType::Int:
4095 case clang::BuiltinType::Long:
4096 case clang::BuiltinType::LongLong:
4097 case clang::BuiltinType::Int128:
4098 case clang::BuiltinType::Float:
4099 case clang::BuiltinType::Double:
4100 case clang::BuiltinType::LongDouble:
4103 case clang::BuiltinType::NullPtr:
4106 case clang::BuiltinType::ObjCId:
4107 case clang::BuiltinType::ObjCClass:
4108 case clang::BuiltinType::ObjCSel:
4111 case clang::BuiltinType::Dependent:
4112 case clang::BuiltinType::Overload:
4113 case clang::BuiltinType::BoundMember:
4114 case clang::BuiltinType::UnknownAny:
4118 case clang::Type::Typedef:
4119 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4121 ->getUnderlyingType())
4131 return lldb::eTypeClassInvalid;
4133 clang::QualType qual_type =
4136 switch (qual_type->getTypeClass()) {
4137 case clang::Type::Atomic:
4138 case clang::Type::Auto:
4139 case clang::Type::CountAttributed:
4140 case clang::Type::Decltype:
4141 case clang::Type::Elaborated:
4142 case clang::Type::Paren:
4143 case clang::Type::TypeOf:
4144 case clang::Type::TypeOfExpr:
4145 case clang::Type::Using:
4146 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4147 case clang::Type::UnaryTransform:
4149 case clang::Type::FunctionNoProto:
4150 return lldb::eTypeClassFunction;
4151 case clang::Type::FunctionProto:
4152 return lldb::eTypeClassFunction;
4153 case clang::Type::IncompleteArray:
4154 return lldb::eTypeClassArray;
4155 case clang::Type::VariableArray:
4156 return lldb::eTypeClassArray;
4157 case clang::Type::ConstantArray:
4158 return lldb::eTypeClassArray;
4159 case clang::Type::DependentSizedArray:
4160 return lldb::eTypeClassArray;
4161 case clang::Type::ArrayParameter:
4162 return lldb::eTypeClassArray;
4163 case clang::Type::DependentSizedExtVector:
4164 return lldb::eTypeClassVector;
4165 case clang::Type::DependentVector:
4166 return lldb::eTypeClassVector;
4167 case clang::Type::ExtVector:
4168 return lldb::eTypeClassVector;
4169 case clang::Type::Vector:
4170 return lldb::eTypeClassVector;
4171 case clang::Type::Builtin:
4173 case clang::Type::BitInt:
4174 case clang::Type::DependentBitInt:
4175 return lldb::eTypeClassBuiltin;
4176 case clang::Type::ObjCObjectPointer:
4177 return lldb::eTypeClassObjCObjectPointer;
4178 case clang::Type::BlockPointer:
4179 return lldb::eTypeClassBlockPointer;
4180 case clang::Type::Pointer:
4181 return lldb::eTypeClassPointer;
4182 case clang::Type::LValueReference:
4183 return lldb::eTypeClassReference;
4184 case clang::Type::RValueReference:
4185 return lldb::eTypeClassReference;
4186 case clang::Type::MemberPointer:
4187 return lldb::eTypeClassMemberPointer;
4188 case clang::Type::Complex:
4189 if (qual_type->isComplexType())
4190 return lldb::eTypeClassComplexFloat;
4192 return lldb::eTypeClassComplexInteger;
4193 case clang::Type::ObjCObject:
4194 return lldb::eTypeClassObjCObject;
4195 case clang::Type::ObjCInterface:
4196 return lldb::eTypeClassObjCInterface;
4197 case clang::Type::Record: {
4198 const clang::RecordType *record_type =
4199 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4200 const clang::RecordDecl *record_decl = record_type->getDecl();
4201 if (record_decl->isUnion())
4202 return lldb::eTypeClassUnion;
4203 else if (record_decl->isStruct())
4204 return lldb::eTypeClassStruct;
4206 return lldb::eTypeClassClass;
4208 case clang::Type::Enum:
4209 return lldb::eTypeClassEnumeration;
4210 case clang::Type::Typedef:
4211 return lldb::eTypeClassTypedef;
4212 case clang::Type::UnresolvedUsing:
4215 case clang::Type::Attributed:
4216 case clang::Type::BTFTagAttributed:
4218 case clang::Type::TemplateTypeParm:
4220 case clang::Type::SubstTemplateTypeParm:
4222 case clang::Type::SubstTemplateTypeParmPack:
4224 case clang::Type::InjectedClassName:
4226 case clang::Type::DependentName:
4228 case clang::Type::DependentTemplateSpecialization:
4230 case clang::Type::PackExpansion:
4233 case clang::Type::TemplateSpecialization:
4235 case clang::Type::DeducedTemplateSpecialization:
4237 case clang::Type::Pipe:
4241 case clang::Type::Decayed:
4243 case clang::Type::Adjusted:
4245 case clang::Type::ObjCTypeParam:
4248 case clang::Type::DependentAddressSpace:
4250 case clang::Type::MacroQualified:
4254 case clang::Type::ConstantMatrix:
4255 case clang::Type::DependentSizedMatrix:
4259 case clang::Type::PackIndexing:
4262 case clang::Type::HLSLAttributedResource:
4266 return lldb::eTypeClassOther;
4271 return GetQualType(type).getQualifiers().getCVRQualifiers();
4283 const clang::Type *array_eletype =
4284 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4289 return GetType(clang::QualType(array_eletype, 0));
4300 return GetType(ast_ctx.getConstantArrayType(
4301 qual_type, llvm::APInt(64, size),
nullptr,
4302 clang::ArraySizeModifier::Normal, 0));
4304 return GetType(ast_ctx.getIncompleteArrayType(
4305 qual_type, clang::ArraySizeModifier::Normal, 0));
4319 clang::QualType qual_type) {
4320 if (qual_type->isPointerType())
4321 qual_type = ast->getPointerType(
4323 else if (
const ConstantArrayType *arr =
4324 ast->getAsConstantArrayType(qual_type)) {
4325 qual_type = ast->getConstantArrayType(
4327 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4328 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4330 qual_type = qual_type.getUnqualifiedType();
4331 qual_type.removeLocalConst();
4332 qual_type.removeLocalRestrict();
4333 qual_type.removeLocalVolatile();
4355 const clang::FunctionProtoType *func =
4358 return func->getNumParams();
4366 const clang::FunctionProtoType *func =
4367 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4369 const uint32_t num_args = func->getNumParams();
4371 return GetType(func->getParamType(idx));
4381 const clang::FunctionProtoType *func =
4382 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4384 return GetType(func->getReturnType());
4391 size_t num_functions = 0;
4394 switch (qual_type->getTypeClass()) {
4395 case clang::Type::Record:
4397 const clang::RecordType *record_type =
4398 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4399 const clang::RecordDecl *record_decl = record_type->getDecl();
4400 assert(record_decl);
4401 const clang::CXXRecordDecl *cxx_record_decl =
4402 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4403 if (cxx_record_decl)
4404 num_functions = std::distance(cxx_record_decl->method_begin(),
4405 cxx_record_decl->method_end());
4409 case clang::Type::ObjCObjectPointer: {
4410 const clang::ObjCObjectPointerType *objc_class_type =
4411 qual_type->castAs<clang::ObjCObjectPointerType>();
4412 const clang::ObjCInterfaceType *objc_interface_type =
4413 objc_class_type->getInterfaceType();
4414 if (objc_interface_type &&
4416 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4417 clang::ObjCInterfaceDecl *class_interface_decl =
4418 objc_interface_type->getDecl();
4419 if (class_interface_decl) {
4420 num_functions = std::distance(class_interface_decl->meth_begin(),
4421 class_interface_decl->meth_end());
4427 case clang::Type::ObjCObject:
4428 case clang::Type::ObjCInterface:
4430 const clang::ObjCObjectType *objc_class_type =
4431 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4432 if (objc_class_type) {
4433 clang::ObjCInterfaceDecl *class_interface_decl =
4434 objc_class_type->getInterface();
4435 if (class_interface_decl)
4436 num_functions = std::distance(class_interface_decl->meth_begin(),
4437 class_interface_decl->meth_end());
4446 return num_functions;
4458 switch (qual_type->getTypeClass()) {
4459 case clang::Type::Record:
4461 const clang::RecordType *record_type =
4462 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4463 const clang::RecordDecl *record_decl = record_type->getDecl();
4464 assert(record_decl);
4465 const clang::CXXRecordDecl *cxx_record_decl =
4466 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4467 if (cxx_record_decl) {
4468 auto method_iter = cxx_record_decl->method_begin();
4469 auto method_end = cxx_record_decl->method_end();
4471 static_cast<size_t>(std::distance(method_iter, method_end))) {
4472 std::advance(method_iter, idx);
4473 clang::CXXMethodDecl *cxx_method_decl =
4474 method_iter->getCanonicalDecl();
4475 if (cxx_method_decl) {
4476 name = cxx_method_decl->getDeclName().getAsString();
4477 if (cxx_method_decl->isStatic())
4479 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4481 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4485 clang_type =
GetType(cxx_method_decl->getType());
4493 case clang::Type::ObjCObjectPointer: {
4494 const clang::ObjCObjectPointerType *objc_class_type =
4495 qual_type->castAs<clang::ObjCObjectPointerType>();
4496 const clang::ObjCInterfaceType *objc_interface_type =
4497 objc_class_type->getInterfaceType();
4498 if (objc_interface_type &&
4500 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4501 clang::ObjCInterfaceDecl *class_interface_decl =
4502 objc_interface_type->getDecl();
4503 if (class_interface_decl) {
4504 auto method_iter = class_interface_decl->meth_begin();
4505 auto method_end = class_interface_decl->meth_end();
4507 static_cast<size_t>(std::distance(method_iter, method_end))) {
4508 std::advance(method_iter, idx);
4509 clang::ObjCMethodDecl *objc_method_decl =
4510 method_iter->getCanonicalDecl();
4511 if (objc_method_decl) {
4513 name = objc_method_decl->getSelector().getAsString();
4514 if (objc_method_decl->isClassMethod())
4525 case clang::Type::ObjCObject:
4526 case clang::Type::ObjCInterface:
4528 const clang::ObjCObjectType *objc_class_type =
4529 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4530 if (objc_class_type) {
4531 clang::ObjCInterfaceDecl *class_interface_decl =
4532 objc_class_type->getInterface();
4533 if (class_interface_decl) {
4534 auto method_iter = class_interface_decl->meth_begin();
4535 auto method_end = class_interface_decl->meth_end();
4537 static_cast<size_t>(std::distance(method_iter, method_end))) {
4538 std::advance(method_iter, idx);
4539 clang::ObjCMethodDecl *objc_method_decl =
4540 method_iter->getCanonicalDecl();
4541 if (objc_method_decl) {
4543 name = objc_method_decl->getSelector().getAsString();
4544 if (objc_method_decl->isClassMethod())
4577 return GetType(qual_type.getTypePtr()->getPointeeType());
4587 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4588 case clang::Type::ObjCObject:
4589 case clang::Type::ObjCInterface:
4636 auto pauth = PointerAuthQualifier::fromOpaqueValue(payload);
4637 clang::QualType result =
4638 clang_ast.getPointerAuthType(
GetQualType(type), pauth);
4648 result.addVolatile();
4658 result.addRestrict();
4667 if (type && typedef_name && typedef_name[0]) {
4671 clang::DeclContext *decl_ctx =
4676 clang::TypedefDecl *decl =
4677 clang::TypedefDecl::CreateDeserialized(clang_ast, GlobalDeclID());
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);
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();
4695 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4696 tdecl->setTypedefNameForAnonDecl(decl);
4698 decl->setAccess(clang::AS_public);
4701 return GetType(clang_ast.getTypedefType(decl));
4709 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4712 return GetType(typedef_type->getDecl()->getUnderlyingType());
4725 const FunctionType::ExtInfo generic_ext_info(
4734 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4739const llvm::fltSemantics &
4742 const size_t bit_size = byte_size * 8;
4743 if (bit_size == ast.getTypeSize(ast.FloatTy))
4744 return ast.getFloatTypeSemantics(ast.FloatTy);
4745 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4746 return ast.getFloatTypeSemantics(ast.DoubleTy);
4747 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4748 bit_size == llvm::APFloat::semanticsSizeInBits(
4749 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4750 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4751 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4752 return ast.getFloatTypeSemantics(ast.HalfTy);
4753 return llvm::APFloatBase::Bogus();
4756std::optional<uint64_t>
4759 assert(qual_type->isObjCObjectOrInterfaceType());
4764 if (std::optional<uint64_t> bit_size =
4765 objc_runtime->GetTypeBitSize(
GetType(qual_type)))
4769 static bool g_printed =
false;
4774 llvm::outs() <<
"warning: trying to determine the size of type ";
4776 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4777 "reliable. please file a bug against LLDB.\n";
4778 llvm::outs() <<
"backtrace:\n";
4779 llvm::sys::PrintStackTrace(llvm::outs());
4780 llvm::outs() <<
"\n";
4789std::optional<uint64_t>
4793 return std::nullopt;
4796 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4797 switch (type_class) {
4798 case clang::Type::ConstantArray:
4799 case clang::Type::FunctionProto:
4800 case clang::Type::Record:
4802 case clang::Type::ObjCInterface:
4803 case clang::Type::ObjCObject:
4805 case clang::Type::IncompleteArray: {
4806 const uint64_t bit_size =
getASTContext().getTypeSize(qual_type);
4809 qual_type->getArrayElementTypeNoTypeQual()
4810 ->getCanonicalTypeUnqualified());
4815 if (
const uint64_t bit_size =
getASTContext().getTypeSize(qual_type))
4819 return std::nullopt;
4822std::optional<size_t>
4838 switch (qual_type->getTypeClass()) {
4839 case clang::Type::Atomic:
4840 case clang::Type::Auto:
4841 case clang::Type::CountAttributed:
4842 case clang::Type::Decltype:
4843 case clang::Type::Elaborated:
4844 case clang::Type::Paren:
4845 case clang::Type::Typedef:
4846 case clang::Type::TypeOf:
4847 case clang::Type::TypeOfExpr:
4848 case clang::Type::Using:
4849 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4851 case clang::Type::UnaryTransform:
4854 case clang::Type::FunctionNoProto:
4855 case clang::Type::FunctionProto:
4858 case clang::Type::IncompleteArray:
4859 case clang::Type::VariableArray:
4860 case clang::Type::ArrayParameter:
4863 case clang::Type::ConstantArray:
4866 case clang::Type::DependentVector:
4867 case clang::Type::ExtVector:
4868 case clang::Type::Vector:
4872 case clang::Type::BitInt:
4873 case clang::Type::DependentBitInt:
4877 case clang::Type::Builtin:
4878 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4879 case clang::BuiltinType::Void:
4882 case clang::BuiltinType::Char_S:
4883 case clang::BuiltinType::SChar:
4884 case clang::BuiltinType::WChar_S:
4885 case clang::BuiltinType::Short:
4886 case clang::BuiltinType::Int:
4887 case clang::BuiltinType::Long:
4888 case clang::BuiltinType::LongLong:
4889 case clang::BuiltinType::Int128:
4892 case clang::BuiltinType::Bool:
4893 case clang::BuiltinType::Char_U:
4894 case clang::BuiltinType::UChar:
4895 case clang::BuiltinType::WChar_U:
4896 case clang::BuiltinType::Char8:
4897 case clang::BuiltinType::Char16:
4898 case clang::BuiltinType::Char32:
4899 case clang::BuiltinType::UShort:
4900 case clang::BuiltinType::UInt:
4901 case clang::BuiltinType::ULong:
4902 case clang::BuiltinType::ULongLong:
4903 case clang::BuiltinType::UInt128:
4907 case clang::BuiltinType::ShortAccum:
4908 case clang::BuiltinType::Accum:
4909 case clang::BuiltinType::LongAccum:
4910 case clang::BuiltinType::UShortAccum:
4911 case clang::BuiltinType::UAccum:
4912 case clang::BuiltinType::ULongAccum:
4913 case clang::BuiltinType::ShortFract:
4914 case clang::BuiltinType::Fract:
4915 case clang::BuiltinType::LongFract:
4916 case clang::BuiltinType::UShortFract:
4917 case clang::BuiltinType::UFract:
4918 case clang::BuiltinType::ULongFract:
4919 case clang::BuiltinType::SatShortAccum:
4920 case clang::BuiltinType::SatAccum:
4921 case clang::BuiltinType::SatLongAccum:
4922 case clang::BuiltinType::SatUShortAccum:
4923 case clang::BuiltinType::SatUAccum:
4924 case clang::BuiltinType::SatULongAccum:
4925 case clang::BuiltinType::SatShortFract:
4926 case clang::BuiltinType::SatFract:
4927 case clang::BuiltinType::SatLongFract:
4928 case clang::BuiltinType::SatUShortFract:
4929 case clang::BuiltinType::SatUFract:
4930 case clang::BuiltinType::SatULongFract:
4933 case clang::BuiltinType::Half:
4934 case clang::BuiltinType::Float:
4935 case clang::BuiltinType::Float16:
4936 case clang::BuiltinType::Float128:
4937 case clang::BuiltinType::Double:
4938 case clang::BuiltinType::LongDouble:
4939 case clang::BuiltinType::BFloat16:
4940 case clang::BuiltinType::Ibm128:
4943 case clang::BuiltinType::ObjCClass:
4944 case clang::BuiltinType::ObjCId:
4945 case clang::BuiltinType::ObjCSel:
4948 case clang::BuiltinType::NullPtr:
4951 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4952 case clang::BuiltinType::Kind::BoundMember:
4953 case clang::BuiltinType::Kind::BuiltinFn:
4954 case clang::BuiltinType::Kind::Dependent:
4955 case clang::BuiltinType::Kind::OCLClkEvent:
4956 case clang::BuiltinType::Kind::OCLEvent:
4957 case clang::BuiltinType::Kind::OCLImage1dRO:
4958 case clang::BuiltinType::Kind::OCLImage1dWO:
4959 case clang::BuiltinType::Kind::OCLImage1dRW:
4960 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4961 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4962 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4963 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4964 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4965 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4966 case clang::BuiltinType::Kind::OCLImage2dRO:
4967 case clang::BuiltinType::Kind::OCLImage2dWO:
4968 case clang::BuiltinType::Kind::OCLImage2dRW:
4969 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4970 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4971 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4972 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4973 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4974 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4975 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4976 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4977 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4978 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4979 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4980 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4981 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4982 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4983 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4984 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4985 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4986 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4987 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4988 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4989 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4990 case clang::BuiltinType::Kind::OCLImage3dRO:
4991 case clang::BuiltinType::Kind::OCLImage3dWO:
4992 case clang::BuiltinType::Kind::OCLImage3dRW:
4993 case clang::BuiltinType::Kind::OCLQueue:
4994 case clang::BuiltinType::Kind::OCLReserveID:
4995 case clang::BuiltinType::Kind::OCLSampler:
4996 case clang::BuiltinType::Kind::HLSLResource:
4997 case clang::BuiltinType::Kind::ArraySection:
4998 case clang::BuiltinType::Kind::OMPArrayShaping:
4999 case clang::BuiltinType::Kind::OMPIterator:
5000 case clang::BuiltinType::Kind::Overload:
5001 case clang::BuiltinType::Kind::PseudoObject:
5002 case clang::BuiltinType::Kind::UnknownAny:
5005 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
5006 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
5007 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
5008 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
5009 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
5010 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
5011 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
5012 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
5013 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
5014 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
5015 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
5016 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
5020 case clang::BuiltinType::VectorPair:
5021 case clang::BuiltinType::VectorQuad:
5025#define SVE_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5026#include "clang/Basic/AArch64SVEACLETypes.def"
5030#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5031#include "clang/Basic/RISCVVTypes.def"
5035 case clang::BuiltinType::WasmExternRef:
5038 case clang::BuiltinType::IncompleteMatrixIdx:
5041 case clang::BuiltinType::UnresolvedTemplate:
5045#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
5046 case clang::BuiltinType::Id:
5047#include "clang/Basic/AMDGPUTypes.def"
5053 case clang::Type::ObjCObjectPointer:
5054 case clang::Type::BlockPointer:
5055 case clang::Type::Pointer:
5056 case clang::Type::LValueReference:
5057 case clang::Type::RValueReference:
5058 case clang::Type::MemberPointer:
5060 case clang::Type::Complex: {
5062 if (qual_type->isComplexType())
5065 const clang::ComplexType *complex_type =
5066 qual_type->getAsComplexIntegerType();
5076 case clang::Type::ObjCInterface:
5078 case clang::Type::Record:
5080 case clang::Type::Enum:
5081 return qual_type->isUnsignedIntegerOrEnumerationType()
5084 case clang::Type::DependentSizedArray:
5085 case clang::Type::DependentSizedExtVector:
5086 case clang::Type::UnresolvedUsing:
5087 case clang::Type::Attributed:
5088 case clang::Type::BTFTagAttributed:
5089 case clang::Type::TemplateTypeParm:
5090 case clang::Type::SubstTemplateTypeParm:
5091 case clang::Type::SubstTemplateTypeParmPack:
5092 case clang::Type::InjectedClassName:
5093 case clang::Type::DependentName:
5094 case clang::Type::DependentTemplateSpecialization:
5095 case clang::Type::PackExpansion:
5096 case clang::Type::ObjCObject:
5098 case clang::Type::TemplateSpecialization:
5099 case clang::Type::DeducedTemplateSpecialization:
5100 case clang::Type::Adjusted:
5101 case clang::Type::Pipe:
5105 case clang::Type::Decayed:
5107 case clang::Type::ObjCTypeParam:
5110 case clang::Type::DependentAddressSpace:
5112 case clang::Type::MacroQualified:
5115 case clang::Type::ConstantMatrix:
5116 case clang::Type::DependentSizedMatrix:
5120 case clang::Type::PackIndexing:
5123 case clang::Type::HLSLAttributedResource:
5136 switch (qual_type->getTypeClass()) {
5137 case clang::Type::Atomic:
5138 case clang::Type::Auto:
5139 case clang::Type::CountAttributed:
5140 case clang::Type::Decltype:
5141 case clang::Type::Elaborated:
5142 case clang::Type::Paren:
5143 case clang::Type::Typedef:
5144 case clang::Type::TypeOf:
5145 case clang::Type::TypeOfExpr:
5146 case clang::Type::Using:
5147 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5148 case clang::Type::UnaryTransform:
5151 case clang::Type::FunctionNoProto:
5152 case clang::Type::FunctionProto:
5155 case clang::Type::IncompleteArray:
5156 case clang::Type::VariableArray:
5157 case clang::Type::ArrayParameter:
5160 case clang::Type::ConstantArray:
5163 case clang::Type::DependentVector:
5164 case clang::Type::ExtVector:
5165 case clang::Type::Vector:
5168 case clang::Type::BitInt:
5169 case clang::Type::DependentBitInt:
5173 case clang::Type::Builtin:
5174 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5175 case clang::BuiltinType::UnknownAny:
5176 case clang::BuiltinType::Void:
5177 case clang::BuiltinType::BoundMember:
5180 case clang::BuiltinType::Bool:
5182 case clang::BuiltinType::Char_S:
5183 case clang::BuiltinType::SChar:
5184 case clang::BuiltinType::WChar_S:
5185 case clang::BuiltinType::Char_U:
5186 case clang::BuiltinType::UChar:
5187 case clang::BuiltinType::WChar_U:
5189 case clang::BuiltinType::Char8:
5191 case clang::BuiltinType::Char16:
5193 case clang::BuiltinType::Char32:
5195 case clang::BuiltinType::UShort:
5197 case clang::BuiltinType::Short:
5199 case clang::BuiltinType::UInt:
5201 case clang::BuiltinType::Int:
5203 case clang::BuiltinType::ULong:
5205 case clang::BuiltinType::Long:
5207 case clang::BuiltinType::ULongLong:
5209 case clang::BuiltinType::LongLong:
5211 case clang::BuiltinType::UInt128:
5213 case clang::BuiltinType::Int128:
5215 case clang::BuiltinType::Half:
5216 case clang::BuiltinType::Float:
5217 case clang::BuiltinType::Double:
5218 case clang::BuiltinType::LongDouble:
5224 case clang::Type::ObjCObjectPointer:
5226 case clang::Type::BlockPointer:
5228 case clang::Type::Pointer:
5230 case clang::Type::LValueReference:
5231 case clang::Type::RValueReference:
5233 case clang::Type::MemberPointer:
5235 case clang::Type::Complex: {
5236 if (qual_type->isComplexType())
5241 case clang::Type::ObjCInterface:
5243 case clang::Type::Record:
5245 case clang::Type::Enum:
5247 case clang::Type::DependentSizedArray:
5248 case clang::Type::DependentSizedExtVector:
5249 case clang::Type::UnresolvedUsing:
5250 case clang::Type::Attributed:
5251 case clang::Type::BTFTagAttributed:
5252 case clang::Type::TemplateTypeParm:
5253 case clang::Type::SubstTemplateTypeParm:
5254 case clang::Type::SubstTemplateTypeParmPack:
5255 case clang::Type::InjectedClassName:
5256 case clang::Type::DependentName:
5257 case clang::Type::DependentTemplateSpecialization:
5258 case clang::Type::PackExpansion:
5259 case clang::Type::ObjCObject:
5261 case clang::Type::TemplateSpecialization:
5262 case clang::Type::DeducedTemplateSpecialization:
5263 case clang::Type::Adjusted:
5264 case clang::Type::Pipe:
5268 case clang::Type::Decayed:
5270 case clang::Type::ObjCTypeParam:
5273 case clang::Type::DependentAddressSpace:
5275 case clang::Type::MacroQualified:
5279 case clang::Type::ConstantMatrix:
5280 case clang::Type::DependentSizedMatrix:
5284 case clang::Type::PackIndexing:
5287 case clang::Type::HLSLAttributedResource:
5295 bool check_superclass) {
5296 while (class_interface_decl) {
5297 if (class_interface_decl->ivar_size() > 0)
5300 if (check_superclass)
5301 class_interface_decl = class_interface_decl->getSuperClass();
5308static std::optional<SymbolFile::ArrayInfo>
5310 clang::QualType qual_type,
5312 if (qual_type->isIncompleteArrayType())
5313 if (std::optional<ClangASTMetadata> metadata =
5317 return std::nullopt;
5320llvm::Expected<uint32_t>
5322 bool omit_empty_base_classes,
5325 return llvm::createStringError(
"invalid clang type");
5327 uint32_t num_children = 0;
5329 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5330 switch (type_class) {
5331 case clang::Type::Builtin:
5332 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5333 case clang::BuiltinType::ObjCId:
5334 case clang::BuiltinType::ObjCClass:
5343 case clang::Type::Complex:
5345 case clang::Type::Record:
5347 const clang::RecordType *record_type =
5348 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5349 const clang::RecordDecl *record_decl = record_type->getDecl();
5350 assert(record_decl);
5351 const clang::CXXRecordDecl *cxx_record_decl =
5352 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5353 if (cxx_record_decl) {
5354 if (omit_empty_base_classes) {
5358 clang::CXXRecordDecl::base_class_const_iterator base_class,
5360 for (base_class = cxx_record_decl->bases_begin(),
5361 base_class_end = cxx_record_decl->bases_end();
5362 base_class != base_class_end; ++base_class) {
5363 const clang::CXXRecordDecl *base_class_decl =
5364 llvm::cast<clang::CXXRecordDecl>(
5365 base_class->getType()
5366 ->getAs<clang::RecordType>()
5377 num_children += cxx_record_decl->getNumBases();
5380 num_children += std::distance(record_decl->field_begin(),
5381 record_decl->field_end());
5383 return llvm::createStringError(
5386 case clang::Type::ObjCObject:
5387 case clang::Type::ObjCInterface:
5389 const clang::ObjCObjectType *objc_class_type =
5390 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5391 assert(objc_class_type);
5392 if (objc_class_type) {
5393 clang::ObjCInterfaceDecl *class_interface_decl =
5394 objc_class_type->getInterface();
5396 if (class_interface_decl) {
5398 clang::ObjCInterfaceDecl *superclass_interface_decl =
5399 class_interface_decl->getSuperClass();
5400 if (superclass_interface_decl) {
5401 if (omit_empty_base_classes) {
5408 num_children += class_interface_decl->ivar_size();
5414 case clang::Type::LValueReference:
5415 case clang::Type::RValueReference:
5416 case clang::Type::ObjCObjectPointer: {
5419 uint32_t num_pointee_children = 0;
5421 auto num_children_or_err =
5422 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5423 if (!num_children_or_err)
5424 return num_children_or_err;
5425 num_pointee_children = *num_children_or_err;
5428 if (num_pointee_children == 0)
5431 num_children = num_pointee_children;
5434 case clang::Type::Vector:
5435 case clang::Type::ExtVector:
5437 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5440 case clang::Type::ConstantArray:
5441 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5445 case clang::Type::IncompleteArray:
5446 if (
auto array_info =
5449 num_children = array_info->element_orders.size()
5450 ? array_info->element_orders.back().value_or(0)
5454 case clang::Type::Pointer: {
5455 const clang::PointerType *pointer_type =
5456 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5457 clang::QualType pointee_type(pointer_type->getPointeeType());
5459 uint32_t num_pointee_children = 0;
5461 auto num_children_or_err =
5462 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5463 if (!num_children_or_err)
5464 return num_children_or_err;
5465 num_pointee_children = *num_children_or_err;
5467 if (num_pointee_children == 0) {
5472 num_children = num_pointee_children;
5478 return num_children;
5489 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5490 if (type_class == clang::Type::Builtin) {
5491 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5492 case clang::BuiltinType::Void:
5494 case clang::BuiltinType::Bool:
5496 case clang::BuiltinType::Char_S:
5498 case clang::BuiltinType::Char_U:
5500 case clang::BuiltinType::Char8:
5502 case clang::BuiltinType::Char16:
5504 case clang::BuiltinType::Char32:
5506 case clang::BuiltinType::UChar:
5508 case clang::BuiltinType::SChar:
5510 case clang::BuiltinType::WChar_S:
5512 case clang::BuiltinType::WChar_U:
5514 case clang::BuiltinType::Short:
5516 case clang::BuiltinType::UShort:
5518 case clang::BuiltinType::Int:
5520 case clang::BuiltinType::UInt:
5522 case clang::BuiltinType::Long:
5524 case clang::BuiltinType::ULong:
5526 case clang::BuiltinType::LongLong:
5528 case clang::BuiltinType::ULongLong:
5530 case clang::BuiltinType::Int128:
5532 case clang::BuiltinType::UInt128:
5535 case clang::BuiltinType::Half:
5537 case clang::BuiltinType::Float:
5539 case clang::BuiltinType::Double:
5541 case clang::BuiltinType::LongDouble:
5544 case clang::BuiltinType::NullPtr:
5546 case clang::BuiltinType::ObjCId:
5548 case clang::BuiltinType::ObjCClass:
5550 case clang::BuiltinType::ObjCSel:
5564 const llvm::APSInt &value)>
const &callback) {
5565 const clang::EnumType *enum_type =
5568 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5572 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5573 for (enum_pos = enum_decl->enumerator_begin(),
5574 enum_end_pos = enum_decl->enumerator_end();
5575 enum_pos != enum_end_pos; ++enum_pos) {
5576 ConstString name(enum_pos->getNameAsString().c_str());
5577 if (!callback(integer_type, name, enum_pos->getInitVal()))
5584#pragma mark Aggregate Types
5592 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5593 switch (type_class) {
5594 case clang::Type::Record:
5596 const clang::RecordType *record_type =
5597 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5599 clang::RecordDecl *record_decl = record_type->getDecl();
5601 count = std::distance(record_decl->field_begin(),
5602 record_decl->field_end());
5608 case clang::Type::ObjCObjectPointer: {
5609 const clang::ObjCObjectPointerType *objc_class_type =
5610 qual_type->castAs<clang::ObjCObjectPointerType>();
5611 const clang::ObjCInterfaceType *objc_interface_type =
5612 objc_class_type->getInterfaceType();
5613 if (objc_interface_type &&
5615 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5616 clang::ObjCInterfaceDecl *class_interface_decl =
5617 objc_interface_type->getDecl();
5618 if (class_interface_decl) {
5619 count = class_interface_decl->ivar_size();
5625 case clang::Type::ObjCObject:
5626 case clang::Type::ObjCInterface:
5628 const clang::ObjCObjectType *objc_class_type =
5629 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5630 if (objc_class_type) {
5631 clang::ObjCInterfaceDecl *class_interface_decl =
5632 objc_class_type->getInterface();
5634 if (class_interface_decl)
5635 count = class_interface_decl->ivar_size();
5648 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5649 std::string &name, uint64_t *bit_offset_ptr,
5650 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5651 if (class_interface_decl) {
5652 if (idx < (class_interface_decl->ivar_size())) {
5653 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5654 ivar_end = class_interface_decl->ivar_end();
5655 uint32_t ivar_idx = 0;
5657 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5658 ++ivar_pos, ++ivar_idx) {
5659 if (ivar_idx == idx) {
5660 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5662 clang::QualType ivar_qual_type(ivar_decl->getType());
5664 name.assign(ivar_decl->getNameAsString());
5666 if (bit_offset_ptr) {
5667 const clang::ASTRecordLayout &interface_layout =
5668 ast->getASTObjCInterfaceLayout(class_interface_decl);
5669 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5672 const bool is_bitfield = ivar_pos->isBitField();
5674 if (bitfield_bit_size_ptr) {
5675 *bitfield_bit_size_ptr = 0;
5677 if (is_bitfield && ast) {
5678 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5679 clang::Expr::EvalResult result;
5680 if (bitfield_bit_size_expr &&
5681 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5682 llvm::APSInt bitfield_apsint = result.Val.getInt();
5683 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5687 if (is_bitfield_ptr)
5688 *is_bitfield_ptr = is_bitfield;
5690 return ivar_qual_type.getAsOpaquePtr();
5699 size_t idx, std::string &name,
5700 uint64_t *bit_offset_ptr,
5701 uint32_t *bitfield_bit_size_ptr,
5702 bool *is_bitfield_ptr) {
5707 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5708 switch (type_class) {
5709 case clang::Type::Record:
5711 const clang::RecordType *record_type =
5712 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5713 const clang::RecordDecl *record_decl = record_type->getDecl();
5714 uint32_t field_idx = 0;
5715 clang::RecordDecl::field_iterator field, field_end;
5716 for (field = record_decl->field_begin(),
5717 field_end = record_decl->field_end();
5718 field != field_end; ++field, ++field_idx) {
5719 if (idx == field_idx) {
5722 name.assign(field->getNameAsString());
5726 if (bit_offset_ptr) {
5727 const clang::ASTRecordLayout &record_layout =
5729 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5732 const bool is_bitfield = field->isBitField();
5734 if (bitfield_bit_size_ptr) {
5735 *bitfield_bit_size_ptr = 0;
5738 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5739 clang::Expr::EvalResult result;
5740 if (bitfield_bit_size_expr &&
5741 bitfield_bit_size_expr->EvaluateAsInt(result,
5743 llvm::APSInt bitfield_apsint = result.Val.getInt();
5744 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5748 if (is_bitfield_ptr)
5749 *is_bitfield_ptr = is_bitfield;
5751 return GetType(field->getType());
5757 case clang::Type::ObjCObjectPointer: {
5758 const clang::ObjCObjectPointerType *objc_class_type =
5759 qual_type->castAs<clang::ObjCObjectPointerType>();
5760 const clang::ObjCInterfaceType *objc_interface_type =
5761 objc_class_type->getInterfaceType();
5762 if (objc_interface_type &&
5764 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5765 clang::ObjCInterfaceDecl *class_interface_decl =
5766 objc_interface_type->getDecl();
5767 if (class_interface_decl) {
5771 name, bit_offset_ptr, bitfield_bit_size_ptr,
5778 case clang::Type::ObjCObject:
5779 case clang::Type::ObjCInterface:
5781 const clang::ObjCObjectType *objc_class_type =
5782 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5783 assert(objc_class_type);
5784 if (objc_class_type) {
5785 clang::ObjCInterfaceDecl *class_interface_decl =
5786 objc_class_type->getInterface();
5790 name, bit_offset_ptr, bitfield_bit_size_ptr,
5806 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5807 switch (type_class) {
5808 case clang::Type::Record:
5810 const clang::CXXRecordDecl *cxx_record_decl =
5811 qual_type->getAsCXXRecordDecl();
5812 if (cxx_record_decl)
5813 count = cxx_record_decl->getNumBases();
5817 case clang::Type::ObjCObjectPointer:
5821 case clang::Type::ObjCObject:
5823 const clang::ObjCObjectType *objc_class_type =
5824 qual_type->getAsObjCQualifiedInterfaceType();
5825 if (objc_class_type) {
5826 clang::ObjCInterfaceDecl *class_interface_decl =
5827 objc_class_type->getInterface();
5829 if (class_interface_decl && class_interface_decl->getSuperClass())
5834 case clang::Type::ObjCInterface:
5836 const clang::ObjCInterfaceType *objc_interface_type =
5837 qual_type->getAs<clang::ObjCInterfaceType>();
5838 if (objc_interface_type) {
5839 clang::ObjCInterfaceDecl *class_interface_decl =
5840 objc_interface_type->getInterface();
5842 if (class_interface_decl && class_interface_decl->getSuperClass())
5858 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5859 switch (type_class) {
5860 case clang::Type::Record:
5862 const clang::CXXRecordDecl *cxx_record_decl =
5863 qual_type->getAsCXXRecordDecl();
5864 if (cxx_record_decl)
5865 count = cxx_record_decl->getNumVBases();
5878 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5879 switch (type_class) {
5880 case clang::Type::Record:
5882 const clang::CXXRecordDecl *cxx_record_decl =
5883 qual_type->getAsCXXRecordDecl();
5884 if (cxx_record_decl) {
5885 uint32_t curr_idx = 0;
5886 clang::CXXRecordDecl::base_class_const_iterator base_class,
5888 for (base_class = cxx_record_decl->bases_begin(),
5889 base_class_end = cxx_record_decl->bases_end();
5890 base_class != base_class_end; ++base_class, ++curr_idx) {
5891 if (curr_idx == idx) {
5892 if (bit_offset_ptr) {
5893 const clang::ASTRecordLayout &record_layout =
5895 const clang::CXXRecordDecl *base_class_decl =
5896 llvm::cast<clang::CXXRecordDecl>(
5897 base_class->getType()
5898 ->castAs<clang::RecordType>()
5900 if (base_class->isVirtual())
5902 record_layout.getVBaseClassOffset(base_class_decl)
5907 record_layout.getBaseClassOffset(base_class_decl)
5911 return GetType(base_class->getType());
5918 case clang::Type::ObjCObjectPointer:
5921 case clang::Type::ObjCObject:
5923 const clang::ObjCObjectType *objc_class_type =
5924 qual_type->getAsObjCQualifiedInterfaceType();
5925 if (objc_class_type) {
5926 clang::ObjCInterfaceDecl *class_interface_decl =
5927 objc_class_type->getInterface();
5929 if (class_interface_decl) {
5930 clang::ObjCInterfaceDecl *superclass_interface_decl =
5931 class_interface_decl->getSuperClass();
5932 if (superclass_interface_decl) {
5934 *bit_offset_ptr = 0;
5936 superclass_interface_decl));
5942 case clang::Type::ObjCInterface:
5944 const clang::ObjCObjectType *objc_interface_type =
5945 qual_type->getAs<clang::ObjCInterfaceType>();
5946 if (objc_interface_type) {
5947 clang::ObjCInterfaceDecl *class_interface_decl =
5948 objc_interface_type->getInterface();
5950 if (class_interface_decl) {
5951 clang::ObjCInterfaceDecl *superclass_interface_decl =
5952 class_interface_decl->getSuperClass();
5953 if (superclass_interface_decl) {
5955 *bit_offset_ptr = 0;
5957 superclass_interface_decl));
5973 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5974 switch (type_class) {
5975 case clang::Type::Record:
5977 const clang::CXXRecordDecl *cxx_record_decl =
5978 qual_type->getAsCXXRecordDecl();
5979 if (cxx_record_decl) {
5980 uint32_t curr_idx = 0;
5981 clang::CXXRecordDecl::base_class_const_iterator base_class,
5983 for (base_class = cxx_record_decl->vbases_begin(),
5984 base_class_end = cxx_record_decl->vbases_end();
5985 base_class != base_class_end; ++base_class, ++curr_idx) {
5986 if (curr_idx == idx) {
5987 if (bit_offset_ptr) {
5988 const clang::ASTRecordLayout &record_layout =
5990 const clang::CXXRecordDecl *base_class_decl =
5991 llvm::cast<clang::CXXRecordDecl>(
5992 base_class->getType()
5993 ->castAs<clang::RecordType>()
5996 record_layout.getVBaseClassOffset(base_class_decl)
6000 return GetType(base_class->getType());
6015 llvm::StringRef name) {
6017 switch (qual_type->getTypeClass()) {
6018 case clang::Type::Record: {
6022 const clang::RecordType *record_type =
6023 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6024 const clang::RecordDecl *record_decl = record_type->getDecl();
6026 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
6027 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
6028 auto *var_decl = dyn_cast<clang::VarDecl>(decl);
6029 if (!var_decl || var_decl->getStorageClass() != clang::SC_Static)
6053 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6054 switch (type_class) {
6055 case clang::Type::Builtin:
6056 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
6057 case clang::BuiltinType::UnknownAny:
6058 case clang::BuiltinType::Void:
6059 case clang::BuiltinType::NullPtr:
6060 case clang::BuiltinType::OCLEvent:
6061 case clang::BuiltinType::OCLImage1dRO:
6062 case clang::BuiltinType::OCLImage1dWO:
6063 case clang::BuiltinType::OCLImage1dRW:
6064 case clang::BuiltinType::OCLImage1dArrayRO:
6065 case clang::BuiltinType::OCLImage1dArrayWO:
6066 case clang::BuiltinType::OCLImage1dArrayRW:
6067 case clang::BuiltinType::OCLImage1dBufferRO:
6068 case clang::BuiltinType::OCLImage1dBufferWO:
6069 case clang::BuiltinType::OCLImage1dBufferRW:
6070 case clang::BuiltinType::OCLImage2dRO:
6071 case clang::BuiltinType::OCLImage2dWO:
6072 case clang::BuiltinType::OCLImage2dRW:
6073 case clang::BuiltinType::OCLImage2dArrayRO:
6074 case clang::BuiltinType::OCLImage2dArrayWO:
6075 case clang::BuiltinType::OCLImage2dArrayRW:
6076 case clang::BuiltinType::OCLImage3dRO:
6077 case clang::BuiltinType::OCLImage3dWO:
6078 case clang::BuiltinType::OCLImage3dRW:
6079 case clang::BuiltinType::OCLSampler:
6080 case clang::BuiltinType::HLSLResource:
6082 case clang::BuiltinType::Bool:
6083 case clang::BuiltinType::Char_U:
6084 case clang::BuiltinType::UChar:
6085 case clang::BuiltinType::WChar_U:
6086 case clang::BuiltinType::Char16:
6087 case clang::BuiltinType::Char32:
6088 case clang::BuiltinType::UShort:
6089 case clang::BuiltinType::UInt:
6090 case clang::BuiltinType::ULong:
6091 case clang::BuiltinType::ULongLong:
6092 case clang::BuiltinType::UInt128:
6093 case clang::BuiltinType::Char_S:
6094 case clang::BuiltinType::SChar:
6095 case clang::BuiltinType::WChar_S:
6096 case clang::BuiltinType::Short:
6097 case clang::BuiltinType::Int:
6098 case clang::BuiltinType::Long:
6099 case clang::BuiltinType::LongLong:
6100 case clang::BuiltinType::Int128:
6101 case clang::BuiltinType::Float:
6102 case clang::BuiltinType::Double:
6103 case clang::BuiltinType::LongDouble:
6104 case clang::BuiltinType::Dependent:
6105 case clang::BuiltinType::Overload:
6106 case clang::BuiltinType::ObjCId:
6107 case clang::BuiltinType::ObjCClass:
6108 case clang::BuiltinType::ObjCSel:
6109 case clang::BuiltinType::BoundMember:
6110 case clang::BuiltinType::Half:
6111 case clang::BuiltinType::ARCUnbridgedCast:
6112 case clang::BuiltinType::PseudoObject:
6113 case clang::BuiltinType::BuiltinFn:
6114 case clang::BuiltinType::ArraySection:
6121 case clang::Type::Complex:
6123 case clang::Type::Pointer:
6125 case clang::Type::BlockPointer:
6128 case clang::Type::LValueReference:
6130 case clang::Type::RValueReference:
6132 case clang::Type::MemberPointer:
6134 case clang::Type::ConstantArray:
6136 case clang::Type::IncompleteArray:
6138 case clang::Type::VariableArray:
6140 case clang::Type::DependentSizedArray:
6142 case clang::Type::DependentSizedExtVector:
6144 case clang::Type::Vector:
6146 case clang::Type::ExtVector:
6148 case clang::Type::FunctionProto:
6150 case clang::Type::FunctionNoProto:
6152 case clang::Type::UnresolvedUsing:
6154 case clang::Type::Record:
6156 case clang::Type::Enum:
6158 case clang::Type::TemplateTypeParm:
6160 case clang::Type::SubstTemplateTypeParm:
6162 case clang::Type::TemplateSpecialization:
6164 case clang::Type::InjectedClassName:
6166 case clang::Type::DependentName:
6168 case clang::Type::DependentTemplateSpecialization:
6170 case clang::Type::ObjCObject:
6172 case clang::Type::ObjCInterface:
6174 case clang::Type::ObjCObjectPointer:
6184 bool transparent_pointers,
bool omit_empty_base_classes,
6185 bool ignore_array_bounds, std::string &child_name,
6186 uint32_t &child_byte_size, int32_t &child_byte_offset,
6187 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6188 bool &child_is_base_class,
bool &child_is_deref_of_parent,
6193 auto get_exe_scope = [&exe_ctx]() {
6197 clang::QualType parent_qual_type(
6199 const clang::Type::TypeClass parent_type_class =
6200 parent_qual_type->getTypeClass();
6201 child_bitfield_bit_size = 0;
6202 child_bitfield_bit_offset = 0;
6203 child_is_base_class =
false;
6206 auto num_children_or_err =
6208 if (!num_children_or_err)
6209 return num_children_or_err.takeError();
6211 const bool idx_is_valid = idx < *num_children_or_err;
6213 switch (parent_type_class) {
6214 case clang::Type::Builtin:
6216 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) {
6217 case clang::BuiltinType::ObjCId:
6218 case clang::BuiltinType::ObjCClass:
6231 case clang::Type::Record:
6233 const clang::RecordType *record_type =
6234 llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6235 const clang::RecordDecl *record_decl = record_type->getDecl();
6236 assert(record_decl);
6237 const clang::ASTRecordLayout &record_layout =
6239 uint32_t child_idx = 0;
6241 const clang::CXXRecordDecl *cxx_record_decl =
6242 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6243 if (cxx_record_decl) {
6245 clang::CXXRecordDecl::base_class_const_iterator base_class,
6247 for (base_class = cxx_record_decl->bases_begin(),
6248 base_class_end = cxx_record_decl->bases_end();
6249 base_class != base_class_end; ++base_class) {
6250 const clang::CXXRecordDecl *base_class_decl =
nullptr;
6253 if (omit_empty_base_classes) {
6254 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6255 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6260 if (idx == child_idx) {
6261 if (base_class_decl ==
nullptr)
6262 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6263 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6265 if (base_class->isVirtual()) {
6266 bool handled =
false;
6268 clang::VTableContextBase *vtable_ctx =
6272 record_layout, cxx_record_decl,
6273 base_class_decl, bit_offset);
6276 bit_offset = record_layout.getVBaseClassOffset(base_class_decl)
6280 bit_offset = record_layout.getBaseClassOffset(base_class_decl)
6285 child_byte_offset = bit_offset / 8;
6288 std::optional<uint64_t> size =
6289 base_class_clang_type.
GetBitSize(get_exe_scope());
6291 return llvm::createStringError(
"no size info for base class");
6293 uint64_t base_class_clang_type_bit_size = *size;
6296 assert(base_class_clang_type_bit_size % 8 == 0);
6297 child_byte_size = base_class_clang_type_bit_size / 8;
6298 child_is_base_class =
true;
6299 return base_class_clang_type;
6307 uint32_t field_idx = 0;
6308 clang::RecordDecl::field_iterator field, field_end;
6309 for (field = record_decl->field_begin(),
6310 field_end = record_decl->field_end();
6311 field != field_end; ++field, ++field_idx, ++child_idx) {
6312 if (idx == child_idx) {
6315 child_name.assign(field->getNameAsString());
6320 assert(field_idx < record_layout.getFieldCount());
6321 std::optional<uint64_t> size =
6324 return llvm::createStringError(
"no size info for field");
6326 child_byte_size = *size;
6327 const uint32_t child_bit_size = child_byte_size * 8;
6331 bit_offset = record_layout.getFieldOffset(field_idx);
6333 child_bitfield_bit_offset = bit_offset % child_bit_size;
6334 const uint32_t child_bit_offset =
6335 bit_offset - child_bitfield_bit_offset;
6336 child_byte_offset = child_bit_offset / 8;
6338 child_byte_offset = bit_offset / 8;
6341 return field_clang_type;
6347 case clang::Type::ObjCObject:
6348 case clang::Type::ObjCInterface:
6350 const clang::ObjCObjectType *objc_class_type =
6351 llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6352 assert(objc_class_type);
6353 if (objc_class_type) {
6354 uint32_t child_idx = 0;
6355 clang::ObjCInterfaceDecl *class_interface_decl =
6356 objc_class_type->getInterface();
6358 if (class_interface_decl) {
6360 const clang::ASTRecordLayout &interface_layout =
6361 getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
6362 clang::ObjCInterfaceDecl *superclass_interface_decl =
6363 class_interface_decl->getSuperClass();
6364 if (superclass_interface_decl) {
6365 if (omit_empty_base_classes) {
6368 superclass_interface_decl));
6369 if (llvm::expectedToStdOptional(
6371 omit_empty_base_classes, exe_ctx))
6374 clang::QualType ivar_qual_type(
6376 superclass_interface_decl));
6379 superclass_interface_decl->getNameAsString());
6381 clang::TypeInfo ivar_type_info =
6384 child_byte_size = ivar_type_info.Width / 8;
6385 child_byte_offset = 0;
6386 child_is_base_class =
true;
6388 return GetType(ivar_qual_type);
6397 const uint32_t superclass_idx = child_idx;
6399 if (idx < (child_idx + class_interface_decl->ivar_size())) {
6400 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6401 ivar_end = class_interface_decl->ivar_end();
6403 for (ivar_pos = class_interface_decl->ivar_begin();
6404 ivar_pos != ivar_end; ++ivar_pos) {
6405 if (child_idx == idx) {
6406 clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6408 clang::QualType ivar_qual_type(ivar_decl->getType());
6410 child_name.assign(ivar_decl->getNameAsString());
6412 clang::TypeInfo ivar_type_info =
6415 child_byte_size = ivar_type_info.Width / 8;
6431 if (objc_runtime !=
nullptr) {
6434 parent_ast_type, ivar_decl->getNameAsString().c_str());
6442 if (child_byte_offset ==
6444 bit_offset = interface_layout.getFieldOffset(child_idx -
6446 child_byte_offset = bit_offset / 8;
6457 bit_offset = interface_layout.getFieldOffset(
6458 child_idx - superclass_idx);
6460 child_bitfield_bit_offset = bit_offset % 8;
6462 return GetType(ivar_qual_type);
6472 case clang::Type::ObjCObjectPointer:
6477 child_is_deref_of_parent =
false;
6478 bool tmp_child_is_deref_of_parent =
false;
6480 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6481 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6482 child_bitfield_bit_size, child_bitfield_bit_offset,
6483 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6486 child_is_deref_of_parent =
true;
6487 const char *parent_name =
6490 child_name.assign(1,
'*');
6491 child_name += parent_name;
6496 if (std::optional<uint64_t> size =
6497 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6498 child_byte_size = *size;
6499 child_byte_offset = 0;
6500 return pointee_clang_type;
6507 case clang::Type::Vector:
6508 case clang::Type::ExtVector:
6510 const clang::VectorType *array =
6511 llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6515 char element_name[64];
6516 ::snprintf(element_name,
sizeof(element_name),
"[%" PRIu64
"]",
6517 static_cast<uint64_t
>(idx));
6518 child_name.assign(element_name);
6519 if (std::optional<uint64_t> size =
6521 child_byte_size = *size;
6522 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6523 return element_type;
6530 case clang::Type::ConstantArray:
6531 case clang::Type::IncompleteArray:
6532 if (ignore_array_bounds || idx_is_valid) {
6533 const clang::ArrayType *array =
GetQualType(type)->getAsArrayTypeUnsafe();
6537 child_name = std::string(llvm::formatv(
"[{0}]", idx));
6538 if (std::optional<uint64_t> size =
6540 child_byte_size = *size;
6541 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6542 return element_type;
6549 case clang::Type::Pointer: {
6557 child_is_deref_of_parent =
false;
6558 bool tmp_child_is_deref_of_parent =
false;
6560 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6561 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6562 child_bitfield_bit_size, child_bitfield_bit_offset,
6563 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6566 child_is_deref_of_parent =
true;
6568 const char *parent_name =
6571 child_name.assign(1,
'*');
6572 child_name += parent_name;
6577 if (std::optional<uint64_t> size =
6578 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6579 child_byte_size = *size;
6580 child_byte_offset = 0;
6581 return pointee_clang_type;
6588 case clang::Type::LValueReference:
6589 case clang::Type::RValueReference:
6591 const clang::ReferenceType *reference_type =
6592 llvm::cast<clang::ReferenceType>(
6595 GetType(reference_type->getPointeeType());
6597 child_is_deref_of_parent =
false;
6598 bool tmp_child_is_deref_of_parent =
false;
6600 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6601 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6602 child_bitfield_bit_size, child_bitfield_bit_offset,
6603 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6606 const char *parent_name =
6609 child_name.assign(1,
'&');
6610 child_name += parent_name;
6615 if (std::optional<uint64_t> size =
6616 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6617 child_byte_size = *size;
6618 child_byte_offset = 0;
6619 return pointee_clang_type;
6633 const clang::RecordDecl *record_decl,
6634 const clang::CXXBaseSpecifier *base_spec,
6635 bool omit_empty_base_classes) {
6636 uint32_t child_idx = 0;
6638 const clang::CXXRecordDecl *cxx_record_decl =
6639 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6641 if (cxx_record_decl) {
6642 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6643 for (base_class = cxx_record_decl->bases_begin(),
6644 base_class_end = cxx_record_decl->bases_end();
6645 base_class != base_class_end; ++base_class) {
6646 if (omit_empty_base_classes) {
6651 if (base_class == base_spec)
6661 const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl,
6662 bool omit_empty_base_classes) {
6664 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6665 omit_empty_base_classes);
6667 clang::RecordDecl::field_iterator field, field_end;
6668 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6669 field != field_end; ++field, ++child_idx) {
6670 if (field->getCanonicalDecl() == canonical_decl)
6712 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
6713 if (type && !name.empty()) {
6715 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6716 switch (type_class) {
6717 case clang::Type::Record:
6719 const clang::RecordType *record_type =
6720 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6721 const clang::RecordDecl *record_decl = record_type->getDecl();
6723 assert(record_decl);
6724 uint32_t child_idx = 0;
6726 const clang::CXXRecordDecl *cxx_record_decl =
6727 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6730 clang::RecordDecl::field_iterator field, field_end;
6731 for (field = record_decl->field_begin(),
6732 field_end = record_decl->field_end();
6733 field != field_end; ++field, ++child_idx) {
6734 llvm::StringRef field_name = field->getName();
6735 if (field_name.empty()) {
6737 std::vector<uint32_t> save_indices = child_indexes;
6738 child_indexes.push_back(child_idx);
6740 name, omit_empty_base_classes, child_indexes))
6741 return child_indexes.size();
6742 child_indexes = std::move(save_indices);
6743 }
else if (field_name == name) {
6745 child_indexes.push_back(
6747 cxx_record_decl, omit_empty_base_classes));
6748 return child_indexes.size();
6752 if (cxx_record_decl) {
6753 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6756 clang::IdentifierInfo &ident_ref =
getASTContext().Idents.get(name);
6757 clang::DeclarationName decl_name(&ident_ref);
6759 clang::CXXBasePaths paths;
6760 if (cxx_record_decl->lookupInBases(
6761 [decl_name](
const clang::CXXBaseSpecifier *specifier,
6762 clang::CXXBasePath &path) {
6763 CXXRecordDecl *record =
6764 specifier->getType()->getAsCXXRecordDecl();
6765 auto r = record->lookup(decl_name);
6766 path.Decls = r.begin();
6770 clang::CXXBasePaths::const_paths_iterator path,
6771 path_end = paths.end();
6772 for (path = paths.begin(); path != path_end; ++path) {
6773 const size_t num_path_elements = path->size();
6774 for (
size_t e = 0; e < num_path_elements; ++e) {
6775 clang::CXXBasePathElement elem = (*path)[e];
6778 omit_empty_base_classes);
6780 child_indexes.clear();
6783 child_indexes.push_back(child_idx);
6784 parent_record_decl = llvm::cast<clang::RecordDecl>(
6785 elem.Base->getType()
6786 ->castAs<clang::RecordType>()
6790 for (clang::DeclContext::lookup_iterator I = path->Decls, E;
6793 parent_record_decl, *I, omit_empty_base_classes);
6795 child_indexes.clear();
6798 child_indexes.push_back(child_idx);
6802 return child_indexes.size();
6808 case clang::Type::ObjCObject:
6809 case clang::Type::ObjCInterface:
6811 llvm::StringRef name_sref(name);
6812 const clang::ObjCObjectType *objc_class_type =
6813 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6814 assert(objc_class_type);
6815 if (objc_class_type) {
6816 uint32_t child_idx = 0;
6817 clang::ObjCInterfaceDecl *class_interface_decl =
6818 objc_class_type->getInterface();
6820 if (class_interface_decl) {
6821 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6822 ivar_end = class_interface_decl->ivar_end();
6823 clang::ObjCInterfaceDecl *superclass_interface_decl =
6824 class_interface_decl->getSuperClass();
6826 for (ivar_pos = class_interface_decl->ivar_begin();
6827 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6828 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6830 if (ivar_decl->getName() == name_sref) {
6831 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6832 (omit_empty_base_classes &&
6836 child_indexes.push_back(child_idx);
6837 return child_indexes.size();
6841 if (superclass_interface_decl) {
6845 child_indexes.push_back(0);
6849 superclass_interface_decl));
6851 name, omit_empty_base_classes, child_indexes)) {
6854 return child_indexes.size();
6859 child_indexes.pop_back();
6866 case clang::Type::ObjCObjectPointer: {
6868 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6869 ->getPointeeType());
6871 name, omit_empty_base_classes, child_indexes);
6874 case clang::Type::ConstantArray: {
6914 case clang::Type::LValueReference:
6915 case clang::Type::RValueReference: {
6916 const clang::ReferenceType *reference_type =
6917 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6918 clang::QualType pointee_type(reference_type->getPointeeType());
6923 name, omit_empty_base_classes, child_indexes);
6927 case clang::Type::Pointer: {
6932 name, omit_empty_base_classes, child_indexes);
6949 llvm::StringRef name,
6950 bool omit_empty_base_classes) {
6951 if (type && !name.empty()) {
6954 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6956 switch (type_class) {
6957 case clang::Type::Record:
6959 const clang::RecordType *record_type =
6960 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6961 const clang::RecordDecl *record_decl = record_type->getDecl();
6963 assert(record_decl);
6964 uint32_t child_idx = 0;
6966 const clang::CXXRecordDecl *cxx_record_decl =
6967 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6969 if (cxx_record_decl) {
6970 clang::CXXRecordDecl::base_class_const_iterator base_class,
6972 for (base_class = cxx_record_decl->bases_begin(),
6973 base_class_end = cxx_record_decl->bases_end();
6974 base_class != base_class_end; ++base_class) {
6976 clang::CXXRecordDecl *base_class_decl =
6977 llvm::cast<clang::CXXRecordDecl>(
6978 base_class->getType()
6979 ->castAs<clang::RecordType>()
6981 if (omit_empty_base_classes &&
6986 std::string base_class_type_name(
6988 if (base_class_type_name == name)
6995 clang::RecordDecl::field_iterator field, field_end;
6996 for (field = record_decl->field_begin(),
6997 field_end = record_decl->field_end();
6998 field != field_end; ++field, ++child_idx) {
6999 if (field->getName() == name)
7005 case clang::Type::ObjCObject:
7006 case clang::Type::ObjCInterface:
7008 const clang::ObjCObjectType *objc_class_type =
7009 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
7010 assert(objc_class_type);
7011 if (objc_class_type) {
7012 uint32_t child_idx = 0;
7013 clang::ObjCInterfaceDecl *class_interface_decl =
7014 objc_class_type->getInterface();
7016 if (class_interface_decl) {
7017 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
7018 ivar_end = class_interface_decl->ivar_end();
7019 clang::ObjCInterfaceDecl *superclass_interface_decl =
7020 class_interface_decl->getSuperClass();
7022 for (ivar_pos = class_interface_decl->ivar_begin();
7023 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
7024 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
7026 if (ivar_decl->getName() == name) {
7027 if ((!omit_empty_base_classes && superclass_interface_decl) ||
7028 (omit_empty_base_classes &&
7036 if (superclass_interface_decl) {
7037 if (superclass_interface_decl->getName() == name)
7045 case clang::Type::ObjCObjectPointer: {
7047 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
7048 ->getPointeeType());
7050 name, omit_empty_base_classes);
7053 case clang::Type::ConstantArray: {
7093 case clang::Type::LValueReference:
7094 case clang::Type::RValueReference: {
7095 const clang::ReferenceType *reference_type =
7096 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
7101 omit_empty_base_classes);
7105 case clang::Type::Pointer: {
7106 const clang::PointerType *pointer_type =
7107 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
7112 omit_empty_base_classes);
7142 llvm::StringRef name) {
7143 if (!type || name.empty())
7147 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7149 switch (type_class) {
7150 case clang::Type::Record: {
7153 const clang::RecordType *record_type =
7154 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7155 const clang::RecordDecl *record_decl = record_type->getDecl();
7157 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7158 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
7159 if (
auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
7161 if (
auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl))
7177 if (
auto *cxx_record_decl = dyn_cast<clang::TagType>(clang_type))
7178 return isa<clang::ClassTemplateSpecializationDecl>(
7179 cxx_record_decl->getDecl());
7190 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7191 switch (type_class) {
7192 case clang::Type::Record:
7194 const clang::CXXRecordDecl *cxx_record_decl =
7195 qual_type->getAsCXXRecordDecl();
7196 if (cxx_record_decl) {
7197 const clang::ClassTemplateSpecializationDecl *template_decl =
7198 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7200 if (template_decl) {
7201 const auto &template_arg_list = template_decl->getTemplateArgs();
7202 size_t num_args = template_arg_list.size();
7203 assert(num_args &&
"template specialization without any args");
7204 if (expand_pack && num_args) {
7205 const auto &pack = template_arg_list[num_args - 1];
7206 if (pack.getKind() == clang::TemplateArgument::Pack)
7207 num_args += pack.pack_size() - 1;
7222const clang::ClassTemplateSpecializationDecl *
7229 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7230 switch (type_class) {
7231 case clang::Type::Record: {
7234 const clang::CXXRecordDecl *cxx_record_decl =
7235 qual_type->getAsCXXRecordDecl();
7236 if (!cxx_record_decl)
7238 return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7247const TemplateArgument *
7249 size_t idx,
bool expand_pack) {
7250 const auto &args = decl->getTemplateArgs();
7251 const size_t args_size = args.size();
7253 assert(args_size &&
"template specialization without any args");
7257 const size_t last_idx = args_size - 1;
7266 if (!expand_pack || args[last_idx].getKind() != clang::TemplateArgument::Pack)
7267 return idx >= args.size() ? nullptr : &args[idx];
7272 const auto &pack = args[last_idx];
7273 const size_t pack_idx = idx - last_idx;
7274 if (pack_idx >= pack.pack_size())
7276 return &pack.pack_elements()[pack_idx];
7281 size_t arg_idx,
bool expand_pack) {
7282 const clang::ClassTemplateSpecializationDecl *template_decl =
7291 switch (arg->getKind()) {
7292 case clang::TemplateArgument::Null:
7295 case clang::TemplateArgument::NullPtr:
7298 case clang::TemplateArgument::Type:
7301 case clang::TemplateArgument::Declaration:
7304 case clang::TemplateArgument::Integral:
7307 case clang::TemplateArgument::Template:
7310 case clang::TemplateArgument::TemplateExpansion:
7313 case clang::TemplateArgument::Expression:
7316 case clang::TemplateArgument::Pack:
7319 case clang::TemplateArgument::StructuralValue:
7322 llvm_unreachable(
"Unhandled clang::TemplateArgument::ArgKind");
7327 size_t idx,
bool expand_pack) {
7328 const clang::ClassTemplateSpecializationDecl *template_decl =
7334 if (!arg || arg->getKind() != clang::TemplateArgument::Type)
7337 return GetType(arg->getAsType());
7340std::optional<CompilerType::IntegralTemplateArgument>
7342 size_t idx,
bool expand_pack) {
7343 const clang::ClassTemplateSpecializationDecl *template_decl =
7346 return std::nullopt;
7349 if (!arg || arg->getKind() != clang::TemplateArgument::Integral)
7350 return std::nullopt;
7352 return {{arg->getAsIntegral(),
GetType(arg->getIntegralType())}};
7362 const clang::EnumType *enutype =
7365 return enutype->getDecl();
7370 const clang::RecordType *record_type =
7373 return record_type->getDecl();
7381clang::TypedefNameDecl *
7383 const clang::TypedefType *typedef_type =
7386 return typedef_type->getDecl();
7390clang::CXXRecordDecl *
7395clang::ObjCInterfaceDecl *
7397 const clang::ObjCObjectType *objc_class_type =
7398 llvm::dyn_cast<clang::ObjCObjectType>(
7400 if (objc_class_type)
7401 return objc_class_type->getInterface();
7408 uint32_t bitfield_bit_size) {
7416 clang::IdentifierInfo *ident =
nullptr;
7418 ident = &clang_ast.Idents.get(name);
7420 clang::FieldDecl *field =
nullptr;
7422 clang::Expr *bit_width =
nullptr;
7423 if (bitfield_bit_size != 0) {
7424 if (clang_ast.IntTy.isNull()) {
7427 "{0} failed: builtin ASTContext types have not been initialized");
7431 llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
7433 bit_width =
new (clang_ast)
7434 clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
7435 clang_ast.IntTy, clang::SourceLocation());
7438 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7440 field = clang::FieldDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7441 field->setDeclContext(record_decl);
7442 field->setDeclName(ident);
7445 field->setBitWidth(bit_width);
7451 if (
const clang::TagType *TagT =
7452 field->getType()->getAs<clang::TagType>()) {
7453 if (clang::RecordDecl *Rec =
7454 llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7455 if (!Rec->getDeclName()) {
7456 Rec->setAnonymousStructOrUnion(
true);
7457 field->setImplicit();
7463 clang::AccessSpecifier access_specifier =
7465 field->setAccess(access_specifier);
7467 if (clang::CXXRecordDecl *cxx_record_decl =
7468 llvm::dyn_cast<CXXRecordDecl>(record_decl)) {
7469 AddAccessSpecifierDecl(cxx_record_decl, ast->getASTContext(),
7470 ast->GetCXXRecordDeclAccess(cxx_record_decl),
7472 ast->SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
7474 record_decl->addDecl(field);
7479 clang::ObjCInterfaceDecl *class_interface_decl =
7480 ast->GetAsObjCInterfaceDecl(type);
7482 if (class_interface_decl) {
7483 const bool is_synthesized =
false;
7488 clang::ObjCIvarDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7489 ivar->setDeclContext(class_interface_decl);
7490 ivar->setDeclName(ident);
7494 ivar->setBitWidth(bit_width);
7495 ivar->setSynthesize(is_synthesized);
7500 class_interface_decl->addDecl(field);
7523 typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7525 IndirectFieldVector indirect_fields;
7526 clang::RecordDecl::field_iterator field_pos;
7527 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7528 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7529 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos;
7530 last_field_pos = field_pos++) {
7531 if (field_pos->isAnonymousStructOrUnion()) {
7532 clang::QualType field_qual_type = field_pos->getType();
7534 const clang::RecordType *field_record_type =
7535 field_qual_type->getAs<clang::RecordType>();
7537 if (!field_record_type)
7540 clang::RecordDecl *field_record_decl = field_record_type->getDecl();
7542 if (!field_record_decl)
7545 for (clang::RecordDecl::decl_iterator
7546 di = field_record_decl->decls_begin(),
7547 de = field_record_decl->decls_end();
7549 if (clang::FieldDecl *nested_field_decl =
7550 llvm::dyn_cast<clang::FieldDecl>(*di)) {
7551 clang::NamedDecl **chain =
7552 new (ast->getASTContext()) clang::NamedDecl *[2];
7553 chain[0] = *field_pos;
7554 chain[1] = nested_field_decl;
7555 clang::IndirectFieldDecl *indirect_field =
7556 clang::IndirectFieldDecl::Create(
7557 ast->getASTContext(), record_decl, clang::SourceLocation(),
7558 nested_field_decl->getIdentifier(),
7559 nested_field_decl->getType(), {chain, 2});
7562 indirect_field->setImplicit();
7565 field_pos->getAccess(), nested_field_decl->getAccess()));
7567 indirect_fields.push_back(indirect_field);
7568 }
else if (clang::IndirectFieldDecl *nested_indirect_field_decl =
7569 llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
7570 size_t nested_chain_size =
7571 nested_indirect_field_decl->getChainingSize();
7572 clang::NamedDecl **chain =
new (ast->getASTContext())
7573 clang::NamedDecl *[nested_chain_size + 1];
7574 chain[0] = *field_pos;
7576 int chain_index = 1;
7577 for (clang::IndirectFieldDecl::chain_iterator
7578 nci = nested_indirect_field_decl->chain_begin(),
7579 nce = nested_indirect_field_decl->chain_end();
7581 chain[chain_index] = *nci;
7585 clang::IndirectFieldDecl *indirect_field =
7586 clang::IndirectFieldDecl::Create(
7587 ast->getASTContext(), record_decl, clang::SourceLocation(),
7588 nested_indirect_field_decl->getIdentifier(),
7589 nested_indirect_field_decl->getType(),
7590 {chain, nested_chain_size + 1});
7593 indirect_field->setImplicit();
7596 field_pos->getAccess(), nested_indirect_field_decl->getAccess()));
7598 indirect_fields.push_back(indirect_field);
7606 if (last_field_pos != field_end_pos) {
7607 if (last_field_pos->getType()->isIncompleteArrayType())
7608 record_decl->hasFlexibleArrayMember();
7611 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(),
7612 ife = indirect_fields.end();
7614 record_decl->addDecl(*ifi);
7628 record_decl->addAttr(
7629 clang::PackedAttr::CreateImplicit(ast->getASTContext()));
7649 clang::VarDecl *var_decl =
nullptr;
7650 clang::IdentifierInfo *ident =
nullptr;
7652 ident = &ast->getASTContext().Idents.get(name);
7655 clang::VarDecl::CreateDeserialized(ast->getASTContext(), GlobalDeclID());
7656 var_decl->setDeclContext(record_decl);
7657 var_decl->setDeclName(ident);
7659 var_decl->setStorageClass(clang::SC_Static);
7664 var_decl->setAccess(
7666 record_decl->addDecl(var_decl);
7668 VerifyDecl(var_decl);
7674 VarDecl *var,
const llvm::APInt &init_value) {
7675 assert(!var->hasInit() &&
"variable already initialized");
7677 clang::ASTContext &ast = var->getASTContext();
7678 QualType qt = var->getType();
7679 assert(qt->isIntegralOrEnumerationType() &&
7680 "only integer or enum types supported");
7683 if (
const EnumType *enum_type = qt->getAs<EnumType>()) {
7684 const EnumDecl *enum_decl = enum_type->getDecl();
7685 qt = enum_decl->getIntegerType();
7689 if (qt->isSpecificBuiltinType(BuiltinType::Bool)) {
7690 var->setInit(CXXBoolLiteralExpr::Create(
7691 ast, !init_value.isZero(), qt.getUnqualifiedType(), SourceLocation()));
7693 var->setInit(IntegerLiteral::Create(
7694 ast, init_value, qt.getUnqualifiedType(), SourceLocation()));
7699 clang::VarDecl *var,
const llvm::APFloat &init_value) {
7700 assert(!var->hasInit() &&
"variable already initialized");
7702 clang::ASTContext &ast = var->getASTContext();
7703 QualType qt = var->getType();
7704 assert(qt->isFloatingType() &&
"only floating point types supported");
7705 var->setInit(FloatingLiteral::Create(
7706 ast, init_value,
true, qt.getUnqualifiedType(), SourceLocation()));
7711 const char *mangled_name,
const CompilerType &method_clang_type,
7713 bool is_explicit,
bool is_attr_used,
bool is_artificial) {
7714 if (!type || !method_clang_type.
IsValid() || name.empty())
7719 clang::CXXRecordDecl *cxx_record_decl =
7720 record_qual_type->getAsCXXRecordDecl();
7722 if (cxx_record_decl ==
nullptr)
7727 clang::CXXMethodDecl *cxx_method_decl =
nullptr;
7729 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7731 const clang::FunctionType *function_type =
7732 llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7734 if (function_type ==
nullptr)
7737 const clang::FunctionProtoType *method_function_prototype(
7738 llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7740 if (!method_function_prototype)
7743 unsigned int num_params = method_function_prototype->getNumParams();
7745 clang::CXXDestructorDecl *cxx_dtor_decl(
nullptr);
7746 clang::CXXConstructorDecl *cxx_ctor_decl(
nullptr);
7751 const clang::ExplicitSpecifier explicit_spec(
7752 nullptr , is_explicit ? clang::ExplicitSpecKind::ResolvedTrue
7753 : clang::ExplicitSpecKind::ResolvedFalse);
7755 if (name.starts_with(
"~")) {
7756 cxx_dtor_decl = clang::CXXDestructorDecl::CreateDeserialized(
7758 cxx_dtor_decl->setDeclContext(cxx_record_decl);
7759 cxx_dtor_decl->setDeclName(
7762 cxx_dtor_decl->setType(method_qual_type);
7763 cxx_dtor_decl->setImplicit(is_artificial);
7764 cxx_dtor_decl->setInlineSpecified(is_inline);
7765 cxx_dtor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7766 cxx_method_decl = cxx_dtor_decl;
7767 }
else if (decl_name == cxx_record_decl->getDeclName()) {
7768 cxx_ctor_decl = clang::CXXConstructorDecl::CreateDeserialized(
7770 cxx_ctor_decl->setDeclContext(cxx_record_decl);
7771 cxx_ctor_decl->setDeclName(
7774 cxx_ctor_decl->setType(method_qual_type);
7775 cxx_ctor_decl->setImplicit(is_artificial);
7776 cxx_ctor_decl->setInlineSpecified(is_inline);
7777 cxx_ctor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7778 cxx_ctor_decl->setNumCtorInitializers(0);
7779 cxx_ctor_decl->setExplicitSpecifier(explicit_spec);
7780 cxx_method_decl = cxx_ctor_decl;
7782 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7783 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7786 if (op_kind != clang::NUM_OVERLOADED_OPERATORS) {
7791 const bool is_method =
true;
7793 is_method, op_kind, num_params))
7795 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7797 cxx_method_decl->setDeclContext(cxx_record_decl);
7798 cxx_method_decl->setDeclName(
7799 getASTContext().DeclarationNames.getCXXOperatorName(op_kind));
7800 cxx_method_decl->setType(method_qual_type);
7801 cxx_method_decl->setStorageClass(SC);
7802 cxx_method_decl->setInlineSpecified(is_inline);
7803 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7804 }
else if (num_params == 0) {
7806 auto *cxx_conversion_decl =
7807 clang::CXXConversionDecl::CreateDeserialized(
getASTContext(),
7809 cxx_conversion_decl->setDeclContext(cxx_record_decl);
7810 cxx_conversion_decl->setDeclName(
7811 getASTContext().DeclarationNames.getCXXConversionFunctionName(
7813 function_type->getReturnType())));
7814 cxx_conversion_decl->setType(method_qual_type);
7815 cxx_conversion_decl->setInlineSpecified(is_inline);
7816 cxx_conversion_decl->setExplicitSpecifier(explicit_spec);
7817 cxx_conversion_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7818 cxx_method_decl = cxx_conversion_decl;
7822 if (cxx_method_decl ==
nullptr) {
7823 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7825 cxx_method_decl->setDeclContext(cxx_record_decl);
7826 cxx_method_decl->setDeclName(decl_name);
7827 cxx_method_decl->setType(method_qual_type);
7828 cxx_method_decl->setInlineSpecified(is_inline);
7829 cxx_method_decl->setStorageClass(SC);
7830 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7835 clang::AccessSpecifier access_specifier =
7838 cxx_method_decl->setAccess(access_specifier);
7839 cxx_method_decl->setVirtualAsWritten(is_virtual);
7842 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(
getASTContext()));
7844 if (mangled_name !=
nullptr) {
7845 cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7851 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
7853 for (
unsigned param_index = 0; param_index < num_params; ++param_index) {
7854 params.push_back(clang::ParmVarDecl::Create(
7856 clang::SourceLocation(),
7858 method_function_prototype->getParamType(param_index),
nullptr,
7859 clang::SC_None,
nullptr));
7862 cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params));
7869 cxx_record_decl->addDecl(cxx_method_decl);
7878 if (is_artificial) {
7879 if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() &&
7880 cxx_record_decl->hasTrivialDefaultConstructor()) ||
7881 (cxx_ctor_decl->isCopyConstructor() &&
7882 cxx_record_decl->hasTrivialCopyConstructor()) ||
7883 (cxx_ctor_decl->isMoveConstructor() &&
7884 cxx_record_decl->hasTrivialMoveConstructor()))) {
7885 cxx_ctor_decl->setDefaulted();
7886 cxx_ctor_decl->setTrivial(
true);
7887 }
else if (cxx_dtor_decl) {
7888 if (cxx_record_decl->hasTrivialDestructor()) {
7889 cxx_dtor_decl->setDefaulted();
7890 cxx_dtor_decl->setTrivial(
true);
7892 }
else if ((cxx_method_decl->isCopyAssignmentOperator() &&
7893 cxx_record_decl->hasTrivialCopyAssignment()) ||
7894 (cxx_method_decl->isMoveAssignmentOperator() &&
7895 cxx_record_decl->hasTrivialMoveAssignment())) {
7896 cxx_method_decl->setDefaulted();
7897 cxx_method_decl->setTrivial(
true);
7901 VerifyDecl(cxx_method_decl);
7903 return cxx_method_decl;
7909 for (
auto *method : record->methods())
7910 addOverridesForMethod(method);
7913#pragma mark C++ Base Classes
7915std::unique_ptr<clang::CXXBaseSpecifier>
7918 bool base_of_class) {
7922 return std::make_unique<clang::CXXBaseSpecifier>(
7923 clang::SourceRange(), is_virtual, base_of_class,
7926 clang::SourceLocation());
7931 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) {
7935 if (!cxx_record_decl)
7937 std::vector<clang::CXXBaseSpecifier *> raw_bases;
7938 raw_bases.reserve(bases.size());
7942 for (
auto &b : bases)
7943 raw_bases.push_back(b.get());
7944 cxx_record_decl->setBases(raw_bases.data(), raw_bases.size());
7956 if (type && superclass_clang_type.
IsValid() &&
7958 clang::ObjCInterfaceDecl *class_interface_decl =
7960 clang::ObjCInterfaceDecl *super_interface_decl =
7962 if (class_interface_decl && super_interface_decl) {
7963 class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
7964 clang_ast.getObjCInterfaceType(super_interface_decl)));
7973 const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl,
7974 const char *property_setter_name,
const char *property_getter_name,
7976 if (!type || !property_clang_type.
IsValid() || property_name ==
nullptr ||
7977 property_name[0] ==
'\0')
7986 if (!class_interface_decl)
7991 if (property_clang_type.
IsValid())
7992 property_clang_type_to_access = property_clang_type;
7994 property_clang_type_to_access = ast->GetType(ivar_decl->getType());
7996 if (!class_interface_decl || !property_clang_type_to_access.
IsValid())
7999 clang::TypeSourceInfo *prop_type_source;
8001 prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
8003 prop_type_source = clang_ast.getTrivialTypeSourceInfo(
8006 clang::ObjCPropertyDecl *property_decl =
8007 clang::ObjCPropertyDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8008 property_decl->setDeclContext(class_interface_decl);
8009 property_decl->setDeclName(&clang_ast.Idents.get(property_name));
8010 property_decl->setType(ivar_decl
8011 ? ivar_decl->getType()
8019 ast->SetMetadata(property_decl, metadata);
8021 class_interface_decl->addDecl(property_decl);
8023 clang::Selector setter_sel, getter_sel;
8025 if (property_setter_name) {
8026 std::string property_setter_no_colon(property_setter_name,
8027 strlen(property_setter_name) - 1);
8028 const clang::IdentifierInfo *setter_ident =
8029 &clang_ast.Idents.get(property_setter_no_colon);
8030 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8031 }
else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
8032 std::string setter_sel_string(
"set");
8033 setter_sel_string.push_back(::toupper(property_name[0]));
8034 setter_sel_string.append(&property_name[1]);
8035 const clang::IdentifierInfo *setter_ident =
8036 &clang_ast.Idents.get(setter_sel_string);
8037 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8039 property_decl->setSetterName(setter_sel);
8040 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
8042 if (property_getter_name !=
nullptr) {
8043 const clang::IdentifierInfo *getter_ident =
8044 &clang_ast.Idents.get(property_getter_name);
8045 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8047 const clang::IdentifierInfo *getter_ident =
8048 &clang_ast.Idents.get(property_name);
8049 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8051 property_decl->setGetterName(getter_sel);
8052 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
8055 property_decl->setPropertyIvarDecl(ivar_decl);
8057 if (property_attributes & DW_APPLE_PROPERTY_readonly)
8058 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
8059 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
8060 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
8061 if (property_attributes & DW_APPLE_PROPERTY_assign)
8062 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
8063 if (property_attributes & DW_APPLE_PROPERTY_retain)
8064 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
8065 if (property_attributes & DW_APPLE_PROPERTY_copy)
8066 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
8067 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
8068 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
8069 if (property_attributes & ObjCPropertyAttribute::kind_nullability)
8070 property_decl->setPropertyAttributes(
8071 ObjCPropertyAttribute::kind_nullability);
8072 if (property_attributes & ObjCPropertyAttribute::kind_null_resettable)
8073 property_decl->setPropertyAttributes(
8074 ObjCPropertyAttribute::kind_null_resettable);
8075 if (property_attributes & ObjCPropertyAttribute::kind_class)
8076 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
8078 const bool isInstance =
8079 (property_attributes & ObjCPropertyAttribute::kind_class) == 0;
8081 clang::ObjCMethodDecl *getter =
nullptr;
8082 if (!getter_sel.isNull())
8083 getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8084 : class_interface_decl->lookupClassMethod(getter_sel);
8085 if (!getter_sel.isNull() && !getter) {
8086 const bool isVariadic =
false;
8087 const bool isPropertyAccessor =
true;
8088 const bool isSynthesizedAccessorStub =
false;
8089 const bool isImplicitlyDeclared =
true;
8090 const bool isDefined =
false;
8091 const clang::ObjCImplementationControl impControl =
8092 clang::ObjCImplementationControl::None;
8093 const bool HasRelatedResultType =
false;
8096 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8097 getter->setDeclName(getter_sel);
8099 getter->setDeclContext(class_interface_decl);
8100 getter->setInstanceMethod(isInstance);
8101 getter->setVariadic(isVariadic);
8102 getter->setPropertyAccessor(isPropertyAccessor);
8103 getter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8104 getter->setImplicit(isImplicitlyDeclared);
8105 getter->setDefined(isDefined);
8106 getter->setDeclImplementation(impControl);
8107 getter->setRelatedResultType(HasRelatedResultType);
8111 ast->SetMetadata(getter, metadata);
8113 getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
8114 llvm::ArrayRef<clang::SourceLocation>());
8115 class_interface_decl->addDecl(getter);
8119 getter->setPropertyAccessor(
true);
8120 property_decl->setGetterMethodDecl(getter);
8123 clang::ObjCMethodDecl *setter =
nullptr;
8124 setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8125 : class_interface_decl->lookupClassMethod(setter_sel);
8126 if (!setter_sel.isNull() && !setter) {
8127 clang::QualType result_type = clang_ast.VoidTy;
8128 const bool isVariadic =
false;
8129 const bool isPropertyAccessor =
true;
8130 const bool isSynthesizedAccessorStub =
false;
8131 const bool isImplicitlyDeclared =
true;
8132 const bool isDefined =
false;
8133 const clang::ObjCImplementationControl impControl =
8134 clang::ObjCImplementationControl::None;
8135 const bool HasRelatedResultType =
false;
8138 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8139 setter->setDeclName(setter_sel);
8140 setter->setReturnType(result_type);
8141 setter->setDeclContext(class_interface_decl);
8142 setter->setInstanceMethod(isInstance);
8143 setter->setVariadic(isVariadic);
8144 setter->setPropertyAccessor(isPropertyAccessor);
8145 setter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8146 setter->setImplicit(isImplicitlyDeclared);
8147 setter->setDefined(isDefined);
8148 setter->setDeclImplementation(impControl);
8149 setter->setRelatedResultType(HasRelatedResultType);
8153 ast->SetMetadata(setter, metadata);
8155 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8156 params.push_back(clang::ParmVarDecl::Create(
8157 clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8160 clang::SC_Auto,
nullptr));
8162 setter->setMethodParams(clang_ast,
8163 llvm::ArrayRef<clang::ParmVarDecl *>(params),
8164 llvm::ArrayRef<clang::SourceLocation>());
8166 class_interface_decl->addDecl(setter);
8170 setter->setPropertyAccessor(
true);
8171 property_decl->setSetterMethodDecl(setter);
8178 bool check_superclass) {
8180 if (class_interface_decl)
8190 const CompilerType &method_clang_type,
bool is_artificial,
bool is_variadic,
8191 bool is_objc_direct_call) {
8192 if (!type || !method_clang_type.
IsValid())
8197 if (class_interface_decl ==
nullptr)
8201 if (lldb_ast ==
nullptr)
8205 const char *selector_start = ::strchr(name,
' ');
8206 if (selector_start ==
nullptr)
8210 llvm::SmallVector<const clang::IdentifierInfo *, 12> selector_idents;
8215 unsigned num_selectors_with_args = 0;
8216 for (start = selector_start; start && *start !=
'\0' && *start !=
']';
8218 len = ::strcspn(start,
":]");
8219 bool has_arg = (start[len] ==
':');
8221 ++num_selectors_with_args;
8222 selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
8227 if (selector_idents.size() == 0)
8230 clang::Selector method_selector = ast.Selectors.getSelector(
8231 num_selectors_with_args ? selector_idents.size() : 0,
8232 selector_idents.data());
8237 const clang::Type *method_type(method_qual_type.getTypePtr());
8239 if (method_type ==
nullptr)
8242 const clang::FunctionProtoType *method_function_prototype(
8243 llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8245 if (!method_function_prototype)
8248 const bool isInstance = (name[0] ==
'-');
8249 const bool isVariadic = is_variadic;
8250 const bool isPropertyAccessor =
false;
8251 const bool isSynthesizedAccessorStub =
false;
8253 const bool isImplicitlyDeclared =
true;
8254 const bool isDefined =
false;
8255 const clang::ObjCImplementationControl impControl =
8256 clang::ObjCImplementationControl::None;
8257 const bool HasRelatedResultType =
false;
8259 const unsigned num_args = method_function_prototype->getNumParams();
8261 if (num_args != num_selectors_with_args)
8265 auto *objc_method_decl =
8266 clang::ObjCMethodDecl::CreateDeserialized(ast, GlobalDeclID());
8267 objc_method_decl->setDeclName(method_selector);
8268 objc_method_decl->setReturnType(method_function_prototype->getReturnType());
8269 objc_method_decl->setDeclContext(
8271 objc_method_decl->setInstanceMethod(isInstance);
8272 objc_method_decl->setVariadic(isVariadic);
8273 objc_method_decl->setPropertyAccessor(isPropertyAccessor);
8274 objc_method_decl->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8275 objc_method_decl->setImplicit(isImplicitlyDeclared);
8276 objc_method_decl->setDefined(isDefined);
8277 objc_method_decl->setDeclImplementation(impControl);
8278 objc_method_decl->setRelatedResultType(HasRelatedResultType);
8281 if (objc_method_decl ==
nullptr)
8285 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8287 for (
unsigned param_index = 0; param_index < num_args; ++param_index) {
8288 params.push_back(clang::ParmVarDecl::Create(
8289 ast, objc_method_decl, clang::SourceLocation(),
8290 clang::SourceLocation(),
8292 method_function_prototype->getParamType(param_index),
nullptr,
8293 clang::SC_Auto,
nullptr));
8296 objc_method_decl->setMethodParams(
8297 ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
8298 llvm::ArrayRef<clang::SourceLocation>());
8301 if (is_objc_direct_call) {
8304 objc_method_decl->addAttr(
8305 clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
8310 objc_method_decl->createImplicitParams(ast, class_interface_decl);
8313 class_interface_decl->addDecl(objc_method_decl);
8315 VerifyDecl(objc_method_decl);
8317 return objc_method_decl;
8327 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8328 switch (type_class) {
8329 case clang::Type::Record: {
8330 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8331 if (cxx_record_decl) {
8332 cxx_record_decl->setHasExternalLexicalStorage(has_extern);
8333 cxx_record_decl->setHasExternalVisibleStorage(has_extern);
8338 case clang::Type::Enum: {
8339 clang::EnumDecl *enum_decl =
8340 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8342 enum_decl->setHasExternalLexicalStorage(has_extern);
8343 enum_decl->setHasExternalVisibleStorage(has_extern);
8348 case clang::Type::ObjCObject:
8349 case clang::Type::ObjCInterface: {
8350 const clang::ObjCObjectType *objc_class_type =
8351 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8352 assert(objc_class_type);
8353 if (objc_class_type) {
8354 clang::ObjCInterfaceDecl *class_interface_decl =
8355 objc_class_type->getInterface();
8357 if (class_interface_decl) {
8358 class_interface_decl->setHasExternalLexicalStorage(has_extern);
8359 class_interface_decl->setHasExternalVisibleStorage(has_extern);
8375 if (!qual_type.isNull()) {
8376 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8378 clang::TagDecl *tag_decl = tag_type->getDecl();
8380 tag_decl->startDefinition();
8385 const clang::ObjCObjectType *object_type =
8386 qual_type->getAs<clang::ObjCObjectType>();
8388 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8389 if (interface_decl) {
8390 interface_decl->startDefinition();
8401 if (qual_type.isNull())
8406 if (lldb_ast ==
nullptr)
8412 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8414 clang::TagDecl *tag_decl = tag_type->getDecl();
8416 if (
auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
8426 if (cxx_record_decl->hasUserDeclaredMoveConstructor() ||
8427 cxx_record_decl->hasUserDeclaredMoveAssignment()) {
8428 if (cxx_record_decl->needsImplicitCopyConstructor())
8429 cxx_record_decl->setImplicitCopyConstructorIsDeleted();
8430 if (cxx_record_decl->needsImplicitCopyAssignment())
8431 cxx_record_decl->setImplicitCopyAssignmentIsDeleted();
8434 if (!cxx_record_decl->isCompleteDefinition())
8435 cxx_record_decl->completeDefinition();
8436 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
8437 cxx_record_decl->setHasExternalLexicalStorage(
false);
8438 cxx_record_decl->setHasExternalVisibleStorage(
false);
8440 clang::AccessSpecifier::AS_none);
8445 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8449 clang::EnumDecl *enum_decl = enutype->getDecl();
8451 if (enum_decl->isCompleteDefinition())
8454 clang::ASTContext &ast = lldb_ast->getASTContext();
8458 QualType integer_type(enum_decl->getIntegerType());
8459 if (!integer_type.isNull()) {
8460 unsigned NumPositiveBits = 1;
8461 unsigned NumNegativeBits = 0;
8463 clang::QualType promotion_qual_type;
8466 if (ast.getTypeSize(enum_decl->getIntegerType()) <
8467 ast.getTypeSize(ast.IntTy)) {
8468 if (enum_decl->getIntegerType()->isSignedIntegerType())
8469 promotion_qual_type = ast.IntTy;
8471 promotion_qual_type = ast.UnsignedIntTy;
8473 promotion_qual_type = enum_decl->getIntegerType();
8475 enum_decl->completeDefinition(enum_decl->getIntegerType(),
8476 promotion_qual_type, NumPositiveBits,
8484 const llvm::APSInt &value) {
8495 if (!enum_opaque_compiler_type)
8498 clang::QualType enum_qual_type(
8501 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8506 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8511 clang::EnumConstantDecl *enumerator_decl =
8512 clang::EnumConstantDecl::CreateDeserialized(
getASTContext(),
8514 enumerator_decl->setDeclContext(enutype->getDecl());
8515 if (name && name[0])
8516 enumerator_decl->setDeclName(&
getASTContext().Idents.get(name));
8517 enumerator_decl->setType(clang::QualType(enutype, 0));
8521 if (!enumerator_decl)
8524 enutype->getDecl()->addDecl(enumerator_decl);
8526 VerifyDecl(enumerator_decl);
8527 return enumerator_decl;
8532 int64_t enum_value, uint32_t enum_value_bit_size) {
8534 bool is_signed =
false;
8537 llvm::APSInt value(enum_value_bit_size, is_signed);
8545 const clang::Type *clang_type = qt.getTypePtrOrNull();
8546 const auto *enum_type = llvm::dyn_cast_or_null<clang::EnumType>(clang_type);
8550 return GetType(enum_type->getDecl()->getIntegerType());
8556 if (type && pointee_type.
IsValid() &&
8562 return ast->GetType(ast->getASTContext().getMemberPointerType(
8570#define DEPTH_INCREMENT 2
8573LLVM_DUMP_METHOD
void
8587 llvm::StringRef symbol_name) {
8594 symfile->
GetTypes(
nullptr, eTypeClassAny, type_list);
8595 size_t ntypes = type_list.
GetSize();
8597 for (
size_t i = 0; i < ntypes; ++i) {
8600 if (!symbol_name.empty())
8601 if (symbol_name != type->GetName().GetStringRef())
8604 s << type->GetName().AsCString() <<
"\n";
8607 if (clang::TagDecl *tag_decl =
GetAsTagDecl(full_type)) {
8615 if (
auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8617 if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8629 size_t byte_size, uint32_t bitfield_bit_offset,
8630 uint32_t bitfield_bit_size) {
8631 const clang::EnumType *enutype =
8632 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8633 const clang::EnumDecl *enum_decl = enutype->getDecl();
8636 bool qual_type_is_signed = qual_type->isSignedIntegerOrEnumerationType();
8637 const uint64_t enum_svalue =
8640 bitfield_bit_offset)
8642 bitfield_bit_offset);
8643 bool can_be_bitfield =
true;
8644 uint64_t covered_bits = 0;
8645 int num_enumerators = 0;
8653 clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
8654 if (enumerators.empty())
8655 can_be_bitfield =
false;
8657 for (
auto *enumerator : enumerators) {
8658 llvm::APSInt init_val = enumerator->getInitVal();
8659 uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
8660 : init_val.getZExtValue();
8661 if (qual_type_is_signed)
8662 val = llvm::SignExtend64(val, 8 * byte_size);
8663 if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8664 can_be_bitfield =
false;
8665 covered_bits |= val;
8667 if (val == enum_svalue) {
8676 offset = byte_offset;
8678 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8682 if (!can_be_bitfield) {
8683 if (qual_type_is_signed)
8684 s.
Printf(
"%" PRIi64, enum_svalue);
8686 s.
Printf(
"%" PRIu64, enum_uvalue);
8693 s.
Printf(
"0x%" PRIx64, enum_uvalue);
8697 uint64_t remaining_value = enum_uvalue;
8698 std::vector<std::pair<uint64_t, llvm::StringRef>> values;
8699 values.reserve(num_enumerators);
8700 for (
auto *enumerator : enum_decl->enumerators())
8701 if (
auto val = enumerator->getInitVal().getZExtValue())
8702 values.emplace_back(val, enumerator->getName());
8707 std::stable_sort(values.begin(), values.end(),
8708 [](
const auto &a,
const auto &b) {
8709 return llvm::popcount(a.first) > llvm::popcount(b.first);
8712 for (
const auto &val : values) {
8713 if ((remaining_value & val.first) != val.first)
8715 remaining_value &= ~val.first;
8717 if (remaining_value)
8723 if (remaining_value)
8724 s.
Printf(
"0x%" PRIx64, remaining_value);
8732 size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
8741 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8743 if (type_class == clang::Type::Elaborated) {
8744 qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
8745 return DumpTypeValue(qual_type.getAsOpaquePtr(), s, format, data, byte_offset, byte_size,
8746 bitfield_bit_size, bitfield_bit_offset, exe_scope);
8749 switch (type_class) {
8750 case clang::Type::Typedef: {
8751 clang::QualType typedef_qual_type =
8752 llvm::cast<clang::TypedefType>(qual_type)
8754 ->getUnderlyingType();
8757 format = typedef_clang_type.
GetFormat();
8758 clang::TypeInfo typedef_type_info =
8760 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
8770 bitfield_bit_offset,
8775 case clang::Type::Enum:
8780 return DumpEnumValue(qual_type, s, data, byte_offset, byte_size,
8781 bitfield_bit_offset, bitfield_bit_size);
8789 uint32_t item_count = 1;
8828 item_count = byte_size;
8833 item_count = byte_size / 2;
8838 item_count = byte_size / 4;
8844 bitfield_bit_size, bitfield_bit_offset,
8860 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(clang_type)) {
8869 clang::QualType qual_type =
8872 llvm::SmallVector<char, 1024> buf;
8873 llvm::raw_svector_ostream llvm_ostrm(buf);
8875 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8876 switch (type_class) {
8877 case clang::Type::ObjCObject:
8878 case clang::Type::ObjCInterface: {
8881 auto *objc_class_type =
8882 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8883 assert(objc_class_type);
8884 if (!objc_class_type)
8886 clang::ObjCInterfaceDecl *class_interface_decl =
8887 objc_class_type->getInterface();
8888 if (!class_interface_decl)
8891 class_interface_decl->dump(llvm_ostrm);
8893 class_interface_decl->print(llvm_ostrm,
8898 case clang::Type::Typedef: {
8899 auto *typedef_type = qual_type->getAs<clang::TypedefType>();
8902 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8904 typedef_decl->dump(llvm_ostrm);
8907 if (!clang_typedef_name.empty()) {
8914 case clang::Type::Record: {
8917 auto *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8918 const clang::RecordDecl *record_decl = record_type->getDecl();
8920 record_decl->dump(llvm_ostrm);
8922 record_decl->print(llvm_ostrm,
getASTContext().getPrintingPolicy(),
8928 if (
auto *tag_type =
8929 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) {
8930 if (clang::TagDecl *tag_decl = tag_type->getDecl()) {
8932 tag_decl->dump(llvm_ostrm);
8934 tag_decl->print(llvm_ostrm, 0);
8940 std::string clang_type_name(qual_type.getAsString());
8941 if (!clang_type_name.empty())
8948 if (buf.size() > 0) {
8949 s.
Write(buf.data(), buf.size());
8956 clang::QualType qual_type(
8959 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8960 switch (type_class) {
8961 case clang::Type::Record: {
8962 const clang::CXXRecordDecl *cxx_record_decl =
8963 qual_type->getAsCXXRecordDecl();
8964 if (cxx_record_decl)
8965 printf(
"class %s", cxx_record_decl->getName().str().c_str());
8968 case clang::Type::Enum: {
8969 clang::EnumDecl *enum_decl =
8970 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8972 printf(
"enum %s", enum_decl->getName().str().c_str());
8976 case clang::Type::ObjCObject:
8977 case clang::Type::ObjCInterface: {
8978 const clang::ObjCObjectType *objc_class_type =
8979 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
8980 if (objc_class_type) {
8981 clang::ObjCInterfaceDecl *class_interface_decl =
8982 objc_class_type->getInterface();
8986 if (class_interface_decl)
8987 printf(
"@class %s", class_interface_decl->getName().str().c_str());
8991 case clang::Type::Typedef:
8992 printf(
"typedef %s", llvm::cast<clang::TypedefType>(qual_type)
8999 case clang::Type::Auto:
9002 llvm::cast<clang::AutoType>(qual_type)
9004 .getAsOpaquePtr()));
9006 case clang::Type::Elaborated:
9007 printf(
"elaborated ");
9009 type.
GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)
9011 .getAsOpaquePtr()));
9013 case clang::Type::Paren:
9017 llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
9020 printf(
"TypeSystemClang::DumpTypeName() type_class = %u", type_class);
9030 if (template_param_infos.
IsValid()) {
9031 std::string template_basename(parent_name);
9033 if (
auto i = template_basename.find(
'<'); i != std::string::npos)
9034 template_basename.erase(i);
9037 template_basename.c_str(), tag_decl_kind,
9038 template_param_infos);
9053 clang::ObjCInterfaceDecl *decl) {
9081 const clang::RecordDecl *record_decl, uint64_t &bit_size,
9082 uint64_t &alignment,
9083 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
9084 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9086 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9099 field_offsets, base_offsets, vbase_offsets);
9106 clang::NamedDecl *nd =
9107 llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl);
9116 clang::NamedDecl *nd =
9117 llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl);
9118 if (nd !=
nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) {
9120 if (mc && mc->shouldMangleCXXName(nd)) {
9121 llvm::SmallVector<char, 1024> buf;
9122 llvm::raw_svector_ostream llvm_ostrm(buf);
9123 if (llvm::isa<clang::CXXConstructorDecl>(nd)) {
9125 clang::GlobalDecl(llvm::dyn_cast<clang::CXXConstructorDecl>(nd),
9128 }
else if (llvm::isa<clang::CXXDestructorDecl>(nd)) {
9130 clang::GlobalDecl(llvm::dyn_cast<clang::CXXDestructorDecl>(nd),
9134 mc->mangleName(nd, llvm_ostrm);
9151 if (clang::FunctionDecl *func_decl =
9152 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9153 return GetType(func_decl->getReturnType());
9154 if (clang::ObjCMethodDecl *objc_method =
9155 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9156 return GetType(objc_method->getReturnType());
9162 if (clang::FunctionDecl *func_decl =
9163 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9164 return func_decl->param_size();
9165 if (clang::ObjCMethodDecl *objc_method =
9166 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9167 return objc_method->param_size();
9173 clang::DeclContext
const *decl_ctx) {
9174 switch (clang_kind) {
9175 case Decl::TranslationUnit:
9177 case Decl::Namespace:
9188 if (decl_ctx->isFunctionOrMethod())
9190 if (decl_ctx->isRecord())
9200 std::vector<lldb_private::CompilerContext> &context) {
9201 if (decl_ctx ==
nullptr)
9204 clang::Decl::Kind clang_kind = decl_ctx->getDeclKind();
9205 if (clang_kind == Decl::TranslationUnit)
9210 context.push_back({compiler_kind, decl_ctx_name});
9213std::vector<lldb_private::CompilerContext>
9215 std::vector<lldb_private::CompilerContext> context;
9218 clang::Decl *decl = (clang::Decl *)opaque_decl;
9220 clang::DeclContext *decl_ctx = decl->getDeclContext();
9223 auto compiler_kind =
9225 context.push_back({compiler_kind, decl_name});
9232 if (clang::FunctionDecl *func_decl =
9233 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) {
9234 if (idx < func_decl->param_size()) {
9235 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9237 return GetType(var_decl->getOriginalType());
9239 }
else if (clang::ObjCMethodDecl *objc_method =
9240 llvm::dyn_cast<clang::ObjCMethodDecl>(
9241 (clang::Decl *)opaque_decl)) {
9242 if (idx < objc_method->param_size())
9243 return GetType(objc_method->parameters()[idx]->getOriginalType());
9249 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
9250 clang::VarDecl *var_decl = llvm::dyn_cast<clang::VarDecl>(decl);
9253 clang::Expr *init_expr = var_decl->getInit();
9256 std::optional<llvm::APSInt> value =
9266 void *opaque_decl_ctx,
ConstString name,
const bool ignore_using_decls) {
9267 std::vector<CompilerDecl> found_decls;
9269 if (opaque_decl_ctx && symbol_file) {
9270 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9271 std::set<DeclContext *> searched;
9272 std::multimap<DeclContext *, DeclContext *> search_queue;
9274 for (clang::DeclContext *decl_context = root_decl_ctx;
9275 decl_context !=
nullptr && found_decls.empty();
9276 decl_context = decl_context->getParent()) {
9277 search_queue.insert(std::make_pair(decl_context, decl_context));
9279 for (
auto it = search_queue.find(decl_context); it != search_queue.end();
9281 if (!searched.insert(it->second).second)
9286 for (clang::Decl *child : it->second->decls()) {
9287 if (clang::UsingDirectiveDecl *ud =
9288 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9289 if (ignore_using_decls)
9291 clang::DeclContext *from = ud->getCommonAncestor();
9292 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9293 search_queue.insert(
9294 std::make_pair(from, ud->getNominatedNamespace()));
9295 }
else if (clang::UsingDecl *ud =
9296 llvm::dyn_cast<clang::UsingDecl>(child)) {
9297 if (ignore_using_decls)
9299 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9300 clang::Decl *target = usd->getTargetDecl();
9301 if (clang::NamedDecl *nd =
9302 llvm::dyn_cast<clang::NamedDecl>(target)) {
9303 IdentifierInfo *ii = nd->getIdentifier();
9304 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9308 }
else if (clang::NamedDecl *nd =
9309 llvm::dyn_cast<clang::NamedDecl>(child)) {
9310 IdentifierInfo *ii = nd->getIdentifier();
9311 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9362 clang::DeclContext *child_decl_ctx,
9366 if (frame_decl_ctx && symbol_file) {
9367 std::set<DeclContext *> searched;
9368 std::multimap<DeclContext *, DeclContext *> search_queue;
9371 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9375 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx !=
nullptr;
9376 decl_ctx = decl_ctx->getParent()) {
9377 if (!decl_ctx->isLookupContext())
9379 if (decl_ctx == parent_decl_ctx)
9382 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9383 for (
auto it = search_queue.find(decl_ctx); it != search_queue.end();
9385 if (searched.find(it->second) != searched.end())
9393 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9396 searched.insert(it->second);
9400 for (clang::Decl *child : it->second->decls()) {
9401 if (clang::UsingDirectiveDecl *ud =
9402 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9403 clang::DeclContext *ns = ud->getNominatedNamespace();
9404 if (ns == parent_decl_ctx)
9407 clang::DeclContext *from = ud->getCommonAncestor();
9408 if (searched.find(ns) == searched.end())
9409 search_queue.insert(std::make_pair(from, ns));
9410 }
else if (child_name) {
9411 if (clang::UsingDecl *ud =
9412 llvm::dyn_cast<clang::UsingDecl>(child)) {
9413 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9414 clang::Decl *target = usd->getTargetDecl();
9415 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9419 IdentifierInfo *ii = nd->getIdentifier();
9420 if (ii ==
nullptr ||
9421 ii->getName() != child_name->
AsCString(
nullptr))
9444 if (opaque_decl_ctx) {
9445 clang::NamedDecl *named_decl =
9446 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9449 llvm::raw_string_ostream stream{name};
9451 policy.AlwaysIncludeTypeForTemplateArgument =
true;
9452 named_decl->getNameForDiagnostic(stream, policy,
false);
9461 if (opaque_decl_ctx) {
9462 clang::NamedDecl *named_decl =
9463 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9471 if (!opaque_decl_ctx)
9474 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9475 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9477 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9479 }
else if (clang::FunctionDecl *fun_decl =
9480 llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9481 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9482 return metadata->HasObjectPtr();
9488std::vector<lldb_private::CompilerContext>
9490 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9491 std::vector<lldb_private::CompilerContext> context;
9497 void *opaque_decl_ctx,
void *other_opaque_decl_ctx) {
9498 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9499 auto *other = (clang::DeclContext *)other_opaque_decl_ctx;
9503 auto is_transparent_lookup_allowed = [](clang::DeclContext *DC) {
9504 if (DC->isInlineNamespace())
9507 if (
auto const *NS = dyn_cast<NamespaceDecl>(DC))
9508 return NS->isAnonymousNamespace();
9515 if (decl_ctx == other)
9517 }
while (is_transparent_lookup_allowed(other) &&
9518 (other = other->getParent()));
9525 if (!opaque_decl_ctx)
9528 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9529 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9531 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9533 }
else if (
auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9534 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9535 return metadata->GetObjectPtrLanguage();
9555 return llvm::dyn_cast<clang::ObjCMethodDecl>(
9563 return llvm::dyn_cast<clang::CXXMethodDecl>(
9568clang::FunctionDecl *
9571 return llvm::dyn_cast<clang::FunctionDecl>(
9576clang::NamespaceDecl *
9579 return llvm::dyn_cast<clang::NamespaceDecl>(
9584std::optional<ClangASTMetadata>
9586 const Decl *
object) {
9594 llvm::dyn_cast_or_null<TypeSystemClang>(dc.
GetTypeSystem());
9616 lldbassert(started &&
"Unable to start a class type definition.");
9635 SpecializedScratchAST(llvm::StringRef name, llvm::Triple triple,
9636 std::unique_ptr<ClangASTSource> ast_source)
9638 m_scratch_ast_source_up(std::move(ast_source)) {
9640 m_scratch_ast_source_up->InstallASTContext(*
this);
9641 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9642 m_scratch_ast_source_up->CreateProxy());
9643 SetExternalSource(proxy_ast_source);
9647 std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
9655 llvm::Triple triple)
9657 m_target_wp(target.shared_from_this()),
9658 m_persistent_variables(
9662 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9674 std::optional<IsolatedASTKind> ast_kind,
9675 bool create_on_demand) {
9678 if (
auto err = type_system_or_err.takeError()) {
9680 "Couldn't get scratch TypeSystemClang: {0}");
9683 auto ts_sp = *type_system_or_err;
9685 llvm::dyn_cast_or_null<ScratchTypeSystemClang>(ts_sp.get());
9690 return std::static_pointer_cast<TypeSystemClang>(ts_sp);
9692 return std::static_pointer_cast<TypeSystemClang>(
9697static llvm::StringRef
9701 return "C++ modules";
9703 llvm_unreachable(
"Unimplemented IsolatedASTKind?");
9708 output <<
"State of scratch Clang type system:\n";
9712 typedef std::pair<IsolatedASTKey, TypeSystem *> KeyAndTS;
9713 std::vector<KeyAndTS> sorted_typesystems;
9715 sorted_typesystems.emplace_back(a.first, a.second.get());
9716 llvm::stable_sort(sorted_typesystems, llvm::less_first());
9719 for (
const auto &a : sorted_typesystems) {
9722 output <<
"State of scratch Clang type subsystem "
9724 a.second->Dump(output);
9729 llvm::StringRef expr, llvm::StringRef prefix,
SourceLanguage language,
9737 desired_type, options, ctx_obj);
9742 const ValueList &arg_value_list,
const char *name) {
9747 Process *process = target_sp->GetProcessSP().get();
9752 arg_value_list, name);
9755std::unique_ptr<UtilityFunction>
9762 return std::make_unique<ClangUtilityFunction>(
9763 *target_sp.get(), std::move(text), std::move(name),
9764 target_sp->GetDebugUtilityExpression());
9778 importer.
ForgetSource(&a.second->getASTContext(), src_ctx);
9782 return std::make_unique<ClangASTSource>(
9787static llvm::StringRef
9791 return "scratch ASTContext for C++ module types";
9793 llvm_unreachable(
"Unimplemented ASTFeature kind?");
9800 return *found_ast->second;
9803 std::shared_ptr<TypeSystemClang> new_ast_sp =
9813 const clang::RecordType *record_type =
9814 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
9816 const clang::RecordDecl *record_decl = record_type->getDecl();
9817 assert(record_decl);
9818 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(record_decl))
9819 return metadata->IsForcefullyCompleted();
9828 std::optional<ClangASTMetadata> metadata =
GetMetadata(td);
9832 metadata->SetIsForcefullyCompleted();
9840 LLDB_LOG(log,
"Created new TypeSystem for (ASTContext*){0:x} '{1}'",
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s, const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_offset, uint32_t bitfield_bit_size)
static lldb::opaque_compiler_type_t GetObjCFieldAtIndex(clang::ASTContext *ast, clang::ObjCInterfaceDecl *class_interface_decl, size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr)
static void ParseLangArgs(LangOptions &Opts, ArchSpec arch)
static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast, clang::QualType qual_type)
const TemplateArgument * GetNthTemplateArgument(const clang::ClassTemplateSpecializationDecl *decl, size_t idx, bool expand_pack)
static int64_t ReadVBaseOffsetFromVTable(Process &process, VTableContextBase &vtable_ctx, lldb::addr_t vtable_ptr, const CXXRecordDecl *cxx_record_decl, const CXXRecordDecl *base_class_decl)
static const clang::RecordType * GetCompleteRecordType(clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion)
Returns the clang::RecordType of the specified qual_type.
lldb_private::ThreadSafeDenseMap< clang::ASTContext *, TypeSystemClang * > ClangASTMap
static bool IsClangDeclContext(const CompilerDeclContext &dc)
static bool TemplateParameterAllowsValue(NamedDecl *param, const TemplateArgument &value)
Returns true if the given template parameter can represent the given value.
static CompilerContextKind GetCompilerKind(clang::Decl::Kind clang_kind, clang::DeclContext const *decl_ctx)
static QualType RemoveWrappingTypes(QualType type, ArrayRef< clang::Type::TypeClass > mask={})
Aggressively desugar the provided type, skipping past various kinds of syntactic sugar and other cons...
static TemplateParameterList * CreateTemplateParameterList(ASTContext &ast, const TypeSystemClang::TemplateParameterInfos &template_param_infos, llvm::SmallVector< NamedDecl *, 8 > &template_param_decls)
clang::DeclContext * FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root)
static bool check_op_param(bool is_method, clang::OverloadedOperatorKind op_kind, bool unary, bool binary, uint32_t num_params)
static llvm::StringRef GetSpecializedASTName(ScratchTypeSystemClang::IsolatedASTKind feature)
static const clang::ObjCObjectType * GetCompleteObjCObjectType(clang::ASTContext *ast, QualType qual_type, bool allow_completion)
Returns the clang::ObjCObjectType of the specified qual_type.
static bool ObjCDeclHasIVars(clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass)
static lldb::addr_t GetVTableAddress(Process &process, VTableContextBase &vtable_ctx, ValueObject &valobj, const ASTRecordLayout &record_layout)
static clang::ObjCIvarDecl::AccessControl ConvertAccessTypeToObjCIvarAccessControl(AccessType access)
static std::optional< SymbolFile::ArrayInfo > GetDynamicArrayInfo(TypeSystemClang &ast, SymbolFile *sym_file, clang::QualType qual_type, const ExecutionContext *exe_ctx)
static llvm::StringRef GetNameForIsolatedASTKind(ScratchTypeSystemClang::IsolatedASTKind kind)
Returns a human-readable name that uniquely identifiers the sub-AST kind.
static void InsertCompilerContext(TypeSystemClang *ts, clang::DeclContext *decl_ctx, std::vector< lldb_private::CompilerContext > &context)
static bool GetVBaseBitOffset(VTableContextBase &vtable_ctx, ValueObject &valobj, const ASTRecordLayout &record_layout, const CXXRecordDecl *cxx_record_decl, const CXXRecordDecl *base_class_decl, int32_t &bit_offset)
static const clang::EnumType * GetCompleteEnumType(clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion)
Returns the clang::EnumType of the specified qual_type.
static bool QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext &ast, QualType qual_type)
static ClangASTMap & GetASTMap()
static bool GetCompleteQualType(clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion=true)
static void SetMemberOwningModule(clang::Decl *member, const clang::Decl *parent)
static bool ClassTemplateAllowsToInstantiationArgs(ClassTemplateDecl *class_template_decl, const TypeSystemClang::TemplateParameterInfos &instantiation_values)
Returns true if the given class template declaration could produce an instantiation with the specifie...
#define LLDB_INVALID_DECL_LEVEL
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info) override
DiagnosticConsumer * clone(DiagnosticsEngine &Diags) const
A section + offset based address class.
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool CharIsSignedByDefault() const
Returns true if 'char' is a signed type by default in the architecture false otherwise.
Manages and observes all Clang AST node importing in LLDB.
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
"lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can be called.
"lldb/Expression/ClangPersistentVariables.h" Manages persistent values that need to be preserved betw...
"lldb/Expression/ClangUserExpression.h" Encapsulates a single expression for use with Clang
Represents a generic declaration context in a program.
TypeSystem * GetTypeSystem() const
void * GetOpaqueDeclContext() const
Represents a generic declaration such as a function declaration.
lldb::TypeSystemSP GetSharedPointer() const
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
void SetCompilerType(lldb::TypeSystemWP type_system, lldb::opaque_compiler_type_t type)
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
lldb::Encoding GetEncoding(uint64_t &count) const
size_t GetIndexOfChildMemberWithName(llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) const
Lookup a child member given a name.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
LLVM_DUMP_METHOD void dump() const
Dumping types.
uint32_t GetNumDirectBaseClasses() const
ConstString GetTypeName(bool BaseOnly=false) const
uint32_t GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
bool DumpTypeValue(Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope)
bool IsAggregateType() const
lldb::Format GetFormat() const
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
bool IsIntegerType(bool &is_signed) const
bool GetCompleteType() const
Type Completion.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
std::optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
A class that describes the declaration location of a lldb object.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
bool Test(ValueType bit) const
Test a single flag bit.
bool AnySet(ValueType mask) const
Test one or more flags.
Encapsulates a function that can be called.
static bool LanguageIsC(lldb::LanguageType language)
static bool LanguageIsCPlusPlus(lldb::LanguageType language)
static bool LanguageIsPascal(lldb::LanguageType language)
static bool LanguageIsObjC(lldb::LanguageType language)
A class that describes an executable image and its associated object and symbol files.
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
virtual size_t GetByteOffsetForIvar(CompilerType &parent_qual_type, const char *ivar_name)
static ObjCLanguageRuntime * Get(Process &process)
unsigned GetValue() const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
uint32_t GetAddressByteSize() const
The TypeSystemClang instance used for the scratch ASTContext in a lldb::Target.
void Finalize() override
Free up any resources associated with this TypeSystem.
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
llvm::Triple m_triple
The target triple.
std::unique_ptr< ClangASTSource > CreateASTSource()
lldb::TargetWP m_target_wp
TypeSystemClang & GetIsolatedAST(IsolatedASTKind feature)
Returns the requested sub-AST.
UserExpression * GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, Expression::ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj) override
std::unique_ptr< ClangASTSource > m_scratch_ast_source_up
The ExternalASTSource that performs lookups and completes minimally imported types.
IsolatedASTKind
The different kinds of isolated ASTs within the scratch TypeSystem.
@ CppModules
The isolated AST for declarations/types from expressions that imported type information from a C++ mo...
std::unique_ptr< ClangPersistentVariables > m_persistent_variables
The persistent variables associated with this process for the expression parser.
static char ID
LLVM RTTI support.
PersistentExpressionState * GetPersistentExpressionState() override
FunctionCaller * GetFunctionCaller(const CompilerType &return_type, const Address &function_address, const ValueList &arg_value_list, const char *name) override
std::unique_ptr< UtilityFunction > CreateUtilityFunction(std::string text, std::string name) override
void ForgetSource(clang::ASTContext *src_ctx, ClangASTImporter &importer)
Unregisters the given ASTContext as a source from the scratch AST (and all sub-ASTs).
void Dump(llvm::raw_ostream &output) override
static const std::nullopt_t DefaultAST
Alias for requesting the default scratch TypeSystemClang in GetForTarget.
ScratchTypeSystemClang(Target &target, llvm::Triple triple)
llvm::DenseMap< IsolatedASTKey, std::shared_ptr< TypeSystemClang > > m_isolated_asts
Map from IsolatedASTKind to their actual TypeSystemClang instance.
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
Provides public interface for all SymbolFiles.
virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx)
virtual bool CompleteType(CompilerType &compiler_type)=0
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list)=0
virtual std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx)=0
If type_uid points to an array type, return its characteristics.
llvm::Expected< lldb::TypeSystemSP > GetScratchTypeSystemForLanguage(lldb::LanguageType language, bool create_on_demand=true)
const ArchSpec & GetArchitecture() const
void Insert(_KeyType k, _ValueType v)
_ValueType Lookup(_KeyType k)
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
The implementation of lldb::Type's m_payload field for TypeSystemClang.
void SetIsCompleteObjCClass(bool is_complete_objc_class)
bool IsCompleteObjCClass()
Type::Payload m_payload
The payload is used for typedefs and ptrauth types.
TypePayloadClang()=default
void SetOwningModule(OptionalClangModuleID id)
static constexpr unsigned ObjCClassBit
llvm::ArrayRef< clang::TemplateArgument > GetParameterPackArgs() const
clang::TemplateArgument const & Front() const
llvm::StringRef GetPackName() const
bool hasParameterPack() const
TemplateParameterInfos const & GetParameterPack() const
llvm::ArrayRef< const char * > GetNames() const
llvm::ArrayRef< clang::TemplateArgument > GetArgs() const
A TypeSystem implementation based on Clang.
bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override
clang::TranslationUnitDecl * GetTranslationUnitDecl()
size_t GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) override
static clang::TypedefNameDecl * GetAsTypedefDecl(const CompilerType &type)
std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl, bool qualified=true)
Returns the internal type name for the given NamedDecl using the type printing policy.
static clang::ObjCInterfaceDecl * GetAsObjCInterfaceDecl(const CompilerType &type)
uint32_t m_pointer_byte_size
bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope) override
std::string m_display_name
A string describing what this TypeSystemClang represents (e.g., AST for debug information,...
ConstString GetTypeName(lldb::opaque_compiler_type_t type, bool base_only) override
static void SetOwningModule(clang::Decl *decl, OptionalClangModuleID owning_module)
Set the owning module for decl.
std::unique_ptr< clang::TargetInfo > m_target_info_up
std::unique_ptr< clang::LangOptions > m_language_options_up
Scalar DeclGetConstantValue(void *opaque_decl) override
bool BaseSpecifierIsEmpty(const clang::CXXBaseSpecifier *b)
static uint32_t GetNumPointeeChildren(clang::QualType type)
ConstString DeclGetMangledName(void *opaque_decl) override
CompilerType GetBasicType(lldb::BasicType type)
clang::ClassTemplateDecl * CreateClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef class_name, int kind, const TemplateParameterInfos &infos)
void SetExternalSource(llvm::IntrusiveRefCntPtr< clang::ExternalASTSource > &ast_source_up)
clang::UsingDecl * CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, OptionalClangModuleID owning_module, clang::NamedDecl *target)
static clang::AccessSpecifier ConvertAccessTypeToAccessSpecifier(lldb::AccessType access)
CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override
std::optional< uint64_t > GetByteSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope)
bool IsForcefullyCompleted(lldb::opaque_compiler_type_t type) override
bool SupportsLanguage(lldb::LanguageType language) override
uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override
OptionalClangModuleID GetOrCreateClangModule(llvm::StringRef name, OptionalClangModuleID parent, bool is_framework=false, bool is_explicit=false)
Synthesize a clang::Module and return its ID or a default-constructed ID.
void CompleteTagDecl(clang::TagDecl *)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
std::shared_ptr< clang::TargetOptions > & getTargetOptions()
static TypeSystemClang * GetASTContext(clang::ASTContext *ast_ctx)
bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) override
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
const char * GetTargetTriple()
TypeSystemClang(llvm::StringRef name, llvm::Triple triple)
Constructs a TypeSystemClang with an ASTContext using the given triple.
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, Module *module, Target *target)
clang::TargetInfo * getTargetInfo()
clang::FunctionTemplateDecl * CreateFunctionTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos)
CompilerType CreateArrayType(const CompilerType &element_type, std::optional< size_t > element_count, bool is_vector)
static bool AreTypesSame(CompilerType type1, CompilerType type2, bool ignore_qualifiers=false)
std::optional< uint64_t > GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
CompilerType GetArrayType(lldb::opaque_compiler_type_t type, uint64_t size) override
bool IsFunctionType(lldb::opaque_compiler_type_t type) override
CompilerType GetFunctionReturnType(lldb::opaque_compiler_type_t type) override
std::optional< ClangASTMetadata > GetMetadata(const clang::Decl *object)
static bool IsObjCClassTypeAndHasIVars(const CompilerType &type, bool check_superclass)
CompilerType GetLValueReferenceType(lldb::opaque_compiler_type_t type) override
bool SetDeclIsForcefullyCompleted(const clang::TagDecl *td)
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override
bool CanPassInRegisters(const CompilerType &type) override
CompilerDecl GetStaticFieldWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name) override
static clang::DeclContext * GetDeclContextForType(clang::QualType type)
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) override
bool IsEnumerationType(lldb::opaque_compiler_type_t type, bool &is_signed) override
bool IsTemplateType(lldb::opaque_compiler_type_t type) override
CompilerType GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
static bool IsCXXClassType(const CompilerType &type)
bool IsIntegerType(lldb::opaque_compiler_type_t type, bool &is_signed) override
void SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object, clang::AccessSpecifier access)
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override
static bool IsOperator(llvm::StringRef name, clang::OverloadedOperatorKind &op_kind)
bool IsCharType(lldb::opaque_compiler_type_t type) override
CompilerType CreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
static void SetFloatingInitializerForVariable(clang::VarDecl *var, const llvm::APFloat &init_value)
Initializes a variable with a floating point value.
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type) override
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) override
CompilerType GetType(clang::QualType qt)
Creates a CompilerType from the given QualType with the current TypeSystemClang instance as the Compi...
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override
std::string m_target_triple
bool TransferBaseClasses(lldb::opaque_compiler_type_t type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier > > bases)
bool IsBeingDefined(lldb::opaque_compiler_type_t type) override
ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override
std::unique_ptr< clang::IdentifierTable > m_identifier_table_up
std::optional< uint64_t > GetObjCBitSize(clang::QualType qual_type, ExecutionContextScope *exe_scope)
static lldb::BasicType GetBasicTypeEnumeration(llvm::StringRef name)
static void SetIntegerInitializerForVariable(clang::VarDecl *var, const llvm::APInt &init_value)
Initializes a variable with an integer value.
bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override
CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) override
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override
std::unique_ptr< clang::SourceManager > m_source_manager_up
bool IsVoidType(lldb::opaque_compiler_type_t type) override
static void SetIsPacked(const CompilerType &type)
void ForEachEnumerator(lldb::opaque_compiler_type_t type, std::function< bool(const CompilerType &integer_type, ConstString name, const llvm::APSInt &value)> const &callback) override
clang::AccessSpecifier GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object)
CompilerType CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *class_template_specialization_decl)
bool IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) override
void CreateFunctionTemplateSpecializationInfo(clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template, const TemplateParameterInfos &infos)
llvm::StringRef getDisplayName() const
Returns the display name of this TypeSystemClang that indicates what purpose it serves in LLDB.
bool IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length)
CompilerType GetRValueReferenceType(lldb::opaque_compiler_type_t type) override
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
unsigned GetPtrAuthDiscriminator(lldb::opaque_compiler_type_t type) override
CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override
bool GetCompleteType(lldb::opaque_compiler_type_t type) override
bool IsBlockPointerType(lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) override
bool IsConst(lldb::opaque_compiler_type_t type) override
static clang::AccessSpecifier UnifyAccessSpecifiers(clang::AccessSpecifier lhs, clang::AccessSpecifier rhs)
std::unique_ptr< clang::CXXBaseSpecifier > CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, lldb::AccessType access, bool is_virtual, bool base_of_class)
CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override
std::vector< CompilerDecl > DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, const bool ignore_using_decls) override
void setSema(clang::Sema *s)
uint32_t GetPointerByteSize() override
bool IsCompleteType(lldb::opaque_compiler_type_t type) override
void Dump(llvm::raw_ostream &output) override
CompilerType GetIntTypeFromBitSize(size_t bit_size, bool is_signed)
clang::MangleContext * getMangleContext()
void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *)
unsigned GetPtrAuthKey(lldb::opaque_compiler_type_t type) override
static void DumpDeclContextHiearchy(clang::DeclContext *decl_ctx)
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
CompilerType GetTypeForFormatters(void *type) override
void SetMetadataAsUserID(const clang::Decl *decl, lldb::user_id_t user_id)
bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override
This is used by swift.
static LanguageSet GetSupportedLanguagesForExpressions()
CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override
CompilerDeclContext GetCompilerDeclContextForType(const CompilerType &type) override
Returns the direct parent context of specified type.
std::unique_ptr< clang::SelectorTable > m_selector_table_up
PDBASTParser * GetPDBParser() override
std::optional< CompilerType::IntegralTemplateArgument > GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
bool DeclContextIsClassMethod(void *opaque_decl_ctx) override
void SetTargetTriple(llvm::StringRef target_triple)
CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
static bool CheckOverloadedOperatorKindParameterCount(bool is_method, clang::OverloadedOperatorKind op_kind, uint32_t num_params)
clang::DeclarationName GetDeclarationName(llvm::StringRef name, const CompilerType &function_clang_type)
DeclMetadataMap m_decl_metadata
Maps Decls to their associated ClangASTMetadata.
static clang::CXXMethodDecl * DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc)
CompilerType GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override
uint32_t CountDeclLevels(clang::DeclContext *frame_decl_ctx, clang::DeclContext *child_decl_ctx, ConstString *child_name=nullptr, CompilerType *child_type=nullptr)
static clang::QualType GetQualType(lldb::opaque_compiler_type_t type)
clang::PrintingPolicy GetTypePrintingPolicy()
Returns the PrintingPolicy used when generating the internal type names.
uint32_t GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override
static clang::RecordDecl * GetAsRecordDecl(const CompilerType &type)
CompilerType GetPointerSizedIntType(bool is_signed)
clang::FunctionDecl * CreateFunctionDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, const CompilerType &function_Type, clang::StorageClass storage, bool is_inline)
uint32_t GetNumBaseClasses(const clang::CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes)
lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) override
std::unique_ptr< DWARFASTParserClang > m_dwarf_ast_parser_up
CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size)
bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override
int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override
static void BuildIndirectFields(const CompilerType &type)
std::unique_ptr< clang::FileManager > m_file_manager_up
uint32_t GetIndexForRecordBase(const clang::RecordDecl *record_decl, const clang::CXXBaseSpecifier *base_spec, bool omit_empty_base_classes)
bool IsAnonymousType(lldb::opaque_compiler_type_t type) override
bool Verify(lldb::opaque_compiler_type_t type) override
Verify the integrity of the type to catch CompilerTypes that mix and match invalid TypeSystem/Opaque ...
size_t GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override
void AddMethodOverridesForCXXRecordType(lldb::opaque_compiler_type_t type)
CompilerType CreateBlockPointerType(const CompilerType &function_type)
lldb::LanguageType GetMinimumLanguage(lldb::opaque_compiler_type_t type) override
bool FieldIsBitfield(clang::FieldDecl *field, uint32_t &bitfield_bit_size)
clang::ClassTemplateSpecializationDecl * CreateClassTemplateSpecializationDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::ClassTemplateDecl *class_template_decl, int kind, const TemplateParameterInfos &infos)
std::unique_ptr< clang::HeaderSearch > m_header_search_up
void Finalize() override
Free up any resources associated with this TypeSystem.
clang::CXXMethodDecl * AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, llvm::StringRef name, const char *mangled_name, const CompilerType &method_type, lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, bool is_explicit, bool is_attr_used, bool is_artificial)
static clang::ASTContext * DeclContextGetTypeSystemClang(const CompilerDeclContext &dc)
uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, CompilerType *base_type_ptr) override
clang::EnumConstantDecl * AddEnumerationValueToEnumerationType(const CompilerType &enum_type, const Declaration &decl, const char *name, int64_t enum_value, uint32_t enum_value_bit_size)
LLVM_DUMP_METHOD void dump(lldb::opaque_compiler_type_t type) const override
Convenience LLVM-style dump method for use in the debugger only.
CXXRecordDeclAccessMap m_cxx_record_decl_access
Maps CXXRecordDecl to their most recent added method/field's AccessSpecifier.
clang::NamespaceDecl * GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool is_inline=false)
std::unique_ptr< clang::ASTContext > m_ast_up
CompilerType CreateGenericFunctionPrototype() override
static clang::QualType GetCanonicalQualType(lldb::opaque_compiler_type_t type)
CompilerType DeclGetFunctionReturnType(void *opaque_decl) override
static bool IsEnumType(lldb::opaque_compiler_type_t type)
std::unique_ptr< npdb::PdbAstBuilder > m_native_pdb_ast_parser_up
static clang::CXXRecordDecl * GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type)
CompilerType GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name) override
static bool SetObjCSuperClass(const CompilerType &type, const CompilerType &superclass_compiler_type)
clang::UsingDirectiveDecl * CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::NamespaceDecl *ns_decl)
static lldb::opaque_compiler_type_t GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type)
bool IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) override
void DumpFromSymbolFile(Stream &s, llvm::StringRef symbol_name)
Dump clang AST types from the symbol file.
CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override
static void DumpDeclHiearchy(clang::Decl *decl)
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
static clang::FunctionDecl * DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc)
bool IsScalarType(lldb::opaque_compiler_type_t type) override
bool GetPtrAuthAddressDiversity(lldb::opaque_compiler_type_t type) override
std::shared_ptr< clang::TargetOptions > m_target_options_rp
lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override
static bool IsClassType(lldb::opaque_compiler_type_t type)
bool IsDefined(lldb::opaque_compiler_type_t type) override
static bool IsObjCClassType(const CompilerType &type)
TypeMetadataMap m_type_metadata
Maps Types to their associated ClangASTMetadata.
const llvm::fltSemantics & GetFloatTypeSemantics(size_t byte_size) override
CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override
bool RecordHasFields(const clang::RecordDecl *record_decl)
CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index) override
static std::optional< ClangASTMetadata > DeclContextGetMetaData(const CompilerDeclContext &dc, const clang::Decl *object)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override
static clang::ObjCMethodDecl * AddMethodToObjCObjectType(const CompilerType &type, const char *name, const CompilerType &method_compiler_type, bool is_artificial, bool is_variadic, bool is_objc_direct_call)
~TypeSystemClang() override
CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, void *other_opaque_decl_ctx) override
CompilerType AddPtrAuthModifier(lldb::opaque_compiler_type_t type, uint32_t payload) override
static bool AddObjCClassProperty(const CompilerType &type, const char *property_name, const CompilerType &property_compiler_type, clang::ObjCIvarDecl *ivar_decl, const char *property_setter_name, const char *property_getter_name, uint32_t property_attributes, ClangASTMetadata metadata)
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
void SetMetadata(const clang::Decl *object, ClangASTMetadata meta_data)
CompilerType CreateEnumerationType(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const Declaration &decl, const CompilerType &integer_qual_type, bool is_scoped)
clang::ParmVarDecl * CreateParameterDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const char *name, const CompilerType ¶m_type, int storage, bool add_decl=false)
void DumpTypeDescription(lldb::opaque_compiler_type_t type, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) override
Dump the type to stdout.
CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, size_t idx) override
static clang::NamespaceDecl * DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc)
npdb::PdbAstBuilder * GetNativePDBParser() override
std::unique_ptr< clang::DiagnosticConsumer > m_diagnostic_consumer_up
CompilerType CreateObjCClass(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool isInternal, std::optional< ClangASTMetadata > metadata=std::nullopt)
CompilerType GetTypeForDecl(clang::NamedDecl *decl)
CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
static clang::DeclContext * DeclContextGetAsDeclContext(const CompilerDeclContext &dc)
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, uint64_t &count) override
bool IsTypedefType(lldb::opaque_compiler_type_t type) override
CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override
std::optional< size_t > GetTypeBitAlign(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
std::unique_ptr< clang::Builtin::Context > m_builtins_up
CompilerType GetBuiltinTypeByName(ConstString name) override
bool GetCompleteDecl(clang::Decl *decl)
static bool StartTagDeclarationDefinition(const CompilerType &type)
uint32_t GetIndexForRecordChild(const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl, bool omit_empty_base_classes)
bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, CompilerType *target_type, bool check_cplusplus, bool check_objc) override
CompilerType GetOrCreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
void LogCreation() const
Emits information about this TypeSystem into the expression log.
static llvm::StringRef GetPluginNameStatic()
clang::Sema * m_sema
The sema associated that is currently used to build this ASTContext.
size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override
static clang::VarDecl * AddVariableToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &var_type, lldb::AccessType access)
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override
const clang::ClassTemplateSpecializationDecl * GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type)
std::unique_ptr< clang::MangleContext > m_mangle_ctx_up
TypeMemberFunctionImpl GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) override
bool IsTypeImpl(lldb::opaque_compiler_type_t type, llvm::function_ref< bool(clang::QualType)> predicate) const
size_t DeclGetFunctionNumArguments(void *opaque_decl) override
CompilerType CreateFunctionType(const CompilerType &result_type, const CompilerType *args, unsigned num_args, bool is_variadic, unsigned type_quals, clang::CallingConv cc=clang::CC_C, clang::RefQualifierKind ref_qual=clang::RQ_None)
CompilerType GetAtomicType(lldb::opaque_compiler_type_t type) override
std::unique_ptr< PDBASTParser > m_pdb_ast_parser_up
std::unique_ptr< clang::DiagnosticsEngine > m_diagnostics_engine_up
static std::optional< std::string > GetCXXClassName(const CompilerType &type)
static void DumpTypeName(const CompilerType &type)
plugin::dwarf::DWARFASTParser * GetDWARFParser() override
CompilerType DeclGetFunctionArgumentType(void *opaque_decl, size_t arg_idx) override
bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) override
static clang::EnumDecl * GetAsEnumDecl(const CompilerType &type)
CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override
std::unique_ptr< clang::ModuleMap > m_module_map_up
void SetFunctionParameters(clang::FunctionDecl *function_decl, llvm::ArrayRef< clang::ParmVarDecl * > params)
static bool IsObjCObjectOrInterfaceType(const CompilerType &type)
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx, uint32_t opaque_payload) override
Using the current type, create a new typedef to that type using "typedef_name" as the name and "decl_...
llvm::Expected< uint32_t > GetNumChildren(lldb::opaque_compiler_type_t type, bool omit_empty_base_classes, const ExecutionContext *exe_ctx) override
CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override
clang::TemplateTemplateParmDecl * CreateTemplateTemplateParmDecl(const char *template_name)
lldb::TemplateArgumentKind GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
clang::ClassTemplateDecl * ParseClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, const char *parent_name, int tag_decl_kind, const TypeSystemClang::TemplateParameterInfos &template_param_infos)
clang::ASTContext & getASTContext() const
Returns the clang::ASTContext instance managed by this TypeSystemClang.
std::vector< lldb_private::CompilerContext > DeclGetCompilerContext(void *opaque_decl) override
static CompilerType CreateMemberPointerType(const CompilerType &type, const CompilerType &pointee_type)
std::vector< lldb_private::CompilerContext > DeclContextGetCompilerContext(void *opaque_decl_ctx) override
void CreateASTContext()
Creates the internal ASTContext.
CompilerType GetCStringType(bool is_const)
bool IsAggregateType(lldb::opaque_compiler_type_t type) override
uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes) override
static bool IsObjCObjectPointerType(const CompilerType &type, CompilerType *target_type=nullptr)
bool IsVectorType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size) override
static LanguageSet GetSupportedLanguagesForTypes()
clang::VarDecl * CreateVariableDeclaration(clang::DeclContext *decl_context, OptionalClangModuleID owning_module, const char *name, clang::QualType type)
clang::BlockDecl * CreateBlockDeclaration(clang::DeclContext *ctx, OptionalClangModuleID owning_module)
ConstString DeclContextGetName(void *opaque_decl_ctx) override
size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type, bool expand_pack) override
ConstString DeclGetName(void *opaque_decl) override
Interface for representing a type system.
virtual SymbolFile * GetSymbolFile() const
bool m_has_forcefully_completed_types
Used for reporting statistics.
Encapsulates a one-time expression for use in lldb.
virtual uint64_t GetData(DataExtractor &data, Status &error)
CompilerType GetCompilerType()
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
AddressType GetAddressTypeOfChildren()
ConstString GetName() const
const ExecutionContextRef & GetExecutionContextRef() const
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_IVAR_OFFSET
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
lldb::offset_t DumpDataExtractor(const DataExtractor &DE, Stream *s, lldb::offset_t offset, lldb::Format item_format, size_t item_byte_size, size_t item_count, size_t num_per_line, uint64_t base_addr, uint32_t item_bit_size, uint32_t item_bit_offset, ExecutionContextScope *exe_scope=nullptr, bool show_memory_tags=false)
Dumps item_count objects into the stream s.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
void * opaque_compiler_type_t
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedShort
@ eBasicTypeUnsignedInt128
@ eBasicTypeUnsignedWChar
@ eBasicTypeLongDoubleComplex
@ eBasicTypeUnsignedLongLong
@ eBasicTypeDoubleComplex
Format
Display format definitions.
@ eFormatCString
NULL terminated C strings.
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
@ eFormatVoid
Do not print this.
@ eFormatComplex
Floating point complex type.
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
LanguageType
Programming language type.
@ eLanguageTypeC_plus_plus_20
ISO C++:2020.
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
@ eLanguageTypeC11
ISO C:2011.
@ eLanguageTypeC99
ISO C:1999.
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeC_plus_plus_17
ISO C++:2017.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
@ eLanguageTypeC89
ISO C:1989.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
@ eLanguageTypeDylan
Dylan.
std::shared_ptr< lldb_private::Type > TypeSP
@ eTemplateArgumentKindTemplate
@ eTemplateArgumentKindTemplateExpansion
@ eTemplateArgumentKindNull
@ eTemplateArgumentKindNullPtr
@ eTemplateArgumentKindDeclaration
@ eTemplateArgumentKindIntegral
@ eTemplateArgumentKindPack
@ eTemplateArgumentKindType
@ eTemplateArgumentKindStructuralValue
@ eTemplateArgumentKindExpression
Encoding
Register encoding definitions.
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
MemberFunctionKind
Kind of member function.
@ eMemberFunctionKindInstanceMethod
A function that applies to a specific instance.
@ eMemberFunctionKindConstructor
A function used to create instances.
@ eMemberFunctionKindUnknown
Not sure what the type of this is.
@ eMemberFunctionKindDestructor
A function used to tear down existing instances.
@ eMemberFunctionKindStaticMethod
A function that applies to a type rather than any instance.
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::Target > TargetSP
static clang::QualType GetQualType(const CompilerType &ct)
static clang::QualType GetCanonicalQualType(const CompilerType &ct)
static bool IsClangType(const CompilerType &ct)
static CompilerType RemoveFastQualifiers(const CompilerType &ct)
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
void Insert(lldb::LanguageType language)
A type-erased pair of llvm::dwarf::SourceLanguageName and version.