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"
92using llvm::StringSwitch;
97static void VerifyDecl(clang::Decl *decl) {
98 assert(decl &&
"VerifyDecl called with nullptr?");
124bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
126 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
127 "Methods should have the same AST context");
128 clang::ASTContext &context = m1->getASTContext();
130 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
131 context.getCanonicalType(m1->getType()));
133 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
134 context.getCanonicalType(m2->getType()));
136 auto compareArgTypes = [&context](
const clang::QualType &m1p,
137 const clang::QualType &m2p) {
138 return context.hasSameType(m1p.getUnqualifiedType(),
139 m2p.getUnqualifiedType());
144 return (m1->getNumParams() != m2->getNumParams()) ||
145 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
146 m2Type->param_type_begin(), compareArgTypes);
152void addOverridesForMethod(clang::CXXMethodDecl *decl) {
153 if (!decl->isVirtual())
156 clang::CXXBasePaths paths;
157 llvm::SmallVector<clang::NamedDecl *, 4> decls;
159 auto find_overridden_methods =
160 [&decls, decl](
const clang::CXXBaseSpecifier *specifier,
161 clang::CXXBasePath &path) {
162 if (
auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
163 specifier->getType()->castAs<clang::RecordType>()->getDecl())) {
165 clang::DeclarationName name = decl->getDeclName();
169 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
170 if (
auto *baseDtorDecl = base_record->getDestructor()) {
171 if (baseDtorDecl->isVirtual()) {
172 decls.push_back(baseDtorDecl);
179 for (path.Decls = base_record->lookup(name).begin();
180 path.Decls != path.Decls.end(); ++path.Decls) {
181 if (
auto *method_decl =
182 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
183 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
184 decls.push_back(method_decl);
193 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
194 for (
auto *overridden_decl : decls)
195 decl->addOverriddenMethod(
196 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
202 VTableContextBase &vtable_ctx,
204 const ASTRecordLayout &record_layout) {
208 uint32_t type_info = this_type.
GetTypeInfo(&pointee_type);
213 bool ptr_or_ref =
false;
214 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
220 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
221 if ((type_info & cpp_class) != cpp_class)
226 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
240 vbtable_ptr_addr += vbtable_ptr_offset;
251 auto size = valobj.
GetData(data, err);
259 VTableContextBase &vtable_ctx,
261 const CXXRecordDecl *cxx_record_decl,
262 const CXXRecordDecl *base_class_decl) {
263 if (vtable_ctx.isMicrosoft()) {
264 clang::MicrosoftVTableContext &msoft_vtable_ctx =
265 static_cast<clang::MicrosoftVTableContext &
>(vtable_ctx);
269 const unsigned vbtable_index =
270 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
271 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
277 clang::ItaniumVTableContext &itanium_vtable_ctx =
278 static_cast<clang::ItaniumVTableContext &
>(vtable_ctx);
280 clang::CharUnits base_offset_offset =
281 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
284 vtable_ptr + base_offset_offset.getQuantity();
293 const ASTRecordLayout &record_layout,
294 const CXXRecordDecl *cxx_record_decl,
295 const CXXRecordDecl *base_class_decl,
296 int32_t &bit_offset) {
308 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
309 if (base_offset == INT64_MAX)
312 bit_offset = base_offset * 8;
322 static llvm::once_flag g_once_flag;
323 llvm::call_once(g_once_flag, []() {
330 bool is_complete_objc_class)
331 : m_payload(owning_module.GetValue()) {
343 const clang::Decl *parent) {
344 if (!member || !parent)
351 member->setFromASTFile();
352 member->setOwningModuleID(
id.GetValue());
353 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
354 if (llvm::isa<clang::NamedDecl>(member))
355 if (
auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
356 dc->setHasExternalVisibleStorage(
true);
359 dc->setHasExternalLexicalStorage(
true);
366 clang::OverloadedOperatorKind &op_kind) {
368 if (!name.consume_front(
"operator"))
373 bool space_after_operator = name.consume_front(
" ");
375 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
376 .Case(
"+", clang::OO_Plus)
377 .Case(
"+=", clang::OO_PlusEqual)
378 .Case(
"++", clang::OO_PlusPlus)
379 .Case(
"-", clang::OO_Minus)
380 .Case(
"-=", clang::OO_MinusEqual)
381 .Case(
"--", clang::OO_MinusMinus)
382 .Case(
"->", clang::OO_Arrow)
383 .Case(
"->*", clang::OO_ArrowStar)
384 .Case(
"*", clang::OO_Star)
385 .Case(
"*=", clang::OO_StarEqual)
386 .Case(
"/", clang::OO_Slash)
387 .Case(
"/=", clang::OO_SlashEqual)
388 .Case(
"%", clang::OO_Percent)
389 .Case(
"%=", clang::OO_PercentEqual)
390 .Case(
"^", clang::OO_Caret)
391 .Case(
"^=", clang::OO_CaretEqual)
392 .Case(
"&", clang::OO_Amp)
393 .Case(
"&=", clang::OO_AmpEqual)
394 .Case(
"&&", clang::OO_AmpAmp)
395 .Case(
"|", clang::OO_Pipe)
396 .Case(
"|=", clang::OO_PipeEqual)
397 .Case(
"||", clang::OO_PipePipe)
398 .Case(
"~", clang::OO_Tilde)
399 .Case(
"!", clang::OO_Exclaim)
400 .Case(
"!=", clang::OO_ExclaimEqual)
401 .Case(
"=", clang::OO_Equal)
402 .Case(
"==", clang::OO_EqualEqual)
403 .Case(
"<", clang::OO_Less)
404 .Case(
"<=>", clang::OO_Spaceship)
405 .Case(
"<<", clang::OO_LessLess)
406 .Case(
"<<=", clang::OO_LessLessEqual)
407 .Case(
"<=", clang::OO_LessEqual)
408 .Case(
">", clang::OO_Greater)
409 .Case(
">>", clang::OO_GreaterGreater)
410 .Case(
">>=", clang::OO_GreaterGreaterEqual)
411 .Case(
">=", clang::OO_GreaterEqual)
412 .Case(
"()", clang::OO_Call)
413 .Case(
"[]", clang::OO_Subscript)
414 .Case(
",", clang::OO_Comma)
415 .Default(clang::NUM_OVERLOADED_OPERATORS);
418 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
430 if (!space_after_operator)
435 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
436 .Case(
"new", clang::OO_New)
437 .Case(
"new[]", clang::OO_Array_New)
438 .Case(
"delete", clang::OO_Delete)
439 .Case(
"delete[]", clang::OO_Array_Delete)
441 .Default(clang::NUM_OVERLOADED_OPERATORS);
446clang::AccessSpecifier
466 std::vector<std::string> Includes;
467 LangOptions::setLangDefaults(Opts, clang::Language::ObjCXX, arch.
GetTriple(),
468 Includes, clang::LangStandard::lang_gnucxx98);
470 Opts.setValueVisibilityMode(DefaultVisibility);
474 Opts.Trigraphs = !Opts.GNUMode;
476 Opts.OptimizeSize = 0;
489 Opts.NoInlineDefine = !Opt;
493 Opts.ModulesLocalVisibility = 1;
497 llvm::Triple target_triple) {
499 if (!target_triple.str().empty())
509 ASTContext &existing_ctxt) {
525 if (!TypeSystemClangSupportsLanguage(language))
539 if (triple.getVendor() == llvm::Triple::Apple &&
540 triple.getOS() == llvm::Triple::UnknownOS) {
541 if (triple.getArch() == llvm::Triple::arm ||
542 triple.getArch() == llvm::Triple::aarch64 ||
543 triple.getArch() == llvm::Triple::aarch64_32 ||
544 triple.getArch() == llvm::Triple::thumb) {
545 triple.setOS(llvm::Triple::IOS);
547 triple.setOS(llvm::Triple::MacOSX);
552 std::string ast_name =
554 return std::make_shared<TypeSystemClang>(ast_name, triple);
555 }
else if (target && target->
IsValid())
556 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
618 assert(s ==
nullptr || &s->getASTContext() ==
m_ast_up.get());
631 llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
633 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(
true);
634 ast.setExternalSource(ast_source_up);
647 const clang::Diagnostic &info)
override {
649 llvm::SmallVector<char, 32> diag_str(10);
650 info.FormatDiagnostic(diag_str);
651 diag_str.push_back(
'\0');
652 LLDB_LOGF(m_log,
"Compiler diagnostic: %s\n", diag_str.data());
656 DiagnosticConsumer *
clone(DiagnosticsEngine &Diags)
const {
677 clang::FileSystemOptions file_system_options;
681 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(
new DiagnosticIDs());
683 std::make_unique<DiagnosticsEngine>(diag_id_sp,
new DiagnosticOptions());
687 m_ast_up = std::make_unique<ASTContext>(
699 m_ast_up->InitBuiltinTypes(*target_info);
703 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
736#pragma mark Basic Types
739 ASTContext &ast, QualType qual_type) {
740 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
741 return qual_type_bit_size == bit_size;
756 return GetType(ast.UnsignedCharTy);
758 return GetType(ast.UnsignedShortTy);
760 return GetType(ast.UnsignedIntTy);
762 return GetType(ast.UnsignedLongTy);
764 return GetType(ast.UnsignedLongLongTy);
766 return GetType(ast.UnsignedInt128Ty);
771 return GetType(ast.SignedCharTy);
779 return GetType(ast.LongLongTy);
790 return GetType(ast.LongDoubleTy);
797 if (bit_size && !(bit_size & 0x7u))
798 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
806 static const llvm::StringMap<lldb::BasicType> g_type_map = {
859 auto iter = g_type_map.find(name);
860 if (iter == g_type_map.end())
887 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
903 return GetType(ast.UnsignedCharTy);
905 return GetType(ast.UnsignedShortTy);
907 return GetType(ast.UnsignedIntTy);
912 if (type_name.contains(
"complex")) {
921 case DW_ATE_complex_float: {
922 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
924 return GetType(FloatComplexTy);
926 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
928 return GetType(DoubleComplexTy);
930 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
932 return GetType(LongDoubleComplexTy);
942 if (type_name ==
"float" &&
945 if (type_name ==
"double" &&
948 if (type_name ==
"long double" &&
950 return GetType(ast.LongDoubleTy);
957 return GetType(ast.LongDoubleTy);
963 if (!type_name.empty()) {
964 if (type_name ==
"wchar_t" &&
969 if (type_name ==
"void" &&
972 if (type_name.contains(
"long long") &&
974 return GetType(ast.LongLongTy);
975 if (type_name.contains(
"long") &&
978 if (type_name.contains(
"short") &&
981 if (type_name.contains(
"char")) {
985 return GetType(ast.SignedCharTy);
987 if (type_name.contains(
"int")) {
1004 return GetType(ast.LongLongTy);
1009 case DW_ATE_signed_char:
1010 if (type_name ==
"char") {
1015 return GetType(ast.SignedCharTy);
1018 case DW_ATE_unsigned:
1019 if (!type_name.empty()) {
1020 if (type_name ==
"wchar_t") {
1027 if (type_name.contains(
"long long")) {
1029 return GetType(ast.UnsignedLongLongTy);
1030 }
else if (type_name.contains(
"long")) {
1032 return GetType(ast.UnsignedLongTy);
1033 }
else if (type_name.contains(
"short")) {
1035 return GetType(ast.UnsignedShortTy);
1036 }
else if (type_name.contains(
"char")) {
1038 return GetType(ast.UnsignedCharTy);
1039 }
else if (type_name.contains(
"int")) {
1041 return GetType(ast.UnsignedIntTy);
1043 return GetType(ast.UnsignedInt128Ty);
1048 return GetType(ast.UnsignedCharTy);
1050 return GetType(ast.UnsignedShortTy);
1052 return GetType(ast.UnsignedIntTy);
1054 return GetType(ast.UnsignedLongTy);
1056 return GetType(ast.UnsignedLongLongTy);
1058 return GetType(ast.UnsignedInt128Ty);
1061 case DW_ATE_unsigned_char:
1062 if (type_name ==
"char") {
1067 return GetType(ast.UnsignedCharTy);
1069 return GetType(ast.UnsignedShortTy);
1072 case DW_ATE_imaginary_float:
1084 if (!type_name.empty()) {
1085 if (type_name ==
"char16_t")
1087 if (type_name ==
"char32_t")
1089 if (type_name ==
"char8_t")
1098 "error: need to add support for DW_TAG_base_type '{0}' "
1099 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1100 type_name, dw_ate, bit_size);
1106 QualType char_type(ast.CharTy);
1109 char_type.addConst();
1111 return GetType(ast.getPointerType(char_type));
1115 bool ignore_qualifiers) {
1126 if (ignore_qualifiers) {
1127 type1_qual = type1_qual.getUnqualifiedType();
1128 type2_qual = type2_qual.getUnqualifiedType();
1131 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1138 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
1139 if (
auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1151 if (clang::ObjCInterfaceDecl *interface_decl =
1152 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1154 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1156 if (clang::ValueDecl *value_decl = llvm::dyn_cast<clang::ValueDecl>(decl))
1170 return GetType(value_decl->getType());
1173#pragma mark Structure, Unions, Classes
1177 if (!decl || !owning_module.
HasValue())
1180 decl->setFromASTFile();
1181 decl->setOwningModuleID(owning_module.
GetValue());
1182 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1188 bool is_framework,
bool is_explicit) {
1190 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1192 assert(ast_source &&
"external ast source was lost");
1198 auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1209 clang::Module *module;
1210 auto parent_desc = ast_source->getSourceDescriptor(parent.
GetValue());
1212 name, parent_desc ? parent_desc->getModuleOrNull() :
nullptr,
1213 is_framework, is_explicit);
1215 return ast_source->GetIDForModule(module);
1217 return ast_source->RegisterModule(module);
1222 AccessType access_type, llvm::StringRef name,
int kind,
1223 LanguageType language, std::optional<ClangASTMetadata> metadata,
1224 bool exports_symbols) {
1227 if (decl_ctx ==
nullptr)
1228 decl_ctx = ast.getTranslationUnitDecl();
1232 bool isInternal =
false;
1233 return CreateObjCClass(name, decl_ctx, owning_module, isInternal, metadata);
1242 bool has_name = !name.empty();
1243 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1244 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1245 decl->setDeclContext(decl_ctx);
1247 decl->setDeclName(&ast.Idents.get(name));
1275 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1276 decl->setAnonymousStructOrUnion(
true);
1286 decl_ctx->addDecl(decl);
1288 return GetType(ast.getTagDeclType(decl));
1294bool IsValueParam(
const clang::TemplateArgument &argument) {
1295 return argument.getKind() == TemplateArgument::Integral;
1298void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1300 clang::AccessSpecifier previous_access,
1301 clang::AccessSpecifier access_specifier) {
1302 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1304 if (previous_access != access_specifier) {
1307 if ((cxx_record_decl->isStruct() &&
1308 previous_access == clang::AccessSpecifier::AS_none &&
1309 access_specifier == clang::AccessSpecifier::AS_public) ||
1310 (cxx_record_decl->isClass() &&
1311 previous_access == clang::AccessSpecifier::AS_none &&
1312 access_specifier == clang::AccessSpecifier::AS_private)) {
1315 cxx_record_decl->addDecl(
1316 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1317 SourceLocation(), SourceLocation()));
1325 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1326 const bool parameter_pack =
false;
1327 const bool is_typename =
false;
1328 const unsigned depth = 0;
1329 const size_t num_template_params = template_param_infos.
Size();
1330 DeclContext *
const decl_context =
1331 ast.getTranslationUnitDecl();
1333 auto const &args = template_param_infos.
GetArgs();
1334 auto const &names = template_param_infos.
GetNames();
1335 for (
size_t i = 0; i < num_template_params; ++i) {
1336 const char *name = names[i];
1338 IdentifierInfo *identifier_info =
nullptr;
1339 if (name && name[0])
1340 identifier_info = &ast.Idents.get(name);
1341 TemplateArgument
const &targ = args[i];
1342 if (IsValueParam(targ)) {
1343 QualType template_param_type = targ.getIntegralType();
1344 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1345 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1346 identifier_info, template_param_type, parameter_pack,
1347 ast.getTrivialTypeSourceInfo(template_param_type)));
1349 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1350 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1351 identifier_info, is_typename, parameter_pack));
1356 IdentifierInfo *identifier_info =
nullptr;
1358 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1359 const bool parameter_pack_true =
true;
1363 QualType template_param_type =
1365 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1366 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1367 num_template_params, identifier_info, template_param_type,
1368 parameter_pack_true,
1369 ast.getTrivialTypeSourceInfo(template_param_type)));
1371 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1372 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1373 num_template_params, identifier_info, is_typename,
1374 parameter_pack_true));
1377 clang::Expr *
const requires_clause =
nullptr;
1378 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1379 ast, SourceLocation(), SourceLocation(), template_param_decls,
1380 SourceLocation(), requires_clause);
1381 return template_param_list;
1386 llvm::SmallVector<NamedDecl *, 8> ignore;
1387 clang::TemplateParameterList *template_param_list =
1390 llvm::SmallVector<clang::TemplateArgument, 2> args(
1391 template_param_infos.
GetArgs());
1393 llvm::ArrayRef<TemplateArgument> pack_args =
1395 args.append(pack_args.begin(), pack_args.end());
1398 llvm::raw_string_ostream os(str);
1400 template_param_list);
1406 clang::FunctionDecl *func_decl,
1411 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1413 ast, template_param_infos, template_param_decls);
1414 FunctionTemplateDecl *func_tmpl_decl =
1415 FunctionTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1416 func_tmpl_decl->setDeclContext(decl_ctx);
1417 func_tmpl_decl->setLocation(func_decl->getLocation());
1418 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1419 func_tmpl_decl->setTemplateParameters(template_param_list);
1420 func_tmpl_decl->init(func_decl);
1423 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1424 i < template_param_decl_count; ++i) {
1426 template_param_decls[i]->setDeclContext(func_decl);
1431 if (decl_ctx->isRecord())
1432 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1434 return func_tmpl_decl;
1438 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1440 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1441 func_decl->getASTContext(), infos.
GetArgs());
1443 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1444 template_args_ptr,
nullptr);
1451 const TemplateArgument &value) {
1452 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1454 if (value.getKind() != TemplateArgument::Type)
1456 }
else if (
auto *type_param =
1457 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1459 if (!IsValueParam(value))
1462 if (type_param->getType() != value.getIntegralType())
1470 "Don't know how to compare template parameter to passed"
1471 " value. Decl kind of parameter is: {0}",
1472 param->getDeclKindName());
1473 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1488 ClassTemplateDecl *class_template_decl,
1491 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1497 std::optional<NamedDecl *> pack_parameter;
1499 size_t non_pack_params = params.size();
1500 for (
size_t i = 0; i < params.size(); ++i) {
1501 NamedDecl *param = params.getParam(i);
1502 if (param->isParameterPack()) {
1503 pack_parameter = param;
1504 non_pack_params = i;
1512 if (non_pack_params != instantiation_values.
Size())
1530 for (
const auto pair :
1531 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1532 const TemplateArgument &passed_arg = std::get<0>(pair);
1533 NamedDecl *found_param = std::get<1>(pair);
1538 return class_template_decl;
1547 ClassTemplateDecl *class_template_decl =
nullptr;
1548 if (decl_ctx ==
nullptr)
1549 decl_ctx = ast.getTranslationUnitDecl();
1551 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1552 DeclarationName decl_name(&identifier_info);
1555 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1556 for (NamedDecl *decl : result) {
1557 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1558 if (!class_template_decl)
1567 template_param_infos))
1569 return class_template_decl;
1572 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1575 ast, template_param_infos, template_param_decls);
1577 CXXRecordDecl *template_cxx_decl =
1578 CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1579 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1581 template_cxx_decl->setDeclContext(decl_ctx);
1582 template_cxx_decl->setDeclName(decl_name);
1585 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1586 i < template_param_decl_count; ++i) {
1587 template_param_decls[i]->setDeclContext(template_cxx_decl);
1595 class_template_decl =
1596 ClassTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1598 class_template_decl->setDeclContext(decl_ctx);
1599 class_template_decl->setDeclName(decl_name);
1600 class_template_decl->setTemplateParameters(template_param_list);
1601 class_template_decl->init(template_cxx_decl);
1602 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1606 class_template_decl->setAccess(
1609 decl_ctx->addDecl(class_template_decl);
1611 VerifyDecl(class_template_decl);
1613 return class_template_decl;
1616TemplateTemplateParmDecl *
1620 auto *decl_ctx = ast.getTranslationUnitDecl();
1622 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1623 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1627 ast, template_param_infos, template_param_decls);
1633 return TemplateTemplateParmDecl::Create(ast, decl_ctx, SourceLocation(),
1636 &identifier_info,
false,
1637 template_param_list);
1640ClassTemplateSpecializationDecl *
1643 ClassTemplateDecl *class_template_decl,
int kind,
1646 llvm::SmallVector<clang::TemplateArgument, 2> args(
1647 template_param_infos.
Size() +
1650 auto const &orig_args = template_param_infos.
GetArgs();
1651 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1653 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1656 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1657 ClassTemplateSpecializationDecl::CreateDeserialized(ast, GlobalDeclID());
1658 class_template_specialization_decl->setTagKind(
1659 static_cast<TagDecl::TagKind
>(kind));
1660 class_template_specialization_decl->setDeclContext(decl_ctx);
1661 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1662 class_template_specialization_decl->setTemplateArgs(
1663 TemplateArgumentList::CreateCopy(ast, args));
1664 ast.getTypeDeclType(class_template_specialization_decl,
nullptr);
1665 class_template_specialization_decl->setDeclName(
1666 class_template_decl->getDeclName());
1668 decl_ctx->addDecl(class_template_specialization_decl);
1670 class_template_specialization_decl->setSpecializationKind(
1671 TSK_ExplicitSpecialization);
1673 return class_template_specialization_decl;
1677 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1678 if (class_template_specialization_decl) {
1680 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1686 clang::OverloadedOperatorKind op_kind,
1687 bool unary,
bool binary,
1688 uint32_t num_params) {
1690 if (op_kind == OO_Call)
1696 if (num_params == 1)
1698 if (num_params == 2)
1705 bool is_method, clang::OverloadedOperatorKind op_kind,
1706 uint32_t num_params) {
1714 case OO_Array_Delete:
1718#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1720 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1722#include "clang/Basic/OperatorKinds.def"
1729clang::AccessSpecifier
1731 clang::AccessSpecifier rhs) {
1734 if (lhs == AS_none || rhs == AS_none)
1736 if (lhs == AS_private || rhs == AS_private)
1738 if (lhs == AS_protected || rhs == AS_protected)
1739 return AS_protected;
1744 uint32_t &bitfield_bit_size) {
1746 if (field ==
nullptr)
1749 if (field->isBitField()) {
1750 Expr *bit_width_expr = field->getBitWidth();
1751 if (bit_width_expr) {
1752 if (std::optional<llvm::APSInt> bit_width_apsint =
1753 bit_width_expr->getIntegerConstantExpr(ast)) {
1754 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1763 if (record_decl ==
nullptr)
1766 if (!record_decl->field_empty())
1770 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1771 if (cxx_record_decl) {
1772 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1773 for (base_class = cxx_record_decl->bases_begin(),
1774 base_class_end = cxx_record_decl->bases_end();
1775 base_class != base_class_end; ++base_class) {
1776 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1777 base_class->getType()->getAs<RecordType>()->getDecl());
1789 if (std::optional<ClangASTMetadata> meta_data =
GetMetadata(record_decl);
1790 meta_data && meta_data->IsForcefullyCompleted())
1796#pragma mark Objective-C Classes
1799 llvm::StringRef name, clang::DeclContext *decl_ctx,
1801 std::optional<ClangASTMetadata> metadata) {
1803 assert(!name.empty());
1805 decl_ctx = ast.getTranslationUnitDecl();
1807 ObjCInterfaceDecl *decl =
1808 ObjCInterfaceDecl::CreateDeserialized(ast, GlobalDeclID());
1809 decl->setDeclContext(decl_ctx);
1810 decl->setDeclName(&ast.Idents.get(name));
1811 decl->setImplicit(isInternal);
1817 return GetType(ast.getObjCInterfaceType(decl));
1826 bool omit_empty_base_classes) {
1827 uint32_t num_bases = 0;
1828 if (cxx_record_decl) {
1829 if (omit_empty_base_classes) {
1830 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1831 for (base_class = cxx_record_decl->bases_begin(),
1832 base_class_end = cxx_record_decl->bases_end();
1833 base_class != base_class_end; ++base_class) {
1840 num_bases = cxx_record_decl->getNumBases();
1845#pragma mark Namespace Declarations
1848 const char *name, clang::DeclContext *decl_ctx,
1850 NamespaceDecl *namespace_decl =
nullptr;
1852 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1854 decl_ctx = translation_unit_decl;
1857 IdentifierInfo &identifier_info = ast.Idents.get(name);
1858 DeclarationName decl_name(&identifier_info);
1859 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1860 for (NamedDecl *decl : result) {
1861 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1863 return namespace_decl;
1866 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1867 SourceLocation(), SourceLocation(),
1868 &identifier_info,
nullptr,
false);
1870 decl_ctx->addDecl(namespace_decl);
1872 if (decl_ctx == translation_unit_decl) {
1873 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1875 return namespace_decl;
1878 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1879 SourceLocation(),
nullptr,
nullptr,
false);
1880 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1881 translation_unit_decl->addDecl(namespace_decl);
1882 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1884 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1885 if (parent_namespace_decl) {
1886 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1888 return namespace_decl;
1890 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1891 SourceLocation(),
nullptr,
nullptr,
false);
1892 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1893 parent_namespace_decl->addDecl(namespace_decl);
1894 assert(namespace_decl ==
1895 parent_namespace_decl->getAnonymousNamespace());
1897 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1898 "no namespace as decl_ctx");
1906 VerifyDecl(namespace_decl);
1907 return namespace_decl;
1914 clang::BlockDecl *decl =
1915 clang::BlockDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1916 decl->setDeclContext(ctx);
1925 clang::DeclContext *right,
1926 clang::DeclContext *root) {
1927 if (root ==
nullptr)
1930 std::set<clang::DeclContext *> path_left;
1931 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1932 path_left.insert(d);
1934 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1935 if (path_left.find(d) != path_left.end())
1943 clang::NamespaceDecl *ns_decl) {
1944 if (decl_ctx && ns_decl) {
1945 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1946 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1948 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1949 clang::SourceLocation(), ns_decl,
1952 decl_ctx->addDecl(using_decl);
1962 clang::NamedDecl *target) {
1963 if (current_decl_ctx && target) {
1964 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1966 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1968 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1970 target->getDeclName(), using_decl, target);
1972 using_decl->addShadowDecl(shadow_decl);
1973 current_decl_ctx->addDecl(using_decl);
1981 const char *name, clang::QualType type) {
1983 clang::VarDecl *var_decl =
1984 clang::VarDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1985 var_decl->setDeclContext(decl_context);
1986 if (name && name[0])
1987 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1988 var_decl->setType(type);
1990 var_decl->setAccess(clang::AS_public);
1991 decl_context->addDecl(var_decl);
2000 switch (basic_type) {
2002 return ast->VoidTy.getAsOpaquePtr();
2004 return ast->CharTy.getAsOpaquePtr();
2006 return ast->SignedCharTy.getAsOpaquePtr();
2008 return ast->UnsignedCharTy.getAsOpaquePtr();
2010 return ast->getWCharType().getAsOpaquePtr();
2012 return ast->getSignedWCharType().getAsOpaquePtr();
2014 return ast->getUnsignedWCharType().getAsOpaquePtr();
2016 return ast->Char8Ty.getAsOpaquePtr();
2018 return ast->Char16Ty.getAsOpaquePtr();
2020 return ast->Char32Ty.getAsOpaquePtr();
2022 return ast->ShortTy.getAsOpaquePtr();
2024 return ast->UnsignedShortTy.getAsOpaquePtr();
2026 return ast->IntTy.getAsOpaquePtr();
2028 return ast->UnsignedIntTy.getAsOpaquePtr();
2030 return ast->LongTy.getAsOpaquePtr();
2032 return ast->UnsignedLongTy.getAsOpaquePtr();
2034 return ast->LongLongTy.getAsOpaquePtr();
2036 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2038 return ast->Int128Ty.getAsOpaquePtr();
2040 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2042 return ast->BoolTy.getAsOpaquePtr();
2044 return ast->HalfTy.getAsOpaquePtr();
2046 return ast->FloatTy.getAsOpaquePtr();
2048 return ast->DoubleTy.getAsOpaquePtr();
2050 return ast->LongDoubleTy.getAsOpaquePtr();
2052 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2054 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2056 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2058 return ast->getObjCIdType().getAsOpaquePtr();
2060 return ast->getObjCClassType().getAsOpaquePtr();
2062 return ast->getObjCSelType().getAsOpaquePtr();
2064 return ast->NullPtrTy.getAsOpaquePtr();
2070#pragma mark Function Types
2072clang::DeclarationName
2075 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2076 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2085 const clang::FunctionProtoType *function_type =
2086 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2087 if (function_type ==
nullptr)
2088 return clang::DeclarationName();
2090 const bool is_method =
false;
2091 const unsigned int num_params = function_type->getNumParams();
2093 is_method, op_kind, num_params))
2094 return clang::DeclarationName();
2096 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2100 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2101 printing_policy.SuppressTagKeyword =
true;
2104 printing_policy.SuppressInlineNamespace =
false;
2105 printing_policy.SuppressUnwrittenScope =
false;
2117 printing_policy.SuppressDefaultTemplateArgs =
false;
2118 return printing_policy;
2125 llvm::raw_string_ostream os(result);
2126 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2132 llvm::StringRef name,
const CompilerType &function_clang_type,
2133 clang::StorageClass storage,
bool is_inline) {
2134 FunctionDecl *func_decl =
nullptr;
2137 decl_ctx = ast.getTranslationUnitDecl();
2139 const bool hasWrittenPrototype =
true;
2140 const bool isConstexprSpecified =
false;
2142 clang::DeclarationName declarationName =
2144 func_decl = FunctionDecl::CreateDeserialized(ast, GlobalDeclID());
2145 func_decl->setDeclContext(decl_ctx);
2146 func_decl->setDeclName(declarationName);
2148 func_decl->setStorageClass(storage);
2149 func_decl->setInlineSpecified(is_inline);
2150 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2151 func_decl->setConstexprKind(isConstexprSpecified
2152 ? ConstexprSpecKind::Constexpr
2153 : ConstexprSpecKind::Unspecified);
2155 decl_ctx->addDecl(func_decl);
2157 VerifyDecl(func_decl);
2164 unsigned num_args,
bool is_variadic,
unsigned type_quals,
2165 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2169 std::vector<QualType> qual_type_args;
2170 if (num_args > 0 && args ==
nullptr)
2174 for (
unsigned i = 0; i < num_args; ++i) {
2189 FunctionProtoType::ExtProtoInfo proto_info;
2190 proto_info.ExtInfo = cc;
2191 proto_info.Variadic = is_variadic;
2192 proto_info.ExceptionSpec = EST_None;
2193 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2194 proto_info.RefQualifier = ref_qual;
2202 const char *name,
const CompilerType ¶m_type,
int storage,
2205 auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
2206 decl->setDeclContext(decl_ctx);
2207 if (name && name[0])
2208 decl->setDeclName(&ast.Idents.get(name));
2210 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2213 decl_ctx->addDecl(decl);
2219 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2221 function_decl->setParams(params);
2226 QualType block_type =
m_ast_up->getBlockPointerType(
2232#pragma mark Array Types
2236 std::optional<size_t> element_count,
2249 clang::ArraySizeModifier::Normal, 0));
2255 llvm::APInt ap_element_count(64, *element_count);
2257 ap_element_count,
nullptr,
2258 clang::ArraySizeModifier::Normal, 0));
2262 llvm::StringRef type_name,
2263 const std::initializer_list<std::pair<const char *, CompilerType>>
2267 if (!type_name.empty() &&
2268 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2270 lldbassert(0 &&
"Trying to create a type for an existing name");
2278 for (
const auto &field : type_fields)
2288 llvm::StringRef type_name,
2289 const std::initializer_list<std::pair<const char *, CompilerType>>
2293 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2299#pragma mark Enumeration Types
2302 llvm::StringRef name, clang::DeclContext *decl_ctx,
2304 const CompilerType &integer_clang_type,
bool is_scoped) {
2311 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
2312 enum_decl->setDeclContext(decl_ctx);
2314 enum_decl->setDeclName(&ast.Idents.get(name));
2315 enum_decl->setScoped(is_scoped);
2316 enum_decl->setScopedUsingClassTag(is_scoped);
2317 enum_decl->setFixed(
false);
2320 decl_ctx->addDecl(enum_decl);
2325 enum_decl->setAccess(AS_public);
2327 return GetType(ast.getTagDeclType(enum_decl));
2335 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2336 return GetType(ast.SignedCharTy);
2338 if (bit_size == ast.getTypeSize(ast.ShortTy))
2341 if (bit_size == ast.getTypeSize(ast.IntTy))
2344 if (bit_size == ast.getTypeSize(ast.LongTy))
2347 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2348 return GetType(ast.LongLongTy);
2350 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2353 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2354 return GetType(ast.UnsignedCharTy);
2356 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2357 return GetType(ast.UnsignedShortTy);
2359 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2360 return GetType(ast.UnsignedIntTy);
2362 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2363 return GetType(ast.UnsignedLongTy);
2365 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2366 return GetType(ast.UnsignedLongLongTy);
2368 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2369 return GetType(ast.UnsignedInt128Ty);
2383 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2385 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2386 named_decl->getDeclName().getAsString().c_str());
2388 printf(
"%20s\n", decl_ctx->getDeclKindName());
2394 if (decl ==
nullptr)
2398 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2400 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2401 record_decl->getDeclName().getAsString().c_str(),
2402 record_decl->isInjectedClassName() ?
" (injected class name)" :
"");
2405 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2407 printf(
"%20s: %s\n", decl->getDeclKindName(),
2408 named_decl->getDeclName().getAsString().c_str());
2410 printf(
"%20s\n", decl->getDeclKindName());
2416 clang::Decl *decl) {
2420 ExternalASTSource *ast_source = ast->getExternalSource();
2425 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2426 if (tag_decl->isCompleteDefinition())
2429 if (!tag_decl->hasExternalLexicalStorage())
2432 ast_source->CompleteType(tag_decl);
2434 return !tag_decl->getTypeForDecl()->isIncompleteType();
2435 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2436 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2437 if (objc_interface_decl->getDefinition())
2440 if (!objc_interface_decl->hasExternalLexicalStorage())
2443 ast_source->CompleteType(objc_interface_decl);
2445 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2475std::optional<ClangASTMetadata>
2481 return std::nullopt;
2484std::optional<ClangASTMetadata>
2490 return std::nullopt;
2494 clang::AccessSpecifier access) {
2495 if (access == clang::AccessSpecifier::AS_none)
2501clang::AccessSpecifier
2506 return clang::AccessSpecifier::AS_none;
2528 if (find(mask, type->getTypeClass()) != mask.end())
2530 switch (type->getTypeClass()) {
2533 case clang::Type::Atomic:
2534 type = cast<clang::AtomicType>(type)->getValueType();
2536 case clang::Type::Auto:
2537 case clang::Type::Decltype:
2538 case clang::Type::Elaborated:
2539 case clang::Type::Paren:
2540 case clang::Type::SubstTemplateTypeParm:
2541 case clang::Type::TemplateSpecialization:
2542 case clang::Type::Typedef:
2543 case clang::Type::TypeOf:
2544 case clang::Type::TypeOfExpr:
2545 case clang::Type::Using:
2546 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2560 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2561 switch (type_class) {
2562 case clang::Type::ObjCInterface:
2563 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2565 case clang::Type::ObjCObjectPointer:
2567 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2568 ->getPointeeType());
2569 case clang::Type::Record:
2570 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2571 case clang::Type::Enum:
2572 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2585 clang::QualType qual_type,
2586 bool allow_completion) {
2587 assert(qual_type->isRecordType());
2589 const auto *tag_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2591 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2595 if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
2598 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2599 const bool fields_loaded =
2600 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2603 if (is_complete && fields_loaded)
2606 if (!allow_completion)
2614 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2615 if (external_ast_source) {
2616 external_ast_source->CompleteType(cxx_record_decl);
2617 if (cxx_record_decl->isCompleteDefinition()) {
2618 cxx_record_decl->field_begin();
2619 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2631 clang::QualType qual_type,
2632 bool allow_completion) {
2633 assert(qual_type->isEnumeralType());
2636 const clang::EnumType *enum_type =
2637 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
2639 auto *tag_decl = enum_type->getAsTagDecl();
2643 if (tag_decl->getDefinition())
2646 if (!allow_completion)
2650 if (!tag_decl->hasExternalLexicalStorage())
2654 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2655 if (!external_ast_source)
2658 external_ast_source->CompleteType(tag_decl);
2666static const clang::ObjCObjectType *
2668 bool allow_completion) {
2669 assert(qual_type->isObjCObjectType());
2672 const clang::ObjCObjectType *objc_class_type =
2673 llvm::cast<clang::ObjCObjectType>(qual_type);
2675 clang::ObjCInterfaceDecl *class_interface_decl =
2676 objc_class_type->getInterface();
2679 if (!class_interface_decl)
2680 return objc_class_type;
2683 if (class_interface_decl->getDefinition())
2684 return objc_class_type;
2686 if (!allow_completion)
2690 if (!class_interface_decl->hasExternalLexicalStorage())
2694 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2695 if (!external_ast_source)
2698 external_ast_source->CompleteType(class_interface_decl);
2699 return objc_class_type;
2703 clang::QualType qual_type,
2704 bool allow_completion =
true) {
2706 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2707 switch (type_class) {
2708 case clang::Type::ConstantArray:
2709 case clang::Type::IncompleteArray:
2710 case clang::Type::VariableArray: {
2711 const clang::ArrayType *array_type =
2712 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2718 case clang::Type::Record: {
2719 if (
const auto *RT =
2721 return !RT->isIncompleteType();
2726 case clang::Type::Enum: {
2728 return !ET->isIncompleteType();
2732 case clang::Type::ObjCObject:
2733 case clang::Type::ObjCInterface: {
2734 if (
const auto *OT =
2736 return !OT->isIncompleteType();
2741 case clang::Type::Attributed:
2743 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2753static clang::ObjCIvarDecl::AccessControl
2757 return clang::ObjCIvarDecl::None;
2759 return clang::ObjCIvarDecl::Public;
2761 return clang::ObjCIvarDecl::Private;
2763 return clang::ObjCIvarDecl::Protected;
2765 return clang::ObjCIvarDecl::Package;
2767 return clang::ObjCIvarDecl::None;
2774 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2781 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2782 switch (type_class) {
2783 case clang::Type::IncompleteArray:
2784 case clang::Type::VariableArray:
2785 case clang::Type::ConstantArray:
2786 case clang::Type::ExtVector:
2787 case clang::Type::Vector:
2788 case clang::Type::Record:
2789 case clang::Type::ObjCObject:
2790 case clang::Type::ObjCInterface:
2802 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2803 switch (type_class) {
2804 case clang::Type::Record: {
2805 if (
const clang::RecordType *record_type =
2806 llvm::dyn_cast_or_null<clang::RecordType>(
2807 qual_type.getTypePtrOrNull())) {
2808 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2809 return record_decl->isAnonymousStructOrUnion();
2823 uint64_t *size,
bool *is_incomplete) {
2826 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2827 switch (type_class) {
2831 case clang::Type::ConstantArray:
2832 if (element_type_ptr)
2834 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2838 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2840 .getLimitedValue(ULLONG_MAX);
2842 *is_incomplete =
false;
2845 case clang::Type::IncompleteArray:
2846 if (element_type_ptr)
2848 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2854 *is_incomplete =
true;
2857 case clang::Type::VariableArray:
2858 if (element_type_ptr)
2860 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2866 *is_incomplete =
false;
2869 case clang::Type::DependentSizedArray:
2870 if (element_type_ptr)
2873 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2879 *is_incomplete =
false;
2882 if (element_type_ptr)
2883 element_type_ptr->
Clear();
2887 *is_incomplete =
false;
2895 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2896 switch (type_class) {
2897 case clang::Type::Vector: {
2898 const clang::VectorType *vector_type =
2899 qual_type->getAs<clang::VectorType>();
2902 *size = vector_type->getNumElements();
2904 *element_type =
GetType(vector_type->getElementType());
2908 case clang::Type::ExtVector: {
2909 const clang::ExtVectorType *ext_vector_type =
2910 qual_type->getAs<clang::ExtVectorType>();
2911 if (ext_vector_type) {
2913 *size = ext_vector_type->getNumElements();
2917 ext_vector_type->getElementType().getAsOpaquePtr());
2933 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2936 clang::ObjCInterfaceDecl *result_iface_decl =
2937 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2939 std::optional<ClangASTMetadata> ast_metadata =
GetMetadata(result_iface_decl);
2943 return (ast_metadata->GetISAPtr() != 0);
2947 return GetQualType(type).getUnqualifiedType()->isCharType();
2956 const bool allow_completion =
true;
2971 if (!pointee_or_element_clang_type.
IsValid())
2974 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2975 if (pointee_or_element_clang_type.
IsCharType()) {
2976 if (type_flags.
Test(eTypeIsArray)) {
2979 length = llvm::cast<clang::ConstantArrayType>(
2993 if (
auto pointer_auth = qual_type.getPointerAuth())
2994 return pointer_auth.getKey();
3003 if (
auto pointer_auth = qual_type.getPointerAuth())
3004 return pointer_auth.getExtraDiscriminator();
3013 if (
auto pointer_auth = qual_type.getPointerAuth())
3014 return pointer_auth.isAddressDiscriminated();
3020 auto isFunctionType = [&](clang::QualType qual_type) {
3021 return qual_type->isFunctionType();
3035 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3036 switch (type_class) {
3037 case clang::Type::Record:
3039 const clang::CXXRecordDecl *cxx_record_decl =
3040 qual_type->getAsCXXRecordDecl();
3041 if (cxx_record_decl) {
3042 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3045 const clang::RecordType *record_type =
3046 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3048 const clang::RecordDecl *record_decl = record_type->getDecl();
3052 clang::RecordDecl::field_iterator field_pos,
3053 field_end = record_decl->field_end();
3054 uint32_t num_fields = 0;
3055 bool is_hva =
false;
3056 bool is_hfa =
false;
3057 clang::QualType base_qual_type;
3058 uint64_t base_bitwidth = 0;
3059 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3061 clang::QualType field_qual_type = field_pos->getType();
3062 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
3063 if (field_qual_type->isFloatingType()) {
3064 if (field_qual_type->isComplexType())
3067 if (num_fields == 0)
3068 base_qual_type = field_qual_type;
3073 if (field_qual_type.getTypePtr() !=
3074 base_qual_type.getTypePtr())
3078 }
else if (field_qual_type->isVectorType() ||
3079 field_qual_type->isExtVectorType()) {
3080 if (num_fields == 0) {
3081 base_qual_type = field_qual_type;
3082 base_bitwidth = field_bitwidth;
3087 if (base_bitwidth != field_bitwidth)
3089 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3098 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3115 const clang::FunctionProtoType *func =
3116 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3118 return func->getNumParams();
3125 const size_t index) {
3128 const clang::FunctionProtoType *func =
3129 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3131 if (index < func->getNumParams())
3132 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3140 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3144 if (predicate(qual_type))
3147 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3148 switch (type_class) {
3152 case clang::Type::LValueReference:
3153 case clang::Type::RValueReference: {
3154 const clang::ReferenceType *reference_type =
3155 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3157 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3166 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3167 return qual_type->isMemberFunctionPointerType();
3170 return IsTypeImpl(type, isMemberFunctionPointerType);
3174 auto isFunctionPointerType = [](clang::QualType qual_type) {
3175 return qual_type->isFunctionPointerType();
3178 return IsTypeImpl(type, isFunctionPointerType);
3184 auto isBlockPointerType = [&](clang::QualType qual_type) {
3185 if (qual_type->isBlockPointerType()) {
3186 if (function_pointer_type_ptr) {
3187 const clang::BlockPointerType *block_pointer_type =
3188 qual_type->castAs<clang::BlockPointerType>();
3189 QualType pointee_type = block_pointer_type->getPointeeType();
3190 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3192 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3209 const clang::BuiltinType *builtin_type =
3210 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3213 if (builtin_type->isInteger()) {
3214 is_signed = builtin_type->isSignedInteger();
3225 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3229 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3241 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3245 return enum_type->isScopedEnumeralType();
3256 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3257 switch (type_class) {
3258 case clang::Type::Builtin:
3259 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3262 case clang::BuiltinType::ObjCId:
3263 case clang::BuiltinType::ObjCClass:
3267 case clang::Type::ObjCObjectPointer:
3271 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3275 case clang::Type::BlockPointer:
3278 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3282 case clang::Type::Pointer:
3285 llvm::cast<clang::PointerType>(qual_type)
3289 case clang::Type::MemberPointer:
3292 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3301 pointee_type->
Clear();
3309 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3310 switch (type_class) {
3311 case clang::Type::Builtin:
3312 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3315 case clang::BuiltinType::ObjCId:
3316 case clang::BuiltinType::ObjCClass:
3320 case clang::Type::ObjCObjectPointer:
3324 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3328 case clang::Type::BlockPointer:
3331 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3335 case clang::Type::Pointer:
3338 llvm::cast<clang::PointerType>(qual_type)
3342 case clang::Type::MemberPointer:
3345 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3349 case clang::Type::LValueReference:
3352 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3356 case clang::Type::RValueReference:
3359 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3368 pointee_type->
Clear();
3377 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3379 switch (type_class) {
3380 case clang::Type::LValueReference:
3383 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3389 case clang::Type::RValueReference:
3392 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3404 pointee_type->
Clear();
3409 uint32_t &count,
bool &is_complex) {
3413 if (
const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3414 qual_type->getCanonicalTypeInternal())) {
3415 clang::BuiltinType::Kind kind = BT->getKind();
3416 if (kind >= clang::BuiltinType::Float &&
3417 kind <= clang::BuiltinType::LongDouble) {
3422 }
else if (
const clang::ComplexType *CT =
3423 llvm::dyn_cast<clang::ComplexType>(
3424 qual_type->getCanonicalTypeInternal())) {
3431 }
else if (
const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3432 qual_type->getCanonicalTypeInternal())) {
3435 count = VT->getNumElements();
3451 const clang::TagType *tag_type =
3452 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3454 clang::TagDecl *tag_decl = tag_type->getDecl();
3456 return tag_decl->isCompleteDefinition();
3459 const clang::ObjCObjectType *objc_class_type =
3460 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3461 if (objc_class_type) {
3462 clang::ObjCInterfaceDecl *class_interface_decl =
3463 objc_class_type->getInterface();
3464 if (class_interface_decl)
3465 return class_interface_decl->getDefinition() !=
nullptr;
3476 const clang::ObjCObjectPointerType *obj_pointer_type =
3477 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3479 if (obj_pointer_type)
3480 return obj_pointer_type->isObjCClassType();
3495 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3496 return (type_class == clang::Type::Record);
3503 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3504 return (type_class == clang::Type::Enum);
3510 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3511 switch (type_class) {
3512 case clang::Type::Record:
3514 const clang::RecordType *record_type =
3515 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3516 const clang::RecordDecl *record_decl = record_type->getDecl();
3518 const clang::CXXRecordDecl *cxx_record_decl =
3519 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3520 if (cxx_record_decl) {
3527 return cxx_record_decl->isDynamicClass();
3542 bool check_cplusplus,
3544 clang::QualType pointee_qual_type;
3547 bool success =
false;
3548 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3549 switch (type_class) {
3550 case clang::Type::Builtin:
3552 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3553 clang::BuiltinType::ObjCId) {
3554 if (dynamic_pointee_type)
3560 case clang::Type::ObjCObjectPointer:
3562 if (
const auto *objc_pointee_type =
3563 qual_type->getPointeeType().getTypePtrOrNull()) {
3564 if (
const auto *objc_object_type =
3565 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3566 objc_pointee_type)) {
3567 if (objc_object_type->isObjCClass())
3571 if (dynamic_pointee_type)
3574 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3581 case clang::Type::Pointer:
3583 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3587 case clang::Type::LValueReference:
3588 case clang::Type::RValueReference:
3590 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3602 const clang::Type::TypeClass pointee_type_class =
3603 pointee_qual_type.getCanonicalType()->getTypeClass();
3604 switch (pointee_type_class) {
3605 case clang::Type::Builtin:
3606 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3607 case clang::BuiltinType::UnknownAny:
3608 case clang::BuiltinType::Void:
3609 if (dynamic_pointee_type)
3611 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3618 case clang::Type::Record:
3619 if (check_cplusplus) {
3620 clang::CXXRecordDecl *cxx_record_decl =
3621 pointee_qual_type->getAsCXXRecordDecl();
3622 if (cxx_record_decl) {
3623 bool is_complete = cxx_record_decl->isCompleteDefinition();
3626 success = cxx_record_decl->isDynamicClass();
3628 if (std::optional<ClangASTMetadata> metadata =
3630 success = metadata->GetIsDynamicCXXType();
3634 success = cxx_record_decl->isDynamicClass();
3641 if (dynamic_pointee_type)
3643 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3650 case clang::Type::ObjCObject:
3651 case clang::Type::ObjCInterface:
3653 if (dynamic_pointee_type)
3655 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3665 if (dynamic_pointee_type)
3666 dynamic_pointee_type->
Clear();
3674 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3681 ->getTypeClass() == clang::Type::Typedef;
3691 if (
auto *record_decl =
3693 return record_decl->canPassInRegisters();
3699 return TypeSystemClangSupportsLanguage(language);
3702std::optional<std::string>
3705 return std::nullopt;
3708 if (qual_type.isNull())
3709 return std::nullopt;
3711 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3712 if (!cxx_record_decl)
3713 return std::nullopt;
3715 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3723 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3730 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3732 return tag_type->isBeingDefined();
3743 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3744 if (class_type_ptr) {
3745 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3746 const clang::ObjCObjectPointerType *obj_pointer_type =
3747 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3748 if (obj_pointer_type ==
nullptr)
3749 class_type_ptr->
Clear();
3753 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3760 class_type_ptr->
Clear();
3769 const bool allow_completion =
true;
3789 {clang::Type::Typedef, clang::Type::Atomic});
3792 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3793 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3800 if (
auto *named_decl = qual_type->getAsTagDecl())
3812 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3813 printing_policy.SuppressTagKeyword =
true;
3814 printing_policy.SuppressScope =
false;
3815 printing_policy.SuppressUnwrittenScope =
true;
3816 printing_policy.SuppressInlineNamespace =
true;
3817 return ConstString(qual_type.getAsString(printing_policy));
3826 if (pointee_or_element_clang_type)
3827 pointee_or_element_clang_type->
Clear();
3829 clang::QualType qual_type =
3832 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3833 switch (type_class) {
3834 case clang::Type::Attributed:
3835 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3838 pointee_or_element_clang_type);
3839 case clang::Type::Builtin: {
3840 const clang::BuiltinType *builtin_type =
3841 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3843 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3844 switch (builtin_type->getKind()) {
3845 case clang::BuiltinType::ObjCId:
3846 case clang::BuiltinType::ObjCClass:
3847 if (pointee_or_element_clang_type)
3851 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3854 case clang::BuiltinType::ObjCSel:
3855 if (pointee_or_element_clang_type)
3858 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3861 case clang::BuiltinType::Bool:
3862 case clang::BuiltinType::Char_U:
3863 case clang::BuiltinType::UChar:
3864 case clang::BuiltinType::WChar_U:
3865 case clang::BuiltinType::Char16:
3866 case clang::BuiltinType::Char32:
3867 case clang::BuiltinType::UShort:
3868 case clang::BuiltinType::UInt:
3869 case clang::BuiltinType::ULong:
3870 case clang::BuiltinType::ULongLong:
3871 case clang::BuiltinType::UInt128:
3872 case clang::BuiltinType::Char_S:
3873 case clang::BuiltinType::SChar:
3874 case clang::BuiltinType::WChar_S:
3875 case clang::BuiltinType::Short:
3876 case clang::BuiltinType::Int:
3877 case clang::BuiltinType::Long:
3878 case clang::BuiltinType::LongLong:
3879 case clang::BuiltinType::Int128:
3880 case clang::BuiltinType::Float:
3881 case clang::BuiltinType::Double:
3882 case clang::BuiltinType::LongDouble:
3883 builtin_type_flags |= eTypeIsScalar;
3884 if (builtin_type->isInteger()) {
3885 builtin_type_flags |= eTypeIsInteger;
3886 if (builtin_type->isSignedInteger())
3887 builtin_type_flags |= eTypeIsSigned;
3888 }
else if (builtin_type->isFloatingPoint())
3889 builtin_type_flags |= eTypeIsFloat;
3894 return builtin_type_flags;
3897 case clang::Type::BlockPointer:
3898 if (pointee_or_element_clang_type)
3900 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3901 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3903 case clang::Type::Complex: {
3904 uint32_t complex_type_flags =
3905 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3906 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3907 qual_type->getCanonicalTypeInternal());
3909 clang::QualType complex_element_type(complex_type->getElementType());
3910 if (complex_element_type->isIntegerType())
3911 complex_type_flags |= eTypeIsFloat;
3912 else if (complex_element_type->isFloatingType())
3913 complex_type_flags |= eTypeIsInteger;
3915 return complex_type_flags;
3918 case clang::Type::ConstantArray:
3919 case clang::Type::DependentSizedArray:
3920 case clang::Type::IncompleteArray:
3921 case clang::Type::VariableArray:
3922 if (pointee_or_element_clang_type)
3924 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3927 return eTypeHasChildren | eTypeIsArray;
3929 case clang::Type::DependentName:
3931 case clang::Type::DependentSizedExtVector:
3932 return eTypeHasChildren | eTypeIsVector;
3933 case clang::Type::DependentTemplateSpecialization:
3934 return eTypeIsTemplate;
3936 case clang::Type::Enum:
3937 if (pointee_or_element_clang_type)
3939 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3943 return eTypeIsEnumeration | eTypeHasValue;
3945 case clang::Type::FunctionProto:
3946 return eTypeIsFuncPrototype | eTypeHasValue;
3947 case clang::Type::FunctionNoProto:
3948 return eTypeIsFuncPrototype | eTypeHasValue;
3949 case clang::Type::InjectedClassName:
3952 case clang::Type::LValueReference:
3953 case clang::Type::RValueReference:
3954 if (pointee_or_element_clang_type)
3957 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3960 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3962 case clang::Type::MemberPointer:
3963 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3965 case clang::Type::ObjCObjectPointer:
3966 if (pointee_or_element_clang_type)
3968 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3969 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3972 case clang::Type::ObjCObject:
3973 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3974 case clang::Type::ObjCInterface:
3975 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3977 case clang::Type::Pointer:
3978 if (pointee_or_element_clang_type)
3980 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3981 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3983 case clang::Type::Record:
3984 if (qual_type->getAsCXXRecordDecl())
3985 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3987 return eTypeHasChildren | eTypeIsStructUnion;
3989 case clang::Type::SubstTemplateTypeParm:
3990 return eTypeIsTemplate;
3991 case clang::Type::TemplateTypeParm:
3992 return eTypeIsTemplate;
3993 case clang::Type::TemplateSpecialization:
3994 return eTypeIsTemplate;
3996 case clang::Type::Typedef:
3997 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
3999 ->getUnderlyingType())
4001 case clang::Type::UnresolvedUsing:
4004 case clang::Type::ExtVector:
4005 case clang::Type::Vector: {
4006 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4007 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
4008 qual_type->getCanonicalTypeInternal());
4010 if (vector_type->isIntegerType())
4011 vector_type_flags |= eTypeIsFloat;
4012 else if (vector_type->isFloatingType())
4013 vector_type_flags |= eTypeIsInteger;
4015 return vector_type_flags;
4030 if (qual_type->isAnyPointerType()) {
4031 if (qual_type->isObjCObjectPointerType())
4033 if (qual_type->getPointeeCXXRecordDecl())
4036 clang::QualType pointee_type(qual_type->getPointeeType());
4037 if (pointee_type->getPointeeCXXRecordDecl())
4039 if (pointee_type->isObjCObjectOrInterfaceType())
4041 if (pointee_type->isObjCClassType())
4043 if (pointee_type.getTypePtr() ==
4047 if (qual_type->isObjCObjectOrInterfaceType())
4049 if (qual_type->getAsCXXRecordDecl())
4051 switch (qual_type->getTypeClass()) {
4054 case clang::Type::Builtin:
4055 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4057 case clang::BuiltinType::Void:
4058 case clang::BuiltinType::Bool:
4059 case clang::BuiltinType::Char_U:
4060 case clang::BuiltinType::UChar:
4061 case clang::BuiltinType::WChar_U:
4062 case clang::BuiltinType::Char16:
4063 case clang::BuiltinType::Char32:
4064 case clang::BuiltinType::UShort:
4065 case clang::BuiltinType::UInt:
4066 case clang::BuiltinType::ULong:
4067 case clang::BuiltinType::ULongLong:
4068 case clang::BuiltinType::UInt128:
4069 case clang::BuiltinType::Char_S:
4070 case clang::BuiltinType::SChar:
4071 case clang::BuiltinType::WChar_S:
4072 case clang::BuiltinType::Short:
4073 case clang::BuiltinType::Int:
4074 case clang::BuiltinType::Long:
4075 case clang::BuiltinType::LongLong:
4076 case clang::BuiltinType::Int128:
4077 case clang::BuiltinType::Float:
4078 case clang::BuiltinType::Double:
4079 case clang::BuiltinType::LongDouble:
4082 case clang::BuiltinType::NullPtr:
4085 case clang::BuiltinType::ObjCId:
4086 case clang::BuiltinType::ObjCClass:
4087 case clang::BuiltinType::ObjCSel:
4090 case clang::BuiltinType::Dependent:
4091 case clang::BuiltinType::Overload:
4092 case clang::BuiltinType::BoundMember:
4093 case clang::BuiltinType::UnknownAny:
4097 case clang::Type::Typedef:
4098 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4100 ->getUnderlyingType())
4110 return lldb::eTypeClassInvalid;
4112 clang::QualType qual_type =
4115 switch (qual_type->getTypeClass()) {
4116 case clang::Type::Atomic:
4117 case clang::Type::Auto:
4118 case clang::Type::CountAttributed:
4119 case clang::Type::Decltype:
4120 case clang::Type::Elaborated:
4121 case clang::Type::Paren:
4122 case clang::Type::TypeOf:
4123 case clang::Type::TypeOfExpr:
4124 case clang::Type::Using:
4125 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4126 case clang::Type::UnaryTransform:
4128 case clang::Type::FunctionNoProto:
4129 return lldb::eTypeClassFunction;
4130 case clang::Type::FunctionProto:
4131 return lldb::eTypeClassFunction;
4132 case clang::Type::IncompleteArray:
4133 return lldb::eTypeClassArray;
4134 case clang::Type::VariableArray:
4135 return lldb::eTypeClassArray;
4136 case clang::Type::ConstantArray:
4137 return lldb::eTypeClassArray;
4138 case clang::Type::DependentSizedArray:
4139 return lldb::eTypeClassArray;
4140 case clang::Type::ArrayParameter:
4141 return lldb::eTypeClassArray;
4142 case clang::Type::DependentSizedExtVector:
4143 return lldb::eTypeClassVector;
4144 case clang::Type::DependentVector:
4145 return lldb::eTypeClassVector;
4146 case clang::Type::ExtVector:
4147 return lldb::eTypeClassVector;
4148 case clang::Type::Vector:
4149 return lldb::eTypeClassVector;
4150 case clang::Type::Builtin:
4152 case clang::Type::BitInt:
4153 case clang::Type::DependentBitInt:
4154 return lldb::eTypeClassBuiltin;
4155 case clang::Type::ObjCObjectPointer:
4156 return lldb::eTypeClassObjCObjectPointer;
4157 case clang::Type::BlockPointer:
4158 return lldb::eTypeClassBlockPointer;
4159 case clang::Type::Pointer:
4160 return lldb::eTypeClassPointer;
4161 case clang::Type::LValueReference:
4162 return lldb::eTypeClassReference;
4163 case clang::Type::RValueReference:
4164 return lldb::eTypeClassReference;
4165 case clang::Type::MemberPointer:
4166 return lldb::eTypeClassMemberPointer;
4167 case clang::Type::Complex:
4168 if (qual_type->isComplexType())
4169 return lldb::eTypeClassComplexFloat;
4171 return lldb::eTypeClassComplexInteger;
4172 case clang::Type::ObjCObject:
4173 return lldb::eTypeClassObjCObject;
4174 case clang::Type::ObjCInterface:
4175 return lldb::eTypeClassObjCInterface;
4176 case clang::Type::Record: {
4177 const clang::RecordType *record_type =
4178 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4179 const clang::RecordDecl *record_decl = record_type->getDecl();
4180 if (record_decl->isUnion())
4181 return lldb::eTypeClassUnion;
4182 else if (record_decl->isStruct())
4183 return lldb::eTypeClassStruct;
4185 return lldb::eTypeClassClass;
4187 case clang::Type::Enum:
4188 return lldb::eTypeClassEnumeration;
4189 case clang::Type::Typedef:
4190 return lldb::eTypeClassTypedef;
4191 case clang::Type::UnresolvedUsing:
4194 case clang::Type::Attributed:
4195 case clang::Type::BTFTagAttributed:
4197 case clang::Type::TemplateTypeParm:
4199 case clang::Type::SubstTemplateTypeParm:
4201 case clang::Type::SubstTemplateTypeParmPack:
4203 case clang::Type::InjectedClassName:
4205 case clang::Type::DependentName:
4207 case clang::Type::DependentTemplateSpecialization:
4209 case clang::Type::PackExpansion:
4212 case clang::Type::TemplateSpecialization:
4214 case clang::Type::DeducedTemplateSpecialization:
4216 case clang::Type::Pipe:
4220 case clang::Type::Decayed:
4222 case clang::Type::Adjusted:
4224 case clang::Type::ObjCTypeParam:
4227 case clang::Type::DependentAddressSpace:
4229 case clang::Type::MacroQualified:
4233 case clang::Type::ConstantMatrix:
4234 case clang::Type::DependentSizedMatrix:
4238 case clang::Type::PackIndexing:
4242 return lldb::eTypeClassOther;
4247 return GetQualType(type).getQualifiers().getCVRQualifiers();
4259 const clang::Type *array_eletype =
4260 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4265 return GetType(clang::QualType(array_eletype, 0));
4276 return GetType(ast_ctx.getConstantArrayType(
4277 qual_type, llvm::APInt(64, size),
nullptr,
4278 clang::ArraySizeModifier::Normal, 0));
4280 return GetType(ast_ctx.getIncompleteArrayType(
4281 qual_type, clang::ArraySizeModifier::Normal, 0));
4295 clang::QualType qual_type) {
4296 if (qual_type->isPointerType())
4297 qual_type = ast->getPointerType(
4299 else if (
const ConstantArrayType *arr =
4300 ast->getAsConstantArrayType(qual_type)) {
4301 qual_type = ast->getConstantArrayType(
4303 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4304 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4306 qual_type = qual_type.getUnqualifiedType();
4307 qual_type.removeLocalConst();
4308 qual_type.removeLocalRestrict();
4309 qual_type.removeLocalVolatile();
4331 const clang::FunctionProtoType *func =
4334 return func->getNumParams();
4342 const clang::FunctionProtoType *func =
4343 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4345 const uint32_t num_args = func->getNumParams();
4347 return GetType(func->getParamType(idx));
4357 const clang::FunctionProtoType *func =
4358 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4360 return GetType(func->getReturnType());
4367 size_t num_functions = 0;
4370 switch (qual_type->getTypeClass()) {
4371 case clang::Type::Record:
4373 const clang::RecordType *record_type =
4374 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4375 const clang::RecordDecl *record_decl = record_type->getDecl();
4376 assert(record_decl);
4377 const clang::CXXRecordDecl *cxx_record_decl =
4378 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4379 if (cxx_record_decl)
4380 num_functions = std::distance(cxx_record_decl->method_begin(),
4381 cxx_record_decl->method_end());
4385 case clang::Type::ObjCObjectPointer: {
4386 const clang::ObjCObjectPointerType *objc_class_type =
4387 qual_type->castAs<clang::ObjCObjectPointerType>();
4388 const clang::ObjCInterfaceType *objc_interface_type =
4389 objc_class_type->getInterfaceType();
4390 if (objc_interface_type &&
4392 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4393 clang::ObjCInterfaceDecl *class_interface_decl =
4394 objc_interface_type->getDecl();
4395 if (class_interface_decl) {
4396 num_functions = std::distance(class_interface_decl->meth_begin(),
4397 class_interface_decl->meth_end());
4403 case clang::Type::ObjCObject:
4404 case clang::Type::ObjCInterface:
4406 const clang::ObjCObjectType *objc_class_type =
4407 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4408 if (objc_class_type) {
4409 clang::ObjCInterfaceDecl *class_interface_decl =
4410 objc_class_type->getInterface();
4411 if (class_interface_decl)
4412 num_functions = std::distance(class_interface_decl->meth_begin(),
4413 class_interface_decl->meth_end());
4422 return num_functions;
4434 switch (qual_type->getTypeClass()) {
4435 case clang::Type::Record:
4437 const clang::RecordType *record_type =
4438 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4439 const clang::RecordDecl *record_decl = record_type->getDecl();
4440 assert(record_decl);
4441 const clang::CXXRecordDecl *cxx_record_decl =
4442 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4443 if (cxx_record_decl) {
4444 auto method_iter = cxx_record_decl->method_begin();
4445 auto method_end = cxx_record_decl->method_end();
4447 static_cast<size_t>(std::distance(method_iter, method_end))) {
4448 std::advance(method_iter, idx);
4449 clang::CXXMethodDecl *cxx_method_decl =
4450 method_iter->getCanonicalDecl();
4451 if (cxx_method_decl) {
4452 name = cxx_method_decl->getDeclName().getAsString();
4453 if (cxx_method_decl->isStatic())
4455 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4457 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4461 clang_type =
GetType(cxx_method_decl->getType());
4469 case clang::Type::ObjCObjectPointer: {
4470 const clang::ObjCObjectPointerType *objc_class_type =
4471 qual_type->castAs<clang::ObjCObjectPointerType>();
4472 const clang::ObjCInterfaceType *objc_interface_type =
4473 objc_class_type->getInterfaceType();
4474 if (objc_interface_type &&
4476 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4477 clang::ObjCInterfaceDecl *class_interface_decl =
4478 objc_interface_type->getDecl();
4479 if (class_interface_decl) {
4480 auto method_iter = class_interface_decl->meth_begin();
4481 auto method_end = class_interface_decl->meth_end();
4483 static_cast<size_t>(std::distance(method_iter, method_end))) {
4484 std::advance(method_iter, idx);
4485 clang::ObjCMethodDecl *objc_method_decl =
4486 method_iter->getCanonicalDecl();
4487 if (objc_method_decl) {
4489 name = objc_method_decl->getSelector().getAsString();
4490 if (objc_method_decl->isClassMethod())
4501 case clang::Type::ObjCObject:
4502 case clang::Type::ObjCInterface:
4504 const clang::ObjCObjectType *objc_class_type =
4505 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4506 if (objc_class_type) {
4507 clang::ObjCInterfaceDecl *class_interface_decl =
4508 objc_class_type->getInterface();
4509 if (class_interface_decl) {
4510 auto method_iter = class_interface_decl->meth_begin();
4511 auto method_end = class_interface_decl->meth_end();
4513 static_cast<size_t>(std::distance(method_iter, method_end))) {
4514 std::advance(method_iter, idx);
4515 clang::ObjCMethodDecl *objc_method_decl =
4516 method_iter->getCanonicalDecl();
4517 if (objc_method_decl) {
4519 name = objc_method_decl->getSelector().getAsString();
4520 if (objc_method_decl->isClassMethod())
4553 return GetType(qual_type.getTypePtr()->getPointeeType());
4563 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4564 case clang::Type::ObjCObject:
4565 case clang::Type::ObjCInterface:
4612 auto pauth = PointerAuthQualifier::fromOpaqueValue(payload);
4613 clang::QualType result =
4614 clang_ast.getPointerAuthType(
GetQualType(type), pauth);
4624 result.addVolatile();
4634 result.addRestrict();
4643 if (type && typedef_name && typedef_name[0]) {
4647 clang::DeclContext *decl_ctx =
4652 clang::TypedefDecl *decl =
4653 clang::TypedefDecl::CreateDeserialized(clang_ast, GlobalDeclID());
4654 decl->setDeclContext(decl_ctx);
4655 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4656 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4657 decl_ctx->addDecl(decl);
4660 clang::TagDecl *tdecl =
nullptr;
4661 if (!qual_type.isNull()) {
4662 if (
const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4663 tdecl = rt->getDecl();
4664 if (
const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4665 tdecl = et->getDecl();
4671 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4672 tdecl->setTypedefNameForAnonDecl(decl);
4674 decl->setAccess(clang::AS_public);
4677 return GetType(clang_ast.getTypedefType(decl));
4685 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4688 return GetType(typedef_type->getDecl()->getUnderlyingType());
4701 const FunctionType::ExtInfo generic_ext_info(
4710 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4715const llvm::fltSemantics &
4718 const size_t bit_size = byte_size * 8;
4719 if (bit_size == ast.getTypeSize(ast.FloatTy))
4720 return ast.getFloatTypeSemantics(ast.FloatTy);
4721 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4722 return ast.getFloatTypeSemantics(ast.DoubleTy);
4723 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4724 bit_size == llvm::APFloat::semanticsSizeInBits(
4725 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4726 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4727 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4728 return ast.getFloatTypeSemantics(ast.HalfTy);
4729 return llvm::APFloatBase::Bogus();
4732std::optional<uint64_t>
4735 assert(qual_type->isObjCObjectOrInterfaceType());
4740 if (std::optional<uint64_t> bit_size =
4741 objc_runtime->GetTypeBitSize(
GetType(qual_type)))
4745 static bool g_printed =
false;
4750 llvm::outs() <<
"warning: trying to determine the size of type ";
4752 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4753 "reliable. please file a bug against LLDB.\n";
4754 llvm::outs() <<
"backtrace:\n";
4755 llvm::sys::PrintStackTrace(llvm::outs());
4756 llvm::outs() <<
"\n";
4765std::optional<uint64_t>
4769 return std::nullopt;
4772 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4773 switch (type_class) {
4774 case clang::Type::ConstantArray:
4775 case clang::Type::FunctionProto:
4776 case clang::Type::Record:
4778 case clang::Type::ObjCInterface:
4779 case clang::Type::ObjCObject:
4781 case clang::Type::IncompleteArray: {
4782 const uint64_t bit_size =
getASTContext().getTypeSize(qual_type);
4785 qual_type->getArrayElementTypeNoTypeQual()
4786 ->getCanonicalTypeUnqualified());
4791 if (
const uint64_t bit_size =
getASTContext().getTypeSize(qual_type))
4795 return std::nullopt;
4798std::optional<size_t>
4814 switch (qual_type->getTypeClass()) {
4815 case clang::Type::Atomic:
4816 case clang::Type::Auto:
4817 case clang::Type::CountAttributed:
4818 case clang::Type::Decltype:
4819 case clang::Type::Elaborated:
4820 case clang::Type::Paren:
4821 case clang::Type::Typedef:
4822 case clang::Type::TypeOf:
4823 case clang::Type::TypeOfExpr:
4824 case clang::Type::Using:
4825 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4827 case clang::Type::UnaryTransform:
4830 case clang::Type::FunctionNoProto:
4831 case clang::Type::FunctionProto:
4834 case clang::Type::IncompleteArray:
4835 case clang::Type::VariableArray:
4836 case clang::Type::ArrayParameter:
4839 case clang::Type::ConstantArray:
4842 case clang::Type::DependentVector:
4843 case clang::Type::ExtVector:
4844 case clang::Type::Vector:
4848 case clang::Type::BitInt:
4849 case clang::Type::DependentBitInt:
4853 case clang::Type::Builtin:
4854 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4855 case clang::BuiltinType::Void:
4858 case clang::BuiltinType::Char_S:
4859 case clang::BuiltinType::SChar:
4860 case clang::BuiltinType::WChar_S:
4861 case clang::BuiltinType::Short:
4862 case clang::BuiltinType::Int:
4863 case clang::BuiltinType::Long:
4864 case clang::BuiltinType::LongLong:
4865 case clang::BuiltinType::Int128:
4868 case clang::BuiltinType::Bool:
4869 case clang::BuiltinType::Char_U:
4870 case clang::BuiltinType::UChar:
4871 case clang::BuiltinType::WChar_U:
4872 case clang::BuiltinType::Char8:
4873 case clang::BuiltinType::Char16:
4874 case clang::BuiltinType::Char32:
4875 case clang::BuiltinType::UShort:
4876 case clang::BuiltinType::UInt:
4877 case clang::BuiltinType::ULong:
4878 case clang::BuiltinType::ULongLong:
4879 case clang::BuiltinType::UInt128:
4883 case clang::BuiltinType::ShortAccum:
4884 case clang::BuiltinType::Accum:
4885 case clang::BuiltinType::LongAccum:
4886 case clang::BuiltinType::UShortAccum:
4887 case clang::BuiltinType::UAccum:
4888 case clang::BuiltinType::ULongAccum:
4889 case clang::BuiltinType::ShortFract:
4890 case clang::BuiltinType::Fract:
4891 case clang::BuiltinType::LongFract:
4892 case clang::BuiltinType::UShortFract:
4893 case clang::BuiltinType::UFract:
4894 case clang::BuiltinType::ULongFract:
4895 case clang::BuiltinType::SatShortAccum:
4896 case clang::BuiltinType::SatAccum:
4897 case clang::BuiltinType::SatLongAccum:
4898 case clang::BuiltinType::SatUShortAccum:
4899 case clang::BuiltinType::SatUAccum:
4900 case clang::BuiltinType::SatULongAccum:
4901 case clang::BuiltinType::SatShortFract:
4902 case clang::BuiltinType::SatFract:
4903 case clang::BuiltinType::SatLongFract:
4904 case clang::BuiltinType::SatUShortFract:
4905 case clang::BuiltinType::SatUFract:
4906 case clang::BuiltinType::SatULongFract:
4909 case clang::BuiltinType::Half:
4910 case clang::BuiltinType::Float:
4911 case clang::BuiltinType::Float16:
4912 case clang::BuiltinType::Float128:
4913 case clang::BuiltinType::Double:
4914 case clang::BuiltinType::LongDouble:
4915 case clang::BuiltinType::BFloat16:
4916 case clang::BuiltinType::Ibm128:
4919 case clang::BuiltinType::ObjCClass:
4920 case clang::BuiltinType::ObjCId:
4921 case clang::BuiltinType::ObjCSel:
4924 case clang::BuiltinType::NullPtr:
4927 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4928 case clang::BuiltinType::Kind::BoundMember:
4929 case clang::BuiltinType::Kind::BuiltinFn:
4930 case clang::BuiltinType::Kind::Dependent:
4931 case clang::BuiltinType::Kind::OCLClkEvent:
4932 case clang::BuiltinType::Kind::OCLEvent:
4933 case clang::BuiltinType::Kind::OCLImage1dRO:
4934 case clang::BuiltinType::Kind::OCLImage1dWO:
4935 case clang::BuiltinType::Kind::OCLImage1dRW:
4936 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4937 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4938 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4939 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4940 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4941 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4942 case clang::BuiltinType::Kind::OCLImage2dRO:
4943 case clang::BuiltinType::Kind::OCLImage2dWO:
4944 case clang::BuiltinType::Kind::OCLImage2dRW:
4945 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4946 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4947 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4948 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4949 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4950 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4951 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4952 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4953 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4954 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4955 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4956 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4957 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4958 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4959 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4960 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4961 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4962 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4963 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4964 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4965 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4966 case clang::BuiltinType::Kind::OCLImage3dRO:
4967 case clang::BuiltinType::Kind::OCLImage3dWO:
4968 case clang::BuiltinType::Kind::OCLImage3dRW:
4969 case clang::BuiltinType::Kind::OCLQueue:
4970 case clang::BuiltinType::Kind::OCLReserveID:
4971 case clang::BuiltinType::Kind::OCLSampler:
4972 case clang::BuiltinType::Kind::HLSLResource:
4973 case clang::BuiltinType::Kind::ArraySection:
4974 case clang::BuiltinType::Kind::OMPArrayShaping:
4975 case clang::BuiltinType::Kind::OMPIterator:
4976 case clang::BuiltinType::Kind::Overload:
4977 case clang::BuiltinType::Kind::PseudoObject:
4978 case clang::BuiltinType::Kind::UnknownAny:
4981 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4982 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4983 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4984 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4985 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4986 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4987 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4988 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4989 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4990 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4991 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4992 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4996 case clang::BuiltinType::VectorPair:
4997 case clang::BuiltinType::VectorQuad:
5001 case clang::BuiltinType::SveBool:
5002 case clang::BuiltinType::SveBoolx2:
5003 case clang::BuiltinType::SveBoolx4:
5004 case clang::BuiltinType::SveCount:
5005 case clang::BuiltinType::SveInt8:
5006 case clang::BuiltinType::SveInt8x2:
5007 case clang::BuiltinType::SveInt8x3:
5008 case clang::BuiltinType::SveInt8x4:
5009 case clang::BuiltinType::SveInt16:
5010 case clang::BuiltinType::SveInt16x2:
5011 case clang::BuiltinType::SveInt16x3:
5012 case clang::BuiltinType::SveInt16x4:
5013 case clang::BuiltinType::SveInt32:
5014 case clang::BuiltinType::SveInt32x2:
5015 case clang::BuiltinType::SveInt32x3:
5016 case clang::BuiltinType::SveInt32x4:
5017 case clang::BuiltinType::SveInt64:
5018 case clang::BuiltinType::SveInt64x2:
5019 case clang::BuiltinType::SveInt64x3:
5020 case clang::BuiltinType::SveInt64x4:
5021 case clang::BuiltinType::SveUint8:
5022 case clang::BuiltinType::SveUint8x2:
5023 case clang::BuiltinType::SveUint8x3:
5024 case clang::BuiltinType::SveUint8x4:
5025 case clang::BuiltinType::SveUint16:
5026 case clang::BuiltinType::SveUint16x2:
5027 case clang::BuiltinType::SveUint16x3:
5028 case clang::BuiltinType::SveUint16x4:
5029 case clang::BuiltinType::SveUint32:
5030 case clang::BuiltinType::SveUint32x2:
5031 case clang::BuiltinType::SveUint32x3:
5032 case clang::BuiltinType::SveUint32x4:
5033 case clang::BuiltinType::SveUint64:
5034 case clang::BuiltinType::SveUint64x2:
5035 case clang::BuiltinType::SveUint64x3:
5036 case clang::BuiltinType::SveUint64x4:
5037 case clang::BuiltinType::SveFloat16:
5038 case clang::BuiltinType::SveBFloat16:
5039 case clang::BuiltinType::SveBFloat16x2:
5040 case clang::BuiltinType::SveBFloat16x3:
5041 case clang::BuiltinType::SveBFloat16x4:
5042 case clang::BuiltinType::SveFloat16x2:
5043 case clang::BuiltinType::SveFloat16x3:
5044 case clang::BuiltinType::SveFloat16x4:
5045 case clang::BuiltinType::SveFloat32:
5046 case clang::BuiltinType::SveFloat32x2:
5047 case clang::BuiltinType::SveFloat32x3:
5048 case clang::BuiltinType::SveFloat32x4:
5049 case clang::BuiltinType::SveFloat64:
5050 case clang::BuiltinType::SveFloat64x2:
5051 case clang::BuiltinType::SveFloat64x3:
5052 case clang::BuiltinType::SveFloat64x4:
5056#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5057#include "clang/Basic/RISCVVTypes.def"
5061 case clang::BuiltinType::WasmExternRef:
5064 case clang::BuiltinType::IncompleteMatrixIdx:
5067 case clang::BuiltinType::UnresolvedTemplate:
5071#define AMDGPU_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5072#include "clang/Basic/AMDGPUTypes.def"
5078 case clang::Type::ObjCObjectPointer:
5079 case clang::Type::BlockPointer:
5080 case clang::Type::Pointer:
5081 case clang::Type::LValueReference:
5082 case clang::Type::RValueReference:
5083 case clang::Type::MemberPointer:
5085 case clang::Type::Complex: {
5087 if (qual_type->isComplexType())
5090 const clang::ComplexType *complex_type =
5091 qual_type->getAsComplexIntegerType();
5101 case clang::Type::ObjCInterface:
5103 case clang::Type::Record:
5105 case clang::Type::Enum:
5106 return qual_type->isUnsignedIntegerOrEnumerationType()
5109 case clang::Type::DependentSizedArray:
5110 case clang::Type::DependentSizedExtVector:
5111 case clang::Type::UnresolvedUsing:
5112 case clang::Type::Attributed:
5113 case clang::Type::BTFTagAttributed:
5114 case clang::Type::TemplateTypeParm:
5115 case clang::Type::SubstTemplateTypeParm:
5116 case clang::Type::SubstTemplateTypeParmPack:
5117 case clang::Type::InjectedClassName:
5118 case clang::Type::DependentName:
5119 case clang::Type::DependentTemplateSpecialization:
5120 case clang::Type::PackExpansion:
5121 case clang::Type::ObjCObject:
5123 case clang::Type::TemplateSpecialization:
5124 case clang::Type::DeducedTemplateSpecialization:
5125 case clang::Type::Adjusted:
5126 case clang::Type::Pipe:
5130 case clang::Type::Decayed:
5132 case clang::Type::ObjCTypeParam:
5135 case clang::Type::DependentAddressSpace:
5137 case clang::Type::MacroQualified:
5140 case clang::Type::ConstantMatrix:
5141 case clang::Type::DependentSizedMatrix:
5145 case clang::Type::PackIndexing:
5158 switch (qual_type->getTypeClass()) {
5159 case clang::Type::Atomic:
5160 case clang::Type::Auto:
5161 case clang::Type::CountAttributed:
5162 case clang::Type::Decltype:
5163 case clang::Type::Elaborated:
5164 case clang::Type::Paren:
5165 case clang::Type::Typedef:
5166 case clang::Type::TypeOf:
5167 case clang::Type::TypeOfExpr:
5168 case clang::Type::Using:
5169 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5170 case clang::Type::UnaryTransform:
5173 case clang::Type::FunctionNoProto:
5174 case clang::Type::FunctionProto:
5177 case clang::Type::IncompleteArray:
5178 case clang::Type::VariableArray:
5179 case clang::Type::ArrayParameter:
5182 case clang::Type::ConstantArray:
5185 case clang::Type::DependentVector:
5186 case clang::Type::ExtVector:
5187 case clang::Type::Vector:
5190 case clang::Type::BitInt:
5191 case clang::Type::DependentBitInt:
5195 case clang::Type::Builtin:
5196 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5197 case clang::BuiltinType::UnknownAny:
5198 case clang::BuiltinType::Void:
5199 case clang::BuiltinType::BoundMember:
5202 case clang::BuiltinType::Bool:
5204 case clang::BuiltinType::Char_S:
5205 case clang::BuiltinType::SChar:
5206 case clang::BuiltinType::WChar_S:
5207 case clang::BuiltinType::Char_U:
5208 case clang::BuiltinType::UChar:
5209 case clang::BuiltinType::WChar_U:
5211 case clang::BuiltinType::Char8:
5213 case clang::BuiltinType::Char16:
5215 case clang::BuiltinType::Char32:
5217 case clang::BuiltinType::UShort:
5219 case clang::BuiltinType::Short:
5221 case clang::BuiltinType::UInt:
5223 case clang::BuiltinType::Int:
5225 case clang::BuiltinType::ULong:
5227 case clang::BuiltinType::Long:
5229 case clang::BuiltinType::ULongLong:
5231 case clang::BuiltinType::LongLong:
5233 case clang::BuiltinType::UInt128:
5235 case clang::BuiltinType::Int128:
5237 case clang::BuiltinType::Half:
5238 case clang::BuiltinType::Float:
5239 case clang::BuiltinType::Double:
5240 case clang::BuiltinType::LongDouble:
5246 case clang::Type::ObjCObjectPointer:
5248 case clang::Type::BlockPointer:
5250 case clang::Type::Pointer:
5252 case clang::Type::LValueReference:
5253 case clang::Type::RValueReference:
5255 case clang::Type::MemberPointer:
5257 case clang::Type::Complex: {
5258 if (qual_type->isComplexType())
5263 case clang::Type::ObjCInterface:
5265 case clang::Type::Record:
5267 case clang::Type::Enum:
5269 case clang::Type::DependentSizedArray:
5270 case clang::Type::DependentSizedExtVector:
5271 case clang::Type::UnresolvedUsing:
5272 case clang::Type::Attributed:
5273 case clang::Type::BTFTagAttributed:
5274 case clang::Type::TemplateTypeParm:
5275 case clang::Type::SubstTemplateTypeParm:
5276 case clang::Type::SubstTemplateTypeParmPack:
5277 case clang::Type::InjectedClassName:
5278 case clang::Type::DependentName:
5279 case clang::Type::DependentTemplateSpecialization:
5280 case clang::Type::PackExpansion:
5281 case clang::Type::ObjCObject:
5283 case clang::Type::TemplateSpecialization:
5284 case clang::Type::DeducedTemplateSpecialization:
5285 case clang::Type::Adjusted:
5286 case clang::Type::Pipe:
5290 case clang::Type::Decayed:
5292 case clang::Type::ObjCTypeParam:
5295 case clang::Type::DependentAddressSpace:
5297 case clang::Type::MacroQualified:
5301 case clang::Type::ConstantMatrix:
5302 case clang::Type::DependentSizedMatrix:
5306 case clang::Type::PackIndexing:
5314 bool check_superclass) {
5315 while (class_interface_decl) {
5316 if (class_interface_decl->ivar_size() > 0)
5319 if (check_superclass)
5320 class_interface_decl = class_interface_decl->getSuperClass();
5327static std::optional<SymbolFile::ArrayInfo>
5329 clang::QualType qual_type,
5331 if (qual_type->isIncompleteArrayType())
5332 if (std::optional<ClangASTMetadata> metadata =
5336 return std::nullopt;
5339llvm::Expected<uint32_t>
5341 bool omit_empty_base_classes,
5344 return llvm::createStringError(
"invalid clang type");
5346 uint32_t num_children = 0;
5348 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5349 switch (type_class) {
5350 case clang::Type::Builtin:
5351 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5352 case clang::BuiltinType::ObjCId:
5353 case clang::BuiltinType::ObjCClass:
5362 case clang::Type::Complex:
5364 case clang::Type::Record:
5366 const clang::RecordType *record_type =
5367 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5368 const clang::RecordDecl *record_decl = record_type->getDecl();
5369 assert(record_decl);
5370 const clang::CXXRecordDecl *cxx_record_decl =
5371 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5372 if (cxx_record_decl) {
5373 if (omit_empty_base_classes) {
5377 clang::CXXRecordDecl::base_class_const_iterator base_class,
5379 for (base_class = cxx_record_decl->bases_begin(),
5380 base_class_end = cxx_record_decl->bases_end();
5381 base_class != base_class_end; ++base_class) {
5382 const clang::CXXRecordDecl *base_class_decl =
5383 llvm::cast<clang::CXXRecordDecl>(
5384 base_class->getType()
5385 ->getAs<clang::RecordType>()
5396 num_children += cxx_record_decl->getNumBases();
5399 num_children += std::distance(record_decl->field_begin(),
5400 record_decl->field_end());
5402 return llvm::createStringError(
5405 case clang::Type::ObjCObject:
5406 case clang::Type::ObjCInterface:
5408 const clang::ObjCObjectType *objc_class_type =
5409 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5410 assert(objc_class_type);
5411 if (objc_class_type) {
5412 clang::ObjCInterfaceDecl *class_interface_decl =
5413 objc_class_type->getInterface();
5415 if (class_interface_decl) {
5417 clang::ObjCInterfaceDecl *superclass_interface_decl =
5418 class_interface_decl->getSuperClass();
5419 if (superclass_interface_decl) {
5420 if (omit_empty_base_classes) {
5427 num_children += class_interface_decl->ivar_size();
5433 case clang::Type::LValueReference:
5434 case clang::Type::RValueReference:
5435 case clang::Type::ObjCObjectPointer: {
5438 uint32_t num_pointee_children = 0;
5440 auto num_children_or_err =
5441 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5442 if (!num_children_or_err)
5443 return num_children_or_err;
5444 num_pointee_children = *num_children_or_err;
5447 if (num_pointee_children == 0)
5450 num_children = num_pointee_children;
5453 case clang::Type::Vector:
5454 case clang::Type::ExtVector:
5456 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5459 case clang::Type::ConstantArray:
5460 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5464 case clang::Type::IncompleteArray:
5465 if (
auto array_info =
5468 num_children = array_info->element_orders.size()
5469 ? array_info->element_orders.back().value_or(0)
5473 case clang::Type::Pointer: {
5474 const clang::PointerType *pointer_type =
5475 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5476 clang::QualType pointee_type(pointer_type->getPointeeType());
5478 uint32_t num_pointee_children = 0;
5480 auto num_children_or_err =
5481 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5482 if (!num_children_or_err)
5483 return num_children_or_err;
5484 num_pointee_children = *num_children_or_err;
5486 if (num_pointee_children == 0) {
5491 num_children = num_pointee_children;
5497 return num_children;
5508 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5509 if (type_class == clang::Type::Builtin) {
5510 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5511 case clang::BuiltinType::Void:
5513 case clang::BuiltinType::Bool:
5515 case clang::BuiltinType::Char_S:
5517 case clang::BuiltinType::Char_U:
5519 case clang::BuiltinType::Char8:
5521 case clang::BuiltinType::Char16:
5523 case clang::BuiltinType::Char32:
5525 case clang::BuiltinType::UChar:
5527 case clang::BuiltinType::SChar:
5529 case clang::BuiltinType::WChar_S:
5531 case clang::BuiltinType::WChar_U:
5533 case clang::BuiltinType::Short:
5535 case clang::BuiltinType::UShort:
5537 case clang::BuiltinType::Int:
5539 case clang::BuiltinType::UInt:
5541 case clang::BuiltinType::Long:
5543 case clang::BuiltinType::ULong:
5545 case clang::BuiltinType::LongLong:
5547 case clang::BuiltinType::ULongLong:
5549 case clang::BuiltinType::Int128:
5551 case clang::BuiltinType::UInt128:
5554 case clang::BuiltinType::Half:
5556 case clang::BuiltinType::Float:
5558 case clang::BuiltinType::Double:
5560 case clang::BuiltinType::LongDouble:
5563 case clang::BuiltinType::NullPtr:
5565 case clang::BuiltinType::ObjCId:
5567 case clang::BuiltinType::ObjCClass:
5569 case clang::BuiltinType::ObjCSel:
5583 const llvm::APSInt &value)>
const &callback) {
5584 const clang::EnumType *enum_type =
5587 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5591 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5592 for (enum_pos = enum_decl->enumerator_begin(),
5593 enum_end_pos = enum_decl->enumerator_end();
5594 enum_pos != enum_end_pos; ++enum_pos) {
5595 ConstString name(enum_pos->getNameAsString().c_str());
5596 if (!callback(integer_type, name, enum_pos->getInitVal()))
5603#pragma mark Aggregate Types
5611 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5612 switch (type_class) {
5613 case clang::Type::Record:
5615 const clang::RecordType *record_type =
5616 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5618 clang::RecordDecl *record_decl = record_type->getDecl();
5620 count = std::distance(record_decl->field_begin(),
5621 record_decl->field_end());
5627 case clang::Type::ObjCObjectPointer: {
5628 const clang::ObjCObjectPointerType *objc_class_type =
5629 qual_type->castAs<clang::ObjCObjectPointerType>();
5630 const clang::ObjCInterfaceType *objc_interface_type =
5631 objc_class_type->getInterfaceType();
5632 if (objc_interface_type &&
5634 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5635 clang::ObjCInterfaceDecl *class_interface_decl =
5636 objc_interface_type->getDecl();
5637 if (class_interface_decl) {
5638 count = class_interface_decl->ivar_size();
5644 case clang::Type::ObjCObject:
5645 case clang::Type::ObjCInterface:
5647 const clang::ObjCObjectType *objc_class_type =
5648 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5649 if (objc_class_type) {
5650 clang::ObjCInterfaceDecl *class_interface_decl =
5651 objc_class_type->getInterface();
5653 if (class_interface_decl)
5654 count = class_interface_decl->ivar_size();
5667 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5668 std::string &name, uint64_t *bit_offset_ptr,
5669 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5670 if (class_interface_decl) {
5671 if (idx < (class_interface_decl->ivar_size())) {
5672 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5673 ivar_end = class_interface_decl->ivar_end();
5674 uint32_t ivar_idx = 0;
5676 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5677 ++ivar_pos, ++ivar_idx) {
5678 if (ivar_idx == idx) {
5679 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5681 clang::QualType ivar_qual_type(ivar_decl->getType());
5683 name.assign(ivar_decl->getNameAsString());
5685 if (bit_offset_ptr) {
5686 const clang::ASTRecordLayout &interface_layout =
5687 ast->getASTObjCInterfaceLayout(class_interface_decl);
5688 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5691 const bool is_bitfield = ivar_pos->isBitField();
5693 if (bitfield_bit_size_ptr) {
5694 *bitfield_bit_size_ptr = 0;
5696 if (is_bitfield && ast) {
5697 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5698 clang::Expr::EvalResult result;
5699 if (bitfield_bit_size_expr &&
5700 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5701 llvm::APSInt bitfield_apsint = result.Val.getInt();
5702 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5706 if (is_bitfield_ptr)
5707 *is_bitfield_ptr = is_bitfield;
5709 return ivar_qual_type.getAsOpaquePtr();
5718 size_t idx, std::string &name,
5719 uint64_t *bit_offset_ptr,
5720 uint32_t *bitfield_bit_size_ptr,
5721 bool *is_bitfield_ptr) {
5726 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5727 switch (type_class) {
5728 case clang::Type::Record:
5730 const clang::RecordType *record_type =
5731 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5732 const clang::RecordDecl *record_decl = record_type->getDecl();
5733 uint32_t field_idx = 0;
5734 clang::RecordDecl::field_iterator field, field_end;
5735 for (field = record_decl->field_begin(),
5736 field_end = record_decl->field_end();
5737 field != field_end; ++field, ++field_idx) {
5738 if (idx == field_idx) {
5741 name.assign(field->getNameAsString());
5745 if (bit_offset_ptr) {
5746 const clang::ASTRecordLayout &record_layout =
5748 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5751 const bool is_bitfield = field->isBitField();
5753 if (bitfield_bit_size_ptr) {
5754 *bitfield_bit_size_ptr = 0;
5757 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5758 clang::Expr::EvalResult result;
5759 if (bitfield_bit_size_expr &&
5760 bitfield_bit_size_expr->EvaluateAsInt(result,
5762 llvm::APSInt bitfield_apsint = result.Val.getInt();
5763 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5767 if (is_bitfield_ptr)
5768 *is_bitfield_ptr = is_bitfield;
5770 return GetType(field->getType());
5776 case clang::Type::ObjCObjectPointer: {
5777 const clang::ObjCObjectPointerType *objc_class_type =
5778 qual_type->castAs<clang::ObjCObjectPointerType>();
5779 const clang::ObjCInterfaceType *objc_interface_type =
5780 objc_class_type->getInterfaceType();
5781 if (objc_interface_type &&
5783 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5784 clang::ObjCInterfaceDecl *class_interface_decl =
5785 objc_interface_type->getDecl();
5786 if (class_interface_decl) {
5790 name, bit_offset_ptr, bitfield_bit_size_ptr,
5797 case clang::Type::ObjCObject:
5798 case clang::Type::ObjCInterface:
5800 const clang::ObjCObjectType *objc_class_type =
5801 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5802 assert(objc_class_type);
5803 if (objc_class_type) {
5804 clang::ObjCInterfaceDecl *class_interface_decl =
5805 objc_class_type->getInterface();
5809 name, bit_offset_ptr, bitfield_bit_size_ptr,
5825 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5826 switch (type_class) {
5827 case clang::Type::Record:
5829 const clang::CXXRecordDecl *cxx_record_decl =
5830 qual_type->getAsCXXRecordDecl();
5831 if (cxx_record_decl)
5832 count = cxx_record_decl->getNumBases();
5836 case clang::Type::ObjCObjectPointer:
5840 case clang::Type::ObjCObject:
5842 const clang::ObjCObjectType *objc_class_type =
5843 qual_type->getAsObjCQualifiedInterfaceType();
5844 if (objc_class_type) {
5845 clang::ObjCInterfaceDecl *class_interface_decl =
5846 objc_class_type->getInterface();
5848 if (class_interface_decl && class_interface_decl->getSuperClass())
5853 case clang::Type::ObjCInterface:
5855 const clang::ObjCInterfaceType *objc_interface_type =
5856 qual_type->getAs<clang::ObjCInterfaceType>();
5857 if (objc_interface_type) {
5858 clang::ObjCInterfaceDecl *class_interface_decl =
5859 objc_interface_type->getInterface();
5861 if (class_interface_decl && class_interface_decl->getSuperClass())
5877 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5878 switch (type_class) {
5879 case clang::Type::Record:
5881 const clang::CXXRecordDecl *cxx_record_decl =
5882 qual_type->getAsCXXRecordDecl();
5883 if (cxx_record_decl)
5884 count = cxx_record_decl->getNumVBases();
5897 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5898 switch (type_class) {
5899 case clang::Type::Record:
5901 const clang::CXXRecordDecl *cxx_record_decl =
5902 qual_type->getAsCXXRecordDecl();
5903 if (cxx_record_decl) {
5904 uint32_t curr_idx = 0;
5905 clang::CXXRecordDecl::base_class_const_iterator base_class,
5907 for (base_class = cxx_record_decl->bases_begin(),
5908 base_class_end = cxx_record_decl->bases_end();
5909 base_class != base_class_end; ++base_class, ++curr_idx) {
5910 if (curr_idx == idx) {
5911 if (bit_offset_ptr) {
5912 const clang::ASTRecordLayout &record_layout =
5914 const clang::CXXRecordDecl *base_class_decl =
5915 llvm::cast<clang::CXXRecordDecl>(
5916 base_class->getType()
5917 ->castAs<clang::RecordType>()
5919 if (base_class->isVirtual())
5921 record_layout.getVBaseClassOffset(base_class_decl)
5926 record_layout.getBaseClassOffset(base_class_decl)
5930 return GetType(base_class->getType());
5937 case clang::Type::ObjCObjectPointer:
5940 case clang::Type::ObjCObject:
5942 const clang::ObjCObjectType *objc_class_type =
5943 qual_type->getAsObjCQualifiedInterfaceType();
5944 if (objc_class_type) {
5945 clang::ObjCInterfaceDecl *class_interface_decl =
5946 objc_class_type->getInterface();
5948 if (class_interface_decl) {
5949 clang::ObjCInterfaceDecl *superclass_interface_decl =
5950 class_interface_decl->getSuperClass();
5951 if (superclass_interface_decl) {
5953 *bit_offset_ptr = 0;
5955 superclass_interface_decl));
5961 case clang::Type::ObjCInterface:
5963 const clang::ObjCObjectType *objc_interface_type =
5964 qual_type->getAs<clang::ObjCInterfaceType>();
5965 if (objc_interface_type) {
5966 clang::ObjCInterfaceDecl *class_interface_decl =
5967 objc_interface_type->getInterface();
5969 if (class_interface_decl) {
5970 clang::ObjCInterfaceDecl *superclass_interface_decl =
5971 class_interface_decl->getSuperClass();
5972 if (superclass_interface_decl) {
5974 *bit_offset_ptr = 0;
5976 superclass_interface_decl));
5992 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5993 switch (type_class) {
5994 case clang::Type::Record:
5996 const clang::CXXRecordDecl *cxx_record_decl =
5997 qual_type->getAsCXXRecordDecl();
5998 if (cxx_record_decl) {
5999 uint32_t curr_idx = 0;
6000 clang::CXXRecordDecl::base_class_const_iterator base_class,
6002 for (base_class = cxx_record_decl->vbases_begin(),
6003 base_class_end = cxx_record_decl->vbases_end();
6004 base_class != base_class_end; ++base_class, ++curr_idx) {
6005 if (curr_idx == idx) {
6006 if (bit_offset_ptr) {
6007 const clang::ASTRecordLayout &record_layout =
6009 const clang::CXXRecordDecl *base_class_decl =
6010 llvm::cast<clang::CXXRecordDecl>(
6011 base_class->getType()
6012 ->castAs<clang::RecordType>()
6015 record_layout.getVBaseClassOffset(base_class_decl)
6019 return GetType(base_class->getType());
6034 llvm::StringRef name) {
6036 switch (qual_type->getTypeClass()) {
6037 case clang::Type::Record: {
6041 const clang::RecordType *record_type =
6042 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6043 const clang::RecordDecl *record_decl = record_type->getDecl();
6045 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
6046 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
6047 auto *var_decl = dyn_cast<clang::VarDecl>(decl);
6048 if (!var_decl || var_decl->getStorageClass() != clang::SC_Static)
6072 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6073 switch (type_class) {
6074 case clang::Type::Builtin:
6075 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
6076 case clang::BuiltinType::UnknownAny:
6077 case clang::BuiltinType::Void:
6078 case clang::BuiltinType::NullPtr:
6079 case clang::BuiltinType::OCLEvent:
6080 case clang::BuiltinType::OCLImage1dRO:
6081 case clang::BuiltinType::OCLImage1dWO:
6082 case clang::BuiltinType::OCLImage1dRW:
6083 case clang::BuiltinType::OCLImage1dArrayRO:
6084 case clang::BuiltinType::OCLImage1dArrayWO:
6085 case clang::BuiltinType::OCLImage1dArrayRW:
6086 case clang::BuiltinType::OCLImage1dBufferRO:
6087 case clang::BuiltinType::OCLImage1dBufferWO:
6088 case clang::BuiltinType::OCLImage1dBufferRW:
6089 case clang::BuiltinType::OCLImage2dRO:
6090 case clang::BuiltinType::OCLImage2dWO:
6091 case clang::BuiltinType::OCLImage2dRW:
6092 case clang::BuiltinType::OCLImage2dArrayRO:
6093 case clang::BuiltinType::OCLImage2dArrayWO:
6094 case clang::BuiltinType::OCLImage2dArrayRW:
6095 case clang::BuiltinType::OCLImage3dRO:
6096 case clang::BuiltinType::OCLImage3dWO:
6097 case clang::BuiltinType::OCLImage3dRW:
6098 case clang::BuiltinType::OCLSampler:
6099 case clang::BuiltinType::HLSLResource:
6101 case clang::BuiltinType::Bool:
6102 case clang::BuiltinType::Char_U:
6103 case clang::BuiltinType::UChar:
6104 case clang::BuiltinType::WChar_U:
6105 case clang::BuiltinType::Char16:
6106 case clang::BuiltinType::Char32:
6107 case clang::BuiltinType::UShort:
6108 case clang::BuiltinType::UInt:
6109 case clang::BuiltinType::ULong:
6110 case clang::BuiltinType::ULongLong:
6111 case clang::BuiltinType::UInt128:
6112 case clang::BuiltinType::Char_S:
6113 case clang::BuiltinType::SChar:
6114 case clang::BuiltinType::WChar_S:
6115 case clang::BuiltinType::Short:
6116 case clang::BuiltinType::Int:
6117 case clang::BuiltinType::Long:
6118 case clang::BuiltinType::LongLong:
6119 case clang::BuiltinType::Int128:
6120 case clang::BuiltinType::Float:
6121 case clang::BuiltinType::Double:
6122 case clang::BuiltinType::LongDouble:
6123 case clang::BuiltinType::Dependent:
6124 case clang::BuiltinType::Overload:
6125 case clang::BuiltinType::ObjCId:
6126 case clang::BuiltinType::ObjCClass:
6127 case clang::BuiltinType::ObjCSel:
6128 case clang::BuiltinType::BoundMember:
6129 case clang::BuiltinType::Half:
6130 case clang::BuiltinType::ARCUnbridgedCast:
6131 case clang::BuiltinType::PseudoObject:
6132 case clang::BuiltinType::BuiltinFn:
6133 case clang::BuiltinType::ArraySection:
6140 case clang::Type::Complex:
6142 case clang::Type::Pointer:
6144 case clang::Type::BlockPointer:
6147 case clang::Type::LValueReference:
6149 case clang::Type::RValueReference:
6151 case clang::Type::MemberPointer:
6153 case clang::Type::ConstantArray:
6155 case clang::Type::IncompleteArray:
6157 case clang::Type::VariableArray:
6159 case clang::Type::DependentSizedArray:
6161 case clang::Type::DependentSizedExtVector:
6163 case clang::Type::Vector:
6165 case clang::Type::ExtVector:
6167 case clang::Type::FunctionProto:
6169 case clang::Type::FunctionNoProto:
6171 case clang::Type::UnresolvedUsing:
6173 case clang::Type::Record:
6175 case clang::Type::Enum:
6177 case clang::Type::TemplateTypeParm:
6179 case clang::Type::SubstTemplateTypeParm:
6181 case clang::Type::TemplateSpecialization:
6183 case clang::Type::InjectedClassName:
6185 case clang::Type::DependentName:
6187 case clang::Type::DependentTemplateSpecialization:
6189 case clang::Type::ObjCObject:
6191 case clang::Type::ObjCInterface:
6193 case clang::Type::ObjCObjectPointer:
6203 bool transparent_pointers,
bool omit_empty_base_classes,
6204 bool ignore_array_bounds, std::string &child_name,
6205 uint32_t &child_byte_size, int32_t &child_byte_offset,
6206 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6207 bool &child_is_base_class,
bool &child_is_deref_of_parent,
6212 auto get_exe_scope = [&exe_ctx]() {
6216 clang::QualType parent_qual_type(
6218 const clang::Type::TypeClass parent_type_class =
6219 parent_qual_type->getTypeClass();
6220 child_bitfield_bit_size = 0;
6221 child_bitfield_bit_offset = 0;
6222 child_is_base_class =
false;
6225 auto num_children_or_err =
6227 if (!num_children_or_err)
6228 return num_children_or_err.takeError();
6230 const bool idx_is_valid = idx < *num_children_or_err;
6232 switch (parent_type_class) {
6233 case clang::Type::Builtin:
6235 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) {
6236 case clang::BuiltinType::ObjCId:
6237 case clang::BuiltinType::ObjCClass:
6250 case clang::Type::Record:
6252 const clang::RecordType *record_type =
6253 llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6254 const clang::RecordDecl *record_decl = record_type->getDecl();
6255 assert(record_decl);
6256 const clang::ASTRecordLayout &record_layout =
6258 uint32_t child_idx = 0;
6260 const clang::CXXRecordDecl *cxx_record_decl =
6261 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6262 if (cxx_record_decl) {
6264 clang::CXXRecordDecl::base_class_const_iterator base_class,
6266 for (base_class = cxx_record_decl->bases_begin(),
6267 base_class_end = cxx_record_decl->bases_end();
6268 base_class != base_class_end; ++base_class) {
6269 const clang::CXXRecordDecl *base_class_decl =
nullptr;
6272 if (omit_empty_base_classes) {
6273 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6274 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6279 if (idx == child_idx) {
6280 if (base_class_decl ==
nullptr)
6281 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6282 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6284 if (base_class->isVirtual()) {
6285 bool handled =
false;
6287 clang::VTableContextBase *vtable_ctx =
6291 record_layout, cxx_record_decl,
6292 base_class_decl, bit_offset);
6295 bit_offset = record_layout.getVBaseClassOffset(base_class_decl)
6299 bit_offset = record_layout.getBaseClassOffset(base_class_decl)
6304 child_byte_offset = bit_offset / 8;
6307 std::optional<uint64_t> size =
6308 base_class_clang_type.
GetBitSize(get_exe_scope());
6310 return llvm::createStringError(
"no size info for base class");
6312 uint64_t base_class_clang_type_bit_size = *size;
6315 assert(base_class_clang_type_bit_size % 8 == 0);
6316 child_byte_size = base_class_clang_type_bit_size / 8;
6317 child_is_base_class =
true;
6318 return base_class_clang_type;
6326 uint32_t field_idx = 0;
6327 clang::RecordDecl::field_iterator field, field_end;
6328 for (field = record_decl->field_begin(),
6329 field_end = record_decl->field_end();
6330 field != field_end; ++field, ++field_idx, ++child_idx) {
6331 if (idx == child_idx) {
6334 child_name.assign(field->getNameAsString());
6339 assert(field_idx < record_layout.getFieldCount());
6340 std::optional<uint64_t> size =
6343 return llvm::createStringError(
"no size info for field");
6345 child_byte_size = *size;
6346 const uint32_t child_bit_size = child_byte_size * 8;
6350 bit_offset = record_layout.getFieldOffset(field_idx);
6352 child_bitfield_bit_offset = bit_offset % child_bit_size;
6353 const uint32_t child_bit_offset =
6354 bit_offset - child_bitfield_bit_offset;
6355 child_byte_offset = child_bit_offset / 8;
6357 child_byte_offset = bit_offset / 8;
6360 return field_clang_type;
6366 case clang::Type::ObjCObject:
6367 case clang::Type::ObjCInterface:
6369 const clang::ObjCObjectType *objc_class_type =
6370 llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6371 assert(objc_class_type);
6372 if (objc_class_type) {
6373 uint32_t child_idx = 0;
6374 clang::ObjCInterfaceDecl *class_interface_decl =
6375 objc_class_type->getInterface();
6377 if (class_interface_decl) {
6379 const clang::ASTRecordLayout &interface_layout =
6380 getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
6381 clang::ObjCInterfaceDecl *superclass_interface_decl =
6382 class_interface_decl->getSuperClass();
6383 if (superclass_interface_decl) {
6384 if (omit_empty_base_classes) {
6387 superclass_interface_decl));
6388 if (llvm::expectedToStdOptional(
6390 omit_empty_base_classes, exe_ctx))
6393 clang::QualType ivar_qual_type(
6395 superclass_interface_decl));
6398 superclass_interface_decl->getNameAsString());
6400 clang::TypeInfo ivar_type_info =
6403 child_byte_size = ivar_type_info.Width / 8;
6404 child_byte_offset = 0;
6405 child_is_base_class =
true;
6407 return GetType(ivar_qual_type);
6416 const uint32_t superclass_idx = child_idx;
6418 if (idx < (child_idx + class_interface_decl->ivar_size())) {
6419 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6420 ivar_end = class_interface_decl->ivar_end();
6422 for (ivar_pos = class_interface_decl->ivar_begin();
6423 ivar_pos != ivar_end; ++ivar_pos) {
6424 if (child_idx == idx) {
6425 clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6427 clang::QualType ivar_qual_type(ivar_decl->getType());
6429 child_name.assign(ivar_decl->getNameAsString());
6431 clang::TypeInfo ivar_type_info =
6434 child_byte_size = ivar_type_info.Width / 8;
6450 if (objc_runtime !=
nullptr) {
6453 parent_ast_type, ivar_decl->getNameAsString().c_str());
6461 if (child_byte_offset ==
6463 bit_offset = interface_layout.getFieldOffset(child_idx -
6465 child_byte_offset = bit_offset / 8;
6476 bit_offset = interface_layout.getFieldOffset(
6477 child_idx - superclass_idx);
6479 child_bitfield_bit_offset = bit_offset % 8;
6481 return GetType(ivar_qual_type);
6491 case clang::Type::ObjCObjectPointer:
6496 child_is_deref_of_parent =
false;
6497 bool tmp_child_is_deref_of_parent =
false;
6499 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6500 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6501 child_bitfield_bit_size, child_bitfield_bit_offset,
6502 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6505 child_is_deref_of_parent =
true;
6506 const char *parent_name =
6509 child_name.assign(1,
'*');
6510 child_name += parent_name;
6515 if (std::optional<uint64_t> size =
6516 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6517 child_byte_size = *size;
6518 child_byte_offset = 0;
6519 return pointee_clang_type;
6526 case clang::Type::Vector:
6527 case clang::Type::ExtVector:
6529 const clang::VectorType *array =
6530 llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6534 char element_name[64];
6535 ::snprintf(element_name,
sizeof(element_name),
"[%" PRIu64
"]",
6536 static_cast<uint64_t
>(idx));
6537 child_name.assign(element_name);
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::ConstantArray:
6550 case clang::Type::IncompleteArray:
6551 if (ignore_array_bounds || idx_is_valid) {
6552 const clang::ArrayType *array =
GetQualType(type)->getAsArrayTypeUnsafe();
6556 child_name = std::string(llvm::formatv(
"[{0}]", idx));
6557 if (std::optional<uint64_t> size =
6559 child_byte_size = *size;
6560 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6561 return element_type;
6568 case clang::Type::Pointer: {
6576 child_is_deref_of_parent =
false;
6577 bool tmp_child_is_deref_of_parent =
false;
6579 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6580 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6581 child_bitfield_bit_size, child_bitfield_bit_offset,
6582 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6585 child_is_deref_of_parent =
true;
6587 const char *parent_name =
6590 child_name.assign(1,
'*');
6591 child_name += parent_name;
6596 if (std::optional<uint64_t> size =
6597 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6598 child_byte_size = *size;
6599 child_byte_offset = 0;
6600 return pointee_clang_type;
6607 case clang::Type::LValueReference:
6608 case clang::Type::RValueReference:
6610 const clang::ReferenceType *reference_type =
6611 llvm::cast<clang::ReferenceType>(
6614 GetType(reference_type->getPointeeType());
6616 child_is_deref_of_parent =
false;
6617 bool tmp_child_is_deref_of_parent =
false;
6619 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6620 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6621 child_bitfield_bit_size, child_bitfield_bit_offset,
6622 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6625 const char *parent_name =
6628 child_name.assign(1,
'&');
6629 child_name += parent_name;
6634 if (std::optional<uint64_t> size =
6635 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6636 child_byte_size = *size;
6637 child_byte_offset = 0;
6638 return pointee_clang_type;
6652 const clang::RecordDecl *record_decl,
6653 const clang::CXXBaseSpecifier *base_spec,
6654 bool omit_empty_base_classes) {
6655 uint32_t child_idx = 0;
6657 const clang::CXXRecordDecl *cxx_record_decl =
6658 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6660 if (cxx_record_decl) {
6661 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6662 for (base_class = cxx_record_decl->bases_begin(),
6663 base_class_end = cxx_record_decl->bases_end();
6664 base_class != base_class_end; ++base_class) {
6665 if (omit_empty_base_classes) {
6670 if (base_class == base_spec)
6680 const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl,
6681 bool omit_empty_base_classes) {
6683 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6684 omit_empty_base_classes);
6686 clang::RecordDecl::field_iterator field, field_end;
6687 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6688 field != field_end; ++field, ++child_idx) {
6689 if (field->getCanonicalDecl() == canonical_decl)
6731 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
6732 if (type && !name.empty()) {
6734 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6735 switch (type_class) {
6736 case clang::Type::Record:
6738 const clang::RecordType *record_type =
6739 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6740 const clang::RecordDecl *record_decl = record_type->getDecl();
6742 assert(record_decl);
6743 uint32_t child_idx = 0;
6745 const clang::CXXRecordDecl *cxx_record_decl =
6746 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6749 clang::RecordDecl::field_iterator field, field_end;
6750 for (field = record_decl->field_begin(),
6751 field_end = record_decl->field_end();
6752 field != field_end; ++field, ++child_idx) {
6753 llvm::StringRef field_name = field->getName();
6754 if (field_name.empty()) {
6756 child_indexes.push_back(child_idx);
6758 name, omit_empty_base_classes, child_indexes))
6759 return child_indexes.size();
6760 child_indexes.pop_back();
6762 }
else if (field_name == name) {
6764 child_indexes.push_back(
6766 cxx_record_decl, omit_empty_base_classes));
6767 return child_indexes.size();
6771 if (cxx_record_decl) {
6772 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6775 clang::IdentifierInfo &ident_ref =
getASTContext().Idents.get(name);
6776 clang::DeclarationName decl_name(&ident_ref);
6778 clang::CXXBasePaths paths;
6779 if (cxx_record_decl->lookupInBases(
6780 [decl_name](
const clang::CXXBaseSpecifier *specifier,
6781 clang::CXXBasePath &path) {
6782 CXXRecordDecl *record =
6783 specifier->getType()->getAsCXXRecordDecl();
6784 auto r = record->lookup(decl_name);
6785 path.Decls = r.begin();
6789 clang::CXXBasePaths::const_paths_iterator path,
6790 path_end = paths.end();
6791 for (path = paths.begin(); path != path_end; ++path) {
6792 const size_t num_path_elements = path->size();
6793 for (
size_t e = 0; e < num_path_elements; ++e) {
6794 clang::CXXBasePathElement elem = (*path)[e];
6797 omit_empty_base_classes);
6799 child_indexes.clear();
6802 child_indexes.push_back(child_idx);
6803 parent_record_decl = llvm::cast<clang::RecordDecl>(
6804 elem.Base->getType()
6805 ->castAs<clang::RecordType>()
6809 for (clang::DeclContext::lookup_iterator I = path->Decls, E;
6812 parent_record_decl, *I, omit_empty_base_classes);
6814 child_indexes.clear();
6817 child_indexes.push_back(child_idx);
6821 return child_indexes.size();
6827 case clang::Type::ObjCObject:
6828 case clang::Type::ObjCInterface:
6830 llvm::StringRef name_sref(name);
6831 const clang::ObjCObjectType *objc_class_type =
6832 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6833 assert(objc_class_type);
6834 if (objc_class_type) {
6835 uint32_t child_idx = 0;
6836 clang::ObjCInterfaceDecl *class_interface_decl =
6837 objc_class_type->getInterface();
6839 if (class_interface_decl) {
6840 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6841 ivar_end = class_interface_decl->ivar_end();
6842 clang::ObjCInterfaceDecl *superclass_interface_decl =
6843 class_interface_decl->getSuperClass();
6845 for (ivar_pos = class_interface_decl->ivar_begin();
6846 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6847 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6849 if (ivar_decl->getName() == name_sref) {
6850 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6851 (omit_empty_base_classes &&
6855 child_indexes.push_back(child_idx);
6856 return child_indexes.size();
6860 if (superclass_interface_decl) {
6864 child_indexes.push_back(0);
6868 superclass_interface_decl));
6870 name, omit_empty_base_classes, child_indexes)) {
6873 return child_indexes.size();
6878 child_indexes.pop_back();
6885 case clang::Type::ObjCObjectPointer: {
6887 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6888 ->getPointeeType());
6890 name, omit_empty_base_classes, child_indexes);
6893 case clang::Type::ConstantArray: {
6933 case clang::Type::LValueReference:
6934 case clang::Type::RValueReference: {
6935 const clang::ReferenceType *reference_type =
6936 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6937 clang::QualType pointee_type(reference_type->getPointeeType());
6942 name, omit_empty_base_classes, child_indexes);
6946 case clang::Type::Pointer: {
6951 name, omit_empty_base_classes, child_indexes);
6968 llvm::StringRef name,
6969 bool omit_empty_base_classes) {
6970 if (type && !name.empty()) {
6973 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6975 switch (type_class) {
6976 case clang::Type::Record:
6978 const clang::RecordType *record_type =
6979 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6980 const clang::RecordDecl *record_decl = record_type->getDecl();
6982 assert(record_decl);
6983 uint32_t child_idx = 0;
6985 const clang::CXXRecordDecl *cxx_record_decl =
6986 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6988 if (cxx_record_decl) {
6989 clang::CXXRecordDecl::base_class_const_iterator base_class,
6991 for (base_class = cxx_record_decl->bases_begin(),
6992 base_class_end = cxx_record_decl->bases_end();
6993 base_class != base_class_end; ++base_class) {
6995 clang::CXXRecordDecl *base_class_decl =
6996 llvm::cast<clang::CXXRecordDecl>(
6997 base_class->getType()
6998 ->castAs<clang::RecordType>()
7000 if (omit_empty_base_classes &&
7005 std::string base_class_type_name(
7007 if (base_class_type_name == name)
7014 clang::RecordDecl::field_iterator field, field_end;
7015 for (field = record_decl->field_begin(),
7016 field_end = record_decl->field_end();
7017 field != field_end; ++field, ++child_idx) {
7018 if (field->getName() == name)
7024 case clang::Type::ObjCObject:
7025 case clang::Type::ObjCInterface:
7027 const clang::ObjCObjectType *objc_class_type =
7028 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
7029 assert(objc_class_type);
7030 if (objc_class_type) {
7031 uint32_t child_idx = 0;
7032 clang::ObjCInterfaceDecl *class_interface_decl =
7033 objc_class_type->getInterface();
7035 if (class_interface_decl) {
7036 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
7037 ivar_end = class_interface_decl->ivar_end();
7038 clang::ObjCInterfaceDecl *superclass_interface_decl =
7039 class_interface_decl->getSuperClass();
7041 for (ivar_pos = class_interface_decl->ivar_begin();
7042 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
7043 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
7045 if (ivar_decl->getName() == name) {
7046 if ((!omit_empty_base_classes && superclass_interface_decl) ||
7047 (omit_empty_base_classes &&
7055 if (superclass_interface_decl) {
7056 if (superclass_interface_decl->getName() == name)
7064 case clang::Type::ObjCObjectPointer: {
7066 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
7067 ->getPointeeType());
7069 name, omit_empty_base_classes);
7072 case clang::Type::ConstantArray: {
7112 case clang::Type::LValueReference:
7113 case clang::Type::RValueReference: {
7114 const clang::ReferenceType *reference_type =
7115 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
7120 omit_empty_base_classes);
7124 case clang::Type::Pointer: {
7125 const clang::PointerType *pointer_type =
7126 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
7131 omit_empty_base_classes);
7161 llvm::StringRef name) {
7162 if (!type || name.empty())
7166 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7168 switch (type_class) {
7169 case clang::Type::Record: {
7172 const clang::RecordType *record_type =
7173 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7174 const clang::RecordDecl *record_decl = record_type->getDecl();
7176 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7177 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
7178 if (
auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
7180 if (
auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl))
7196 if (
auto *cxx_record_decl = dyn_cast<clang::TagType>(clang_type))
7197 return isa<clang::ClassTemplateSpecializationDecl>(
7198 cxx_record_decl->getDecl());
7209 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7210 switch (type_class) {
7211 case clang::Type::Record:
7213 const clang::CXXRecordDecl *cxx_record_decl =
7214 qual_type->getAsCXXRecordDecl();
7215 if (cxx_record_decl) {
7216 const clang::ClassTemplateSpecializationDecl *template_decl =
7217 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7219 if (template_decl) {
7220 const auto &template_arg_list = template_decl->getTemplateArgs();
7221 size_t num_args = template_arg_list.size();
7222 assert(num_args &&
"template specialization without any args");
7223 if (expand_pack && num_args) {
7224 const auto &pack = template_arg_list[num_args - 1];
7225 if (pack.getKind() == clang::TemplateArgument::Pack)
7226 num_args += pack.pack_size() - 1;
7241const clang::ClassTemplateSpecializationDecl *
7248 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7249 switch (type_class) {
7250 case clang::Type::Record: {
7253 const clang::CXXRecordDecl *cxx_record_decl =
7254 qual_type->getAsCXXRecordDecl();
7255 if (!cxx_record_decl)
7257 return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7266const TemplateArgument *
7268 size_t idx,
bool expand_pack) {
7269 const auto &args = decl->getTemplateArgs();
7270 const size_t args_size = args.size();
7272 assert(args_size &&
"template specialization without any args");
7276 const size_t last_idx = args_size - 1;
7285 if (!expand_pack || args[last_idx].getKind() != clang::TemplateArgument::Pack)
7286 return idx >= args.size() ? nullptr : &args[idx];
7291 const auto &pack = args[last_idx];
7292 const size_t pack_idx = idx - last_idx;
7293 if (pack_idx >= pack.pack_size())
7295 return &pack.pack_elements()[pack_idx];
7300 size_t arg_idx,
bool expand_pack) {
7301 const clang::ClassTemplateSpecializationDecl *template_decl =
7310 switch (arg->getKind()) {
7311 case clang::TemplateArgument::Null:
7314 case clang::TemplateArgument::NullPtr:
7317 case clang::TemplateArgument::Type:
7320 case clang::TemplateArgument::Declaration:
7323 case clang::TemplateArgument::Integral:
7326 case clang::TemplateArgument::Template:
7329 case clang::TemplateArgument::TemplateExpansion:
7332 case clang::TemplateArgument::Expression:
7335 case clang::TemplateArgument::Pack:
7338 case clang::TemplateArgument::StructuralValue:
7341 llvm_unreachable(
"Unhandled clang::TemplateArgument::ArgKind");
7346 size_t idx,
bool expand_pack) {
7347 const clang::ClassTemplateSpecializationDecl *template_decl =
7353 if (!arg || arg->getKind() != clang::TemplateArgument::Type)
7356 return GetType(arg->getAsType());
7359std::optional<CompilerType::IntegralTemplateArgument>
7361 size_t idx,
bool expand_pack) {
7362 const clang::ClassTemplateSpecializationDecl *template_decl =
7365 return std::nullopt;
7368 if (!arg || arg->getKind() != clang::TemplateArgument::Integral)
7369 return std::nullopt;
7371 return {{arg->getAsIntegral(),
GetType(arg->getIntegralType())}};
7381 const clang::EnumType *enutype =
7384 return enutype->getDecl();
7389 const clang::RecordType *record_type =
7392 return record_type->getDecl();
7400clang::TypedefNameDecl *
7402 const clang::TypedefType *typedef_type =
7405 return typedef_type->getDecl();
7409clang::CXXRecordDecl *
7414clang::ObjCInterfaceDecl *
7416 const clang::ObjCObjectType *objc_class_type =
7417 llvm::dyn_cast<clang::ObjCObjectType>(
7419 if (objc_class_type)
7420 return objc_class_type->getInterface();
7427 uint32_t bitfield_bit_size) {
7435 clang::IdentifierInfo *ident =
nullptr;
7437 ident = &clang_ast.Idents.get(name);
7439 clang::FieldDecl *field =
nullptr;
7441 clang::Expr *bit_width =
nullptr;
7442 if (bitfield_bit_size != 0) {
7443 llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
7445 bit_width =
new (clang_ast)
7446 clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
7447 clang_ast.IntTy, clang::SourceLocation());
7450 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7452 field = clang::FieldDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7453 field->setDeclContext(record_decl);
7454 field->setDeclName(ident);
7457 field->setBitWidth(bit_width);
7463 if (
const clang::TagType *TagT =
7464 field->getType()->getAs<clang::TagType>()) {
7465 if (clang::RecordDecl *Rec =
7466 llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7467 if (!Rec->getDeclName()) {
7468 Rec->setAnonymousStructOrUnion(
true);
7469 field->setImplicit();
7475 clang::AccessSpecifier access_specifier =
7477 field->setAccess(access_specifier);
7479 if (clang::CXXRecordDecl *cxx_record_decl =
7480 llvm::dyn_cast<CXXRecordDecl>(record_decl)) {
7481 AddAccessSpecifierDecl(cxx_record_decl, ast->getASTContext(),
7482 ast->GetCXXRecordDeclAccess(cxx_record_decl),
7484 ast->SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
7486 record_decl->addDecl(field);
7491 clang::ObjCInterfaceDecl *class_interface_decl =
7492 ast->GetAsObjCInterfaceDecl(type);
7494 if (class_interface_decl) {
7495 const bool is_synthesized =
false;
7500 clang::ObjCIvarDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7501 ivar->setDeclContext(class_interface_decl);
7502 ivar->setDeclName(ident);
7506 ivar->setBitWidth(bit_width);
7507 ivar->setSynthesize(is_synthesized);
7512 class_interface_decl->addDecl(field);
7535 typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7537 IndirectFieldVector indirect_fields;
7538 clang::RecordDecl::field_iterator field_pos;
7539 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7540 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7541 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos;
7542 last_field_pos = field_pos++) {
7543 if (field_pos->isAnonymousStructOrUnion()) {
7544 clang::QualType field_qual_type = field_pos->getType();
7546 const clang::RecordType *field_record_type =
7547 field_qual_type->getAs<clang::RecordType>();
7549 if (!field_record_type)
7552 clang::RecordDecl *field_record_decl = field_record_type->getDecl();
7554 if (!field_record_decl)
7557 for (clang::RecordDecl::decl_iterator
7558 di = field_record_decl->decls_begin(),
7559 de = field_record_decl->decls_end();
7561 if (clang::FieldDecl *nested_field_decl =
7562 llvm::dyn_cast<clang::FieldDecl>(*di)) {
7563 clang::NamedDecl **chain =
7564 new (ast->getASTContext()) clang::NamedDecl *[2];
7565 chain[0] = *field_pos;
7566 chain[1] = nested_field_decl;
7567 clang::IndirectFieldDecl *indirect_field =
7568 clang::IndirectFieldDecl::Create(
7569 ast->getASTContext(), record_decl, clang::SourceLocation(),
7570 nested_field_decl->getIdentifier(),
7571 nested_field_decl->getType(), {chain, 2});
7574 indirect_field->setImplicit();
7577 field_pos->getAccess(), nested_field_decl->getAccess()));
7579 indirect_fields.push_back(indirect_field);
7580 }
else if (clang::IndirectFieldDecl *nested_indirect_field_decl =
7581 llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
7582 size_t nested_chain_size =
7583 nested_indirect_field_decl->getChainingSize();
7584 clang::NamedDecl **chain =
new (ast->getASTContext())
7585 clang::NamedDecl *[nested_chain_size + 1];
7586 chain[0] = *field_pos;
7588 int chain_index = 1;
7589 for (clang::IndirectFieldDecl::chain_iterator
7590 nci = nested_indirect_field_decl->chain_begin(),
7591 nce = nested_indirect_field_decl->chain_end();
7593 chain[chain_index] = *nci;
7597 clang::IndirectFieldDecl *indirect_field =
7598 clang::IndirectFieldDecl::Create(
7599 ast->getASTContext(), record_decl, clang::SourceLocation(),
7600 nested_indirect_field_decl->getIdentifier(),
7601 nested_indirect_field_decl->getType(),
7602 {chain, nested_chain_size + 1});
7605 indirect_field->setImplicit();
7608 field_pos->getAccess(), nested_indirect_field_decl->getAccess()));
7610 indirect_fields.push_back(indirect_field);
7618 if (last_field_pos != field_end_pos) {
7619 if (last_field_pos->getType()->isIncompleteArrayType())
7620 record_decl->hasFlexibleArrayMember();
7623 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(),
7624 ife = indirect_fields.end();
7626 record_decl->addDecl(*ifi);
7640 record_decl->addAttr(
7641 clang::PackedAttr::CreateImplicit(ast->getASTContext()));
7661 clang::VarDecl *var_decl =
nullptr;
7662 clang::IdentifierInfo *ident =
nullptr;
7664 ident = &ast->getASTContext().Idents.get(name);
7667 clang::VarDecl::CreateDeserialized(ast->getASTContext(), GlobalDeclID());
7668 var_decl->setDeclContext(record_decl);
7669 var_decl->setDeclName(ident);
7671 var_decl->setStorageClass(clang::SC_Static);
7676 var_decl->setAccess(
7678 record_decl->addDecl(var_decl);
7680 VerifyDecl(var_decl);
7686 VarDecl *var,
const llvm::APInt &init_value) {
7687 assert(!var->hasInit() &&
"variable already initialized");
7689 clang::ASTContext &ast = var->getASTContext();
7690 QualType qt = var->getType();
7691 assert(qt->isIntegralOrEnumerationType() &&
7692 "only integer or enum types supported");
7695 if (
const EnumType *enum_type = qt->getAs<EnumType>()) {
7696 const EnumDecl *enum_decl = enum_type->getDecl();
7697 qt = enum_decl->getIntegerType();
7701 if (qt->isSpecificBuiltinType(BuiltinType::Bool)) {
7702 var->setInit(CXXBoolLiteralExpr::Create(
7703 ast, !init_value.isZero(), qt.getUnqualifiedType(), SourceLocation()));
7705 var->setInit(IntegerLiteral::Create(
7706 ast, init_value, qt.getUnqualifiedType(), SourceLocation()));
7711 clang::VarDecl *var,
const llvm::APFloat &init_value) {
7712 assert(!var->hasInit() &&
"variable already initialized");
7714 clang::ASTContext &ast = var->getASTContext();
7715 QualType qt = var->getType();
7716 assert(qt->isFloatingType() &&
"only floating point types supported");
7717 var->setInit(FloatingLiteral::Create(
7718 ast, init_value,
true, qt.getUnqualifiedType(), SourceLocation()));
7723 const char *mangled_name,
const CompilerType &method_clang_type,
7725 bool is_explicit,
bool is_attr_used,
bool is_artificial) {
7726 if (!type || !method_clang_type.
IsValid() || name.empty())
7731 clang::CXXRecordDecl *cxx_record_decl =
7732 record_qual_type->getAsCXXRecordDecl();
7734 if (cxx_record_decl ==
nullptr)
7739 clang::CXXMethodDecl *cxx_method_decl =
nullptr;
7741 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7743 const clang::FunctionType *function_type =
7744 llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7746 if (function_type ==
nullptr)
7749 const clang::FunctionProtoType *method_function_prototype(
7750 llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7752 if (!method_function_prototype)
7755 unsigned int num_params = method_function_prototype->getNumParams();
7757 clang::CXXDestructorDecl *cxx_dtor_decl(
nullptr);
7758 clang::CXXConstructorDecl *cxx_ctor_decl(
nullptr);
7763 const clang::ExplicitSpecifier explicit_spec(
7764 nullptr , is_explicit ? clang::ExplicitSpecKind::ResolvedTrue
7765 : clang::ExplicitSpecKind::ResolvedFalse);
7767 if (name.starts_with(
"~")) {
7768 cxx_dtor_decl = clang::CXXDestructorDecl::CreateDeserialized(
7770 cxx_dtor_decl->setDeclContext(cxx_record_decl);
7771 cxx_dtor_decl->setDeclName(
7774 cxx_dtor_decl->setType(method_qual_type);
7775 cxx_dtor_decl->setImplicit(is_artificial);
7776 cxx_dtor_decl->setInlineSpecified(is_inline);
7777 cxx_dtor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7778 cxx_method_decl = cxx_dtor_decl;
7779 }
else if (decl_name == cxx_record_decl->getDeclName()) {
7780 cxx_ctor_decl = clang::CXXConstructorDecl::CreateDeserialized(
7782 cxx_ctor_decl->setDeclContext(cxx_record_decl);
7783 cxx_ctor_decl->setDeclName(
7786 cxx_ctor_decl->setType(method_qual_type);
7787 cxx_ctor_decl->setImplicit(is_artificial);
7788 cxx_ctor_decl->setInlineSpecified(is_inline);
7789 cxx_ctor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7790 cxx_ctor_decl->setNumCtorInitializers(0);
7791 cxx_ctor_decl->setExplicitSpecifier(explicit_spec);
7792 cxx_method_decl = cxx_ctor_decl;
7794 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7795 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7798 if (op_kind != clang::NUM_OVERLOADED_OPERATORS) {
7803 const bool is_method =
true;
7805 is_method, op_kind, num_params))
7807 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7809 cxx_method_decl->setDeclContext(cxx_record_decl);
7810 cxx_method_decl->setDeclName(
7811 getASTContext().DeclarationNames.getCXXOperatorName(op_kind));
7812 cxx_method_decl->setType(method_qual_type);
7813 cxx_method_decl->setStorageClass(SC);
7814 cxx_method_decl->setInlineSpecified(is_inline);
7815 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7816 }
else if (num_params == 0) {
7818 auto *cxx_conversion_decl =
7819 clang::CXXConversionDecl::CreateDeserialized(
getASTContext(),
7821 cxx_conversion_decl->setDeclContext(cxx_record_decl);
7822 cxx_conversion_decl->setDeclName(
7823 getASTContext().DeclarationNames.getCXXConversionFunctionName(
7825 function_type->getReturnType())));
7826 cxx_conversion_decl->setType(method_qual_type);
7827 cxx_conversion_decl->setInlineSpecified(is_inline);
7828 cxx_conversion_decl->setExplicitSpecifier(explicit_spec);
7829 cxx_conversion_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7830 cxx_method_decl = cxx_conversion_decl;
7834 if (cxx_method_decl ==
nullptr) {
7835 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7837 cxx_method_decl->setDeclContext(cxx_record_decl);
7838 cxx_method_decl->setDeclName(decl_name);
7839 cxx_method_decl->setType(method_qual_type);
7840 cxx_method_decl->setInlineSpecified(is_inline);
7841 cxx_method_decl->setStorageClass(SC);
7842 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7847 clang::AccessSpecifier access_specifier =
7850 cxx_method_decl->setAccess(access_specifier);
7851 cxx_method_decl->setVirtualAsWritten(is_virtual);
7854 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(
getASTContext()));
7856 if (mangled_name !=
nullptr) {
7857 cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7863 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
7865 for (
unsigned param_index = 0; param_index < num_params; ++param_index) {
7866 params.push_back(clang::ParmVarDecl::Create(
7868 clang::SourceLocation(),
7870 method_function_prototype->getParamType(param_index),
nullptr,
7871 clang::SC_None,
nullptr));
7874 cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params));
7881 cxx_record_decl->addDecl(cxx_method_decl);
7890 if (is_artificial) {
7891 if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() &&
7892 cxx_record_decl->hasTrivialDefaultConstructor()) ||
7893 (cxx_ctor_decl->isCopyConstructor() &&
7894 cxx_record_decl->hasTrivialCopyConstructor()) ||
7895 (cxx_ctor_decl->isMoveConstructor() &&
7896 cxx_record_decl->hasTrivialMoveConstructor()))) {
7897 cxx_ctor_decl->setDefaulted();
7898 cxx_ctor_decl->setTrivial(
true);
7899 }
else if (cxx_dtor_decl) {
7900 if (cxx_record_decl->hasTrivialDestructor()) {
7901 cxx_dtor_decl->setDefaulted();
7902 cxx_dtor_decl->setTrivial(
true);
7904 }
else if ((cxx_method_decl->isCopyAssignmentOperator() &&
7905 cxx_record_decl->hasTrivialCopyAssignment()) ||
7906 (cxx_method_decl->isMoveAssignmentOperator() &&
7907 cxx_record_decl->hasTrivialMoveAssignment())) {
7908 cxx_method_decl->setDefaulted();
7909 cxx_method_decl->setTrivial(
true);
7913 VerifyDecl(cxx_method_decl);
7915 return cxx_method_decl;
7921 for (
auto *method : record->methods())
7922 addOverridesForMethod(method);
7925#pragma mark C++ Base Classes
7927std::unique_ptr<clang::CXXBaseSpecifier>
7930 bool base_of_class) {
7934 return std::make_unique<clang::CXXBaseSpecifier>(
7935 clang::SourceRange(), is_virtual, base_of_class,
7938 clang::SourceLocation());
7943 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) {
7947 if (!cxx_record_decl)
7949 std::vector<clang::CXXBaseSpecifier *> raw_bases;
7950 raw_bases.reserve(bases.size());
7954 for (
auto &b : bases)
7955 raw_bases.push_back(b.get());
7956 cxx_record_decl->setBases(raw_bases.data(), raw_bases.size());
7968 if (type && superclass_clang_type.
IsValid() &&
7970 clang::ObjCInterfaceDecl *class_interface_decl =
7972 clang::ObjCInterfaceDecl *super_interface_decl =
7974 if (class_interface_decl && super_interface_decl) {
7975 class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
7976 clang_ast.getObjCInterfaceType(super_interface_decl)));
7985 const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl,
7986 const char *property_setter_name,
const char *property_getter_name,
7988 if (!type || !property_clang_type.
IsValid() || property_name ==
nullptr ||
7989 property_name[0] ==
'\0')
7998 if (!class_interface_decl)
8003 if (property_clang_type.
IsValid())
8004 property_clang_type_to_access = property_clang_type;
8006 property_clang_type_to_access = ast->GetType(ivar_decl->getType());
8008 if (!class_interface_decl || !property_clang_type_to_access.
IsValid())
8011 clang::TypeSourceInfo *prop_type_source;
8013 prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
8015 prop_type_source = clang_ast.getTrivialTypeSourceInfo(
8018 clang::ObjCPropertyDecl *property_decl =
8019 clang::ObjCPropertyDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8020 property_decl->setDeclContext(class_interface_decl);
8021 property_decl->setDeclName(&clang_ast.Idents.get(property_name));
8022 property_decl->setType(ivar_decl
8023 ? ivar_decl->getType()
8031 ast->SetMetadata(property_decl, metadata);
8033 class_interface_decl->addDecl(property_decl);
8035 clang::Selector setter_sel, getter_sel;
8037 if (property_setter_name) {
8038 std::string property_setter_no_colon(property_setter_name,
8039 strlen(property_setter_name) - 1);
8040 const clang::IdentifierInfo *setter_ident =
8041 &clang_ast.Idents.get(property_setter_no_colon);
8042 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8043 }
else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
8044 std::string setter_sel_string(
"set");
8045 setter_sel_string.push_back(::toupper(property_name[0]));
8046 setter_sel_string.append(&property_name[1]);
8047 const clang::IdentifierInfo *setter_ident =
8048 &clang_ast.Idents.get(setter_sel_string);
8049 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8051 property_decl->setSetterName(setter_sel);
8052 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
8054 if (property_getter_name !=
nullptr) {
8055 const clang::IdentifierInfo *getter_ident =
8056 &clang_ast.Idents.get(property_getter_name);
8057 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8059 const clang::IdentifierInfo *getter_ident =
8060 &clang_ast.Idents.get(property_name);
8061 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8063 property_decl->setGetterName(getter_sel);
8064 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
8067 property_decl->setPropertyIvarDecl(ivar_decl);
8069 if (property_attributes & DW_APPLE_PROPERTY_readonly)
8070 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
8071 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
8072 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
8073 if (property_attributes & DW_APPLE_PROPERTY_assign)
8074 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
8075 if (property_attributes & DW_APPLE_PROPERTY_retain)
8076 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
8077 if (property_attributes & DW_APPLE_PROPERTY_copy)
8078 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
8079 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
8080 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
8081 if (property_attributes & ObjCPropertyAttribute::kind_nullability)
8082 property_decl->setPropertyAttributes(
8083 ObjCPropertyAttribute::kind_nullability);
8084 if (property_attributes & ObjCPropertyAttribute::kind_null_resettable)
8085 property_decl->setPropertyAttributes(
8086 ObjCPropertyAttribute::kind_null_resettable);
8087 if (property_attributes & ObjCPropertyAttribute::kind_class)
8088 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
8090 const bool isInstance =
8091 (property_attributes & ObjCPropertyAttribute::kind_class) == 0;
8093 clang::ObjCMethodDecl *getter =
nullptr;
8094 if (!getter_sel.isNull())
8095 getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8096 : class_interface_decl->lookupClassMethod(getter_sel);
8097 if (!getter_sel.isNull() && !getter) {
8098 const bool isVariadic =
false;
8099 const bool isPropertyAccessor =
true;
8100 const bool isSynthesizedAccessorStub =
false;
8101 const bool isImplicitlyDeclared =
true;
8102 const bool isDefined =
false;
8103 const clang::ObjCImplementationControl impControl =
8104 clang::ObjCImplementationControl::None;
8105 const bool HasRelatedResultType =
false;
8108 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8109 getter->setDeclName(getter_sel);
8111 getter->setDeclContext(class_interface_decl);
8112 getter->setInstanceMethod(isInstance);
8113 getter->setVariadic(isVariadic);
8114 getter->setPropertyAccessor(isPropertyAccessor);
8115 getter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8116 getter->setImplicit(isImplicitlyDeclared);
8117 getter->setDefined(isDefined);
8118 getter->setDeclImplementation(impControl);
8119 getter->setRelatedResultType(HasRelatedResultType);
8123 ast->SetMetadata(getter, metadata);
8125 getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
8126 llvm::ArrayRef<clang::SourceLocation>());
8127 class_interface_decl->addDecl(getter);
8131 getter->setPropertyAccessor(
true);
8132 property_decl->setGetterMethodDecl(getter);
8135 clang::ObjCMethodDecl *setter =
nullptr;
8136 setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8137 : class_interface_decl->lookupClassMethod(setter_sel);
8138 if (!setter_sel.isNull() && !setter) {
8139 clang::QualType result_type = clang_ast.VoidTy;
8140 const bool isVariadic =
false;
8141 const bool isPropertyAccessor =
true;
8142 const bool isSynthesizedAccessorStub =
false;
8143 const bool isImplicitlyDeclared =
true;
8144 const bool isDefined =
false;
8145 const clang::ObjCImplementationControl impControl =
8146 clang::ObjCImplementationControl::None;
8147 const bool HasRelatedResultType =
false;
8150 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8151 setter->setDeclName(setter_sel);
8152 setter->setReturnType(result_type);
8153 setter->setDeclContext(class_interface_decl);
8154 setter->setInstanceMethod(isInstance);
8155 setter->setVariadic(isVariadic);
8156 setter->setPropertyAccessor(isPropertyAccessor);
8157 setter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8158 setter->setImplicit(isImplicitlyDeclared);
8159 setter->setDefined(isDefined);
8160 setter->setDeclImplementation(impControl);
8161 setter->setRelatedResultType(HasRelatedResultType);
8165 ast->SetMetadata(setter, metadata);
8167 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8168 params.push_back(clang::ParmVarDecl::Create(
8169 clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8172 clang::SC_Auto,
nullptr));
8174 setter->setMethodParams(clang_ast,
8175 llvm::ArrayRef<clang::ParmVarDecl *>(params),
8176 llvm::ArrayRef<clang::SourceLocation>());
8178 class_interface_decl->addDecl(setter);
8182 setter->setPropertyAccessor(
true);
8183 property_decl->setSetterMethodDecl(setter);
8190 bool check_superclass) {
8192 if (class_interface_decl)
8202 const CompilerType &method_clang_type,
bool is_artificial,
bool is_variadic,
8203 bool is_objc_direct_call) {
8204 if (!type || !method_clang_type.
IsValid())
8209 if (class_interface_decl ==
nullptr)
8213 if (lldb_ast ==
nullptr)
8217 const char *selector_start = ::strchr(name,
' ');
8218 if (selector_start ==
nullptr)
8222 llvm::SmallVector<const clang::IdentifierInfo *, 12> selector_idents;
8227 unsigned num_selectors_with_args = 0;
8228 for (start = selector_start; start && *start !=
'\0' && *start !=
']';
8230 len = ::strcspn(start,
":]");
8231 bool has_arg = (start[len] ==
':');
8233 ++num_selectors_with_args;
8234 selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
8239 if (selector_idents.size() == 0)
8242 clang::Selector method_selector = ast.Selectors.getSelector(
8243 num_selectors_with_args ? selector_idents.size() : 0,
8244 selector_idents.data());
8249 const clang::Type *method_type(method_qual_type.getTypePtr());
8251 if (method_type ==
nullptr)
8254 const clang::FunctionProtoType *method_function_prototype(
8255 llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8257 if (!method_function_prototype)
8260 const bool isInstance = (name[0] ==
'-');
8261 const bool isVariadic = is_variadic;
8262 const bool isPropertyAccessor =
false;
8263 const bool isSynthesizedAccessorStub =
false;
8265 const bool isImplicitlyDeclared =
true;
8266 const bool isDefined =
false;
8267 const clang::ObjCImplementationControl impControl =
8268 clang::ObjCImplementationControl::None;
8269 const bool HasRelatedResultType =
false;
8271 const unsigned num_args = method_function_prototype->getNumParams();
8273 if (num_args != num_selectors_with_args)
8277 auto *objc_method_decl =
8278 clang::ObjCMethodDecl::CreateDeserialized(ast, GlobalDeclID());
8279 objc_method_decl->setDeclName(method_selector);
8280 objc_method_decl->setReturnType(method_function_prototype->getReturnType());
8281 objc_method_decl->setDeclContext(
8283 objc_method_decl->setInstanceMethod(isInstance);
8284 objc_method_decl->setVariadic(isVariadic);
8285 objc_method_decl->setPropertyAccessor(isPropertyAccessor);
8286 objc_method_decl->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8287 objc_method_decl->setImplicit(isImplicitlyDeclared);
8288 objc_method_decl->setDefined(isDefined);
8289 objc_method_decl->setDeclImplementation(impControl);
8290 objc_method_decl->setRelatedResultType(HasRelatedResultType);
8293 if (objc_method_decl ==
nullptr)
8297 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8299 for (
unsigned param_index = 0; param_index < num_args; ++param_index) {
8300 params.push_back(clang::ParmVarDecl::Create(
8301 ast, objc_method_decl, clang::SourceLocation(),
8302 clang::SourceLocation(),
8304 method_function_prototype->getParamType(param_index),
nullptr,
8305 clang::SC_Auto,
nullptr));
8308 objc_method_decl->setMethodParams(
8309 ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
8310 llvm::ArrayRef<clang::SourceLocation>());
8313 if (is_objc_direct_call) {
8316 objc_method_decl->addAttr(
8317 clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
8322 objc_method_decl->createImplicitParams(ast, class_interface_decl);
8325 class_interface_decl->addDecl(objc_method_decl);
8327 VerifyDecl(objc_method_decl);
8329 return objc_method_decl;
8339 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8340 switch (type_class) {
8341 case clang::Type::Record: {
8342 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8343 if (cxx_record_decl) {
8344 cxx_record_decl->setHasExternalLexicalStorage(has_extern);
8345 cxx_record_decl->setHasExternalVisibleStorage(has_extern);
8350 case clang::Type::Enum: {
8351 clang::EnumDecl *enum_decl =
8352 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8354 enum_decl->setHasExternalLexicalStorage(has_extern);
8355 enum_decl->setHasExternalVisibleStorage(has_extern);
8360 case clang::Type::ObjCObject:
8361 case clang::Type::ObjCInterface: {
8362 const clang::ObjCObjectType *objc_class_type =
8363 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8364 assert(objc_class_type);
8365 if (objc_class_type) {
8366 clang::ObjCInterfaceDecl *class_interface_decl =
8367 objc_class_type->getInterface();
8369 if (class_interface_decl) {
8370 class_interface_decl->setHasExternalLexicalStorage(has_extern);
8371 class_interface_decl->setHasExternalVisibleStorage(has_extern);
8387 if (!qual_type.isNull()) {
8388 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8390 clang::TagDecl *tag_decl = tag_type->getDecl();
8392 tag_decl->startDefinition();
8397 const clang::ObjCObjectType *object_type =
8398 qual_type->getAs<clang::ObjCObjectType>();
8400 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8401 if (interface_decl) {
8402 interface_decl->startDefinition();
8413 if (qual_type.isNull())
8418 if (lldb_ast ==
nullptr)
8424 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8426 clang::TagDecl *tag_decl = tag_type->getDecl();
8428 if (
auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
8438 if (cxx_record_decl->hasUserDeclaredMoveConstructor() ||
8439 cxx_record_decl->hasUserDeclaredMoveAssignment()) {
8440 if (cxx_record_decl->needsImplicitCopyConstructor())
8441 cxx_record_decl->setImplicitCopyConstructorIsDeleted();
8442 if (cxx_record_decl->needsImplicitCopyAssignment())
8443 cxx_record_decl->setImplicitCopyAssignmentIsDeleted();
8446 if (!cxx_record_decl->isCompleteDefinition())
8447 cxx_record_decl->completeDefinition();
8448 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
8449 cxx_record_decl->setHasExternalLexicalStorage(
false);
8450 cxx_record_decl->setHasExternalVisibleStorage(
false);
8452 clang::AccessSpecifier::AS_none);
8457 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8461 clang::EnumDecl *enum_decl = enutype->getDecl();
8463 if (enum_decl->isCompleteDefinition())
8466 clang::ASTContext &ast = lldb_ast->getASTContext();
8470 QualType integer_type(enum_decl->getIntegerType());
8471 if (!integer_type.isNull()) {
8472 unsigned NumPositiveBits = 1;
8473 unsigned NumNegativeBits = 0;
8475 clang::QualType promotion_qual_type;
8478 if (ast.getTypeSize(enum_decl->getIntegerType()) <
8479 ast.getTypeSize(ast.IntTy)) {
8480 if (enum_decl->getIntegerType()->isSignedIntegerType())
8481 promotion_qual_type = ast.IntTy;
8483 promotion_qual_type = ast.UnsignedIntTy;
8485 promotion_qual_type = enum_decl->getIntegerType();
8487 enum_decl->completeDefinition(enum_decl->getIntegerType(),
8488 promotion_qual_type, NumPositiveBits,
8496 const llvm::APSInt &value) {
8507 if (!enum_opaque_compiler_type)
8510 clang::QualType enum_qual_type(
8513 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8518 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8523 clang::EnumConstantDecl *enumerator_decl =
8524 clang::EnumConstantDecl::CreateDeserialized(
getASTContext(),
8526 enumerator_decl->setDeclContext(enutype->getDecl());
8527 if (name && name[0])
8528 enumerator_decl->setDeclName(&
getASTContext().Idents.get(name));
8529 enumerator_decl->setType(clang::QualType(enutype, 0));
8533 if (!enumerator_decl)
8536 enutype->getDecl()->addDecl(enumerator_decl);
8538 VerifyDecl(enumerator_decl);
8539 return enumerator_decl;
8544 int64_t enum_value, uint32_t enum_value_bit_size) {
8546 bool is_signed =
false;
8549 llvm::APSInt value(enum_value_bit_size, is_signed);
8557 const clang::Type *clang_type = qt.getTypePtrOrNull();
8558 const auto *enum_type = llvm::dyn_cast_or_null<clang::EnumType>(clang_type);
8562 return GetType(enum_type->getDecl()->getIntegerType());
8568 if (type && pointee_type.
IsValid() &&
8574 return ast->GetType(ast->getASTContext().getMemberPointerType(
8582#define DEPTH_INCREMENT 2
8585LLVM_DUMP_METHOD
void
8599 llvm::StringRef symbol_name) {
8606 symfile->
GetTypes(
nullptr, eTypeClassAny, type_list);
8607 size_t ntypes = type_list.
GetSize();
8609 for (
size_t i = 0; i < ntypes; ++i) {
8612 if (!symbol_name.empty())
8613 if (symbol_name != type->GetName().GetStringRef())
8616 s << type->GetName().AsCString() <<
"\n";
8619 if (clang::TagDecl *tag_decl =
GetAsTagDecl(full_type)) {
8627 if (
auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8629 if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8641 size_t byte_size, uint32_t bitfield_bit_offset,
8642 uint32_t bitfield_bit_size) {
8643 const clang::EnumType *enutype =
8644 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8645 const clang::EnumDecl *enum_decl = enutype->getDecl();
8648 bool qual_type_is_signed = qual_type->isSignedIntegerOrEnumerationType();
8649 const uint64_t enum_svalue =
8652 bitfield_bit_offset)
8654 bitfield_bit_offset);
8655 bool can_be_bitfield =
true;
8656 uint64_t covered_bits = 0;
8657 int num_enumerators = 0;
8665 clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
8666 if (enumerators.empty())
8667 can_be_bitfield =
false;
8669 for (
auto *enumerator : enumerators) {
8670 llvm::APSInt init_val = enumerator->getInitVal();
8671 uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
8672 : init_val.getZExtValue();
8673 if (qual_type_is_signed)
8674 val = llvm::SignExtend64(val, 8 * byte_size);
8675 if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8676 can_be_bitfield =
false;
8677 covered_bits |= val;
8679 if (val == enum_svalue) {
8688 offset = byte_offset;
8690 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8694 if (!can_be_bitfield) {
8695 if (qual_type_is_signed)
8696 s.
Printf(
"%" PRIi64, enum_svalue);
8698 s.
Printf(
"%" PRIu64, enum_uvalue);
8705 s.
Printf(
"0x%" PRIx64, enum_uvalue);
8709 uint64_t remaining_value = enum_uvalue;
8710 std::vector<std::pair<uint64_t, llvm::StringRef>> values;
8711 values.reserve(num_enumerators);
8712 for (
auto *enumerator : enum_decl->enumerators())
8713 if (
auto val = enumerator->getInitVal().getZExtValue())
8714 values.emplace_back(val, enumerator->getName());
8719 std::stable_sort(values.begin(), values.end(),
8720 [](
const auto &a,
const auto &b) {
8721 return llvm::popcount(a.first) > llvm::popcount(b.first);
8724 for (
const auto &val : values) {
8725 if ((remaining_value & val.first) != val.first)
8727 remaining_value &= ~val.first;
8729 if (remaining_value)
8735 if (remaining_value)
8736 s.
Printf(
"0x%" PRIx64, remaining_value);
8744 size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
8753 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8755 if (type_class == clang::Type::Elaborated) {
8756 qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
8757 return DumpTypeValue(qual_type.getAsOpaquePtr(), s, format, data, byte_offset, byte_size,
8758 bitfield_bit_size, bitfield_bit_offset, exe_scope);
8761 switch (type_class) {
8762 case clang::Type::Typedef: {
8763 clang::QualType typedef_qual_type =
8764 llvm::cast<clang::TypedefType>(qual_type)
8766 ->getUnderlyingType();
8769 format = typedef_clang_type.
GetFormat();
8770 clang::TypeInfo typedef_type_info =
8772 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
8782 bitfield_bit_offset,
8787 case clang::Type::Enum:
8792 return DumpEnumValue(qual_type, s, data, byte_offset, byte_size,
8793 bitfield_bit_offset, bitfield_bit_size);
8801 uint32_t item_count = 1;
8840 item_count = byte_size;
8845 item_count = byte_size / 2;
8850 item_count = byte_size / 4;
8856 bitfield_bit_size, bitfield_bit_offset,
8872 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(clang_type)) {
8881 clang::QualType qual_type =
8884 llvm::SmallVector<char, 1024> buf;
8885 llvm::raw_svector_ostream llvm_ostrm(buf);
8887 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8888 switch (type_class) {
8889 case clang::Type::ObjCObject:
8890 case clang::Type::ObjCInterface: {
8893 auto *objc_class_type =
8894 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8895 assert(objc_class_type);
8896 if (!objc_class_type)
8898 clang::ObjCInterfaceDecl *class_interface_decl =
8899 objc_class_type->getInterface();
8900 if (!class_interface_decl)
8903 class_interface_decl->dump(llvm_ostrm);
8905 class_interface_decl->print(llvm_ostrm,
8910 case clang::Type::Typedef: {
8911 auto *typedef_type = qual_type->getAs<clang::TypedefType>();
8914 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8916 typedef_decl->dump(llvm_ostrm);
8919 if (!clang_typedef_name.empty()) {
8926 case clang::Type::Record: {
8929 auto *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8930 const clang::RecordDecl *record_decl = record_type->getDecl();
8932 record_decl->dump(llvm_ostrm);
8934 record_decl->print(llvm_ostrm,
getASTContext().getPrintingPolicy(),
8940 if (
auto *tag_type =
8941 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) {
8942 if (clang::TagDecl *tag_decl = tag_type->getDecl()) {
8944 tag_decl->dump(llvm_ostrm);
8946 tag_decl->print(llvm_ostrm, 0);
8952 std::string clang_type_name(qual_type.getAsString());
8953 if (!clang_type_name.empty())
8960 if (buf.size() > 0) {
8961 s.
Write(buf.data(), buf.size());
8968 clang::QualType qual_type(
8971 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8972 switch (type_class) {
8973 case clang::Type::Record: {
8974 const clang::CXXRecordDecl *cxx_record_decl =
8975 qual_type->getAsCXXRecordDecl();
8976 if (cxx_record_decl)
8977 printf(
"class %s", cxx_record_decl->getName().str().c_str());
8980 case clang::Type::Enum: {
8981 clang::EnumDecl *enum_decl =
8982 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8984 printf(
"enum %s", enum_decl->getName().str().c_str());
8988 case clang::Type::ObjCObject:
8989 case clang::Type::ObjCInterface: {
8990 const clang::ObjCObjectType *objc_class_type =
8991 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
8992 if (objc_class_type) {
8993 clang::ObjCInterfaceDecl *class_interface_decl =
8994 objc_class_type->getInterface();
8998 if (class_interface_decl)
8999 printf(
"@class %s", class_interface_decl->getName().str().c_str());
9003 case clang::Type::Typedef:
9004 printf(
"typedef %s", llvm::cast<clang::TypedefType>(qual_type)
9011 case clang::Type::Auto:
9014 llvm::cast<clang::AutoType>(qual_type)
9016 .getAsOpaquePtr()));
9018 case clang::Type::Elaborated:
9019 printf(
"elaborated ");
9021 type.
GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)
9023 .getAsOpaquePtr()));
9025 case clang::Type::Paren:
9029 llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
9032 printf(
"TypeSystemClang::DumpTypeName() type_class = %u", type_class);
9042 if (template_param_infos.
IsValid()) {
9043 std::string template_basename(parent_name);
9045 if (
auto i = template_basename.find(
'<'); i != std::string::npos)
9046 template_basename.erase(i);
9049 template_basename.c_str(), tag_decl_kind,
9050 template_param_infos);
9065 clang::ObjCInterfaceDecl *decl) {
9093 const clang::RecordDecl *record_decl, uint64_t &bit_size,
9094 uint64_t &alignment,
9095 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
9096 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9098 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9111 field_offsets, base_offsets, vbase_offsets);
9118 clang::NamedDecl *nd =
9119 llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl);
9121 return ConstString(nd->getDeclName().getAsString());
9128 clang::NamedDecl *nd =
9129 llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl);
9130 if (nd !=
nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) {
9132 if (mc && mc->shouldMangleCXXName(nd)) {
9133 llvm::SmallVector<char, 1024> buf;
9134 llvm::raw_svector_ostream llvm_ostrm(buf);
9135 if (llvm::isa<clang::CXXConstructorDecl>(nd)) {
9137 clang::GlobalDecl(llvm::dyn_cast<clang::CXXConstructorDecl>(nd),
9140 }
else if (llvm::isa<clang::CXXDestructorDecl>(nd)) {
9142 clang::GlobalDecl(llvm::dyn_cast<clang::CXXDestructorDecl>(nd),
9146 mc->mangleName(nd, llvm_ostrm);
9163 if (clang::FunctionDecl *func_decl =
9164 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9165 return GetType(func_decl->getReturnType());
9166 if (clang::ObjCMethodDecl *objc_method =
9167 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9168 return GetType(objc_method->getReturnType());
9174 if (clang::FunctionDecl *func_decl =
9175 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9176 return func_decl->param_size();
9177 if (clang::ObjCMethodDecl *objc_method =
9178 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9179 return objc_method->param_size();
9185 clang::DeclContext
const *decl_ctx) {
9186 switch (clang_kind) {
9187 case Decl::TranslationUnit:
9189 case Decl::Namespace:
9200 if (decl_ctx->isFunctionOrMethod())
9202 if (decl_ctx->isRecord())
9212 std::vector<lldb_private::CompilerContext> &context) {
9213 if (decl_ctx ==
nullptr)
9216 clang::Decl::Kind clang_kind = decl_ctx->getDeclKind();
9217 if (clang_kind == Decl::TranslationUnit)
9222 context.push_back({compiler_kind, decl_ctx_name});
9225std::vector<lldb_private::CompilerContext>
9227 std::vector<lldb_private::CompilerContext> context;
9230 clang::Decl *decl = (clang::Decl *)opaque_decl;
9232 clang::DeclContext *decl_ctx = decl->getDeclContext();
9235 auto compiler_kind =
9237 context.push_back({compiler_kind, decl_name});
9244 if (clang::FunctionDecl *func_decl =
9245 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) {
9246 if (idx < func_decl->param_size()) {
9247 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9249 return GetType(var_decl->getOriginalType());
9251 }
else if (clang::ObjCMethodDecl *objc_method =
9252 llvm::dyn_cast<clang::ObjCMethodDecl>(
9253 (clang::Decl *)opaque_decl)) {
9254 if (idx < objc_method->param_size())
9255 return GetType(objc_method->parameters()[idx]->getOriginalType());
9261 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
9262 clang::VarDecl *var_decl = llvm::dyn_cast<clang::VarDecl>(decl);
9265 clang::Expr *init_expr = var_decl->getInit();
9268 std::optional<llvm::APSInt> value =
9278 void *opaque_decl_ctx,
ConstString name,
const bool ignore_using_decls) {
9279 std::vector<CompilerDecl> found_decls;
9281 if (opaque_decl_ctx && symbol_file) {
9282 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9283 std::set<DeclContext *> searched;
9284 std::multimap<DeclContext *, DeclContext *> search_queue;
9286 for (clang::DeclContext *decl_context = root_decl_ctx;
9287 decl_context !=
nullptr && found_decls.empty();
9288 decl_context = decl_context->getParent()) {
9289 search_queue.insert(std::make_pair(decl_context, decl_context));
9291 for (
auto it = search_queue.find(decl_context); it != search_queue.end();
9293 if (!searched.insert(it->second).second)
9298 for (clang::Decl *child : it->second->decls()) {
9299 if (clang::UsingDirectiveDecl *ud =
9300 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9301 if (ignore_using_decls)
9303 clang::DeclContext *from = ud->getCommonAncestor();
9304 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9305 search_queue.insert(
9306 std::make_pair(from, ud->getNominatedNamespace()));
9307 }
else if (clang::UsingDecl *ud =
9308 llvm::dyn_cast<clang::UsingDecl>(child)) {
9309 if (ignore_using_decls)
9311 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9312 clang::Decl *target = usd->getTargetDecl();
9313 if (clang::NamedDecl *nd =
9314 llvm::dyn_cast<clang::NamedDecl>(target)) {
9315 IdentifierInfo *ii = nd->getIdentifier();
9316 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9320 }
else if (clang::NamedDecl *nd =
9321 llvm::dyn_cast<clang::NamedDecl>(child)) {
9322 IdentifierInfo *ii = nd->getIdentifier();
9323 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9374 clang::DeclContext *child_decl_ctx,
9378 if (frame_decl_ctx && symbol_file) {
9379 std::set<DeclContext *> searched;
9380 std::multimap<DeclContext *, DeclContext *> search_queue;
9383 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9387 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx !=
nullptr;
9388 decl_ctx = decl_ctx->getParent()) {
9389 if (!decl_ctx->isLookupContext())
9391 if (decl_ctx == parent_decl_ctx)
9394 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9395 for (
auto it = search_queue.find(decl_ctx); it != search_queue.end();
9397 if (searched.find(it->second) != searched.end())
9405 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9408 searched.insert(it->second);
9412 for (clang::Decl *child : it->second->decls()) {
9413 if (clang::UsingDirectiveDecl *ud =
9414 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9415 clang::DeclContext *ns = ud->getNominatedNamespace();
9416 if (ns == parent_decl_ctx)
9419 clang::DeclContext *from = ud->getCommonAncestor();
9420 if (searched.find(ns) == searched.end())
9421 search_queue.insert(std::make_pair(from, ns));
9422 }
else if (child_name) {
9423 if (clang::UsingDecl *ud =
9424 llvm::dyn_cast<clang::UsingDecl>(child)) {
9425 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9426 clang::Decl *target = usd->getTargetDecl();
9427 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9431 IdentifierInfo *ii = nd->getIdentifier();
9432 if (ii ==
nullptr ||
9433 ii->getName() != child_name->
AsCString(
nullptr))
9456 if (opaque_decl_ctx) {
9457 clang::NamedDecl *named_decl =
9458 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9461 llvm::raw_string_ostream stream{name};
9463 policy.AlwaysIncludeTypeForTemplateArgument =
true;
9464 named_decl->getNameForDiagnostic(stream, policy,
false);
9473 if (opaque_decl_ctx) {
9474 clang::NamedDecl *named_decl =
9475 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9483 if (!opaque_decl_ctx)
9486 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9487 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9489 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9491 }
else if (clang::FunctionDecl *fun_decl =
9492 llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9493 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9494 return metadata->HasObjectPtr();
9500std::vector<lldb_private::CompilerContext>
9502 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9503 std::vector<lldb_private::CompilerContext> context;
9509 void *opaque_decl_ctx,
void *other_opaque_decl_ctx) {
9510 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9511 auto *other = (clang::DeclContext *)other_opaque_decl_ctx;
9515 auto is_transparent_lookup_allowed = [](clang::DeclContext *DC) {
9516 if (DC->isInlineNamespace())
9519 if (
auto const *NS = dyn_cast<NamespaceDecl>(DC))
9520 return NS->isAnonymousNamespace();
9527 if (decl_ctx == other)
9529 }
while (is_transparent_lookup_allowed(other) &&
9530 (other = other->getParent()));
9537 if (!opaque_decl_ctx)
9540 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9541 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9543 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9545 }
else if (
auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9546 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9547 return metadata->GetObjectPtrLanguage();
9567 return llvm::dyn_cast<clang::ObjCMethodDecl>(
9575 return llvm::dyn_cast<clang::CXXMethodDecl>(
9580clang::FunctionDecl *
9583 return llvm::dyn_cast<clang::FunctionDecl>(
9588clang::NamespaceDecl *
9591 return llvm::dyn_cast<clang::NamespaceDecl>(
9596std::optional<ClangASTMetadata>
9598 const Decl *
object) {
9606 llvm::dyn_cast_or_null<TypeSystemClang>(dc.
GetTypeSystem());
9628 lldbassert(started &&
"Unable to start a class type definition.");
9647 SpecializedScratchAST(llvm::StringRef name, llvm::Triple triple,
9648 std::unique_ptr<ClangASTSource> ast_source)
9650 m_scratch_ast_source_up(std::move(ast_source)) {
9652 m_scratch_ast_source_up->InstallASTContext(*
this);
9653 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9654 m_scratch_ast_source_up->CreateProxy());
9655 SetExternalSource(proxy_ast_source);
9659 std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
9667 llvm::Triple triple)
9669 m_target_wp(target.shared_from_this()),
9670 m_persistent_variables(
9674 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9686 std::optional<IsolatedASTKind> ast_kind,
9687 bool create_on_demand) {
9690 if (
auto err = type_system_or_err.takeError()) {
9692 "Couldn't get scratch TypeSystemClang");
9695 auto ts_sp = *type_system_or_err;
9697 llvm::dyn_cast_or_null<ScratchTypeSystemClang>(ts_sp.get());
9702 return std::static_pointer_cast<TypeSystemClang>(ts_sp);
9704 return std::static_pointer_cast<TypeSystemClang>(
9709static llvm::StringRef
9713 return "C++ modules";
9715 llvm_unreachable(
"Unimplemented IsolatedASTKind?");
9720 output <<
"State of scratch Clang type system:\n";
9724 typedef std::pair<IsolatedASTKey, TypeSystem *> KeyAndTS;
9725 std::vector<KeyAndTS> sorted_typesystems;
9727 sorted_typesystems.emplace_back(a.first, a.second.get());
9728 llvm::stable_sort(sorted_typesystems, llvm::less_first());
9731 for (
const auto &a : sorted_typesystems) {
9734 output <<
"State of scratch Clang type subsystem "
9736 a.second->Dump(output);
9741 llvm::StringRef expr, llvm::StringRef prefix,
SourceLanguage language,
9749 desired_type, options, ctx_obj);
9754 const ValueList &arg_value_list,
const char *name) {
9759 Process *process = target_sp->GetProcessSP().get();
9764 arg_value_list, name);
9767std::unique_ptr<UtilityFunction>
9774 return std::make_unique<ClangUtilityFunction>(
9775 *target_sp.get(), std::move(text), std::move(name),
9776 target_sp->GetDebugUtilityExpression());
9790 importer.
ForgetSource(&a.second->getASTContext(), src_ctx);
9794 return std::make_unique<ClangASTSource>(
9799static llvm::StringRef
9803 return "scratch ASTContext for C++ module types";
9805 llvm_unreachable(
"Unimplemented ASTFeature kind?");
9812 return *found_ast->second;
9815 std::shared_ptr<TypeSystemClang> new_ast_sp =
9825 const clang::RecordType *record_type =
9826 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
9828 const clang::RecordDecl *record_decl = record_type->getDecl();
9829 assert(record_decl);
9830 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(record_decl))
9831 return metadata->IsForcefullyCompleted();
9840 std::optional<ClangASTMetadata> metadata =
GetMetadata(td);
9844 metadata->SetIsForcefullyCompleted();
9852 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.
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 *)
std::string PrintTemplateParams(const TemplateParameterInfos &template_param_infos)
Return the template parameters (including surrounding <>) in string form.
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.