11#include "clang/AST/DeclBase.h"
12#include "clang/AST/ExprCXX.h"
13#include "llvm/Support/Casting.h"
14#include "llvm/Support/FormatAdapters.h"
15#include "llvm/Support/FormatVariadic.h"
22#include "clang/AST/ASTContext.h"
23#include "clang/AST/ASTImporter.h"
24#include "clang/AST/Attr.h"
25#include "clang/AST/CXXInheritance.h"
26#include "clang/AST/DeclObjC.h"
27#include "clang/AST/DeclTemplate.h"
28#include "clang/AST/Mangle.h"
29#include "clang/AST/RecordLayout.h"
30#include "clang/AST/Type.h"
31#include "clang/AST/VTableBuilder.h"
32#include "clang/Basic/Builtins.h"
33#include "clang/Basic/Diagnostic.h"
34#include "clang/Basic/FileManager.h"
35#include "clang/Basic/FileSystemOptions.h"
36#include "clang/Basic/LangStandard.h"
37#include "clang/Basic/SourceManager.h"
38#include "clang/Basic/TargetInfo.h"
39#include "clang/Basic/TargetOptions.h"
40#include "clang/Frontend/FrontendOptions.h"
41#include "clang/Lex/HeaderSearch.h"
42#include "clang/Lex/HeaderSearchOptions.h"
43#include "clang/Lex/ModuleMap.h"
44#include "clang/Sema/Sema.h"
46#include "llvm/Support/Signals.h"
47#include "llvm/Support/Threading.h"
92using llvm::StringSwitch;
97static void VerifyDecl(clang::Decl *decl) {
98 assert(decl &&
"VerifyDecl called with nullptr?");
124bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
126 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
127 "Methods should have the same AST context");
128 clang::ASTContext &context = m1->getASTContext();
130 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
131 context.getCanonicalType(m1->getType()));
133 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
134 context.getCanonicalType(m2->getType()));
136 auto compareArgTypes = [&context](
const clang::QualType &m1p,
137 const clang::QualType &m2p) {
138 return context.hasSameType(m1p.getUnqualifiedType(),
139 m2p.getUnqualifiedType());
144 return (m1->getNumParams() != m2->getNumParams()) ||
145 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
146 m2Type->param_type_begin(), compareArgTypes);
152void addOverridesForMethod(clang::CXXMethodDecl *decl) {
153 if (!decl->isVirtual())
156 clang::CXXBasePaths paths;
157 llvm::SmallVector<clang::NamedDecl *, 4> decls;
159 auto find_overridden_methods =
160 [&decls, decl](
const clang::CXXBaseSpecifier *specifier,
161 clang::CXXBasePath &path) {
162 if (
auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
163 specifier->getType()->castAs<clang::RecordType>()->getDecl())) {
165 clang::DeclarationName name = decl->getDeclName();
169 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
170 if (
auto *baseDtorDecl = base_record->getDestructor()) {
171 if (baseDtorDecl->isVirtual()) {
172 decls.push_back(baseDtorDecl);
179 for (path.Decls = base_record->lookup(name).begin();
180 path.Decls != path.Decls.end(); ++path.Decls) {
181 if (
auto *method_decl =
182 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
183 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
184 decls.push_back(method_decl);
193 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
194 for (
auto *overridden_decl : decls)
195 decl->addOverriddenMethod(
196 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
202 VTableContextBase &vtable_ctx,
204 const ASTRecordLayout &record_layout) {
208 uint32_t type_info = this_type.
GetTypeInfo(&pointee_type);
213 bool ptr_or_ref =
false;
214 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
220 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
221 if ((type_info & cpp_class) != cpp_class)
226 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
240 vbtable_ptr_addr += vbtable_ptr_offset;
251 auto size = valobj.
GetData(data, err);
259 VTableContextBase &vtable_ctx,
261 const CXXRecordDecl *cxx_record_decl,
262 const CXXRecordDecl *base_class_decl) {
263 if (vtable_ctx.isMicrosoft()) {
264 clang::MicrosoftVTableContext &msoft_vtable_ctx =
265 static_cast<clang::MicrosoftVTableContext &
>(vtable_ctx);
269 const unsigned vbtable_index =
270 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
271 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
277 clang::ItaniumVTableContext &itanium_vtable_ctx =
278 static_cast<clang::ItaniumVTableContext &
>(vtable_ctx);
280 clang::CharUnits base_offset_offset =
281 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
284 vtable_ptr + base_offset_offset.getQuantity();
293 const ASTRecordLayout &record_layout,
294 const CXXRecordDecl *cxx_record_decl,
295 const CXXRecordDecl *base_class_decl,
296 int32_t &bit_offset) {
308 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
309 if (base_offset == INT64_MAX)
312 bit_offset = base_offset * 8;
322 static llvm::once_flag g_once_flag;
323 llvm::call_once(g_once_flag, []() {
330 bool is_complete_objc_class)
331 : m_payload(owning_module.GetValue()) {
343 const clang::Decl *parent) {
344 if (!member || !parent)
351 member->setFromASTFile();
352 member->setOwningModuleID(
id.GetValue());
353 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
354 if (llvm::isa<clang::NamedDecl>(member))
355 if (
auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
356 dc->setHasExternalVisibleStorage(
true);
359 dc->setHasExternalLexicalStorage(
true);
366 clang::OverloadedOperatorKind &op_kind) {
368 if (!name.consume_front(
"operator"))
373 bool space_after_operator = name.consume_front(
" ");
375 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
376 .Case(
"+", clang::OO_Plus)
377 .Case(
"+=", clang::OO_PlusEqual)
378 .Case(
"++", clang::OO_PlusPlus)
379 .Case(
"-", clang::OO_Minus)
380 .Case(
"-=", clang::OO_MinusEqual)
381 .Case(
"--", clang::OO_MinusMinus)
382 .Case(
"->", clang::OO_Arrow)
383 .Case(
"->*", clang::OO_ArrowStar)
384 .Case(
"*", clang::OO_Star)
385 .Case(
"*=", clang::OO_StarEqual)
386 .Case(
"/", clang::OO_Slash)
387 .Case(
"/=", clang::OO_SlashEqual)
388 .Case(
"%", clang::OO_Percent)
389 .Case(
"%=", clang::OO_PercentEqual)
390 .Case(
"^", clang::OO_Caret)
391 .Case(
"^=", clang::OO_CaretEqual)
392 .Case(
"&", clang::OO_Amp)
393 .Case(
"&=", clang::OO_AmpEqual)
394 .Case(
"&&", clang::OO_AmpAmp)
395 .Case(
"|", clang::OO_Pipe)
396 .Case(
"|=", clang::OO_PipeEqual)
397 .Case(
"||", clang::OO_PipePipe)
398 .Case(
"~", clang::OO_Tilde)
399 .Case(
"!", clang::OO_Exclaim)
400 .Case(
"!=", clang::OO_ExclaimEqual)
401 .Case(
"=", clang::OO_Equal)
402 .Case(
"==", clang::OO_EqualEqual)
403 .Case(
"<", clang::OO_Less)
404 .Case(
"<=>", clang::OO_Spaceship)
405 .Case(
"<<", clang::OO_LessLess)
406 .Case(
"<<=", clang::OO_LessLessEqual)
407 .Case(
"<=", clang::OO_LessEqual)
408 .Case(
">", clang::OO_Greater)
409 .Case(
">>", clang::OO_GreaterGreater)
410 .Case(
">>=", clang::OO_GreaterGreaterEqual)
411 .Case(
">=", clang::OO_GreaterEqual)
412 .Case(
"()", clang::OO_Call)
413 .Case(
"[]", clang::OO_Subscript)
414 .Case(
",", clang::OO_Comma)
415 .Default(clang::NUM_OVERLOADED_OPERATORS);
418 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
430 if (!space_after_operator)
435 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
436 .Case(
"new", clang::OO_New)
437 .Case(
"new[]", clang::OO_Array_New)
438 .Case(
"delete", clang::OO_Delete)
439 .Case(
"delete[]", clang::OO_Array_Delete)
441 .Default(clang::NUM_OVERLOADED_OPERATORS);
446clang::AccessSpecifier
466 std::vector<std::string> Includes;
467 LangOptions::setLangDefaults(Opts, clang::Language::ObjCXX, arch.
GetTriple(),
468 Includes, clang::LangStandard::lang_gnucxx98);
470 Opts.setValueVisibilityMode(DefaultVisibility);
474 Opts.Trigraphs = !Opts.GNUMode;
476 Opts.OptimizeSize = 0;
489 Opts.NoInlineDefine = !Opt;
493 Opts.ModulesLocalVisibility = 1;
497 llvm::Triple target_triple) {
499 if (!target_triple.str().empty())
509 ASTContext &existing_ctxt) {
525 if (!TypeSystemClangSupportsLanguage(language))
539 if (triple.getVendor() == llvm::Triple::Apple &&
540 triple.getOS() == llvm::Triple::UnknownOS) {
541 if (triple.getArch() == llvm::Triple::arm ||
542 triple.getArch() == llvm::Triple::aarch64 ||
543 triple.getArch() == llvm::Triple::aarch64_32 ||
544 triple.getArch() == llvm::Triple::thumb) {
545 triple.setOS(llvm::Triple::IOS);
547 triple.setOS(llvm::Triple::MacOSX);
552 std::string ast_name =
554 return std::make_shared<TypeSystemClang>(ast_name, triple);
555 }
else if (target && target->
IsValid())
556 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
618 assert(s ==
nullptr || &s->getASTContext() ==
m_ast_up.get());
631 llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
633 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(
true);
634 ast.setExternalSource(ast_source_up);
647 const clang::Diagnostic &info)
override {
649 llvm::SmallVector<char, 32> diag_str(10);
650 info.FormatDiagnostic(diag_str);
651 diag_str.push_back(
'\0');
652 LLDB_LOGF(m_log,
"Compiler diagnostic: %s\n", diag_str.data());
656 DiagnosticConsumer *
clone(DiagnosticsEngine &Diags)
const {
677 clang::FileSystemOptions file_system_options;
681 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(
new DiagnosticIDs());
683 std::make_unique<DiagnosticsEngine>(diag_id_sp,
new DiagnosticOptions());
687 m_ast_up = std::make_unique<ASTContext>(
699 m_ast_up->InitBuiltinTypes(*target_info);
703 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
736#pragma mark Basic Types
739 ASTContext &ast, QualType qual_type) {
740 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
741 return qual_type_bit_size == bit_size;
756 return GetType(ast.UnsignedCharTy);
758 return GetType(ast.UnsignedShortTy);
760 return GetType(ast.UnsignedIntTy);
762 return GetType(ast.UnsignedLongTy);
764 return GetType(ast.UnsignedLongLongTy);
766 return GetType(ast.UnsignedInt128Ty);
771 return GetType(ast.SignedCharTy);
779 return GetType(ast.LongLongTy);
790 return GetType(ast.LongDoubleTy);
797 if (bit_size && !(bit_size & 0x7u))
798 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
806 static const llvm::StringMap<lldb::BasicType> g_type_map = {
859 auto iter = g_type_map.find(name);
860 if (iter == g_type_map.end())
887 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
903 return GetType(ast.UnsignedCharTy);
905 return GetType(ast.UnsignedShortTy);
907 return GetType(ast.UnsignedIntTy);
912 if (type_name.contains(
"complex")) {
921 case DW_ATE_complex_float: {
922 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
924 return GetType(FloatComplexTy);
926 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
928 return GetType(DoubleComplexTy);
930 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
932 return GetType(LongDoubleComplexTy);
942 if (type_name ==
"float" &&
945 if (type_name ==
"double" &&
948 if (type_name ==
"long double" &&
950 return GetType(ast.LongDoubleTy);
957 return GetType(ast.LongDoubleTy);
963 if (!type_name.empty()) {
964 if (type_name ==
"wchar_t" &&
969 if (type_name ==
"void" &&
972 if (type_name.contains(
"long long") &&
974 return GetType(ast.LongLongTy);
975 if (type_name.contains(
"long") &&
978 if (type_name.contains(
"short") &&
981 if (type_name.contains(
"char")) {
985 return GetType(ast.SignedCharTy);
987 if (type_name.contains(
"int")) {
1004 return GetType(ast.LongLongTy);
1009 case DW_ATE_signed_char:
1010 if (type_name ==
"char") {
1015 return GetType(ast.SignedCharTy);
1018 case DW_ATE_unsigned:
1019 if (!type_name.empty()) {
1020 if (type_name ==
"wchar_t") {
1027 if (type_name.contains(
"long long")) {
1029 return GetType(ast.UnsignedLongLongTy);
1030 }
else if (type_name.contains(
"long")) {
1032 return GetType(ast.UnsignedLongTy);
1033 }
else if (type_name.contains(
"short")) {
1035 return GetType(ast.UnsignedShortTy);
1036 }
else if (type_name.contains(
"char")) {
1038 return GetType(ast.UnsignedCharTy);
1039 }
else if (type_name.contains(
"int")) {
1041 return GetType(ast.UnsignedIntTy);
1043 return GetType(ast.UnsignedInt128Ty);
1048 return GetType(ast.UnsignedCharTy);
1050 return GetType(ast.UnsignedShortTy);
1052 return GetType(ast.UnsignedIntTy);
1054 return GetType(ast.UnsignedLongTy);
1056 return GetType(ast.UnsignedLongLongTy);
1058 return GetType(ast.UnsignedInt128Ty);
1061 case DW_ATE_unsigned_char:
1062 if (type_name ==
"char") {
1067 return GetType(ast.UnsignedCharTy);
1069 return GetType(ast.UnsignedShortTy);
1072 case DW_ATE_imaginary_float:
1084 if (!type_name.empty()) {
1085 if (type_name ==
"char16_t")
1087 if (type_name ==
"char32_t")
1089 if (type_name ==
"char8_t")
1098 "error: need to add support for DW_TAG_base_type '{0}' "
1099 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1100 type_name, dw_ate, bit_size);
1106 QualType char_type(ast.CharTy);
1109 char_type.addConst();
1111 return GetType(ast.getPointerType(char_type));
1115 bool ignore_qualifiers) {
1126 if (ignore_qualifiers) {
1127 type1_qual = type1_qual.getUnqualifiedType();
1128 type2_qual = type2_qual.getUnqualifiedType();
1131 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1138 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
1139 if (
auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1151 if (clang::ObjCInterfaceDecl *interface_decl =
1152 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1154 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1156 if (clang::ValueDecl *value_decl = llvm::dyn_cast<clang::ValueDecl>(decl))
1170 return GetType(value_decl->getType());
1173#pragma mark Structure, Unions, Classes
1177 if (!decl || !owning_module.
HasValue())
1180 decl->setFromASTFile();
1181 decl->setOwningModuleID(owning_module.
GetValue());
1182 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1188 bool is_framework,
bool is_explicit) {
1190 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1192 assert(ast_source &&
"external ast source was lost");
1198 auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1209 clang::Module *module;
1210 auto parent_desc = ast_source->getSourceDescriptor(parent.
GetValue());
1212 name, parent_desc ? parent_desc->getModuleOrNull() :
nullptr,
1213 is_framework, is_explicit);
1215 return ast_source->GetIDForModule(module);
1217 return ast_source->RegisterModule(module);
1222 AccessType access_type, llvm::StringRef name,
int kind,
1223 LanguageType language, std::optional<ClangASTMetadata> metadata,
1224 bool exports_symbols) {
1227 if (decl_ctx ==
nullptr)
1228 decl_ctx = ast.getTranslationUnitDecl();
1232 bool isInternal =
false;
1233 return CreateObjCClass(name, decl_ctx, owning_module, isInternal, metadata);
1242 bool has_name = !name.empty();
1243 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1244 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1245 decl->setDeclContext(decl_ctx);
1247 decl->setDeclName(&ast.Idents.get(name));
1275 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1276 decl->setAnonymousStructOrUnion(
true);
1286 decl_ctx->addDecl(decl);
1288 return GetType(ast.getTagDeclType(decl));
1294bool IsValueParam(
const clang::TemplateArgument &argument) {
1295 return argument.getKind() == TemplateArgument::Integral;
1298void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1300 clang::AccessSpecifier previous_access,
1301 clang::AccessSpecifier access_specifier) {
1302 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1304 if (previous_access != access_specifier) {
1307 if ((cxx_record_decl->isStruct() &&
1308 previous_access == clang::AccessSpecifier::AS_none &&
1309 access_specifier == clang::AccessSpecifier::AS_public) ||
1310 (cxx_record_decl->isClass() &&
1311 previous_access == clang::AccessSpecifier::AS_none &&
1312 access_specifier == clang::AccessSpecifier::AS_private)) {
1315 cxx_record_decl->addDecl(
1316 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1317 SourceLocation(), SourceLocation()));
1325 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1326 const bool parameter_pack =
false;
1327 const bool is_typename =
false;
1328 const unsigned depth = 0;
1329 const size_t num_template_params = template_param_infos.
Size();
1330 DeclContext *
const decl_context =
1331 ast.getTranslationUnitDecl();
1333 auto const &args = template_param_infos.
GetArgs();
1334 auto const &names = template_param_infos.
GetNames();
1335 for (
size_t i = 0; i < num_template_params; ++i) {
1336 const char *name = names[i];
1338 IdentifierInfo *identifier_info =
nullptr;
1339 if (name && name[0])
1340 identifier_info = &ast.Idents.get(name);
1341 TemplateArgument
const &targ = args[i];
1342 if (IsValueParam(targ)) {
1343 QualType template_param_type = targ.getIntegralType();
1344 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1345 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1346 identifier_info, template_param_type, parameter_pack,
1347 ast.getTrivialTypeSourceInfo(template_param_type)));
1349 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1350 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1351 identifier_info, is_typename, parameter_pack));
1356 IdentifierInfo *identifier_info =
nullptr;
1358 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1359 const bool parameter_pack_true =
true;
1363 QualType template_param_type =
1365 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1366 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1367 num_template_params, identifier_info, template_param_type,
1368 parameter_pack_true,
1369 ast.getTrivialTypeSourceInfo(template_param_type)));
1371 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1372 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1373 num_template_params, identifier_info, is_typename,
1374 parameter_pack_true));
1377 clang::Expr *
const requires_clause =
nullptr;
1378 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1379 ast, SourceLocation(), SourceLocation(), template_param_decls,
1380 SourceLocation(), requires_clause);
1381 return template_param_list;
1386 llvm::SmallVector<NamedDecl *, 8> ignore;
1387 clang::TemplateParameterList *template_param_list =
1390 llvm::SmallVector<clang::TemplateArgument, 2> args(
1391 template_param_infos.
GetArgs());
1393 llvm::ArrayRef<TemplateArgument> pack_args =
1395 args.append(pack_args.begin(), pack_args.end());
1398 llvm::raw_string_ostream os(str);
1400 template_param_list);
1406 clang::FunctionDecl *func_decl,
1411 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1413 ast, template_param_infos, template_param_decls);
1414 FunctionTemplateDecl *func_tmpl_decl =
1415 FunctionTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1416 func_tmpl_decl->setDeclContext(decl_ctx);
1417 func_tmpl_decl->setLocation(func_decl->getLocation());
1418 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1419 func_tmpl_decl->setTemplateParameters(template_param_list);
1420 func_tmpl_decl->init(func_decl);
1423 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1424 i < template_param_decl_count; ++i) {
1426 template_param_decls[i]->setDeclContext(func_decl);
1431 if (decl_ctx->isRecord())
1432 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1434 return func_tmpl_decl;
1438 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1440 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1441 func_decl->getASTContext(), infos.
GetArgs());
1443 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1444 template_args_ptr,
nullptr);
1451 const TemplateArgument &value) {
1452 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1454 if (value.getKind() != TemplateArgument::Type)
1456 }
else if (
auto *type_param =
1457 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1459 if (!IsValueParam(value))
1462 if (type_param->getType() != value.getIntegralType())
1470 "Don't know how to compare template parameter to passed"
1471 " value. Decl kind of parameter is: {0}",
1472 param->getDeclKindName());
1473 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1488 ClassTemplateDecl *class_template_decl,
1491 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1497 std::optional<NamedDecl *> pack_parameter;
1499 size_t non_pack_params = params.size();
1500 for (
size_t i = 0; i < params.size(); ++i) {
1501 NamedDecl *param = params.getParam(i);
1502 if (param->isParameterPack()) {
1503 pack_parameter = param;
1504 non_pack_params = i;
1512 if (non_pack_params != instantiation_values.
Size())
1530 for (
const auto pair :
1531 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1532 const TemplateArgument &passed_arg = std::get<0>(pair);
1533 NamedDecl *found_param = std::get<1>(pair);
1538 return class_template_decl;
1547 ClassTemplateDecl *class_template_decl =
nullptr;
1548 if (decl_ctx ==
nullptr)
1549 decl_ctx = ast.getTranslationUnitDecl();
1551 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1552 DeclarationName decl_name(&identifier_info);
1555 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1556 for (NamedDecl *decl : result) {
1557 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1558 if (!class_template_decl)
1567 template_param_infos))
1569 return class_template_decl;
1572 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1575 ast, template_param_infos, template_param_decls);
1577 CXXRecordDecl *template_cxx_decl =
1578 CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1579 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1581 template_cxx_decl->setDeclContext(decl_ctx);
1582 template_cxx_decl->setDeclName(decl_name);
1585 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1586 i < template_param_decl_count; ++i) {
1587 template_param_decls[i]->setDeclContext(template_cxx_decl);
1595 class_template_decl =
1596 ClassTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1598 class_template_decl->setDeclContext(decl_ctx);
1599 class_template_decl->setDeclName(decl_name);
1600 class_template_decl->setTemplateParameters(template_param_list);
1601 class_template_decl->init(template_cxx_decl);
1602 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1606 class_template_decl->setAccess(
1609 decl_ctx->addDecl(class_template_decl);
1611 VerifyDecl(class_template_decl);
1613 return class_template_decl;
1616TemplateTemplateParmDecl *
1620 auto *decl_ctx = ast.getTranslationUnitDecl();
1622 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1623 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1627 ast, template_param_infos, template_param_decls);
1633 return TemplateTemplateParmDecl::Create(ast, decl_ctx, SourceLocation(),
1636 &identifier_info,
false,
1637 template_param_list);
1640ClassTemplateSpecializationDecl *
1643 ClassTemplateDecl *class_template_decl,
int kind,
1646 llvm::SmallVector<clang::TemplateArgument, 2> args(
1647 template_param_infos.
Size() +
1650 auto const &orig_args = template_param_infos.
GetArgs();
1651 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1653 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1656 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1657 ClassTemplateSpecializationDecl::CreateDeserialized(ast, GlobalDeclID());
1658 class_template_specialization_decl->setTagKind(
1659 static_cast<TagDecl::TagKind
>(kind));
1660 class_template_specialization_decl->setDeclContext(decl_ctx);
1661 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1662 class_template_specialization_decl->setTemplateArgs(
1663 TemplateArgumentList::CreateCopy(ast, args));
1664 ast.getTypeDeclType(class_template_specialization_decl,
nullptr);
1665 class_template_specialization_decl->setDeclName(
1666 class_template_decl->getDeclName());
1668 decl_ctx->addDecl(class_template_specialization_decl);
1670 class_template_specialization_decl->setSpecializationKind(
1671 TSK_ExplicitSpecialization);
1673 return class_template_specialization_decl;
1677 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1678 if (class_template_specialization_decl) {
1680 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1686 clang::OverloadedOperatorKind op_kind,
1687 bool unary,
bool binary,
1688 uint32_t num_params) {
1690 if (op_kind == OO_Call)
1696 if (num_params == 1)
1698 if (num_params == 2)
1705 bool is_method, clang::OverloadedOperatorKind op_kind,
1706 uint32_t num_params) {
1714 case OO_Array_Delete:
1718#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1720 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1722#include "clang/Basic/OperatorKinds.def"
1729clang::AccessSpecifier
1731 clang::AccessSpecifier rhs) {
1734 if (lhs == AS_none || rhs == AS_none)
1736 if (lhs == AS_private || rhs == AS_private)
1738 if (lhs == AS_protected || rhs == AS_protected)
1739 return AS_protected;
1744 uint32_t &bitfield_bit_size) {
1746 if (field ==
nullptr)
1749 if (field->isBitField()) {
1750 Expr *bit_width_expr = field->getBitWidth();
1751 if (bit_width_expr) {
1752 if (std::optional<llvm::APSInt> bit_width_apsint =
1753 bit_width_expr->getIntegerConstantExpr(ast)) {
1754 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1763 if (record_decl ==
nullptr)
1766 if (!record_decl->field_empty())
1770 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1771 if (cxx_record_decl) {
1772 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1773 for (base_class = cxx_record_decl->bases_begin(),
1774 base_class_end = cxx_record_decl->bases_end();
1775 base_class != base_class_end; ++base_class) {
1776 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1777 base_class->getType()->getAs<RecordType>()->getDecl());
1789 if (std::optional<ClangASTMetadata> meta_data =
GetMetadata(record_decl);
1790 meta_data && meta_data->IsForcefullyCompleted())
1796#pragma mark Objective-C Classes
1799 llvm::StringRef name, clang::DeclContext *decl_ctx,
1801 std::optional<ClangASTMetadata> metadata) {
1803 assert(!name.empty());
1805 decl_ctx = ast.getTranslationUnitDecl();
1807 ObjCInterfaceDecl *decl =
1808 ObjCInterfaceDecl::CreateDeserialized(ast, GlobalDeclID());
1809 decl->setDeclContext(decl_ctx);
1810 decl->setDeclName(&ast.Idents.get(name));
1811 decl->setImplicit(isInternal);
1817 return GetType(ast.getObjCInterfaceType(decl));
1826 bool omit_empty_base_classes) {
1827 uint32_t num_bases = 0;
1828 if (cxx_record_decl) {
1829 if (omit_empty_base_classes) {
1830 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1831 for (base_class = cxx_record_decl->bases_begin(),
1832 base_class_end = cxx_record_decl->bases_end();
1833 base_class != base_class_end; ++base_class) {
1840 num_bases = cxx_record_decl->getNumBases();
1845#pragma mark Namespace Declarations
1848 const char *name, clang::DeclContext *decl_ctx,
1850 NamespaceDecl *namespace_decl =
nullptr;
1852 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1854 decl_ctx = translation_unit_decl;
1857 IdentifierInfo &identifier_info = ast.Idents.get(name);
1858 DeclarationName decl_name(&identifier_info);
1859 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1860 for (NamedDecl *decl : result) {
1861 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1863 return namespace_decl;
1866 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1867 SourceLocation(), SourceLocation(),
1868 &identifier_info,
nullptr,
false);
1870 decl_ctx->addDecl(namespace_decl);
1872 if (decl_ctx == translation_unit_decl) {
1873 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1875 return namespace_decl;
1878 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1879 SourceLocation(),
nullptr,
nullptr,
false);
1880 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1881 translation_unit_decl->addDecl(namespace_decl);
1882 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1884 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1885 if (parent_namespace_decl) {
1886 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1888 return namespace_decl;
1890 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1891 SourceLocation(),
nullptr,
nullptr,
false);
1892 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1893 parent_namespace_decl->addDecl(namespace_decl);
1894 assert(namespace_decl ==
1895 parent_namespace_decl->getAnonymousNamespace());
1897 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1898 "no namespace as decl_ctx");
1906 VerifyDecl(namespace_decl);
1907 return namespace_decl;
1914 clang::BlockDecl *decl =
1915 clang::BlockDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1916 decl->setDeclContext(ctx);
1925 clang::DeclContext *right,
1926 clang::DeclContext *root) {
1927 if (root ==
nullptr)
1930 std::set<clang::DeclContext *> path_left;
1931 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1932 path_left.insert(d);
1934 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1935 if (path_left.find(d) != path_left.end())
1943 clang::NamespaceDecl *ns_decl) {
1944 if (decl_ctx && ns_decl) {
1945 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1946 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1948 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1949 clang::SourceLocation(), ns_decl,
1952 decl_ctx->addDecl(using_decl);
1962 clang::NamedDecl *target) {
1963 if (current_decl_ctx && target) {
1964 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1966 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1968 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1970 target->getDeclName(), using_decl, target);
1972 using_decl->addShadowDecl(shadow_decl);
1973 current_decl_ctx->addDecl(using_decl);
1981 const char *name, clang::QualType type) {
1983 clang::VarDecl *var_decl =
1984 clang::VarDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1985 var_decl->setDeclContext(decl_context);
1986 if (name && name[0])
1987 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1988 var_decl->setType(type);
1990 var_decl->setAccess(clang::AS_public);
1991 decl_context->addDecl(var_decl);
2000 switch (basic_type) {
2002 return ast->VoidTy.getAsOpaquePtr();
2004 return ast->CharTy.getAsOpaquePtr();
2006 return ast->SignedCharTy.getAsOpaquePtr();
2008 return ast->UnsignedCharTy.getAsOpaquePtr();
2010 return ast->getWCharType().getAsOpaquePtr();
2012 return ast->getSignedWCharType().getAsOpaquePtr();
2014 return ast->getUnsignedWCharType().getAsOpaquePtr();
2016 return ast->Char8Ty.getAsOpaquePtr();
2018 return ast->Char16Ty.getAsOpaquePtr();
2020 return ast->Char32Ty.getAsOpaquePtr();
2022 return ast->ShortTy.getAsOpaquePtr();
2024 return ast->UnsignedShortTy.getAsOpaquePtr();
2026 return ast->IntTy.getAsOpaquePtr();
2028 return ast->UnsignedIntTy.getAsOpaquePtr();
2030 return ast->LongTy.getAsOpaquePtr();
2032 return ast->UnsignedLongTy.getAsOpaquePtr();
2034 return ast->LongLongTy.getAsOpaquePtr();
2036 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2038 return ast->Int128Ty.getAsOpaquePtr();
2040 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2042 return ast->BoolTy.getAsOpaquePtr();
2044 return ast->HalfTy.getAsOpaquePtr();
2046 return ast->FloatTy.getAsOpaquePtr();
2048 return ast->DoubleTy.getAsOpaquePtr();
2050 return ast->LongDoubleTy.getAsOpaquePtr();
2052 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2054 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2056 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2058 return ast->getObjCIdType().getAsOpaquePtr();
2060 return ast->getObjCClassType().getAsOpaquePtr();
2062 return ast->getObjCSelType().getAsOpaquePtr();
2064 return ast->NullPtrTy.getAsOpaquePtr();
2070#pragma mark Function Types
2072clang::DeclarationName
2075 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2076 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2085 const clang::FunctionProtoType *function_type =
2086 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2087 if (function_type ==
nullptr)
2088 return clang::DeclarationName();
2090 const bool is_method =
false;
2091 const unsigned int num_params = function_type->getNumParams();
2093 is_method, op_kind, num_params))
2094 return clang::DeclarationName();
2096 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2100 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2101 printing_policy.SuppressTagKeyword =
true;
2104 printing_policy.SuppressInlineNamespace =
false;
2105 printing_policy.SuppressUnwrittenScope =
false;
2117 printing_policy.SuppressDefaultTemplateArgs =
false;
2118 return printing_policy;
2125 llvm::raw_string_ostream os(result);
2126 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2132 llvm::StringRef name,
const CompilerType &function_clang_type,
2133 clang::StorageClass storage,
bool is_inline) {
2134 FunctionDecl *func_decl =
nullptr;
2137 decl_ctx = ast.getTranslationUnitDecl();
2139 const bool hasWrittenPrototype =
true;
2140 const bool isConstexprSpecified =
false;
2142 clang::DeclarationName declarationName =
2144 func_decl = FunctionDecl::CreateDeserialized(ast, GlobalDeclID());
2145 func_decl->setDeclContext(decl_ctx);
2146 func_decl->setDeclName(declarationName);
2148 func_decl->setStorageClass(storage);
2149 func_decl->setInlineSpecified(is_inline);
2150 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2151 func_decl->setConstexprKind(isConstexprSpecified
2152 ? ConstexprSpecKind::Constexpr
2153 : ConstexprSpecKind::Unspecified);
2155 decl_ctx->addDecl(func_decl);
2157 VerifyDecl(func_decl);
2164 unsigned num_args,
bool is_variadic,
unsigned type_quals,
2165 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2169 std::vector<QualType> qual_type_args;
2170 if (num_args > 0 && args ==
nullptr)
2174 for (
unsigned i = 0; i < num_args; ++i) {
2189 FunctionProtoType::ExtProtoInfo proto_info;
2190 proto_info.ExtInfo = cc;
2191 proto_info.Variadic = is_variadic;
2192 proto_info.ExceptionSpec = EST_None;
2193 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2194 proto_info.RefQualifier = ref_qual;
2202 const char *name,
const CompilerType ¶m_type,
int storage,
2205 auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
2206 decl->setDeclContext(decl_ctx);
2207 if (name && name[0])
2208 decl->setDeclName(&ast.Idents.get(name));
2210 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2213 decl_ctx->addDecl(decl);
2219 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2221 function_decl->setParams(params);
2226 QualType block_type =
m_ast_up->getBlockPointerType(
2232#pragma mark Array Types
2236 std::optional<size_t> element_count,
2249 clang::ArraySizeModifier::Normal, 0));
2255 llvm::APInt ap_element_count(64, *element_count);
2257 ap_element_count,
nullptr,
2258 clang::ArraySizeModifier::Normal, 0));
2262 llvm::StringRef type_name,
2263 const std::initializer_list<std::pair<const char *, CompilerType>>
2267 if (!type_name.empty() &&
2268 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2270 lldbassert(0 &&
"Trying to create a type for an existing name");
2278 for (
const auto &field : type_fields)
2288 llvm::StringRef type_name,
2289 const std::initializer_list<std::pair<const char *, CompilerType>>
2293 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2299#pragma mark Enumeration Types
2302 llvm::StringRef name, clang::DeclContext *decl_ctx,
2304 const CompilerType &integer_clang_type,
bool is_scoped) {
2311 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
2312 enum_decl->setDeclContext(decl_ctx);
2314 enum_decl->setDeclName(&ast.Idents.get(name));
2315 enum_decl->setScoped(is_scoped);
2316 enum_decl->setScopedUsingClassTag(is_scoped);
2317 enum_decl->setFixed(
false);
2320 decl_ctx->addDecl(enum_decl);
2325 enum_decl->setAccess(AS_public);
2327 return GetType(ast.getTagDeclType(enum_decl));
2335 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2336 return GetType(ast.SignedCharTy);
2338 if (bit_size == ast.getTypeSize(ast.ShortTy))
2341 if (bit_size == ast.getTypeSize(ast.IntTy))
2344 if (bit_size == ast.getTypeSize(ast.LongTy))
2347 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2348 return GetType(ast.LongLongTy);
2350 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2353 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2354 return GetType(ast.UnsignedCharTy);
2356 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2357 return GetType(ast.UnsignedShortTy);
2359 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2360 return GetType(ast.UnsignedIntTy);
2362 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2363 return GetType(ast.UnsignedLongTy);
2365 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2366 return GetType(ast.UnsignedLongLongTy);
2368 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2369 return GetType(ast.UnsignedInt128Ty);
2383 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2385 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2386 named_decl->getDeclName().getAsString().c_str());
2388 printf(
"%20s\n", decl_ctx->getDeclKindName());
2394 if (decl ==
nullptr)
2398 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2400 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2401 record_decl->getDeclName().getAsString().c_str(),
2402 record_decl->isInjectedClassName() ?
" (injected class name)" :
"");
2405 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2407 printf(
"%20s: %s\n", decl->getDeclKindName(),
2408 named_decl->getDeclName().getAsString().c_str());
2410 printf(
"%20s\n", decl->getDeclKindName());
2416 clang::Decl *decl) {
2420 ExternalASTSource *ast_source = ast->getExternalSource();
2425 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2426 if (tag_decl->isCompleteDefinition())
2429 if (!tag_decl->hasExternalLexicalStorage())
2432 ast_source->CompleteType(tag_decl);
2434 return !tag_decl->getTypeForDecl()->isIncompleteType();
2435 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2436 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2437 if (objc_interface_decl->getDefinition())
2440 if (!objc_interface_decl->hasExternalLexicalStorage())
2443 ast_source->CompleteType(objc_interface_decl);
2445 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2475std::optional<ClangASTMetadata>
2481 return std::nullopt;
2484std::optional<ClangASTMetadata>
2490 return std::nullopt;
2494 clang::AccessSpecifier access) {
2495 if (access == clang::AccessSpecifier::AS_none)
2501clang::AccessSpecifier
2506 return clang::AccessSpecifier::AS_none;
2528 if (find(mask, type->getTypeClass()) != mask.end())
2530 switch (type->getTypeClass()) {
2533 case clang::Type::Atomic:
2534 type = cast<clang::AtomicType>(type)->getValueType();
2536 case clang::Type::Auto:
2537 case clang::Type::Decltype:
2538 case clang::Type::Elaborated:
2539 case clang::Type::Paren:
2540 case clang::Type::SubstTemplateTypeParm:
2541 case clang::Type::TemplateSpecialization:
2542 case clang::Type::Typedef:
2543 case clang::Type::TypeOf:
2544 case clang::Type::TypeOfExpr:
2545 case clang::Type::Using:
2546 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2560 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2561 switch (type_class) {
2562 case clang::Type::ObjCInterface:
2563 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2565 case clang::Type::ObjCObjectPointer:
2567 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2568 ->getPointeeType());
2569 case clang::Type::Record:
2570 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2571 case clang::Type::Enum:
2572 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2585 clang::QualType qual_type,
2586 bool allow_completion) {
2587 assert(qual_type->isRecordType());
2589 const auto *tag_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2591 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2595 if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
2598 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2599 const bool fields_loaded =
2600 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2603 if (is_complete && fields_loaded)
2606 if (!allow_completion)
2614 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2615 if (external_ast_source) {
2616 external_ast_source->CompleteType(cxx_record_decl);
2617 if (cxx_record_decl->isCompleteDefinition()) {
2618 cxx_record_decl->field_begin();
2619 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2631 clang::QualType qual_type,
2632 bool allow_completion) {
2633 assert(qual_type->isEnumeralType());
2636 const clang::EnumType *enum_type =
2637 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
2639 auto *tag_decl = enum_type->getAsTagDecl();
2643 if (tag_decl->getDefinition())
2646 if (!allow_completion)
2650 if (!tag_decl->hasExternalLexicalStorage())
2654 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2655 if (!external_ast_source)
2658 external_ast_source->CompleteType(tag_decl);
2666static const clang::ObjCObjectType *
2668 bool allow_completion) {
2669 assert(qual_type->isObjCObjectType());
2672 const clang::ObjCObjectType *objc_class_type =
2673 llvm::cast<clang::ObjCObjectType>(qual_type);
2675 clang::ObjCInterfaceDecl *class_interface_decl =
2676 objc_class_type->getInterface();
2679 if (!class_interface_decl)
2680 return objc_class_type;
2683 if (class_interface_decl->getDefinition())
2684 return objc_class_type;
2686 if (!allow_completion)
2690 if (!class_interface_decl->hasExternalLexicalStorage())
2694 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2695 if (!external_ast_source)
2698 external_ast_source->CompleteType(class_interface_decl);
2699 return objc_class_type;
2703 clang::QualType qual_type,
2704 bool allow_completion =
true) {
2706 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2707 switch (type_class) {
2708 case clang::Type::ConstantArray:
2709 case clang::Type::IncompleteArray:
2710 case clang::Type::VariableArray: {
2711 const clang::ArrayType *array_type =
2712 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2718 case clang::Type::Record: {
2719 if (
const auto *RT =
2721 return !RT->isIncompleteType();
2726 case clang::Type::Enum: {
2728 return !ET->isIncompleteType();
2732 case clang::Type::ObjCObject:
2733 case clang::Type::ObjCInterface: {
2734 if (
const auto *OT =
2736 return !OT->isIncompleteType();
2741 case clang::Type::Attributed:
2743 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2753static clang::ObjCIvarDecl::AccessControl
2757 return clang::ObjCIvarDecl::None;
2759 return clang::ObjCIvarDecl::Public;
2761 return clang::ObjCIvarDecl::Private;
2763 return clang::ObjCIvarDecl::Protected;
2765 return clang::ObjCIvarDecl::Package;
2767 return clang::ObjCIvarDecl::None;
2774 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2781 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2782 switch (type_class) {
2783 case clang::Type::IncompleteArray:
2784 case clang::Type::VariableArray:
2785 case clang::Type::ConstantArray:
2786 case clang::Type::ExtVector:
2787 case clang::Type::Vector:
2788 case clang::Type::Record:
2789 case clang::Type::ObjCObject:
2790 case clang::Type::ObjCInterface:
2802 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2803 switch (type_class) {
2804 case clang::Type::Record: {
2805 if (
const clang::RecordType *record_type =
2806 llvm::dyn_cast_or_null<clang::RecordType>(
2807 qual_type.getTypePtrOrNull())) {
2808 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2809 return record_decl->isAnonymousStructOrUnion();
2823 uint64_t *size,
bool *is_incomplete) {
2826 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2827 switch (type_class) {
2831 case clang::Type::ConstantArray:
2832 if (element_type_ptr)
2834 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2838 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2840 .getLimitedValue(ULLONG_MAX);
2842 *is_incomplete =
false;
2845 case clang::Type::IncompleteArray:
2846 if (element_type_ptr)
2848 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2854 *is_incomplete =
true;
2857 case clang::Type::VariableArray:
2858 if (element_type_ptr)
2860 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2866 *is_incomplete =
false;
2869 case clang::Type::DependentSizedArray:
2870 if (element_type_ptr)
2873 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2879 *is_incomplete =
false;
2882 if (element_type_ptr)
2883 element_type_ptr->
Clear();
2887 *is_incomplete =
false;
2895 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2896 switch (type_class) {
2897 case clang::Type::Vector: {
2898 const clang::VectorType *vector_type =
2899 qual_type->getAs<clang::VectorType>();
2902 *size = vector_type->getNumElements();
2904 *element_type =
GetType(vector_type->getElementType());
2908 case clang::Type::ExtVector: {
2909 const clang::ExtVectorType *ext_vector_type =
2910 qual_type->getAs<clang::ExtVectorType>();
2911 if (ext_vector_type) {
2913 *size = ext_vector_type->getNumElements();
2917 ext_vector_type->getElementType().getAsOpaquePtr());
2933 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2936 clang::ObjCInterfaceDecl *result_iface_decl =
2937 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2939 std::optional<ClangASTMetadata> ast_metadata =
GetMetadata(result_iface_decl);
2943 return (ast_metadata->GetISAPtr() != 0);
2947 return GetQualType(type).getUnqualifiedType()->isCharType();
2956 const bool allow_completion =
true;
2971 if (!pointee_or_element_clang_type.
IsValid())
2974 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2975 if (pointee_or_element_clang_type.
IsCharType()) {
2976 if (type_flags.
Test(eTypeIsArray)) {
2979 length = llvm::cast<clang::ConstantArrayType>(
2993 if (
auto pointer_auth = qual_type.getPointerAuth())
2994 return pointer_auth.getKey();
3003 if (
auto pointer_auth = qual_type.getPointerAuth())
3004 return pointer_auth.getExtraDiscriminator();
3013 if (
auto pointer_auth = qual_type.getPointerAuth())
3014 return pointer_auth.isAddressDiscriminated();
3020 auto isFunctionType = [&](clang::QualType qual_type) {
3021 return qual_type->isFunctionType();
3035 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3036 switch (type_class) {
3037 case clang::Type::Record:
3039 const clang::CXXRecordDecl *cxx_record_decl =
3040 qual_type->getAsCXXRecordDecl();
3041 if (cxx_record_decl) {
3042 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3045 const clang::RecordType *record_type =
3046 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3048 const clang::RecordDecl *record_decl = record_type->getDecl();
3052 clang::RecordDecl::field_iterator field_pos,
3053 field_end = record_decl->field_end();
3054 uint32_t num_fields = 0;
3055 bool is_hva =
false;
3056 bool is_hfa =
false;
3057 clang::QualType base_qual_type;
3058 uint64_t base_bitwidth = 0;
3059 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3061 clang::QualType field_qual_type = field_pos->getType();
3062 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
3063 if (field_qual_type->isFloatingType()) {
3064 if (field_qual_type->isComplexType())
3067 if (num_fields == 0)
3068 base_qual_type = field_qual_type;
3073 if (field_qual_type.getTypePtr() !=
3074 base_qual_type.getTypePtr())
3078 }
else if (field_qual_type->isVectorType() ||
3079 field_qual_type->isExtVectorType()) {
3080 if (num_fields == 0) {
3081 base_qual_type = field_qual_type;
3082 base_bitwidth = field_bitwidth;
3087 if (base_bitwidth != field_bitwidth)
3089 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3098 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3115 const clang::FunctionProtoType *func =
3116 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3118 return func->getNumParams();
3125 const size_t index) {
3128 const clang::FunctionProtoType *func =
3129 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3131 if (index < func->getNumParams())
3132 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3140 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3144 if (predicate(qual_type))
3147 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3148 switch (type_class) {
3152 case clang::Type::LValueReference:
3153 case clang::Type::RValueReference: {
3154 const clang::ReferenceType *reference_type =
3155 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3157 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3166 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3167 return qual_type->isMemberFunctionPointerType();
3170 return IsTypeImpl(type, isMemberFunctionPointerType);
3174 auto isFunctionPointerType = [](clang::QualType qual_type) {
3175 return qual_type->isFunctionPointerType();
3178 return IsTypeImpl(type, isFunctionPointerType);
3184 auto isBlockPointerType = [&](clang::QualType qual_type) {
3185 if (qual_type->isBlockPointerType()) {
3186 if (function_pointer_type_ptr) {
3187 const clang::BlockPointerType *block_pointer_type =
3188 qual_type->castAs<clang::BlockPointerType>();
3189 QualType pointee_type = block_pointer_type->getPointeeType();
3190 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3192 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3209 const clang::BuiltinType *builtin_type =
3210 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3213 if (builtin_type->isInteger()) {
3214 is_signed = builtin_type->isSignedInteger();
3225 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3229 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3241 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3245 return enum_type->isScopedEnumeralType();
3256 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3257 switch (type_class) {
3258 case clang::Type::Builtin:
3259 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3262 case clang::BuiltinType::ObjCId:
3263 case clang::BuiltinType::ObjCClass:
3267 case clang::Type::ObjCObjectPointer:
3271 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3275 case clang::Type::BlockPointer:
3278 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3282 case clang::Type::Pointer:
3285 llvm::cast<clang::PointerType>(qual_type)
3289 case clang::Type::MemberPointer:
3292 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3301 pointee_type->
Clear();
3309 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3310 switch (type_class) {
3311 case clang::Type::Builtin:
3312 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3315 case clang::BuiltinType::ObjCId:
3316 case clang::BuiltinType::ObjCClass:
3320 case clang::Type::ObjCObjectPointer:
3324 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3328 case clang::Type::BlockPointer:
3331 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3335 case clang::Type::Pointer:
3338 llvm::cast<clang::PointerType>(qual_type)
3342 case clang::Type::MemberPointer:
3345 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3349 case clang::Type::LValueReference:
3352 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3356 case clang::Type::RValueReference:
3359 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3368 pointee_type->
Clear();
3377 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3379 switch (type_class) {
3380 case clang::Type::LValueReference:
3383 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3389 case clang::Type::RValueReference:
3392 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3404 pointee_type->
Clear();
3409 uint32_t &count,
bool &is_complex) {
3413 if (
const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3414 qual_type->getCanonicalTypeInternal())) {
3415 clang::BuiltinType::Kind kind = BT->getKind();
3416 if (kind >= clang::BuiltinType::Float &&
3417 kind <= clang::BuiltinType::LongDouble) {
3422 }
else if (
const clang::ComplexType *CT =
3423 llvm::dyn_cast<clang::ComplexType>(
3424 qual_type->getCanonicalTypeInternal())) {
3431 }
else if (
const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3432 qual_type->getCanonicalTypeInternal())) {
3435 count = VT->getNumElements();
3451 const clang::TagType *tag_type =
3452 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3454 clang::TagDecl *tag_decl = tag_type->getDecl();
3456 return tag_decl->isCompleteDefinition();
3459 const clang::ObjCObjectType *objc_class_type =
3460 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3461 if (objc_class_type) {
3462 clang::ObjCInterfaceDecl *class_interface_decl =
3463 objc_class_type->getInterface();
3464 if (class_interface_decl)
3465 return class_interface_decl->getDefinition() !=
nullptr;
3476 const clang::ObjCObjectPointerType *obj_pointer_type =
3477 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3479 if (obj_pointer_type)
3480 return obj_pointer_type->isObjCClassType();
3495 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3496 return (type_class == clang::Type::Record);
3503 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3504 return (type_class == clang::Type::Enum);
3510 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3511 switch (type_class) {
3512 case clang::Type::Record:
3514 const clang::RecordType *record_type =
3515 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3516 const clang::RecordDecl *record_decl = record_type->getDecl();
3518 const clang::CXXRecordDecl *cxx_record_decl =
3519 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3520 if (cxx_record_decl) {
3527 return cxx_record_decl->isDynamicClass();
3542 bool check_cplusplus,
3544 clang::QualType pointee_qual_type;
3547 bool success =
false;
3548 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3549 switch (type_class) {
3550 case clang::Type::Builtin:
3552 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3553 clang::BuiltinType::ObjCId) {
3554 if (dynamic_pointee_type)
3560 case clang::Type::ObjCObjectPointer:
3562 if (
const auto *objc_pointee_type =
3563 qual_type->getPointeeType().getTypePtrOrNull()) {
3564 if (
const auto *objc_object_type =
3565 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3566 objc_pointee_type)) {
3567 if (objc_object_type->isObjCClass())
3571 if (dynamic_pointee_type)
3574 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3581 case clang::Type::Pointer:
3583 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3587 case clang::Type::LValueReference:
3588 case clang::Type::RValueReference:
3590 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3602 const clang::Type::TypeClass pointee_type_class =
3603 pointee_qual_type.getCanonicalType()->getTypeClass();
3604 switch (pointee_type_class) {
3605 case clang::Type::Builtin:
3606 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3607 case clang::BuiltinType::UnknownAny:
3608 case clang::BuiltinType::Void:
3609 if (dynamic_pointee_type)
3611 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3618 case clang::Type::Record:
3619 if (check_cplusplus) {
3620 clang::CXXRecordDecl *cxx_record_decl =
3621 pointee_qual_type->getAsCXXRecordDecl();
3622 if (cxx_record_decl) {
3623 bool is_complete = cxx_record_decl->isCompleteDefinition();
3626 success = cxx_record_decl->isDynamicClass();
3628 if (std::optional<ClangASTMetadata> metadata =
3630 success = metadata->GetIsDynamicCXXType();
3634 success = cxx_record_decl->isDynamicClass();
3641 if (dynamic_pointee_type)
3643 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3650 case clang::Type::ObjCObject:
3651 case clang::Type::ObjCInterface:
3653 if (dynamic_pointee_type)
3655 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3665 if (dynamic_pointee_type)
3666 dynamic_pointee_type->
Clear();
3674 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3681 ->getTypeClass() == clang::Type::Typedef;
3691 if (
auto *record_decl =
3693 return record_decl->canPassInRegisters();
3699 return TypeSystemClangSupportsLanguage(language);
3702std::optional<std::string>
3705 return std::nullopt;
3708 if (qual_type.isNull())
3709 return std::nullopt;
3711 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3712 if (!cxx_record_decl)
3713 return std::nullopt;
3715 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3723 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3730 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3732 return tag_type->isBeingDefined();
3743 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3744 if (class_type_ptr) {
3745 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3746 const clang::ObjCObjectPointerType *obj_pointer_type =
3747 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3748 if (obj_pointer_type ==
nullptr)
3749 class_type_ptr->
Clear();
3753 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3760 class_type_ptr->
Clear();
3769 const bool allow_completion =
true;
3789 {clang::Type::Typedef, clang::Type::Atomic});
3792 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3793 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3800 if (
auto *named_decl = qual_type->getAsTagDecl())
3812 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3813 printing_policy.SuppressTagKeyword =
true;
3814 printing_policy.SuppressScope =
false;
3815 printing_policy.SuppressUnwrittenScope =
true;
3816 printing_policy.SuppressInlineNamespace =
true;
3817 return ConstString(qual_type.getAsString(printing_policy));
3826 if (pointee_or_element_clang_type)
3827 pointee_or_element_clang_type->
Clear();
3829 clang::QualType qual_type =
3832 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3833 switch (type_class) {
3834 case clang::Type::Attributed:
3835 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3838 pointee_or_element_clang_type);
3839 case clang::Type::Builtin: {
3840 const clang::BuiltinType *builtin_type =
3841 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3843 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3844 switch (builtin_type->getKind()) {
3845 case clang::BuiltinType::ObjCId:
3846 case clang::BuiltinType::ObjCClass:
3847 if (pointee_or_element_clang_type)
3851 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3854 case clang::BuiltinType::ObjCSel:
3855 if (pointee_or_element_clang_type)
3858 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3861 case clang::BuiltinType::Bool:
3862 case clang::BuiltinType::Char_U:
3863 case clang::BuiltinType::UChar:
3864 case clang::BuiltinType::WChar_U:
3865 case clang::BuiltinType::Char16:
3866 case clang::BuiltinType::Char32:
3867 case clang::BuiltinType::UShort:
3868 case clang::BuiltinType::UInt:
3869 case clang::BuiltinType::ULong:
3870 case clang::BuiltinType::ULongLong:
3871 case clang::BuiltinType::UInt128:
3872 case clang::BuiltinType::Char_S:
3873 case clang::BuiltinType::SChar:
3874 case clang::BuiltinType::WChar_S:
3875 case clang::BuiltinType::Short:
3876 case clang::BuiltinType::Int:
3877 case clang::BuiltinType::Long:
3878 case clang::BuiltinType::LongLong:
3879 case clang::BuiltinType::Int128:
3880 case clang::BuiltinType::Float:
3881 case clang::BuiltinType::Double:
3882 case clang::BuiltinType::LongDouble:
3883 builtin_type_flags |= eTypeIsScalar;
3884 if (builtin_type->isInteger()) {
3885 builtin_type_flags |= eTypeIsInteger;
3886 if (builtin_type->isSignedInteger())
3887 builtin_type_flags |= eTypeIsSigned;
3888 }
else if (builtin_type->isFloatingPoint())
3889 builtin_type_flags |= eTypeIsFloat;
3894 return builtin_type_flags;
3897 case clang::Type::BlockPointer:
3898 if (pointee_or_element_clang_type)
3900 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3901 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3903 case clang::Type::Complex: {
3904 uint32_t complex_type_flags =
3905 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3906 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3907 qual_type->getCanonicalTypeInternal());
3909 clang::QualType complex_element_type(complex_type->getElementType());
3910 if (complex_element_type->isIntegerType())
3911 complex_type_flags |= eTypeIsFloat;
3912 else if (complex_element_type->isFloatingType())
3913 complex_type_flags |= eTypeIsInteger;
3915 return complex_type_flags;
3918 case clang::Type::ConstantArray:
3919 case clang::Type::DependentSizedArray:
3920 case clang::Type::IncompleteArray:
3921 case clang::Type::VariableArray:
3922 if (pointee_or_element_clang_type)
3924 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3927 return eTypeHasChildren | eTypeIsArray;
3929 case clang::Type::DependentName:
3931 case clang::Type::DependentSizedExtVector:
3932 return eTypeHasChildren | eTypeIsVector;
3933 case clang::Type::DependentTemplateSpecialization:
3934 return eTypeIsTemplate;
3936 case clang::Type::Enum:
3937 if (pointee_or_element_clang_type)
3939 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3943 return eTypeIsEnumeration | eTypeHasValue;
3945 case clang::Type::FunctionProto:
3946 return eTypeIsFuncPrototype | eTypeHasValue;
3947 case clang::Type::FunctionNoProto:
3948 return eTypeIsFuncPrototype | eTypeHasValue;
3949 case clang::Type::InjectedClassName:
3952 case clang::Type::LValueReference:
3953 case clang::Type::RValueReference:
3954 if (pointee_or_element_clang_type)
3957 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3960 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3962 case clang::Type::MemberPointer:
3963 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3965 case clang::Type::ObjCObjectPointer:
3966 if (pointee_or_element_clang_type)
3968 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3969 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3972 case clang::Type::ObjCObject:
3973 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3974 case clang::Type::ObjCInterface:
3975 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3977 case clang::Type::Pointer:
3978 if (pointee_or_element_clang_type)
3980 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3981 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3983 case clang::Type::Record:
3984 if (qual_type->getAsCXXRecordDecl())
3985 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3987 return eTypeHasChildren | eTypeIsStructUnion;
3989 case clang::Type::SubstTemplateTypeParm:
3990 return eTypeIsTemplate;
3991 case clang::Type::TemplateTypeParm:
3992 return eTypeIsTemplate;
3993 case clang::Type::TemplateSpecialization:
3994 return eTypeIsTemplate;
3996 case clang::Type::Typedef:
3997 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
3999 ->getUnderlyingType())
4001 case clang::Type::UnresolvedUsing:
4004 case clang::Type::ExtVector:
4005 case clang::Type::Vector: {
4006 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4007 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
4008 qual_type->getCanonicalTypeInternal());
4010 if (vector_type->isIntegerType())
4011 vector_type_flags |= eTypeIsFloat;
4012 else if (vector_type->isFloatingType())
4013 vector_type_flags |= eTypeIsInteger;
4015 return vector_type_flags;
4030 if (qual_type->isAnyPointerType()) {
4031 if (qual_type->isObjCObjectPointerType())
4033 if (qual_type->getPointeeCXXRecordDecl())
4036 clang::QualType pointee_type(qual_type->getPointeeType());
4037 if (pointee_type->getPointeeCXXRecordDecl())
4039 if (pointee_type->isObjCObjectOrInterfaceType())
4041 if (pointee_type->isObjCClassType())
4043 if (pointee_type.getTypePtr() ==
4047 if (qual_type->isObjCObjectOrInterfaceType())
4049 if (qual_type->getAsCXXRecordDecl())
4051 switch (qual_type->getTypeClass()) {
4054 case clang::Type::Builtin:
4055 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4057 case clang::BuiltinType::Void:
4058 case clang::BuiltinType::Bool:
4059 case clang::BuiltinType::Char_U:
4060 case clang::BuiltinType::UChar:
4061 case clang::BuiltinType::WChar_U:
4062 case clang::BuiltinType::Char16:
4063 case clang::BuiltinType::Char32:
4064 case clang::BuiltinType::UShort:
4065 case clang::BuiltinType::UInt:
4066 case clang::BuiltinType::ULong:
4067 case clang::BuiltinType::ULongLong:
4068 case clang::BuiltinType::UInt128:
4069 case clang::BuiltinType::Char_S:
4070 case clang::BuiltinType::SChar:
4071 case clang::BuiltinType::WChar_S:
4072 case clang::BuiltinType::Short:
4073 case clang::BuiltinType::Int:
4074 case clang::BuiltinType::Long:
4075 case clang::BuiltinType::LongLong:
4076 case clang::BuiltinType::Int128:
4077 case clang::BuiltinType::Float:
4078 case clang::BuiltinType::Double:
4079 case clang::BuiltinType::LongDouble:
4082 case clang::BuiltinType::NullPtr:
4085 case clang::BuiltinType::ObjCId:
4086 case clang::BuiltinType::ObjCClass:
4087 case clang::BuiltinType::ObjCSel:
4090 case clang::BuiltinType::Dependent:
4091 case clang::BuiltinType::Overload:
4092 case clang::BuiltinType::BoundMember:
4093 case clang::BuiltinType::UnknownAny:
4097 case clang::Type::Typedef:
4098 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4100 ->getUnderlyingType())
4110 return lldb::eTypeClassInvalid;
4112 clang::QualType qual_type =
4115 switch (qual_type->getTypeClass()) {
4116 case clang::Type::Atomic:
4117 case clang::Type::Auto:
4118 case clang::Type::CountAttributed:
4119 case clang::Type::Decltype:
4120 case clang::Type::Elaborated:
4121 case clang::Type::Paren:
4122 case clang::Type::TypeOf:
4123 case clang::Type::TypeOfExpr:
4124 case clang::Type::Using:
4125 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4126 case clang::Type::UnaryTransform:
4128 case clang::Type::FunctionNoProto:
4129 return lldb::eTypeClassFunction;
4130 case clang::Type::FunctionProto:
4131 return lldb::eTypeClassFunction;
4132 case clang::Type::IncompleteArray:
4133 return lldb::eTypeClassArray;
4134 case clang::Type::VariableArray:
4135 return lldb::eTypeClassArray;
4136 case clang::Type::ConstantArray:
4137 return lldb::eTypeClassArray;
4138 case clang::Type::DependentSizedArray:
4139 return lldb::eTypeClassArray;
4140 case clang::Type::ArrayParameter:
4141 return lldb::eTypeClassArray;
4142 case clang::Type::DependentSizedExtVector:
4143 return lldb::eTypeClassVector;
4144 case clang::Type::DependentVector:
4145 return lldb::eTypeClassVector;
4146 case clang::Type::ExtVector:
4147 return lldb::eTypeClassVector;
4148 case clang::Type::Vector:
4149 return lldb::eTypeClassVector;
4150 case clang::Type::Builtin:
4152 case clang::Type::BitInt:
4153 case clang::Type::DependentBitInt:
4154 return lldb::eTypeClassBuiltin;
4155 case clang::Type::ObjCObjectPointer:
4156 return lldb::eTypeClassObjCObjectPointer;
4157 case clang::Type::BlockPointer:
4158 return lldb::eTypeClassBlockPointer;
4159 case clang::Type::Pointer:
4160 return lldb::eTypeClassPointer;
4161 case clang::Type::LValueReference:
4162 return lldb::eTypeClassReference;
4163 case clang::Type::RValueReference:
4164 return lldb::eTypeClassReference;
4165 case clang::Type::MemberPointer:
4166 return lldb::eTypeClassMemberPointer;
4167 case clang::Type::Complex:
4168 if (qual_type->isComplexType())
4169 return lldb::eTypeClassComplexFloat;
4171 return lldb::eTypeClassComplexInteger;
4172 case clang::Type::ObjCObject:
4173 return lldb::eTypeClassObjCObject;
4174 case clang::Type::ObjCInterface:
4175 return lldb::eTypeClassObjCInterface;
4176 case clang::Type::Record: {
4177 const clang::RecordType *record_type =
4178 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4179 const clang::RecordDecl *record_decl = record_type->getDecl();
4180 if (record_decl->isUnion())
4181 return lldb::eTypeClassUnion;
4182 else if (record_decl->isStruct())
4183 return lldb::eTypeClassStruct;
4185 return lldb::eTypeClassClass;
4187 case clang::Type::Enum:
4188 return lldb::eTypeClassEnumeration;
4189 case clang::Type::Typedef:
4190 return lldb::eTypeClassTypedef;
4191 case clang::Type::UnresolvedUsing:
4194 case clang::Type::Attributed:
4195 case clang::Type::BTFTagAttributed:
4197 case clang::Type::TemplateTypeParm:
4199 case clang::Type::SubstTemplateTypeParm:
4201 case clang::Type::SubstTemplateTypeParmPack:
4203 case clang::Type::InjectedClassName:
4205 case clang::Type::DependentName:
4207 case clang::Type::DependentTemplateSpecialization:
4209 case clang::Type::PackExpansion:
4212 case clang::Type::TemplateSpecialization:
4214 case clang::Type::DeducedTemplateSpecialization:
4216 case clang::Type::Pipe:
4220 case clang::Type::Decayed:
4222 case clang::Type::Adjusted:
4224 case clang::Type::ObjCTypeParam:
4227 case clang::Type::DependentAddressSpace:
4229 case clang::Type::MacroQualified:
4233 case clang::Type::ConstantMatrix:
4234 case clang::Type::DependentSizedMatrix:
4238 case clang::Type::PackIndexing:
4242 return lldb::eTypeClassOther;
4247 return GetQualType(type).getQualifiers().getCVRQualifiers();
4259 const clang::Type *array_eletype =
4260 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4265 return GetType(clang::QualType(array_eletype, 0));
4276 return GetType(ast_ctx.getConstantArrayType(
4277 qual_type, llvm::APInt(64, size),
nullptr,
4278 clang::ArraySizeModifier::Normal, 0));
4280 return GetType(ast_ctx.getIncompleteArrayType(
4281 qual_type, clang::ArraySizeModifier::Normal, 0));
4295 clang::QualType qual_type) {
4296 if (qual_type->isPointerType())
4297 qual_type = ast->getPointerType(
4299 else if (
const ConstantArrayType *arr =
4300 ast->getAsConstantArrayType(qual_type)) {
4301 qual_type = ast->getConstantArrayType(
4303 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4304 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4306 qual_type = qual_type.getUnqualifiedType();
4307 qual_type.removeLocalConst();
4308 qual_type.removeLocalRestrict();
4309 qual_type.removeLocalVolatile();
4331 const clang::FunctionProtoType *func =
4334 return func->getNumParams();
4342 const clang::FunctionProtoType *func =
4343 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4345 const uint32_t num_args = func->getNumParams();
4347 return GetType(func->getParamType(idx));
4357 const clang::FunctionProtoType *func =
4358 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4360 return GetType(func->getReturnType());
4367 size_t num_functions = 0;
4370 switch (qual_type->getTypeClass()) {
4371 case clang::Type::Record:
4373 const clang::RecordType *record_type =
4374 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4375 const clang::RecordDecl *record_decl = record_type->getDecl();
4376 assert(record_decl);
4377 const clang::CXXRecordDecl *cxx_record_decl =
4378 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4379 if (cxx_record_decl)
4380 num_functions = std::distance(cxx_record_decl->method_begin(),
4381 cxx_record_decl->method_end());
4385 case clang::Type::ObjCObjectPointer: {
4386 const clang::ObjCObjectPointerType *objc_class_type =
4387 qual_type->castAs<clang::ObjCObjectPointerType>();
4388 const clang::ObjCInterfaceType *objc_interface_type =
4389 objc_class_type->getInterfaceType();
4390 if (objc_interface_type &&
4392 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4393 clang::ObjCInterfaceDecl *class_interface_decl =
4394 objc_interface_type->getDecl();
4395 if (class_interface_decl) {
4396 num_functions = std::distance(class_interface_decl->meth_begin(),
4397 class_interface_decl->meth_end());
4403 case clang::Type::ObjCObject:
4404 case clang::Type::ObjCInterface:
4406 const clang::ObjCObjectType *objc_class_type =
4407 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4408 if (objc_class_type) {
4409 clang::ObjCInterfaceDecl *class_interface_decl =
4410 objc_class_type->getInterface();
4411 if (class_interface_decl)
4412 num_functions = std::distance(class_interface_decl->meth_begin(),
4413 class_interface_decl->meth_end());
4422 return num_functions;
4434 switch (qual_type->getTypeClass()) {
4435 case clang::Type::Record:
4437 const clang::RecordType *record_type =
4438 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4439 const clang::RecordDecl *record_decl = record_type->getDecl();
4440 assert(record_decl);
4441 const clang::CXXRecordDecl *cxx_record_decl =
4442 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4443 if (cxx_record_decl) {
4444 auto method_iter = cxx_record_decl->method_begin();
4445 auto method_end = cxx_record_decl->method_end();
4447 static_cast<size_t>(std::distance(method_iter, method_end))) {
4448 std::advance(method_iter, idx);
4449 clang::CXXMethodDecl *cxx_method_decl =
4450 method_iter->getCanonicalDecl();
4451 if (cxx_method_decl) {
4452 name = cxx_method_decl->getDeclName().getAsString();
4453 if (cxx_method_decl->isStatic())
4455 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4457 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4461 clang_type =
GetType(cxx_method_decl->getType());
4469 case clang::Type::ObjCObjectPointer: {
4470 const clang::ObjCObjectPointerType *objc_class_type =
4471 qual_type->castAs<clang::ObjCObjectPointerType>();
4472 const clang::ObjCInterfaceType *objc_interface_type =
4473 objc_class_type->getInterfaceType();
4474 if (objc_interface_type &&
4476 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4477 clang::ObjCInterfaceDecl *class_interface_decl =
4478 objc_interface_type->getDecl();
4479 if (class_interface_decl) {
4480 auto method_iter = class_interface_decl->meth_begin();
4481 auto method_end = class_interface_decl->meth_end();
4483 static_cast<size_t>(std::distance(method_iter, method_end))) {
4484 std::advance(method_iter, idx);
4485 clang::ObjCMethodDecl *objc_method_decl =
4486 method_iter->getCanonicalDecl();
4487 if (objc_method_decl) {
4489 name = objc_method_decl->getSelector().getAsString();
4490 if (objc_method_decl->isClassMethod())
4501 case clang::Type::ObjCObject:
4502 case clang::Type::ObjCInterface:
4504 const clang::ObjCObjectType *objc_class_type =
4505 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4506 if (objc_class_type) {
4507 clang::ObjCInterfaceDecl *class_interface_decl =
4508 objc_class_type->getInterface();
4509 if (class_interface_decl) {
4510 auto method_iter = class_interface_decl->meth_begin();
4511 auto method_end = class_interface_decl->meth_end();
4513 static_cast<size_t>(std::distance(method_iter, method_end))) {
4514 std::advance(method_iter, idx);
4515 clang::ObjCMethodDecl *objc_method_decl =
4516 method_iter->getCanonicalDecl();
4517 if (objc_method_decl) {
4519 name = objc_method_decl->getSelector().getAsString();
4520 if (objc_method_decl->isClassMethod())
4553 return GetType(qual_type.getTypePtr()->getPointeeType());
4563 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4564 case clang::Type::ObjCObject:
4565 case clang::Type::ObjCInterface:
4612 auto pauth = PointerAuthQualifier::fromOpaqueValue(payload);
4613 clang::QualType result =
4614 clang_ast.getPointerAuthType(
GetQualType(type), pauth);
4624 result.addVolatile();
4634 result.addRestrict();
4643 if (type && typedef_name && typedef_name[0]) {
4647 clang::DeclContext *decl_ctx =
4652 clang::TypedefDecl *decl =
4653 clang::TypedefDecl::CreateDeserialized(clang_ast, GlobalDeclID());
4654 decl->setDeclContext(decl_ctx);
4655 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4656 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4657 decl_ctx->addDecl(decl);
4660 clang::TagDecl *tdecl =
nullptr;
4661 if (!qual_type.isNull()) {
4662 if (
const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4663 tdecl = rt->getDecl();
4664 if (
const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4665 tdecl = et->getDecl();
4671 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4672 tdecl->setTypedefNameForAnonDecl(decl);
4674 decl->setAccess(clang::AS_public);
4677 return GetType(clang_ast.getTypedefType(decl));
4685 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4688 return GetType(typedef_type->getDecl()->getUnderlyingType());
4701 const FunctionType::ExtInfo generic_ext_info(
4710 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4715const llvm::fltSemantics &
4718 const size_t bit_size = byte_size * 8;
4719 if (bit_size == ast.getTypeSize(ast.FloatTy))
4720 return ast.getFloatTypeSemantics(ast.FloatTy);
4721 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4722 return ast.getFloatTypeSemantics(ast.DoubleTy);
4723 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4724 bit_size == llvm::APFloat::semanticsSizeInBits(
4725 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4726 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4727 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4728 return ast.getFloatTypeSemantics(ast.HalfTy);
4729 return llvm::APFloatBase::Bogus();
4732std::optional<uint64_t>
4735 assert(qual_type->isObjCObjectOrInterfaceType());
4740 if (std::optional<uint64_t> bit_size =
4741 objc_runtime->GetTypeBitSize(
GetType(qual_type)))
4745 static bool g_printed =
false;
4750 llvm::outs() <<
"warning: trying to determine the size of type ";
4752 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4753 "reliable. please file a bug against LLDB.\n";
4754 llvm::outs() <<
"backtrace:\n";
4755 llvm::sys::PrintStackTrace(llvm::outs());
4756 llvm::outs() <<
"\n";
4765std::optional<uint64_t>
4769 return std::nullopt;
4772 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4773 switch (type_class) {
4774 case clang::Type::ConstantArray:
4775 case clang::Type::FunctionProto:
4776 case clang::Type::Record:
4778 case clang::Type::ObjCInterface:
4779 case clang::Type::ObjCObject:
4781 case clang::Type::IncompleteArray: {
4782 const uint64_t bit_size =
getASTContext().getTypeSize(qual_type);
4785 qual_type->getArrayElementTypeNoTypeQual()
4786 ->getCanonicalTypeUnqualified());
4791 if (
const uint64_t bit_size =
getASTContext().getTypeSize(qual_type))
4795 return std::nullopt;
4798std::optional<size_t>
4814 switch (qual_type->getTypeClass()) {
4815 case clang::Type::Atomic:
4816 case clang::Type::Auto:
4817 case clang::Type::CountAttributed:
4818 case clang::Type::Decltype:
4819 case clang::Type::Elaborated:
4820 case clang::Type::Paren:
4821 case clang::Type::Typedef:
4822 case clang::Type::TypeOf:
4823 case clang::Type::TypeOfExpr:
4824 case clang::Type::Using:
4825 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4827 case clang::Type::UnaryTransform:
4830 case clang::Type::FunctionNoProto:
4831 case clang::Type::FunctionProto:
4834 case clang::Type::IncompleteArray:
4835 case clang::Type::VariableArray:
4836 case clang::Type::ArrayParameter:
4839 case clang::Type::ConstantArray:
4842 case clang::Type::DependentVector:
4843 case clang::Type::ExtVector:
4844 case clang::Type::Vector:
4848 case clang::Type::BitInt:
4849 case clang::Type::DependentBitInt:
4853 case clang::Type::Builtin:
4854 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4855 case clang::BuiltinType::Void:
4858 case clang::BuiltinType::Char_S:
4859 case clang::BuiltinType::SChar:
4860 case clang::BuiltinType::WChar_S:
4861 case clang::BuiltinType::Short:
4862 case clang::BuiltinType::Int:
4863 case clang::BuiltinType::Long:
4864 case clang::BuiltinType::LongLong:
4865 case clang::BuiltinType::Int128:
4868 case clang::BuiltinType::Bool:
4869 case clang::BuiltinType::Char_U:
4870 case clang::BuiltinType::UChar:
4871 case clang::BuiltinType::WChar_U:
4872 case clang::BuiltinType::Char8:
4873 case clang::BuiltinType::Char16:
4874 case clang::BuiltinType::Char32:
4875 case clang::BuiltinType::UShort:
4876 case clang::BuiltinType::UInt:
4877 case clang::BuiltinType::ULong:
4878 case clang::BuiltinType::ULongLong:
4879 case clang::BuiltinType::UInt128:
4883 case clang::BuiltinType::ShortAccum:
4884 case clang::BuiltinType::Accum:
4885 case clang::BuiltinType::LongAccum:
4886 case clang::BuiltinType::UShortAccum:
4887 case clang::BuiltinType::UAccum:
4888 case clang::BuiltinType::ULongAccum:
4889 case clang::BuiltinType::ShortFract:
4890 case clang::BuiltinType::Fract:
4891 case clang::BuiltinType::LongFract:
4892 case clang::BuiltinType::UShortFract:
4893 case clang::BuiltinType::UFract:
4894 case clang::BuiltinType::ULongFract:
4895 case clang::BuiltinType::SatShortAccum:
4896 case clang::BuiltinType::SatAccum:
4897 case clang::BuiltinType::SatLongAccum:
4898 case clang::BuiltinType::SatUShortAccum:
4899 case clang::BuiltinType::SatUAccum:
4900 case clang::BuiltinType::SatULongAccum:
4901 case clang::BuiltinType::SatShortFract:
4902 case clang::BuiltinType::SatFract:
4903 case clang::BuiltinType::SatLongFract:
4904 case clang::BuiltinType::SatUShortFract:
4905 case clang::BuiltinType::SatUFract:
4906 case clang::BuiltinType::SatULongFract:
4909 case clang::BuiltinType::Half:
4910 case clang::BuiltinType::Float:
4911 case clang::BuiltinType::Float16:
4912 case clang::BuiltinType::Float128:
4913 case clang::BuiltinType::Double:
4914 case clang::BuiltinType::LongDouble:
4915 case clang::BuiltinType::BFloat16:
4916 case clang::BuiltinType::Ibm128:
4919 case clang::BuiltinType::ObjCClass:
4920 case clang::BuiltinType::ObjCId:
4921 case clang::BuiltinType::ObjCSel:
4924 case clang::BuiltinType::NullPtr:
4927 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4928 case clang::BuiltinType::Kind::BoundMember:
4929 case clang::BuiltinType::Kind::BuiltinFn:
4930 case clang::BuiltinType::Kind::Dependent:
4931 case clang::BuiltinType::Kind::OCLClkEvent:
4932 case clang::BuiltinType::Kind::OCLEvent:
4933 case clang::BuiltinType::Kind::OCLImage1dRO:
4934 case clang::BuiltinType::Kind::OCLImage1dWO:
4935 case clang::BuiltinType::Kind::OCLImage1dRW:
4936 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4937 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4938 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4939 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4940 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4941 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4942 case clang::BuiltinType::Kind::OCLImage2dRO:
4943 case clang::BuiltinType::Kind::OCLImage2dWO:
4944 case clang::BuiltinType::Kind::OCLImage2dRW:
4945 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4946 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4947 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4948 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4949 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4950 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4951 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4952 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4953 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4954 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4955 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4956 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4957 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4958 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4959 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4960 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4961 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4962 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4963 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4964 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4965 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4966 case clang::BuiltinType::Kind::OCLImage3dRO:
4967 case clang::BuiltinType::Kind::OCLImage3dWO:
4968 case clang::BuiltinType::Kind::OCLImage3dRW:
4969 case clang::BuiltinType::Kind::OCLQueue:
4970 case clang::BuiltinType::Kind::OCLReserveID:
4971 case clang::BuiltinType::Kind::OCLSampler:
4972 case clang::BuiltinType::Kind::HLSLResource:
4973 case clang::BuiltinType::Kind::ArraySection:
4974 case clang::BuiltinType::Kind::OMPArrayShaping:
4975 case clang::BuiltinType::Kind::OMPIterator:
4976 case clang::BuiltinType::Kind::Overload:
4977 case clang::BuiltinType::Kind::PseudoObject:
4978 case clang::BuiltinType::Kind::UnknownAny:
4981 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4982 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4983 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4984 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4985 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4986 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4987 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4988 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4989 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4990 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4991 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4992 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4996 case clang::BuiltinType::VectorPair:
4997 case clang::BuiltinType::VectorQuad:
5001 case clang::BuiltinType::SveBool:
5002 case clang::BuiltinType::SveBoolx2:
5003 case clang::BuiltinType::SveBoolx4:
5004 case clang::BuiltinType::SveCount:
5005 case clang::BuiltinType::SveInt8:
5006 case clang::BuiltinType::SveInt8x2:
5007 case clang::BuiltinType::SveInt8x3:
5008 case clang::BuiltinType::SveInt8x4:
5009 case clang::BuiltinType::SveInt16:
5010 case clang::BuiltinType::SveInt16x2:
5011 case clang::BuiltinType::SveInt16x3:
5012 case clang::BuiltinType::SveInt16x4:
5013 case clang::BuiltinType::SveInt32:
5014 case clang::BuiltinType::SveInt32x2:
5015 case clang::BuiltinType::SveInt32x3:
5016 case clang::BuiltinType::SveInt32x4:
5017 case clang::BuiltinType::SveInt64:
5018 case clang::BuiltinType::SveInt64x2:
5019 case clang::BuiltinType::SveInt64x3:
5020 case clang::BuiltinType::SveInt64x4:
5021 case clang::BuiltinType::SveUint8:
5022 case clang::BuiltinType::SveUint8x2:
5023 case clang::BuiltinType::SveUint8x3:
5024 case clang::BuiltinType::SveUint8x4:
5025 case clang::BuiltinType::SveUint16:
5026 case clang::BuiltinType::SveUint16x2:
5027 case clang::BuiltinType::SveUint16x3:
5028 case clang::BuiltinType::SveUint16x4:
5029 case clang::BuiltinType::SveUint32:
5030 case clang::BuiltinType::SveUint32x2:
5031 case clang::BuiltinType::SveUint32x3:
5032 case clang::BuiltinType::SveUint32x4:
5033 case clang::BuiltinType::SveUint64:
5034 case clang::BuiltinType::SveUint64x2:
5035 case clang::BuiltinType::SveUint64x3:
5036 case clang::BuiltinType::SveUint64x4:
5037 case clang::BuiltinType::SveFloat16:
5038 case clang::BuiltinType::SveBFloat16:
5039 case clang::BuiltinType::SveBFloat16x2:
5040 case clang::BuiltinType::SveBFloat16x3:
5041 case clang::BuiltinType::SveBFloat16x4:
5042 case clang::BuiltinType::SveFloat16x2:
5043 case clang::BuiltinType::SveFloat16x3:
5044 case clang::BuiltinType::SveFloat16x4:
5045 case clang::BuiltinType::SveFloat32:
5046 case clang::BuiltinType::SveFloat32x2:
5047 case clang::BuiltinType::SveFloat32x3:
5048 case clang::BuiltinType::SveFloat32x4:
5049 case clang::BuiltinType::SveFloat64:
5050 case clang::BuiltinType::SveFloat64x2:
5051 case clang::BuiltinType::SveFloat64x3:
5052 case clang::BuiltinType::SveFloat64x4:
5056#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5057#include "clang/Basic/RISCVVTypes.def"
5061 case clang::BuiltinType::WasmExternRef:
5064 case clang::BuiltinType::IncompleteMatrixIdx:
5067 case clang::BuiltinType::UnresolvedTemplate:
5071#define AMDGPU_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
5072#include "clang/Basic/AMDGPUTypes.def"
5078 case clang::Type::ObjCObjectPointer:
5079 case clang::Type::BlockPointer:
5080 case clang::Type::Pointer:
5081 case clang::Type::LValueReference:
5082 case clang::Type::RValueReference:
5083 case clang::Type::MemberPointer:
5085 case clang::Type::Complex: {
5087 if (qual_type->isComplexType())
5090 const clang::ComplexType *complex_type =
5091 qual_type->getAsComplexIntegerType();
5101 case clang::Type::ObjCInterface:
5103 case clang::Type::Record:
5105 case clang::Type::Enum:
5106 return qual_type->isUnsignedIntegerOrEnumerationType()
5109 case clang::Type::DependentSizedArray:
5110 case clang::Type::DependentSizedExtVector:
5111 case clang::Type::UnresolvedUsing:
5112 case clang::Type::Attributed:
5113 case clang::Type::BTFTagAttributed:
5114 case clang::Type::TemplateTypeParm:
5115 case clang::Type::SubstTemplateTypeParm:
5116 case clang::Type::SubstTemplateTypeParmPack:
5117 case clang::Type::InjectedClassName:
5118 case clang::Type::DependentName:
5119 case clang::Type::DependentTemplateSpecialization:
5120 case clang::Type::PackExpansion:
5121 case clang::Type::ObjCObject:
5123 case clang::Type::TemplateSpecialization:
5124 case clang::Type::DeducedTemplateSpecialization:
5125 case clang::Type::Adjusted:
5126 case clang::Type::Pipe:
5130 case clang::Type::Decayed:
5132 case clang::Type::ObjCTypeParam:
5135 case clang::Type::DependentAddressSpace:
5137 case clang::Type::MacroQualified:
5140 case clang::Type::ConstantMatrix:
5141 case clang::Type::DependentSizedMatrix:
5145 case clang::Type::PackIndexing:
5158 switch (qual_type->getTypeClass()) {
5159 case clang::Type::Atomic:
5160 case clang::Type::Auto:
5161 case clang::Type::CountAttributed:
5162 case clang::Type::Decltype:
5163 case clang::Type::Elaborated:
5164 case clang::Type::Paren:
5165 case clang::Type::Typedef:
5166 case clang::Type::TypeOf:
5167 case clang::Type::TypeOfExpr:
5168 case clang::Type::Using:
5169 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5170 case clang::Type::UnaryTransform:
5173 case clang::Type::FunctionNoProto:
5174 case clang::Type::FunctionProto:
5177 case clang::Type::IncompleteArray:
5178 case clang::Type::VariableArray:
5179 case clang::Type::ArrayParameter:
5182 case clang::Type::ConstantArray:
5185 case clang::Type::DependentVector:
5186 case clang::Type::ExtVector:
5187 case clang::Type::Vector:
5190 case clang::Type::BitInt:
5191 case clang::Type::DependentBitInt:
5195 case clang::Type::Builtin:
5196 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5197 case clang::BuiltinType::UnknownAny:
5198 case clang::BuiltinType::Void:
5199 case clang::BuiltinType::BoundMember:
5202 case clang::BuiltinType::Bool:
5204 case clang::BuiltinType::Char_S:
5205 case clang::BuiltinType::SChar:
5206 case clang::BuiltinType::WChar_S:
5207 case clang::BuiltinType::Char_U:
5208 case clang::BuiltinType::UChar:
5209 case clang::BuiltinType::WChar_U:
5211 case clang::BuiltinType::Char8:
5213 case clang::BuiltinType::Char16:
5215 case clang::BuiltinType::Char32:
5217 case clang::BuiltinType::UShort:
5219 case clang::BuiltinType::Short:
5221 case clang::BuiltinType::UInt:
5223 case clang::BuiltinType::Int:
5225 case clang::BuiltinType::ULong:
5227 case clang::BuiltinType::Long:
5229 case clang::BuiltinType::ULongLong:
5231 case clang::BuiltinType::LongLong:
5233 case clang::BuiltinType::UInt128:
5235 case clang::BuiltinType::Int128:
5237 case clang::BuiltinType::Half:
5238 case clang::BuiltinType::Float:
5239 case clang::BuiltinType::Double:
5240 case clang::BuiltinType::LongDouble:
5246 case clang::Type::ObjCObjectPointer:
5248 case clang::Type::BlockPointer:
5250 case clang::Type::Pointer:
5252 case clang::Type::LValueReference:
5253 case clang::Type::RValueReference:
5255 case clang::Type::MemberPointer:
5257 case clang::Type::Complex: {
5258 if (qual_type->isComplexType())
5263 case clang::Type::ObjCInterface:
5265 case clang::Type::Record:
5267 case clang::Type::Enum:
5269 case clang::Type::DependentSizedArray:
5270 case clang::Type::DependentSizedExtVector:
5271 case clang::Type::UnresolvedUsing:
5272 case clang::Type::Attributed:
5273 case clang::Type::BTFTagAttributed:
5274 case clang::Type::TemplateTypeParm:
5275 case clang::Type::SubstTemplateTypeParm:
5276 case clang::Type::SubstTemplateTypeParmPack:
5277 case clang::Type::InjectedClassName:
5278 case clang::Type::DependentName:
5279 case clang::Type::DependentTemplateSpecialization:
5280 case clang::Type::PackExpansion:
5281 case clang::Type::ObjCObject:
5283 case clang::Type::TemplateSpecialization:
5284 case clang::Type::DeducedTemplateSpecialization:
5285 case clang::Type::Adjusted:
5286 case clang::Type::Pipe:
5290 case clang::Type::Decayed:
5292 case clang::Type::ObjCTypeParam:
5295 case clang::Type::DependentAddressSpace:
5297 case clang::Type::MacroQualified:
5301 case clang::Type::ConstantMatrix:
5302 case clang::Type::DependentSizedMatrix:
5306 case clang::Type::PackIndexing:
5314 bool check_superclass) {
5315 while (class_interface_decl) {
5316 if (class_interface_decl->ivar_size() > 0)
5319 if (check_superclass)
5320 class_interface_decl = class_interface_decl->getSuperClass();
5327static std::optional<SymbolFile::ArrayInfo>
5329 clang::QualType qual_type,
5331 if (qual_type->isIncompleteArrayType())
5332 if (std::optional<ClangASTMetadata> metadata =
5336 return std::nullopt;
5339llvm::Expected<uint32_t>
5341 bool omit_empty_base_classes,
5344 return llvm::createStringError(
"invalid clang type");
5346 uint32_t num_children = 0;
5348 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5349 switch (type_class) {
5350 case clang::Type::Builtin:
5351 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5352 case clang::BuiltinType::ObjCId:
5353 case clang::BuiltinType::ObjCClass:
5362 case clang::Type::Complex:
5364 case clang::Type::Record:
5366 const clang::RecordType *record_type =
5367 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5368 const clang::RecordDecl *record_decl = record_type->getDecl();
5369 assert(record_decl);
5370 const clang::CXXRecordDecl *cxx_record_decl =
5371 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5372 if (cxx_record_decl) {
5373 if (omit_empty_base_classes) {
5377 clang::CXXRecordDecl::base_class_const_iterator base_class,
5379 for (base_class = cxx_record_decl->bases_begin(),
5380 base_class_end = cxx_record_decl->bases_end();
5381 base_class != base_class_end; ++base_class) {
5382 const clang::CXXRecordDecl *base_class_decl =
5383 llvm::cast<clang::CXXRecordDecl>(
5384 base_class->getType()
5385 ->getAs<clang::RecordType>()
5396 num_children += cxx_record_decl->getNumBases();
5399 num_children += std::distance(record_decl->field_begin(),
5400 record_decl->field_end());
5402 return llvm::createStringError(
5405 case clang::Type::ObjCObject:
5406 case clang::Type::ObjCInterface:
5408 const clang::ObjCObjectType *objc_class_type =
5409 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5410 assert(objc_class_type);
5411 if (objc_class_type) {
5412 clang::ObjCInterfaceDecl *class_interface_decl =
5413 objc_class_type->getInterface();
5415 if (class_interface_decl) {
5417 clang::ObjCInterfaceDecl *superclass_interface_decl =
5418 class_interface_decl->getSuperClass();
5419 if (superclass_interface_decl) {
5420 if (omit_empty_base_classes) {
5427 num_children += class_interface_decl->ivar_size();
5433 case clang::Type::LValueReference:
5434 case clang::Type::RValueReference:
5435 case clang::Type::ObjCObjectPointer: {
5438 uint32_t num_pointee_children = 0;
5440 auto num_children_or_err =
5441 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5442 if (!num_children_or_err)
5443 return num_children_or_err;
5444 num_pointee_children = *num_children_or_err;
5447 if (num_pointee_children == 0)
5450 num_children = num_pointee_children;
5453 case clang::Type::Vector:
5454 case clang::Type::ExtVector:
5456 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5459 case clang::Type::ConstantArray:
5460 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5464 case clang::Type::IncompleteArray:
5465 if (
auto array_info =
5468 num_children = array_info->element_orders.size()
5469 ? array_info->element_orders.back().value_or(0)
5473 case clang::Type::Pointer: {
5474 const clang::PointerType *pointer_type =
5475 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5476 clang::QualType pointee_type(pointer_type->getPointeeType());
5478 uint32_t num_pointee_children = 0;
5480 auto num_children_or_err =
5481 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5482 if (!num_children_or_err)
5483 return num_children_or_err;
5484 num_pointee_children = *num_children_or_err;
5486 if (num_pointee_children == 0) {
5491 num_children = num_pointee_children;
5497 return num_children;
5508 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5509 if (type_class == clang::Type::Builtin) {
5510 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5511 case clang::BuiltinType::Void:
5513 case clang::BuiltinType::Bool:
5515 case clang::BuiltinType::Char_S:
5517 case clang::BuiltinType::Char_U:
5519 case clang::BuiltinType::Char8:
5521 case clang::BuiltinType::Char16:
5523 case clang::BuiltinType::Char32:
5525 case clang::BuiltinType::UChar:
5527 case clang::BuiltinType::SChar:
5529 case clang::BuiltinType::WChar_S:
5531 case clang::BuiltinType::WChar_U:
5533 case clang::BuiltinType::Short:
5535 case clang::BuiltinType::UShort:
5537 case clang::BuiltinType::Int:
5539 case clang::BuiltinType::UInt:
5541 case clang::BuiltinType::Long:
5543 case clang::BuiltinType::ULong:
5545 case clang::BuiltinType::LongLong:
5547 case clang::BuiltinType::ULongLong:
5549 case clang::BuiltinType::Int128:
5551 case clang::BuiltinType::UInt128:
5554 case clang::BuiltinType::Half:
5556 case clang::BuiltinType::Float:
5558 case clang::BuiltinType::Double:
5560 case clang::BuiltinType::LongDouble:
5563 case clang::BuiltinType::NullPtr:
5565 case clang::BuiltinType::ObjCId:
5567 case clang::BuiltinType::ObjCClass:
5569 case clang::BuiltinType::ObjCSel:
5583 const llvm::APSInt &value)>
const &callback) {
5584 const clang::EnumType *enum_type =
5587 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5591 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5592 for (enum_pos = enum_decl->enumerator_begin(),
5593 enum_end_pos = enum_decl->enumerator_end();
5594 enum_pos != enum_end_pos; ++enum_pos) {
5595 ConstString name(enum_pos->getNameAsString().c_str());
5596 if (!callback(integer_type, name, enum_pos->getInitVal()))
5603#pragma mark Aggregate Types
5611 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5612 switch (type_class) {
5613 case clang::Type::Record:
5615 const clang::RecordType *record_type =
5616 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5618 clang::RecordDecl *record_decl = record_type->getDecl();
5620 count = std::distance(record_decl->field_begin(),
5621 record_decl->field_end());
5627 case clang::Type::ObjCObjectPointer: {
5628 const clang::ObjCObjectPointerType *objc_class_type =
5629 qual_type->castAs<clang::ObjCObjectPointerType>();
5630 const clang::ObjCInterfaceType *objc_interface_type =
5631 objc_class_type->getInterfaceType();
5632 if (objc_interface_type &&
5634 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5635 clang::ObjCInterfaceDecl *class_interface_decl =
5636 objc_interface_type->getDecl();
5637 if (class_interface_decl) {
5638 count = class_interface_decl->ivar_size();
5644 case clang::Type::ObjCObject:
5645 case clang::Type::ObjCInterface:
5647 const clang::ObjCObjectType *objc_class_type =
5648 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5649 if (objc_class_type) {
5650 clang::ObjCInterfaceDecl *class_interface_decl =
5651 objc_class_type->getInterface();
5653 if (class_interface_decl)
5654 count = class_interface_decl->ivar_size();
5667 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5668 std::string &name, uint64_t *bit_offset_ptr,
5669 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5670 if (class_interface_decl) {
5671 if (idx < (class_interface_decl->ivar_size())) {
5672 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5673 ivar_end = class_interface_decl->ivar_end();
5674 uint32_t ivar_idx = 0;
5676 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5677 ++ivar_pos, ++ivar_idx) {
5678 if (ivar_idx == idx) {
5679 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5681 clang::QualType ivar_qual_type(ivar_decl->getType());
5683 name.assign(ivar_decl->getNameAsString());
5685 if (bit_offset_ptr) {
5686 const clang::ASTRecordLayout &interface_layout =
5687 ast->getASTObjCInterfaceLayout(class_interface_decl);
5688 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5691 const bool is_bitfield = ivar_pos->isBitField();
5693 if (bitfield_bit_size_ptr) {
5694 *bitfield_bit_size_ptr = 0;
5696 if (is_bitfield && ast) {
5697 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5698 clang::Expr::EvalResult result;
5699 if (bitfield_bit_size_expr &&
5700 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5701 llvm::APSInt bitfield_apsint = result.Val.getInt();
5702 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5706 if (is_bitfield_ptr)
5707 *is_bitfield_ptr = is_bitfield;
5709 return ivar_qual_type.getAsOpaquePtr();
5718 size_t idx, std::string &name,
5719 uint64_t *bit_offset_ptr,
5720 uint32_t *bitfield_bit_size_ptr,
5721 bool *is_bitfield_ptr) {
5726 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5727 switch (type_class) {
5728 case clang::Type::Record:
5730 const clang::RecordType *record_type =
5731 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5732 const clang::RecordDecl *record_decl = record_type->getDecl();
5733 uint32_t field_idx = 0;
5734 clang::RecordDecl::field_iterator field, field_end;
5735 for (field = record_decl->field_begin(),
5736 field_end = record_decl->field_end();
5737 field != field_end; ++field, ++field_idx) {
5738 if (idx == field_idx) {
5741 name.assign(field->getNameAsString());
5745 if (bit_offset_ptr) {
5746 const clang::ASTRecordLayout &record_layout =
5748 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5751 const bool is_bitfield = field->isBitField();
5753 if (bitfield_bit_size_ptr) {
5754 *bitfield_bit_size_ptr = 0;
5757 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5758 clang::Expr::EvalResult result;
5759 if (bitfield_bit_size_expr &&
5760 bitfield_bit_size_expr->EvaluateAsInt(result,
5762 llvm::APSInt bitfield_apsint = result.Val.getInt();
5763 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5767 if (is_bitfield_ptr)
5768 *is_bitfield_ptr = is_bitfield;
5770 return GetType(field->getType());
5776 case clang::Type::ObjCObjectPointer: {
5777 const clang::ObjCObjectPointerType *objc_class_type =
5778 qual_type->castAs<clang::ObjCObjectPointerType>();
5779 const clang::ObjCInterfaceType *objc_interface_type =
5780 objc_class_type->getInterfaceType();
5781 if (objc_interface_type &&
5783 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5784 clang::ObjCInterfaceDecl *class_interface_decl =
5785 objc_interface_type->getDecl();
5786 if (class_interface_decl) {
5790 name, bit_offset_ptr, bitfield_bit_size_ptr,