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,
1226 if (decl_ctx ==
nullptr)
1227 decl_ctx = ast.getTranslationUnitDecl();
1231 bool isForwardDecl =
true;
1232 bool isInternal =
false;
1234 isInternal, metadata);
1243 bool has_name = !name.empty();
1244 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1245 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1246 decl->setDeclContext(decl_ctx);
1248 decl->setDeclName(&ast.Idents.get(name));
1276 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1277 decl->setAnonymousStructOrUnion(
true);
1287 decl_ctx->addDecl(decl);
1289 return GetType(ast.getTagDeclType(decl));
1295bool IsValueParam(
const clang::TemplateArgument &argument) {
1296 return argument.getKind() == TemplateArgument::Integral;
1299void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1301 clang::AccessSpecifier previous_access,
1302 clang::AccessSpecifier access_specifier) {
1303 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1305 if (previous_access != access_specifier) {
1308 if ((cxx_record_decl->isStruct() &&
1309 previous_access == clang::AccessSpecifier::AS_none &&
1310 access_specifier == clang::AccessSpecifier::AS_public) ||
1311 (cxx_record_decl->isClass() &&
1312 previous_access == clang::AccessSpecifier::AS_none &&
1313 access_specifier == clang::AccessSpecifier::AS_private)) {
1316 cxx_record_decl->addDecl(
1317 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1318 SourceLocation(), SourceLocation()));
1326 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1327 const bool parameter_pack =
false;
1328 const bool is_typename =
false;
1329 const unsigned depth = 0;
1330 const size_t num_template_params = template_param_infos.
Size();
1331 DeclContext *
const decl_context =
1332 ast.getTranslationUnitDecl();
1334 auto const &args = template_param_infos.
GetArgs();
1335 auto const &names = template_param_infos.
GetNames();
1336 for (
size_t i = 0; i < num_template_params; ++i) {
1337 const char *name = names[i];
1339 IdentifierInfo *identifier_info =
nullptr;
1340 if (name && name[0])
1341 identifier_info = &ast.Idents.get(name);
1342 TemplateArgument
const &targ = args[i];
1343 if (IsValueParam(targ)) {
1344 QualType template_param_type = targ.getIntegralType();
1345 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1346 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1347 identifier_info, template_param_type, parameter_pack,
1348 ast.getTrivialTypeSourceInfo(template_param_type)));
1350 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1351 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1352 identifier_info, is_typename, parameter_pack));
1357 IdentifierInfo *identifier_info =
nullptr;
1359 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1360 const bool parameter_pack_true =
true;
1364 QualType template_param_type =
1366 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1367 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1368 num_template_params, identifier_info, template_param_type,
1369 parameter_pack_true,
1370 ast.getTrivialTypeSourceInfo(template_param_type)));
1372 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1373 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1374 num_template_params, identifier_info, is_typename,
1375 parameter_pack_true));
1378 clang::Expr *
const requires_clause =
nullptr;
1379 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1380 ast, SourceLocation(), SourceLocation(), template_param_decls,
1381 SourceLocation(), requires_clause);
1382 return template_param_list;
1387 llvm::SmallVector<NamedDecl *, 8> ignore;
1388 clang::TemplateParameterList *template_param_list =
1391 llvm::SmallVector<clang::TemplateArgument, 2> args(
1392 template_param_infos.
GetArgs());
1394 llvm::ArrayRef<TemplateArgument> pack_args =
1396 args.append(pack_args.begin(), pack_args.end());
1399 llvm::raw_string_ostream os(str);
1401 template_param_list);
1407 clang::FunctionDecl *func_decl,
1412 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1414 ast, template_param_infos, template_param_decls);
1415 FunctionTemplateDecl *func_tmpl_decl =
1416 FunctionTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1417 func_tmpl_decl->setDeclContext(decl_ctx);
1418 func_tmpl_decl->setLocation(func_decl->getLocation());
1419 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1420 func_tmpl_decl->setTemplateParameters(template_param_list);
1421 func_tmpl_decl->init(func_decl);
1424 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1425 i < template_param_decl_count; ++i) {
1427 template_param_decls[i]->setDeclContext(func_decl);
1432 if (decl_ctx->isRecord())
1433 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1435 return func_tmpl_decl;
1439 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1441 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1442 func_decl->getASTContext(), infos.
GetArgs());
1444 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1445 template_args_ptr,
nullptr);
1452 const TemplateArgument &value) {
1453 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1455 if (value.getKind() != TemplateArgument::Type)
1457 }
else if (
auto *type_param =
1458 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1460 if (!IsValueParam(value))
1463 if (type_param->getType() != value.getIntegralType())
1471 "Don't know how to compare template parameter to passed"
1472 " value. Decl kind of parameter is: {0}",
1473 param->getDeclKindName());
1474 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1489 ClassTemplateDecl *class_template_decl,
1492 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1498 std::optional<NamedDecl *> pack_parameter;
1500 size_t non_pack_params = params.size();
1501 for (
size_t i = 0; i < params.size(); ++i) {
1502 NamedDecl *param = params.getParam(i);
1503 if (param->isParameterPack()) {
1504 pack_parameter = param;
1505 non_pack_params = i;
1513 if (non_pack_params != instantiation_values.
Size())
1531 for (
const auto pair :
1532 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1533 const TemplateArgument &passed_arg = std::get<0>(pair);
1534 NamedDecl *found_param = std::get<1>(pair);
1539 return class_template_decl;
1548 ClassTemplateDecl *class_template_decl =
nullptr;
1549 if (decl_ctx ==
nullptr)
1550 decl_ctx = ast.getTranslationUnitDecl();
1552 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1553 DeclarationName decl_name(&identifier_info);
1556 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1557 for (NamedDecl *decl : result) {
1558 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1559 if (!class_template_decl)
1568 template_param_infos))
1570 return class_template_decl;
1573 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1576 ast, template_param_infos, template_param_decls);
1578 CXXRecordDecl *template_cxx_decl =
1579 CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1580 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1582 template_cxx_decl->setDeclContext(decl_ctx);
1583 template_cxx_decl->setDeclName(decl_name);
1586 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1587 i < template_param_decl_count; ++i) {
1588 template_param_decls[i]->setDeclContext(template_cxx_decl);
1596 class_template_decl =
1597 ClassTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1599 class_template_decl->setDeclContext(decl_ctx);
1600 class_template_decl->setDeclName(decl_name);
1601 class_template_decl->setTemplateParameters(template_param_list);
1602 class_template_decl->init(template_cxx_decl);
1603 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1607 class_template_decl->setAccess(
1610 decl_ctx->addDecl(class_template_decl);
1612 VerifyDecl(class_template_decl);
1614 return class_template_decl;
1617TemplateTemplateParmDecl *
1621 auto *decl_ctx = ast.getTranslationUnitDecl();
1623 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1624 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1628 ast, template_param_infos, template_param_decls);
1634 return TemplateTemplateParmDecl::Create(ast, decl_ctx, SourceLocation(),
1637 &identifier_info,
false,
1638 template_param_list);
1641ClassTemplateSpecializationDecl *
1644 ClassTemplateDecl *class_template_decl,
int kind,
1647 llvm::SmallVector<clang::TemplateArgument, 2> args(
1648 template_param_infos.
Size() +
1651 auto const &orig_args = template_param_infos.
GetArgs();
1652 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1654 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1657 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1658 ClassTemplateSpecializationDecl::CreateDeserialized(ast, GlobalDeclID());
1659 class_template_specialization_decl->setTagKind(
1660 static_cast<TagDecl::TagKind
>(kind));
1661 class_template_specialization_decl->setDeclContext(decl_ctx);
1662 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1663 class_template_specialization_decl->setTemplateArgs(
1664 TemplateArgumentList::CreateCopy(ast, args));
1665 ast.getTypeDeclType(class_template_specialization_decl,
nullptr);
1666 class_template_specialization_decl->setDeclName(
1667 class_template_decl->getDeclName());
1669 decl_ctx->addDecl(class_template_specialization_decl);
1671 class_template_specialization_decl->setSpecializationKind(
1672 TSK_ExplicitSpecialization);
1674 return class_template_specialization_decl;
1678 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1679 if (class_template_specialization_decl) {
1681 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1687 clang::OverloadedOperatorKind op_kind,
1688 bool unary,
bool binary,
1689 uint32_t num_params) {
1691 if (op_kind == OO_Call)
1697 if (num_params == 1)
1699 if (num_params == 2)
1706 bool is_method, clang::OverloadedOperatorKind op_kind,
1707 uint32_t num_params) {
1715 case OO_Array_Delete:
1719#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1721 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1723#include "clang/Basic/OperatorKinds.def"
1730clang::AccessSpecifier
1732 clang::AccessSpecifier rhs) {
1735 if (lhs == AS_none || rhs == AS_none)
1737 if (lhs == AS_private || rhs == AS_private)
1739 if (lhs == AS_protected || rhs == AS_protected)
1740 return AS_protected;
1745 uint32_t &bitfield_bit_size) {
1747 if (field ==
nullptr)
1750 if (field->isBitField()) {
1751 Expr *bit_width_expr = field->getBitWidth();
1752 if (bit_width_expr) {
1753 if (std::optional<llvm::APSInt> bit_width_apsint =
1754 bit_width_expr->getIntegerConstantExpr(ast)) {
1755 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1764 if (record_decl ==
nullptr)
1767 if (!record_decl->field_empty())
1771 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1772 if (cxx_record_decl) {
1773 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1774 for (base_class = cxx_record_decl->bases_begin(),
1775 base_class_end = cxx_record_decl->bases_end();
1776 base_class != base_class_end; ++base_class) {
1777 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1778 base_class->getType()->getAs<RecordType>()->getDecl());
1797#pragma mark Objective-C Classes
1800 llvm::StringRef name, clang::DeclContext *decl_ctx,
1804 assert(!name.empty());
1806 decl_ctx = ast.getTranslationUnitDecl();
1808 ObjCInterfaceDecl *decl =
1809 ObjCInterfaceDecl::CreateDeserialized(ast, GlobalDeclID());
1810 decl->setDeclContext(decl_ctx);
1811 decl->setDeclName(&ast.Idents.get(name));
1813 decl->setImplicit(isInternal);
1819 return GetType(ast.getObjCInterfaceType(decl));
1828 bool omit_empty_base_classes) {
1829 uint32_t num_bases = 0;
1830 if (cxx_record_decl) {
1831 if (omit_empty_base_classes) {
1832 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1833 for (base_class = cxx_record_decl->bases_begin(),
1834 base_class_end = cxx_record_decl->bases_end();
1835 base_class != base_class_end; ++base_class) {
1842 num_bases = cxx_record_decl->getNumBases();
1847#pragma mark Namespace Declarations
1850 const char *name, clang::DeclContext *decl_ctx,
1852 NamespaceDecl *namespace_decl =
nullptr;
1854 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1856 decl_ctx = translation_unit_decl;
1859 IdentifierInfo &identifier_info = ast.Idents.get(name);
1860 DeclarationName decl_name(&identifier_info);
1861 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1862 for (NamedDecl *decl : result) {
1863 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1865 return namespace_decl;
1868 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1869 SourceLocation(), SourceLocation(),
1870 &identifier_info,
nullptr,
false);
1872 decl_ctx->addDecl(namespace_decl);
1874 if (decl_ctx == translation_unit_decl) {
1875 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1877 return namespace_decl;
1880 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1881 SourceLocation(),
nullptr,
nullptr,
false);
1882 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1883 translation_unit_decl->addDecl(namespace_decl);
1884 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1886 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1887 if (parent_namespace_decl) {
1888 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1890 return namespace_decl;
1892 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1893 SourceLocation(),
nullptr,
nullptr,
false);
1894 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1895 parent_namespace_decl->addDecl(namespace_decl);
1896 assert(namespace_decl ==
1897 parent_namespace_decl->getAnonymousNamespace());
1899 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1900 "no namespace as decl_ctx");
1908 VerifyDecl(namespace_decl);
1909 return namespace_decl;
1916 clang::BlockDecl *decl =
1917 clang::BlockDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1918 decl->setDeclContext(ctx);
1927 clang::DeclContext *right,
1928 clang::DeclContext *root) {
1929 if (root ==
nullptr)
1932 std::set<clang::DeclContext *> path_left;
1933 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1934 path_left.insert(d);
1936 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1937 if (path_left.find(d) != path_left.end())
1945 clang::NamespaceDecl *ns_decl) {
1946 if (decl_ctx && ns_decl) {
1947 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1948 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1950 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1951 clang::SourceLocation(), ns_decl,
1954 decl_ctx->addDecl(using_decl);
1964 clang::NamedDecl *target) {
1965 if (current_decl_ctx && target) {
1966 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1968 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1970 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1972 target->getDeclName(), using_decl, target);
1974 using_decl->addShadowDecl(shadow_decl);
1975 current_decl_ctx->addDecl(using_decl);
1983 const char *name, clang::QualType type) {
1985 clang::VarDecl *var_decl =
1986 clang::VarDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1987 var_decl->setDeclContext(decl_context);
1988 if (name && name[0])
1989 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1990 var_decl->setType(type);
1992 var_decl->setAccess(clang::AS_public);
1993 decl_context->addDecl(var_decl);
2002 switch (basic_type) {
2004 return ast->VoidTy.getAsOpaquePtr();
2006 return ast->CharTy.getAsOpaquePtr();
2008 return ast->SignedCharTy.getAsOpaquePtr();
2010 return ast->UnsignedCharTy.getAsOpaquePtr();
2012 return ast->getWCharType().getAsOpaquePtr();
2014 return ast->getSignedWCharType().getAsOpaquePtr();
2016 return ast->getUnsignedWCharType().getAsOpaquePtr();
2018 return ast->Char8Ty.getAsOpaquePtr();
2020 return ast->Char16Ty.getAsOpaquePtr();
2022 return ast->Char32Ty.getAsOpaquePtr();
2024 return ast->ShortTy.getAsOpaquePtr();
2026 return ast->UnsignedShortTy.getAsOpaquePtr();
2028 return ast->IntTy.getAsOpaquePtr();
2030 return ast->UnsignedIntTy.getAsOpaquePtr();
2032 return ast->LongTy.getAsOpaquePtr();
2034 return ast->UnsignedLongTy.getAsOpaquePtr();
2036 return ast->LongLongTy.getAsOpaquePtr();
2038 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2040 return ast->Int128Ty.getAsOpaquePtr();
2042 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2044 return ast->BoolTy.getAsOpaquePtr();
2046 return ast->HalfTy.getAsOpaquePtr();
2048 return ast->FloatTy.getAsOpaquePtr();
2050 return ast->DoubleTy.getAsOpaquePtr();
2052 return ast->LongDoubleTy.getAsOpaquePtr();
2054 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2056 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2058 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2060 return ast->getObjCIdType().getAsOpaquePtr();
2062 return ast->getObjCClassType().getAsOpaquePtr();
2064 return ast->getObjCSelType().getAsOpaquePtr();
2066 return ast->NullPtrTy.getAsOpaquePtr();
2072#pragma mark Function Types
2074clang::DeclarationName
2077 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2078 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2087 const clang::FunctionProtoType *function_type =
2088 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2089 if (function_type ==
nullptr)
2090 return clang::DeclarationName();
2092 const bool is_method =
false;
2093 const unsigned int num_params = function_type->getNumParams();
2095 is_method, op_kind, num_params))
2096 return clang::DeclarationName();
2098 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2102 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2103 printing_policy.SuppressTagKeyword =
true;
2106 printing_policy.SuppressInlineNamespace =
false;
2107 printing_policy.SuppressUnwrittenScope =
false;
2119 printing_policy.SuppressDefaultTemplateArgs =
false;
2120 return printing_policy;
2127 llvm::raw_string_ostream os(result);
2128 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2134 llvm::StringRef name,
const CompilerType &function_clang_type,
2135 clang::StorageClass storage,
bool is_inline) {
2136 FunctionDecl *func_decl =
nullptr;
2139 decl_ctx = ast.getTranslationUnitDecl();
2141 const bool hasWrittenPrototype =
true;
2142 const bool isConstexprSpecified =
false;
2144 clang::DeclarationName declarationName =
2146 func_decl = FunctionDecl::CreateDeserialized(ast, GlobalDeclID());
2147 func_decl->setDeclContext(decl_ctx);
2148 func_decl->setDeclName(declarationName);
2150 func_decl->setStorageClass(storage);
2151 func_decl->setInlineSpecified(is_inline);
2152 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2153 func_decl->setConstexprKind(isConstexprSpecified
2154 ? ConstexprSpecKind::Constexpr
2155 : ConstexprSpecKind::Unspecified);
2157 decl_ctx->addDecl(func_decl);
2159 VerifyDecl(func_decl);
2166 unsigned num_args,
bool is_variadic,
unsigned type_quals,
2167 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2171 std::vector<QualType> qual_type_args;
2172 if (num_args > 0 && args ==
nullptr)
2176 for (
unsigned i = 0; i < num_args; ++i) {
2191 FunctionProtoType::ExtProtoInfo proto_info;
2192 proto_info.ExtInfo = cc;
2193 proto_info.Variadic = is_variadic;
2194 proto_info.ExceptionSpec = EST_None;
2195 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2196 proto_info.RefQualifier = ref_qual;
2204 const char *name,
const CompilerType ¶m_type,
int storage,
2207 auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
2208 decl->setDeclContext(decl_ctx);
2209 if (name && name[0])
2210 decl->setDeclName(&ast.Idents.get(name));
2212 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2215 decl_ctx->addDecl(decl);
2221 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2223 function_decl->setParams(params);
2228 QualType block_type =
m_ast_up->getBlockPointerType(
2234#pragma mark Array Types
2237 size_t element_count,
2247 llvm::APInt ap_element_count(64, element_count);
2248 if (element_count == 0) {
2251 clang::ArraySizeModifier::Normal, 0));
2253 return GetType(ast.getConstantArrayType(
2255 clang::ArraySizeModifier::Normal, 0));
2263 llvm::StringRef type_name,
2264 const std::initializer_list<std::pair<const char *, CompilerType>>
2268 if (!type_name.empty() &&
2269 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2271 lldbassert(0 &&
"Trying to create a type for an existing name");
2279 for (
const auto &field : type_fields)
2289 llvm::StringRef type_name,
2290 const std::initializer_list<std::pair<const char *, CompilerType>>
2294 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2300#pragma mark Enumeration Types
2303 llvm::StringRef name, clang::DeclContext *decl_ctx,
2305 const CompilerType &integer_clang_type,
bool is_scoped) {
2312 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
2313 enum_decl->setDeclContext(decl_ctx);
2315 enum_decl->setDeclName(&ast.Idents.get(name));
2316 enum_decl->setScoped(is_scoped);
2317 enum_decl->setScopedUsingClassTag(is_scoped);
2318 enum_decl->setFixed(
false);
2321 decl_ctx->addDecl(enum_decl);
2326 enum_decl->setAccess(AS_public);
2328 return GetType(ast.getTagDeclType(enum_decl));
2336 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2337 return GetType(ast.SignedCharTy);
2339 if (bit_size == ast.getTypeSize(ast.ShortTy))
2342 if (bit_size == ast.getTypeSize(ast.IntTy))
2345 if (bit_size == ast.getTypeSize(ast.LongTy))
2348 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2349 return GetType(ast.LongLongTy);
2351 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2354 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2355 return GetType(ast.UnsignedCharTy);
2357 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2358 return GetType(ast.UnsignedShortTy);
2360 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2361 return GetType(ast.UnsignedIntTy);
2363 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2364 return GetType(ast.UnsignedLongTy);
2366 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2367 return GetType(ast.UnsignedLongLongTy);
2369 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2370 return GetType(ast.UnsignedInt128Ty);
2384 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2386 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2387 named_decl->getDeclName().getAsString().c_str());
2389 printf(
"%20s\n", decl_ctx->getDeclKindName());
2395 if (decl ==
nullptr)
2399 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2401 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2402 record_decl->getDeclName().getAsString().c_str(),
2403 record_decl->isInjectedClassName() ?
" (injected class name)" :
"");
2406 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2408 printf(
"%20s: %s\n", decl->getDeclKindName(),
2409 named_decl->getDeclName().getAsString().c_str());
2411 printf(
"%20s\n", decl->getDeclKindName());
2417 clang::Decl *decl) {
2421 ExternalASTSource *ast_source = ast->getExternalSource();
2426 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2427 if (tag_decl->isCompleteDefinition())
2430 if (!tag_decl->hasExternalLexicalStorage())
2433 ast_source->CompleteType(tag_decl);
2435 return !tag_decl->getTypeForDecl()->isIncompleteType();
2436 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2437 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2438 if (objc_interface_decl->getDefinition())
2441 if (!objc_interface_decl->hasExternalLexicalStorage())
2444 ast_source->CompleteType(objc_interface_decl);
2446 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2491 clang::AccessSpecifier access) {
2492 if (access == clang::AccessSpecifier::AS_none)
2498clang::AccessSpecifier
2503 return clang::AccessSpecifier::AS_none;
2525 if (find(mask, type->getTypeClass()) != mask.end())
2527 switch (type->getTypeClass()) {
2530 case clang::Type::Atomic:
2531 type = cast<clang::AtomicType>(type)->getValueType();
2533 case clang::Type::Auto:
2534 case clang::Type::Decltype:
2535 case clang::Type::Elaborated:
2536 case clang::Type::Paren:
2537 case clang::Type::SubstTemplateTypeParm:
2538 case clang::Type::TemplateSpecialization:
2539 case clang::Type::Typedef:
2540 case clang::Type::TypeOf:
2541 case clang::Type::TypeOfExpr:
2542 case clang::Type::Using:
2543 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2557 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2558 switch (type_class) {
2559 case clang::Type::ObjCInterface:
2560 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2562 case clang::Type::ObjCObjectPointer:
2564 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2565 ->getPointeeType());
2566 case clang::Type::Record:
2567 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2568 case clang::Type::Enum:
2569 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2582 clang::QualType qual_type,
2583 bool allow_completion) {
2584 assert(qual_type->isRecordType());
2586 const auto *tag_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2588 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2592 if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
2595 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2596 const bool fields_loaded =
2597 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2600 if (is_complete && fields_loaded)
2603 if (!allow_completion)
2611 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2612 if (external_ast_source) {
2613 external_ast_source->CompleteType(cxx_record_decl);
2614 if (cxx_record_decl->isCompleteDefinition()) {
2615 cxx_record_decl->field_begin();
2616 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2628 clang::QualType qual_type,
2629 bool allow_completion) {
2630 assert(qual_type->isEnumeralType());
2633 const clang::EnumType *enum_type =
2634 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
2636 auto *tag_decl = enum_type->getAsTagDecl();
2640 if (tag_decl->getDefinition())
2643 if (!allow_completion)
2647 if (!tag_decl->hasExternalLexicalStorage())
2651 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2652 if (!external_ast_source)
2655 external_ast_source->CompleteType(tag_decl);
2663static const clang::ObjCObjectType *
2665 bool allow_completion) {
2666 assert(qual_type->isObjCObjectType());
2669 const clang::ObjCObjectType *objc_class_type =
2670 llvm::cast<clang::ObjCObjectType>(qual_type);
2672 clang::ObjCInterfaceDecl *class_interface_decl =
2673 objc_class_type->getInterface();
2676 if (!class_interface_decl)
2677 return objc_class_type;
2680 if (class_interface_decl->getDefinition())
2681 return objc_class_type;
2683 if (!allow_completion)
2687 if (!class_interface_decl->hasExternalLexicalStorage())
2691 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2692 if (!external_ast_source)
2695 external_ast_source->CompleteType(class_interface_decl);
2696 return objc_class_type;
2700 clang::QualType qual_type,
2701 bool allow_completion =
true) {
2703 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2704 switch (type_class) {
2705 case clang::Type::ConstantArray:
2706 case clang::Type::IncompleteArray:
2707 case clang::Type::VariableArray: {
2708 const clang::ArrayType *array_type =
2709 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2715 case clang::Type::Record: {
2716 if (
const auto *RT =
2718 return !RT->isIncompleteType();
2723 case clang::Type::Enum: {
2725 return !ET->isIncompleteType();
2729 case clang::Type::ObjCObject:
2730 case clang::Type::ObjCInterface: {
2731 if (
const auto *OT =
2733 return !OT->isIncompleteType();
2738 case clang::Type::Attributed:
2740 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2750static clang::ObjCIvarDecl::AccessControl
2754 return clang::ObjCIvarDecl::None;
2756 return clang::ObjCIvarDecl::Public;
2758 return clang::ObjCIvarDecl::Private;
2760 return clang::ObjCIvarDecl::Protected;
2762 return clang::ObjCIvarDecl::Package;
2764 return clang::ObjCIvarDecl::None;
2771 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2778 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2779 switch (type_class) {
2780 case clang::Type::IncompleteArray:
2781 case clang::Type::VariableArray:
2782 case clang::Type::ConstantArray:
2783 case clang::Type::ExtVector:
2784 case clang::Type::Vector:
2785 case clang::Type::Record:
2786 case clang::Type::ObjCObject:
2787 case clang::Type::ObjCInterface:
2799 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2800 switch (type_class) {
2801 case clang::Type::Record: {
2802 if (
const clang::RecordType *record_type =
2803 llvm::dyn_cast_or_null<clang::RecordType>(
2804 qual_type.getTypePtrOrNull())) {
2805 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2806 return record_decl->isAnonymousStructOrUnion();
2820 uint64_t *size,
bool *is_incomplete) {
2823 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2824 switch (type_class) {
2828 case clang::Type::ConstantArray:
2829 if (element_type_ptr)
2831 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2835 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2837 .getLimitedValue(ULLONG_MAX);
2839 *is_incomplete =
false;
2842 case clang::Type::IncompleteArray:
2843 if (element_type_ptr)
2845 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2851 *is_incomplete =
true;
2854 case clang::Type::VariableArray:
2855 if (element_type_ptr)
2857 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2863 *is_incomplete =
false;
2866 case clang::Type::DependentSizedArray:
2867 if (element_type_ptr)
2870 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2876 *is_incomplete =
false;
2879 if (element_type_ptr)
2880 element_type_ptr->
Clear();
2884 *is_incomplete =
false;
2892 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2893 switch (type_class) {
2894 case clang::Type::Vector: {
2895 const clang::VectorType *vector_type =
2896 qual_type->getAs<clang::VectorType>();
2899 *size = vector_type->getNumElements();
2901 *element_type =
GetType(vector_type->getElementType());
2905 case clang::Type::ExtVector: {
2906 const clang::ExtVectorType *ext_vector_type =
2907 qual_type->getAs<clang::ExtVectorType>();
2908 if (ext_vector_type) {
2910 *size = ext_vector_type->getNumElements();
2914 ext_vector_type->getElementType().getAsOpaquePtr());
2930 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2933 clang::ObjCInterfaceDecl *result_iface_decl =
2934 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2939 return (ast_metadata->
GetISAPtr() != 0);
2943 return GetQualType(type).getUnqualifiedType()->isCharType();
2952 const bool allow_completion =
true;
2967 if (!pointee_or_element_clang_type.
IsValid())
2970 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2971 if (pointee_or_element_clang_type.
IsCharType()) {
2972 if (type_flags.
Test(eTypeIsArray)) {
2975 length = llvm::cast<clang::ConstantArrayType>(
2989 if (
auto pointer_auth = qual_type.getPointerAuth())
2990 return pointer_auth.getKey();
2999 if (
auto pointer_auth = qual_type.getPointerAuth())
3000 return pointer_auth.getExtraDiscriminator();
3009 if (
auto pointer_auth = qual_type.getPointerAuth())
3010 return pointer_auth.isAddressDiscriminated();
3016 auto isFunctionType = [&](clang::QualType qual_type) {
3017 return qual_type->isFunctionType();
3031 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3032 switch (type_class) {
3033 case clang::Type::Record:
3035 const clang::CXXRecordDecl *cxx_record_decl =
3036 qual_type->getAsCXXRecordDecl();
3037 if (cxx_record_decl) {
3038 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3041 const clang::RecordType *record_type =
3042 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3044 const clang::RecordDecl *record_decl = record_type->getDecl();
3048 clang::RecordDecl::field_iterator field_pos,
3049 field_end = record_decl->field_end();
3050 uint32_t num_fields = 0;
3051 bool is_hva =
false;
3052 bool is_hfa =
false;
3053 clang::QualType base_qual_type;
3054 uint64_t base_bitwidth = 0;
3055 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3057 clang::QualType field_qual_type = field_pos->getType();
3058 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
3059 if (field_qual_type->isFloatingType()) {
3060 if (field_qual_type->isComplexType())
3063 if (num_fields == 0)
3064 base_qual_type = field_qual_type;
3069 if (field_qual_type.getTypePtr() !=
3070 base_qual_type.getTypePtr())
3074 }
else if (field_qual_type->isVectorType() ||
3075 field_qual_type->isExtVectorType()) {
3076 if (num_fields == 0) {
3077 base_qual_type = field_qual_type;
3078 base_bitwidth = field_bitwidth;
3083 if (base_bitwidth != field_bitwidth)
3085 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3094 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3111 const clang::FunctionProtoType *func =
3112 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3114 return func->getNumParams();
3121 const size_t index) {
3124 const clang::FunctionProtoType *func =
3125 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3127 if (index < func->getNumParams())
3128 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3136 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3140 if (predicate(qual_type))
3143 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3144 switch (type_class) {
3148 case clang::Type::LValueReference:
3149 case clang::Type::RValueReference: {
3150 const clang::ReferenceType *reference_type =
3151 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3153 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3162 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3163 return qual_type->isMemberFunctionPointerType();
3166 return IsTypeImpl(type, isMemberFunctionPointerType);
3170 auto isFunctionPointerType = [](clang::QualType qual_type) {
3171 return qual_type->isFunctionPointerType();
3174 return IsTypeImpl(type, isFunctionPointerType);
3180 auto isBlockPointerType = [&](clang::QualType qual_type) {
3181 if (qual_type->isBlockPointerType()) {
3182 if (function_pointer_type_ptr) {
3183 const clang::BlockPointerType *block_pointer_type =
3184 qual_type->castAs<clang::BlockPointerType>();
3185 QualType pointee_type = block_pointer_type->getPointeeType();
3186 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3188 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3205 const clang::BuiltinType *builtin_type =
3206 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3209 if (builtin_type->isInteger()) {
3210 is_signed = builtin_type->isSignedInteger();
3221 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3225 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3237 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3241 return enum_type->isScopedEnumeralType();
3252 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3253 switch (type_class) {
3254 case clang::Type::Builtin:
3255 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3258 case clang::BuiltinType::ObjCId:
3259 case clang::BuiltinType::ObjCClass:
3263 case clang::Type::ObjCObjectPointer:
3267 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3271 case clang::Type::BlockPointer:
3274 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3278 case clang::Type::Pointer:
3281 llvm::cast<clang::PointerType>(qual_type)
3285 case clang::Type::MemberPointer:
3288 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3297 pointee_type->
Clear();
3305 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3306 switch (type_class) {
3307 case clang::Type::Builtin:
3308 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3311 case clang::BuiltinType::ObjCId:
3312 case clang::BuiltinType::ObjCClass:
3316 case clang::Type::ObjCObjectPointer:
3320 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3324 case clang::Type::BlockPointer:
3327 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3331 case clang::Type::Pointer:
3334 llvm::cast<clang::PointerType>(qual_type)
3338 case clang::Type::MemberPointer:
3341 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3345 case clang::Type::LValueReference:
3348 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3352 case clang::Type::RValueReference:
3355 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3364 pointee_type->
Clear();
3373 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3375 switch (type_class) {
3376 case clang::Type::LValueReference:
3379 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3385 case clang::Type::RValueReference:
3388 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3400 pointee_type->
Clear();
3405 uint32_t &count,
bool &is_complex) {
3409 if (
const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3410 qual_type->getCanonicalTypeInternal())) {
3411 clang::BuiltinType::Kind kind = BT->getKind();
3412 if (kind >= clang::BuiltinType::Float &&
3413 kind <= clang::BuiltinType::LongDouble) {
3418 }
else if (
const clang::ComplexType *CT =
3419 llvm::dyn_cast<clang::ComplexType>(
3420 qual_type->getCanonicalTypeInternal())) {
3427 }
else if (
const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3428 qual_type->getCanonicalTypeInternal())) {
3431 count = VT->getNumElements();
3447 const clang::TagType *tag_type =
3448 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3450 clang::TagDecl *tag_decl = tag_type->getDecl();
3452 return tag_decl->isCompleteDefinition();
3455 const clang::ObjCObjectType *objc_class_type =
3456 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3457 if (objc_class_type) {
3458 clang::ObjCInterfaceDecl *class_interface_decl =
3459 objc_class_type->getInterface();
3460 if (class_interface_decl)
3461 return class_interface_decl->getDefinition() !=
nullptr;
3472 const clang::ObjCObjectPointerType *obj_pointer_type =
3473 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3475 if (obj_pointer_type)
3476 return obj_pointer_type->isObjCClassType();
3491 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3492 return (type_class == clang::Type::Record);
3499 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3500 return (type_class == clang::Type::Enum);
3506 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3507 switch (type_class) {
3508 case clang::Type::Record:
3510 const clang::RecordType *record_type =
3511 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3512 const clang::RecordDecl *record_decl = record_type->getDecl();
3514 const clang::CXXRecordDecl *cxx_record_decl =
3515 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3516 if (cxx_record_decl) {
3523 return cxx_record_decl->isDynamicClass();
3538 bool check_cplusplus,
3540 clang::QualType pointee_qual_type;
3543 bool success =
false;
3544 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3545 switch (type_class) {
3546 case clang::Type::Builtin:
3548 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3549 clang::BuiltinType::ObjCId) {
3550 if (dynamic_pointee_type)
3556 case clang::Type::ObjCObjectPointer:
3558 if (
const auto *objc_pointee_type =
3559 qual_type->getPointeeType().getTypePtrOrNull()) {
3560 if (
const auto *objc_object_type =
3561 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3562 objc_pointee_type)) {
3563 if (objc_object_type->isObjCClass())
3567 if (dynamic_pointee_type)
3570 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3577 case clang::Type::Pointer:
3579 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3583 case clang::Type::LValueReference:
3584 case clang::Type::RValueReference:
3586 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3598 const clang::Type::TypeClass pointee_type_class =
3599 pointee_qual_type.getCanonicalType()->getTypeClass();
3600 switch (pointee_type_class) {
3601 case clang::Type::Builtin:
3602 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3603 case clang::BuiltinType::UnknownAny:
3604 case clang::BuiltinType::Void:
3605 if (dynamic_pointee_type)
3607 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3614 case clang::Type::Record:
3615 if (check_cplusplus) {
3616 clang::CXXRecordDecl *cxx_record_decl =
3617 pointee_qual_type->getAsCXXRecordDecl();
3618 if (cxx_record_decl) {
3619 bool is_complete = cxx_record_decl->isCompleteDefinition();
3622 success = cxx_record_decl->isDynamicClass();
3630 success = cxx_record_decl->isDynamicClass();
3637 if (dynamic_pointee_type)
3639 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3646 case clang::Type::ObjCObject:
3647 case clang::Type::ObjCInterface:
3649 if (dynamic_pointee_type)
3651 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3661 if (dynamic_pointee_type)
3662 dynamic_pointee_type->
Clear();
3670 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3677 ->getTypeClass() == clang::Type::Typedef;
3687 if (
auto *record_decl =
3689 return record_decl->canPassInRegisters();
3695 return TypeSystemClangSupportsLanguage(language);
3698std::optional<std::string>
3701 return std::nullopt;
3704 if (qual_type.isNull())
3705 return std::nullopt;
3707 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3708 if (!cxx_record_decl)
3709 return std::nullopt;
3711 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3719 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3726 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3728 return tag_type->isBeingDefined();
3739 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3740 if (class_type_ptr) {
3741 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3742 const clang::ObjCObjectPointerType *obj_pointer_type =
3743 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3744 if (obj_pointer_type ==
nullptr)
3745 class_type_ptr->
Clear();
3749 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3756 class_type_ptr->
Clear();
3765 const bool allow_completion =
true;
3785 {clang::Type::Typedef, clang::Type::Atomic});
3788 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3789 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3796 if (
auto *named_decl = qual_type->getAsTagDecl())
3808 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3809 printing_policy.SuppressTagKeyword =
true;
3810 printing_policy.SuppressScope =
false;
3811 printing_policy.SuppressUnwrittenScope =
true;
3812 printing_policy.SuppressInlineNamespace =
true;
3813 return ConstString(qual_type.getAsString(printing_policy));
3822 if (pointee_or_element_clang_type)
3823 pointee_or_element_clang_type->
Clear();
3825 clang::QualType qual_type =
3828 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3829 switch (type_class) {
3830 case clang::Type::Attributed:
3831 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3834 pointee_or_element_clang_type);
3835 case clang::Type::Builtin: {
3836 const clang::BuiltinType *builtin_type =
3837 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3839 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3840 switch (builtin_type->getKind()) {
3841 case clang::BuiltinType::ObjCId:
3842 case clang::BuiltinType::ObjCClass:
3843 if (pointee_or_element_clang_type)
3847 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3850 case clang::BuiltinType::ObjCSel:
3851 if (pointee_or_element_clang_type)
3854 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3857 case clang::BuiltinType::Bool:
3858 case clang::BuiltinType::Char_U:
3859 case clang::BuiltinType::UChar:
3860 case clang::BuiltinType::WChar_U:
3861 case clang::BuiltinType::Char16:
3862 case clang::BuiltinType::Char32:
3863 case clang::BuiltinType::UShort:
3864 case clang::BuiltinType::UInt:
3865 case clang::BuiltinType::ULong:
3866 case clang::BuiltinType::ULongLong:
3867 case clang::BuiltinType::UInt128:
3868 case clang::BuiltinType::Char_S:
3869 case clang::BuiltinType::SChar:
3870 case clang::BuiltinType::WChar_S:
3871 case clang::BuiltinType::Short:
3872 case clang::BuiltinType::Int:
3873 case clang::BuiltinType::Long:
3874 case clang::BuiltinType::LongLong:
3875 case clang::BuiltinType::Int128:
3876 case clang::BuiltinType::Float:
3877 case clang::BuiltinType::Double:
3878 case clang::BuiltinType::LongDouble:
3879 builtin_type_flags |= eTypeIsScalar;
3880 if (builtin_type->isInteger()) {
3881 builtin_type_flags |= eTypeIsInteger;
3882 if (builtin_type->isSignedInteger())
3883 builtin_type_flags |= eTypeIsSigned;
3884 }
else if (builtin_type->isFloatingPoint())
3885 builtin_type_flags |= eTypeIsFloat;
3890 return builtin_type_flags;
3893 case clang::Type::BlockPointer:
3894 if (pointee_or_element_clang_type)
3896 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3897 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3899 case clang::Type::Complex: {
3900 uint32_t complex_type_flags =
3901 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3902 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3903 qual_type->getCanonicalTypeInternal());
3905 clang::QualType complex_element_type(complex_type->getElementType());
3906 if (complex_element_type->isIntegerType())
3907 complex_type_flags |= eTypeIsFloat;
3908 else if (complex_element_type->isFloatingType())
3909 complex_type_flags |= eTypeIsInteger;
3911 return complex_type_flags;
3914 case clang::Type::ConstantArray:
3915 case clang::Type::DependentSizedArray:
3916 case clang::Type::IncompleteArray:
3917 case clang::Type::VariableArray:
3918 if (pointee_or_element_clang_type)
3920 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3923 return eTypeHasChildren | eTypeIsArray;
3925 case clang::Type::DependentName:
3927 case clang::Type::DependentSizedExtVector:
3928 return eTypeHasChildren | eTypeIsVector;
3929 case clang::Type::DependentTemplateSpecialization:
3930 return eTypeIsTemplate;
3932 case clang::Type::Enum:
3933 if (pointee_or_element_clang_type)
3935 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3939 return eTypeIsEnumeration | eTypeHasValue;
3941 case clang::Type::FunctionProto:
3942 return eTypeIsFuncPrototype | eTypeHasValue;
3943 case clang::Type::FunctionNoProto:
3944 return eTypeIsFuncPrototype | eTypeHasValue;
3945 case clang::Type::InjectedClassName:
3948 case clang::Type::LValueReference:
3949 case clang::Type::RValueReference:
3950 if (pointee_or_element_clang_type)
3953 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3956 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3958 case clang::Type::MemberPointer:
3959 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3961 case clang::Type::ObjCObjectPointer:
3962 if (pointee_or_element_clang_type)
3964 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3965 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3968 case clang::Type::ObjCObject:
3969 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3970 case clang::Type::ObjCInterface:
3971 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3973 case clang::Type::Pointer:
3974 if (pointee_or_element_clang_type)
3976 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3977 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3979 case clang::Type::Record:
3980 if (qual_type->getAsCXXRecordDecl())
3981 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3983 return eTypeHasChildren | eTypeIsStructUnion;
3985 case clang::Type::SubstTemplateTypeParm:
3986 return eTypeIsTemplate;
3987 case clang::Type::TemplateTypeParm:
3988 return eTypeIsTemplate;
3989 case clang::Type::TemplateSpecialization:
3990 return eTypeIsTemplate;
3992 case clang::Type::Typedef:
3993 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
3995 ->getUnderlyingType())
3997 case clang::Type::UnresolvedUsing:
4000 case clang::Type::ExtVector:
4001 case clang::Type::Vector: {
4002 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4003 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
4004 qual_type->getCanonicalTypeInternal());
4006 if (vector_type->isIntegerType())
4007 vector_type_flags |= eTypeIsFloat;
4008 else if (vector_type->isFloatingType())
4009 vector_type_flags |= eTypeIsInteger;
4011 return vector_type_flags;
4026 if (qual_type->isAnyPointerType()) {
4027 if (qual_type->isObjCObjectPointerType())
4029 if (qual_type->getPointeeCXXRecordDecl())
4032 clang::QualType pointee_type(qual_type->getPointeeType());
4033 if (pointee_type->getPointeeCXXRecordDecl())
4035 if (pointee_type->isObjCObjectOrInterfaceType())
4037 if (pointee_type->isObjCClassType())
4039 if (pointee_type.getTypePtr() ==
4043 if (qual_type->isObjCObjectOrInterfaceType())
4045 if (qual_type->getAsCXXRecordDecl())
4047 switch (qual_type->getTypeClass()) {
4050 case clang::Type::Builtin:
4051 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4053 case clang::BuiltinType::Void:
4054 case clang::BuiltinType::Bool:
4055 case clang::BuiltinType::Char_U:
4056 case clang::BuiltinType::UChar:
4057 case clang::BuiltinType::WChar_U:
4058 case clang::BuiltinType::Char16:
4059 case clang::BuiltinType::Char32:
4060 case clang::BuiltinType::UShort:
4061 case clang::BuiltinType::UInt:
4062 case clang::BuiltinType::ULong:
4063 case clang::BuiltinType::ULongLong:
4064 case clang::BuiltinType::UInt128:
4065 case clang::BuiltinType::Char_S:
4066 case clang::BuiltinType::SChar:
4067 case clang::BuiltinType::WChar_S:
4068 case clang::BuiltinType::Short:
4069 case clang::BuiltinType::Int:
4070 case clang::BuiltinType::Long:
4071 case clang::BuiltinType::LongLong:
4072 case clang::BuiltinType::Int128:
4073 case clang::BuiltinType::Float:
4074 case clang::BuiltinType::Double:
4075 case clang::BuiltinType::LongDouble:
4078 case clang::BuiltinType::NullPtr:
4081 case clang::BuiltinType::ObjCId:
4082 case clang::BuiltinType::ObjCClass:
4083 case clang::BuiltinType::ObjCSel:
4086 case clang::BuiltinType::Dependent:
4087 case clang::BuiltinType::Overload:
4088 case clang::BuiltinType::BoundMember:
4089 case clang::BuiltinType::UnknownAny:
4093 case clang::Type::Typedef:
4094 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4096 ->getUnderlyingType())
4106 return lldb::eTypeClassInvalid;
4108 clang::QualType qual_type =
4111 switch (qual_type->getTypeClass()) {
4112 case clang::Type::Atomic:
4113 case clang::Type::Auto:
4114 case clang::Type::CountAttributed:
4115 case clang::Type::Decltype:
4116 case clang::Type::Elaborated:
4117 case clang::Type::Paren:
4118 case clang::Type::TypeOf:
4119 case clang::Type::TypeOfExpr:
4120 case clang::Type::Using:
4121 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4122 case clang::Type::UnaryTransform:
4124 case clang::Type::FunctionNoProto:
4125 return lldb::eTypeClassFunction;
4126 case clang::Type::FunctionProto:
4127 return lldb::eTypeClassFunction;
4128 case clang::Type::IncompleteArray:
4129 return lldb::eTypeClassArray;
4130 case clang::Type::VariableArray:
4131 return lldb::eTypeClassArray;
4132 case clang::Type::ConstantArray:
4133 return lldb::eTypeClassArray;
4134 case clang::Type::DependentSizedArray:
4135 return lldb::eTypeClassArray;
4136 case clang::Type::ArrayParameter:
4137 return lldb::eTypeClassArray;
4138 case clang::Type::DependentSizedExtVector:
4139 return lldb::eTypeClassVector;
4140 case clang::Type::DependentVector:
4141 return lldb::eTypeClassVector;
4142 case clang::Type::ExtVector:
4143 return lldb::eTypeClassVector;
4144 case clang::Type::Vector:
4145 return lldb::eTypeClassVector;
4146 case clang::Type::Builtin:
4148 case clang::Type::BitInt:
4149 case clang::Type::DependentBitInt:
4150 return lldb::eTypeClassBuiltin;
4151 case clang::Type::ObjCObjectPointer:
4152 return lldb::eTypeClassObjCObjectPointer;
4153 case clang::Type::BlockPointer:
4154 return lldb::eTypeClassBlockPointer;
4155 case clang::Type::Pointer:
4156 return lldb::eTypeClassPointer;
4157 case clang::Type::LValueReference:
4158 return lldb::eTypeClassReference;
4159 case clang::Type::RValueReference:
4160 return lldb::eTypeClassReference;
4161 case clang::Type::MemberPointer:
4162 return lldb::eTypeClassMemberPointer;
4163 case clang::Type::Complex:
4164 if (qual_type->isComplexType())
4165 return lldb::eTypeClassComplexFloat;
4167 return lldb::eTypeClassComplexInteger;
4168 case clang::Type::ObjCObject:
4169 return lldb::eTypeClassObjCObject;
4170 case clang::Type::ObjCInterface:
4171 return lldb::eTypeClassObjCInterface;
4172 case clang::Type::Record: {
4173 const clang::RecordType *record_type =
4174 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4175 const clang::RecordDecl *record_decl = record_type->getDecl();
4176 if (record_decl->isUnion())
4177 return lldb::eTypeClassUnion;
4178 else if (record_decl->isStruct())
4179 return lldb::eTypeClassStruct;
4181 return lldb::eTypeClassClass;
4183 case clang::Type::Enum:
4184 return lldb::eTypeClassEnumeration;
4185 case clang::Type::Typedef:
4186 return lldb::eTypeClassTypedef;
4187 case clang::Type::UnresolvedUsing:
4190 case clang::Type::Attributed:
4191 case clang::Type::BTFTagAttributed:
4193 case clang::Type::TemplateTypeParm:
4195 case clang::Type::SubstTemplateTypeParm:
4197 case clang::Type::SubstTemplateTypeParmPack:
4199 case clang::Type::InjectedClassName:
4201 case clang::Type::DependentName:
4203 case clang::Type::DependentTemplateSpecialization:
4205 case clang::Type::PackExpansion:
4208 case clang::Type::TemplateSpecialization:
4210 case clang::Type::DeducedTemplateSpecialization:
4212 case clang::Type::Pipe:
4216 case clang::Type::Decayed:
4218 case clang::Type::Adjusted:
4220 case clang::Type::ObjCTypeParam:
4223 case clang::Type::DependentAddressSpace:
4225 case clang::Type::MacroQualified:
4229 case clang::Type::ConstantMatrix:
4230 case clang::Type::DependentSizedMatrix:
4234 case clang::Type::PackIndexing:
4238 return lldb::eTypeClassOther;
4243 return GetQualType(type).getQualifiers().getCVRQualifiers();
4255 const clang::Type *array_eletype =
4256 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4261 return GetType(clang::QualType(array_eletype, 0));
4272 return GetType(ast_ctx.getConstantArrayType(
4273 qual_type, llvm::APInt(64, size),
nullptr,
4274 clang::ArraySizeModifier::Normal, 0));
4276 return GetType(ast_ctx.getIncompleteArrayType(
4277 qual_type, clang::ArraySizeModifier::Normal, 0));
4291 clang::QualType qual_type) {
4292 if (qual_type->isPointerType())
4293 qual_type = ast->getPointerType(
4295 else if (
const ConstantArrayType *arr =
4296 ast->getAsConstantArrayType(qual_type)) {
4297 qual_type = ast->getConstantArrayType(
4299 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4300 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4302 qual_type = qual_type.getUnqualifiedType();
4303 qual_type.removeLocalConst();
4304 qual_type.removeLocalRestrict();
4305 qual_type.removeLocalVolatile();
4327 const clang::FunctionProtoType *func =
4330 return func->getNumParams();
4338 const clang::FunctionProtoType *func =
4339 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4341 const uint32_t num_args = func->getNumParams();
4343 return GetType(func->getParamType(idx));
4353 const clang::FunctionProtoType *func =
4354 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4356 return GetType(func->getReturnType());
4363 size_t num_functions = 0;
4366 switch (qual_type->getTypeClass()) {
4367 case clang::Type::Record:
4369 const clang::RecordType *record_type =
4370 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4371 const clang::RecordDecl *record_decl = record_type->getDecl();
4372 assert(record_decl);
4373 const clang::CXXRecordDecl *cxx_record_decl =
4374 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4375 if (cxx_record_decl)
4376 num_functions = std::distance(cxx_record_decl->method_begin(),
4377 cxx_record_decl->method_end());
4381 case clang::Type::ObjCObjectPointer: {
4382 const clang::ObjCObjectPointerType *objc_class_type =
4383 qual_type->castAs<clang::ObjCObjectPointerType>();
4384 const clang::ObjCInterfaceType *objc_interface_type =
4385 objc_class_type->getInterfaceType();
4386 if (objc_interface_type &&
4388 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4389 clang::ObjCInterfaceDecl *class_interface_decl =
4390 objc_interface_type->getDecl();
4391 if (class_interface_decl) {
4392 num_functions = std::distance(class_interface_decl->meth_begin(),
4393 class_interface_decl->meth_end());
4399 case clang::Type::ObjCObject:
4400 case clang::Type::ObjCInterface:
4402 const clang::ObjCObjectType *objc_class_type =
4403 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4404 if (objc_class_type) {
4405 clang::ObjCInterfaceDecl *class_interface_decl =
4406 objc_class_type->getInterface();
4407 if (class_interface_decl)
4408 num_functions = std::distance(class_interface_decl->meth_begin(),
4409 class_interface_decl->meth_end());
4418 return num_functions;
4430 switch (qual_type->getTypeClass()) {
4431 case clang::Type::Record:
4433 const clang::RecordType *record_type =
4434 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4435 const clang::RecordDecl *record_decl = record_type->getDecl();
4436 assert(record_decl);
4437 const clang::CXXRecordDecl *cxx_record_decl =
4438 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4439 if (cxx_record_decl) {
4440 auto method_iter = cxx_record_decl->method_begin();
4441 auto method_end = cxx_record_decl->method_end();
4443 static_cast<size_t>(std::distance(method_iter, method_end))) {
4444 std::advance(method_iter, idx);
4445 clang::CXXMethodDecl *cxx_method_decl =
4446 method_iter->getCanonicalDecl();
4447 if (cxx_method_decl) {
4448 name = cxx_method_decl->getDeclName().getAsString();
4449 if (cxx_method_decl->isStatic())
4451 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4453 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4457 clang_type =
GetType(cxx_method_decl->getType());
4465 case clang::Type::ObjCObjectPointer: {
4466 const clang::ObjCObjectPointerType *objc_class_type =
4467 qual_type->castAs<clang::ObjCObjectPointerType>();
4468 const clang::ObjCInterfaceType *objc_interface_type =
4469 objc_class_type->getInterfaceType();
4470 if (objc_interface_type &&
4472 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4473 clang::ObjCInterfaceDecl *class_interface_decl =
4474 objc_interface_type->getDecl();
4475 if (class_interface_decl) {
4476 auto method_iter = class_interface_decl->meth_begin();
4477 auto method_end = class_interface_decl->meth_end();
4479 static_cast<size_t>(std::distance(method_iter, method_end))) {
4480 std::advance(method_iter, idx);
4481 clang::ObjCMethodDecl *objc_method_decl =
4482 method_iter->getCanonicalDecl();
4483 if (objc_method_decl) {
4485 name = objc_method_decl->getSelector().getAsString();
4486 if (objc_method_decl->isClassMethod())
4497 case clang::Type::ObjCObject:
4498 case clang::Type::ObjCInterface:
4500 const clang::ObjCObjectType *objc_class_type =
4501 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4502 if (objc_class_type) {
4503 clang::ObjCInterfaceDecl *class_interface_decl =
4504 objc_class_type->getInterface();
4505 if (class_interface_decl) {
4506 auto method_iter = class_interface_decl->meth_begin();
4507 auto method_end = class_interface_decl->meth_end();
4509 static_cast<size_t>(std::distance(method_iter, method_end))) {
4510 std::advance(method_iter, idx);
4511 clang::ObjCMethodDecl *objc_method_decl =
4512 method_iter->getCanonicalDecl();
4513 if (objc_method_decl) {
4515 name = objc_method_decl->getSelector().getAsString();
4516 if (objc_method_decl->isClassMethod())
4549 return GetType(qual_type.getTypePtr()->getPointeeType());
4559 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4560 case clang::Type::ObjCObject:
4561 case clang::Type::ObjCInterface:
4608 auto pauth = PointerAuthQualifier::fromOpaqueValue(payload);
4609 clang::QualType result =
4610 clang_ast.getPointerAuthType(
GetQualType(type), pauth);
4620 result.addVolatile();
4630 result.addRestrict();
4639 if (type && typedef_name && typedef_name[0]) {
4643 clang::DeclContext *decl_ctx =
4648 clang::TypedefDecl *decl =
4649 clang::TypedefDecl::CreateDeserialized(clang_ast, GlobalDeclID());
4650 decl->setDeclContext(decl_ctx);
4651 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4652 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4653 decl_ctx->addDecl(decl);
4656 clang::TagDecl *tdecl =
nullptr;
4657 if (!qual_type.isNull()) {
4658 if (
const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4659 tdecl = rt->getDecl();
4660 if (
const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4661 tdecl = et->getDecl();
4667 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4668 tdecl->setTypedefNameForAnonDecl(decl);
4670 decl->setAccess(clang::AS_public);
4673 return GetType(clang_ast.getTypedefType(decl));
4681 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4684 return GetType(typedef_type->getDecl()->getUnderlyingType());
4697 const FunctionType::ExtInfo generic_ext_info(
4706 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4711const llvm::fltSemantics &
4714 const size_t bit_size = byte_size * 8;
4715 if (bit_size == ast.getTypeSize(ast.FloatTy))
4716 return ast.getFloatTypeSemantics(ast.FloatTy);
4717 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4718 return ast.getFloatTypeSemantics(ast.DoubleTy);
4719 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4720 bit_size == llvm::APFloat::semanticsSizeInBits(
4721 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4722 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4723 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4724 return ast.getFloatTypeSemantics(ast.HalfTy);
4725 return llvm::APFloatBase::Bogus();
4728std::optional<uint64_t>
4733 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4734 switch (type_class) {
4735 case clang::Type::Record:
4739 return std::nullopt;
4742 case clang::Type::ObjCInterface:
4743 case clang::Type::ObjCObject: {
4749 if (std::optional<uint64_t> bit_size =
4750 objc_runtime->GetTypeBitSize(
GetType(qual_type)))
4754 static bool g_printed =
false;
4759 llvm::outs() <<
"warning: trying to determine the size of type ";
4761 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4762 "reliable. please file a bug against LLDB.\n";
4763 llvm::outs() <<
"backtrace:\n";
4764 llvm::sys::PrintStackTrace(llvm::outs());
4765 llvm::outs() <<
"\n";
4772 const uint32_t bit_size =
getASTContext().getTypeSize(qual_type);
4773 if (bit_size == 0) {
4774 if (qual_type->isIncompleteArrayType())
4776 qual_type->getArrayElementTypeNoTypeQual()
4777 ->getCanonicalTypeUnqualified());
4779 if (qual_type->isObjCObjectOrInterfaceType())
4783 if (qual_type->isFunctionProtoType())
4789 return std::nullopt;
4792std::optional<size_t>
4808 switch (qual_type->getTypeClass()) {
4809 case clang::Type::Atomic:
4810 case clang::Type::Auto:
4811 case clang::Type::CountAttributed:
4812 case clang::Type::Decltype:
4813 case clang::Type::Elaborated:
4814 case clang::Type::Paren:
4815 case clang::Type::Typedef:
4816 case clang::Type::TypeOf:
4817 case clang::Type::TypeOfExpr:
4818 case clang::Type::Using:
4819 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4821 case clang::Type::UnaryTransform:
4824 case clang::Type::FunctionNoProto:
4825 case clang::Type::FunctionProto:
4828 case clang::Type::IncompleteArray:
4829 case clang::Type::VariableArray:
4830 case clang::Type::ArrayParameter:
4833 case clang::Type::ConstantArray:
4836 case clang::Type::DependentVector:
4837 case clang::Type::ExtVector:
4838 case clang::Type::Vector:
4842 case clang::Type::BitInt:
4843 case clang::Type::DependentBitInt:
4847 case clang::Type::Builtin:
4848 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4849 case clang::BuiltinType::Void:
4852 case clang::BuiltinType::Char_S:
4853 case clang::BuiltinType::SChar:
4854 case clang::BuiltinType::WChar_S:
4855 case clang::BuiltinType::Short:
4856 case clang::BuiltinType::Int:
4857 case clang::BuiltinType::Long:
4858 case clang::BuiltinType::LongLong:
4859 case clang::BuiltinType::Int128:
4862 case clang::BuiltinType::Bool:
4863 case clang::BuiltinType::Char_U:
4864 case clang::BuiltinType::UChar:
4865 case clang::BuiltinType::WChar_U:
4866 case clang::BuiltinType::Char8:
4867 case clang::BuiltinType::Char16:
4868 case clang::BuiltinType::Char32:
4869 case clang::BuiltinType::UShort:
4870 case clang::BuiltinType::UInt:
4871 case clang::BuiltinType::ULong:
4872 case clang::BuiltinType::ULongLong:
4873 case clang::BuiltinType::UInt128:
4877 case clang::BuiltinType::ShortAccum:
4878 case clang::BuiltinType::Accum:
4879 case clang::BuiltinType::LongAccum:
4880 case clang::BuiltinType::UShortAccum:
4881 case clang::BuiltinType::UAccum:
4882 case clang::BuiltinType::ULongAccum:
4883 case clang::BuiltinType::ShortFract:
4884 case clang::BuiltinType::Fract:
4885 case clang::BuiltinType::LongFract:
4886 case clang::BuiltinType::UShortFract:
4887 case clang::BuiltinType::UFract:
4888 case clang::BuiltinType::ULongFract:
4889 case clang::BuiltinType::SatShortAccum:
4890 case clang::BuiltinType::SatAccum:
4891 case clang::BuiltinType::SatLongAccum:
4892 case clang::BuiltinType::SatUShortAccum:
4893 case clang::BuiltinType::SatUAccum:
4894 case clang::BuiltinType::SatULongAccum:
4895 case clang::BuiltinType::SatShortFract:
4896 case clang::BuiltinType::SatFract:
4897 case clang::BuiltinType::SatLongFract:
4898 case clang::BuiltinType::SatUShortFract:
4899 case clang::BuiltinType::SatUFract:
4900 case clang::BuiltinType::SatULongFract:
4903 case clang::BuiltinType::Half:
4904 case clang::BuiltinType::Float:
4905 case clang::BuiltinType::Float16:
4906 case clang::BuiltinType::Float128:
4907 case clang::BuiltinType::Double:
4908 case clang::BuiltinType::LongDouble:
4909 case clang::BuiltinType::BFloat16:
4910 case clang::BuiltinType::Ibm128:
4913 case clang::BuiltinType::ObjCClass:
4914 case clang::BuiltinType::ObjCId:
4915 case clang::BuiltinType::ObjCSel:
4918 case clang::BuiltinType::NullPtr:
4921 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4922 case clang::BuiltinType::Kind::BoundMember:
4923 case clang::BuiltinType::Kind::BuiltinFn:
4924 case clang::BuiltinType::Kind::Dependent:
4925 case clang::BuiltinType::Kind::OCLClkEvent:
4926 case clang::BuiltinType::Kind::OCLEvent:
4927 case clang::BuiltinType::Kind::OCLImage1dRO:
4928 case clang::BuiltinType::Kind::OCLImage1dWO:
4929 case clang::BuiltinType::Kind::OCLImage1dRW:
4930 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4931 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4932 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4933 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4934 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4935 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4936 case clang::BuiltinType::Kind::OCLImage2dRO:
4937 case clang::BuiltinType::Kind::OCLImage2dWO:
4938 case clang::BuiltinType::Kind::OCLImage2dRW:
4939 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4940 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4941 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4942 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4943 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4944 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4945 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4946 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4947 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4948 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4949 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4950 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4951 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4952 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4953 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4954 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4955 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4956 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4957 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4958 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4959 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4960 case clang::BuiltinType::Kind::OCLImage3dRO:
4961 case clang::BuiltinType::Kind::OCLImage3dWO:
4962 case clang::BuiltinType::Kind::OCLImage3dRW:
4963 case clang::BuiltinType::Kind::OCLQueue:
4964 case clang::BuiltinType::Kind::OCLReserveID:
4965 case clang::BuiltinType::Kind::OCLSampler:
4966 case clang::BuiltinType::Kind::ArraySection:
4967 case clang::BuiltinType::Kind::OMPArrayShaping:
4968 case clang::BuiltinType::Kind::OMPIterator:
4969 case clang::BuiltinType::Kind::Overload:
4970 case clang::BuiltinType::Kind::PseudoObject:
4971 case clang::BuiltinType::Kind::UnknownAny:
4974 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4975 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4976 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4977 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4978 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4979 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4980 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4981 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4982 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4983 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4984 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4985 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4989 case clang::BuiltinType::VectorPair:
4990 case clang::BuiltinType::VectorQuad:
4994 case clang::BuiltinType::SveBool:
4995 case clang::BuiltinType::SveBoolx2:
4996 case clang::BuiltinType::SveBoolx4:
4997 case clang::BuiltinType::SveCount:
4998 case clang::BuiltinType::SveInt8:
4999 case clang::BuiltinType::SveInt8x2:
5000 case clang::BuiltinType::SveInt8x3:
5001 case clang::BuiltinType::SveInt8x4:
5002 case clang::BuiltinType::SveInt16:
5003 case clang::BuiltinType::SveInt16x2:
5004 case clang::BuiltinType::SveInt16x3:
5005 case clang::BuiltinType::SveInt16x4:
5006 case clang::BuiltinType::SveInt32:
5007 case clang::BuiltinType::SveInt32x2:
5008 case clang::BuiltinType::SveInt32x3:
5009 case clang::BuiltinType::SveInt32x4:
5010 case clang::BuiltinType::SveInt64:
5011 case clang::BuiltinType::SveInt64x2:
5012 case clang::BuiltinType::SveInt64x3:
5013 case clang::BuiltinType::SveInt64x4:
5014 case clang::BuiltinType::SveUint8:
5015 case clang::BuiltinType::SveUint8x2:
5016 case clang::BuiltinType::SveUint8x3:
5017 case clang::BuiltinType::SveUint8x4:
5018 case clang::BuiltinType::SveUint16:
5019 case clang::BuiltinType::SveUint16x2:
5020 case clang::BuiltinType::SveUint16x3:
5021 case clang::BuiltinType::SveUint16x4:
5022 case clang::BuiltinType::SveUint32:
5023 case clang::BuiltinType::SveUint32x2:
5024 case clang::BuiltinType::SveUint32x3:
5025 case clang::BuiltinType::SveUint32x4:
5026 case clang::BuiltinType::SveUint64:
5027 case clang::BuiltinType::SveUint64x2:
5028 case clang::BuiltinType::SveUint64x3:
5029 case clang::BuiltinType::SveUint64x4:
5030 case clang::BuiltinType::SveFloat16:
5031 case clang::BuiltinType::SveBFloat16:
5032 case clang::BuiltinType::SveBFloat16x2:
5033 case clang::BuiltinType::SveBFloat16x3:
5034 case clang::BuiltinType::SveBFloat16x4:
5035 case clang::BuiltinType::SveFloat16x2:
5036 case clang::BuiltinType::SveFloat16x3:
5037 case clang::BuiltinType::SveFloat16x4:
5038 case clang::BuiltinType::SveFloat32:
5039 case clang::BuiltinType::SveFloat32x2:
5040 case clang::BuiltinType::SveFloat32x3:
5041 case clang::BuiltinType::SveFloat32x4:
5042 case clang::BuiltinType::SveFloat64:
5043 case clang::BuiltinType::SveFloat64x2:
5044 case clang::BuiltinType::SveFloat64x3:
5045 case clang::BuiltinType::SveFloat64x4:
5049#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5050#include "clang/Basic/RISCVVTypes.def"
5054 case clang::BuiltinType::WasmExternRef:
5057 case clang::BuiltinType::IncompleteMatrixIdx:
5060 case clang::BuiltinType::UnresolvedTemplate:
5064#define AMDGPU_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5065#include "clang/Basic/AMDGPUTypes.def"
5071 case clang::Type::ObjCObjectPointer:
5072 case clang::Type::BlockPointer:
5073 case clang::Type::Pointer:
5074 case clang::Type::LValueReference:
5075 case clang::Type::RValueReference:
5076 case clang::Type::MemberPointer:
5078 case clang::Type::Complex: {
5080 if (qual_type->isComplexType())
5083 const clang::ComplexType *complex_type =
5084 qual_type->getAsComplexIntegerType();
5094 case clang::Type::ObjCInterface:
5096 case clang::Type::Record:
5098 case clang::Type::Enum:
5099 return qual_type->isUnsignedIntegerOrEnumerationType()
5102 case clang::Type::DependentSizedArray:
5103 case clang::Type::DependentSizedExtVector:
5104 case clang::Type::UnresolvedUsing:
5105 case clang::Type::Attributed:
5106 case clang::Type::BTFTagAttributed:
5107 case clang::Type::TemplateTypeParm:
5108 case clang::Type::SubstTemplateTypeParm:
5109 case clang::Type::SubstTemplateTypeParmPack:
5110 case clang::Type::InjectedClassName:
5111 case clang::Type::DependentName:
5112 case clang::Type::DependentTemplateSpecialization:
5113 case clang::Type::PackExpansion:
5114 case clang::Type::ObjCObject:
5116 case clang::Type::TemplateSpecialization:
5117 case clang::Type::DeducedTemplateSpecialization:
5118 case clang::Type::Adjusted:
5119 case clang::Type::Pipe:
5123 case clang::Type::Decayed:
5125 case clang::Type::ObjCTypeParam:
5128 case clang::Type::DependentAddressSpace:
5130 case clang::Type::MacroQualified:
5133 case clang::Type::ConstantMatrix:
5134 case clang::Type::DependentSizedMatrix:
5138 case clang::Type::PackIndexing:
5151 switch (qual_type->getTypeClass()) {
5152 case clang::Type::Atomic:
5153 case clang::Type::Auto:
5154 case clang::Type::CountAttributed:
5155 case clang::Type::Decltype:
5156 case clang::Type::Elaborated:
5157 case clang::Type::Paren:
5158 case clang::Type::Typedef:
5159 case clang::Type::TypeOf:
5160 case clang::Type::TypeOfExpr:
5161 case clang::Type::Using:
5162 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5163 case clang::Type::UnaryTransform:
5166 case clang::Type::FunctionNoProto:
5167 case clang::Type::FunctionProto:
5170 case clang::Type::IncompleteArray:
5171 case clang::Type::VariableArray:
5172 case clang::Type::ArrayParameter:
5175 case clang::Type::ConstantArray:
5178 case clang::Type::DependentVector:
5179 case clang::Type::ExtVector:
5180 case clang::Type::Vector:
5183 case clang::Type::BitInt:
5184 case clang::Type::DependentBitInt:
5188 case clang::Type::Builtin:
5189 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5190 case clang::BuiltinType::UnknownAny:
5191 case clang::BuiltinType::Void:
5192 case clang::BuiltinType::BoundMember:
5195 case clang::BuiltinType::Bool:
5197 case clang::BuiltinType::Char_S:
5198 case clang::BuiltinType::SChar:
5199 case clang::BuiltinType::WChar_S:
5200 case clang::BuiltinType::Char_U:
5201 case clang::BuiltinType::UChar:
5202 case clang::BuiltinType::WChar_U:
5204 case clang::BuiltinType::Char8:
5206 case clang::BuiltinType::Char16:
5208 case clang::BuiltinType::Char32:
5210 case clang::BuiltinType::UShort:
5212 case clang::BuiltinType::Short:
5214 case clang::BuiltinType::UInt:
5216 case clang::BuiltinType::Int:
5218 case clang::BuiltinType::ULong:
5220 case clang::BuiltinType::Long:
5222 case clang::BuiltinType::ULongLong:
5224 case clang::BuiltinType::LongLong:
5226 case clang::BuiltinType::UInt128:
5228 case clang::BuiltinType::Int128:
5230 case clang::BuiltinType::Half:
5231 case clang::BuiltinType::Float:
5232 case clang::BuiltinType::Double:
5233 case clang::BuiltinType::LongDouble:
5239 case clang::Type::ObjCObjectPointer:
5241 case clang::Type::BlockPointer:
5243 case clang::Type::Pointer:
5245 case clang::Type::LValueReference:
5246 case clang::Type::RValueReference:
5248 case clang::Type::MemberPointer:
5250 case clang::Type::Complex: {
5251 if (qual_type->isComplexType())
5256 case clang::Type::ObjCInterface:
5258 case clang::Type::Record:
5260 case clang::Type::Enum:
5262 case clang::Type::DependentSizedArray:
5263 case clang::Type::DependentSizedExtVector:
5264 case clang::Type::UnresolvedUsing:
5265 case clang::Type::Attributed:
5266 case clang::Type::BTFTagAttributed:
5267 case clang::Type::TemplateTypeParm:
5268 case clang::Type::SubstTemplateTypeParm:
5269 case clang::Type::SubstTemplateTypeParmPack:
5270 case clang::Type::InjectedClassName:
5271 case clang::Type::DependentName:
5272 case clang::Type::DependentTemplateSpecialization:
5273 case clang::Type::PackExpansion:
5274 case clang::Type::ObjCObject:
5276 case clang::Type::TemplateSpecialization:
5277 case clang::Type::DeducedTemplateSpecialization:
5278 case clang::Type::Adjusted:
5279 case clang::Type::Pipe:
5283 case clang::Type::Decayed:
5285 case clang::Type::ObjCTypeParam:
5288 case clang::Type::DependentAddressSpace:
5290 case clang::Type::MacroQualified:
5294 case clang::Type::ConstantMatrix:
5295 case clang::Type::DependentSizedMatrix:
5299 case clang::Type::PackIndexing:
5307 bool check_superclass) {
5308 while (class_interface_decl) {
5309 if (class_interface_decl->ivar_size() > 0)
5312 if (check_superclass)
5313 class_interface_decl = class_interface_decl->getSuperClass();
5320static std::optional<SymbolFile::ArrayInfo>
5322 clang::QualType qual_type,
5324 if (qual_type->isIncompleteArrayType())
5325 if (
auto *metadata = ast.
GetMetadata(qual_type.getTypePtr()))
5328 return std::nullopt;
5331llvm::Expected<uint32_t>
5333 bool omit_empty_base_classes,
5336 return llvm::createStringError(
"invalid clang type");
5338 uint32_t num_children = 0;
5340 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5341 switch (type_class) {
5342 case clang::Type::Builtin:
5343 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5344 case clang::BuiltinType::ObjCId:
5345 case clang::BuiltinType::ObjCClass:
5354 case clang::Type::Complex:
5356 case clang::Type::Record:
5358 const clang::RecordType *record_type =
5359 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5360 const clang::RecordDecl *record_decl = record_type->getDecl();
5361 assert(record_decl);
5362 const clang::CXXRecordDecl *cxx_record_decl =
5363 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5364 if (cxx_record_decl) {
5365 if (omit_empty_base_classes) {
5369 clang::CXXRecordDecl::base_class_const_iterator base_class,
5371 for (base_class = cxx_record_decl->bases_begin(),
5372 base_class_end = cxx_record_decl->bases_end();
5373 base_class != base_class_end; ++base_class) {
5374 const clang::CXXRecordDecl *base_class_decl =
5375 llvm::cast<clang::CXXRecordDecl>(
5376 base_class->getType()
5377 ->getAs<clang::RecordType>()
5388 num_children += cxx_record_decl->getNumBases();
5391 num_children += std::distance(record_decl->field_begin(),
5392 record_decl->field_end());
5394 return llvm::createStringError(
5397 case clang::Type::ObjCObject:
5398 case clang::Type::ObjCInterface:
5400 const clang::ObjCObjectType *objc_class_type =
5401 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5402 assert(objc_class_type);
5403 if (objc_class_type) {
5404 clang::ObjCInterfaceDecl *class_interface_decl =
5405 objc_class_type->getInterface();
5407 if (class_interface_decl) {
5409 clang::ObjCInterfaceDecl *superclass_interface_decl =
5410 class_interface_decl->getSuperClass();
5411 if (superclass_interface_decl) {
5412 if (omit_empty_base_classes) {
5419 num_children += class_interface_decl->ivar_size();
5425 case clang::Type::LValueReference:
5426 case clang::Type::RValueReference:
5427 case clang::Type::ObjCObjectPointer: {
5430 uint32_t num_pointee_children = 0;
5432 auto num_children_or_err =
5433 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5434 if (!num_children_or_err)
5435 return num_children_or_err;
5436 num_pointee_children = *num_children_or_err;
5439 if (num_pointee_children == 0)
5442 num_children = num_pointee_children;
5445 case clang::Type::Vector:
5446 case clang::Type::ExtVector:
5448 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5451 case clang::Type::ConstantArray:
5452 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5456 case clang::Type::IncompleteArray:
5457 if (
auto array_info =
5460 num_children = array_info->element_orders.size()
5461 ? array_info->element_orders.back()
5465 case clang::Type::Pointer: {
5466 const clang::PointerType *pointer_type =
5467 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5468 clang::QualType pointee_type(pointer_type->getPointeeType());
5470 uint32_t num_pointee_children = 0;
5472 auto num_children_or_err =
5473 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5474 if (!num_children_or_err)
5475 return num_children_or_err;
5476 num_pointee_children = *num_children_or_err;
5478 if (num_pointee_children == 0) {
5483 num_children = num_pointee_children;
5489 return num_children;
5500 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5501 if (type_class == clang::Type::Builtin) {
5502 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5503 case clang::BuiltinType::Void:
5505 case clang::BuiltinType::Bool:
5507 case clang::BuiltinType::Char_S:
5509 case clang::BuiltinType::Char_U:
5511 case clang::BuiltinType::Char8:
5513 case clang::BuiltinType::Char16:
5515 case clang::BuiltinType::Char32:
5517 case clang::BuiltinType::UChar:
5519 case clang::BuiltinType::SChar:
5521 case clang::BuiltinType::WChar_S:
5523 case clang::BuiltinType::WChar_U:
5525 case clang::BuiltinType::Short:
5527 case clang::BuiltinType::UShort:
5529 case clang::BuiltinType::Int:
5531 case clang::BuiltinType::UInt:
5533 case clang::BuiltinType::Long:
5535 case clang::BuiltinType::ULong:
5537 case clang::BuiltinType::LongLong:
5539 case clang::BuiltinType::ULongLong:
5541 case clang::BuiltinType::Int128:
5543 case clang::BuiltinType::UInt128:
5546 case clang::BuiltinType::Half:
5548 case clang::BuiltinType::Float:
5550 case clang::BuiltinType::Double:
5552 case clang::BuiltinType::LongDouble:
5555 case clang::BuiltinType::NullPtr:
5557 case clang::BuiltinType::ObjCId:
5559 case clang::BuiltinType::ObjCClass:
5561 case clang::BuiltinType::ObjCSel:
5575 const llvm::APSInt &value)>
const &callback) {
5576 const clang::EnumType *enum_type =
5579 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5583 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5584 for (enum_pos = enum_decl->enumerator_begin(),
5585 enum_end_pos = enum_decl->enumerator_end();
5586 enum_pos != enum_end_pos; ++enum_pos) {
5587 ConstString name(enum_pos->getNameAsString().c_str());
5588 if (!callback(integer_type, name, enum_pos->getInitVal()))
5595#pragma mark Aggregate Types
5603 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5604 switch (type_class) {
5605 case clang::Type::Record:
5607 const clang::RecordType *record_type =
5608 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5610 clang::RecordDecl *record_decl = record_type->getDecl();
5612 count = std::distance(record_decl->field_begin(),
5613 record_decl->field_end());
5619 case clang::Type::ObjCObjectPointer: {
5620 const clang::ObjCObjectPointerType *objc_class_type =
5621 qual_type->castAs<clang::ObjCObjectPointerType>();
5622 const clang::ObjCInterfaceType *objc_interface_type =
5623 objc_class_type->getInterfaceType();
5624 if (objc_interface_type &&
5626 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5627 clang::ObjCInterfaceDecl *class_interface_decl =
5628 objc_interface_type->getDecl();
5629 if (class_interface_decl) {
5630 count = class_interface_decl->ivar_size();
5636 case clang::Type::ObjCObject:
5637 case clang::Type::ObjCInterface:
5639 const clang::ObjCObjectType *objc_class_type =
5640 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5641 if (objc_class_type) {
5642 clang::ObjCInterfaceDecl *class_interface_decl =
5643 objc_class_type->getInterface();
5645 if (class_interface_decl)
5646 count = class_interface_decl->ivar_size();
5659 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5660 std::string &name, uint64_t *bit_offset_ptr,
5661 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5662 if (class_interface_decl) {
5663 if (idx < (class_interface_decl->ivar_size())) {
5664 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5665 ivar_end = class_interface_decl->ivar_end();
5666 uint32_t ivar_idx = 0;
5668 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5669 ++ivar_pos, ++ivar_idx) {
5670 if (ivar_idx == idx) {
5671 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5673 clang::QualType ivar_qual_type(ivar_decl->getType());
5675 name.assign(ivar_decl->getNameAsString());
5677 if (bit_offset_ptr) {
5678 const clang::ASTRecordLayout &interface_layout =
5679 ast->getASTObjCInterfaceLayout(class_interface_decl);
5680 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5683 const bool is_bitfield = ivar_pos->isBitField();
5685 if (bitfield_bit_size_ptr) {
5686 *bitfield_bit_size_ptr = 0;
5688 if (is_bitfield && ast) {
5689 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5690 clang::Expr::EvalResult result;
5691 if (bitfield_bit_size_expr &&
5692 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5693 llvm::APSInt bitfield_apsint = result.Val.getInt();
5694 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5698 if (is_bitfield_ptr)
5699 *is_bitfield_ptr = is_bitfield;
5701 return ivar_qual_type.getAsOpaquePtr();
5710 size_t idx, std::string &name,
5711 uint64_t *bit_offset_ptr,
5712 uint32_t *bitfield_bit_size_ptr,
5713 bool *is_bitfield_ptr) {
5718 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5719 switch (type_class) {
5720 case clang::Type::Record:
5722 const clang::RecordType *record_type =
5723 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5724 const clang::RecordDecl *record_decl = record_type->getDecl();
5725 uint32_t field_idx = 0;
5726 clang::RecordDecl::field_iterator field, field_end;
5727 for (field = record_decl->field_begin(),
5728 field_end = record_decl->field_end();
5729 field != field_end; ++field, ++field_idx) {
5730 if (idx == field_idx) {
5733 name.assign(field->getNameAsString());
5737 if (bit_offset_ptr) {
5738 const clang::ASTRecordLayout &record_layout =
5740 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5743 const bool is_bitfield = field->isBitField();
5745 if (bitfield_bit_size_ptr) {
5746 *bitfield_bit_size_ptr = 0;
5749 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5750 clang::Expr::EvalResult result;
5751 if (bitfield_bit_size_expr &&
5752 bitfield_bit_size_expr->EvaluateAsInt(result,
5754 llvm::APSInt bitfield_apsint = result.Val.getInt();
5755 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5759 if (is_bitfield_ptr)
5760 *is_bitfield_ptr = is_bitfield;
5762 return GetType(field->getType());
5768 case clang::Type::ObjCObjectPointer: {
5769 const clang::ObjCObjectPointerType *objc_class_type =
5770 qual_type->castAs<clang::ObjCObjectPointerType>();
5771 const clang::ObjCInterfaceType *objc_interface_type =
5772 objc_class_type->getInterfaceType();
5773 if (objc_interface_type &&
5775 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5776 clang::ObjCInterfaceDecl *class_interface_decl =
5777 objc_interface_type->getDecl();
5778 if (class_interface_decl) {
5782 name, bit_offset_ptr, bitfield_bit_size_ptr,
5789 case clang::Type::ObjCObject:
5790 case clang::Type::ObjCInterface:
5792 const clang::ObjCObjectType *objc_class_type =
5793 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5794 assert(objc_class_type);
5795 if (objc_class_type) {
5796 clang::ObjCInterfaceDecl *class_interface_decl =
5797 objc_class_type->getInterface();
5801 name, bit_offset_ptr, bitfield_bit_size_ptr,
5817 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5818 switch (type_class) {
5819 case clang::Type::Record:
5821 const clang::CXXRecordDecl *cxx_record_decl =
5822 qual_type->getAsCXXRecordDecl();
5823 if (cxx_record_decl)
5824 count = cxx_record_decl->getNumBases();
5828 case clang::Type::ObjCObjectPointer:
5832 case clang::Type::ObjCObject:
5834 const clang::ObjCObjectType *objc_class_type =
5835 qual_type->getAsObjCQualifiedInterfaceType();
5836 if (objc_class_type) {
5837 clang::ObjCInterfaceDecl *class_interface_decl =
5838 objc_class_type->getInterface();
5840 if (class_interface_decl && class_interface_decl->getSuperClass())
5845 case clang::Type::ObjCInterface:
5847 const clang::ObjCInterfaceType *objc_interface_type =
5848 qual_type->getAs<clang::ObjCInterfaceType>();
5849 if (objc_interface_type) {
5850 clang::ObjCInterfaceDecl *class_interface_decl =
5851 objc_interface_type->getInterface();
5853 if (class_interface_decl && class_interface_decl->getSuperClass())
5869 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5870 switch (type_class) {
5871 case clang::Type::Record:
5873 const clang::CXXRecordDecl *cxx_record_decl =
5874 qual_type->getAsCXXRecordDecl();
5875 if (cxx_record_decl)
5876 count = cxx_record_decl->getNumVBases();
5889 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5890 switch (type_class) {
5891 case clang::Type::Record:
5893 const clang::CXXRecordDecl *cxx_record_decl =
5894 qual_type->getAsCXXRecordDecl();
5895 if (cxx_record_decl) {
5896 uint32_t curr_idx = 0;
5897 clang::CXXRecordDecl::base_class_const_iterator base_class,
5899 for (base_class = cxx_record_decl->bases_begin(),
5900 base_class_end = cxx_record_decl->bases_end();
5901 base_class != base_class_end; ++base_class, ++curr_idx) {
5902 if (curr_idx == idx) {
5903 if (bit_offset_ptr) {
5904 const clang::ASTRecordLayout &record_layout =
5906 const clang::CXXRecordDecl *base_class_decl =
5907 llvm::cast<clang::CXXRecordDecl>(
5908 base_class->getType()
5909 ->castAs<clang::RecordType>()
5911 if (base_class->isVirtual())
5913 record_layout.getVBaseClassOffset(base_class_decl)
5918 record_layout.getBaseClassOffset(base_class_decl)
5922 return GetType(base_class->getType());
5929 case clang::Type::ObjCObjectPointer:
5932 case clang::Type::ObjCObject:
5934 const clang::ObjCObjectType *objc_class_type =
5935 qual_type->getAsObjCQualifiedInterfaceType();
5936 if (objc_class_type) {
5937 clang::ObjCInterfaceDecl *class_interface_decl =
5938 objc_class_type->getInterface();
5940 if (class_interface_decl) {
5941 clang::ObjCInterfaceDecl *superclass_interface_decl =
5942 class_interface_decl->getSuperClass();
5943 if (superclass_interface_decl) {
5945 *bit_offset_ptr = 0;
5947 superclass_interface_decl));
5953 case clang::Type::ObjCInterface:
5955 const clang::ObjCObjectType *objc_interface_type =
5956 qual_type->getAs<clang::ObjCInterfaceType>();
5957 if (objc_interface_type) {
5958 clang::ObjCInterfaceDecl *class_interface_decl =
5959 objc_interface_type->getInterface();
5961 if (class_interface_decl) {
5962 clang::ObjCInterfaceDecl *superclass_interface_decl =
5963 class_interface_decl->getSuperClass();
5964 if (superclass_interface_decl) {
5966 *bit_offset_ptr = 0;
5968 superclass_interface_decl));
5984 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5985 switch (type_class) {
5986 case clang::Type::Record:
5988 const clang::CXXRecordDecl *cxx_record_decl =
5989 qual_type->getAsCXXRecordDecl();
5990 if (cxx_record_decl) {
5991 uint32_t curr_idx = 0;
5992 clang::CXXRecordDecl::base_class_const_iterator base_class,
5994 for (base_class = cxx_record_decl->vbases_begin(),
5995 base_class_end = cxx_record_decl->vbases_end();
5996 base_class != base_class_end; ++base_class, ++curr_idx) {
5997 if (curr_idx == idx) {
5998 if (bit_offset_ptr) {
5999 const clang::ASTRecordLayout &record_layout =
6001 const clang::CXXRecordDecl *base_class_decl =
6002 llvm::cast<clang::CXXRecordDecl>(
6003 base_class->getType()
6004 ->castAs<clang::RecordType>()
6007 record_layout.getVBaseClassOffset(base_class_decl)
6011 return GetType(base_class->getType());
6026 llvm::StringRef name) {
6028 switch (qual_type->getTypeClass()) {
6029 case clang::Type::Record: {
6033 const clang::RecordType *record_type =
6034 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6035 const clang::RecordDecl *record_decl = record_type->getDecl();
6037 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
6038 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
6039 auto *var_decl = dyn_cast<clang::VarDecl>(decl);
6040 if (!var_decl || var_decl->getStorageClass() != clang::SC_Static)
6064 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6065 switch (type_class) {
6066 case clang::Type::Builtin:
6067 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
6068 case clang::BuiltinType::UnknownAny:
6069 case clang::BuiltinType::Void:
6070 case clang::BuiltinType::NullPtr:
6071 case clang::BuiltinType::OCLEvent:
6072 case clang::BuiltinType::OCLImage1dRO:
6073 case clang::BuiltinType::OCLImage1dWO:
6074 case clang::BuiltinType::OCLImage1dRW:
6075 case clang::BuiltinType::OCLImage1dArrayRO:
6076 case clang::BuiltinType::OCLImage1dArrayWO:
6077 case clang::BuiltinType::OCLImage1dArrayRW:
6078 case clang::BuiltinType::OCLImage1dBufferRO:
6079 case clang::BuiltinType::OCLImage1dBufferWO:
6080 case clang::BuiltinType::OCLImage1dBufferRW:
6081 case clang::BuiltinType::OCLImage2dRO:
6082 case clang::BuiltinType::OCLImage2dWO:
6083 case clang::BuiltinType::OCLImage2dRW:
6084 case clang::BuiltinType::OCLImage2dArrayRO:
6085 case clang::BuiltinType::OCLImage2dArrayWO:
6086 case clang::BuiltinType::OCLImage2dArrayRW:
6087 case clang::BuiltinType::OCLImage3dRO:
6088 case clang::BuiltinType::OCLImage3dWO:
6089 case clang::BuiltinType::OCLImage3dRW:
6090 case clang::BuiltinType::OCLSampler:
6092 case clang::BuiltinType::Bool:
6093 case clang::BuiltinType::Char_U:
6094 case clang::BuiltinType::UChar:
6095 case clang::BuiltinType::WChar_U:
6096 case clang::BuiltinType::Char16:
6097 case clang::BuiltinType::Char32:
6098 case clang::BuiltinType::UShort:
6099 case clang::BuiltinType::UInt:
6100 case clang::BuiltinType::ULong:
6101 case clang::BuiltinType::ULongLong:
6102 case clang::BuiltinType::UInt128:
6103 case clang::BuiltinType::Char_S:
6104 case clang::BuiltinType::SChar:
6105 case clang::BuiltinType::WChar_S:
6106 case clang::BuiltinType::Short:
6107 case clang::BuiltinType::Int:
6108 case clang::BuiltinType::Long:
6109 case clang::BuiltinType::LongLong:
6110 case clang::BuiltinType::Int128:
6111 case clang::BuiltinType::Float:
6112 case clang::BuiltinType::Double:
6113 case clang::BuiltinType::LongDouble:
6114 case clang::BuiltinType::Dependent:
6115 case clang::BuiltinType::Overload:
6116 case clang::BuiltinType::ObjCId:
6117 case clang::BuiltinType::ObjCClass:
6118 case clang::BuiltinType::ObjCSel:
6119 case clang::BuiltinType::BoundMember:
6120 case clang::BuiltinType::Half:
6121 case clang::BuiltinType::ARCUnbridgedCast:
6122 case clang::BuiltinType::PseudoObject:
6123 case clang::BuiltinType::BuiltinFn:
6124 case clang::BuiltinType::ArraySection:
6131 case clang::Type::Complex:
6133 case clang::Type::Pointer:
6135 case clang::Type::BlockPointer:
6138 case clang::Type::LValueReference:
6140 case clang::Type::RValueReference:
6142 case clang::Type::MemberPointer:
6144 case clang::Type::ConstantArray:
6146 case clang::Type::IncompleteArray:
6148 case clang::Type::VariableArray:
6150 case clang::Type::DependentSizedArray:
6152 case clang::Type::DependentSizedExtVector:
6154 case clang::Type::Vector:
6156 case clang::Type::ExtVector:
6158 case clang::Type::FunctionProto:
6160 case clang::Type::FunctionNoProto:
6162 case clang::Type::UnresolvedUsing:
6164 case clang::Type::Record:
6166 case clang::Type::Enum:
6168 case clang::Type::TemplateTypeParm:
6170 case clang::Type::SubstTemplateTypeParm:
6172 case clang::Type::TemplateSpecialization:
6174 case clang::Type::InjectedClassName:
6176 case clang::Type::DependentName:
6178 case clang::Type::DependentTemplateSpecialization:
6180 case clang::Type::ObjCObject:
6182 case clang::Type::ObjCInterface:
6184 case clang::Type::ObjCObjectPointer:
6194 bool transparent_pointers,
bool omit_empty_base_classes,
6195 bool ignore_array_bounds, std::string &child_name,
6196 uint32_t &child_byte_size, int32_t &child_byte_offset,
6197 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6198 bool &child_is_base_class,
bool &child_is_deref_of_parent,
6203 auto get_exe_scope = [&exe_ctx]() {
6207 clang::QualType parent_qual_type(
6209 const clang::Type::TypeClass parent_type_class =
6210 parent_qual_type->getTypeClass();
6211 child_bitfield_bit_size = 0;
6212 child_bitfield_bit_offset = 0;
6213 child_is_base_class =
false;
6216 auto num_children_or_err =
6218 if (!num_children_or_err)
6219 return num_children_or_err.takeError();
6221 const bool idx_is_valid = idx < *num_children_or_err;
6223 switch (parent_type_class) {
6224 case clang::Type::Builtin:
6226 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) {
6227 case clang::BuiltinType::ObjCId:
6228 case clang::BuiltinType::ObjCClass:
6241 case clang::Type::Record:
6243 const clang::RecordType *record_type =
6244 llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6245 const clang::RecordDecl *record_decl = record_type->getDecl();
6246 assert(record_decl);
6247 const clang::ASTRecordLayout &record_layout =
6249 uint32_t child_idx = 0;
6251 const clang::CXXRecordDecl *cxx_record_decl =
6252 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6253 if (cxx_record_decl) {
6255 clang::CXXRecordDecl::base_class_const_iterator base_class,
6257 for (base_class = cxx_record_decl->bases_begin(),
6258 base_class_end = cxx_record_decl->bases_end();
6259 base_class != base_class_end; ++base_class) {
6260 const clang::CXXRecordDecl *base_class_decl =
nullptr;
6263 if (omit_empty_base_classes) {
6264 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6265 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6270 if (idx == child_idx) {
6271 if (base_class_decl ==
nullptr)
6272 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6273 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6275 if (base_class->isVirtual()) {
6276 bool handled =
false;
6278 clang::VTableContextBase *vtable_ctx =
6282 record_layout, cxx_record_decl,
6283 base_class_decl, bit_offset);
6286 bit_offset = record_layout.getVBaseClassOffset(base_class_decl)
6290 bit_offset = record_layout.getBaseClassOffset(base_class_decl)
6295 child_byte_offset = bit_offset / 8;
6298 std::optional<uint64_t> size =
6299 base_class_clang_type.
GetBitSize(get_exe_scope());
6301 return llvm::createStringError(
"no size info for base class");
6303 uint64_t base_class_clang_type_bit_size = *size;
6306 assert(base_class_clang_type_bit_size % 8 == 0);
6307 child_byte_size = base_class_clang_type_bit_size / 8;
6308 child_is_base_class =
true;
6309 return base_class_clang_type;
6317 uint32_t field_idx = 0;
6318 clang::RecordDecl::field_iterator field, field_end;
6319 for (field = record_decl->field_begin(),
6320 field_end = record_decl->field_end();
6321 field != field_end; ++field, ++field_idx, ++child_idx) {
6322 if (idx == child_idx) {
6325 child_name.assign(field->getNameAsString());
6330 assert(field_idx < record_layout.getFieldCount());
6331 std::optional<uint64_t> size =
6334 return llvm::createStringError(
"no size info for field");
6336 child_byte_size = *size;
6337 const uint32_t child_bit_size = child_byte_size * 8;
6341 bit_offset = record_layout.getFieldOffset(field_idx);
6343 child_bitfield_bit_offset = bit_offset % child_bit_size;
6344 const uint32_t child_bit_offset =
6345 bit_offset - child_bitfield_bit_offset;
6346 child_byte_offset = child_bit_offset / 8;
6348 child_byte_offset = bit_offset / 8;
6351 return field_clang_type;
6357 case clang::Type::ObjCObject:
6358 case clang::Type::ObjCInterface:
6360 const clang::ObjCObjectType *objc_class_type =
6361 llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6362 assert(objc_class_type);
6363 if (objc_class_type) {
6364 uint32_t child_idx = 0;
6365 clang::ObjCInterfaceDecl *class_interface_decl =
6366 objc_class_type->getInterface();
6368 if (class_interface_decl) {
6370 const clang::ASTRecordLayout &interface_layout =
6371 getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
6372 clang::ObjCInterfaceDecl *superclass_interface_decl =
6373 class_interface_decl->getSuperClass();
6374 if (superclass_interface_decl) {
6375 if (omit_empty_base_classes) {
6378 superclass_interface_decl));
6379 if (llvm::expectedToStdOptional(
6381 omit_empty_base_classes, exe_ctx))
6384 clang::QualType ivar_qual_type(
6386 superclass_interface_decl));
6389 superclass_interface_decl->getNameAsString());
6391 clang::TypeInfo ivar_type_info =
6394 child_byte_size = ivar_type_info.Width / 8;
6395 child_byte_offset = 0;
6396 child_is_base_class =
true;
6398 return GetType(ivar_qual_type);
6407 const uint32_t superclass_idx = child_idx;
6409 if (idx < (child_idx + class_interface_decl->ivar_size())) {
6410 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6411 ivar_end = class_interface_decl->ivar_end();
6413 for (ivar_pos = class_interface_decl->ivar_begin();
6414 ivar_pos != ivar_end; ++ivar_pos) {
6415 if (child_idx == idx) {
6416 clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6418 clang::QualType ivar_qual_type(ivar_decl->getType());
6420 child_name.assign(ivar_decl->getNameAsString());
6422 clang::TypeInfo ivar_type_info =
6425 child_byte_size = ivar_type_info.Width / 8;
6441 if (objc_runtime !=
nullptr) {
6444 parent_ast_type, ivar_decl->getNameAsString().c_str());
6452 if (child_byte_offset ==
6454 bit_offset = interface_layout.getFieldOffset(child_idx -
6456 child_byte_offset = bit_offset / 8;
6467 bit_offset = interface_layout.getFieldOffset(
6468 child_idx - superclass_idx);
6470 child_bitfield_bit_offset = bit_offset % 8;
6472 return GetType(ivar_qual_type);
6482 case clang::Type::ObjCObjectPointer:
6487 child_is_deref_of_parent =
false;
6488 bool tmp_child_is_deref_of_parent =
false;
6490 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6491 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6492 child_bitfield_bit_size, child_bitfield_bit_offset,
6493 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6496 child_is_deref_of_parent =
true;
6497 const char *parent_name =
6500 child_name.assign(1,
'*');
6501 child_name += parent_name;
6506 if (std::optional<uint64_t> size =
6507 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6508 child_byte_size = *size;
6509 child_byte_offset = 0;
6510 return pointee_clang_type;
6517 case clang::Type::Vector:
6518 case clang::Type::ExtVector:
6520 const clang::VectorType *array =
6521 llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6525 char element_name[64];
6526 ::snprintf(element_name,
sizeof(element_name),
"[%" PRIu64
"]",
6527 static_cast<uint64_t
>(idx));
6528 child_name.assign(element_name);
6529 if (std::optional<uint64_t> size =
6531 child_byte_size = *size;
6532 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6533 return element_type;
6540 case clang::Type::ConstantArray:
6541 case clang::Type::IncompleteArray:
6542 if (ignore_array_bounds || idx_is_valid) {
6543 const clang::ArrayType *array =
GetQualType(type)->getAsArrayTypeUnsafe();
6547 child_name = std::string(llvm::formatv(
"[{0}]", idx));
6548 if (std::optional<uint64_t> size =
6550 child_byte_size = *size;
6551 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6552 return element_type;
6559 case clang::Type::Pointer: {
6567 child_is_deref_of_parent =
false;
6568 bool tmp_child_is_deref_of_parent =
false;
6570 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6571 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6572 child_bitfield_bit_size, child_bitfield_bit_offset,
6573 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6576 child_is_deref_of_parent =
true;
6578 const char *parent_name =
6581 child_name.assign(1,
'*');
6582 child_name += parent_name;
6587 if (std::optional<uint64_t> size =
6588 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6589 child_byte_size = *size;
6590 child_byte_offset = 0;
6591 return pointee_clang_type;
6598 case clang::Type::LValueReference:
6599 case clang::Type::RValueReference:
6601 const clang::ReferenceType *reference_type =
6602 llvm::cast<clang::ReferenceType>(
6605 GetType(reference_type->getPointeeType());
6607 child_is_deref_of_parent =
false;
6608 bool tmp_child_is_deref_of_parent =
false;
6610 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6611 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6612 child_bitfield_bit_size, child_bitfield_bit_offset,
6613 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6616 const char *parent_name =
6619 child_name.assign(1,
'&');
6620 child_name += parent_name;
6625 if (std::optional<uint64_t> size =
6626 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6627 child_byte_size = *size;
6628 child_byte_offset = 0;
6629 return pointee_clang_type;
6643 const clang::RecordDecl *record_decl,
6644 const clang::CXXBaseSpecifier *base_spec,
6645 bool omit_empty_base_classes) {
6646 uint32_t child_idx = 0;
6648 const clang::CXXRecordDecl *cxx_record_decl =
6649 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6651 if (cxx_record_decl) {
6652 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6653 for (base_class = cxx_record_decl->bases_begin(),
6654 base_class_end = cxx_record_decl->bases_end();
6655 base_class != base_class_end; ++base_class) {
6656 if (omit_empty_base_classes) {
6661 if (base_class == base_spec)
6671 const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl,
6672 bool omit_empty_base_classes) {
6674 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6675 omit_empty_base_classes);
6677 clang::RecordDecl::field_iterator field, field_end;
6678 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6679 field != field_end; ++field, ++child_idx) {
6680 if (field->getCanonicalDecl() == canonical_decl)
6722 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
6723 if (type && !name.empty()) {
6725 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6726 switch (type_class) {
6727 case clang::Type::Record:
6729 const clang::RecordType *record_type =
6730 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6731 const clang::RecordDecl *record_decl = record_type->getDecl();
6733 assert(record_decl);
6734 uint32_t child_idx = 0;
6736 const clang::CXXRecordDecl *cxx_record_decl =
6737 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6740 clang::RecordDecl::field_iterator field, field_end;
6741 for (field = record_decl->field_begin(),
6742 field_end = record_decl->field_end();
6743 field != field_end; ++field, ++child_idx) {
6744 llvm::StringRef field_name = field->getName();
6745 if (field_name.empty()) {
6747 child_indexes.push_back(child_idx);
6749 name, omit_empty_base_classes, child_indexes))
6750 return child_indexes.size();
6751 child_indexes.pop_back();
6753 }
else if (field_name == name) {
6755 child_indexes.push_back(
6757 cxx_record_decl, omit_empty_base_classes));
6758 return child_indexes.size();
6762 if (cxx_record_decl) {
6763 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6766 clang::IdentifierInfo &ident_ref =
getASTContext().Idents.get(name);
6767 clang::DeclarationName decl_name(&ident_ref);
6769 clang::CXXBasePaths paths;
6770 if (cxx_record_decl->lookupInBases(
6771 [decl_name](
const clang::CXXBaseSpecifier *specifier,
6772 clang::CXXBasePath &path) {
6773 CXXRecordDecl *record =
6774 specifier->getType()->getAsCXXRecordDecl();
6775 auto r = record->lookup(decl_name);
6776 path.Decls = r.begin();
6780 clang::CXXBasePaths::const_paths_iterator path,
6781 path_end = paths.end();
6782 for (path = paths.begin(); path != path_end; ++path) {
6783 const size_t num_path_elements = path->size();
6784 for (
size_t e = 0; e < num_path_elements; ++e) {
6785 clang::CXXBasePathElement elem = (*path)[e];
6788 omit_empty_base_classes);
6790 child_indexes.clear();
6793 child_indexes.push_back(child_idx);
6794 parent_record_decl = llvm::cast<clang::RecordDecl>(
6795 elem.Base->getType()
6796 ->castAs<clang::RecordType>()
6800 for (clang::DeclContext::lookup_iterator I = path->Decls, E;
6803 parent_record_decl, *I, omit_empty_base_classes);
6805 child_indexes.clear();
6808 child_indexes.push_back(child_idx);
6812 return child_indexes.size();
6818 case clang::Type::ObjCObject:
6819 case clang::Type::ObjCInterface:
6821 llvm::StringRef name_sref(name);
6822 const clang::ObjCObjectType *objc_class_type =
6823 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6824 assert(objc_class_type);
6825 if (objc_class_type) {
6826 uint32_t child_idx = 0;
6827 clang::ObjCInterfaceDecl *class_interface_decl =
6828 objc_class_type->getInterface();
6830 if (class_interface_decl) {
6831 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6832 ivar_end = class_interface_decl->ivar_end();
6833 clang::ObjCInterfaceDecl *superclass_interface_decl =
6834 class_interface_decl->getSuperClass();
6836 for (ivar_pos = class_interface_decl->ivar_begin();
6837 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6838 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6840 if (ivar_decl->getName() == name_sref) {
6841 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6842 (omit_empty_base_classes &&
6846 child_indexes.push_back(child_idx);
6847 return child_indexes.size();
6851 if (superclass_interface_decl) {
6855 child_indexes.push_back(0);
6859 superclass_interface_decl));
6861 name, omit_empty_base_classes, child_indexes)) {
6864 return child_indexes.size();
6869 child_indexes.pop_back();
6876 case clang::Type::ObjCObjectPointer: {
6878 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6879 ->getPointeeType());
6881 name, omit_empty_base_classes, child_indexes);
6884 case clang::Type::ConstantArray: {
6924 case clang::Type::LValueReference:
6925 case clang::Type::RValueReference: {
6926 const clang::ReferenceType *reference_type =
6927 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6928 clang::QualType pointee_type(reference_type->getPointeeType());
6933 name, omit_empty_base_classes, child_indexes);
6937 case clang::Type::Pointer: {
6942 name, omit_empty_base_classes, child_indexes);
6959 llvm::StringRef name,
6960 bool omit_empty_base_classes) {
6961 if (type && !name.empty()) {
6964 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6966 switch (type_class) {
6967 case clang::Type::Record:
6969 const clang::RecordType *record_type =
6970 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6971 const clang::RecordDecl *record_decl = record_type->getDecl();
6973 assert(record_decl);
6974 uint32_t child_idx = 0;
6976 const clang::CXXRecordDecl *cxx_record_decl =
6977 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6979 if (cxx_record_decl) {
6980 clang::CXXRecordDecl::base_class_const_iterator base_class,
6982 for (base_class = cxx_record_decl->bases_begin(),
6983 base_class_end = cxx_record_decl->bases_end();
6984 base_class != base_class_end; ++base_class) {
6986 clang::CXXRecordDecl *base_class_decl =
6987 llvm::cast<clang::CXXRecordDecl>(
6988 base_class->getType()
6989 ->castAs<clang::RecordType>()
6991 if (omit_empty_base_classes &&
6996 std::string base_class_type_name(
6998 if (base_class_type_name == name)
7005 clang::RecordDecl::field_iterator field, field_end;
7006 for (field = record_decl->field_begin(),
7007 field_end = record_decl->field_end();
7008 field != field_end; ++field, ++child_idx) {
7009 if (field->getName() == name)
7015 case clang::Type::ObjCObject:
7016 case clang::Type::ObjCInterface:
7018 const clang::ObjCObjectType *objc_class_type =
7019 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
7020 assert(objc_class_type);
7021 if (objc_class_type) {
7022 uint32_t child_idx = 0;
7023 clang::ObjCInterfaceDecl *class_interface_decl =
7024 objc_class_type->getInterface();
7026 if (class_interface_decl) {
7027 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
7028 ivar_end = class_interface_decl->ivar_end();
7029 clang::ObjCInterfaceDecl *superclass_interface_decl =
7030 class_interface_decl->getSuperClass();
7032 for (ivar_pos = class_interface_decl->ivar_begin();
7033 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
7034 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
7036 if (ivar_decl->getName() == name) {
7037 if ((!omit_empty_base_classes && superclass_interface_decl) ||
7038 (omit_empty_base_classes &&
7046 if (superclass_interface_decl) {
7047 if (superclass_interface_decl->getName() == name)
7055 case clang::Type::ObjCObjectPointer: {
7057 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
7058 ->getPointeeType());
7060 name, omit_empty_base_classes);
7063 case clang::Type::ConstantArray: {
7103 case clang::Type::LValueReference:
7104 case clang::Type::RValueReference: {
7105 const clang::ReferenceType *reference_type =
7106 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
7111 omit_empty_base_classes);
7115 case clang::Type::Pointer: {
7116 const clang::PointerType *pointer_type =
7117 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
7122 omit_empty_base_classes);
7152 llvm::StringRef name) {
7153 if (!type || name.empty())
7157 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7159 switch (type_class) {
7160 case clang::Type::Record: {
7163 const clang::RecordType *record_type =
7164 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7165 const clang::RecordDecl *record_decl = record_type->getDecl();
7167 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7168 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
7169 if (
auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
7171 if (
auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl))
7187 if (
auto *cxx_record_decl = dyn_cast<clang::TagType>(clang_type))
7188 return isa<clang::ClassTemplateSpecializationDecl>(
7189 cxx_record_decl->getDecl());
7200 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7201 switch (type_class) {
7202 case clang::Type::Record:
7204 const clang::CXXRecordDecl *cxx_record_decl =
7205 qual_type->getAsCXXRecordDecl();
7206 if (cxx_record_decl) {
7207 const clang::ClassTemplateSpecializationDecl *template_decl =
7208 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7210 if (template_decl) {
7211 const auto &template_arg_list = template_decl->getTemplateArgs();
7212 size_t num_args = template_arg_list.size();
7213 assert(num_args &&
"template specialization without any args");
7214 if (expand_pack && num_args) {
7215 const auto &pack = template_arg_list[num_args - 1];
7216 if (pack.getKind() == clang::TemplateArgument::Pack)
7217 num_args += pack.pack_size() - 1;
7232const clang::ClassTemplateSpecializationDecl *
7239 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7240 switch (type_class) {
7241 case clang::Type::Record: {
7244 const clang::CXXRecordDecl *cxx_record_decl =
7245 qual_type->getAsCXXRecordDecl();
7246 if (!cxx_record_decl)
7248 return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7257const TemplateArgument *
7259 size_t idx,
bool expand_pack) {
7260 const auto &args = decl->getTemplateArgs();
7261 const size_t args_size = args.size();
7263 assert(args_size &&
"template specialization without any args");
7267 const size_t last_idx = args_size - 1;
7276 if (!expand_pack || args[last_idx].getKind() != clang::TemplateArgument::Pack)
7277 return idx >= args.size() ? nullptr : &args[idx];
7282 const auto &pack = args[last_idx];
7283 const size_t pack_idx = idx - last_idx;
7284 if (pack_idx >= pack.pack_size())
7286 return &pack.pack_elements()[pack_idx];
7291 size_t arg_idx,
bool expand_pack) {
7292 const clang::ClassTemplateSpecializationDecl *template_decl =
7301 switch (arg->getKind()) {
7302 case clang::TemplateArgument::Null:
7305 case clang::TemplateArgument::NullPtr:
7308 case clang::TemplateArgument::Type:
7311 case clang::TemplateArgument::Declaration:
7314 case clang::TemplateArgument::Integral:
7317 case clang::TemplateArgument::Template:
7320 case clang::TemplateArgument::TemplateExpansion:
7323 case clang::TemplateArgument::Expression:
7326 case clang::TemplateArgument::Pack:
7329 case clang::TemplateArgument::StructuralValue:
7332 llvm_unreachable(
"Unhandled clang::TemplateArgument::ArgKind");
7337 size_t idx,
bool expand_pack) {
7338 const clang::ClassTemplateSpecializationDecl *template_decl =
7344 if (!arg || arg->getKind() != clang::TemplateArgument::Type)
7347 return GetType(arg->getAsType());
7350std::optional<CompilerType::IntegralTemplateArgument>
7352 size_t idx,
bool expand_pack) {
7353 const clang::ClassTemplateSpecializationDecl *template_decl =
7356 return std::nullopt;
7359 if (!arg || arg->getKind() != clang::TemplateArgument::Integral)
7360 return std::nullopt;
7362 return {{arg->getAsIntegral(),
GetType(arg->getIntegralType())}};
7372 const clang::EnumType *enutype =
7375 return enutype->getDecl();
7380 const clang::RecordType *record_type =
7383 return record_type->getDecl();
7391clang::TypedefNameDecl *
7393 const clang::TypedefType *typedef_type =
7396 return typedef_type->getDecl();
7400clang::CXXRecordDecl *
7405clang::ObjCInterfaceDecl *
7407 const clang::ObjCObjectType *objc_class_type =
7408 llvm::dyn_cast<clang::ObjCObjectType>(
7410 if (objc_class_type)
7411 return objc_class_type->getInterface();
7418 uint32_t bitfield_bit_size) {
7426 clang::IdentifierInfo *ident =
nullptr;
7428 ident = &clang_ast.Idents.get(name);
7430 clang::FieldDecl *field =
nullptr;
7432 clang::Expr *bit_width =
nullptr;
7433 if (bitfield_bit_size != 0) {
7434 llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
7436 bit_width =
new (clang_ast)
7437 clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
7438 clang_ast.IntTy, clang::SourceLocation());
7441 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7443 field = clang::FieldDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7444 field->setDeclContext(record_decl);
7445 field->setDeclName(ident);
7448 field->setBitWidth(bit_width);
7454 if (
const clang::TagType *TagT =
7455 field->getType()->getAs<clang::TagType>()) {
7456 if (clang::RecordDecl *Rec =
7457 llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7458 if (!Rec->getDeclName()) {
7459 Rec->setAnonymousStructOrUnion(
true);
7460 field->setImplicit();
7466 clang::AccessSpecifier access_specifier =
7468 field->setAccess(access_specifier);
7470 if (clang::CXXRecordDecl *cxx_record_decl =
7471 llvm::dyn_cast<CXXRecordDecl>(record_decl)) {
7472 AddAccessSpecifierDecl(cxx_record_decl, ast->getASTContext(),
7473 ast->GetCXXRecordDeclAccess(cxx_record_decl),
7475 ast->SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
7477 record_decl->addDecl(field);
7482 clang::ObjCInterfaceDecl *class_interface_decl =
7483 ast->GetAsObjCInterfaceDecl(type);
7485 if (class_interface_decl) {
7486 const bool is_synthesized =
false;
7491 clang::ObjCIvarDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7492 ivar->setDeclContext(class_interface_decl);
7493 ivar->setDeclName(ident);
7497 ivar->setBitWidth(bit_width);
7498 ivar->setSynthesize(is_synthesized);
7503 class_interface_decl->addDecl(field);
7526 typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7528 IndirectFieldVector indirect_fields;
7529 clang::RecordDecl::field_iterator field_pos;
7530 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7531 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7532 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos;
7533 last_field_pos = field_pos++) {
7534 if (field_pos->isAnonymousStructOrUnion()) {
7535 clang::QualType field_qual_type = field_pos->getType();
7537 const clang::RecordType *field_record_type =
7538 field_qual_type->getAs<clang::RecordType>();
7540 if (!field_record_type)
7543 clang::RecordDecl *field_record_decl = field_record_type->getDecl();
7545 if (!field_record_decl)
7548 for (clang::RecordDecl::decl_iterator
7549 di = field_record_decl->decls_begin(),
7550 de = field_record_decl->decls_end();
7552 if (clang::FieldDecl *nested_field_decl =
7553 llvm::dyn_cast<clang::FieldDecl>(*di)) {
7554 clang::NamedDecl **chain =
7555 new (ast->getASTContext()) clang::NamedDecl *[2];
7556 chain[0] = *field_pos;
7557 chain[1] = nested_field_decl;
7558 clang::IndirectFieldDecl *indirect_field =
7559 clang::IndirectFieldDecl::Create(
7560 ast->getASTContext(), record_decl, clang::SourceLocation(),
7561 nested_field_decl->getIdentifier(),
7562 nested_field_decl->getType(), {chain, 2});
7565 indirect_field->setImplicit();
7568 field_pos->getAccess(), nested_field_decl->getAccess()));
7570 indirect_fields.push_back(indirect_field);
7571 }
else if (clang::IndirectFieldDecl *nested_indirect_field_decl =
7572 llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
7573 size_t nested_chain_size =
7574 nested_indirect_field_decl->getChainingSize();
7575 clang::NamedDecl **chain =
new (ast->getASTContext())
7576 clang::NamedDecl *[nested_chain_size + 1];
7577 chain[0] = *field_pos;
7579 int chain_index = 1;
7580 for (clang::IndirectFieldDecl::chain_iterator
7581 nci = nested_indirect_field_decl->chain_begin(),
7582 nce = nested_indirect_field_decl->chain_end();
7584 chain[chain_index] = *nci;
7588 clang::IndirectFieldDecl *indirect_field =
7589 clang::IndirectFieldDecl::Create(
7590 ast->getASTContext(), record_decl, clang::SourceLocation(),
7591 nested_indirect_field_decl->getIdentifier(),
7592 nested_indirect_field_decl->getType(),
7593 {chain, nested_chain_size + 1});
7596 indirect_field->setImplicit();
7599 field_pos->getAccess(), nested_indirect_field_decl->getAccess()));
7601 indirect_fields.push_back(indirect_field);
7609 if (last_field_pos != field_end_pos) {
7610 if (last_field_pos->getType()->isIncompleteArrayType())
7611 record_decl->hasFlexibleArrayMember();
7614 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(),
7615 ife = indirect_fields.end();
7617 record_decl->addDecl(*ifi);
7631 record_decl->addAttr(
7632 clang::PackedAttr::CreateImplicit(ast->getASTContext()));
7652 clang::VarDecl *var_decl =
nullptr;
7653 clang::IdentifierInfo *ident =
nullptr;
7655 ident = &ast->getASTContext().Idents.get(name);
7658 clang::VarDecl::CreateDeserialized(ast->getASTContext(), GlobalDeclID());
7659 var_decl->setDeclContext(record_decl);
7660 var_decl->setDeclName(ident);
7662 var_decl->setStorageClass(clang::SC_Static);
7667 var_decl->setAccess(
7669 record_decl->addDecl(var_decl);
7671 VerifyDecl(var_decl);
7677 VarDecl *var,
const llvm::APInt &init_value) {
7678 assert(!var->hasInit() &&
"variable already initialized");
7680 clang::ASTContext &ast = var->getASTContext();
7681 QualType qt = var->getType();
7682 assert(qt->isIntegralOrEnumerationType() &&
7683 "only integer or enum types supported");
7686 if (
const EnumType *enum_type = qt->getAs<EnumType>()) {
7687 const EnumDecl *enum_decl = enum_type->getDecl();
7688 qt = enum_decl->getIntegerType();
7692 if (qt->isSpecificBuiltinType(BuiltinType::Bool)) {
7693 var->setInit(CXXBoolLiteralExpr::Create(
7694 ast, !init_value.isZero(), qt.getUnqualifiedType(), SourceLocation()));
7696 var->setInit(IntegerLiteral::Create(
7697 ast, init_value, qt.getUnqualifiedType(), SourceLocation()));
7702 clang::VarDecl *var,
const llvm::APFloat &init_value) {
7703 assert(!var->hasInit() &&
"variable already initialized");
7705 clang::ASTContext &ast = var->getASTContext();
7706 QualType qt = var->getType();
7707 assert(qt->isFloatingType() &&
"only floating point types supported");
7708 var->setInit(FloatingLiteral::Create(
7709 ast, init_value,
true, qt.getUnqualifiedType(), SourceLocation()));
7714 const char *mangled_name,
const CompilerType &method_clang_type,
7716 bool is_explicit,
bool is_attr_used,
bool is_artificial) {
7717 if (!type || !method_clang_type.
IsValid() || name.empty())
7722 clang::CXXRecordDecl *cxx_record_decl =
7723 record_qual_type->getAsCXXRecordDecl();
7725 if (cxx_record_decl ==
nullptr)
7730 clang::CXXMethodDecl *cxx_method_decl =
nullptr;
7732 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7734 const clang::FunctionType *function_type =
7735 llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7737 if (function_type ==
nullptr)
7740 const clang::FunctionProtoType *method_function_prototype(
7741 llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7743 if (!method_function_prototype)
7746 unsigned int num_params = method_function_prototype->getNumParams();
7748 clang::CXXDestructorDecl *cxx_dtor_decl(
nullptr);
7749 clang::CXXConstructorDecl *cxx_ctor_decl(
nullptr);
7754 const clang::ExplicitSpecifier explicit_spec(
7755 nullptr , is_explicit ? clang::ExplicitSpecKind::ResolvedTrue
7756 : clang::ExplicitSpecKind::ResolvedFalse);
7758 if (name.starts_with(
"~")) {
7759 cxx_dtor_decl = clang::CXXDestructorDecl::CreateDeserialized(
7761 cxx_dtor_decl->setDeclContext(cxx_record_decl);
7762 cxx_dtor_decl->setDeclName(
7765 cxx_dtor_decl->setType(method_qual_type);
7766 cxx_dtor_decl->setImplicit(is_artificial);
7767 cxx_dtor_decl->setInlineSpecified(is_inline);
7768 cxx_dtor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7769 cxx_method_decl = cxx_dtor_decl;
7770 }
else if (decl_name == cxx_record_decl->getDeclName()) {
7771 cxx_ctor_decl = clang::CXXConstructorDecl::CreateDeserialized(
7773 cxx_ctor_decl->setDeclContext(cxx_record_decl);
7774 cxx_ctor_decl->setDeclName(
7777 cxx_ctor_decl->setType(method_qual_type);
7778 cxx_ctor_decl->setImplicit(is_artificial);
7779 cxx_ctor_decl->setInlineSpecified(is_inline);
7780 cxx_ctor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7781 cxx_ctor_decl->setNumCtorInitializers(0);
7782 cxx_ctor_decl->setExplicitSpecifier(explicit_spec);
7783 cxx_method_decl = cxx_ctor_decl;
7785 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7786 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7789 if (op_kind != clang::NUM_OVERLOADED_OPERATORS) {
7794 const bool is_method =
true;
7796 is_method, op_kind, num_params))
7798 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7800 cxx_method_decl->setDeclContext(cxx_record_decl);
7801 cxx_method_decl->setDeclName(
7802 getASTContext().DeclarationNames.getCXXOperatorName(op_kind));
7803 cxx_method_decl->setType(method_qual_type);
7804 cxx_method_decl->setStorageClass(SC);
7805 cxx_method_decl->setInlineSpecified(is_inline);
7806 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7807 }
else if (num_params == 0) {
7809 auto *cxx_conversion_decl =
7810 clang::CXXConversionDecl::CreateDeserialized(
getASTContext(),
7812 cxx_conversion_decl->setDeclContext(cxx_record_decl);
7813 cxx_conversion_decl->setDeclName(
7814 getASTContext().DeclarationNames.getCXXConversionFunctionName(
7816 function_type->getReturnType())));
7817 cxx_conversion_decl->setType(method_qual_type);
7818 cxx_conversion_decl->setInlineSpecified(is_inline);
7819 cxx_conversion_decl->setExplicitSpecifier(explicit_spec);
7820 cxx_conversion_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7821 cxx_method_decl = cxx_conversion_decl;
7825 if (cxx_method_decl ==
nullptr) {
7826 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7828 cxx_method_decl->setDeclContext(cxx_record_decl);
7829 cxx_method_decl->setDeclName(decl_name);
7830 cxx_method_decl->setType(method_qual_type);
7831 cxx_method_decl->setInlineSpecified(is_inline);
7832 cxx_method_decl->setStorageClass(SC);
7833 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7838 clang::AccessSpecifier access_specifier =
7841 cxx_method_decl->setAccess(access_specifier);
7842 cxx_method_decl->setVirtualAsWritten(is_virtual);
7845 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(
getASTContext()));
7847 if (mangled_name !=
nullptr) {
7848 cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7854 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
7856 for (
unsigned param_index = 0; param_index < num_params; ++param_index) {
7857 params.push_back(clang::ParmVarDecl::Create(
7859 clang::SourceLocation(),
7861 method_function_prototype->getParamType(param_index),
nullptr,
7862 clang::SC_None,
nullptr));
7865 cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params));
7872 cxx_record_decl->addDecl(cxx_method_decl);
7881 if (is_artificial) {
7882 if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() &&
7883 cxx_record_decl->hasTrivialDefaultConstructor()) ||
7884 (cxx_ctor_decl->isCopyConstructor() &&
7885 cxx_record_decl->hasTrivialCopyConstructor()) ||
7886 (cxx_ctor_decl->isMoveConstructor() &&
7887 cxx_record_decl->hasTrivialMoveConstructor()))) {
7888 cxx_ctor_decl->setDefaulted();
7889 cxx_ctor_decl->setTrivial(
true);
7890 }
else if (cxx_dtor_decl) {
7891 if (cxx_record_decl->hasTrivialDestructor()) {
7892 cxx_dtor_decl->setDefaulted();
7893 cxx_dtor_decl->setTrivial(
true);
7895 }
else if ((cxx_method_decl->isCopyAssignmentOperator() &&
7896 cxx_record_decl->hasTrivialCopyAssignment()) ||
7897 (cxx_method_decl->isMoveAssignmentOperator() &&
7898 cxx_record_decl->hasTrivialMoveAssignment())) {
7899 cxx_method_decl->setDefaulted();
7900 cxx_method_decl->setTrivial(
true);
7904 VerifyDecl(cxx_method_decl);
7906 return cxx_method_decl;
7912 for (
auto *method : record->methods())
7913 addOverridesForMethod(method);
7916#pragma mark C++ Base Classes
7918std::unique_ptr<clang::CXXBaseSpecifier>
7921 bool base_of_class) {
7925 return std::make_unique<clang::CXXBaseSpecifier>(
7926 clang::SourceRange(), is_virtual, base_of_class,
7929 clang::SourceLocation());
7934 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) {
7938 if (!cxx_record_decl)
7940 std::vector<clang::CXXBaseSpecifier *> raw_bases;
7941 raw_bases.reserve(bases.size());
7945 for (
auto &b : bases)
7946 raw_bases.push_back(b.get());
7947 cxx_record_decl->setBases(raw_bases.data(), raw_bases.size());
7959 if (type && superclass_clang_type.
IsValid() &&
7961 clang::ObjCInterfaceDecl *class_interface_decl =
7963 clang::ObjCInterfaceDecl *super_interface_decl =
7965 if (class_interface_decl && super_interface_decl) {
7966 class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
7967 clang_ast.getObjCInterfaceType(super_interface_decl)));
7976 const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl,
7977 const char *property_setter_name,
const char *property_getter_name,
7979 if (!type || !property_clang_type.
IsValid() || property_name ==
nullptr ||
7980 property_name[0] ==
'\0')
7989 if (!class_interface_decl)
7994 if (property_clang_type.
IsValid())
7995 property_clang_type_to_access = property_clang_type;
7997 property_clang_type_to_access = ast->GetType(ivar_decl->getType());
7999 if (!class_interface_decl || !property_clang_type_to_access.
IsValid())
8002 clang::TypeSourceInfo *prop_type_source;
8004 prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
8006 prop_type_source = clang_ast.getTrivialTypeSourceInfo(
8009 clang::ObjCPropertyDecl *property_decl =
8010 clang::ObjCPropertyDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8011 property_decl->setDeclContext(class_interface_decl);
8012 property_decl->setDeclName(&clang_ast.Idents.get(property_name));
8013 property_decl->setType(ivar_decl
8014 ? ivar_decl->getType()
8023 ast->SetMetadata(property_decl, *metadata);
8025 class_interface_decl->addDecl(property_decl);
8027 clang::Selector setter_sel, getter_sel;
8029 if (property_setter_name) {
8030 std::string property_setter_no_colon(property_setter_name,
8031 strlen(property_setter_name) - 1);
8032 const clang::IdentifierInfo *setter_ident =
8033 &clang_ast.Idents.get(property_setter_no_colon);
8034 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8035 }
else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
8036 std::string setter_sel_string(
"set");
8037 setter_sel_string.push_back(::toupper(property_name[0]));
8038 setter_sel_string.append(&property_name[1]);
8039 const clang::IdentifierInfo *setter_ident =
8040 &clang_ast.Idents.get(setter_sel_string);
8041 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
8043 property_decl->setSetterName(setter_sel);
8044 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
8046 if (property_getter_name !=
nullptr) {
8047 const clang::IdentifierInfo *getter_ident =
8048 &clang_ast.Idents.get(property_getter_name);
8049 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8051 const clang::IdentifierInfo *getter_ident =
8052 &clang_ast.Idents.get(property_name);
8053 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
8055 property_decl->setGetterName(getter_sel);
8056 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
8059 property_decl->setPropertyIvarDecl(ivar_decl);
8061 if (property_attributes & DW_APPLE_PROPERTY_readonly)
8062 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
8063 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
8064 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
8065 if (property_attributes & DW_APPLE_PROPERTY_assign)
8066 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
8067 if (property_attributes & DW_APPLE_PROPERTY_retain)
8068 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
8069 if (property_attributes & DW_APPLE_PROPERTY_copy)
8070 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
8071 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
8072 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
8073 if (property_attributes & ObjCPropertyAttribute::kind_nullability)
8074 property_decl->setPropertyAttributes(
8075 ObjCPropertyAttribute::kind_nullability);
8076 if (property_attributes & ObjCPropertyAttribute::kind_null_resettable)
8077 property_decl->setPropertyAttributes(
8078 ObjCPropertyAttribute::kind_null_resettable);
8079 if (property_attributes & ObjCPropertyAttribute::kind_class)
8080 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
8082 const bool isInstance =
8083 (property_attributes & ObjCPropertyAttribute::kind_class) == 0;
8085 clang::ObjCMethodDecl *getter =
nullptr;
8086 if (!getter_sel.isNull())
8087 getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8088 : class_interface_decl->lookupClassMethod(getter_sel);
8089 if (!getter_sel.isNull() && !getter) {
8090 const bool isVariadic =
false;
8091 const bool isPropertyAccessor =
true;
8092 const bool isSynthesizedAccessorStub =
false;
8093 const bool isImplicitlyDeclared =
true;
8094 const bool isDefined =
false;
8095 const clang::ObjCImplementationControl impControl =
8096 clang::ObjCImplementationControl::None;
8097 const bool HasRelatedResultType =
false;
8100 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8101 getter->setDeclName(getter_sel);
8103 getter->setDeclContext(class_interface_decl);
8104 getter->setInstanceMethod(isInstance);
8105 getter->setVariadic(isVariadic);
8106 getter->setPropertyAccessor(isPropertyAccessor);
8107 getter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8108 getter->setImplicit(isImplicitlyDeclared);
8109 getter->setDefined(isDefined);
8110 getter->setDeclImplementation(impControl);
8111 getter->setRelatedResultType(HasRelatedResultType);
8116 ast->SetMetadata(getter, *metadata);
8118 getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
8119 llvm::ArrayRef<clang::SourceLocation>());
8120 class_interface_decl->addDecl(getter);
8124 getter->setPropertyAccessor(
true);
8125 property_decl->setGetterMethodDecl(getter);
8128 clang::ObjCMethodDecl *setter =
nullptr;
8129 setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8130 : class_interface_decl->lookupClassMethod(setter_sel);
8131 if (!setter_sel.isNull() && !setter) {
8132 clang::QualType result_type = clang_ast.VoidTy;
8133 const bool isVariadic =
false;
8134 const bool isPropertyAccessor =
true;
8135 const bool isSynthesizedAccessorStub =
false;
8136 const bool isImplicitlyDeclared =
true;
8137 const bool isDefined =
false;
8138 const clang::ObjCImplementationControl impControl =
8139 clang::ObjCImplementationControl::None;
8140 const bool HasRelatedResultType =
false;
8143 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8144 setter->setDeclName(setter_sel);
8145 setter->setReturnType(result_type);
8146 setter->setDeclContext(class_interface_decl);
8147 setter->setInstanceMethod(isInstance);
8148 setter->setVariadic(isVariadic);
8149 setter->setPropertyAccessor(isPropertyAccessor);
8150 setter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8151 setter->setImplicit(isImplicitlyDeclared);
8152 setter->setDefined(isDefined);
8153 setter->setDeclImplementation(impControl);
8154 setter->setRelatedResultType(HasRelatedResultType);
8159 ast->SetMetadata(setter, *metadata);
8161 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8162 params.push_back(clang::ParmVarDecl::Create(
8163 clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8166 clang::SC_Auto,
nullptr));
8168 setter->setMethodParams(clang_ast,
8169 llvm::ArrayRef<clang::ParmVarDecl *>(params),
8170 llvm::ArrayRef<clang::SourceLocation>());
8172 class_interface_decl->addDecl(setter);
8176 setter->setPropertyAccessor(
true);
8177 property_decl->setSetterMethodDecl(setter);
8184 bool check_superclass) {
8186 if (class_interface_decl)
8196 const CompilerType &method_clang_type,
bool is_artificial,
bool is_variadic,
8197 bool is_objc_direct_call) {
8198 if (!type || !method_clang_type.
IsValid())
8203 if (class_interface_decl ==
nullptr)
8207 if (lldb_ast ==
nullptr)
8211 const char *selector_start = ::strchr(name,
' ');
8212 if (selector_start ==
nullptr)
8216 llvm::SmallVector<const clang::IdentifierInfo *, 12> selector_idents;
8221 unsigned num_selectors_with_args = 0;
8222 for (start = selector_start; start && *start !=
'\0' && *start !=
']';
8224 len = ::strcspn(start,
":]");
8225 bool has_arg = (start[len] ==
':');
8227 ++num_selectors_with_args;
8228 selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
8233 if (selector_idents.size() == 0)
8236 clang::Selector method_selector = ast.Selectors.getSelector(
8237 num_selectors_with_args ? selector_idents.size() : 0,
8238 selector_idents.data());
8243 const clang::Type *method_type(method_qual_type.getTypePtr());
8245 if (method_type ==
nullptr)
8248 const clang::FunctionProtoType *method_function_prototype(
8249 llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8251 if (!method_function_prototype)
8254 const bool isInstance = (name[0] ==
'-');
8255 const bool isVariadic = is_variadic;
8256 const bool isPropertyAccessor =
false;
8257 const bool isSynthesizedAccessorStub =
false;
8259 const bool isImplicitlyDeclared =
true;
8260 const bool isDefined =
false;
8261 const clang::ObjCImplementationControl impControl =
8262 clang::ObjCImplementationControl::None;
8263 const bool HasRelatedResultType =
false;
8265 const unsigned num_args = method_function_prototype->getNumParams();
8267 if (num_args != num_selectors_with_args)
8271 auto *objc_method_decl =
8272 clang::ObjCMethodDecl::CreateDeserialized(ast, GlobalDeclID());
8273 objc_method_decl->setDeclName(method_selector);
8274 objc_method_decl->setReturnType(method_function_prototype->getReturnType());
8275 objc_method_decl->setDeclContext(
8277 objc_method_decl->setInstanceMethod(isInstance);
8278 objc_method_decl->setVariadic(isVariadic);
8279 objc_method_decl->setPropertyAccessor(isPropertyAccessor);
8280 objc_method_decl->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8281 objc_method_decl->setImplicit(isImplicitlyDeclared);
8282 objc_method_decl->setDefined(isDefined);
8283 objc_method_decl->setDeclImplementation(impControl);
8284 objc_method_decl->setRelatedResultType(HasRelatedResultType);
8287 if (objc_method_decl ==
nullptr)
8291 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8293 for (
unsigned param_index = 0; param_index < num_args; ++param_index) {
8294 params.push_back(clang::ParmVarDecl::Create(
8295 ast, objc_method_decl, clang::SourceLocation(),
8296 clang::SourceLocation(),
8298 method_function_prototype->getParamType(param_index),
nullptr,
8299 clang::SC_Auto,
nullptr));
8302 objc_method_decl->setMethodParams(
8303 ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
8304 llvm::ArrayRef<clang::SourceLocation>());
8307 if (is_objc_direct_call) {
8310 objc_method_decl->addAttr(
8311 clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
8316 objc_method_decl->createImplicitParams(ast, class_interface_decl);
8319 class_interface_decl->addDecl(objc_method_decl);
8321 VerifyDecl(objc_method_decl);
8323 return objc_method_decl;
8333 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8334 switch (type_class) {
8335 case clang::Type::Record: {
8336 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8337 if (cxx_record_decl) {
8338 cxx_record_decl->setHasExternalLexicalStorage(has_extern);
8339 cxx_record_decl->setHasExternalVisibleStorage(has_extern);
8344 case clang::Type::Enum: {
8345 clang::EnumDecl *enum_decl =
8346 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8348 enum_decl->setHasExternalLexicalStorage(has_extern);
8349 enum_decl->setHasExternalVisibleStorage(has_extern);
8354 case clang::Type::ObjCObject:
8355 case clang::Type::ObjCInterface: {
8356 const clang::ObjCObjectType *objc_class_type =
8357 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8358 assert(objc_class_type);
8359 if (objc_class_type) {
8360 clang::ObjCInterfaceDecl *class_interface_decl =
8361 objc_class_type->getInterface();
8363 if (class_interface_decl) {
8364 class_interface_decl->setHasExternalLexicalStorage(has_extern);
8365 class_interface_decl->setHasExternalVisibleStorage(has_extern);
8381 if (!qual_type.isNull()) {
8382 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8384 clang::TagDecl *tag_decl = tag_type->getDecl();
8386 tag_decl->startDefinition();
8391 const clang::ObjCObjectType *object_type =
8392 qual_type->getAs<clang::ObjCObjectType>();
8394 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8395 if (interface_decl) {
8396 interface_decl->startDefinition();
8407 if (qual_type.isNull())
8412 if (lldb_ast ==
nullptr)
8418 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8420 clang::TagDecl *tag_decl = tag_type->getDecl();
8422 if (
auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
8432 if (cxx_record_decl->hasUserDeclaredMoveConstructor() ||
8433 cxx_record_decl->hasUserDeclaredMoveAssignment()) {
8434 if (cxx_record_decl->needsImplicitCopyConstructor())
8435 cxx_record_decl->setImplicitCopyConstructorIsDeleted();
8436 if (cxx_record_decl->needsImplicitCopyAssignment())
8437 cxx_record_decl->setImplicitCopyAssignmentIsDeleted();
8440 if (!cxx_record_decl->isCompleteDefinition())
8441 cxx_record_decl->completeDefinition();
8442 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
8443 cxx_record_decl->setHasExternalLexicalStorage(
false);
8444 cxx_record_decl->setHasExternalVisibleStorage(
false);
8446 clang::AccessSpecifier::AS_none);
8451 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8455 clang::EnumDecl *enum_decl = enutype->getDecl();
8457 if (enum_decl->isCompleteDefinition())
8460 clang::ASTContext &ast = lldb_ast->getASTContext();
8464 QualType integer_type(enum_decl->getIntegerType());
8465 if (!integer_type.isNull()) {
8466 unsigned NumPositiveBits = 1;
8467 unsigned NumNegativeBits = 0;
8469 clang::QualType promotion_qual_type;
8472 if (ast.getTypeSize(enum_decl->getIntegerType()) <
8473 ast.getTypeSize(ast.IntTy)) {
8474 if (enum_decl->getIntegerType()->isSignedIntegerType())
8475 promotion_qual_type = ast.IntTy;
8477 promotion_qual_type = ast.UnsignedIntTy;
8479 promotion_qual_type = enum_decl->getIntegerType();
8481 enum_decl->completeDefinition(enum_decl->getIntegerType(),
8482 promotion_qual_type, NumPositiveBits,
8490 const llvm::APSInt &value) {
8501 if (!enum_opaque_compiler_type)
8504 clang::QualType enum_qual_type(
8507 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8512 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8517 clang::EnumConstantDecl *enumerator_decl =
8518 clang::EnumConstantDecl::CreateDeserialized(
getASTContext(),
8520 enumerator_decl->setDeclContext(enutype->getDecl());
8521 if (name && name[0])
8522 enumerator_decl->setDeclName(&
getASTContext().Idents.get(name));
8523 enumerator_decl->setType(clang::QualType(enutype, 0));
8527 if (!enumerator_decl)
8530 enutype->getDecl()->addDecl(enumerator_decl);
8532 VerifyDecl(enumerator_decl);
8533 return enumerator_decl;
8538 int64_t enum_value, uint32_t enum_value_bit_size) {
8540 bool is_signed =
false;
8543 llvm::APSInt value(enum_value_bit_size, is_signed);
8551 const clang::Type *clang_type = qt.getTypePtrOrNull();
8552 const auto *enum_type = llvm::dyn_cast_or_null<clang::EnumType>(clang_type);
8556 return GetType(enum_type->getDecl()->getIntegerType());
8562 if (type && pointee_type.
IsValid() &&
8568 return ast->GetType(ast->getASTContext().getMemberPointerType(
8576#define DEPTH_INCREMENT 2
8579LLVM_DUMP_METHOD
void
8593 llvm::StringRef symbol_name) {
8600 symfile->
GetTypes(
nullptr, eTypeClassAny, type_list);
8601 size_t ntypes = type_list.
GetSize();
8603 for (
size_t i = 0; i < ntypes; ++i) {
8606 if (!symbol_name.empty())
8607 if (symbol_name != type->GetName().GetStringRef())
8610 s << type->GetName().AsCString() <<
"\n";
8613 if (clang::TagDecl *tag_decl =
GetAsTagDecl(full_type)) {
8621 if (
auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8623 if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8635 size_t byte_size, uint32_t bitfield_bit_offset,
8636 uint32_t bitfield_bit_size) {
8637 const clang::EnumType *enutype =
8638 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8639 const clang::EnumDecl *enum_decl = enutype->getDecl();
8642 bool qual_type_is_signed = qual_type->isSignedIntegerOrEnumerationType();
8643 const uint64_t enum_svalue =
8646 bitfield_bit_offset)
8648 bitfield_bit_offset);
8649 bool can_be_bitfield =
true;
8650 uint64_t covered_bits = 0;
8651 int num_enumerators = 0;
8659 clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
8660 if (enumerators.empty())
8661 can_be_bitfield =
false;
8663 for (
auto *enumerator : enumerators) {
8664 llvm::APSInt init_val = enumerator->getInitVal();
8665 uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
8666 : init_val.getZExtValue();
8667 if (qual_type_is_signed)
8668 val = llvm::SignExtend64(val, 8 * byte_size);
8669 if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8670 can_be_bitfield =
false;
8671 covered_bits |= val;
8673 if (val == enum_svalue) {
8682 offset = byte_offset;
8684 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8688 if (!can_be_bitfield) {
8689 if (qual_type_is_signed)
8690 s.
Printf(
"%" PRIi64, enum_svalue);
8692 s.
Printf(
"%" PRIu64, enum_uvalue);
8699 s.
Printf(
"0x%" PRIx64, enum_uvalue);
8703 uint64_t remaining_value = enum_uvalue;
8704 std::vector<std::pair<uint64_t, llvm::StringRef>> values;
8705 values.reserve(num_enumerators);
8706 for (
auto *enumerator : enum_decl->enumerators())
8707 if (
auto val = enumerator->getInitVal().getZExtValue())
8708 values.emplace_back(val, enumerator->getName());
8713 std::stable_sort(values.begin(), values.end(),
8714 [](
const auto &a,
const auto &b) {
8715 return llvm::popcount(a.first) > llvm::popcount(b.first);
8718 for (
const auto &val : values) {
8719 if ((remaining_value & val.first) != val.first)
8721 remaining_value &= ~val.first;
8723 if (remaining_value)
8729 if (remaining_value)
8730 s.
Printf(
"0x%" PRIx64, remaining_value);
8738 size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
8747 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8749 if (type_class == clang::Type::Elaborated) {
8750 qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
8751 return DumpTypeValue(qual_type.getAsOpaquePtr(), s, format, data, byte_offset, byte_size,
8752 bitfield_bit_size, bitfield_bit_offset, exe_scope);
8755 switch (type_class) {
8756 case clang::Type::Typedef: {
8757 clang::QualType typedef_qual_type =
8758 llvm::cast<clang::TypedefType>(qual_type)
8760 ->getUnderlyingType();
8763 format = typedef_clang_type.
GetFormat();
8764 clang::TypeInfo typedef_type_info =
8766 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
8776 bitfield_bit_offset,
8781 case clang::Type::Enum:
8786 return DumpEnumValue(qual_type, s, data, byte_offset, byte_size,
8787 bitfield_bit_offset, bitfield_bit_size);
8795 uint32_t item_count = 1;
8834 item_count = byte_size;
8839 item_count = byte_size / 2;
8844 item_count = byte_size / 4;
8850 bitfield_bit_size, bitfield_bit_offset,
8876 clang::QualType qual_type =
8879 llvm::SmallVector<char, 1024> buf;
8880 llvm::raw_svector_ostream llvm_ostrm(buf);
8882 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8883 switch (type_class) {
8884 case clang::Type::ObjCObject:
8885 case clang::Type::ObjCInterface: {
8888 auto *objc_class_type =
8889 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8890 assert(objc_class_type);
8891 if (!objc_class_type)
8893 clang::ObjCInterfaceDecl *class_interface_decl =
8894 objc_class_type->getInterface();
8895 if (!class_interface_decl)
8898 class_interface_decl->dump(llvm_ostrm);
8900 class_interface_decl->print(llvm_ostrm,
8905 case clang::Type::Typedef: {
8906 auto *typedef_type = qual_type->getAs<clang::TypedefType>();
8909 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8911 typedef_decl->dump(llvm_ostrm);
8914 if (!clang_typedef_name.empty()) {
8921 case clang::Type::Record: {
8924 auto *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8925 const clang::RecordDecl *record_decl = record_type->getDecl();
8927 record_decl->dump(llvm_ostrm);
8929 record_decl->print(llvm_ostrm,
getASTContext().getPrintingPolicy(),
8935 if (
auto *tag_type =
8936 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) {
8937 if (clang::TagDecl *tag_decl = tag_type->getDecl()) {
8939 tag_decl->dump(llvm_ostrm);
8941 tag_decl->print(llvm_ostrm, 0);
8947 std::string clang_type_name(qual_type.getAsString());
8948 if (!clang_type_name.empty())
8955 if (buf.size() > 0) {
8956 s.
Write(buf.data(), buf.size());
8963 clang::QualType qual_type(
8966 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8967 switch (type_class) {
8968 case clang::Type::Record: {
8969 const clang::CXXRecordDecl *cxx_record_decl =
8970 qual_type->getAsCXXRecordDecl();
8971 if (cxx_record_decl)
8972 printf(
"class %s", cxx_record_decl->getName().str().c_str());
8975 case clang::Type::Enum: {
8976 clang::EnumDecl *enum_decl =
8977 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8979 printf(
"enum %s", enum_decl->getName().str().c_str());
8983 case clang::Type::ObjCObject:
8984 case clang::Type::ObjCInterface: {
8985 const clang::ObjCObjectType *objc_class_type =
8986 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
8987 if (objc_class_type) {
8988 clang::ObjCInterfaceDecl *class_interface_decl =
8989 objc_class_type->getInterface();
8993 if (class_interface_decl)
8994 printf(
"@class %s", class_interface_decl->getName().str().c_str());
8998 case clang::Type::Typedef:
8999 printf(
"typedef %s", llvm::cast<clang::TypedefType>(qual_type)
9006 case clang::Type::Auto:
9009 llvm::cast<clang::AutoType>(qual_type)
9011 .getAsOpaquePtr()));
9013 case clang::Type::Elaborated:
9014 printf(
"elaborated ");
9016 type.
GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)
9018 .getAsOpaquePtr()));
9020 case clang::Type::Paren:
9024 llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
9027 printf(
"TypeSystemClang::DumpTypeName() type_class = %u", type_class);
9037 if (template_param_infos.
IsValid()) {
9038 std::string template_basename(parent_name);
9040 if (
auto i = template_basename.find(
'<'); i != std::string::npos)
9041 template_basename.erase(i);
9044 template_basename.c_str(), tag_decl_kind,
9045 template_param_infos);
9060 clang::ObjCInterfaceDecl *decl) {
9088 const clang::RecordDecl *record_decl, uint64_t &bit_size,
9089 uint64_t &alignment,
9090 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
9091 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9093 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9106 field_offsets, base_offsets, vbase_offsets);
9113 clang::NamedDecl *nd =
9114 llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl);
9116 return ConstString(nd->getDeclName().getAsString());
9123 clang::NamedDecl *nd =
9124 llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl);
9125 if (nd !=
nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) {
9127 if (mc && mc->shouldMangleCXXName(nd)) {
9128 llvm::SmallVector<char, 1024> buf;
9129 llvm::raw_svector_ostream llvm_ostrm(buf);
9130 if (llvm::isa<clang::CXXConstructorDecl>(nd)) {
9132 clang::GlobalDecl(llvm::dyn_cast<clang::CXXConstructorDecl>(nd),
9135 }
else if (llvm::isa<clang::CXXDestructorDecl>(nd)) {
9137 clang::GlobalDecl(llvm::dyn_cast<clang::CXXDestructorDecl>(nd),
9141 mc->mangleName(nd, llvm_ostrm);
9158 if (clang::FunctionDecl *func_decl =
9159 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9160 return GetType(func_decl->getReturnType());
9161 if (clang::ObjCMethodDecl *objc_method =
9162 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9163 return GetType(objc_method->getReturnType());
9169 if (clang::FunctionDecl *func_decl =
9170 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9171 return func_decl->param_size();
9172 if (clang::ObjCMethodDecl *objc_method =
9173 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9174 return objc_method->param_size();
9180 clang::DeclContext
const *decl_ctx) {
9181 switch (clang_kind) {
9182 case Decl::TranslationUnit:
9184 case Decl::Namespace:
9195 if (decl_ctx->isFunctionOrMethod())
9197 if (decl_ctx->isRecord())
9207 std::vector<lldb_private::CompilerContext> &context) {
9208 if (decl_ctx ==
nullptr)
9211 clang::Decl::Kind clang_kind = decl_ctx->getDeclKind();
9212 if (clang_kind == Decl::TranslationUnit)
9217 context.push_back({compiler_kind, decl_ctx_name});
9220std::vector<lldb_private::CompilerContext>
9222 std::vector<lldb_private::CompilerContext> context;
9225 clang::Decl *decl = (clang::Decl *)opaque_decl;
9227 clang::DeclContext *decl_ctx = decl->getDeclContext();
9230 auto compiler_kind =
9232 context.push_back({compiler_kind, decl_name});
9239 if (clang::FunctionDecl *func_decl =
9240 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) {
9241 if (idx < func_decl->param_size()) {
9242 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9244 return GetType(var_decl->getOriginalType());
9246 }
else if (clang::ObjCMethodDecl *objc_method =
9247 llvm::dyn_cast<clang::ObjCMethodDecl>(
9248 (clang::Decl *)opaque_decl)) {
9249 if (idx < objc_method->param_size())
9250 return GetType(objc_method->parameters()[idx]->getOriginalType());
9256 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
9257 clang::VarDecl *var_decl = llvm::dyn_cast<clang::VarDecl>(decl);
9260 clang::Expr *init_expr = var_decl->getInit();
9263 std::optional<llvm::APSInt> value =
9273 void *opaque_decl_ctx,
ConstString name,
const bool ignore_using_decls) {
9274 std::vector<CompilerDecl> found_decls;
9276 if (opaque_decl_ctx && symbol_file) {
9277 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9278 std::set<DeclContext *> searched;
9279 std::multimap<DeclContext *, DeclContext *> search_queue;
9281 for (clang::DeclContext *decl_context = root_decl_ctx;
9282 decl_context !=
nullptr && found_decls.empty();
9283 decl_context = decl_context->getParent()) {
9284 search_queue.insert(std::make_pair(decl_context, decl_context));
9286 for (
auto it = search_queue.find(decl_context); it != search_queue.end();
9288 if (!searched.insert(it->second).second)
9293 for (clang::Decl *child : it->second->decls()) {
9294 if (clang::UsingDirectiveDecl *ud =
9295 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9296 if (ignore_using_decls)
9298 clang::DeclContext *from = ud->getCommonAncestor();
9299 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9300 search_queue.insert(
9301 std::make_pair(from, ud->getNominatedNamespace()));
9302 }
else if (clang::UsingDecl *ud =
9303 llvm::dyn_cast<clang::UsingDecl>(child)) {
9304 if (ignore_using_decls)
9306 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9307 clang::Decl *target = usd->getTargetDecl();
9308 if (clang::NamedDecl *nd =
9309 llvm::dyn_cast<clang::NamedDecl>(target)) {
9310 IdentifierInfo *ii = nd->getIdentifier();
9311 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9315 }
else if (clang::NamedDecl *nd =
9316 llvm::dyn_cast<clang::NamedDecl>(child)) {
9317 IdentifierInfo *ii = nd->getIdentifier();
9318 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9369 clang::DeclContext *child_decl_ctx,
9373 if (frame_decl_ctx && symbol_file) {
9374 std::set<DeclContext *> searched;
9375 std::multimap<DeclContext *, DeclContext *> search_queue;
9378 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9382 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx !=
nullptr;
9383 decl_ctx = decl_ctx->getParent()) {
9384 if (!decl_ctx->isLookupContext())
9386 if (decl_ctx == parent_decl_ctx)
9389 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9390 for (
auto it = search_queue.find(decl_ctx); it != search_queue.end();
9392 if (searched.find(it->second) != searched.end())
9400 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9403 searched.insert(it->second);
9407 for (clang::Decl *child : it->second->decls()) {
9408 if (clang::UsingDirectiveDecl *ud =
9409 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9410 clang::DeclContext *ns = ud->getNominatedNamespace();
9411 if (ns == parent_decl_ctx)
9414 clang::DeclContext *from = ud->getCommonAncestor();
9415 if (searched.find(ns) == searched.end())
9416 search_queue.insert(std::make_pair(from, ns));
9417 }
else if (child_name) {
9418 if (clang::UsingDecl *ud =
9419 llvm::dyn_cast<clang::UsingDecl>(child)) {
9420 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9421 clang::Decl *target = usd->getTargetDecl();
9422 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9426 IdentifierInfo *ii = nd->getIdentifier();
9427 if (ii ==
nullptr ||
9428 ii->getName() != child_name->
AsCString(
nullptr))
9451 if (opaque_decl_ctx) {
9452 clang::NamedDecl *named_decl =
9453 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9456 llvm::raw_string_ostream stream{name};
9458 policy.AlwaysIncludeTypeForTemplateArgument =
true;
9459 named_decl->getNameForDiagnostic(stream, policy,
false);
9468 if (opaque_decl_ctx) {
9469 clang::NamedDecl *named_decl =
9470 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9478 if (!opaque_decl_ctx)
9481 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9482 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9484 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9486 }
else if (clang::FunctionDecl *fun_decl =
9487 llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9489 return metadata->HasObjectPtr();
9495std::vector<lldb_private::CompilerContext>
9497 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9498 std::vector<lldb_private::CompilerContext> context;
9504 void *opaque_decl_ctx,
void *other_opaque_decl_ctx) {
9505 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9506 auto *other = (clang::DeclContext *)other_opaque_decl_ctx;
9510 auto is_transparent_lookup_allowed = [](clang::DeclContext *DC) {
9511 if (DC->isInlineNamespace())
9514 if (
auto const *NS = dyn_cast<NamespaceDecl>(DC))
9515 return NS->isAnonymousNamespace();
9522 if (decl_ctx == other)
9524 }
while (is_transparent_lookup_allowed(other) &&
9525 (other = other->getParent()));
9532 if (!opaque_decl_ctx)
9535 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9536 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9538 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9540 }
else if (
auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9542 return metadata->GetObjectPtrLanguage();
9562 return llvm::dyn_cast<clang::ObjCMethodDecl>(
9570 return llvm::dyn_cast<clang::CXXMethodDecl>(
9575clang::FunctionDecl *
9578 return llvm::dyn_cast<clang::FunctionDecl>(
9583clang::NamespaceDecl *
9586 return llvm::dyn_cast<clang::NamespaceDecl>(
9593 const Decl *
object) {
9601 llvm::dyn_cast_or_null<TypeSystemClang>(dc.
GetTypeSystem());
9623 lldbassert(started &&
"Unable to start a class type definition.");
9642 SpecializedScratchAST(llvm::StringRef name, llvm::Triple triple,
9643 std::unique_ptr<ClangASTSource> ast_source)
9645 m_scratch_ast_source_up(std::move(ast_source)) {
9647 m_scratch_ast_source_up->InstallASTContext(*
this);
9648 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9649 m_scratch_ast_source_up->CreateProxy());
9650 SetExternalSource(proxy_ast_source);
9654 std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
9662 llvm::Triple triple)
9664 m_target_wp(target.shared_from_this()),
9665 m_persistent_variables(
9669 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9681 std::optional<IsolatedASTKind> ast_kind,
9682 bool create_on_demand) {
9685 if (
auto err = type_system_or_err.takeError()) {
9687 "Couldn't get scratch TypeSystemClang");
9690 auto ts_sp = *type_system_or_err;
9692 llvm::dyn_cast_or_null<ScratchTypeSystemClang>(ts_sp.get());
9697 return std::static_pointer_cast<TypeSystemClang>(ts_sp);
9699 return std::static_pointer_cast<TypeSystemClang>(
9704static llvm::StringRef
9708 return "C++ modules";
9710 llvm_unreachable(
"Unimplemented IsolatedASTKind?");
9715 output <<
"State of scratch Clang type system:\n";
9719 typedef std::pair<IsolatedASTKey, TypeSystem *> KeyAndTS;
9720 std::vector<KeyAndTS> sorted_typesystems;
9722 sorted_typesystems.emplace_back(a.first, a.second.get());
9723 llvm::stable_sort(sorted_typesystems, llvm::less_first());
9726 for (
const auto &a : sorted_typesystems) {
9729 output <<
"State of scratch Clang type subsystem "
9731 a.second->Dump(output);
9736 llvm::StringRef expr, llvm::StringRef prefix,
SourceLanguage language,
9744 desired_type, options, ctx_obj);
9749 const ValueList &arg_value_list,
const char *name) {
9754 Process *process = target_sp->GetProcessSP().get();
9759 arg_value_list, name);
9762std::unique_ptr<UtilityFunction>
9769 return std::make_unique<ClangUtilityFunction>(
9770 *target_sp.get(), std::move(text), std::move(name),
9771 target_sp->GetDebugUtilityExpression());
9785 importer.
ForgetSource(&a.second->getASTContext(), src_ctx);
9789 return std::make_unique<ClangASTSource>(
9794static llvm::StringRef
9798 return "scratch ASTContext for C++ module types";
9800 llvm_unreachable(
"Unimplemented ASTFeature kind?");
9807 return *found_ast->second;
9810 std::shared_ptr<TypeSystemClang> new_ast_sp =
9820 const clang::RecordType *record_type =
9821 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
9823 const clang::RecordDecl *record_decl = record_type->getDecl();
9824 assert(record_decl);
9837 if (metadata ==
nullptr)
9846 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,...
void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data)
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)
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
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)
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)
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
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 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
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 SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
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 CreateArrayType(const CompilerType &element_type, size_t element_count, bool is_vector)
CompilerType GetTypeForDecl(clang::NamedDecl *decl)
CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
ClangASTMetadata * GetMetadata(const clang::Decl *object)
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
static ClangASTMetadata * DeclContextGetMetaData(const CompilerDeclContext &dc, const clang::Decl *object)
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
CompilerType CreateObjCClass(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool isForwardDecl, bool isInternal, ClangASTMetadata *metadata=nullptr)
void SetFunctionParameters(clang::FunctionDecl *function_decl, llvm::ArrayRef< clang::ParmVarDecl * > params)
static bool IsObjCObjectOrInterfaceType(const CompilerType &type)
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, ClangASTMetadata *metadata=nullptr, bool exports_symbols=false)
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.