11#include "clang/AST/DeclBase.h"
12#include "llvm/Support/Casting.h"
13#include "llvm/Support/FormatAdapters.h"
14#include "llvm/Support/FormatVariadic.h"
21#include "clang/AST/ASTContext.h"
22#include "clang/AST/ASTImporter.h"
23#include "clang/AST/Attr.h"
24#include "clang/AST/CXXInheritance.h"
25#include "clang/AST/DeclObjC.h"
26#include "clang/AST/DeclTemplate.h"
27#include "clang/AST/Mangle.h"
28#include "clang/AST/RecordLayout.h"
29#include "clang/AST/Type.h"
30#include "clang/AST/VTableBuilder.h"
31#include "clang/Basic/Builtins.h"
32#include "clang/Basic/Diagnostic.h"
33#include "clang/Basic/FileManager.h"
34#include "clang/Basic/FileSystemOptions.h"
35#include "clang/Basic/LangStandard.h"
36#include "clang/Basic/SourceManager.h"
37#include "clang/Basic/TargetInfo.h"
38#include "clang/Basic/TargetOptions.h"
39#include "clang/Frontend/FrontendOptions.h"
40#include "clang/Lex/HeaderSearch.h"
41#include "clang/Lex/HeaderSearchOptions.h"
42#include "clang/Lex/ModuleMap.h"
43#include "clang/Sema/Sema.h"
45#include "llvm/Support/Signals.h"
46#include "llvm/Support/Threading.h"
91using llvm::StringSwitch;
96static void VerifyDecl(clang::Decl *decl) {
97 assert(decl &&
"VerifyDecl called with nullptr?");
123bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
125 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
126 "Methods should have the same AST context");
127 clang::ASTContext &context = m1->getASTContext();
129 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
130 context.getCanonicalType(m1->getType()));
132 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
133 context.getCanonicalType(m2->getType()));
135 auto compareArgTypes = [&context](
const clang::QualType &m1p,
136 const clang::QualType &m2p) {
137 return context.hasSameType(m1p.getUnqualifiedType(),
138 m2p.getUnqualifiedType());
143 return (m1->getNumParams() != m2->getNumParams()) ||
144 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
145 m2Type->param_type_begin(), compareArgTypes);
151void addOverridesForMethod(clang::CXXMethodDecl *decl) {
152 if (!decl->isVirtual())
155 clang::CXXBasePaths paths;
156 llvm::SmallVector<clang::NamedDecl *, 4> decls;
158 auto find_overridden_methods =
159 [&decls, decl](
const clang::CXXBaseSpecifier *specifier,
160 clang::CXXBasePath &path) {
161 if (
auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>(
162 specifier->getType()->castAs<clang::RecordType>()->getDecl())) {
164 clang::DeclarationName name = decl->getDeclName();
168 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
169 if (
auto *baseDtorDecl = base_record->getDestructor()) {
170 if (baseDtorDecl->isVirtual()) {
171 decls.push_back(baseDtorDecl);
178 for (path.Decls = base_record->lookup(name).begin();
179 path.Decls != path.Decls.end(); ++path.Decls) {
180 if (
auto *method_decl =
181 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
182 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
183 decls.push_back(method_decl);
192 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
193 for (
auto *overridden_decl : decls)
194 decl->addOverriddenMethod(
195 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
201 VTableContextBase &vtable_ctx,
203 const ASTRecordLayout &record_layout) {
207 uint32_t type_info = this_type.
GetTypeInfo(&pointee_type);
212 bool ptr_or_ref =
false;
213 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
219 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
220 if ((type_info & cpp_class) != cpp_class)
225 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
239 vbtable_ptr_addr += vbtable_ptr_offset;
250 auto size = valobj.
GetData(data, err);
258 VTableContextBase &vtable_ctx,
260 const CXXRecordDecl *cxx_record_decl,
261 const CXXRecordDecl *base_class_decl) {
262 if (vtable_ctx.isMicrosoft()) {
263 clang::MicrosoftVTableContext &msoft_vtable_ctx =
264 static_cast<clang::MicrosoftVTableContext &
>(vtable_ctx);
268 const unsigned vbtable_index =
269 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
270 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
276 clang::ItaniumVTableContext &itanium_vtable_ctx =
277 static_cast<clang::ItaniumVTableContext &
>(vtable_ctx);
279 clang::CharUnits base_offset_offset =
280 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
283 vtable_ptr + base_offset_offset.getQuantity();
292 const ASTRecordLayout &record_layout,
293 const CXXRecordDecl *cxx_record_decl,
294 const CXXRecordDecl *base_class_decl,
295 int32_t &bit_offset) {
307 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
308 if (base_offset == INT64_MAX)
311 bit_offset = base_offset * 8;
321 static llvm::once_flag g_once_flag;
322 llvm::call_once(g_once_flag, []() {
329 bool is_complete_objc_class)
330 : m_payload(owning_module.GetValue()) {
342 const clang::Decl *parent) {
343 if (!member || !parent)
350 member->setFromASTFile();
351 member->setOwningModuleID(
id.GetValue());
352 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
353 if (llvm::isa<clang::NamedDecl>(member))
354 if (
auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
355 dc->setHasExternalVisibleStorage(
true);
358 dc->setHasExternalLexicalStorage(
true);
365 clang::OverloadedOperatorKind &op_kind) {
367 if (!name.consume_front(
"operator"))
372 bool space_after_operator = name.consume_front(
" ");
374 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
375 .Case(
"+", clang::OO_Plus)
376 .Case(
"+=", clang::OO_PlusEqual)
377 .Case(
"++", clang::OO_PlusPlus)
378 .Case(
"-", clang::OO_Minus)
379 .Case(
"-=", clang::OO_MinusEqual)
380 .Case(
"--", clang::OO_MinusMinus)
381 .Case(
"->", clang::OO_Arrow)
382 .Case(
"->*", clang::OO_ArrowStar)
383 .Case(
"*", clang::OO_Star)
384 .Case(
"*=", clang::OO_StarEqual)
385 .Case(
"/", clang::OO_Slash)
386 .Case(
"/=", clang::OO_SlashEqual)
387 .Case(
"%", clang::OO_Percent)
388 .Case(
"%=", clang::OO_PercentEqual)
389 .Case(
"^", clang::OO_Caret)
390 .Case(
"^=", clang::OO_CaretEqual)
391 .Case(
"&", clang::OO_Amp)
392 .Case(
"&=", clang::OO_AmpEqual)
393 .Case(
"&&", clang::OO_AmpAmp)
394 .Case(
"|", clang::OO_Pipe)
395 .Case(
"|=", clang::OO_PipeEqual)
396 .Case(
"||", clang::OO_PipePipe)
397 .Case(
"~", clang::OO_Tilde)
398 .Case(
"!", clang::OO_Exclaim)
399 .Case(
"!=", clang::OO_ExclaimEqual)
400 .Case(
"=", clang::OO_Equal)
401 .Case(
"==", clang::OO_EqualEqual)
402 .Case(
"<", clang::OO_Less)
403 .Case(
"<=>", clang::OO_Spaceship)
404 .Case(
"<<", clang::OO_LessLess)
405 .Case(
"<<=", clang::OO_LessLessEqual)
406 .Case(
"<=", clang::OO_LessEqual)
407 .Case(
">", clang::OO_Greater)
408 .Case(
">>", clang::OO_GreaterGreater)
409 .Case(
">>=", clang::OO_GreaterGreaterEqual)
410 .Case(
">=", clang::OO_GreaterEqual)
411 .Case(
"()", clang::OO_Call)
412 .Case(
"[]", clang::OO_Subscript)
413 .Case(
",", clang::OO_Comma)
414 .Default(clang::NUM_OVERLOADED_OPERATORS);
417 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
429 if (!space_after_operator)
434 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
435 .Case(
"new", clang::OO_New)
436 .Case(
"new[]", clang::OO_Array_New)
437 .Case(
"delete", clang::OO_Delete)
438 .Case(
"delete[]", clang::OO_Array_Delete)
440 .Default(clang::NUM_OVERLOADED_OPERATORS);
445clang::AccessSpecifier
465 std::vector<std::string> Includes;
466 LangOptions::setLangDefaults(Opts, clang::Language::ObjCXX, arch.
GetTriple(),
467 Includes, clang::LangStandard::lang_gnucxx98);
469 Opts.setValueVisibilityMode(DefaultVisibility);
473 Opts.Trigraphs = !Opts.GNUMode;
475 Opts.OptimizeSize = 0;
488 Opts.NoInlineDefine = !Opt;
492 Opts.ModulesLocalVisibility = 1;
496 llvm::Triple target_triple) {
498 if (!target_triple.str().empty())
506 ASTContext &existing_ctxt) {
520 if (!TypeSystemClangSupportsLanguage(language))
534 if (triple.getVendor() == llvm::Triple::Apple &&
535 triple.getOS() == llvm::Triple::UnknownOS) {
536 if (triple.getArch() == llvm::Triple::arm ||
537 triple.getArch() == llvm::Triple::aarch64 ||
538 triple.getArch() == llvm::Triple::aarch64_32 ||
539 triple.getArch() == llvm::Triple::thumb) {
540 triple.setOS(llvm::Triple::IOS);
542 triple.setOS(llvm::Triple::MacOSX);
547 std::string ast_name =
549 return std::make_shared<TypeSystemClang>(ast_name, triple);
550 }
else if (target && target->
IsValid())
551 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
613 assert(s ==
nullptr || &s->getASTContext() ==
m_ast_up.get());
626 llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
628 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(
true);
629 ast.setExternalSource(ast_source_up);
642 const clang::Diagnostic &info)
override {
644 llvm::SmallVector<char, 32> diag_str(10);
645 info.FormatDiagnostic(diag_str);
646 diag_str.push_back(
'\0');
647 LLDB_LOGF(m_log,
"Compiler diagnostic: %s\n", diag_str.data());
651 DiagnosticConsumer *
clone(DiagnosticsEngine &Diags)
const {
672 clang::FileSystemOptions file_system_options;
676 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(
new DiagnosticIDs());
678 std::make_unique<DiagnosticsEngine>(diag_id_sp,
new DiagnosticOptions());
682 m_ast_up = std::make_unique<ASTContext>(
694 m_ast_up->InitBuiltinTypes(*target_info);
698 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up(
731#pragma mark Basic Types
734 ASTContext &ast, QualType qual_type) {
735 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
736 return qual_type_bit_size == bit_size;
751 return GetType(ast.UnsignedCharTy);
753 return GetType(ast.UnsignedShortTy);
755 return GetType(ast.UnsignedIntTy);
757 return GetType(ast.UnsignedLongTy);
759 return GetType(ast.UnsignedLongLongTy);
761 return GetType(ast.UnsignedInt128Ty);
766 return GetType(ast.SignedCharTy);
774 return GetType(ast.LongLongTy);
785 return GetType(ast.LongDoubleTy);
792 if (bit_size && !(bit_size & 0x7u))
793 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
801 static const llvm::StringMap<lldb::BasicType> g_type_map = {
854 auto iter = g_type_map.find(name);
855 if (iter == g_type_map.end())
882 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
898 return GetType(ast.UnsignedCharTy);
900 return GetType(ast.UnsignedShortTy);
902 return GetType(ast.UnsignedIntTy);
907 if (type_name.contains(
"complex")) {
916 case DW_ATE_complex_float: {
917 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
919 return GetType(FloatComplexTy);
921 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
923 return GetType(DoubleComplexTy);
925 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
927 return GetType(LongDoubleComplexTy);
937 if (type_name ==
"float" &&
940 if (type_name ==
"double" &&
943 if (type_name ==
"long double" &&
945 return GetType(ast.LongDoubleTy);
952 return GetType(ast.LongDoubleTy);
958 if (!type_name.empty()) {
959 if (type_name ==
"wchar_t" &&
964 if (type_name ==
"void" &&
967 if (type_name.contains(
"long long") &&
969 return GetType(ast.LongLongTy);
970 if (type_name.contains(
"long") &&
973 if (type_name.contains(
"short") &&
976 if (type_name.contains(
"char")) {
980 return GetType(ast.SignedCharTy);
982 if (type_name.contains(
"int")) {
999 return GetType(ast.LongLongTy);
1004 case DW_ATE_signed_char:
1005 if (type_name ==
"char") {
1010 return GetType(ast.SignedCharTy);
1013 case DW_ATE_unsigned:
1014 if (!type_name.empty()) {
1015 if (type_name ==
"wchar_t") {
1022 if (type_name.contains(
"long long")) {
1024 return GetType(ast.UnsignedLongLongTy);
1025 }
else if (type_name.contains(
"long")) {
1027 return GetType(ast.UnsignedLongTy);
1028 }
else if (type_name.contains(
"short")) {
1030 return GetType(ast.UnsignedShortTy);
1031 }
else if (type_name.contains(
"char")) {
1033 return GetType(ast.UnsignedCharTy);
1034 }
else if (type_name.contains(
"int")) {
1036 return GetType(ast.UnsignedIntTy);
1038 return GetType(ast.UnsignedInt128Ty);
1043 return GetType(ast.UnsignedCharTy);
1045 return GetType(ast.UnsignedShortTy);
1047 return GetType(ast.UnsignedIntTy);
1049 return GetType(ast.UnsignedLongTy);
1051 return GetType(ast.UnsignedLongLongTy);
1053 return GetType(ast.UnsignedInt128Ty);
1056 case DW_ATE_unsigned_char:
1057 if (type_name ==
"char") {
1062 return GetType(ast.UnsignedCharTy);
1064 return GetType(ast.UnsignedShortTy);
1067 case DW_ATE_imaginary_float:
1079 if (!type_name.empty()) {
1080 if (type_name ==
"char16_t")
1082 if (type_name ==
"char32_t")
1084 if (type_name ==
"char8_t")
1093 "error: need to add support for DW_TAG_base_type '{0}' "
1094 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1095 type_name, dw_ate, bit_size);
1101 QualType char_type(ast.CharTy);
1104 char_type.addConst();
1106 return GetType(ast.getPointerType(char_type));
1110 bool ignore_qualifiers) {
1121 if (ignore_qualifiers) {
1122 type1_qual = type1_qual.getUnqualifiedType();
1123 type2_qual = type2_qual.getUnqualifiedType();
1126 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1133 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
1134 if (
auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1146 if (clang::ObjCInterfaceDecl *interface_decl =
1147 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1149 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1162#pragma mark Structure, Unions, Classes
1166 if (!decl || !owning_module.
HasValue())
1169 decl->setFromASTFile();
1170 decl->setOwningModuleID(owning_module.
GetValue());
1171 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1177 bool is_framework,
bool is_explicit) {
1179 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1181 assert(ast_source &&
"external ast source was lost");
1187 auto HSOpts = std::make_shared<clang::HeaderSearchOptions>();
1198 clang::Module *module;
1199 auto parent_desc = ast_source->getSourceDescriptor(parent.
GetValue());
1201 name, parent_desc ? parent_desc->getModuleOrNull() :
nullptr,
1202 is_framework, is_explicit);
1204 return ast_source->GetIDForModule(module);
1206 return ast_source->RegisterModule(module);
1211 AccessType access_type, llvm::StringRef name,
int kind,
1215 if (decl_ctx ==
nullptr)
1216 decl_ctx = ast.getTranslationUnitDecl();
1220 bool isForwardDecl =
true;
1221 bool isInternal =
false;
1223 isInternal, metadata);
1232 bool has_name = !name.empty();
1233 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1234 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1235 decl->setDeclContext(decl_ctx);
1237 decl->setDeclName(&ast.Idents.get(name));
1265 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1266 decl->setAnonymousStructOrUnion(
true);
1276 decl_ctx->addDecl(decl);
1278 return GetType(ast.getTagDeclType(decl));
1284bool IsValueParam(
const clang::TemplateArgument &argument) {
1285 return argument.getKind() == TemplateArgument::Integral;
1288void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
1290 clang::AccessSpecifier previous_access,
1291 clang::AccessSpecifier access_specifier) {
1292 if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
1294 if (previous_access != access_specifier) {
1297 if ((cxx_record_decl->isStruct() &&
1298 previous_access == clang::AccessSpecifier::AS_none &&
1299 access_specifier == clang::AccessSpecifier::AS_public) ||
1300 (cxx_record_decl->isClass() &&
1301 previous_access == clang::AccessSpecifier::AS_none &&
1302 access_specifier == clang::AccessSpecifier::AS_private)) {
1305 cxx_record_decl->addDecl(
1306 AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
1307 SourceLocation(), SourceLocation()));
1315 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1316 const bool parameter_pack =
false;
1317 const bool is_typename =
false;
1318 const unsigned depth = 0;
1319 const size_t num_template_params = template_param_infos.
Size();
1320 DeclContext *
const decl_context =
1321 ast.getTranslationUnitDecl();
1323 auto const &args = template_param_infos.
GetArgs();
1324 auto const &names = template_param_infos.
GetNames();
1325 for (
size_t i = 0; i < num_template_params; ++i) {
1326 const char *name = names[i];
1328 IdentifierInfo *identifier_info =
nullptr;
1329 if (name && name[0])
1330 identifier_info = &ast.Idents.get(name);
1331 TemplateArgument
const &targ = args[i];
1332 if (IsValueParam(targ)) {
1333 QualType template_param_type = targ.getIntegralType();
1334 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1335 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1336 identifier_info, template_param_type, parameter_pack,
1337 ast.getTrivialTypeSourceInfo(template_param_type)));
1339 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1340 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1341 identifier_info, is_typename, parameter_pack));
1346 IdentifierInfo *identifier_info =
nullptr;
1348 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1349 const bool parameter_pack_true =
true;
1353 QualType template_param_type =
1355 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1356 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1357 num_template_params, identifier_info, template_param_type,
1358 parameter_pack_true,
1359 ast.getTrivialTypeSourceInfo(template_param_type)));
1361 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1362 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1363 num_template_params, identifier_info, is_typename,
1364 parameter_pack_true));
1367 clang::Expr *
const requires_clause =
nullptr;
1368 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1369 ast, SourceLocation(), SourceLocation(), template_param_decls,
1370 SourceLocation(), requires_clause);
1371 return template_param_list;
1376 llvm::SmallVector<NamedDecl *, 8> ignore;
1377 clang::TemplateParameterList *template_param_list =
1380 llvm::SmallVector<clang::TemplateArgument, 2> args(
1381 template_param_infos.
GetArgs());
1383 llvm::ArrayRef<TemplateArgument> pack_args =
1385 args.append(pack_args.begin(), pack_args.end());
1388 llvm::raw_string_ostream os(str);
1390 template_param_list);
1396 clang::FunctionDecl *func_decl,
1401 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1403 ast, template_param_infos, template_param_decls);
1404 FunctionTemplateDecl *func_tmpl_decl =
1405 FunctionTemplateDecl::CreateDeserialized(ast, 0);
1406 func_tmpl_decl->setDeclContext(decl_ctx);
1407 func_tmpl_decl->setLocation(func_decl->getLocation());
1408 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1409 func_tmpl_decl->setTemplateParameters(template_param_list);
1410 func_tmpl_decl->init(func_decl);
1413 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1414 i < template_param_decl_count; ++i) {
1416 template_param_decls[i]->setDeclContext(func_decl);
1421 if (decl_ctx->isRecord())
1422 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1424 return func_tmpl_decl;
1428 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1430 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1431 func_decl->getASTContext(), infos.
GetArgs());
1433 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1434 template_args_ptr,
nullptr);
1441 const TemplateArgument &value) {
1442 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1444 if (value.getKind() != TemplateArgument::Type)
1446 }
else if (
auto *type_param =
1447 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1449 if (!IsValueParam(value))
1452 if (type_param->getType() != value.getIntegralType())
1460 "Don't know how to compare template parameter to passed"
1461 " value. Decl kind of parameter is: {0}",
1462 param->getDeclKindName());
1463 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1478 ClassTemplateDecl *class_template_decl,
1481 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1487 std::optional<NamedDecl *> pack_parameter;
1489 size_t non_pack_params = params.size();
1490 for (
size_t i = 0; i < params.size(); ++i) {
1491 NamedDecl *param = params.getParam(i);
1492 if (param->isParameterPack()) {
1493 pack_parameter = param;
1494 non_pack_params = i;
1502 if (non_pack_params != instantiation_values.
Size())
1520 for (
const auto pair :
1521 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1522 const TemplateArgument &passed_arg = std::get<0>(pair);
1523 NamedDecl *found_param = std::get<1>(pair);
1528 return class_template_decl;
1537 ClassTemplateDecl *class_template_decl =
nullptr;
1538 if (decl_ctx ==
nullptr)
1539 decl_ctx = ast.getTranslationUnitDecl();
1541 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1542 DeclarationName decl_name(&identifier_info);
1545 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1546 for (NamedDecl *decl : result) {
1547 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1548 if (!class_template_decl)
1557 template_param_infos))
1559 return class_template_decl;
1562 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1565 ast, template_param_infos, template_param_decls);
1567 CXXRecordDecl *template_cxx_decl = CXXRecordDecl::CreateDeserialized(ast, 0);
1568 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1570 template_cxx_decl->setDeclContext(decl_ctx);
1571 template_cxx_decl->setDeclName(decl_name);
1574 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1575 i < template_param_decl_count; ++i) {
1576 template_param_decls[i]->setDeclContext(template_cxx_decl);
1584 class_template_decl = ClassTemplateDecl::CreateDeserialized(ast, 0);
1586 class_template_decl->setDeclContext(decl_ctx);
1587 class_template_decl->setDeclName(decl_name);
1588 class_template_decl->setTemplateParameters(template_param_list);
1589 class_template_decl->init(template_cxx_decl);
1590 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1594 class_template_decl->setAccess(
1597 decl_ctx->addDecl(class_template_decl);
1599 VerifyDecl(class_template_decl);
1601 return class_template_decl;
1604TemplateTemplateParmDecl *
1608 auto *decl_ctx = ast.getTranslationUnitDecl();
1610 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1611 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1615 ast, template_param_infos, template_param_decls);
1621 return TemplateTemplateParmDecl::Create(ast, decl_ctx, SourceLocation(),
1624 &identifier_info,
false,
1625 template_param_list);
1628ClassTemplateSpecializationDecl *
1631 ClassTemplateDecl *class_template_decl,
int kind,
1634 llvm::SmallVector<clang::TemplateArgument, 2> args(
1635 template_param_infos.
Size() +
1638 auto const &orig_args = template_param_infos.
GetArgs();
1639 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1641 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1644 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1645 ClassTemplateSpecializationDecl::CreateDeserialized(ast, 0);
1646 class_template_specialization_decl->setTagKind(
1647 static_cast<TagDecl::TagKind
>(kind));
1648 class_template_specialization_decl->setDeclContext(decl_ctx);
1649 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1650 class_template_specialization_decl->setTemplateArgs(
1651 TemplateArgumentList::CreateCopy(ast, args));
1652 ast.getTypeDeclType(class_template_specialization_decl,
nullptr);
1653 class_template_specialization_decl->setDeclName(
1654 class_template_decl->getDeclName());
1656 decl_ctx->addDecl(class_template_specialization_decl);
1658 class_template_specialization_decl->setSpecializationKind(
1659 TSK_ExplicitSpecialization);
1661 return class_template_specialization_decl;
1665 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1666 if (class_template_specialization_decl) {
1668 return GetType(ast.getTagDeclType(class_template_specialization_decl));
1674 clang::OverloadedOperatorKind op_kind,
1675 bool unary,
bool binary,
1676 uint32_t num_params) {
1678 if (op_kind == OO_Call)
1684 if (num_params == 1)
1686 if (num_params == 2)
1693 bool is_method, clang::OverloadedOperatorKind op_kind,
1694 uint32_t num_params) {
1702 case OO_Array_Delete:
1706#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1708 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1710#include "clang/Basic/OperatorKinds.def"
1717clang::AccessSpecifier
1719 clang::AccessSpecifier rhs) {
1722 if (lhs == AS_none || rhs == AS_none)
1724 if (lhs == AS_private || rhs == AS_private)
1726 if (lhs == AS_protected || rhs == AS_protected)
1727 return AS_protected;
1732 uint32_t &bitfield_bit_size) {
1734 if (field ==
nullptr)
1737 if (field->isBitField()) {
1738 Expr *bit_width_expr = field->getBitWidth();
1739 if (bit_width_expr) {
1740 if (std::optional<llvm::APSInt> bit_width_apsint =
1741 bit_width_expr->getIntegerConstantExpr(ast)) {
1742 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1751 if (record_decl ==
nullptr)
1754 if (!record_decl->field_empty())
1758 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1759 if (cxx_record_decl) {
1760 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1761 for (base_class = cxx_record_decl->bases_begin(),
1762 base_class_end = cxx_record_decl->bases_end();
1763 base_class != base_class_end; ++base_class) {
1764 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(
1765 base_class->getType()->getAs<RecordType>()->getDecl());
1784#pragma mark Objective-C Classes
1787 llvm::StringRef name, clang::DeclContext *decl_ctx,
1791 assert(!name.empty());
1793 decl_ctx = ast.getTranslationUnitDecl();
1795 ObjCInterfaceDecl *decl = ObjCInterfaceDecl::CreateDeserialized(ast, 0);
1796 decl->setDeclContext(decl_ctx);
1797 decl->setDeclName(&ast.Idents.get(name));
1799 decl->setImplicit(isInternal);
1805 return GetType(ast.getObjCInterfaceType(decl));
1814 bool omit_empty_base_classes) {
1815 uint32_t num_bases = 0;
1816 if (cxx_record_decl) {
1817 if (omit_empty_base_classes) {
1818 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1819 for (base_class = cxx_record_decl->bases_begin(),
1820 base_class_end = cxx_record_decl->bases_end();
1821 base_class != base_class_end; ++base_class) {
1828 num_bases = cxx_record_decl->getNumBases();
1833#pragma mark Namespace Declarations
1836 const char *name, clang::DeclContext *decl_ctx,
1838 NamespaceDecl *namespace_decl =
nullptr;
1840 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1842 decl_ctx = translation_unit_decl;
1845 IdentifierInfo &identifier_info = ast.Idents.get(name);
1846 DeclarationName decl_name(&identifier_info);
1847 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1848 for (NamedDecl *decl : result) {
1849 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1851 return namespace_decl;
1854 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1855 SourceLocation(), SourceLocation(),
1856 &identifier_info,
nullptr,
false);
1858 decl_ctx->addDecl(namespace_decl);
1860 if (decl_ctx == translation_unit_decl) {
1861 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1863 return namespace_decl;
1866 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1867 SourceLocation(),
nullptr,
nullptr,
false);
1868 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1869 translation_unit_decl->addDecl(namespace_decl);
1870 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1872 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1873 if (parent_namespace_decl) {
1874 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1876 return namespace_decl;
1878 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1879 SourceLocation(),
nullptr,
nullptr,
false);
1880 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1881 parent_namespace_decl->addDecl(namespace_decl);
1882 assert(namespace_decl ==
1883 parent_namespace_decl->getAnonymousNamespace());
1885 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1886 "no namespace as decl_ctx");
1894 VerifyDecl(namespace_decl);
1895 return namespace_decl;
1902 clang::BlockDecl *decl =
1904 decl->setDeclContext(ctx);
1913 clang::DeclContext *right,
1914 clang::DeclContext *root) {
1915 if (root ==
nullptr)
1918 std::set<clang::DeclContext *> path_left;
1919 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1920 path_left.insert(d);
1922 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1923 if (path_left.find(d) != path_left.end())
1931 clang::NamespaceDecl *ns_decl) {
1932 if (decl_ctx && ns_decl) {
1933 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1934 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1936 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1937 clang::SourceLocation(), ns_decl,
1940 decl_ctx->addDecl(using_decl);
1950 clang::NamedDecl *target) {
1951 if (current_decl_ctx && target) {
1952 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1954 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1956 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1958 target->getDeclName(), using_decl, target);
1960 using_decl->addShadowDecl(shadow_decl);
1961 current_decl_ctx->addDecl(using_decl);
1969 const char *name, clang::QualType type) {
1971 clang::VarDecl *var_decl =
1973 var_decl->setDeclContext(decl_context);
1974 if (name && name[0])
1975 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1976 var_decl->setType(type);
1978 var_decl->setAccess(clang::AS_public);
1979 decl_context->addDecl(var_decl);
1988 switch (basic_type) {
1990 return ast->VoidTy.getAsOpaquePtr();
1992 return ast->CharTy.getAsOpaquePtr();
1994 return ast->SignedCharTy.getAsOpaquePtr();
1996 return ast->UnsignedCharTy.getAsOpaquePtr();
1998 return ast->getWCharType().getAsOpaquePtr();
2000 return ast->getSignedWCharType().getAsOpaquePtr();
2002 return ast->getUnsignedWCharType().getAsOpaquePtr();
2004 return ast->Char8Ty.getAsOpaquePtr();
2006 return ast->Char16Ty.getAsOpaquePtr();
2008 return ast->Char32Ty.getAsOpaquePtr();
2010 return ast->ShortTy.getAsOpaquePtr();
2012 return ast->UnsignedShortTy.getAsOpaquePtr();
2014 return ast->IntTy.getAsOpaquePtr();
2016 return ast->UnsignedIntTy.getAsOpaquePtr();
2018 return ast->LongTy.getAsOpaquePtr();
2020 return ast->UnsignedLongTy.getAsOpaquePtr();
2022 return ast->LongLongTy.getAsOpaquePtr();
2024 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2026 return ast->Int128Ty.getAsOpaquePtr();
2028 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2030 return ast->BoolTy.getAsOpaquePtr();
2032 return ast->HalfTy.getAsOpaquePtr();
2034 return ast->FloatTy.getAsOpaquePtr();
2036 return ast->DoubleTy.getAsOpaquePtr();
2038 return ast->LongDoubleTy.getAsOpaquePtr();
2040 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2042 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2044 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2046 return ast->getObjCIdType().getAsOpaquePtr();
2048 return ast->getObjCClassType().getAsOpaquePtr();
2050 return ast->getObjCSelType().getAsOpaquePtr();
2052 return ast->NullPtrTy.getAsOpaquePtr();
2058#pragma mark Function Types
2060clang::DeclarationName
2063 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2064 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2073 const clang::FunctionProtoType *function_type =
2074 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2075 if (function_type ==
nullptr)
2076 return clang::DeclarationName();
2078 const bool is_method =
false;
2079 const unsigned int num_params = function_type->getNumParams();
2081 is_method, op_kind, num_params))
2082 return clang::DeclarationName();
2084 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2088 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2089 printing_policy.SuppressTagKeyword =
true;
2092 printing_policy.SuppressInlineNamespace =
false;
2093 printing_policy.SuppressUnwrittenScope =
false;
2105 printing_policy.SuppressDefaultTemplateArgs =
false;
2106 return printing_policy;
2113 llvm::raw_string_ostream os(result);
2114 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2120 llvm::StringRef name,
const CompilerType &function_clang_type,
2121 clang::StorageClass storage,
bool is_inline) {
2122 FunctionDecl *func_decl =
nullptr;
2125 decl_ctx = ast.getTranslationUnitDecl();
2127 const bool hasWrittenPrototype =
true;
2128 const bool isConstexprSpecified =
false;
2130 clang::DeclarationName declarationName =
2132 func_decl = FunctionDecl::CreateDeserialized(ast, 0);
2133 func_decl->setDeclContext(decl_ctx);
2134 func_decl->setDeclName(declarationName);
2136 func_decl->setStorageClass(storage);
2137 func_decl->setInlineSpecified(is_inline);
2138 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2139 func_decl->setConstexprKind(isConstexprSpecified
2140 ? ConstexprSpecKind::Constexpr
2141 : ConstexprSpecKind::Unspecified);
2143 decl_ctx->addDecl(func_decl);
2145 VerifyDecl(func_decl);
2152 unsigned num_args,
bool is_variadic,
unsigned type_quals,
2153 clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
2157 std::vector<QualType> qual_type_args;
2158 if (num_args > 0 && args ==
nullptr)
2162 for (
unsigned i = 0; i < num_args; ++i) {
2177 FunctionProtoType::ExtProtoInfo proto_info;
2178 proto_info.ExtInfo = cc;
2179 proto_info.Variadic = is_variadic;
2180 proto_info.ExceptionSpec = EST_None;
2181 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2182 proto_info.RefQualifier = ref_qual;
2190 const char *name,
const CompilerType ¶m_type,
int storage,
2193 auto *decl = ParmVarDecl::CreateDeserialized(ast, 0);
2194 decl->setDeclContext(decl_ctx);
2195 if (name && name[0])
2196 decl->setDeclName(&ast.Idents.get(name));
2198 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2201 decl_ctx->addDecl(decl);
2207 FunctionDecl *function_decl, llvm::ArrayRef<ParmVarDecl *> params) {
2209 function_decl->setParams(params);
2214 QualType block_type =
m_ast_up->getBlockPointerType(
2220#pragma mark Array Types
2223 size_t element_count,
2233 llvm::APInt ap_element_count(64, element_count);
2234 if (element_count == 0) {
2237 clang::ArraySizeModifier::Normal, 0));
2239 return GetType(ast.getConstantArrayType(
2241 clang::ArraySizeModifier::Normal, 0));
2249 llvm::StringRef type_name,
2250 const std::initializer_list<std::pair<const char *, CompilerType>>
2254 if (!type_name.empty() &&
2255 (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
2257 lldbassert(0 &&
"Trying to create a type for an existing name");
2265 for (
const auto &field : type_fields)
2275 llvm::StringRef type_name,
2276 const std::initializer_list<std::pair<const char *, CompilerType>>
2280 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2286#pragma mark Enumeration Types
2289 llvm::StringRef name, clang::DeclContext *decl_ctx,
2291 const CompilerType &integer_clang_type,
bool is_scoped) {
2298 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, 0);
2299 enum_decl->setDeclContext(decl_ctx);
2301 enum_decl->setDeclName(&ast.Idents.get(name));
2302 enum_decl->setScoped(is_scoped);
2303 enum_decl->setScopedUsingClassTag(is_scoped);
2304 enum_decl->setFixed(
false);
2307 decl_ctx->addDecl(enum_decl);
2312 enum_decl->setAccess(AS_public);
2314 return GetType(ast.getTagDeclType(enum_decl));
2322 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2323 return GetType(ast.SignedCharTy);
2325 if (bit_size == ast.getTypeSize(ast.ShortTy))
2328 if (bit_size == ast.getTypeSize(ast.IntTy))
2331 if (bit_size == ast.getTypeSize(ast.LongTy))
2334 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2335 return GetType(ast.LongLongTy);
2337 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2340 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2341 return GetType(ast.UnsignedCharTy);
2343 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2344 return GetType(ast.UnsignedShortTy);
2346 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2347 return GetType(ast.UnsignedIntTy);
2349 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2350 return GetType(ast.UnsignedLongTy);
2352 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2353 return GetType(ast.UnsignedLongLongTy);
2355 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2356 return GetType(ast.UnsignedInt128Ty);
2370 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2372 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2373 named_decl->getDeclName().getAsString().c_str());
2375 printf(
"%20s\n", decl_ctx->getDeclKindName());
2381 if (decl ==
nullptr)
2385 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2387 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2388 record_decl->getDeclName().getAsString().c_str(),
2389 record_decl->isInjectedClassName() ?
" (injected class name)" :
"");
2392 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2394 printf(
"%20s: %s\n", decl->getDeclKindName(),
2395 named_decl->getDeclName().getAsString().c_str());
2397 printf(
"%20s\n", decl->getDeclKindName());
2403 clang::Decl *decl) {
2407 ExternalASTSource *ast_source = ast->getExternalSource();
2412 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2413 if (tag_decl->isCompleteDefinition())
2416 if (!tag_decl->hasExternalLexicalStorage())
2419 ast_source->CompleteType(tag_decl);
2421 return !tag_decl->getTypeForDecl()->isIncompleteType();
2422 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2423 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2424 if (objc_interface_decl->getDefinition())
2427 if (!objc_interface_decl->hasExternalLexicalStorage())
2430 ast_source->CompleteType(objc_interface_decl);
2432 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2477 clang::AccessSpecifier access) {
2478 if (access == clang::AccessSpecifier::AS_none)
2484clang::AccessSpecifier
2489 return clang::AccessSpecifier::AS_none;
2511 if (find(mask, type->getTypeClass()) != mask.end())
2513 switch (type->getTypeClass()) {
2516 case clang::Type::Atomic:
2517 type = cast<clang::AtomicType>(type)->getValueType();
2519 case clang::Type::Auto:
2520 case clang::Type::Decltype:
2521 case clang::Type::Elaborated:
2522 case clang::Type::Paren:
2523 case clang::Type::SubstTemplateTypeParm:
2524 case clang::Type::TemplateSpecialization:
2525 case clang::Type::Typedef:
2526 case clang::Type::TypeOf:
2527 case clang::Type::TypeOfExpr:
2528 case clang::Type::Using:
2529 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2543 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2544 switch (type_class) {
2545 case clang::Type::ObjCInterface:
2546 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2548 case clang::Type::ObjCObjectPointer:
2550 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2551 ->getPointeeType());
2552 case clang::Type::Record:
2553 return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2554 case clang::Type::Enum:
2555 return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2564 clang::QualType qual_type,
2565 bool allow_completion =
true) {
2567 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2568 switch (type_class) {
2569 case clang::Type::ConstantArray:
2570 case clang::Type::IncompleteArray:
2571 case clang::Type::VariableArray: {
2572 const clang::ArrayType *array_type =
2573 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2579 case clang::Type::Record: {
2580 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2581 if (cxx_record_decl) {
2582 if (cxx_record_decl->hasExternalLexicalStorage()) {
2583 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2584 const bool fields_loaded =
2585 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2586 if (is_complete && fields_loaded)
2589 if (!allow_completion)
2594 clang::ExternalASTSource *external_ast_source =
2595 ast->getExternalSource();
2596 if (external_ast_source) {
2597 external_ast_source->CompleteType(cxx_record_decl);
2598 if (cxx_record_decl->isCompleteDefinition()) {
2599 cxx_record_decl->field_begin();
2600 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2605 const clang::TagType *tag_type =
2606 llvm::cast<clang::TagType>(qual_type.getTypePtr());
2607 return !tag_type->isIncompleteType();
2610 case clang::Type::Enum: {
2611 const clang::TagType *tag_type =
2612 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
2614 clang::TagDecl *tag_decl = tag_type->getDecl();
2616 if (tag_decl->getDefinition())
2619 if (!allow_completion)
2622 if (tag_decl->hasExternalLexicalStorage()) {
2624 clang::ExternalASTSource *external_ast_source =
2625 ast->getExternalSource();
2626 if (external_ast_source) {
2627 external_ast_source->CompleteType(tag_decl);
2628 return !tag_type->isIncompleteType();
2637 case clang::Type::ObjCObject:
2638 case clang::Type::ObjCInterface: {
2639 const clang::ObjCObjectType *objc_class_type =
2640 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2641 if (objc_class_type) {
2642 clang::ObjCInterfaceDecl *class_interface_decl =
2643 objc_class_type->getInterface();
2646 if (class_interface_decl) {
2647 if (class_interface_decl->getDefinition())
2650 if (!allow_completion)
2653 if (class_interface_decl->hasExternalLexicalStorage()) {
2655 clang::ExternalASTSource *external_ast_source =
2656 ast->getExternalSource();
2657 if (external_ast_source) {
2658 external_ast_source->CompleteType(class_interface_decl);
2659 return !objc_class_type->isIncompleteType();
2668 case clang::Type::Attributed:
2670 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(),
2680static clang::ObjCIvarDecl::AccessControl
2684 return clang::ObjCIvarDecl::None;
2686 return clang::ObjCIvarDecl::Public;
2688 return clang::ObjCIvarDecl::Private;
2690 return clang::ObjCIvarDecl::Protected;
2692 return clang::ObjCIvarDecl::Package;
2694 return clang::ObjCIvarDecl::None;
2701 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2708 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2709 switch (type_class) {
2710 case clang::Type::IncompleteArray:
2711 case clang::Type::VariableArray:
2712 case clang::Type::ConstantArray:
2713 case clang::Type::ExtVector:
2714 case clang::Type::Vector:
2715 case clang::Type::Record:
2716 case clang::Type::ObjCObject:
2717 case clang::Type::ObjCInterface:
2729 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2730 switch (type_class) {
2731 case clang::Type::Record: {
2732 if (
const clang::RecordType *record_type =
2733 llvm::dyn_cast_or_null<clang::RecordType>(
2734 qual_type.getTypePtrOrNull())) {
2735 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2736 return record_decl->isAnonymousStructOrUnion();
2750 uint64_t *size,
bool *is_incomplete) {
2753 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2754 switch (type_class) {
2758 case clang::Type::ConstantArray:
2759 if (element_type_ptr)
2761 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2765 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2767 .getLimitedValue(ULLONG_MAX);
2769 *is_incomplete =
false;
2772 case clang::Type::IncompleteArray:
2773 if (element_type_ptr)
2775 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2781 *is_incomplete =
true;
2784 case clang::Type::VariableArray:
2785 if (element_type_ptr)
2787 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2793 *is_incomplete =
false;
2796 case clang::Type::DependentSizedArray:
2797 if (element_type_ptr)
2800 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2806 *is_incomplete =
false;
2809 if (element_type_ptr)
2810 element_type_ptr->
Clear();
2814 *is_incomplete =
false;
2822 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2823 switch (type_class) {
2824 case clang::Type::Vector: {
2825 const clang::VectorType *vector_type =
2826 qual_type->getAs<clang::VectorType>();
2829 *size = vector_type->getNumElements();
2831 *element_type =
GetType(vector_type->getElementType());
2835 case clang::Type::ExtVector: {
2836 const clang::ExtVectorType *ext_vector_type =
2837 qual_type->getAs<clang::ExtVectorType>();
2838 if (ext_vector_type) {
2840 *size = ext_vector_type->getNumElements();
2844 ext_vector_type->getElementType().getAsOpaquePtr());
2860 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2863 clang::ObjCInterfaceDecl *result_iface_decl =
2864 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2869 return (ast_metadata->
GetISAPtr() != 0);
2873 return GetQualType(type).getUnqualifiedType()->isCharType();
2882 const bool allow_completion =
true;
2897 if (!pointee_or_element_clang_type.
IsValid())
2900 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2901 if (pointee_or_element_clang_type.
IsCharType()) {
2902 if (type_flags.
Test(eTypeIsArray)) {
2905 length = llvm::cast<clang::ConstantArrayType>(
2917 auto isFunctionType = [&](clang::QualType qual_type) {
2918 return qual_type->isFunctionType();
2932 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2933 switch (type_class) {
2934 case clang::Type::Record:
2936 const clang::CXXRecordDecl *cxx_record_decl =
2937 qual_type->getAsCXXRecordDecl();
2938 if (cxx_record_decl) {
2939 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
2942 const clang::RecordType *record_type =
2943 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2945 const clang::RecordDecl *record_decl = record_type->getDecl();
2949 clang::RecordDecl::field_iterator field_pos,
2950 field_end = record_decl->field_end();
2951 uint32_t num_fields = 0;
2952 bool is_hva =
false;
2953 bool is_hfa =
false;
2954 clang::QualType base_qual_type;
2955 uint64_t base_bitwidth = 0;
2956 for (field_pos = record_decl->field_begin(); field_pos != field_end;
2958 clang::QualType field_qual_type = field_pos->getType();
2959 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
2960 if (field_qual_type->isFloatingType()) {
2961 if (field_qual_type->isComplexType())
2964 if (num_fields == 0)
2965 base_qual_type = field_qual_type;
2970 if (field_qual_type.getTypePtr() !=
2971 base_qual_type.getTypePtr())
2975 }
else if (field_qual_type->isVectorType() ||
2976 field_qual_type->isExtVectorType()) {
2977 if (num_fields == 0) {
2978 base_qual_type = field_qual_type;
2979 base_bitwidth = field_bitwidth;
2984 if (base_bitwidth != field_bitwidth)
2986 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
2995 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3012 const clang::FunctionProtoType *func =
3013 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3015 return func->getNumParams();
3022 const size_t index) {
3025 const clang::FunctionProtoType *func =
3026 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3028 if (index < func->getNumParams())
3029 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3037 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3041 if (predicate(qual_type))
3044 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3045 switch (type_class) {
3049 case clang::Type::LValueReference:
3050 case clang::Type::RValueReference: {
3051 const clang::ReferenceType *reference_type =
3052 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3054 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3063 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3064 return qual_type->isMemberFunctionPointerType();
3067 return IsTypeImpl(type, isMemberFunctionPointerType);
3071 auto isFunctionPointerType = [](clang::QualType qual_type) {
3072 return qual_type->isFunctionPointerType();
3075 return IsTypeImpl(type, isFunctionPointerType);
3081 auto isBlockPointerType = [&](clang::QualType qual_type) {
3082 if (qual_type->isBlockPointerType()) {
3083 if (function_pointer_type_ptr) {
3084 const clang::BlockPointerType *block_pointer_type =
3085 qual_type->castAs<clang::BlockPointerType>();
3086 QualType pointee_type = block_pointer_type->getPointeeType();
3087 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3089 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3106 const clang::BuiltinType *builtin_type =
3107 llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3110 if (builtin_type->isInteger()) {
3111 is_signed = builtin_type->isSignedInteger();
3122 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3126 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(),
3138 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3142 return enum_type->isScopedEnumeralType();
3153 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3154 switch (type_class) {
3155 case clang::Type::Builtin:
3156 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3159 case clang::BuiltinType::ObjCId:
3160 case clang::BuiltinType::ObjCClass:
3164 case clang::Type::ObjCObjectPointer:
3168 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3172 case clang::Type::BlockPointer:
3175 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3179 case clang::Type::Pointer:
3182 llvm::cast<clang::PointerType>(qual_type)
3186 case clang::Type::MemberPointer:
3189 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3198 pointee_type->
Clear();
3206 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3207 switch (type_class) {
3208 case clang::Type::Builtin:
3209 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3212 case clang::BuiltinType::ObjCId:
3213 case clang::BuiltinType::ObjCClass:
3217 case clang::Type::ObjCObjectPointer:
3221 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3225 case clang::Type::BlockPointer:
3228 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3232 case clang::Type::Pointer:
3235 llvm::cast<clang::PointerType>(qual_type)
3239 case clang::Type::MemberPointer:
3242 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3246 case clang::Type::LValueReference:
3249 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3253 case clang::Type::RValueReference:
3256 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3265 pointee_type->
Clear();
3274 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3276 switch (type_class) {
3277 case clang::Type::LValueReference:
3280 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3286 case clang::Type::RValueReference:
3289 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3301 pointee_type->
Clear();
3306 uint32_t &count,
bool &is_complex) {
3310 if (
const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(
3311 qual_type->getCanonicalTypeInternal())) {
3312 clang::BuiltinType::Kind kind = BT->getKind();
3313 if (kind >= clang::BuiltinType::Float &&
3314 kind <= clang::BuiltinType::LongDouble) {
3319 }
else if (
const clang::ComplexType *CT =
3320 llvm::dyn_cast<clang::ComplexType>(
3321 qual_type->getCanonicalTypeInternal())) {
3328 }
else if (
const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(
3329 qual_type->getCanonicalTypeInternal())) {
3332 count = VT->getNumElements();
3348 const clang::TagType *tag_type =
3349 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3351 clang::TagDecl *tag_decl = tag_type->getDecl();
3353 return tag_decl->isCompleteDefinition();
3356 const clang::ObjCObjectType *objc_class_type =
3357 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3358 if (objc_class_type) {
3359 clang::ObjCInterfaceDecl *class_interface_decl =
3360 objc_class_type->getInterface();
3361 if (class_interface_decl)
3362 return class_interface_decl->getDefinition() !=
nullptr;
3373 const clang::ObjCObjectPointerType *obj_pointer_type =
3374 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3376 if (obj_pointer_type)
3377 return obj_pointer_type->isObjCClassType();
3392 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3393 return (type_class == clang::Type::Record);
3400 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3401 return (type_class == clang::Type::Enum);
3407 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3408 switch (type_class) {
3409 case clang::Type::Record:
3411 const clang::RecordType *record_type =
3412 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3413 const clang::RecordDecl *record_decl = record_type->getDecl();
3415 const clang::CXXRecordDecl *cxx_record_decl =
3416 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3417 if (cxx_record_decl) {
3424 return cxx_record_decl->isDynamicClass();
3439 bool check_cplusplus,
3441 clang::QualType pointee_qual_type;
3444 bool success =
false;
3445 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3446 switch (type_class) {
3447 case clang::Type::Builtin:
3449 llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3450 clang::BuiltinType::ObjCId) {
3451 if (dynamic_pointee_type)
3457 case clang::Type::ObjCObjectPointer:
3459 if (
const auto *objc_pointee_type =
3460 qual_type->getPointeeType().getTypePtrOrNull()) {
3461 if (
const auto *objc_object_type =
3462 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3463 objc_pointee_type)) {
3464 if (objc_object_type->isObjCClass())
3468 if (dynamic_pointee_type)
3471 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3478 case clang::Type::Pointer:
3480 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3484 case clang::Type::LValueReference:
3485 case clang::Type::RValueReference:
3487 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3499 const clang::Type::TypeClass pointee_type_class =
3500 pointee_qual_type.getCanonicalType()->getTypeClass();
3501 switch (pointee_type_class) {
3502 case clang::Type::Builtin:
3503 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3504 case clang::BuiltinType::UnknownAny:
3505 case clang::BuiltinType::Void:
3506 if (dynamic_pointee_type)
3508 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3515 case clang::Type::Record:
3516 if (check_cplusplus) {
3517 clang::CXXRecordDecl *cxx_record_decl =
3518 pointee_qual_type->getAsCXXRecordDecl();
3519 if (cxx_record_decl) {
3520 bool is_complete = cxx_record_decl->isCompleteDefinition();
3523 success = cxx_record_decl->isDynamicClass();
3531 success = cxx_record_decl->isDynamicClass();
3538 if (dynamic_pointee_type)
3540 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3547 case clang::Type::ObjCObject:
3548 case clang::Type::ObjCInterface:
3550 if (dynamic_pointee_type)
3552 weak_from_this(), pointee_qual_type.getAsOpaquePtr());
3562 if (dynamic_pointee_type)
3563 dynamic_pointee_type->
Clear();
3571 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3578 ->getTypeClass() == clang::Type::Typedef;
3588 if (
auto *record_decl =
3590 return record_decl->canPassInRegisters();
3596 return TypeSystemClangSupportsLanguage(language);
3599std::optional<std::string>
3602 return std::nullopt;
3605 if (qual_type.isNull())
3606 return std::nullopt;
3608 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3609 if (!cxx_record_decl)
3610 return std::nullopt;
3612 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3620 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3627 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3629 return tag_type->isBeingDefined();
3640 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3641 if (class_type_ptr) {
3642 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3643 const clang::ObjCObjectPointerType *obj_pointer_type =
3644 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3645 if (obj_pointer_type ==
nullptr)
3646 class_type_ptr->
Clear();
3650 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3657 class_type_ptr->
Clear();
3666 const bool allow_completion =
true;
3686 {clang::Type::Typedef, clang::Type::Atomic});
3689 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3690 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3697 if (
auto *named_decl = qual_type->getAsTagDecl())
3709 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3710 printing_policy.SuppressTagKeyword =
true;
3711 printing_policy.SuppressScope =
false;
3712 printing_policy.SuppressUnwrittenScope =
true;
3713 printing_policy.SuppressInlineNamespace =
true;
3714 return ConstString(qual_type.getAsString(printing_policy));
3723 if (pointee_or_element_clang_type)
3724 pointee_or_element_clang_type->
Clear();
3726 clang::QualType qual_type =
3729 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3730 switch (type_class) {
3731 case clang::Type::Attributed:
3732 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3735 pointee_or_element_clang_type);
3736 case clang::Type::Builtin: {
3737 const clang::BuiltinType *builtin_type =
3738 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3740 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3741 switch (builtin_type->getKind()) {
3742 case clang::BuiltinType::ObjCId:
3743 case clang::BuiltinType::ObjCClass:
3744 if (pointee_or_element_clang_type)
3748 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3751 case clang::BuiltinType::ObjCSel:
3752 if (pointee_or_element_clang_type)
3755 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3758 case clang::BuiltinType::Bool:
3759 case clang::BuiltinType::Char_U:
3760 case clang::BuiltinType::UChar:
3761 case clang::BuiltinType::WChar_U:
3762 case clang::BuiltinType::Char16:
3763 case clang::BuiltinType::Char32:
3764 case clang::BuiltinType::UShort:
3765 case clang::BuiltinType::UInt:
3766 case clang::BuiltinType::ULong:
3767 case clang::BuiltinType::ULongLong:
3768 case clang::BuiltinType::UInt128:
3769 case clang::BuiltinType::Char_S:
3770 case clang::BuiltinType::SChar:
3771 case clang::BuiltinType::WChar_S:
3772 case clang::BuiltinType::Short:
3773 case clang::BuiltinType::Int:
3774 case clang::BuiltinType::Long:
3775 case clang::BuiltinType::LongLong:
3776 case clang::BuiltinType::Int128:
3777 case clang::BuiltinType::Float:
3778 case clang::BuiltinType::Double:
3779 case clang::BuiltinType::LongDouble:
3780 builtin_type_flags |= eTypeIsScalar;
3781 if (builtin_type->isInteger()) {
3782 builtin_type_flags |= eTypeIsInteger;
3783 if (builtin_type->isSignedInteger())
3784 builtin_type_flags |= eTypeIsSigned;
3785 }
else if (builtin_type->isFloatingPoint())
3786 builtin_type_flags |= eTypeIsFloat;
3791 return builtin_type_flags;
3794 case clang::Type::BlockPointer:
3795 if (pointee_or_element_clang_type)
3797 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3798 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3800 case clang::Type::Complex: {
3801 uint32_t complex_type_flags =
3802 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3803 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3804 qual_type->getCanonicalTypeInternal());
3806 clang::QualType complex_element_type(complex_type->getElementType());
3807 if (complex_element_type->isIntegerType())
3808 complex_type_flags |= eTypeIsFloat;
3809 else if (complex_element_type->isFloatingType())
3810 complex_type_flags |= eTypeIsInteger;
3812 return complex_type_flags;
3815 case clang::Type::ConstantArray:
3816 case clang::Type::DependentSizedArray:
3817 case clang::Type::IncompleteArray:
3818 case clang::Type::VariableArray:
3819 if (pointee_or_element_clang_type)
3821 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3824 return eTypeHasChildren | eTypeIsArray;
3826 case clang::Type::DependentName:
3828 case clang::Type::DependentSizedExtVector:
3829 return eTypeHasChildren | eTypeIsVector;
3830 case clang::Type::DependentTemplateSpecialization:
3831 return eTypeIsTemplate;
3833 case clang::Type::Enum:
3834 if (pointee_or_element_clang_type)
3836 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3840 return eTypeIsEnumeration | eTypeHasValue;
3842 case clang::Type::FunctionProto:
3843 return eTypeIsFuncPrototype | eTypeHasValue;
3844 case clang::Type::FunctionNoProto:
3845 return eTypeIsFuncPrototype | eTypeHasValue;
3846 case clang::Type::InjectedClassName:
3849 case clang::Type::LValueReference:
3850 case clang::Type::RValueReference:
3851 if (pointee_or_element_clang_type)
3854 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3857 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3859 case clang::Type::MemberPointer:
3860 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3862 case clang::Type::ObjCObjectPointer:
3863 if (pointee_or_element_clang_type)
3865 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3866 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3869 case clang::Type::ObjCObject:
3870 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3871 case clang::Type::ObjCInterface:
3872 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3874 case clang::Type::Pointer:
3875 if (pointee_or_element_clang_type)
3877 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3878 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3880 case clang::Type::Record:
3881 if (qual_type->getAsCXXRecordDecl())
3882 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3884 return eTypeHasChildren | eTypeIsStructUnion;
3886 case clang::Type::SubstTemplateTypeParm:
3887 return eTypeIsTemplate;
3888 case clang::Type::TemplateTypeParm:
3889 return eTypeIsTemplate;
3890 case clang::Type::TemplateSpecialization:
3891 return eTypeIsTemplate;
3893 case clang::Type::Typedef:
3894 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
3896 ->getUnderlyingType())
3898 case clang::Type::UnresolvedUsing:
3901 case clang::Type::ExtVector:
3902 case clang::Type::Vector: {
3903 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
3904 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
3905 qual_type->getCanonicalTypeInternal());
3907 if (vector_type->isIntegerType())
3908 vector_type_flags |= eTypeIsFloat;
3909 else if (vector_type->isFloatingType())
3910 vector_type_flags |= eTypeIsInteger;
3912 return vector_type_flags;
3927 if (qual_type->isAnyPointerType()) {
3928 if (qual_type->isObjCObjectPointerType())
3930 if (qual_type->getPointeeCXXRecordDecl())
3933 clang::QualType pointee_type(qual_type->getPointeeType());
3934 if (pointee_type->getPointeeCXXRecordDecl())
3936 if (pointee_type->isObjCObjectOrInterfaceType())
3938 if (pointee_type->isObjCClassType())
3940 if (pointee_type.getTypePtr() ==
3944 if (qual_type->isObjCObjectOrInterfaceType())
3946 if (qual_type->getAsCXXRecordDecl())
3948 switch (qual_type->getTypeClass()) {
3951 case clang::Type::Builtin:
3952 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3954 case clang::BuiltinType::Void:
3955 case clang::BuiltinType::Bool:
3956 case clang::BuiltinType::Char_U:
3957 case clang::BuiltinType::UChar:
3958 case clang::BuiltinType::WChar_U:
3959 case clang::BuiltinType::Char16:
3960 case clang::BuiltinType::Char32:
3961 case clang::BuiltinType::UShort:
3962 case clang::BuiltinType::UInt:
3963 case clang::BuiltinType::ULong:
3964 case clang::BuiltinType::ULongLong:
3965 case clang::BuiltinType::UInt128:
3966 case clang::BuiltinType::Char_S:
3967 case clang::BuiltinType::SChar:
3968 case clang::BuiltinType::WChar_S:
3969 case clang::BuiltinType::Short:
3970 case clang::BuiltinType::Int:
3971 case clang::BuiltinType::Long:
3972 case clang::BuiltinType::LongLong:
3973 case clang::BuiltinType::Int128:
3974 case clang::BuiltinType::Float:
3975 case clang::BuiltinType::Double:
3976 case clang::BuiltinType::LongDouble:
3979 case clang::BuiltinType::NullPtr:
3982 case clang::BuiltinType::ObjCId:
3983 case clang::BuiltinType::ObjCClass:
3984 case clang::BuiltinType::ObjCSel:
3987 case clang::BuiltinType::Dependent:
3988 case clang::BuiltinType::Overload:
3989 case clang::BuiltinType::BoundMember:
3990 case clang::BuiltinType::UnknownAny:
3994 case clang::Type::Typedef:
3995 return GetType(llvm::cast<clang::TypedefType>(qual_type)
3997 ->getUnderlyingType())
4007 return lldb::eTypeClassInvalid;
4009 clang::QualType qual_type =
4012 switch (qual_type->getTypeClass()) {
4013 case clang::Type::Atomic:
4014 case clang::Type::Auto:
4015 case clang::Type::CountAttributed:
4016 case clang::Type::Decltype:
4017 case clang::Type::Elaborated:
4018 case clang::Type::Paren:
4019 case clang::Type::TypeOf:
4020 case clang::Type::TypeOfExpr:
4021 case clang::Type::Using:
4022 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4023 case clang::Type::UnaryTransform:
4025 case clang::Type::FunctionNoProto:
4026 return lldb::eTypeClassFunction;
4027 case clang::Type::FunctionProto:
4028 return lldb::eTypeClassFunction;
4029 case clang::Type::IncompleteArray:
4030 return lldb::eTypeClassArray;
4031 case clang::Type::VariableArray:
4032 return lldb::eTypeClassArray;
4033 case clang::Type::ConstantArray:
4034 return lldb::eTypeClassArray;
4035 case clang::Type::DependentSizedArray:
4036 return lldb::eTypeClassArray;
4037 case clang::Type::ArrayParameter:
4038 return lldb::eTypeClassArray;
4039 case clang::Type::DependentSizedExtVector:
4040 return lldb::eTypeClassVector;
4041 case clang::Type::DependentVector:
4042 return lldb::eTypeClassVector;
4043 case clang::Type::ExtVector:
4044 return lldb::eTypeClassVector;
4045 case clang::Type::Vector:
4046 return lldb::eTypeClassVector;
4047 case clang::Type::Builtin:
4049 case clang::Type::BitInt:
4050 case clang::Type::DependentBitInt:
4051 return lldb::eTypeClassBuiltin;
4052 case clang::Type::ObjCObjectPointer:
4053 return lldb::eTypeClassObjCObjectPointer;
4054 case clang::Type::BlockPointer:
4055 return lldb::eTypeClassBlockPointer;
4056 case clang::Type::Pointer:
4057 return lldb::eTypeClassPointer;
4058 case clang::Type::LValueReference:
4059 return lldb::eTypeClassReference;
4060 case clang::Type::RValueReference:
4061 return lldb::eTypeClassReference;
4062 case clang::Type::MemberPointer:
4063 return lldb::eTypeClassMemberPointer;
4064 case clang::Type::Complex:
4065 if (qual_type->isComplexType())
4066 return lldb::eTypeClassComplexFloat;
4068 return lldb::eTypeClassComplexInteger;
4069 case clang::Type::ObjCObject:
4070 return lldb::eTypeClassObjCObject;
4071 case clang::Type::ObjCInterface:
4072 return lldb::eTypeClassObjCInterface;
4073 case clang::Type::Record: {
4074 const clang::RecordType *record_type =
4075 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4076 const clang::RecordDecl *record_decl = record_type->getDecl();
4077 if (record_decl->isUnion())
4078 return lldb::eTypeClassUnion;
4079 else if (record_decl->isStruct())
4080 return lldb::eTypeClassStruct;
4082 return lldb::eTypeClassClass;
4084 case clang::Type::Enum:
4085 return lldb::eTypeClassEnumeration;
4086 case clang::Type::Typedef:
4087 return lldb::eTypeClassTypedef;
4088 case clang::Type::UnresolvedUsing:
4091 case clang::Type::Attributed:
4092 case clang::Type::BTFTagAttributed:
4094 case clang::Type::TemplateTypeParm:
4096 case clang::Type::SubstTemplateTypeParm:
4098 case clang::Type::SubstTemplateTypeParmPack:
4100 case clang::Type::InjectedClassName:
4102 case clang::Type::DependentName:
4104 case clang::Type::DependentTemplateSpecialization:
4106 case clang::Type::PackExpansion:
4109 case clang::Type::TemplateSpecialization:
4111 case clang::Type::DeducedTemplateSpecialization:
4113 case clang::Type::Pipe:
4117 case clang::Type::Decayed:
4119 case clang::Type::Adjusted:
4121 case clang::Type::ObjCTypeParam:
4124 case clang::Type::DependentAddressSpace:
4126 case clang::Type::MacroQualified:
4130 case clang::Type::ConstantMatrix:
4131 case clang::Type::DependentSizedMatrix:
4135 case clang::Type::PackIndexing:
4139 return lldb::eTypeClassOther;
4144 return GetQualType(type).getQualifiers().getCVRQualifiers();
4156 const clang::Type *array_eletype =
4157 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4162 return GetType(clang::QualType(array_eletype, 0));
4173 return GetType(ast_ctx.getConstantArrayType(
4174 qual_type, llvm::APInt(64, size),
nullptr,
4175 clang::ArraySizeModifier::Normal, 0));
4177 return GetType(ast_ctx.getIncompleteArrayType(
4178 qual_type, clang::ArraySizeModifier::Normal, 0));
4192 clang::QualType qual_type) {
4193 if (qual_type->isPointerType())
4194 qual_type = ast->getPointerType(
4196 else if (
const ConstantArrayType *arr =
4197 ast->getAsConstantArrayType(qual_type)) {
4198 qual_type = ast->getConstantArrayType(
4200 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4201 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4203 qual_type = qual_type.getUnqualifiedType();
4204 qual_type.removeLocalConst();
4205 qual_type.removeLocalRestrict();
4206 qual_type.removeLocalVolatile();
4228 const clang::FunctionProtoType *func =
4231 return func->getNumParams();
4239 const clang::FunctionProtoType *func =
4240 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4242 const uint32_t num_args = func->getNumParams();
4244 return GetType(func->getParamType(idx));
4254 const clang::FunctionProtoType *func =
4255 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4257 return GetType(func->getReturnType());
4264 size_t num_functions = 0;
4267 switch (qual_type->getTypeClass()) {
4268 case clang::Type::Record:
4270 const clang::RecordType *record_type =
4271 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4272 const clang::RecordDecl *record_decl = record_type->getDecl();
4273 assert(record_decl);
4274 const clang::CXXRecordDecl *cxx_record_decl =
4275 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4276 if (cxx_record_decl)
4277 num_functions = std::distance(cxx_record_decl->method_begin(),
4278 cxx_record_decl->method_end());
4282 case clang::Type::ObjCObjectPointer: {
4283 const clang::ObjCObjectPointerType *objc_class_type =
4284 qual_type->castAs<clang::ObjCObjectPointerType>();
4285 const clang::ObjCInterfaceType *objc_interface_type =
4286 objc_class_type->getInterfaceType();
4287 if (objc_interface_type &&
4289 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4290 clang::ObjCInterfaceDecl *class_interface_decl =
4291 objc_interface_type->getDecl();
4292 if (class_interface_decl) {
4293 num_functions = std::distance(class_interface_decl->meth_begin(),
4294 class_interface_decl->meth_end());
4300 case clang::Type::ObjCObject:
4301 case clang::Type::ObjCInterface:
4303 const clang::ObjCObjectType *objc_class_type =
4304 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4305 if (objc_class_type) {
4306 clang::ObjCInterfaceDecl *class_interface_decl =
4307 objc_class_type->getInterface();
4308 if (class_interface_decl)
4309 num_functions = std::distance(class_interface_decl->meth_begin(),
4310 class_interface_decl->meth_end());
4319 return num_functions;
4331 switch (qual_type->getTypeClass()) {
4332 case clang::Type::Record:
4334 const clang::RecordType *record_type =
4335 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4336 const clang::RecordDecl *record_decl = record_type->getDecl();
4337 assert(record_decl);
4338 const clang::CXXRecordDecl *cxx_record_decl =
4339 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4340 if (cxx_record_decl) {
4341 auto method_iter = cxx_record_decl->method_begin();
4342 auto method_end = cxx_record_decl->method_end();
4344 static_cast<size_t>(std::distance(method_iter, method_end))) {
4345 std::advance(method_iter, idx);
4346 clang::CXXMethodDecl *cxx_method_decl =
4347 method_iter->getCanonicalDecl();
4348 if (cxx_method_decl) {
4349 name = cxx_method_decl->getDeclName().getAsString();
4350 if (cxx_method_decl->isStatic())
4352 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4354 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4358 clang_type =
GetType(cxx_method_decl->getType());
4366 case clang::Type::ObjCObjectPointer: {
4367 const clang::ObjCObjectPointerType *objc_class_type =
4368 qual_type->castAs<clang::ObjCObjectPointerType>();
4369 const clang::ObjCInterfaceType *objc_interface_type =
4370 objc_class_type->getInterfaceType();
4371 if (objc_interface_type &&
4373 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4374 clang::ObjCInterfaceDecl *class_interface_decl =
4375 objc_interface_type->getDecl();
4376 if (class_interface_decl) {
4377 auto method_iter = class_interface_decl->meth_begin();
4378 auto method_end = class_interface_decl->meth_end();
4380 static_cast<size_t>(std::distance(method_iter, method_end))) {
4381 std::advance(method_iter, idx);
4382 clang::ObjCMethodDecl *objc_method_decl =
4383 method_iter->getCanonicalDecl();
4384 if (objc_method_decl) {
4386 name = objc_method_decl->getSelector().getAsString();
4387 if (objc_method_decl->isClassMethod())
4398 case clang::Type::ObjCObject:
4399 case clang::Type::ObjCInterface:
4401 const clang::ObjCObjectType *objc_class_type =
4402 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4403 if (objc_class_type) {
4404 clang::ObjCInterfaceDecl *class_interface_decl =
4405 objc_class_type->getInterface();
4406 if (class_interface_decl) {
4407 auto method_iter = class_interface_decl->meth_begin();
4408 auto method_end = class_interface_decl->meth_end();
4410 static_cast<size_t>(std::distance(method_iter, method_end))) {
4411 std::advance(method_iter, idx);
4412 clang::ObjCMethodDecl *objc_method_decl =
4413 method_iter->getCanonicalDecl();
4414 if (objc_method_decl) {
4416 name = objc_method_decl->getSelector().getAsString();
4417 if (objc_method_decl->isClassMethod())
4450 return GetType(qual_type.getTypePtr()->getPointeeType());
4460 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4461 case clang::Type::ObjCObject:
4462 case clang::Type::ObjCInterface:
4508 result.addVolatile();
4518 result.addRestrict();
4527 if (type && typedef_name && typedef_name[0]) {
4531 clang::DeclContext *decl_ctx =
4536 clang::TypedefDecl *decl =
4537 clang::TypedefDecl::CreateDeserialized(clang_ast, 0);
4538 decl->setDeclContext(decl_ctx);
4539 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4540 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4541 decl_ctx->addDecl(decl);
4544 clang::TagDecl *tdecl =
nullptr;
4545 if (!qual_type.isNull()) {
4546 if (
const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4547 tdecl = rt->getDecl();
4548 if (
const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4549 tdecl = et->getDecl();
4555 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4556 tdecl->setTypedefNameForAnonDecl(decl);
4558 decl->setAccess(clang::AS_public);
4561 return GetType(clang_ast.getTypedefType(decl));
4569 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4572 return GetType(typedef_type->getDecl()->getUnderlyingType());
4585 const FunctionType::ExtInfo generic_ext_info(
4594 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4599const llvm::fltSemantics &
4602 const size_t bit_size = byte_size * 8;
4603 if (bit_size == ast.getTypeSize(ast.FloatTy))
4604 return ast.getFloatTypeSemantics(ast.FloatTy);
4605 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4606 return ast.getFloatTypeSemantics(ast.DoubleTy);
4607 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4608 bit_size == llvm::APFloat::semanticsSizeInBits(
4609 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4610 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4611 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4612 return ast.getFloatTypeSemantics(ast.HalfTy);
4613 return llvm::APFloatBase::Bogus();
4616std::optional<uint64_t>
4621 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4622 switch (type_class) {
4623 case clang::Type::Record:
4627 return std::nullopt;
4630 case clang::Type::ObjCInterface:
4631 case clang::Type::ObjCObject: {
4637 uint64_t bit_size = 0;
4642 static bool g_printed =
false;
4647 llvm::outs() <<
"warning: trying to determine the size of type ";
4649 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4650 "reliable. please file a bug against LLDB.\n";
4651 llvm::outs() <<
"backtrace:\n";
4652 llvm::sys::PrintStackTrace(llvm::outs());
4653 llvm::outs() <<
"\n";
4660 const uint32_t bit_size =
getASTContext().getTypeSize(qual_type);
4661 if (bit_size == 0) {
4662 if (qual_type->isIncompleteArrayType())
4664 qual_type->getArrayElementTypeNoTypeQual()
4665 ->getCanonicalTypeUnqualified());
4667 if (qual_type->isObjCObjectOrInterfaceType())
4671 if (qual_type->isFunctionProtoType())
4677 return std::nullopt;
4680std::optional<size_t>
4696 switch (qual_type->getTypeClass()) {
4697 case clang::Type::Atomic:
4698 case clang::Type::Auto:
4699 case clang::Type::CountAttributed:
4700 case clang::Type::Decltype:
4701 case clang::Type::Elaborated:
4702 case clang::Type::Paren:
4703 case clang::Type::Typedef:
4704 case clang::Type::TypeOf:
4705 case clang::Type::TypeOfExpr:
4706 case clang::Type::Using:
4707 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4709 case clang::Type::UnaryTransform:
4712 case clang::Type::FunctionNoProto:
4713 case clang::Type::FunctionProto:
4716 case clang::Type::IncompleteArray:
4717 case clang::Type::VariableArray:
4718 case clang::Type::ArrayParameter:
4721 case clang::Type::ConstantArray:
4724 case clang::Type::DependentVector:
4725 case clang::Type::ExtVector:
4726 case clang::Type::Vector:
4730 case clang::Type::BitInt:
4731 case clang::Type::DependentBitInt:
4735 case clang::Type::Builtin:
4736 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4737 case clang::BuiltinType::Void:
4740 case clang::BuiltinType::Char_S:
4741 case clang::BuiltinType::SChar:
4742 case clang::BuiltinType::WChar_S:
4743 case clang::BuiltinType::Short:
4744 case clang::BuiltinType::Int:
4745 case clang::BuiltinType::Long:
4746 case clang::BuiltinType::LongLong:
4747 case clang::BuiltinType::Int128:
4750 case clang::BuiltinType::Bool:
4751 case clang::BuiltinType::Char_U:
4752 case clang::BuiltinType::UChar:
4753 case clang::BuiltinType::WChar_U:
4754 case clang::BuiltinType::Char8:
4755 case clang::BuiltinType::Char16:
4756 case clang::BuiltinType::Char32:
4757 case clang::BuiltinType::UShort:
4758 case clang::BuiltinType::UInt:
4759 case clang::BuiltinType::ULong:
4760 case clang::BuiltinType::ULongLong:
4761 case clang::BuiltinType::UInt128:
4765 case clang::BuiltinType::ShortAccum:
4766 case clang::BuiltinType::Accum:
4767 case clang::BuiltinType::LongAccum:
4768 case clang::BuiltinType::UShortAccum:
4769 case clang::BuiltinType::UAccum:
4770 case clang::BuiltinType::ULongAccum:
4771 case clang::BuiltinType::ShortFract:
4772 case clang::BuiltinType::Fract:
4773 case clang::BuiltinType::LongFract:
4774 case clang::BuiltinType::UShortFract:
4775 case clang::BuiltinType::UFract:
4776 case clang::BuiltinType::ULongFract:
4777 case clang::BuiltinType::SatShortAccum:
4778 case clang::BuiltinType::SatAccum:
4779 case clang::BuiltinType::SatLongAccum:
4780 case clang::BuiltinType::SatUShortAccum:
4781 case clang::BuiltinType::SatUAccum:
4782 case clang::BuiltinType::SatULongAccum:
4783 case clang::BuiltinType::SatShortFract:
4784 case clang::BuiltinType::SatFract:
4785 case clang::BuiltinType::SatLongFract:
4786 case clang::BuiltinType::SatUShortFract:
4787 case clang::BuiltinType::SatUFract:
4788 case clang::BuiltinType::SatULongFract:
4791 case clang::BuiltinType::Half:
4792 case clang::BuiltinType::Float:
4793 case clang::BuiltinType::Float16:
4794 case clang::BuiltinType::Float128:
4795 case clang::BuiltinType::Double:
4796 case clang::BuiltinType::LongDouble:
4797 case clang::BuiltinType::BFloat16:
4798 case clang::BuiltinType::Ibm128:
4801 case clang::BuiltinType::ObjCClass:
4802 case clang::BuiltinType::ObjCId:
4803 case clang::BuiltinType::ObjCSel:
4806 case clang::BuiltinType::NullPtr:
4809 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4810 case clang::BuiltinType::Kind::BoundMember:
4811 case clang::BuiltinType::Kind::BuiltinFn:
4812 case clang::BuiltinType::Kind::Dependent:
4813 case clang::BuiltinType::Kind::OCLClkEvent:
4814 case clang::BuiltinType::Kind::OCLEvent:
4815 case clang::BuiltinType::Kind::OCLImage1dRO:
4816 case clang::BuiltinType::Kind::OCLImage1dWO:
4817 case clang::BuiltinType::Kind::OCLImage1dRW:
4818 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4819 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4820 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4821 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4822 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4823 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4824 case clang::BuiltinType::Kind::OCLImage2dRO:
4825 case clang::BuiltinType::Kind::OCLImage2dWO:
4826 case clang::BuiltinType::Kind::OCLImage2dRW:
4827 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4828 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4829 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4830 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4831 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4832 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4833 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4834 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4835 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4836 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4837 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4838 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4839 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4840 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4841 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4842 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4843 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4844 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4845 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4846 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4847 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4848 case clang::BuiltinType::Kind::OCLImage3dRO:
4849 case clang::BuiltinType::Kind::OCLImage3dWO:
4850 case clang::BuiltinType::Kind::OCLImage3dRW:
4851 case clang::BuiltinType::Kind::OCLQueue:
4852 case clang::BuiltinType::Kind::OCLReserveID:
4853 case clang::BuiltinType::Kind::OCLSampler:
4854 case clang::BuiltinType::Kind::OMPArraySection:
4855 case clang::BuiltinType::Kind::OMPArrayShaping:
4856 case clang::BuiltinType::Kind::OMPIterator:
4857 case clang::BuiltinType::Kind::Overload:
4858 case clang::BuiltinType::Kind::PseudoObject:
4859 case clang::BuiltinType::Kind::UnknownAny:
4862 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4863 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4864 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4865 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4866 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4867 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4868 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4869 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4870 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4871 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4872 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4873 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4877 case clang::BuiltinType::VectorPair:
4878 case clang::BuiltinType::VectorQuad:
4882 case clang::BuiltinType::SveBool:
4883 case clang::BuiltinType::SveBoolx2:
4884 case clang::BuiltinType::SveBoolx4:
4885 case clang::BuiltinType::SveCount:
4886 case clang::BuiltinType::SveInt8:
4887 case clang::BuiltinType::SveInt8x2:
4888 case clang::BuiltinType::SveInt8x3:
4889 case clang::BuiltinType::SveInt8x4:
4890 case clang::BuiltinType::SveInt16:
4891 case clang::BuiltinType::SveInt16x2:
4892 case clang::BuiltinType::SveInt16x3:
4893 case clang::BuiltinType::SveInt16x4:
4894 case clang::BuiltinType::SveInt32:
4895 case clang::BuiltinType::SveInt32x2:
4896 case clang::BuiltinType::SveInt32x3:
4897 case clang::BuiltinType::SveInt32x4:
4898 case clang::BuiltinType::SveInt64:
4899 case clang::BuiltinType::SveInt64x2:
4900 case clang::BuiltinType::SveInt64x3:
4901 case clang::BuiltinType::SveInt64x4:
4902 case clang::BuiltinType::SveUint8:
4903 case clang::BuiltinType::SveUint8x2:
4904 case clang::BuiltinType::SveUint8x3:
4905 case clang::BuiltinType::SveUint8x4:
4906 case clang::BuiltinType::SveUint16:
4907 case clang::BuiltinType::SveUint16x2:
4908 case clang::BuiltinType::SveUint16x3:
4909 case clang::BuiltinType::SveUint16x4:
4910 case clang::BuiltinType::SveUint32:
4911 case clang::BuiltinType::SveUint32x2:
4912 case clang::BuiltinType::SveUint32x3:
4913 case clang::BuiltinType::SveUint32x4:
4914 case clang::BuiltinType::SveUint64:
4915 case clang::BuiltinType::SveUint64x2:
4916 case clang::BuiltinType::SveUint64x3:
4917 case clang::BuiltinType::SveUint64x4:
4918 case clang::BuiltinType::SveFloat16:
4919 case clang::BuiltinType::SveBFloat16:
4920 case clang::BuiltinType::SveBFloat16x2:
4921 case clang::BuiltinType::SveBFloat16x3:
4922 case clang::BuiltinType::SveBFloat16x4:
4923 case clang::BuiltinType::SveFloat16x2:
4924 case clang::BuiltinType::SveFloat16x3:
4925 case clang::BuiltinType::SveFloat16x4:
4926 case clang::BuiltinType::SveFloat32:
4927 case clang::BuiltinType::SveFloat32x2:
4928 case clang::BuiltinType::SveFloat32x3:
4929 case clang::BuiltinType::SveFloat32x4:
4930 case clang::BuiltinType::SveFloat64:
4931 case clang::BuiltinType::SveFloat64x2:
4932 case clang::BuiltinType::SveFloat64x3:
4933 case clang::BuiltinType::SveFloat64x4:
4937#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
4938#include "clang/Basic/RISCVVTypes.def"
4942 case clang::BuiltinType::WasmExternRef:
4945 case clang::BuiltinType::IncompleteMatrixIdx:
4951 case clang::Type::ObjCObjectPointer:
4952 case clang::Type::BlockPointer:
4953 case clang::Type::Pointer:
4954 case clang::Type::LValueReference:
4955 case clang::Type::RValueReference:
4956 case clang::Type::MemberPointer:
4958 case clang::Type::Complex: {
4960 if (qual_type->isComplexType())
4963 const clang::ComplexType *complex_type =
4964 qual_type->getAsComplexIntegerType();
4974 case clang::Type::ObjCInterface:
4976 case clang::Type::Record:
4978 case clang::Type::Enum:
4979 return qual_type->isUnsignedIntegerOrEnumerationType()
4982 case clang::Type::DependentSizedArray:
4983 case clang::Type::DependentSizedExtVector:
4984 case clang::Type::UnresolvedUsing:
4985 case clang::Type::Attributed:
4986 case clang::Type::BTFTagAttributed:
4987 case clang::Type::TemplateTypeParm:
4988 case clang::Type::SubstTemplateTypeParm:
4989 case clang::Type::SubstTemplateTypeParmPack:
4990 case clang::Type::InjectedClassName:
4991 case clang::Type::DependentName:
4992 case clang::Type::DependentTemplateSpecialization:
4993 case clang::Type::PackExpansion:
4994 case clang::Type::ObjCObject:
4996 case clang::Type::TemplateSpecialization:
4997 case clang::Type::DeducedTemplateSpecialization:
4998 case clang::Type::Adjusted:
4999 case clang::Type::Pipe:
5003 case clang::Type::Decayed:
5005 case clang::Type::ObjCTypeParam:
5008 case clang::Type::DependentAddressSpace:
5010 case clang::Type::MacroQualified:
5013 case clang::Type::ConstantMatrix:
5014 case clang::Type::DependentSizedMatrix:
5018 case clang::Type::PackIndexing:
5031 switch (qual_type->getTypeClass()) {
5032 case clang::Type::Atomic:
5033 case clang::Type::Auto:
5034 case clang::Type::CountAttributed:
5035 case clang::Type::Decltype:
5036 case clang::Type::Elaborated:
5037 case clang::Type::Paren:
5038 case clang::Type::Typedef:
5039 case clang::Type::TypeOf:
5040 case clang::Type::TypeOfExpr:
5041 case clang::Type::Using:
5042 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5043 case clang::Type::UnaryTransform:
5046 case clang::Type::FunctionNoProto:
5047 case clang::Type::FunctionProto:
5050 case clang::Type::IncompleteArray:
5051 case clang::Type::VariableArray:
5052 case clang::Type::ArrayParameter:
5055 case clang::Type::ConstantArray:
5058 case clang::Type::DependentVector:
5059 case clang::Type::ExtVector:
5060 case clang::Type::Vector:
5063 case clang::Type::BitInt:
5064 case clang::Type::DependentBitInt:
5068 case clang::Type::Builtin:
5069 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5070 case clang::BuiltinType::UnknownAny:
5071 case clang::BuiltinType::Void:
5072 case clang::BuiltinType::BoundMember:
5075 case clang::BuiltinType::Bool:
5077 case clang::BuiltinType::Char_S:
5078 case clang::BuiltinType::SChar:
5079 case clang::BuiltinType::WChar_S:
5080 case clang::BuiltinType::Char_U:
5081 case clang::BuiltinType::UChar:
5082 case clang::BuiltinType::WChar_U:
5084 case clang::BuiltinType::Char8:
5086 case clang::BuiltinType::Char16:
5088 case clang::BuiltinType::Char32:
5090 case clang::BuiltinType::UShort:
5092 case clang::BuiltinType::Short:
5094 case clang::BuiltinType::UInt:
5096 case clang::BuiltinType::Int:
5098 case clang::BuiltinType::ULong:
5100 case clang::BuiltinType::Long:
5102 case clang::BuiltinType::ULongLong:
5104 case clang::BuiltinType::LongLong:
5106 case clang::BuiltinType::UInt128:
5108 case clang::BuiltinType::Int128:
5110 case clang::BuiltinType::Half:
5111 case clang::BuiltinType::Float:
5112 case clang::BuiltinType::Double:
5113 case clang::BuiltinType::LongDouble:
5119 case clang::Type::ObjCObjectPointer:
5121 case clang::Type::BlockPointer:
5123 case clang::Type::Pointer:
5125 case clang::Type::LValueReference:
5126 case clang::Type::RValueReference:
5128 case clang::Type::MemberPointer:
5130 case clang::Type::Complex: {
5131 if (qual_type->isComplexType())
5136 case clang::Type::ObjCInterface:
5138 case clang::Type::Record:
5140 case clang::Type::Enum:
5142 case clang::Type::DependentSizedArray:
5143 case clang::Type::DependentSizedExtVector:
5144 case clang::Type::UnresolvedUsing:
5145 case clang::Type::Attributed:
5146 case clang::Type::BTFTagAttributed:
5147 case clang::Type::TemplateTypeParm:
5148 case clang::Type::SubstTemplateTypeParm:
5149 case clang::Type::SubstTemplateTypeParmPack:
5150 case clang::Type::InjectedClassName:
5151 case clang::Type::DependentName:
5152 case clang::Type::DependentTemplateSpecialization:
5153 case clang::Type::PackExpansion:
5154 case clang::Type::ObjCObject:
5156 case clang::Type::TemplateSpecialization:
5157 case clang::Type::DeducedTemplateSpecialization:
5158 case clang::Type::Adjusted:
5159 case clang::Type::Pipe:
5163 case clang::Type::Decayed:
5165 case clang::Type::ObjCTypeParam:
5168 case clang::Type::DependentAddressSpace:
5170 case clang::Type::MacroQualified:
5174 case clang::Type::ConstantMatrix:
5175 case clang::Type::DependentSizedMatrix:
5179 case clang::Type::PackIndexing:
5187 bool check_superclass) {
5188 while (class_interface_decl) {
5189 if (class_interface_decl->ivar_size() > 0)
5192 if (check_superclass)
5193 class_interface_decl = class_interface_decl->getSuperClass();
5200static std::optional<SymbolFile::ArrayInfo>
5202 clang::QualType qual_type,
5204 if (qual_type->isIncompleteArrayType())
5205 if (
auto *metadata = ast.
GetMetadata(qual_type.getTypePtr()))
5208 return std::nullopt;
5211llvm::Expected<uint32_t>
5213 bool omit_empty_base_classes,
5216 return llvm::make_error<llvm::StringError>(
"invalid clang type",
5217 llvm::inconvertibleErrorCode());
5219 uint32_t num_children = 0;
5221 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5222 switch (type_class) {
5223 case clang::Type::Builtin:
5224 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5225 case clang::BuiltinType::ObjCId:
5226 case clang::BuiltinType::ObjCClass:
5235 case clang::Type::Complex:
5237 case clang::Type::Record:
5239 const clang::RecordType *record_type =
5240 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5241 const clang::RecordDecl *record_decl = record_type->getDecl();
5242 assert(record_decl);
5243 const clang::CXXRecordDecl *cxx_record_decl =
5244 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5245 if (cxx_record_decl) {
5246 if (omit_empty_base_classes) {
5250 clang::CXXRecordDecl::base_class_const_iterator base_class,
5252 for (base_class = cxx_record_decl->bases_begin(),
5253 base_class_end = cxx_record_decl->bases_end();
5254 base_class != base_class_end; ++base_class) {
5255 const clang::CXXRecordDecl *base_class_decl =
5256 llvm::cast<clang::CXXRecordDecl>(
5257 base_class->getType()
5258 ->getAs<clang::RecordType>()
5269 num_children += cxx_record_decl->getNumBases();
5272 num_children += std::distance(record_decl->field_begin(),
5273 record_decl->field_end());
5275 return llvm::make_error<llvm::StringError>(
5277 llvm::inconvertibleErrorCode());
5279 case clang::Type::ObjCObject:
5280 case clang::Type::ObjCInterface:
5282 const clang::ObjCObjectType *objc_class_type =
5283 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5284 assert(objc_class_type);
5285 if (objc_class_type) {
5286 clang::ObjCInterfaceDecl *class_interface_decl =
5287 objc_class_type->getInterface();
5289 if (class_interface_decl) {
5291 clang::ObjCInterfaceDecl *superclass_interface_decl =
5292 class_interface_decl->getSuperClass();
5293 if (superclass_interface_decl) {
5294 if (omit_empty_base_classes) {
5301 num_children += class_interface_decl->ivar_size();
5307 case clang::Type::LValueReference:
5308 case clang::Type::RValueReference:
5309 case clang::Type::ObjCObjectPointer: {
5312 uint32_t num_pointee_children = 0;
5314 auto num_children_or_err =
5315 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5316 if (!num_children_or_err)
5317 return num_children_or_err;
5318 num_pointee_children = *num_children_or_err;
5321 if (num_pointee_children == 0)
5324 num_children = num_pointee_children;
5327 case clang::Type::Vector:
5328 case clang::Type::ExtVector:
5330 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5333 case clang::Type::ConstantArray:
5334 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5338 case clang::Type::IncompleteArray:
5339 if (
auto array_info =
5342 num_children = array_info->element_orders.size()
5343 ? array_info->element_orders.back()
5347 case clang::Type::Pointer: {
5348 const clang::PointerType *pointer_type =
5349 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5350 clang::QualType pointee_type(pointer_type->getPointeeType());
5352 uint32_t num_pointee_children = 0;
5354 auto num_children_or_err =
5355 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5356 if (!num_children_or_err)
5357 return num_children_or_err;
5358 num_pointee_children = *num_children_or_err;
5360 if (num_pointee_children == 0) {
5365 num_children = num_pointee_children;
5371 return num_children;
5382 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5383 if (type_class == clang::Type::Builtin) {
5384 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5385 case clang::BuiltinType::Void:
5387 case clang::BuiltinType::Bool:
5389 case clang::BuiltinType::Char_S:
5391 case clang::BuiltinType::Char_U:
5393 case clang::BuiltinType::Char8:
5395 case clang::BuiltinType::Char16:
5397 case clang::BuiltinType::Char32:
5399 case clang::BuiltinType::UChar:
5401 case clang::BuiltinType::SChar:
5403 case clang::BuiltinType::WChar_S:
5405 case clang::BuiltinType::WChar_U:
5407 case clang::BuiltinType::Short:
5409 case clang::BuiltinType::UShort:
5411 case clang::BuiltinType::Int:
5413 case clang::BuiltinType::UInt:
5415 case clang::BuiltinType::Long:
5417 case clang::BuiltinType::ULong:
5419 case clang::BuiltinType::LongLong:
5421 case clang::BuiltinType::ULongLong:
5423 case clang::BuiltinType::Int128:
5425 case clang::BuiltinType::UInt128:
5428 case clang::BuiltinType::Half:
5430 case clang::BuiltinType::Float:
5432 case clang::BuiltinType::Double:
5434 case clang::BuiltinType::LongDouble:
5437 case clang::BuiltinType::NullPtr:
5439 case clang::BuiltinType::ObjCId:
5441 case clang::BuiltinType::ObjCClass:
5443 case clang::BuiltinType::ObjCSel:
5457 const llvm::APSInt &value)>
const &callback) {
5458 const clang::EnumType *enum_type =
5461 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5465 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5466 for (enum_pos = enum_decl->enumerator_begin(),
5467 enum_end_pos = enum_decl->enumerator_end();
5468 enum_pos != enum_end_pos; ++enum_pos) {
5469 ConstString name(enum_pos->getNameAsString().c_str());
5470 if (!callback(integer_type, name, enum_pos->getInitVal()))
5477#pragma mark Aggregate Types
5485 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5486 switch (type_class) {
5487 case clang::Type::Record:
5489 const clang::RecordType *record_type =
5490 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5492 clang::RecordDecl *record_decl = record_type->getDecl();
5494 count = std::distance(record_decl->field_begin(),
5495 record_decl->field_end());
5501 case clang::Type::ObjCObjectPointer: {
5502 const clang::ObjCObjectPointerType *objc_class_type =
5503 qual_type->castAs<clang::ObjCObjectPointerType>();
5504 const clang::ObjCInterfaceType *objc_interface_type =
5505 objc_class_type->getInterfaceType();
5506 if (objc_interface_type &&
5508 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5509 clang::ObjCInterfaceDecl *class_interface_decl =
5510 objc_interface_type->getDecl();
5511 if (class_interface_decl) {
5512 count = class_interface_decl->ivar_size();
5518 case clang::Type::ObjCObject:
5519 case clang::Type::ObjCInterface:
5521 const clang::ObjCObjectType *objc_class_type =
5522 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5523 if (objc_class_type) {
5524 clang::ObjCInterfaceDecl *class_interface_decl =
5525 objc_class_type->getInterface();
5527 if (class_interface_decl)
5528 count = class_interface_decl->ivar_size();
5541 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5542 std::string &name, uint64_t *bit_offset_ptr,
5543 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5544 if (class_interface_decl) {
5545 if (idx < (class_interface_decl->ivar_size())) {
5546 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5547 ivar_end = class_interface_decl->ivar_end();
5548 uint32_t ivar_idx = 0;
5550 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5551 ++ivar_pos, ++ivar_idx) {
5552 if (ivar_idx == idx) {
5553 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5555 clang::QualType ivar_qual_type(ivar_decl->getType());
5557 name.assign(ivar_decl->getNameAsString());
5559 if (bit_offset_ptr) {
5560 const clang::ASTRecordLayout &interface_layout =
5561 ast->getASTObjCInterfaceLayout(class_interface_decl);
5562 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5565 const bool is_bitfield = ivar_pos->isBitField();
5567 if (bitfield_bit_size_ptr) {
5568 *bitfield_bit_size_ptr = 0;
5570 if (is_bitfield && ast) {
5571 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5572 clang::Expr::EvalResult result;
5573 if (bitfield_bit_size_expr &&
5574 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5575 llvm::APSInt bitfield_apsint = result.Val.getInt();
5576 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5580 if (is_bitfield_ptr)
5581 *is_bitfield_ptr = is_bitfield;
5583 return ivar_qual_type.getAsOpaquePtr();
5592 size_t idx, std::string &name,
5593 uint64_t *bit_offset_ptr,
5594 uint32_t *bitfield_bit_size_ptr,
5595 bool *is_bitfield_ptr) {
5600 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5601 switch (type_class) {
5602 case clang::Type::Record:
5604 const clang::RecordType *record_type =
5605 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5606 const clang::RecordDecl *record_decl = record_type->getDecl();
5607 uint32_t field_idx = 0;
5608 clang::RecordDecl::field_iterator field, field_end;
5609 for (field = record_decl->field_begin(),
5610 field_end = record_decl->field_end();
5611 field != field_end; ++field, ++field_idx) {
5612 if (idx == field_idx) {
5615 name.assign(field->getNameAsString());
5619 if (bit_offset_ptr) {
5620 const clang::ASTRecordLayout &record_layout =
5622 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5625 const bool is_bitfield = field->isBitField();
5627 if (bitfield_bit_size_ptr) {
5628 *bitfield_bit_size_ptr = 0;
5631 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5632 clang::Expr::EvalResult result;
5633 if (bitfield_bit_size_expr &&
5634 bitfield_bit_size_expr->EvaluateAsInt(result,
5636 llvm::APSInt bitfield_apsint = result.Val.getInt();
5637 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5641 if (is_bitfield_ptr)
5642 *is_bitfield_ptr = is_bitfield;
5644 return GetType(field->getType());
5650 case clang::Type::ObjCObjectPointer: {
5651 const clang::ObjCObjectPointerType *objc_class_type =
5652 qual_type->castAs<clang::ObjCObjectPointerType>();
5653 const clang::ObjCInterfaceType *objc_interface_type =
5654 objc_class_type->getInterfaceType();
5655 if (objc_interface_type &&
5657 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5658 clang::ObjCInterfaceDecl *class_interface_decl =
5659 objc_interface_type->getDecl();
5660 if (class_interface_decl) {
5664 name, bit_offset_ptr, bitfield_bit_size_ptr,
5671 case clang::Type::ObjCObject:
5672 case clang::Type::ObjCInterface:
5674 const clang::ObjCObjectType *objc_class_type =
5675 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5676 assert(objc_class_type);
5677 if (objc_class_type) {
5678 clang::ObjCInterfaceDecl *class_interface_decl =
5679 objc_class_type->getInterface();
5683 name, bit_offset_ptr, bitfield_bit_size_ptr,
5699 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5700 switch (type_class) {
5701 case clang::Type::Record:
5703 const clang::CXXRecordDecl *cxx_record_decl =
5704 qual_type->getAsCXXRecordDecl();
5705 if (cxx_record_decl)
5706 count = cxx_record_decl->getNumBases();
5710 case clang::Type::ObjCObjectPointer:
5714 case clang::Type::ObjCObject:
5716 const clang::ObjCObjectType *objc_class_type =
5717 qual_type->getAsObjCQualifiedInterfaceType();
5718 if (objc_class_type) {
5719 clang::ObjCInterfaceDecl *class_interface_decl =
5720 objc_class_type->getInterface();
5722 if (class_interface_decl && class_interface_decl->getSuperClass())
5727 case clang::Type::ObjCInterface:
5729 const clang::ObjCInterfaceType *objc_interface_type =
5730 qual_type->getAs<clang::ObjCInterfaceType>();
5731 if (objc_interface_type) {
5732 clang::ObjCInterfaceDecl *class_interface_decl =
5733 objc_interface_type->getInterface();
5735 if (class_interface_decl && class_interface_decl->getSuperClass())
5751 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5752 switch (type_class) {
5753 case clang::Type::Record:
5755 const clang::CXXRecordDecl *cxx_record_decl =
5756 qual_type->getAsCXXRecordDecl();
5757 if (cxx_record_decl)
5758 count = cxx_record_decl->getNumVBases();
5771 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5772 switch (type_class) {
5773 case clang::Type::Record:
5775 const clang::CXXRecordDecl *cxx_record_decl =
5776 qual_type->getAsCXXRecordDecl();
5777 if (cxx_record_decl) {
5778 uint32_t curr_idx = 0;
5779 clang::CXXRecordDecl::base_class_const_iterator base_class,
5781 for (base_class = cxx_record_decl->bases_begin(),
5782 base_class_end = cxx_record_decl->bases_end();
5783 base_class != base_class_end; ++base_class, ++curr_idx) {
5784 if (curr_idx == idx) {
5785 if (bit_offset_ptr) {
5786 const clang::ASTRecordLayout &record_layout =
5788 const clang::CXXRecordDecl *base_class_decl =
5789 llvm::cast<clang::CXXRecordDecl>(
5790 base_class->getType()
5791 ->castAs<clang::RecordType>()
5793 if (base_class->isVirtual())
5795 record_layout.getVBaseClassOffset(base_class_decl)
5800 record_layout.getBaseClassOffset(base_class_decl)
5804 return GetType(base_class->getType());
5811 case clang::Type::ObjCObjectPointer:
5814 case clang::Type::ObjCObject:
5816 const clang::ObjCObjectType *objc_class_type =
5817 qual_type->getAsObjCQualifiedInterfaceType();
5818 if (objc_class_type) {
5819 clang::ObjCInterfaceDecl *class_interface_decl =
5820 objc_class_type->getInterface();
5822 if (class_interface_decl) {
5823 clang::ObjCInterfaceDecl *superclass_interface_decl =
5824 class_interface_decl->getSuperClass();
5825 if (superclass_interface_decl) {
5827 *bit_offset_ptr = 0;
5829 superclass_interface_decl));
5835 case clang::Type::ObjCInterface:
5837 const clang::ObjCObjectType *objc_interface_type =
5838 qual_type->getAs<clang::ObjCInterfaceType>();
5839 if (objc_interface_type) {
5840 clang::ObjCInterfaceDecl *class_interface_decl =
5841 objc_interface_type->getInterface();
5843 if (class_interface_decl) {
5844 clang::ObjCInterfaceDecl *superclass_interface_decl =
5845 class_interface_decl->getSuperClass();
5846 if (superclass_interface_decl) {
5848 *bit_offset_ptr = 0;
5850 superclass_interface_decl));
5866 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5867 switch (type_class) {
5868 case clang::Type::Record:
5870 const clang::CXXRecordDecl *cxx_record_decl =
5871 qual_type->getAsCXXRecordDecl();
5872 if (cxx_record_decl) {
5873 uint32_t curr_idx = 0;
5874 clang::CXXRecordDecl::base_class_const_iterator base_class,
5876 for (base_class = cxx_record_decl->vbases_begin(),
5877 base_class_end = cxx_record_decl->vbases_end();
5878 base_class != base_class_end; ++base_class, ++curr_idx) {
5879 if (curr_idx == idx) {
5880 if (bit_offset_ptr) {
5881 const clang::ASTRecordLayout &record_layout =
5883 const clang::CXXRecordDecl *base_class_decl =
5884 llvm::cast<clang::CXXRecordDecl>(
5885 base_class->getType()
5886 ->castAs<clang::RecordType>()
5889 record_layout.getVBaseClassOffset(base_class_decl)
5893 return GetType(base_class->getType());
5916 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5917 switch (type_class) {
5918 case clang::Type::Builtin:
5919 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5920 case clang::BuiltinType::UnknownAny:
5921 case clang::BuiltinType::Void:
5922 case clang::BuiltinType::NullPtr:
5923 case clang::BuiltinType::OCLEvent:
5924 case clang::BuiltinType::OCLImage1dRO:
5925 case clang::BuiltinType::OCLImage1dWO:
5926 case clang::BuiltinType::OCLImage1dRW:
5927 case clang::BuiltinType::OCLImage1dArrayRO:
5928 case clang::BuiltinType::OCLImage1dArrayWO:
5929 case clang::BuiltinType::OCLImage1dArrayRW:
5930 case clang::BuiltinType::OCLImage1dBufferRO:
5931 case clang::BuiltinType::OCLImage1dBufferWO:
5932 case clang::BuiltinType::OCLImage1dBufferRW:
5933 case clang::BuiltinType::OCLImage2dRO:
5934 case clang::BuiltinType::OCLImage2dWO:
5935 case clang::BuiltinType::OCLImage2dRW:
5936 case clang::BuiltinType::OCLImage2dArrayRO:
5937 case clang::BuiltinType::OCLImage2dArrayWO:
5938 case clang::BuiltinType::OCLImage2dArrayRW:
5939 case clang::BuiltinType::OCLImage3dRO:
5940 case clang::BuiltinType::OCLImage3dWO:
5941 case clang::BuiltinType::OCLImage3dRW:
5942 case clang::BuiltinType::OCLSampler:
5944 case clang::BuiltinType::Bool:
5945 case clang::BuiltinType::Char_U:
5946 case clang::BuiltinType::UChar:
5947 case clang::BuiltinType::WChar_U:
5948 case clang::BuiltinType::Char16:
5949 case clang::BuiltinType::Char32:
5950 case clang::BuiltinType::UShort:
5951 case clang::BuiltinType::UInt:
5952 case clang::BuiltinType::ULong:
5953 case clang::BuiltinType::ULongLong:
5954 case clang::BuiltinType::UInt128:
5955 case clang::BuiltinType::Char_S:
5956 case clang::BuiltinType::SChar:
5957 case clang::BuiltinType::WChar_S:
5958 case clang::BuiltinType::Short:
5959 case clang::BuiltinType::Int:
5960 case clang::BuiltinType::Long:
5961 case clang::BuiltinType::LongLong:
5962 case clang::BuiltinType::Int128:
5963 case clang::BuiltinType::Float:
5964 case clang::BuiltinType::Double:
5965 case clang::BuiltinType::LongDouble:
5966 case clang::BuiltinType::Dependent:
5967 case clang::BuiltinType::Overload:
5968 case clang::BuiltinType::ObjCId:
5969 case clang::BuiltinType::ObjCClass:
5970 case clang::BuiltinType::ObjCSel:
5971 case clang::BuiltinType::BoundMember:
5972 case clang::BuiltinType::Half:
5973 case clang::BuiltinType::ARCUnbridgedCast:
5974 case clang::BuiltinType::PseudoObject:
5975 case clang::BuiltinType::BuiltinFn:
5976 case clang::BuiltinType::OMPArraySection:
5983 case clang::Type::Complex:
5985 case clang::Type::Pointer:
5987 case clang::Type::BlockPointer:
5990 case clang::Type::LValueReference:
5992 case clang::Type::RValueReference:
5994 case clang::Type::MemberPointer:
5996 case clang::Type::ConstantArray:
5998 case clang::Type::IncompleteArray:
6000 case clang::Type::VariableArray:
6002 case clang::Type::DependentSizedArray:
6004 case clang::Type::DependentSizedExtVector:
6006 case clang::Type::Vector:
6008 case clang::Type::ExtVector:
6010 case clang::Type::FunctionProto:
6012 case clang::Type::FunctionNoProto:
6014 case clang::Type::UnresolvedUsing:
6016 case clang::Type::Record:
6018 case clang::Type::Enum:
6020 case clang::Type::TemplateTypeParm:
6022 case clang::Type::SubstTemplateTypeParm:
6024 case clang::Type::TemplateSpecialization:
6026 case clang::Type::InjectedClassName:
6028 case clang::Type::DependentName:
6030 case clang::Type::DependentTemplateSpecialization:
6032 case clang::Type::ObjCObject:
6034 case clang::Type::ObjCInterface:
6036 case clang::Type::ObjCObjectPointer:
6046 bool transparent_pointers,
bool omit_empty_base_classes,
6047 bool ignore_array_bounds, std::string &child_name,
6048 uint32_t &child_byte_size, int32_t &child_byte_offset,
6049 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6050 bool &child_is_base_class,
bool &child_is_deref_of_parent,
6055 auto get_exe_scope = [&exe_ctx]() {
6059 clang::QualType parent_qual_type(
6061 const clang::Type::TypeClass parent_type_class =
6062 parent_qual_type->getTypeClass();
6063 child_bitfield_bit_size = 0;
6064 child_bitfield_bit_offset = 0;
6065 child_is_base_class =
false;
6068 auto num_children_or_err =
6070 if (!num_children_or_err) {
6076 const bool idx_is_valid = idx < *num_children_or_err;
6078 switch (parent_type_class) {
6079 case clang::Type::Builtin:
6081 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) {
6082 case clang::BuiltinType::ObjCId:
6083 case clang::BuiltinType::ObjCClass:
6096 case clang::Type::Record:
6098 const clang::RecordType *record_type =
6099 llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6100 const clang::RecordDecl *record_decl = record_type->getDecl();
6101 assert(record_decl);
6102 const clang::ASTRecordLayout &record_layout =
6104 uint32_t child_idx = 0;
6106 const clang::CXXRecordDecl *cxx_record_decl =
6107 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6108 if (cxx_record_decl) {
6110 clang::CXXRecordDecl::base_class_const_iterator base_class,
6112 for (base_class = cxx_record_decl->bases_begin(),
6113 base_class_end = cxx_record_decl->bases_end();
6114 base_class != base_class_end; ++base_class) {
6115 const clang::CXXRecordDecl *base_class_decl =
nullptr;
6118 if (omit_empty_base_classes) {
6119 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6120 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6125 if (idx == child_idx) {
6126 if (base_class_decl ==
nullptr)
6127 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6128 base_class->getType()->getAs<clang::RecordType>()->getDecl());
6130 if (base_class->isVirtual()) {
6131 bool handled =
false;
6133 clang::VTableContextBase *vtable_ctx =
6137 record_layout, cxx_record_decl,
6138 base_class_decl, bit_offset);
6141 bit_offset = record_layout.getVBaseClassOffset(base_class_decl)
6145 bit_offset = record_layout.getBaseClassOffset(base_class_decl)
6150 child_byte_offset = bit_offset / 8;
6153 std::optional<uint64_t> size =
6154 base_class_clang_type.
GetBitSize(get_exe_scope());
6157 uint64_t base_class_clang_type_bit_size = *size;
6160 assert(base_class_clang_type_bit_size % 8 == 0);
6161 child_byte_size = base_class_clang_type_bit_size / 8;
6162 child_is_base_class =
true;
6163 return base_class_clang_type;
6171 uint32_t field_idx = 0;
6172 clang::RecordDecl::field_iterator field, field_end;
6173 for (field = record_decl->field_begin(),
6174 field_end = record_decl->field_end();
6175 field != field_end; ++field, ++field_idx, ++child_idx) {
6176 if (idx == child_idx) {
6179 child_name.assign(field->getNameAsString());
6184 assert(field_idx < record_layout.getFieldCount());
6185 std::optional<uint64_t> size =
6189 child_byte_size = *size;
6190 const uint32_t child_bit_size = child_byte_size * 8;
6194 bit_offset = record_layout.getFieldOffset(field_idx);
6196 child_bitfield_bit_offset = bit_offset % child_bit_size;
6197 const uint32_t child_bit_offset =
6198 bit_offset - child_bitfield_bit_offset;
6199 child_byte_offset = child_bit_offset / 8;
6201 child_byte_offset = bit_offset / 8;
6204 return field_clang_type;
6210 case clang::Type::ObjCObject:
6211 case clang::Type::ObjCInterface:
6213 const clang::ObjCObjectType *objc_class_type =
6214 llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6215 assert(objc_class_type);
6216 if (objc_class_type) {
6217 uint32_t child_idx = 0;
6218 clang::ObjCInterfaceDecl *class_interface_decl =
6219 objc_class_type->getInterface();
6221 if (class_interface_decl) {
6223 const clang::ASTRecordLayout &interface_layout =
6224 getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
6225 clang::ObjCInterfaceDecl *superclass_interface_decl =
6226 class_interface_decl->getSuperClass();
6227 if (superclass_interface_decl) {
6228 if (omit_empty_base_classes) {
6231 superclass_interface_decl));
6232 if (llvm::expectedToStdOptional(
6234 omit_empty_base_classes, exe_ctx))
6237 clang::QualType ivar_qual_type(
6239 superclass_interface_decl));
6242 superclass_interface_decl->getNameAsString());
6244 clang::TypeInfo ivar_type_info =
6247 child_byte_size = ivar_type_info.Width / 8;
6248 child_byte_offset = 0;
6249 child_is_base_class =
true;
6251 return GetType(ivar_qual_type);
6260 const uint32_t superclass_idx = child_idx;
6262 if (idx < (child_idx + class_interface_decl->ivar_size())) {
6263 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6264 ivar_end = class_interface_decl->ivar_end();
6266 for (ivar_pos = class_interface_decl->ivar_begin();
6267 ivar_pos != ivar_end; ++ivar_pos) {
6268 if (child_idx == idx) {
6269 clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6271 clang::QualType ivar_qual_type(ivar_decl->getType());
6273 child_name.assign(ivar_decl->getNameAsString());
6275 clang::TypeInfo ivar_type_info =
6278 child_byte_size = ivar_type_info.Width / 8;
6294 if (objc_runtime !=
nullptr) {
6297 parent_ast_type, ivar_decl->getNameAsString().c_str());
6305 if (child_byte_offset ==
6307 bit_offset = interface_layout.getFieldOffset(child_idx -
6309 child_byte_offset = bit_offset / 8;
6320 bit_offset = interface_layout.getFieldOffset(
6321 child_idx - superclass_idx);
6323 child_bitfield_bit_offset = bit_offset % 8;
6325 return GetType(ivar_qual_type);
6335 case clang::Type::ObjCObjectPointer:
6340 child_is_deref_of_parent =
false;
6341 bool tmp_child_is_deref_of_parent =
false;
6343 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6344 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6345 child_bitfield_bit_size, child_bitfield_bit_offset,
6346 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6349 child_is_deref_of_parent =
true;
6350 const char *parent_name =
6353 child_name.assign(1,
'*');
6354 child_name += parent_name;
6359 if (std::optional<uint64_t> size =
6360 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6361 child_byte_size = *size;
6362 child_byte_offset = 0;
6363 return pointee_clang_type;
6370 case clang::Type::Vector:
6371 case clang::Type::ExtVector:
6373 const clang::VectorType *array =
6374 llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6378 char element_name[64];
6379 ::snprintf(element_name,
sizeof(element_name),
"[%" PRIu64
"]",
6380 static_cast<uint64_t
>(idx));
6381 child_name.assign(element_name);
6382 if (std::optional<uint64_t> size =
6384 child_byte_size = *size;
6385 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6386 return element_type;
6393 case clang::Type::ConstantArray:
6394 case clang::Type::IncompleteArray:
6395 if (ignore_array_bounds || idx_is_valid) {
6396 const clang::ArrayType *array =
GetQualType(type)->getAsArrayTypeUnsafe();
6400 child_name = std::string(llvm::formatv(
"[{0}]", idx));
6401 if (std::optional<uint64_t> size =
6403 child_byte_size = *size;
6404 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6405 return element_type;
6412 case clang::Type::Pointer: {
6420 child_is_deref_of_parent =
false;
6421 bool tmp_child_is_deref_of_parent =
false;
6423 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6424 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6425 child_bitfield_bit_size, child_bitfield_bit_offset,
6426 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6429 child_is_deref_of_parent =
true;
6431 const char *parent_name =
6434 child_name.assign(1,
'*');
6435 child_name += parent_name;
6440 if (std::optional<uint64_t> size =
6441 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6442 child_byte_size = *size;
6443 child_byte_offset = 0;
6444 return pointee_clang_type;
6451 case clang::Type::LValueReference:
6452 case clang::Type::RValueReference:
6454 const clang::ReferenceType *reference_type =
6455 llvm::cast<clang::ReferenceType>(
6458 GetType(reference_type->getPointeeType());
6460 child_is_deref_of_parent =
false;
6461 bool tmp_child_is_deref_of_parent =
false;
6463 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6464 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6465 child_bitfield_bit_size, child_bitfield_bit_offset,
6466 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6469 const char *parent_name =
6472 child_name.assign(1,
'&');
6473 child_name += parent_name;
6478 if (std::optional<uint64_t> size =
6479 pointee_clang_type.
GetByteSize(get_exe_scope())) {
6480 child_byte_size = *size;
6481 child_byte_offset = 0;
6482 return pointee_clang_type;
6496 const clang::RecordDecl *record_decl,
6497 const clang::CXXBaseSpecifier *base_spec,
6498 bool omit_empty_base_classes) {
6499 uint32_t child_idx = 0;
6501 const clang::CXXRecordDecl *cxx_record_decl =
6502 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6504 if (cxx_record_decl) {
6505 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6506 for (base_class = cxx_record_decl->bases_begin(),
6507 base_class_end = cxx_record_decl->bases_end();
6508 base_class != base_class_end; ++base_class) {
6509 if (omit_empty_base_classes) {
6514 if (base_class == base_spec)
6524 const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl,
6525 bool omit_empty_base_classes) {
6527 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6528 omit_empty_base_classes);
6530 clang::RecordDecl::field_iterator field, field_end;
6531 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6532 field != field_end; ++field, ++child_idx) {
6533 if (field->getCanonicalDecl() == canonical_decl)
6575 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
6576 if (type && !name.empty()) {
6578 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6579 switch (type_class) {
6580 case clang::Type::Record:
6582 const clang::RecordType *record_type =
6583 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6584 const clang::RecordDecl *record_decl = record_type->getDecl();
6586 assert(record_decl);
6587 uint32_t child_idx = 0;
6589 const clang::CXXRecordDecl *cxx_record_decl =
6590 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6593 clang::RecordDecl::field_iterator field, field_end;
6594 for (field = record_decl->field_begin(),
6595 field_end = record_decl->field_end();
6596 field != field_end; ++field, ++child_idx) {
6597 llvm::StringRef field_name = field->getName();
6598 if (field_name.empty()) {
6600 child_indexes.push_back(child_idx);
6602 name, omit_empty_base_classes, child_indexes))
6603 return child_indexes.size();
6604 child_indexes.pop_back();
6606 }
else if (field_name.equals(name)) {
6608 child_indexes.push_back(
6610 cxx_record_decl, omit_empty_base_classes));
6611 return child_indexes.size();
6615 if (cxx_record_decl) {
6616 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6619 clang::IdentifierInfo &ident_ref =
getASTContext().Idents.get(name);
6620 clang::DeclarationName decl_name(&ident_ref);
6622 clang::CXXBasePaths paths;
6623 if (cxx_record_decl->lookupInBases(
6624 [decl_name](
const clang::CXXBaseSpecifier *specifier,
6625 clang::CXXBasePath &path) {
6626 CXXRecordDecl *record =
6627 specifier->getType()->getAsCXXRecordDecl();
6628 auto r = record->lookup(decl_name);
6629 path.Decls = r.begin();
6633 clang::CXXBasePaths::const_paths_iterator path,
6634 path_end = paths.end();
6635 for (path = paths.begin(); path != path_end; ++path) {
6636 const size_t num_path_elements = path->size();
6637 for (
size_t e = 0; e < num_path_elements; ++e) {
6638 clang::CXXBasePathElement elem = (*path)[e];
6641 omit_empty_base_classes);
6643 child_indexes.clear();
6646 child_indexes.push_back(child_idx);
6647 parent_record_decl = llvm::cast<clang::RecordDecl>(
6648 elem.Base->getType()
6649 ->castAs<clang::RecordType>()
6653 for (clang::DeclContext::lookup_iterator I = path->Decls, E;
6656 parent_record_decl, *I, omit_empty_base_classes);
6658 child_indexes.clear();
6661 child_indexes.push_back(child_idx);
6665 return child_indexes.size();
6671 case clang::Type::ObjCObject:
6672 case clang::Type::ObjCInterface:
6674 llvm::StringRef name_sref(name);
6675 const clang::ObjCObjectType *objc_class_type =
6676 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6677 assert(objc_class_type);
6678 if (objc_class_type) {
6679 uint32_t child_idx = 0;
6680 clang::ObjCInterfaceDecl *class_interface_decl =
6681 objc_class_type->getInterface();
6683 if (class_interface_decl) {
6684 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6685 ivar_end = class_interface_decl->ivar_end();
6686 clang::ObjCInterfaceDecl *superclass_interface_decl =
6687 class_interface_decl->getSuperClass();
6689 for (ivar_pos = class_interface_decl->ivar_begin();
6690 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6691 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6693 if (ivar_decl->getName().equals(name_sref)) {
6694 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6695 (omit_empty_base_classes &&
6699 child_indexes.push_back(child_idx);
6700 return child_indexes.size();
6704 if (superclass_interface_decl) {
6708 child_indexes.push_back(0);
6712 superclass_interface_decl));
6714 name, omit_empty_base_classes, child_indexes)) {
6717 return child_indexes.size();
6722 child_indexes.pop_back();
6729 case clang::Type::ObjCObjectPointer: {
6731 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6732 ->getPointeeType());
6734 name, omit_empty_base_classes, child_indexes);
6737 case clang::Type::ConstantArray: {
6777 case clang::Type::LValueReference:
6778 case clang::Type::RValueReference: {
6779 const clang::ReferenceType *reference_type =
6780 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6781 clang::QualType pointee_type(reference_type->getPointeeType());
6786 name, omit_empty_base_classes, child_indexes);
6790 case clang::Type::Pointer: {
6795 name, omit_empty_base_classes, child_indexes);
6812 llvm::StringRef name,
6813 bool omit_empty_base_classes) {
6814 if (type && !name.empty()) {
6817 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6819 switch (type_class) {
6820 case clang::Type::Record:
6822 const clang::RecordType *record_type =
6823 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6824 const clang::RecordDecl *record_decl = record_type->getDecl();
6826 assert(record_decl);
6827 uint32_t child_idx = 0;
6829 const clang::CXXRecordDecl *cxx_record_decl =
6830 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6832 if (cxx_record_decl) {
6833 clang::CXXRecordDecl::base_class_const_iterator base_class,
6835 for (base_class = cxx_record_decl->bases_begin(),
6836 base_class_end = cxx_record_decl->bases_end();
6837 base_class != base_class_end; ++base_class) {
6839 clang::CXXRecordDecl *base_class_decl =
6840 llvm::cast<clang::CXXRecordDecl>(
6841 base_class->getType()
6842 ->castAs<clang::RecordType>()
6844 if (omit_empty_base_classes &&
6849 std::string base_class_type_name(
6851 if (base_class_type_name == name)
6858 clang::RecordDecl::field_iterator field, field_end;
6859 for (field = record_decl->field_begin(),
6860 field_end = record_decl->field_end();
6861 field != field_end; ++field, ++child_idx) {
6862 if (field->getName().equals(name))
6868 case clang::Type::ObjCObject:
6869 case clang::Type::ObjCInterface:
6871 const clang::ObjCObjectType *objc_class_type =
6872 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6873 assert(objc_class_type);
6874 if (objc_class_type) {
6875 uint32_t child_idx = 0;
6876 clang::ObjCInterfaceDecl *class_interface_decl =
6877 objc_class_type->getInterface();
6879 if (class_interface_decl) {
6880 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6881 ivar_end = class_interface_decl->ivar_end();
6882 clang::ObjCInterfaceDecl *superclass_interface_decl =
6883 class_interface_decl->getSuperClass();
6885 for (ivar_pos = class_interface_decl->ivar_begin();
6886 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6887 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6889 if (ivar_decl->getName().equals(name)) {
6890 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6891 (omit_empty_base_classes &&
6899 if (superclass_interface_decl) {
6900 if (superclass_interface_decl->getName().equals(name))
6908 case clang::Type::ObjCObjectPointer: {
6910 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6911 ->getPointeeType());
6913 name, omit_empty_base_classes);
6916 case clang::Type::ConstantArray: {
6956 case clang::Type::LValueReference:
6957 case clang::Type::RValueReference: {
6958 const clang::ReferenceType *reference_type =
6959 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6964 omit_empty_base_classes);
6968 case clang::Type::Pointer: {
6969 const clang::PointerType *pointer_type =
6970 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
6975 omit_empty_base_classes);
7005 llvm::StringRef name) {
7006 if (!type || name.empty())
7010 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7012 switch (type_class) {
7013 case clang::Type::Record: {
7016 const clang::RecordType *record_type =
7017 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7018 const clang::RecordDecl *record_decl = record_type->getDecl();
7020 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7021 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
7022 if (
auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
7038 if (
auto *cxx_record_decl = dyn_cast<clang::TagType>(clang_type))
7039 return isa<clang::ClassTemplateSpecializationDecl>(
7040 cxx_record_decl->getDecl());
7051 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7052 switch (type_class) {
7053 case clang::Type::Record:
7055 const clang::CXXRecordDecl *cxx_record_decl =
7056 qual_type->getAsCXXRecordDecl();
7057 if (cxx_record_decl) {
7058 const clang::ClassTemplateSpecializationDecl *template_decl =
7059 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7061 if (template_decl) {
7062 const auto &template_arg_list = template_decl->getTemplateArgs();
7063 size_t num_args = template_arg_list.size();
7064 assert(num_args &&
"template specialization without any args");
7065 if (expand_pack && num_args) {
7066 const auto &pack = template_arg_list[num_args - 1];
7067 if (pack.getKind() == clang::TemplateArgument::Pack)
7068 num_args += pack.pack_size() - 1;
7083const clang::ClassTemplateSpecializationDecl *
7090 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7091 switch (type_class) {
7092 case clang::Type::Record: {
7095 const clang::CXXRecordDecl *cxx_record_decl =
7096 qual_type->getAsCXXRecordDecl();
7097 if (!cxx_record_decl)
7099 return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7108const TemplateArgument *
7110 size_t idx,
bool expand_pack) {
7111 const auto &args = decl->getTemplateArgs();
7112 const size_t args_size = args.size();
7114 assert(args_size &&
"template specialization without any args");
7118 const size_t last_idx = args_size - 1;
7127 if (!expand_pack || args[last_idx].getKind() != clang::TemplateArgument::Pack)
7128 return idx >= args.size() ? nullptr : &args[idx];
7133 const auto &pack = args[last_idx];
7134 const size_t pack_idx = idx - last_idx;
7135 if (pack_idx >= pack.pack_size())
7137 return &pack.pack_elements()[pack_idx];
7142 size_t arg_idx,
bool expand_pack) {
7143 const clang::ClassTemplateSpecializationDecl *template_decl =
7152 switch (arg->getKind()) {
7153 case clang::TemplateArgument::Null:
7156 case clang::TemplateArgument::NullPtr:
7159 case clang::TemplateArgument::Type:
7162 case clang::TemplateArgument::Declaration:
7165 case clang::TemplateArgument::Integral:
7168 case clang::TemplateArgument::Template:
7171 case clang::TemplateArgument::TemplateExpansion:
7174 case clang::TemplateArgument::Expression:
7177 case clang::TemplateArgument::Pack:
7180 case clang::TemplateArgument::StructuralValue:
7183 llvm_unreachable(
"Unhandled clang::TemplateArgument::ArgKind");
7188 size_t idx,
bool expand_pack) {
7189 const clang::ClassTemplateSpecializationDecl *template_decl =
7195 if (!arg || arg->getKind() != clang::TemplateArgument::Type)
7198 return GetType(arg->getAsType());
7201std::optional<CompilerType::IntegralTemplateArgument>
7203 size_t idx,
bool expand_pack) {
7204 const clang::ClassTemplateSpecializationDecl *template_decl =
7207 return std::nullopt;
7210 if (!arg || arg->getKind() != clang::TemplateArgument::Integral)
7211 return std::nullopt;
7213 return {{arg->getAsIntegral(),
GetType(arg->getIntegralType())}};
7223 const clang::EnumType *enutype =
7226 return enutype->getDecl();
7231 const clang::RecordType *record_type =
7234 return record_type->getDecl();
7242clang::TypedefNameDecl *
7244 const clang::TypedefType *typedef_type =
7247 return typedef_type->getDecl();
7251clang::CXXRecordDecl *
7256clang::ObjCInterfaceDecl *
7258 const clang::ObjCObjectType *objc_class_type =
7259 llvm::dyn_cast<clang::ObjCObjectType>(
7261 if (objc_class_type)
7262 return objc_class_type->getInterface();
7269 uint32_t bitfield_bit_size) {
7277 clang::IdentifierInfo *ident =
nullptr;
7279 ident = &clang_ast.Idents.get(name);
7281 clang::FieldDecl *field =
nullptr;
7283 clang::Expr *bit_width =
nullptr;
7284 if (bitfield_bit_size != 0) {
7285 llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
7287 bit_width =
new (clang_ast)
7288 clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
7289 clang_ast.IntTy, clang::SourceLocation());
7292 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7294 field = clang::FieldDecl::CreateDeserialized(clang_ast, 0);
7295 field->setDeclContext(record_decl);
7296 field->setDeclName(ident);
7299 field->setBitWidth(bit_width);
7305 if (
const clang::TagType *TagT =
7306 field->getType()->getAs<clang::TagType>()) {
7307 if (clang::RecordDecl *Rec =
7308 llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7309 if (!Rec->getDeclName()) {
7310 Rec->setAnonymousStructOrUnion(
true);
7311 field->setImplicit();
7317 clang::AccessSpecifier access_specifier =
7319 field->setAccess(access_specifier);
7321 if (clang::CXXRecordDecl *cxx_record_decl =
7322 llvm::dyn_cast<CXXRecordDecl>(record_decl)) {
7323 AddAccessSpecifierDecl(cxx_record_decl, ast->getASTContext(),
7324 ast->GetCXXRecordDeclAccess(cxx_record_decl),
7326 ast->SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
7328 record_decl->addDecl(field);
7333 clang::ObjCInterfaceDecl *class_interface_decl =
7334 ast->GetAsObjCInterfaceDecl(type);
7336 if (class_interface_decl) {
7337 const bool is_synthesized =
false;
7341 auto *ivar = clang::ObjCIvarDecl::CreateDeserialized(clang_ast, 0);
7342 ivar->setDeclContext(class_interface_decl);
7343 ivar->setDeclName(ident);
7347 ivar->setBitWidth(bit_width);
7348 ivar->setSynthesize(is_synthesized);
7353 class_interface_decl->addDecl(field);
7376 typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7378 IndirectFieldVector indirect_fields;
7379 clang::RecordDecl::field_iterator field_pos;
7380 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7381 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7382 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos;
7383 last_field_pos = field_pos++) {
7384 if (field_pos->isAnonymousStructOrUnion()) {
7385 clang::QualType field_qual_type = field_pos->getType();
7387 const clang::RecordType *field_record_type =
7388 field_qual_type->getAs<clang::RecordType>();
7390 if (!field_record_type)
7393 clang::RecordDecl *field_record_decl = field_record_type->getDecl();
7395 if (!field_record_decl)
7398 for (clang::RecordDecl::decl_iterator
7399 di = field_record_decl->decls_begin(),
7400 de = field_record_decl->decls_end();
7402 if (clang::FieldDecl *nested_field_decl =
7403 llvm::dyn_cast<clang::FieldDecl>(*di)) {
7404 clang::NamedDecl **chain =
7405 new (ast->getASTContext()) clang::NamedDecl *[2];
7406 chain[0] = *field_pos;
7407 chain[1] = nested_field_decl;
7408 clang::IndirectFieldDecl *indirect_field =
7409 clang::IndirectFieldDecl::Create(
7410 ast->getASTContext(), record_decl, clang::SourceLocation(),
7411 nested_field_decl->getIdentifier(),
7412 nested_field_decl->getType(), {chain, 2});
7415 indirect_field->setImplicit();
7418 field_pos->getAccess(), nested_field_decl->getAccess()));
7420 indirect_fields.push_back(indirect_field);
7421 }
else if (clang::IndirectFieldDecl *nested_indirect_field_decl =
7422 llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
7423 size_t nested_chain_size =
7424 nested_indirect_field_decl->getChainingSize();
7425 clang::NamedDecl **chain =
new (ast->getASTContext())
7426 clang::NamedDecl *[nested_chain_size + 1];
7427 chain[0] = *field_pos;
7429 int chain_index = 1;
7430 for (clang::IndirectFieldDecl::chain_iterator
7431 nci = nested_indirect_field_decl->chain_begin(),
7432 nce = nested_indirect_field_decl->chain_end();
7434 chain[chain_index] = *nci;
7438 clang::IndirectFieldDecl *indirect_field =
7439 clang::IndirectFieldDecl::Create(
7440 ast->getASTContext(), record_decl, clang::SourceLocation(),
7441 nested_indirect_field_decl->getIdentifier(),
7442 nested_indirect_field_decl->getType(),
7443 {chain, nested_chain_size + 1});
7446 indirect_field->setImplicit();
7449 field_pos->getAccess(), nested_indirect_field_decl->getAccess()));
7451 indirect_fields.push_back(indirect_field);
7459 if (last_field_pos != field_end_pos) {
7460 if (last_field_pos->getType()->isIncompleteArrayType())
7461 record_decl->hasFlexibleArrayMember();
7464 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(),
7465 ife = indirect_fields.end();
7467 record_decl->addDecl(*ifi);
7481 record_decl->addAttr(
7482 clang::PackedAttr::CreateImplicit(ast->getASTContext()));
7502 clang::VarDecl *var_decl =
nullptr;
7503 clang::IdentifierInfo *ident =
nullptr;
7505 ident = &ast->getASTContext().Idents.get(name);
7507 var_decl = clang::VarDecl::CreateDeserialized(ast->getASTContext(), 0);
7508 var_decl->setDeclContext(record_decl);
7509 var_decl->setDeclName(ident);
7511 var_decl->setStorageClass(clang::SC_Static);
7516 var_decl->setAccess(
7518 record_decl->addDecl(var_decl);
7520 VerifyDecl(var_decl);
7526 VarDecl *var,
const llvm::APInt &init_value) {
7527 assert(!var->hasInit() &&
"variable already initialized");
7529 clang::ASTContext &ast = var->getASTContext();
7530 QualType qt = var->getType();
7531 assert(qt->isIntegralOrEnumerationType() &&
7532 "only integer or enum types supported");
7535 if (
const EnumType *enum_type = qt->getAs<EnumType>()) {
7536 const EnumDecl *enum_decl = enum_type->getDecl();
7537 qt = enum_decl->getIntegerType();
7541 if (qt->isSpecificBuiltinType(BuiltinType::Bool)) {
7542 var->setInit(CXXBoolLiteralExpr::Create(
7543 ast, !init_value.isZero(), qt.getUnqualifiedType(), SourceLocation()));
7545 var->setInit(IntegerLiteral::Create(
7546 ast, init_value, qt.getUnqualifiedType(), SourceLocation()));
7551 clang::VarDecl *var,
const llvm::APFloat &init_value) {
7552 assert(!var->hasInit() &&
"variable already initialized");
7554 clang::ASTContext &ast = var->getASTContext();
7555 QualType qt = var->getType();
7556 assert(qt->isFloatingType() &&
"only floating point types supported");
7557 var->setInit(FloatingLiteral::Create(
7558 ast, init_value,
true, qt.getUnqualifiedType(), SourceLocation()));
7563 const char *mangled_name,
const CompilerType &method_clang_type,
7565 bool is_explicit,
bool is_attr_used,
bool is_artificial) {
7566 if (!type || !method_clang_type.
IsValid() || name.empty())
7571 clang::CXXRecordDecl *cxx_record_decl =
7572 record_qual_type->getAsCXXRecordDecl();
7574 if (cxx_record_decl ==
nullptr)
7579 clang::CXXMethodDecl *cxx_method_decl =
nullptr;
7581 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7583 const clang::FunctionType *function_type =
7584 llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7586 if (function_type ==
nullptr)
7589 const clang::FunctionProtoType *method_function_prototype(
7590 llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7592 if (!method_function_prototype)
7595 unsigned int num_params = method_function_prototype->getNumParams();
7597 clang::CXXDestructorDecl *cxx_dtor_decl(
nullptr);
7598 clang::CXXConstructorDecl *cxx_ctor_decl(
nullptr);
7603 const clang::ExplicitSpecifier explicit_spec(
7604 nullptr , is_explicit ? clang::ExplicitSpecKind::ResolvedTrue
7605 : clang::ExplicitSpecKind::ResolvedFalse);
7607 if (name.starts_with(
"~")) {
7609 clang::CXXDestructorDecl::CreateDeserialized(
getASTContext(), 0);
7610 cxx_dtor_decl->setDeclContext(cxx_record_decl);
7611 cxx_dtor_decl->setDeclName(
7614 cxx_dtor_decl->setType(method_qual_type);
7615 cxx_dtor_decl->setImplicit(is_artificial);
7616 cxx_dtor_decl->setInlineSpecified(is_inline);
7617 cxx_dtor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7618 cxx_method_decl = cxx_dtor_decl;
7619 }
else if (decl_name == cxx_record_decl->getDeclName()) {
7620 cxx_ctor_decl = clang::CXXConstructorDecl::CreateDeserialized(
7622 cxx_ctor_decl->setDeclContext(cxx_record_decl);
7623 cxx_ctor_decl->setDeclName(
7626 cxx_ctor_decl->setType(method_qual_type);
7627 cxx_ctor_decl->setImplicit(is_artificial);
7628 cxx_ctor_decl->setInlineSpecified(is_inline);
7629 cxx_ctor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7630 cxx_ctor_decl->setNumCtorInitializers(0);
7631 cxx_ctor_decl->setExplicitSpecifier(explicit_spec);
7632 cxx_method_decl = cxx_ctor_decl;
7634 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7635 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7638 if (op_kind != clang::NUM_OVERLOADED_OPERATORS) {
7643 const bool is_method =
true;
7645 is_method, op_kind, num_params))
7648 clang::CXXMethodDecl::CreateDeserialized(
getASTContext(), 0);
7649 cxx_method_decl->setDeclContext(cxx_record_decl);
7650 cxx_method_decl->setDeclName(
7651 getASTContext().DeclarationNames.getCXXOperatorName(op_kind));
7652 cxx_method_decl->setType(method_qual_type);
7653 cxx_method_decl->setStorageClass(SC);
7654 cxx_method_decl->setInlineSpecified(is_inline);
7655 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7656 }
else if (num_params == 0) {
7658 auto *cxx_conversion_decl =
7659 clang::CXXConversionDecl::CreateDeserialized(
getASTContext(), 0);
7660 cxx_conversion_decl->setDeclContext(cxx_record_decl);
7661 cxx_conversion_decl->setDeclName(
7662 getASTContext().DeclarationNames.getCXXConversionFunctionName(
7664 function_type->getReturnType())));
7665 cxx_conversion_decl->setType(method_qual_type);
7666 cxx_conversion_decl->setInlineSpecified(is_inline);
7667 cxx_conversion_decl->setExplicitSpecifier(explicit_spec);
7668 cxx_conversion_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7669 cxx_method_decl = cxx_conversion_decl;
7673 if (cxx_method_decl ==
nullptr) {
7675 clang::CXXMethodDecl::CreateDeserialized(
getASTContext(), 0);
7676 cxx_method_decl->setDeclContext(cxx_record_decl);
7677 cxx_method_decl->setDeclName(decl_name);
7678 cxx_method_decl->setType(method_qual_type);
7679 cxx_method_decl->setInlineSpecified(is_inline);
7680 cxx_method_decl->setStorageClass(SC);
7681 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7686 clang::AccessSpecifier access_specifier =
7689 cxx_method_decl->setAccess(access_specifier);
7690 cxx_method_decl->setVirtualAsWritten(is_virtual);
7693 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(
getASTContext()));
7695 if (mangled_name !=
nullptr) {
7696 cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7702 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
7704 for (
unsigned param_index = 0; param_index < num_params; ++param_index) {
7705 params.push_back(clang::ParmVarDecl::Create(
7707 clang::SourceLocation(),
7709 method_function_prototype->getParamType(param_index),
nullptr,
7710 clang::SC_None,
nullptr));
7713 cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params));
7720 cxx_record_decl->addDecl(cxx_method_decl);
7729 if (is_artificial) {
7730 if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() &&
7731 cxx_record_decl->hasTrivialDefaultConstructor()) ||
7732 (cxx_ctor_decl->isCopyConstructor() &&
7733 cxx_record_decl->hasTrivialCopyConstructor()) ||
7734 (cxx_ctor_decl->isMoveConstructor() &&
7735 cxx_record_decl->hasTrivialMoveConstructor()))) {
7736 cxx_ctor_decl->setDefaulted();
7737 cxx_ctor_decl->setTrivial(
true);
7738 }
else if (cxx_dtor_decl) {
7739 if (cxx_record_decl->hasTrivialDestructor()) {
7740 cxx_dtor_decl->setDefaulted();
7741 cxx_dtor_decl->setTrivial(
true);
7743 }
else if ((cxx_method_decl->isCopyAssignmentOperator() &&
7744 cxx_record_decl->hasTrivialCopyAssignment()) ||
7745 (cxx_method_decl->isMoveAssignmentOperator() &&
7746 cxx_record_decl->hasTrivialMoveAssignment())) {
7747 cxx_method_decl->setDefaulted();
7748 cxx_method_decl->setTrivial(
true);
7752 VerifyDecl(cxx_method_decl);
7754 return cxx_method_decl;
7760 for (
auto *method : record->methods())
7761 addOverridesForMethod(method);
7764#pragma mark C++ Base Classes
7766std::unique_ptr<clang::CXXBaseSpecifier>
7769 bool base_of_class) {
7773 return std::make_unique<clang::CXXBaseSpecifier>(
7774 clang::SourceRange(), is_virtual, base_of_class,
7777 clang::SourceLocation());
7782 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) {
7786 if (!cxx_record_decl)
7788 std::vector<clang::CXXBaseSpecifier *> raw_bases;
7789 raw_bases.reserve(bases.size());
7793 for (
auto &b : bases)
7794 raw_bases.push_back(b.get());
7795 cxx_record_decl->setBases(raw_bases.data(), raw_bases.size());
7807 if (type && superclass_clang_type.
IsValid() &&
7809 clang::ObjCInterfaceDecl *class_interface_decl =
7811 clang::ObjCInterfaceDecl *super_interface_decl =
7813 if (class_interface_decl && super_interface_decl) {
7814 class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
7815 clang_ast.getObjCInterfaceType(super_interface_decl)));
7824 const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl,
7825 const char *property_setter_name,
const char *property_getter_name,
7827 if (!type || !property_clang_type.
IsValid() || property_name ==
nullptr ||
7828 property_name[0] ==
'\0')
7837 if (!class_interface_decl)
7842 if (property_clang_type.
IsValid())
7843 property_clang_type_to_access = property_clang_type;
7845 property_clang_type_to_access = ast->GetType(ivar_decl->getType());
7847 if (!class_interface_decl || !property_clang_type_to_access.
IsValid())
7850 clang::TypeSourceInfo *prop_type_source;
7852 prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
7854 prop_type_source = clang_ast.getTrivialTypeSourceInfo(
7857 clang::ObjCPropertyDecl *property_decl =
7858 clang::ObjCPropertyDecl::CreateDeserialized(clang_ast, 0);
7859 property_decl->setDeclContext(class_interface_decl);
7860 property_decl->setDeclName(&clang_ast.Idents.get(property_name));
7861 property_decl->setType(ivar_decl
7862 ? ivar_decl->getType()
7871 ast->SetMetadata(property_decl, *metadata);
7873 class_interface_decl->addDecl(property_decl);
7875 clang::Selector setter_sel, getter_sel;
7877 if (property_setter_name) {
7878 std::string property_setter_no_colon(property_setter_name,
7879 strlen(property_setter_name) - 1);
7880 const clang::IdentifierInfo *setter_ident =
7881 &clang_ast.Idents.get(property_setter_no_colon);
7882 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
7883 }
else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
7884 std::string setter_sel_string(
"set");
7885 setter_sel_string.push_back(::toupper(property_name[0]));
7886 setter_sel_string.append(&property_name[1]);
7887 const clang::IdentifierInfo *setter_ident =
7888 &clang_ast.Idents.get(setter_sel_string);
7889 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
7891 property_decl->setSetterName(setter_sel);
7892 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
7894 if (property_getter_name !=
nullptr) {
7895 const clang::IdentifierInfo *getter_ident =
7896 &clang_ast.Idents.get(property_getter_name);
7897 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
7899 const clang::IdentifierInfo *getter_ident =
7900 &clang_ast.Idents.get(property_name);
7901 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
7903 property_decl->setGetterName(getter_sel);
7904 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
7907 property_decl->setPropertyIvarDecl(ivar_decl);
7909 if (property_attributes & DW_APPLE_PROPERTY_readonly)
7910 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
7911 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
7912 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
7913 if (property_attributes & DW_APPLE_PROPERTY_assign)
7914 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
7915 if (property_attributes & DW_APPLE_PROPERTY_retain)
7916 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
7917 if (property_attributes & DW_APPLE_PROPERTY_copy)
7918 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
7919 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
7920 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
7921 if (property_attributes & ObjCPropertyAttribute::kind_nullability)
7922 property_decl->setPropertyAttributes(
7923 ObjCPropertyAttribute::kind_nullability);
7924 if (property_attributes & ObjCPropertyAttribute::kind_null_resettable)
7925 property_decl->setPropertyAttributes(
7926 ObjCPropertyAttribute::kind_null_resettable);
7927 if (property_attributes & ObjCPropertyAttribute::kind_class)
7928 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
7930 const bool isInstance =
7931 (property_attributes & ObjCPropertyAttribute::kind_class) == 0;
7933 clang::ObjCMethodDecl *getter =
nullptr;
7934 if (!getter_sel.isNull())
7935 getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
7936 : class_interface_decl->lookupClassMethod(getter_sel);
7937 if (!getter_sel.isNull() && !getter) {
7938 const bool isVariadic =
false;
7939 const bool isPropertyAccessor =
true;
7940 const bool isSynthesizedAccessorStub =
false;
7941 const bool isImplicitlyDeclared =
true;
7942 const bool isDefined =
false;
7943 const clang::ObjCImplementationControl impControl =
7944 clang::ObjCImplementationControl::None;
7945 const bool HasRelatedResultType =
false;
7947 getter = clang::ObjCMethodDecl::CreateDeserialized(clang_ast, 0);
7948 getter->setDeclName(getter_sel);
7950 getter->setDeclContext(class_interface_decl);
7951 getter->setInstanceMethod(isInstance);
7952 getter->setVariadic(isVariadic);
7953 getter->setPropertyAccessor(isPropertyAccessor);
7954 getter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
7955 getter->setImplicit(isImplicitlyDeclared);
7956 getter->setDefined(isDefined);
7957 getter->setDeclImplementation(impControl);
7958 getter->setRelatedResultType(HasRelatedResultType);
7963 ast->SetMetadata(getter, *metadata);
7965 getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
7966 llvm::ArrayRef<clang::SourceLocation>());
7967 class_interface_decl->addDecl(getter);
7971 getter->setPropertyAccessor(
true);
7972 property_decl->setGetterMethodDecl(getter);
7975 clang::ObjCMethodDecl *setter =
nullptr;
7976 setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
7977 : class_interface_decl->lookupClassMethod(setter_sel);
7978 if (!setter_sel.isNull() && !setter) {
7979 clang::QualType result_type = clang_ast.VoidTy;
7980 const bool isVariadic =
false;
7981 const bool isPropertyAccessor =
true;
7982 const bool isSynthesizedAccessorStub =
false;
7983 const bool isImplicitlyDeclared =
true;
7984 const bool isDefined =
false;
7985 const clang::ObjCImplementationControl impControl =
7986 clang::ObjCImplementationControl::None;
7987 const bool HasRelatedResultType =
false;
7989 setter = clang::ObjCMethodDecl::CreateDeserialized(clang_ast, 0);
7990 setter->setDeclName(setter_sel);
7991 setter->setReturnType(result_type);
7992 setter->setDeclContext(class_interface_decl);
7993 setter->setInstanceMethod(isInstance);
7994 setter->setVariadic(isVariadic);
7995 setter->setPropertyAccessor(isPropertyAccessor);
7996 setter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
7997 setter->setImplicit(isImplicitlyDeclared);
7998 setter->setDefined(isDefined);
7999 setter->setDeclImplementation(impControl);
8000 setter->setRelatedResultType(HasRelatedResultType);
8005 ast->SetMetadata(setter, *metadata);
8007 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8008 params.push_back(clang::ParmVarDecl::Create(
8009 clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8012 clang::SC_Auto,
nullptr));
8014 setter->setMethodParams(clang_ast,
8015 llvm::ArrayRef<clang::ParmVarDecl *>(params),
8016 llvm::ArrayRef<clang::SourceLocation>());
8018 class_interface_decl->addDecl(setter);
8022 setter->setPropertyAccessor(
true);
8023 property_decl->setSetterMethodDecl(setter);
8030 bool check_superclass) {
8032 if (class_interface_decl)
8042 const CompilerType &method_clang_type,
bool is_artificial,
bool is_variadic,
8043 bool is_objc_direct_call) {
8044 if (!type || !method_clang_type.
IsValid())
8049 if (class_interface_decl ==
nullptr)
8053 if (lldb_ast ==
nullptr)
8057 const char *selector_start = ::strchr(name,
' ');
8058 if (selector_start ==
nullptr)
8062 llvm::SmallVector<const clang::IdentifierInfo *, 12> selector_idents;
8067 unsigned num_selectors_with_args = 0;
8068 for (start = selector_start; start && *start !=
'\0' && *start !=
']';
8070 len = ::strcspn(start,
":]");
8071 bool has_arg = (start[len] ==
':');
8073 ++num_selectors_with_args;
8074 selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
8079 if (selector_idents.size() == 0)
8082 clang::Selector method_selector = ast.Selectors.getSelector(
8083 num_selectors_with_args ? selector_idents.size() : 0,
8084 selector_idents.data());
8089 const clang::Type *method_type(method_qual_type.getTypePtr());
8091 if (method_type ==
nullptr)
8094 const clang::FunctionProtoType *method_function_prototype(
8095 llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8097 if (!method_function_prototype)
8100 const bool isInstance = (name[0] ==
'-');
8101 const bool isVariadic = is_variadic;
8102 const bool isPropertyAccessor =
false;
8103 const bool isSynthesizedAccessorStub =
false;
8105 const bool isImplicitlyDeclared =
true;
8106 const bool isDefined =
false;
8107 const clang::ObjCImplementationControl impControl =
8108 clang::ObjCImplementationControl::None;
8109 const bool HasRelatedResultType =
false;
8111 const unsigned num_args = method_function_prototype->getNumParams();
8113 if (num_args != num_selectors_with_args)
8117 auto *objc_method_decl = clang::ObjCMethodDecl::CreateDeserialized(ast, 0);
8118 objc_method_decl->setDeclName(method_selector);
8119 objc_method_decl->setReturnType(method_function_prototype->getReturnType());
8120 objc_method_decl->setDeclContext(
8122 objc_method_decl->setInstanceMethod(isInstance);
8123 objc_method_decl->setVariadic(isVariadic);
8124 objc_method_decl->setPropertyAccessor(isPropertyAccessor);
8125 objc_method_decl->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8126 objc_method_decl->setImplicit(isImplicitlyDeclared);
8127 objc_method_decl->setDefined(isDefined);
8128 objc_method_decl->setDeclImplementation(impControl);
8129 objc_method_decl->setRelatedResultType(HasRelatedResultType);
8132 if (objc_method_decl ==
nullptr)
8136 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8138 for (
unsigned param_index = 0; param_index < num_args; ++param_index) {
8139 params.push_back(clang::ParmVarDecl::Create(
8140 ast, objc_method_decl, clang::SourceLocation(),
8141 clang::SourceLocation(),
8143 method_function_prototype->getParamType(param_index),
nullptr,
8144 clang::SC_Auto,
nullptr));
8147 objc_method_decl->setMethodParams(
8148 ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
8149 llvm::ArrayRef<clang::SourceLocation>());
8152 if (is_objc_direct_call) {
8155 objc_method_decl->addAttr(
8156 clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
8161 objc_method_decl->createImplicitParams(ast, class_interface_decl);
8164 class_interface_decl->addDecl(objc_method_decl);
8166 VerifyDecl(objc_method_decl);
8168 return objc_method_decl;
8178 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8179 switch (type_class) {
8180 case clang::Type::Record: {
8181 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8182 if (cxx_record_decl) {
8183 cxx_record_decl->setHasExternalLexicalStorage(has_extern);
8184 cxx_record_decl->setHasExternalVisibleStorage(has_extern);
8189 case clang::Type::Enum: {
8190 clang::EnumDecl *enum_decl =
8191 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8193 enum_decl->setHasExternalLexicalStorage(has_extern);
8194 enum_decl->setHasExternalVisibleStorage(has_extern);
8199 case clang::Type::ObjCObject:
8200 case clang::Type::ObjCInterface: {
8201 const clang::ObjCObjectType *objc_class_type =
8202 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8203 assert(objc_class_type);
8204 if (objc_class_type) {
8205 clang::ObjCInterfaceDecl *class_interface_decl =
8206 objc_class_type->getInterface();
8208 if (class_interface_decl) {
8209 class_interface_decl->setHasExternalLexicalStorage(has_extern);
8210 class_interface_decl->setHasExternalVisibleStorage(has_extern);
8226 if (!qual_type.isNull()) {
8227 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8229 clang::TagDecl *tag_decl = tag_type->getDecl();
8231 tag_decl->startDefinition();
8236 const clang::ObjCObjectType *object_type =
8237 qual_type->getAs<clang::ObjCObjectType>();
8239 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8240 if (interface_decl) {
8241 interface_decl->startDefinition();
8252 if (qual_type.isNull())
8257 if (lldb_ast ==
nullptr)
8263 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8265 clang::TagDecl *tag_decl = tag_type->getDecl();
8267 if (
auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
8277 if (cxx_record_decl->hasUserDeclaredMoveConstructor() ||
8278 cxx_record_decl->hasUserDeclaredMoveAssignment()) {
8279 if (cxx_record_decl->needsImplicitCopyConstructor())
8280 cxx_record_decl->setImplicitCopyConstructorIsDeleted();
8281 if (cxx_record_decl->needsImplicitCopyAssignment())
8282 cxx_record_decl->setImplicitCopyAssignmentIsDeleted();
8285 if (!cxx_record_decl->isCompleteDefinition())
8286 cxx_record_decl->completeDefinition();
8287 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
8288 cxx_record_decl->setHasExternalLexicalStorage(
false);
8289 cxx_record_decl->setHasExternalVisibleStorage(
false);
8291 clang::AccessSpecifier::AS_none);
8296 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8300 clang::EnumDecl *enum_decl = enutype->getDecl();
8302 if (enum_decl->isCompleteDefinition())
8305 clang::ASTContext &ast = lldb_ast->getASTContext();
8309 QualType integer_type(enum_decl->getIntegerType());
8310 if (!integer_type.isNull()) {
8311 unsigned NumPositiveBits = 1;
8312 unsigned NumNegativeBits = 0;
8314 clang::QualType promotion_qual_type;
8317 if (ast.getTypeSize(enum_decl->getIntegerType()) <
8318 ast.getTypeSize(ast.IntTy)) {
8319 if (enum_decl->getIntegerType()->isSignedIntegerType())
8320 promotion_qual_type = ast.IntTy;
8322 promotion_qual_type = ast.UnsignedIntTy;
8324 promotion_qual_type = enum_decl->getIntegerType();
8326 enum_decl->completeDefinition(enum_decl->getIntegerType(),
8327 promotion_qual_type, NumPositiveBits,
8335 const llvm::APSInt &value) {
8346 if (!enum_opaque_compiler_type)
8349 clang::QualType enum_qual_type(
8352 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8357 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8362 clang::EnumConstantDecl *enumerator_decl =
8363 clang::EnumConstantDecl::CreateDeserialized(
getASTContext(), 0);
8364 enumerator_decl->setDeclContext(enutype->getDecl());
8365 if (name && name[0])
8366 enumerator_decl->setDeclName(&
getASTContext().Idents.get(name));
8367 enumerator_decl->setType(clang::QualType(enutype, 0));
8371 if (!enumerator_decl)
8374 enutype->getDecl()->addDecl(enumerator_decl);
8376 VerifyDecl(enumerator_decl);
8377 return enumerator_decl;
8382 int64_t enum_value, uint32_t enum_value_bit_size) {
8384 bool is_signed =
false;
8387 llvm::APSInt value(enum_value_bit_size, is_signed);
8395 const clang::Type *clang_type = qt.getTypePtrOrNull();
8396 const auto *enum_type = llvm::dyn_cast_or_null<clang::EnumType>(clang_type);
8400 return GetType(enum_type->getDecl()->getIntegerType());
8406 if (type && pointee_type.
IsValid() &&
8412 return ast->GetType(ast->getASTContext().getMemberPointerType(
8420#define DEPTH_INCREMENT 2
8423LLVM_DUMP_METHOD
void
8437 llvm::StringRef symbol_name) {
8444 symfile->
GetTypes(
nullptr, eTypeClassAny, type_list);
8445 size_t ntypes = type_list.
GetSize();
8447 for (
size_t i = 0; i < ntypes; ++i) {
8450 if (!symbol_name.empty())
8451 if (symbol_name != type->GetName().GetStringRef())
8454 s << type->GetName().AsCString() <<
"\n";
8457 if (clang::TagDecl *tag_decl =
GetAsTagDecl(full_type)) {
8465 if (
auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8467 if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8479 size_t byte_size, uint32_t bitfield_bit_offset,
8480 uint32_t bitfield_bit_size) {
8481 const clang::EnumType *enutype =
8482 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8483 const clang::EnumDecl *enum_decl = enutype->getDecl();
8487 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8488 bool can_be_bitfield =
true;
8489 uint64_t covered_bits = 0;
8490 int num_enumerators = 0;
8498 for (
auto *enumerator : enum_decl->enumerators()) {
8499 uint64_t val = enumerator->getInitVal().getSExtValue();
8500 val = llvm::SignExtend64(val, 8*byte_size);
8501 if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8502 can_be_bitfield =
false;
8503 covered_bits |= val;
8505 if (val == enum_svalue) {
8513 offset = byte_offset;
8515 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8519 if (!can_be_bitfield) {
8520 if (qual_type->isSignedIntegerOrEnumerationType())
8521 s.
Printf(
"%" PRIi64, enum_svalue);
8523 s.
Printf(
"%" PRIu64, enum_uvalue);
8527 uint64_t remaining_value = enum_uvalue;
8528 std::vector<std::pair<uint64_t, llvm::StringRef>> values;
8529 values.reserve(num_enumerators);
8530 for (
auto *enumerator : enum_decl->enumerators())
8531 if (
auto val = enumerator->getInitVal().getZExtValue())
8532 values.emplace_back(val, enumerator->getName());
8537 std::stable_sort(values.begin(), values.end(),
8538 [](
const auto &a,
const auto &b) {
8539 return llvm::popcount(a.first) > llvm::popcount(b.first);
8542 for (
const auto &val : values) {
8543 if ((remaining_value & val.first) != val.first)
8545 remaining_value &= ~val.first;
8547 if (remaining_value)
8552 if (remaining_value)
8553 s.
Printf(
"0x%" PRIx64, remaining_value);
8561 size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
8570 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8572 if (type_class == clang::Type::Elaborated) {
8573 qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
8574 return DumpTypeValue(qual_type.getAsOpaquePtr(), s, format, data, byte_offset, byte_size,
8575 bitfield_bit_size, bitfield_bit_offset, exe_scope);
8578 switch (type_class) {
8579 case clang::Type::Typedef: {
8580 clang::QualType typedef_qual_type =
8581 llvm::cast<clang::TypedefType>(qual_type)
8583 ->getUnderlyingType();
8586 format = typedef_clang_type.
GetFormat();
8587 clang::TypeInfo typedef_type_info =
8589 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
8599 bitfield_bit_offset,
8604 case clang::Type::Enum:
8609 return DumpEnumValue(qual_type, s, data, byte_offset, byte_size,
8610 bitfield_bit_offset, bitfield_bit_size);
8618 uint32_t item_count = 1;
8657 item_count = byte_size;
8662 item_count = byte_size / 2;
8667 item_count = byte_size / 4;
8673 bitfield_bit_size, bitfield_bit_offset,
8699 clang::QualType qual_type =
8702 llvm::SmallVector<char, 1024> buf;
8703 llvm::raw_svector_ostream llvm_ostrm(buf);
8705 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8706 switch (type_class) {
8707 case clang::Type::ObjCObject:
8708 case clang::Type::ObjCInterface: {
8711 auto *objc_class_type =
8712 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8713 assert(objc_class_type);
8714 if (!objc_class_type)
8716 clang::ObjCInterfaceDecl *class_interface_decl =
8717 objc_class_type->getInterface();
8718 if (!class_interface_decl)
8721 class_interface_decl->dump(llvm_ostrm);
8723 class_interface_decl->print(llvm_ostrm,
8728 case clang::Type::Typedef: {
8729 auto *typedef_type = qual_type->getAs<clang::TypedefType>();
8732 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8734 typedef_decl->dump(llvm_ostrm);
8737 if (!clang_typedef_name.empty()) {
8744 case clang::Type::Record: {
8747 auto *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8748 const clang::RecordDecl *record_decl = record_type->getDecl();
8750 record_decl->dump(llvm_ostrm);
8752 record_decl->print(llvm_ostrm,
getASTContext().getPrintingPolicy(),
8758 if (
auto *tag_type =
8759 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) {
8760 if (clang::TagDecl *tag_decl = tag_type->getDecl()) {
8762 tag_decl->dump(llvm_ostrm);
8764 tag_decl->print(llvm_ostrm, 0);
8770 std::string clang_type_name(qual_type.getAsString());
8771 if (!clang_type_name.empty())
8778 if (buf.size() > 0) {
8779 s.
Write(buf.data(), buf.size());
8786 clang::QualType qual_type(
8789 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8790 switch (type_class) {
8791 case clang::Type::Record: {
8792 const clang::CXXRecordDecl *cxx_record_decl =
8793 qual_type->getAsCXXRecordDecl();
8794 if (cxx_record_decl)
8795 printf(
"class %s", cxx_record_decl->getName().str().c_str());
8798 case clang::Type::Enum: {
8799 clang::EnumDecl *enum_decl =
8800 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8802 printf(
"enum %s", enum_decl->getName().str().c_str());
8806 case clang::Type::ObjCObject:
8807 case clang::Type::ObjCInterface: {
8808 const clang::ObjCObjectType *objc_class_type =
8809 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
8810 if (objc_class_type) {
8811 clang::ObjCInterfaceDecl *class_interface_decl =
8812 objc_class_type->getInterface();
8816 if (class_interface_decl)
8817 printf(
"@class %s", class_interface_decl->getName().str().c_str());
8821 case clang::Type::Typedef:
8822 printf(
"typedef %s", llvm::cast<clang::TypedefType>(qual_type)
8829 case clang::Type::Auto:
8832 llvm::cast<clang::AutoType>(qual_type)
8834 .getAsOpaquePtr()));
8836 case clang::Type::Elaborated:
8837 printf(
"elaborated ");
8839 type.
GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)
8841 .getAsOpaquePtr()));
8843 case clang::Type::Paren:
8847 llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
8850 printf(
"TypeSystemClang::DumpTypeName() type_class = %u", type_class);
8860 if (template_param_infos.
IsValid()) {
8861 std::string template_basename(parent_name);
8863 if (
auto i = template_basename.find(
'<'); i != std::string::npos)
8864 template_basename.erase(i);
8867 template_basename.c_str(), tag_decl_kind,
8868 template_param_infos);
8883 clang::ObjCInterfaceDecl *decl) {
8911 const clang::RecordDecl *record_decl, uint64_t &bit_size,
8912 uint64_t &alignment,
8913 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8914 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
8916 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
8929 field_offsets, base_offsets, vbase_offsets);
8936 clang::NamedDecl *nd =
8937 llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl);
8939 return ConstString(nd->getDeclName().getAsString());
8946 clang::NamedDecl *nd =
8947 llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl);
8948 if (nd !=
nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) {
8950 if (mc && mc->shouldMangleCXXName(nd)) {
8951 llvm::SmallVector<char, 1024> buf;
8952 llvm::raw_svector_ostream llvm_ostrm(buf);
8953 if (llvm::isa<clang::CXXConstructorDecl>(nd)) {
8955 clang::GlobalDecl(llvm::dyn_cast<clang::CXXConstructorDecl>(nd),
8958 }
else if (llvm::isa<clang::CXXDestructorDecl>(nd)) {
8960 clang::GlobalDecl(llvm::dyn_cast<clang::CXXDestructorDecl>(nd),
8964 mc->mangleName(nd, llvm_ostrm);
8981 if (clang::FunctionDecl *func_decl =
8982 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
8983 return GetType(func_decl->getReturnType());
8984 if (clang::ObjCMethodDecl *objc_method =
8985 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
8986 return GetType(objc_method->getReturnType());
8992 if (clang::FunctionDecl *func_decl =
8993 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
8994 return func_decl->param_size();
8995 if (clang::ObjCMethodDecl *objc_method =
8996 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
8997 return objc_method->param_size();
9003 clang::DeclContext
const *decl_ctx) {
9004 switch (clang_kind) {
9005 case Decl::TranslationUnit:
9007 case Decl::Namespace:
9018 if (decl_ctx->isFunctionOrMethod())
9020 else if (decl_ctx->isRecord())
9032 std::vector<lldb_private::CompilerContext> &context) {
9033 if (decl_ctx ==
nullptr)
9036 clang::Decl::Kind clang_kind = decl_ctx->getDeclKind();
9037 if (clang_kind == Decl::TranslationUnit)
9042 context.push_back({compiler_kind, decl_ctx_name});
9045std::vector<lldb_private::CompilerContext>
9047 std::vector<lldb_private::CompilerContext> context;
9050 clang::Decl *decl = (clang::Decl *)opaque_decl;
9052 clang::DeclContext *decl_ctx = decl->getDeclContext();
9055 auto compiler_kind =
9057 context.push_back({compiler_kind, decl_name});
9064 if (clang::FunctionDecl *func_decl =
9065 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) {
9066 if (idx < func_decl->param_size()) {
9067 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9069 return GetType(var_decl->getOriginalType());
9071 }
else if (clang::ObjCMethodDecl *objc_method =
9072 llvm::dyn_cast<clang::ObjCMethodDecl>(
9073 (clang::Decl *)opaque_decl)) {
9074 if (idx < objc_method->param_size())
9075 return GetType(objc_method->parameters()[idx]->getOriginalType());
9083 void *opaque_decl_ctx,
ConstString name,
const bool ignore_using_decls) {
9084 std::vector<CompilerDecl> found_decls;
9086 if (opaque_decl_ctx && symbol_file) {
9087 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9088 std::set<DeclContext *> searched;
9089 std::multimap<DeclContext *, DeclContext *> search_queue;
9091 for (clang::DeclContext *decl_context = root_decl_ctx;
9092 decl_context !=
nullptr && found_decls.empty();
9093 decl_context = decl_context->getParent()) {
9094 search_queue.insert(std::make_pair(decl_context, decl_context));
9096 for (
auto it = search_queue.find(decl_context); it != search_queue.end();
9098 if (!searched.insert(it->second).second)
9103 for (clang::Decl *child : it->second->decls()) {
9104 if (clang::UsingDirectiveDecl *ud =
9105 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9106 if (ignore_using_decls)
9108 clang::DeclContext *from = ud->getCommonAncestor();
9109 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9110 search_queue.insert(
9111 std::make_pair(from, ud->getNominatedNamespace()));
9112 }
else if (clang::UsingDecl *ud =
9113 llvm::dyn_cast<clang::UsingDecl>(child)) {
9114 if (ignore_using_decls)
9116 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9117 clang::Decl *target = usd->getTargetDecl();
9118 if (clang::NamedDecl *nd =
9119 llvm::dyn_cast<clang::NamedDecl>(target)) {
9120 IdentifierInfo *ii = nd->getIdentifier();
9121 if (ii !=
nullptr &&
9122 ii->getName().equals(name.
AsCString(
nullptr)))
9126 }
else if (clang::NamedDecl *nd =
9127 llvm::dyn_cast<clang::NamedDecl>(child)) {
9128 IdentifierInfo *ii = nd->getIdentifier();
9129 if (ii !=
nullptr && ii->getName().equals(name.
AsCString(
nullptr)))
9180 clang::DeclContext *child_decl_ctx,
9184 if (frame_decl_ctx && symbol_file) {
9185 std::set<DeclContext *> searched;
9186 std::multimap<DeclContext *, DeclContext *> search_queue;
9189 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9193 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx !=
nullptr;
9194 decl_ctx = decl_ctx->getParent()) {
9195 if (!decl_ctx->isLookupContext())
9197 if (decl_ctx == parent_decl_ctx)
9200 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9201 for (
auto it = search_queue.find(decl_ctx); it != search_queue.end();
9203 if (searched.find(it->second) != searched.end())
9211 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9214 searched.insert(it->second);
9218 for (clang::Decl *child : it->second->decls()) {
9219 if (clang::UsingDirectiveDecl *ud =
9220 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9221 clang::DeclContext *ns = ud->getNominatedNamespace();
9222 if (ns == parent_decl_ctx)
9225 clang::DeclContext *from = ud->getCommonAncestor();
9226 if (searched.find(ns) == searched.end())
9227 search_queue.insert(std::make_pair(from, ns));
9228 }
else if (child_name) {
9229 if (clang::UsingDecl *ud =
9230 llvm::dyn_cast<clang::UsingDecl>(child)) {
9231 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9232 clang::Decl *target = usd->getTargetDecl();
9233 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9237 IdentifierInfo *ii = nd->getIdentifier();
9238 if (ii ==
nullptr ||
9239 !ii->getName().equals(child_name->
AsCString(
nullptr)))
9262 if (opaque_decl_ctx) {
9263 clang::NamedDecl *named_decl =
9264 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9267 llvm::raw_string_ostream stream{name};
9269 policy.AlwaysIncludeTypeForTemplateArgument =
true;
9270 named_decl->getNameForDiagnostic(stream, policy,
false);
9279 if (opaque_decl_ctx) {
9280 clang::NamedDecl *named_decl =
9281 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9289 if (!opaque_decl_ctx)
9292 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9293 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9295 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9297 }
else if (clang::FunctionDecl *fun_decl =
9298 llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9300 return metadata->HasObjectPtr();
9306std::vector<lldb_private::CompilerContext>
9308 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9309 std::vector<lldb_private::CompilerContext> context;
9315 void *opaque_decl_ctx,
void *other_opaque_decl_ctx) {
9316 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9317 auto *other = (clang::DeclContext *)other_opaque_decl_ctx;
9321 if (decl_ctx == other)
9326 }
while (other->isInlineNamespace() && (other = other->getParent()));
9333 if (!opaque_decl_ctx)
9336 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9337 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9339 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9341 }
else if (
auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9343 return metadata->GetObjectPtrLanguage();
9363 return llvm::dyn_cast<clang::ObjCMethodDecl>(
9371 return llvm::dyn_cast<clang::CXXMethodDecl>(
9376clang::FunctionDecl *
9379 return llvm::dyn_cast<clang::FunctionDecl>(
9384clang::NamespaceDecl *
9387 return llvm::dyn_cast<clang::NamespaceDecl>(
9394 const Decl *
object) {
9402 llvm::dyn_cast_or_null<TypeSystemClang>(dc.
GetTypeSystem());
9424 lldbassert(started &&
"Unable to start a class type definition.");
9443 SpecializedScratchAST(llvm::StringRef name, llvm::Triple triple,
9444 std::unique_ptr<ClangASTSource> ast_source)
9446 m_scratch_ast_source_up(std::move(ast_source)) {
9448 m_scratch_ast_source_up->InstallASTContext(*
this);
9449 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9450 m_scratch_ast_source_up->CreateProxy());
9451 SetExternalSource(proxy_ast_source);
9455 std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
9463 llvm::Triple triple)
9465 m_target_wp(target.shared_from_this()),
9466 m_persistent_variables(
9470 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9482 std::optional<IsolatedASTKind> ast_kind,
9483 bool create_on_demand) {
9486 if (
auto err = type_system_or_err.takeError()) {
9488 "Couldn't get scratch TypeSystemClang");
9491 auto ts_sp = *type_system_or_err;
9493 llvm::dyn_cast_or_null<ScratchTypeSystemClang>(ts_sp.get());
9498 return std::static_pointer_cast<TypeSystemClang>(ts_sp);
9500 return std::static_pointer_cast<TypeSystemClang>(
9505static llvm::StringRef
9509 return "C++ modules";
9511 llvm_unreachable(
"Unimplemented IsolatedASTKind?");
9516 output <<
"State of scratch Clang type system:\n";
9520 typedef std::pair<IsolatedASTKey, TypeSystem *> KeyAndTS;
9521 std::vector<KeyAndTS> sorted_typesystems;
9523 sorted_typesystems.emplace_back(a.first, a.second.get());
9524 llvm::stable_sort(sorted_typesystems, llvm::less_first());
9527 for (
const auto &a : sorted_typesystems) {
9530 output <<
"State of scratch Clang type subsystem "
9532 a.second->Dump(output);
9545 desired_type, options, ctx_obj);
9550 const ValueList &arg_value_list,
const char *name) {
9555 Process *process = target_sp->GetProcessSP().get();
9560 arg_value_list, name);
9563std::unique_ptr<UtilityFunction>
9570 return std::make_unique<ClangUtilityFunction>(
9571 *target_sp.get(), std::move(text), std::move(name),
9572 target_sp->GetDebugUtilityExpression());
9586 importer.
ForgetSource(&a.second->getASTContext(), src_ctx);
9590 return std::make_unique<ClangASTSource>(
9595static llvm::StringRef
9599 return "scratch ASTContext for C++ module types";
9601 llvm_unreachable(
"Unimplemented ASTFeature kind?");
9608 return *found_ast->second;
9611 std::shared_ptr<TypeSystemClang> new_ast_sp =
9621 const clang::RecordType *record_type =
9622 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
9624 const clang::RecordDecl *record_decl = record_type->getDecl();
9625 assert(record_decl);
9638 if (metadata ==
nullptr)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERRORV(log, error,...)
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s, const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_offset, uint32_t bitfield_bit_size)
static lldb::opaque_compiler_type_t GetObjCFieldAtIndex(clang::ASTContext *ast, clang::ObjCInterfaceDecl *class_interface_decl, size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr)
static void ParseLangArgs(LangOptions &Opts, ArchSpec arch)
static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast, clang::QualType qual_type)
const TemplateArgument * GetNthTemplateArgument(const clang::ClassTemplateSpecializationDecl *decl, size_t idx, bool expand_pack)
static int64_t ReadVBaseOffsetFromVTable(Process &process, VTableContextBase &vtable_ctx, lldb::addr_t vtable_ptr, const CXXRecordDecl *cxx_record_decl, const CXXRecordDecl *base_class_decl)
lldb_private::ThreadSafeDenseMap< clang::ASTContext *, TypeSystemClang * > ClangASTMap
static bool IsClangDeclContext(const CompilerDeclContext &dc)
static bool TemplateParameterAllowsValue(NamedDecl *param, const TemplateArgument &value)
Returns true if the given template parameter can represent the given value.
static CompilerContextKind GetCompilerKind(clang::Decl::Kind clang_kind, clang::DeclContext const *decl_ctx)
static QualType RemoveWrappingTypes(QualType type, ArrayRef< clang::Type::TypeClass > mask={})
Aggressively desugar the provided type, skipping past various kinds of syntactic sugar and other cons...
static TemplateParameterList * CreateTemplateParameterList(ASTContext &ast, const TypeSystemClang::TemplateParameterInfos &template_param_infos, llvm::SmallVector< NamedDecl *, 8 > &template_param_decls)
clang::DeclContext * FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root)
static bool check_op_param(bool is_method, clang::OverloadedOperatorKind op_kind, bool unary, bool binary, uint32_t num_params)
static llvm::StringRef GetSpecializedASTName(ScratchTypeSystemClang::IsolatedASTKind feature)
static bool ObjCDeclHasIVars(clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass)
static lldb::addr_t GetVTableAddress(Process &process, VTableContextBase &vtable_ctx, ValueObject &valobj, const ASTRecordLayout &record_layout)
static clang::ObjCIvarDecl::AccessControl ConvertAccessTypeToObjCIvarAccessControl(AccessType access)
static std::optional< SymbolFile::ArrayInfo > GetDynamicArrayInfo(TypeSystemClang &ast, SymbolFile *sym_file, clang::QualType qual_type, const ExecutionContext *exe_ctx)
static llvm::StringRef GetNameForIsolatedASTKind(ScratchTypeSystemClang::IsolatedASTKind kind)
Returns a human-readable name that uniquely identifiers the sub-AST kind.
static void InsertCompilerContext(TypeSystemClang *ts, clang::DeclContext *decl_ctx, std::vector< lldb_private::CompilerContext > &context)
static bool GetVBaseBitOffset(VTableContextBase &vtable_ctx, ValueObject &valobj, const ASTRecordLayout &record_layout, const CXXRecordDecl *cxx_record_decl, const CXXRecordDecl *base_class_decl, int32_t &bit_offset)
static bool QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext &ast, QualType qual_type)
static ClangASTMap & GetASTMap()
static bool GetCompleteQualType(clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion=true)
static void SetMemberOwningModule(clang::Decl *member, const clang::Decl *parent)
static bool ClassTemplateAllowsToInstantiationArgs(ClassTemplateDecl *class_template_decl, const TypeSystemClang::TemplateParameterInfos &instantiation_values)
Returns true if the given class template declaration could produce an instantiation with the specifie...
#define LLDB_INVALID_DECL_LEVEL
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info) override
DiagnosticConsumer * clone(DiagnosticsEngine &Diags) const
A section + offset based address class.
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool CharIsSignedByDefault() const
Returns true if 'char' is a signed type by default in the architecture false otherwise.
Manages and observes all Clang AST node importing in LLDB.
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
"lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can be called.
"lldb/Expression/ClangPersistentVariables.h" Manages persistent values that need to be preserved betw...
"lldb/Expression/ClangUserExpression.h" Encapsulates a single expression for use with Clang
Represents a generic declaration context in a program.
TypeSystem * GetTypeSystem() const
void * GetOpaqueDeclContext() const
Represents a generic declaration such as a function declaration.
lldb::TypeSystemSP GetSharedPointer() const
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
void SetCompilerType(lldb::TypeSystemWP type_system, lldb::opaque_compiler_type_t type)
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
lldb::Encoding GetEncoding(uint64_t &count) const
size_t GetIndexOfChildMemberWithName(llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) const
Lookup a child member given a name.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
LLVM_DUMP_METHOD void dump() const
Dumping types.
uint32_t GetNumDirectBaseClasses() const
ConstString GetTypeName(bool BaseOnly=false) const
uint32_t GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
bool DumpTypeValue(Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope)
bool IsAggregateType() const
lldb::Format GetFormat() const
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
bool IsIntegerType(bool &is_signed) const
bool GetCompleteType() const
Type Completion.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
std::optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
A class that describes the declaration location of a lldb object.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
bool Test(ValueType bit) const
Test a single flag bit.
bool AnySet(ValueType mask) const
Test one or more flags.
Encapsulates a function that can be called.
static bool LanguageIsC(lldb::LanguageType language)
static bool LanguageIsCPlusPlus(lldb::LanguageType language)
static bool LanguageIsPascal(lldb::LanguageType language)
static bool LanguageIsObjC(lldb::LanguageType language)
A class that describes an executable image and its associated object and symbol files.
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
virtual size_t GetByteOffsetForIvar(CompilerType &parent_qual_type, const char *ivar_name)
bool GetTypeBitSize(const CompilerType &compiler_type, uint64_t &size) override
static ObjCLanguageRuntime * Get(Process &process)
unsigned GetValue() const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
uint32_t GetAddressByteSize() const
The TypeSystemClang instance used for the scratch ASTContext in a lldb::Target.
void Finalize() override
Free up any resources associated with this TypeSystem.
UserExpression * GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, Expression::ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj) override
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
llvm::Triple m_triple
The target triple.
std::unique_ptr< ClangASTSource > CreateASTSource()
lldb::TargetWP m_target_wp
TypeSystemClang & GetIsolatedAST(IsolatedASTKind feature)
Returns the requested sub-AST.
std::unique_ptr< ClangASTSource > m_scratch_ast_source_up
The ExternalASTSource that performs lookups and completes minimally imported types.
IsolatedASTKind
The different kinds of isolated ASTs within the scratch TypeSystem.
@ CppModules
The isolated AST for declarations/types from expressions that imported type information from a C++ mo...
std::unique_ptr< ClangPersistentVariables > m_persistent_variables
The persistent variables associated with this process for the expression parser.
static char ID
LLVM RTTI support.
PersistentExpressionState * GetPersistentExpressionState() override
FunctionCaller * GetFunctionCaller(const CompilerType &return_type, const Address &function_address, const ValueList &arg_value_list, const char *name) override
std::unique_ptr< UtilityFunction > CreateUtilityFunction(std::string text, std::string name) override
void ForgetSource(clang::ASTContext *src_ctx, ClangASTImporter &importer)
Unregisters the given ASTContext as a source from the scratch AST (and all sub-ASTs).
void Dump(llvm::raw_ostream &output) override
static const std::nullopt_t DefaultAST
Alias for requesting the default scratch TypeSystemClang in GetForTarget.
ScratchTypeSystemClang(Target &target, llvm::Triple triple)
llvm::DenseMap< IsolatedASTKey, std::shared_ptr< TypeSystemClang > > m_isolated_asts
Map from IsolatedASTKind to their actual TypeSystemClang instance.
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
Provides public interface for all SymbolFiles.
virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx)
virtual bool CompleteType(CompilerType &compiler_type)=0
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list)=0
virtual std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx)=0
If type_uid points to an array type, return its characteristics.
llvm::Expected< lldb::TypeSystemSP > GetScratchTypeSystemForLanguage(lldb::LanguageType language, bool create_on_demand=true)
const ArchSpec & GetArchitecture() const
void Insert(_KeyType k, _ValueType v)
_ValueType Lookup(_KeyType k)
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
The implementation of lldb::Type's m_payload field for TypeSystemClang.
void SetIsCompleteObjCClass(bool is_complete_objc_class)
bool IsCompleteObjCClass()
Type::Payload m_payload
The Layout is as follows:
TypePayloadClang()=default
void SetOwningModule(OptionalClangModuleID id)
static constexpr unsigned ObjCClassBit
llvm::ArrayRef< clang::TemplateArgument > GetParameterPackArgs() const
clang::TemplateArgument const & Front() const
llvm::StringRef GetPackName() const
bool hasParameterPack() const
TemplateParameterInfos const & GetParameterPack() const
llvm::ArrayRef< const char * > GetNames() const
llvm::ArrayRef< clang::TemplateArgument > GetArgs() const
A TypeSystem implementation based on Clang.
bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override
clang::TranslationUnitDecl * GetTranslationUnitDecl()
size_t GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) override
static clang::TypedefNameDecl * GetAsTypedefDecl(const CompilerType &type)
std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl, bool qualified=true)
Returns the internal type name for the given NamedDecl using the type printing policy.
static clang::ObjCInterfaceDecl * GetAsObjCInterfaceDecl(const CompilerType &type)
uint32_t m_pointer_byte_size
bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope) override
std::string m_display_name
A string describing what this TypeSystemClang represents (e.g., AST for debug information,...
void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data)
CompilerType GetChildCompilerTypeAtIndex(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) override
ConstString GetTypeName(lldb::opaque_compiler_type_t type, bool base_only) override
static void SetOwningModule(clang::Decl *decl, OptionalClangModuleID owning_module)
Set the owning module for decl.
std::unique_ptr< clang::TargetInfo > m_target_info_up
std::unique_ptr< clang::LangOptions > m_language_options_up
bool BaseSpecifierIsEmpty(const clang::CXXBaseSpecifier *b)
static uint32_t GetNumPointeeChildren(clang::QualType type)
ConstString DeclGetMangledName(void *opaque_decl) override
CompilerType GetBasicType(lldb::BasicType type)
clang::ClassTemplateDecl * CreateClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef class_name, int kind, const TemplateParameterInfos &infos)
void SetExternalSource(llvm::IntrusiveRefCntPtr< clang::ExternalASTSource > &ast_source_up)
clang::UsingDecl * CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, OptionalClangModuleID owning_module, clang::NamedDecl *target)
static clang::AccessSpecifier ConvertAccessTypeToAccessSpecifier(lldb::AccessType access)
CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override
std::optional< uint64_t > GetByteSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope)
bool IsForcefullyCompleted(lldb::opaque_compiler_type_t type) override
bool SupportsLanguage(lldb::LanguageType language) override
uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override
OptionalClangModuleID GetOrCreateClangModule(llvm::StringRef name, OptionalClangModuleID parent, bool is_framework=false, bool is_explicit=false)
Synthesize a clang::Module and return its ID or a default-constructed ID.
void CompleteTagDecl(clang::TagDecl *)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
std::shared_ptr< clang::TargetOptions > & getTargetOptions()
static TypeSystemClang * GetASTContext(clang::ASTContext *ast_ctx)
bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) override
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
const char * GetTargetTriple()
TypeSystemClang(llvm::StringRef name, llvm::Triple triple)
Constructs a TypeSystemClang with an ASTContext using the given triple.
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, Module *module, Target *target)
clang::TargetInfo * getTargetInfo()
clang::FunctionTemplateDecl * CreateFunctionTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos)
static bool AreTypesSame(CompilerType type1, CompilerType type2, bool ignore_qualifiers=false)
std::optional< uint64_t > GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
CompilerType GetArrayType(lldb::opaque_compiler_type_t type, uint64_t size) override
bool IsFunctionType(lldb::opaque_compiler_type_t type) override
CompilerType GetFunctionReturnType(lldb::opaque_compiler_type_t type) override
static bool IsObjCClassTypeAndHasIVars(const CompilerType &type, bool check_superclass)
CompilerType GetLValueReferenceType(lldb::opaque_compiler_type_t type) override
bool SetDeclIsForcefullyCompleted(const clang::TagDecl *td)
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override
bool CanPassInRegisters(const CompilerType &type) override
static clang::DeclContext * GetDeclContextForType(clang::QualType type)
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) override
bool IsEnumerationType(lldb::opaque_compiler_type_t type, bool &is_signed) override
bool IsTemplateType(lldb::opaque_compiler_type_t type) override
CompilerType GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
static bool IsCXXClassType(const CompilerType &type)
bool IsIntegerType(lldb::opaque_compiler_type_t type, bool &is_signed) override
void SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object, clang::AccessSpecifier access)
static bool AddObjCClassProperty(const CompilerType &type, const char *property_name, const CompilerType &property_compiler_type, clang::ObjCIvarDecl *ivar_decl, const char *property_setter_name, const char *property_getter_name, uint32_t property_attributes, ClangASTMetadata *metadata)
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override
static bool IsOperator(llvm::StringRef name, clang::OverloadedOperatorKind &op_kind)
bool IsCharType(lldb::opaque_compiler_type_t type) override
CompilerType CreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
static void SetFloatingInitializerForVariable(clang::VarDecl *var, const llvm::APFloat &init_value)
Initializes a variable with a floating point value.
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type) override
CompilerType GetType(clang::QualType qt)
Creates a CompilerType from the given QualType with the current TypeSystemClang instance as the Compi...
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override
std::string m_target_triple
bool TransferBaseClasses(lldb::opaque_compiler_type_t type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier > > bases)
bool IsBeingDefined(lldb::opaque_compiler_type_t type) override
ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override
std::unique_ptr< clang::IdentifierTable > m_identifier_table_up
static lldb::BasicType GetBasicTypeEnumeration(llvm::StringRef name)
static void SetIntegerInitializerForVariable(clang::VarDecl *var, const llvm::APInt &init_value)
Initializes a variable with an integer value.
bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override
CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) override
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override
std::unique_ptr< clang::SourceManager > m_source_manager_up
bool IsVoidType(lldb::opaque_compiler_type_t type) override
static void SetIsPacked(const CompilerType &type)
void ForEachEnumerator(lldb::opaque_compiler_type_t type, std::function< bool(const CompilerType &integer_type, ConstString name, const llvm::APSInt &value)> const &callback) override
clang::AccessSpecifier GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object)
CompilerType CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *class_template_specialization_decl)
bool IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) override
void CreateFunctionTemplateSpecializationInfo(clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template, const TemplateParameterInfos &infos)
bool IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length)
CompilerType GetRValueReferenceType(lldb::opaque_compiler_type_t type) override
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override
bool GetCompleteType(lldb::opaque_compiler_type_t type) override
bool IsBlockPointerType(lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) override
bool IsConst(lldb::opaque_compiler_type_t type) override
static clang::AccessSpecifier UnifyAccessSpecifiers(clang::AccessSpecifier lhs, clang::AccessSpecifier rhs)
std::unique_ptr< clang::CXXBaseSpecifier > CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, lldb::AccessType access, bool is_virtual, bool base_of_class)
CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override
std::vector< CompilerDecl > DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, const bool ignore_using_decls) override
void setSema(clang::Sema *s)
uint32_t GetPointerByteSize() override
bool IsCompleteType(lldb::opaque_compiler_type_t type) override
void Dump(llvm::raw_ostream &output) override
CompilerType GetIntTypeFromBitSize(size_t bit_size, bool is_signed)
clang::MangleContext * getMangleContext()
void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *)
std::string PrintTemplateParams(const TemplateParameterInfos &template_param_infos)
Return the template parameters (including surrounding <>) in string form.
static void DumpDeclContextHiearchy(clang::DeclContext *decl_ctx)
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
CompilerType GetTypeForFormatters(void *type) override
void SetMetadataAsUserID(const clang::Decl *decl, lldb::user_id_t user_id)
bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override
This is used by swift.
static LanguageSet GetSupportedLanguagesForExpressions()
CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override
CompilerDeclContext GetCompilerDeclContextForType(const CompilerType &type) override
Returns the direct parent context of specified type.
std::unique_ptr< clang::SelectorTable > m_selector_table_up
PDBASTParser * GetPDBParser() override
std::optional< CompilerType::IntegralTemplateArgument > GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
bool DeclContextIsClassMethod(void *opaque_decl_ctx) override
void SetTargetTriple(llvm::StringRef target_triple)
CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
static bool CheckOverloadedOperatorKindParameterCount(bool is_method, clang::OverloadedOperatorKind op_kind, uint32_t num_params)
clang::DeclarationName GetDeclarationName(llvm::StringRef name, const CompilerType &function_clang_type)
DeclMetadataMap m_decl_metadata
Maps Decls to their associated ClangASTMetadata.
static clang::CXXMethodDecl * DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc)
CompilerType GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override
uint32_t CountDeclLevels(clang::DeclContext *frame_decl_ctx, clang::DeclContext *child_decl_ctx, ConstString *child_name=nullptr, CompilerType *child_type=nullptr)
static clang::QualType GetQualType(lldb::opaque_compiler_type_t type)
clang::PrintingPolicy GetTypePrintingPolicy()
Returns the PrintingPolicy used when generating the internal type names.
uint32_t GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override
static clang::RecordDecl * GetAsRecordDecl(const CompilerType &type)
CompilerType GetPointerSizedIntType(bool is_signed)
clang::FunctionDecl * CreateFunctionDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, const CompilerType &function_Type, clang::StorageClass storage, bool is_inline)
uint32_t GetNumBaseClasses(const clang::CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes)
lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) override
std::unique_ptr< DWARFASTParserClang > m_dwarf_ast_parser_up
CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size)
bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override
int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override
static void BuildIndirectFields(const CompilerType &type)
std::unique_ptr< clang::FileManager > m_file_manager_up
uint32_t GetIndexForRecordBase(const clang::RecordDecl *record_decl, const clang::CXXBaseSpecifier *base_spec, bool omit_empty_base_classes)
bool IsAnonymousType(lldb::opaque_compiler_type_t type) override
bool Verify(lldb::opaque_compiler_type_t type) override
Verify the integrity of the type to catch CompilerTypes that mix and match invalid TypeSystem/Opaque ...
size_t GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override
void AddMethodOverridesForCXXRecordType(lldb::opaque_compiler_type_t type)
CompilerType CreateBlockPointerType(const CompilerType &function_type)
lldb::LanguageType GetMinimumLanguage(lldb::opaque_compiler_type_t type) override
bool FieldIsBitfield(clang::FieldDecl *field, uint32_t &bitfield_bit_size)
clang::ClassTemplateSpecializationDecl * CreateClassTemplateSpecializationDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::ClassTemplateDecl *class_template_decl, int kind, const TemplateParameterInfos &infos)
std::unique_ptr< clang::HeaderSearch > m_header_search_up
void Finalize() override
Free up any resources associated with this TypeSystem.
clang::CXXMethodDecl * AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, llvm::StringRef name, const char *mangled_name, const CompilerType &method_type, lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, bool is_explicit, bool is_attr_used, bool is_artificial)
static clang::ASTContext * DeclContextGetTypeSystemClang(const CompilerDeclContext &dc)
uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, CompilerType *base_type_ptr) override
clang::EnumConstantDecl * AddEnumerationValueToEnumerationType(const CompilerType &enum_type, const Declaration &decl, const char *name, int64_t enum_value, uint32_t enum_value_bit_size)
LLVM_DUMP_METHOD void dump(lldb::opaque_compiler_type_t type) const override
Convenience LLVM-style dump method for use in the debugger only.
CXXRecordDeclAccessMap m_cxx_record_decl_access
Maps CXXRecordDecl to their most recent added method/field's AccessSpecifier.
clang::NamespaceDecl * GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool is_inline=false)
std::unique_ptr< clang::ASTContext > m_ast_up
CompilerType CreateGenericFunctionPrototype() override
static clang::QualType GetCanonicalQualType(lldb::opaque_compiler_type_t type)
CompilerType DeclGetFunctionReturnType(void *opaque_decl) override
static bool IsEnumType(lldb::opaque_compiler_type_t type)
std::unique_ptr< npdb::PdbAstBuilder > m_native_pdb_ast_parser_up
static clang::CXXRecordDecl * GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type)
CompilerType GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name) override
static bool SetObjCSuperClass(const CompilerType &type, const CompilerType &superclass_compiler_type)
clang::UsingDirectiveDecl * CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::NamespaceDecl *ns_decl)
static lldb::opaque_compiler_type_t GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type)
bool IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) override
void DumpFromSymbolFile(Stream &s, llvm::StringRef symbol_name)
Dump clang AST types from the symbol file.
CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override
static void DumpDeclHiearchy(clang::Decl *decl)
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
static clang::FunctionDecl * DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc)
bool IsScalarType(lldb::opaque_compiler_type_t type) override
std::shared_ptr< clang::TargetOptions > m_target_options_rp
lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override
static bool IsClassType(lldb::opaque_compiler_type_t type)
bool IsDefined(lldb::opaque_compiler_type_t type) override
static bool IsObjCClassType(const CompilerType &type)
TypeMetadataMap m_type_metadata
Maps Types to their associated ClangASTMetadata.
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
const llvm::fltSemantics & GetFloatTypeSemantics(size_t byte_size) override
CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override
bool RecordHasFields(const clang::RecordDecl *record_decl)
CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index) override
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override
static clang::ObjCMethodDecl * AddMethodToObjCObjectType(const CompilerType &type, const char *name, const CompilerType &method_compiler_type, bool is_artificial, bool is_variadic, bool is_objc_direct_call)
~TypeSystemClang() override
CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override
bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, void *other_opaque_decl_ctx) override
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
CompilerType CreateEnumerationType(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const Declaration &decl, const CompilerType &integer_qual_type, bool is_scoped)
clang::ParmVarDecl * CreateParameterDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const char *name, const CompilerType ¶m_type, int storage, bool add_decl=false)
void DumpTypeDescription(lldb::opaque_compiler_type_t type, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) override
Dump the type to stdout.
CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, size_t idx) override
static clang::NamespaceDecl * DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc)
npdb::PdbAstBuilder * GetNativePDBParser() override
std::unique_ptr< clang::DiagnosticConsumer > m_diagnostic_consumer_up
CompilerType CreateArrayType(const CompilerType &element_type, size_t element_count, bool is_vector)
CompilerType GetTypeForDecl(clang::NamedDecl *decl)
CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
ClangASTMetadata * GetMetadata(const clang::Decl *object)
CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
static clang::DeclContext * DeclContextGetAsDeclContext(const CompilerDeclContext &dc)
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, uint64_t &count) override
bool IsTypedefType(lldb::opaque_compiler_type_t type) override
CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override
std::optional< size_t > GetTypeBitAlign(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
std::unique_ptr< clang::Builtin::Context > m_builtins_up
CompilerType GetBuiltinTypeByName(ConstString name) override
bool GetCompleteDecl(clang::Decl *decl)
static bool StartTagDeclarationDefinition(const CompilerType &type)
uint32_t GetIndexForRecordChild(const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl, bool omit_empty_base_classes)
bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, CompilerType *target_type, bool check_cplusplus, bool check_objc) override
static ClangASTMetadata * DeclContextGetMetaData(const CompilerDeclContext &dc, const clang::Decl *object)
CompilerType GetOrCreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
static llvm::StringRef GetPluginNameStatic()
clang::Sema * m_sema
The sema associated that is currently used to build this ASTContext.
size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override
static clang::VarDecl * AddVariableToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &var_type, lldb::AccessType access)
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override
const clang::ClassTemplateSpecializationDecl * GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type)
std::unique_ptr< clang::MangleContext > m_mangle_ctx_up
TypeMemberFunctionImpl GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) override
bool IsTypeImpl(lldb::opaque_compiler_type_t type, llvm::function_ref< bool(clang::QualType)> predicate) const
size_t DeclGetFunctionNumArguments(void *opaque_decl) override
CompilerType CreateFunctionType(const CompilerType &result_type, const CompilerType *args, unsigned num_args, bool is_variadic, unsigned type_quals, clang::CallingConv cc=clang::CC_C, clang::RefQualifierKind ref_qual=clang::RQ_None)
CompilerType GetAtomicType(lldb::opaque_compiler_type_t type) override
std::unique_ptr< PDBASTParser > m_pdb_ast_parser_up
std::unique_ptr< clang::DiagnosticsEngine > m_diagnostics_engine_up
static std::optional< std::string > GetCXXClassName(const CompilerType &type)
static void DumpTypeName(const CompilerType &type)
plugin::dwarf::DWARFASTParser * GetDWARFParser() override
CompilerType DeclGetFunctionArgumentType(void *opaque_decl, size_t arg_idx) override
bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) override
static clang::EnumDecl * GetAsEnumDecl(const CompilerType &type)
CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override
std::unique_ptr< clang::ModuleMap > m_module_map_up
CompilerType CreateObjCClass(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool isForwardDecl, bool isInternal, ClangASTMetadata *metadata=nullptr)
void SetFunctionParameters(clang::FunctionDecl *function_decl, llvm::ArrayRef< clang::ParmVarDecl * > params)
static bool IsObjCObjectOrInterfaceType(const CompilerType &type)
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, ClangASTMetadata *metadata=nullptr, bool exports_symbols=false)
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx, uint32_t opaque_payload) override
Using the current type, create a new typedef to that type using "typedef_name" as the name and "decl_...
llvm::Expected< uint32_t > GetNumChildren(lldb::opaque_compiler_type_t type, bool omit_empty_base_classes, const ExecutionContext *exe_ctx) override
CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override
clang::TemplateTemplateParmDecl * CreateTemplateTemplateParmDecl(const char *template_name)
lldb::TemplateArgumentKind GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
clang::ClassTemplateDecl * ParseClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, const char *parent_name, int tag_decl_kind, const TypeSystemClang::TemplateParameterInfos &template_param_infos)
std::vector< lldb_private::CompilerContext > DeclGetCompilerContext(void *opaque_decl) override
static CompilerType CreateMemberPointerType(const CompilerType &type, const CompilerType &pointee_type)
std::vector< lldb_private::CompilerContext > DeclContextGetCompilerContext(void *opaque_decl_ctx) override
void CreateASTContext()
Creates the internal ASTContext.
CompilerType GetCStringType(bool is_const)
bool IsAggregateType(lldb::opaque_compiler_type_t type) override
uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes) override
static bool IsObjCObjectPointerType(const CompilerType &type, CompilerType *target_type=nullptr)
bool IsVectorType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size) override
static LanguageSet GetSupportedLanguagesForTypes()
clang::VarDecl * CreateVariableDeclaration(clang::DeclContext *decl_context, OptionalClangModuleID owning_module, const char *name, clang::QualType type)
clang::BlockDecl * CreateBlockDeclaration(clang::DeclContext *ctx, OptionalClangModuleID owning_module)
ConstString DeclContextGetName(void *opaque_decl_ctx) override
size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type, bool expand_pack) override
ConstString DeclGetName(void *opaque_decl) override
Interface for representing a type system.
virtual SymbolFile * GetSymbolFile() const
bool m_has_forcefully_completed_types
Used for reporting statistics.
Encapsulates a one-time expression for use in lldb.
virtual uint64_t GetData(DataExtractor &data, Status &error)
CompilerType GetCompilerType()
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
AddressType GetAddressTypeOfChildren()
ConstString GetName() const
const ExecutionContextRef & GetExecutionContextRef() const
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_IVAR_OFFSET
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
lldb::offset_t DumpDataExtractor(const DataExtractor &DE, Stream *s, lldb::offset_t offset, lldb::Format item_format, size_t item_byte_size, size_t item_count, size_t num_per_line, uint64_t base_addr, uint32_t item_bit_size, uint32_t item_bit_offset, ExecutionContextScope *exe_scope=nullptr, bool show_memory_tags=false)
Dumps item_count objects into the stream s.
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
void * opaque_compiler_type_t
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedShort
@ eBasicTypeUnsignedInt128
@ eBasicTypeUnsignedWChar
@ eBasicTypeLongDoubleComplex
@ eBasicTypeUnsignedLongLong
@ eBasicTypeDoubleComplex
Format
Display format definitions.
@ eFormatCString
NULL terminated C strings.
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
@ eFormatVoid
Do not print this.
@ eFormatComplex
Floating point complex type.
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
LanguageType
Programming language type.
@ eLanguageTypeC_plus_plus_20
ISO C++:2020.
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
@ eLanguageTypeC11
ISO C:2011.
@ eLanguageTypeC99
ISO C:1999.
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeC_plus_plus_17
ISO C++:2017.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
@ eLanguageTypeC89
ISO C:1989.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
@ eLanguageTypeDylan
Dylan.
std::shared_ptr< lldb_private::Type > TypeSP
@ eTemplateArgumentKindTemplate
@ eTemplateArgumentKindTemplateExpansion
@ eTemplateArgumentKindNull
@ eTemplateArgumentKindNullPtr
@ eTemplateArgumentKindDeclaration
@ eTemplateArgumentKindIntegral
@ eTemplateArgumentKindPack
@ eTemplateArgumentKindType
@ eTemplateArgumentKindStructuralValue
@ eTemplateArgumentKindExpression
Encoding
Register encoding definitions.
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
MemberFunctionKind
Kind of member function.
@ eMemberFunctionKindInstanceMethod
A function that applies to a specific instance.
@ eMemberFunctionKindConstructor
A function used to create instances.
@ eMemberFunctionKindUnknown
Not sure what the type of this is.
@ eMemberFunctionKindDestructor
A function used to tear down existing instances.
@ eMemberFunctionKindStaticMethod
A function that applies to a type rather than any instance.
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::Target > TargetSP
static clang::QualType GetQualType(const CompilerType &ct)
static clang::QualType GetCanonicalQualType(const CompilerType &ct)
static bool IsClangType(const CompilerType &ct)
static CompilerType RemoveFastQualifiers(const CompilerType &ct)
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
void Insert(lldb::LanguageType language)