11#include "clang/AST/DeclBase.h"
12#include "clang/AST/ExprCXX.h"
13#include "clang/Frontend/ASTConsumers.h"
14#include "llvm/ADT/ScopeExit.h"
15#include "llvm/Support/Casting.h"
16#include "llvm/Support/ErrorExtras.h"
17#include "llvm/Support/FormatAdapters.h"
18#include "llvm/Support/FormatVariadic.h"
25#include "clang/AST/ASTContext.h"
26#include "clang/AST/ASTImporter.h"
27#include "clang/AST/Attr.h"
28#include "clang/AST/CXXInheritance.h"
29#include "clang/AST/DeclObjC.h"
30#include "clang/AST/DeclTemplate.h"
31#include "clang/AST/Mangle.h"
32#include "clang/AST/QualTypeNames.h"
33#include "clang/AST/RecordLayout.h"
34#include "clang/AST/Type.h"
35#include "clang/AST/VTableBuilder.h"
36#include "clang/Basic/Builtins.h"
37#include "clang/Basic/Diagnostic.h"
38#include "clang/Basic/FileManager.h"
39#include "clang/Basic/FileSystemOptions.h"
40#include "clang/Basic/LangStandard.h"
41#include "clang/Basic/SourceManager.h"
42#include "clang/Basic/TargetInfo.h"
43#include "clang/Basic/TargetOptions.h"
44#include "clang/Frontend/FrontendOptions.h"
45#include "clang/Lex/HeaderSearch.h"
46#include "clang/Lex/HeaderSearchOptions.h"
47#include "clang/Lex/ModuleMap.h"
48#include "clang/Sema/Sema.h"
50#include "llvm/Support/Signals.h"
51#include "llvm/Support/Threading.h"
95using namespace llvm::dwarf;
97using llvm::StringSwitch;
102static void VerifyDecl(clang::Decl *decl) {
103 assert(decl &&
"VerifyDecl called with nullptr?");
129bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) {
131 lldbassert(&m1->getASTContext() == &m2->getASTContext() &&
132 "Methods should have the same AST context");
133 clang::ASTContext &context = m1->getASTContext();
135 const auto *m1Type = llvm::cast<clang::FunctionProtoType>(
136 context.getCanonicalType(m1->getType()));
138 const auto *m2Type = llvm::cast<clang::FunctionProtoType>(
139 context.getCanonicalType(m2->getType()));
141 auto compareArgTypes = [&context](
const clang::QualType &m1p,
142 const clang::QualType &m2p) {
143 return context.hasSameType(m1p.getUnqualifiedType(),
144 m2p.getUnqualifiedType());
149 return (m1->getNumParams() != m2->getNumParams()) ||
150 !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(),
151 m2Type->param_type_begin(), compareArgTypes);
157void addOverridesForMethod(clang::CXXMethodDecl *decl) {
158 if (!decl->isVirtual())
161 clang::CXXBasePaths paths;
162 llvm::SmallVector<clang::NamedDecl *, 4> decls;
164 auto find_overridden_methods =
165 [&decls, decl](
const clang::CXXBaseSpecifier *specifier,
166 clang::CXXBasePath &path) {
167 if (
auto *base_record = specifier->getType()->getAsCXXRecordDecl()) {
169 clang::DeclarationName name = decl->getDeclName();
173 if (name.getNameKind() == clang::DeclarationName::CXXDestructorName)
174 if (
auto *baseDtorDecl = base_record->getDestructor()) {
175 if (baseDtorDecl->isVirtual()) {
176 decls.push_back(baseDtorDecl);
183 for (path.Decls = base_record->lookup(name).begin();
184 path.Decls != path.Decls.end(); ++path.Decls) {
185 if (
auto *method_decl =
186 llvm::dyn_cast<clang::CXXMethodDecl>(*path.Decls))
187 if (method_decl->isVirtual() && !isOverload(decl, method_decl)) {
188 decls.push_back(method_decl);
197 if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) {
198 for (
auto *overridden_decl : decls)
199 decl->addOverriddenMethod(
200 llvm::cast<clang::CXXMethodDecl>(overridden_decl));
206 VTableContextBase &vtable_ctx,
208 const ASTRecordLayout &record_layout) {
212 uint32_t type_info = this_type.
GetTypeInfo(&pointee_type);
217 bool ptr_or_ref =
false;
218 if (type_info & (eTypeIsPointer | eTypeIsReference)) {
224 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
225 if ((type_info & cpp_class) != cpp_class)
230 vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity()
244 vbtable_ptr_addr += vbtable_ptr_offset;
255 auto size = valobj.
GetData(data, err);
263 VTableContextBase &vtable_ctx,
265 const CXXRecordDecl *cxx_record_decl,
266 const CXXRecordDecl *base_class_decl) {
267 if (vtable_ctx.isMicrosoft()) {
268 clang::MicrosoftVTableContext &msoft_vtable_ctx =
269 static_cast<clang::MicrosoftVTableContext &
>(vtable_ctx);
273 const unsigned vbtable_index =
274 msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl);
275 const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4;
281 clang::ItaniumVTableContext &itanium_vtable_ctx =
282 static_cast<clang::ItaniumVTableContext &
>(vtable_ctx);
284 clang::CharUnits base_offset_offset =
285 itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl,
288 vtable_ptr + base_offset_offset.getQuantity();
297 const ASTRecordLayout &record_layout,
298 const CXXRecordDecl *cxx_record_decl,
299 const CXXRecordDecl *base_class_decl,
300 int32_t &bit_offset) {
312 *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl);
313 if (base_offset == INT64_MAX)
316 bit_offset = base_offset * 8;
326 static llvm::once_flag g_once_flag;
327 llvm::call_once(g_once_flag, []() {
334 bool is_complete_objc_class)
347 const clang::Decl *parent) {
348 if (!member || !parent)
355 member->setFromASTFile();
356 member->setOwningModuleID(
id.GetValue());
357 member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
358 if (llvm::isa<clang::NamedDecl>(member))
359 if (
auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
360 dc->setHasExternalVisibleStorage(
true);
363 dc->setHasExternalLexicalStorage(
true);
370 clang::OverloadedOperatorKind &op_kind) {
372 if (!name.consume_front(
"operator"))
377 bool space_after_operator = name.consume_front(
" ");
379 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
380 .Case(
"+", clang::OO_Plus)
381 .Case(
"+=", clang::OO_PlusEqual)
382 .Case(
"++", clang::OO_PlusPlus)
383 .Case(
"-", clang::OO_Minus)
384 .Case(
"-=", clang::OO_MinusEqual)
385 .Case(
"--", clang::OO_MinusMinus)
386 .Case(
"->", clang::OO_Arrow)
387 .Case(
"->*", clang::OO_ArrowStar)
388 .Case(
"*", clang::OO_Star)
389 .Case(
"*=", clang::OO_StarEqual)
390 .Case(
"/", clang::OO_Slash)
391 .Case(
"/=", clang::OO_SlashEqual)
392 .Case(
"%", clang::OO_Percent)
393 .Case(
"%=", clang::OO_PercentEqual)
394 .Case(
"^", clang::OO_Caret)
395 .Case(
"^=", clang::OO_CaretEqual)
396 .Case(
"&", clang::OO_Amp)
397 .Case(
"&=", clang::OO_AmpEqual)
398 .Case(
"&&", clang::OO_AmpAmp)
399 .Case(
"|", clang::OO_Pipe)
400 .Case(
"|=", clang::OO_PipeEqual)
401 .Case(
"||", clang::OO_PipePipe)
402 .Case(
"~", clang::OO_Tilde)
403 .Case(
"!", clang::OO_Exclaim)
404 .Case(
"!=", clang::OO_ExclaimEqual)
405 .Case(
"=", clang::OO_Equal)
406 .Case(
"==", clang::OO_EqualEqual)
407 .Case(
"<", clang::OO_Less)
408 .Case(
"<=>", clang::OO_Spaceship)
409 .Case(
"<<", clang::OO_LessLess)
410 .Case(
"<<=", clang::OO_LessLessEqual)
411 .Case(
"<=", clang::OO_LessEqual)
412 .Case(
">", clang::OO_Greater)
413 .Case(
">>", clang::OO_GreaterGreater)
414 .Case(
">>=", clang::OO_GreaterGreaterEqual)
415 .Case(
">=", clang::OO_GreaterEqual)
416 .Case(
"()", clang::OO_Call)
417 .Case(
"[]", clang::OO_Subscript)
418 .Case(
",", clang::OO_Comma)
419 .Default(clang::NUM_OVERLOADED_OPERATORS);
422 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
434 if (!space_after_operator)
439 op_kind = StringSwitch<clang::OverloadedOperatorKind>(name)
440 .Case(
"new", clang::OO_New)
441 .Case(
"new[]", clang::OO_Array_New)
442 .Case(
"delete", clang::OO_Delete)
443 .Case(
"delete[]", clang::OO_Array_Delete)
445 .Default(clang::NUM_OVERLOADED_OPERATORS);
450clang::AccessSpecifier
470 std::vector<std::string> Includes;
471 LangOptions::setLangDefaults(Opts, clang::Language::ObjCXX, arch.
GetTriple(),
472 Includes, clang::LangStandard::lang_gnucxx98);
474 Opts.setValueVisibilityMode(DefaultVisibility);
478 Opts.Trigraphs = !Opts.GNUMode;
483 Opts.ModulesLocalVisibility = 1;
487 llvm::Triple target_triple) {
489 if (!target_triple.str().empty())
499 ASTContext &existing_ctxt) {
515 if (!TypeSystemClangSupportsLanguage(language))
519 arch =
module->GetArchitecture();
529 if (triple.getVendor() == llvm::Triple::Apple &&
530 triple.getOS() == llvm::Triple::UnknownOS) {
531 if (triple.getArch() == llvm::Triple::arm ||
532 triple.getArch() == llvm::Triple::aarch64 ||
533 triple.getArch() == llvm::Triple::aarch64_32 ||
534 triple.getArch() == llvm::Triple::thumb) {
535 triple.setOS(llvm::Triple::IOS);
537 triple.setOS(llvm::Triple::MacOSX);
542 std::string ast_name =
543 "ASTContext for '" +
module->GetFileSpec().GetPath() + "'";
544 return std::make_shared<TypeSystemClang>(ast_name, triple);
545 }
else if (target && target->
IsValid())
546 return std::make_shared<ScratchTypeSystemClang>(*target, triple);
608 assert(s ==
nullptr || &s->getASTContext() ==
m_ast_up.get());
621 llvm::IntrusiveRefCntPtr<ExternalASTSource> ast_source_sp) {
623 ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(
true);
624 ast.setExternalSource(std::move(ast_source_sp));
637 const clang::Diagnostic &info)
override {
639 llvm::SmallVector<char, 32> diag_str(10);
640 info.FormatDiagnostic(diag_str);
641 diag_str.push_back(
'\0');
646 DiagnosticConsumer *
clone(DiagnosticsEngine &Diags)
const {
667 clang::FileSystemOptions file_system_options;
677 m_ast_up = std::make_unique<ASTContext>(
689 m_ast_up->InitBuiltinTypes(*target_info);
693 "Failed to initialize builtin ASTContext types for target '{0}'. "
694 "Printing variables may behave unexpectedly.",
700 static std::once_flag s_uninitialized_target_warning;
702 &s_uninitialized_target_warning);
708 llvm::makeIntrusiveRefCnt<ClangExternalASTSourceCallbacks>(*
this);
740#pragma mark Basic Types
743 ASTContext &ast, QualType qual_type) {
744 uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
745 return qual_type_bit_size == bit_size;
764 return GetType(ast.UnsignedCharTy);
766 return GetType(ast.UnsignedShortTy);
768 return GetType(ast.UnsignedIntTy);
770 return GetType(ast.UnsignedLongTy);
772 return GetType(ast.UnsignedLongLongTy);
774 return GetType(ast.UnsignedInt128Ty);
779 return GetType(ast.SignedCharTy);
787 return GetType(ast.LongLongTy);
798 return GetType(ast.LongDoubleTy);
802 return GetType(ast.Float128Ty);
807 if (bit_size && !(bit_size & 0x7u))
808 return GetType(ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8));
816 static const llvm::StringMap<lldb::BasicType> g_type_map = {
881 auto iter = g_type_map.find(name);
882 if (iter == g_type_map.end())
913 llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size) {
932 return GetType(ast.UnsignedCharTy);
934 return GetType(ast.UnsignedShortTy);
936 return GetType(ast.UnsignedIntTy);
941 if (type_name.contains(
"complex")) {
950 case DW_ATE_complex_float: {
951 CanQualType FloatComplexTy = ast.getComplexType(ast.FloatTy);
953 return GetType(FloatComplexTy);
955 CanQualType DoubleComplexTy = ast.getComplexType(ast.DoubleTy);
957 return GetType(DoubleComplexTy);
959 CanQualType LongDoubleComplexTy = ast.getComplexType(ast.LongDoubleTy);
961 return GetType(LongDoubleComplexTy);
971 if (type_name ==
"float" &&
974 if (type_name ==
"double" &&
977 if (type_name ==
"long double" &&
979 return GetType(ast.LongDoubleTy);
980 if (type_name ==
"__bf16" &&
982 return GetType(ast.BFloat16Ty);
983 if (type_name ==
"_Float16" &&
989 if ((type_name ==
"__float128" || type_name ==
"_Float128" ||
990 type_name ==
"f128") &&
992 return GetType(ast.Float128Ty);
999 return GetType(ast.LongDoubleTy);
1003 return GetType(ast.Float128Ty);
1007 if (!type_name.empty()) {
1008 if (type_name.starts_with(
"_BitInt"))
1009 return GetType(ast.getBitIntType(
false, bit_size));
1010 if (type_name ==
"wchar_t" &&
1015 if (type_name ==
"void" &&
1018 if (type_name.contains(
"long long") &&
1020 return GetType(ast.LongLongTy);
1021 if (type_name.contains(
"long") &&
1024 if (type_name.contains(
"short") &&
1027 if (type_name.contains(
"char")) {
1031 return GetType(ast.SignedCharTy);
1033 if (type_name.contains(
"int")) {
1050 return GetType(ast.LongLongTy);
1055 case DW_ATE_signed_char:
1056 if (type_name ==
"char") {
1061 return GetType(ast.SignedCharTy);
1064 case DW_ATE_unsigned:
1065 if (!type_name.empty()) {
1066 if (type_name.starts_with(
"unsigned _BitInt"))
1067 return GetType(ast.getBitIntType(
true, bit_size));
1068 if (type_name ==
"wchar_t") {
1075 if (type_name.contains(
"long long")) {
1077 return GetType(ast.UnsignedLongLongTy);
1078 }
else if (type_name.contains(
"long")) {
1080 return GetType(ast.UnsignedLongTy);
1081 }
else if (type_name.contains(
"short")) {
1083 return GetType(ast.UnsignedShortTy);
1084 }
else if (type_name.contains(
"char")) {
1086 return GetType(ast.UnsignedCharTy);
1087 }
else if (type_name.contains(
"int")) {
1089 return GetType(ast.UnsignedIntTy);
1091 return GetType(ast.UnsignedInt128Ty);
1096 return GetType(ast.UnsignedCharTy);
1098 return GetType(ast.UnsignedShortTy);
1100 return GetType(ast.UnsignedIntTy);
1102 return GetType(ast.UnsignedLongTy);
1104 return GetType(ast.UnsignedLongLongTy);
1106 return GetType(ast.UnsignedInt128Ty);
1109 case DW_ATE_unsigned_char:
1110 if (type_name ==
"char") {
1115 return GetType(ast.UnsignedCharTy);
1117 return GetType(ast.UnsignedShortTy);
1120 case DW_ATE_imaginary_float:
1132 if (!type_name.empty()) {
1133 if (type_name ==
"char16_t")
1135 if (type_name ==
"char32_t")
1137 if (type_name ==
"char8_t")
1146 "error: need to add support for DW_TAG_base_type '{0}' "
1147 "encoded with DW_ATE = {1:x}, bit_size = {2}",
1148 type_name, dw_ate, bit_size);
1154 QualType char_type(ast.CharTy);
1157 char_type.addConst();
1159 return GetType(ast.getPointerType(char_type));
1163 bool ignore_qualifiers) {
1174 if (ignore_qualifiers) {
1175 type1_qual = type1_qual.getUnqualifiedType();
1176 type2_qual = type2_qual.getUnqualifiedType();
1179 return ast->getASTContext().hasSameType(type1_qual, type2_qual);
1186 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
1187 if (
auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
1199 if (clang::ObjCInterfaceDecl *interface_decl =
1200 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1202 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1204 if (clang::ValueDecl *value_decl = llvm::dyn_cast<clang::ValueDecl>(decl))
1218 return GetType(value_decl->getType());
1221#pragma mark Structure, Unions, Classes
1225 if (!decl || !owning_module.
HasValue())
1228 decl->setFromASTFile();
1229 decl->setOwningModuleID(owning_module.
GetValue());
1230 decl->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
1236 bool is_framework,
bool is_explicit) {
1238 auto *ast_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1240 assert(ast_source &&
"external ast source was lost");
1258 clang::Module *module;
1259 auto parent_desc = ast_source->getSourceDescriptor(parent.
GetValue());
1261 name, parent_desc ? parent_desc->getModuleOrNull() :
nullptr,
1262 is_framework, is_explicit);
1264 return ast_source->GetIDForModule(module);
1266 return ast_source->RegisterModule(module);
1272 std::optional<ClangASTMetadata> metadata,
bool exports_symbols) {
1275 if (decl_ctx ==
nullptr)
1276 decl_ctx = ast.getTranslationUnitDecl();
1280 bool isInternal =
false;
1281 return CreateObjCClass(name, decl_ctx, owning_module, isInternal, metadata);
1290 bool has_name = !name.empty();
1291 CXXRecordDecl *decl = CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1292 decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1293 decl->setDeclContext(decl_ctx);
1295 decl->setDeclName(&ast.Idents.get(name));
1323 if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols)
1324 decl->setAnonymousStructOrUnion(
true);
1330 decl->setAccess(AS_public);
1333 decl_ctx->addDecl(decl);
1335 return GetType(ast.getCanonicalTagType(decl));
1342QualType GetValueParamType(
const clang::TemplateArgument &argument) {
1343 switch (argument.getKind()) {
1344 case TemplateArgument::Integral:
1345 return argument.getIntegralType();
1346 case TemplateArgument::StructuralValue:
1347 return argument.getStructuralValueType();
1357 llvm::SmallVector<NamedDecl *, 8> &template_param_decls) {
1358 const bool parameter_pack =
false;
1359 const bool is_typename =
false;
1360 const unsigned depth = 0;
1361 const size_t num_template_params = template_param_infos.
Size();
1362 DeclContext *
const decl_context =
1363 ast.getTranslationUnitDecl();
1365 auto const &args = template_param_infos.
GetArgs();
1366 auto const &names = template_param_infos.
GetNames();
1367 for (
size_t i = 0; i < num_template_params; ++i) {
1368 const char *name = names[i];
1370 IdentifierInfo *identifier_info =
nullptr;
1371 if (name && name[0])
1372 identifier_info = &ast.Idents.get(name);
1373 TemplateArgument
const &targ = args[i];
1374 QualType template_param_type = GetValueParamType(targ);
1375 if (!template_param_type.isNull()) {
1376 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1377 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1378 identifier_info, template_param_type, parameter_pack,
1379 ast.getTrivialTypeSourceInfo(template_param_type)));
1381 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1382 ast, decl_context, SourceLocation(), SourceLocation(), depth, i,
1383 identifier_info, is_typename, parameter_pack));
1388 IdentifierInfo *identifier_info =
nullptr;
1390 identifier_info = &ast.Idents.get(template_param_infos.
GetPackName());
1391 const bool parameter_pack_true =
true;
1393 QualType template_param_type =
1397 if (!template_param_type.isNull()) {
1398 template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
1399 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1400 num_template_params, identifier_info, template_param_type,
1401 parameter_pack_true,
1402 ast.getTrivialTypeSourceInfo(template_param_type)));
1404 template_param_decls.push_back(TemplateTypeParmDecl::Create(
1405 ast, decl_context, SourceLocation(), SourceLocation(), depth,
1406 num_template_params, identifier_info, is_typename,
1407 parameter_pack_true));
1410 clang::Expr *
const requires_clause =
nullptr;
1411 TemplateParameterList *template_param_list = TemplateParameterList::Create(
1412 ast, SourceLocation(), SourceLocation(), template_param_decls,
1413 SourceLocation(), requires_clause);
1414 return template_param_list;
1419 clang::FunctionDecl *func_decl,
1424 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1426 ast, template_param_infos, template_param_decls);
1427 FunctionTemplateDecl *func_tmpl_decl =
1428 FunctionTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1429 func_tmpl_decl->setDeclContext(decl_ctx);
1430 func_tmpl_decl->setLocation(func_decl->getLocation());
1431 func_tmpl_decl->setDeclName(func_decl->getDeclName());
1432 func_tmpl_decl->setTemplateParameters(template_param_list);
1433 func_tmpl_decl->init(func_decl);
1436 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1437 i < template_param_decl_count; ++i) {
1439 template_param_decls[i]->setDeclContext(func_decl);
1441 func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
1443 return func_tmpl_decl;
1447 FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl,
1449 TemplateArgumentList *template_args_ptr = TemplateArgumentList::CreateCopy(
1450 func_decl->getASTContext(), infos.
GetArgs());
1452 func_decl->setFunctionTemplateSpecialization(func_tmpl_decl,
1453 template_args_ptr,
nullptr);
1460 const TemplateArgument &value) {
1461 if (llvm::isa<TemplateTypeParmDecl>(param)) {
1463 if (value.getKind() != TemplateArgument::Type)
1465 }
else if (
auto *type_param =
1466 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
1468 QualType value_param_type = GetValueParamType(value);
1469 if (value_param_type.isNull())
1473 if (type_param->getType() != value_param_type)
1481 "Don't know how to compare template parameter to passed"
1482 " value. Decl kind of parameter is: {0}",
1483 param->getDeclKindName());
1484 lldbassert(
false &&
"Can't compare this TemplateParmDecl subclass");
1499 ClassTemplateDecl *class_template_decl,
1502 TemplateParameterList ¶ms = *class_template_decl->getTemplateParameters();
1508 std::optional<NamedDecl *> pack_parameter;
1510 size_t non_pack_params = params.size();
1511 for (
size_t i = 0; i < params.size(); ++i) {
1512 NamedDecl *param = params.getParam(i);
1513 if (param->isParameterPack()) {
1514 pack_parameter = param;
1515 non_pack_params = i;
1523 if (non_pack_params != instantiation_values.
Size())
1541 for (
const auto pair :
1542 llvm::zip_first(instantiation_values.
GetArgs(), params)) {
1543 const TemplateArgument &passed_arg = std::get<0>(pair);
1544 NamedDecl *found_param = std::get<1>(pair);
1549 return class_template_decl;
1554 llvm::StringRef class_name,
int kind,
1558 ClassTemplateDecl *class_template_decl =
nullptr;
1559 if (decl_ctx ==
nullptr)
1560 decl_ctx = ast.getTranslationUnitDecl();
1562 IdentifierInfo &identifier_info = ast.Idents.get(class_name);
1563 DeclarationName decl_name(&identifier_info);
1566 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1567 for (NamedDecl *decl : result) {
1568 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1569 if (!class_template_decl)
1578 template_param_infos))
1580 return class_template_decl;
1583 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1586 ast, template_param_infos, template_param_decls);
1588 CXXRecordDecl *template_cxx_decl =
1589 CXXRecordDecl::CreateDeserialized(ast, GlobalDeclID());
1590 template_cxx_decl->setTagKind(
static_cast<TagDecl::TagKind
>(kind));
1592 template_cxx_decl->setDeclContext(decl_ctx);
1593 template_cxx_decl->setDeclName(decl_name);
1596 for (
size_t i = 0, template_param_decl_count = template_param_decls.size();
1597 i < template_param_decl_count; ++i) {
1598 template_param_decls[i]->setDeclContext(template_cxx_decl);
1606 class_template_decl =
1607 ClassTemplateDecl::CreateDeserialized(ast, GlobalDeclID());
1609 class_template_decl->setDeclContext(decl_ctx);
1610 class_template_decl->setDeclName(decl_name);
1611 class_template_decl->setTemplateParameters(template_param_list);
1612 class_template_decl->init(template_cxx_decl);
1613 template_cxx_decl->setDescribedClassTemplate(class_template_decl);
1616 class_template_decl->setAccess(AS_public);
1618 decl_ctx->addDecl(class_template_decl);
1620 VerifyDecl(class_template_decl);
1622 return class_template_decl;
1625TemplateTemplateParmDecl *
1629 auto *decl_ctx = ast.getTranslationUnitDecl();
1631 IdentifierInfo &identifier_info = ast.Idents.get(template_name);
1632 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1636 ast, template_param_infos, template_param_decls);
1642 return TemplateTemplateParmDecl::Create(
1643 ast, decl_ctx, SourceLocation(),
1645 false, &identifier_info,
1646 TemplateNameKind::TNK_Type_template,
true,
1647 template_param_list);
1650ClassTemplateSpecializationDecl *
1653 ClassTemplateDecl *class_template_decl,
int kind,
1656 llvm::SmallVector<clang::TemplateArgument, 2> args(
1657 template_param_infos.
Size() +
1660 auto const &orig_args = template_param_infos.
GetArgs();
1661 std::copy(orig_args.begin(), orig_args.end(), args.begin());
1663 args[args.size() - 1] = TemplateArgument::CreatePackCopy(
1666 ClassTemplateSpecializationDecl *class_template_specialization_decl =
1667 ClassTemplateSpecializationDecl::CreateDeserialized(ast, GlobalDeclID());
1668 class_template_specialization_decl->setTagKind(
1669 static_cast<TagDecl::TagKind
>(kind));
1670 class_template_specialization_decl->setDeclContext(decl_ctx);
1671 class_template_specialization_decl->setInstantiationOf(class_template_decl);
1672 class_template_specialization_decl->setTemplateArgs(
1673 TemplateArgumentList::CreateCopy(ast, args));
1674 void *insert_pos =
nullptr;
1675 if (class_template_decl->findSpecialization(args, insert_pos))
1677 class_template_decl->AddSpecialization(class_template_specialization_decl,
1679 class_template_specialization_decl->setDeclName(
1680 class_template_decl->getDeclName());
1685 class_template_specialization_decl->setStrictPackMatch(
false);
1688 decl_ctx->addDecl(class_template_specialization_decl);
1690 class_template_specialization_decl->setSpecializationKind(
1691 TSK_ExplicitSpecialization);
1693 return class_template_specialization_decl;
1697 ClassTemplateSpecializationDecl *class_template_specialization_decl) {
1698 if (class_template_specialization_decl) {
1700 return GetType(ast.getCanonicalTagType(class_template_specialization_decl));
1706 clang::OverloadedOperatorKind op_kind,
1707 bool unary,
bool binary,
1708 uint32_t num_params) {
1710 if (op_kind == OO_Call)
1716 if (num_params == 1)
1718 if (num_params == 2)
1725 bool is_method, clang::OverloadedOperatorKind op_kind,
1726 uint32_t num_params) {
1734 case OO_Array_Delete:
1738#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1740 return check_op_param(is_method, op_kind, Unary, Binary, num_params);
1742#include "clang/Basic/OperatorKinds.def"
1750 uint32_t &bitfield_bit_size) {
1752 if (field ==
nullptr)
1755 if (field->isBitField()) {
1756 Expr *bit_width_expr = field->getBitWidth();
1757 if (bit_width_expr) {
1758 if (std::optional<llvm::APSInt> bit_width_apsint =
1759 bit_width_expr->getIntegerConstantExpr(ast)) {
1760 bitfield_bit_size = bit_width_apsint->getLimitedValue(
UINT32_MAX);
1769 if (record_decl ==
nullptr)
1772 if (!record_decl->field_empty())
1776 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1777 if (cxx_record_decl) {
1778 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1779 for (base_class = cxx_record_decl->bases_begin(),
1780 base_class_end = cxx_record_decl->bases_end();
1781 base_class != base_class_end; ++base_class) {
1782 assert(record_decl != base_class->getType()->getAsCXXRecordDecl() &&
1783 "Base can't inherit from itself.");
1795 if (std::optional<ClangASTMetadata> meta_data =
GetMetadata(record_decl);
1796 meta_data && meta_data->IsForcefullyCompleted())
1802#pragma mark Objective-C Classes
1805 llvm::StringRef name, clang::DeclContext *decl_ctx,
1807 std::optional<ClangASTMetadata> metadata) {
1809 assert(!name.empty());
1811 decl_ctx = ast.getTranslationUnitDecl();
1813 ObjCInterfaceDecl *decl =
1814 ObjCInterfaceDecl::CreateDeserialized(ast, GlobalDeclID());
1815 decl->setDeclContext(decl_ctx);
1816 decl->setDeclName(&ast.Idents.get(name));
1817 decl->setImplicit(isInternal);
1823 return GetType(ast.getObjCInterfaceType(decl));
1832 bool omit_empty_base_classes) {
1833 uint32_t num_bases = 0;
1834 if (cxx_record_decl) {
1835 if (omit_empty_base_classes) {
1836 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1837 for (base_class = cxx_record_decl->bases_begin(),
1838 base_class_end = cxx_record_decl->bases_end();
1839 base_class != base_class_end; ++base_class) {
1846 num_bases = cxx_record_decl->getNumBases();
1851#pragma mark Namespace Declarations
1854 const char *name, clang::DeclContext *decl_ctx,
1856 NamespaceDecl *namespace_decl =
nullptr;
1858 TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
1860 decl_ctx = translation_unit_decl;
1863 IdentifierInfo &identifier_info = ast.Idents.get(name);
1864 DeclarationName decl_name(&identifier_info);
1865 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1866 for (NamedDecl *decl : result) {
1867 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1869 return namespace_decl;
1872 namespace_decl = NamespaceDecl::Create(ast, decl_ctx, is_inline,
1873 SourceLocation(), SourceLocation(),
1874 &identifier_info,
nullptr,
false);
1876 decl_ctx->addDecl(namespace_decl);
1878 if (decl_ctx == translation_unit_decl) {
1879 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1881 return namespace_decl;
1884 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1885 SourceLocation(),
nullptr,
nullptr,
false);
1886 translation_unit_decl->setAnonymousNamespace(namespace_decl);
1887 translation_unit_decl->addDecl(namespace_decl);
1888 assert(namespace_decl == translation_unit_decl->getAnonymousNamespace());
1890 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1891 if (parent_namespace_decl) {
1892 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1894 return namespace_decl;
1896 NamespaceDecl::Create(ast, decl_ctx,
false, SourceLocation(),
1897 SourceLocation(),
nullptr,
nullptr,
false);
1898 parent_namespace_decl->setAnonymousNamespace(namespace_decl);
1899 parent_namespace_decl->addDecl(namespace_decl);
1900 assert(namespace_decl ==
1901 parent_namespace_decl->getAnonymousNamespace());
1903 assert(
false &&
"GetUniqueNamespaceDeclaration called with no name and "
1904 "no namespace as decl_ctx");
1912 VerifyDecl(namespace_decl);
1913 return namespace_decl;
1920 clang::BlockDecl *decl =
1921 clang::BlockDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1922 decl->setDeclContext(ctx);
1931 clang::DeclContext *right,
1932 clang::DeclContext *root) {
1933 if (root ==
nullptr)
1936 std::set<clang::DeclContext *> path_left;
1937 for (clang::DeclContext *d = left; d !=
nullptr; d = d->getParent())
1938 path_left.insert(d);
1940 for (clang::DeclContext *d = right; d !=
nullptr; d = d->getParent())
1941 if (path_left.find(d) != path_left.end())
1949 clang::NamespaceDecl *ns_decl) {
1950 if (decl_ctx && ns_decl) {
1951 auto *translation_unit =
getASTContext().getTranslationUnitDecl();
1952 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
1954 clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
1955 clang::SourceLocation(), ns_decl,
1958 decl_ctx->addDecl(using_decl);
1968 clang::NamedDecl *target) {
1969 if (current_decl_ctx && target) {
1970 clang::UsingDecl *using_decl = clang::UsingDecl::Create(
1972 clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(),
false);
1974 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
1976 target->getDeclName(), using_decl, target);
1978 using_decl->addShadowDecl(shadow_decl);
1979 current_decl_ctx->addDecl(using_decl);
1987 const char *name, clang::QualType type) {
1989 clang::VarDecl *var_decl =
1990 clang::VarDecl::CreateDeserialized(
getASTContext(), GlobalDeclID());
1991 var_decl->setDeclContext(decl_context);
1992 if (name && name[0])
1993 var_decl->setDeclName(&
getASTContext().Idents.getOwn(name));
1994 var_decl->setType(type);
1996 var_decl->setAccess(clang::AS_public);
1997 decl_context->addDecl(var_decl);
2006 switch (basic_type) {
2008 return ast->VoidTy.getAsOpaquePtr();
2010 return ast->CharTy.getAsOpaquePtr();
2012 return ast->SignedCharTy.getAsOpaquePtr();
2014 return ast->UnsignedCharTy.getAsOpaquePtr();
2016 return ast->getWCharType().getAsOpaquePtr();
2018 return ast->getSignedWCharType().getAsOpaquePtr();
2020 return ast->getUnsignedWCharType().getAsOpaquePtr();
2022 return ast->Char8Ty.getAsOpaquePtr();
2024 return ast->Char16Ty.getAsOpaquePtr();
2026 return ast->Char32Ty.getAsOpaquePtr();
2028 return ast->ShortTy.getAsOpaquePtr();
2030 return ast->UnsignedShortTy.getAsOpaquePtr();
2032 return ast->IntTy.getAsOpaquePtr();
2034 return ast->UnsignedIntTy.getAsOpaquePtr();
2036 return ast->LongTy.getAsOpaquePtr();
2038 return ast->UnsignedLongTy.getAsOpaquePtr();
2040 return ast->LongLongTy.getAsOpaquePtr();
2042 return ast->UnsignedLongLongTy.getAsOpaquePtr();
2044 return ast->Int128Ty.getAsOpaquePtr();
2046 return ast->UnsignedInt128Ty.getAsOpaquePtr();
2048 return ast->BoolTy.getAsOpaquePtr();
2050 return ast->HalfTy.getAsOpaquePtr();
2052 return ast->FloatTy.getAsOpaquePtr();
2054 return ast->DoubleTy.getAsOpaquePtr();
2056 return ast->LongDoubleTy.getAsOpaquePtr();
2058 return ast->Float128Ty.getAsOpaquePtr();
2060 return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
2062 return ast->getComplexType(ast->DoubleTy).getAsOpaquePtr();
2064 return ast->getComplexType(ast->LongDoubleTy).getAsOpaquePtr();
2066 return ast->getObjCIdType().getAsOpaquePtr();
2068 return ast->getObjCClassType().getAsOpaquePtr();
2070 return ast->getObjCSelType().getAsOpaquePtr();
2072 return ast->NullPtrTy.getAsOpaquePtr();
2078#pragma mark Function Types
2080clang::DeclarationName
2083 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
2084 if (!
IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
2093 const clang::FunctionProtoType *function_type =
2094 llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr());
2095 if (function_type ==
nullptr)
2096 return clang::DeclarationName();
2098 const bool is_method =
false;
2099 const unsigned int num_params = function_type->getNumParams();
2101 is_method, op_kind, num_params))
2102 return clang::DeclarationName();
2104 return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
2108 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
2109 printing_policy.SuppressTagKeyword =
true;
2112 printing_policy.SuppressInlineNamespace =
2113 llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
2114 printing_policy.SuppressUnwrittenScope =
false;
2126 printing_policy.SuppressDefaultTemplateArgs =
false;
2127 return printing_policy;
2134 llvm::raw_string_ostream os(result);
2135 named_decl->getNameForDiagnostic(os, printing_policy, qualified);
2141 llvm::StringRef name,
const CompilerType &function_clang_type,
2142 clang::StorageClass storage,
bool is_inline, llvm::StringRef asm_label) {
2143 FunctionDecl *func_decl =
nullptr;
2146 decl_ctx = ast.getTranslationUnitDecl();
2148 const bool hasWrittenPrototype =
true;
2149 const bool isConstexprSpecified =
false;
2151 clang::DeclarationName declarationName =
2153 func_decl = FunctionDecl::CreateDeserialized(ast, GlobalDeclID());
2154 func_decl->setDeclContext(decl_ctx);
2155 func_decl->setDeclName(declarationName);
2157 func_decl->setStorageClass(storage);
2158 func_decl->setInlineSpecified(is_inline);
2159 func_decl->setHasWrittenPrototype(hasWrittenPrototype);
2160 func_decl->setConstexprKind(isConstexprSpecified
2161 ? ConstexprSpecKind::Constexpr
2162 : ConstexprSpecKind::Unspecified);
2174 if (!asm_label.empty())
2175 func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label));
2178 decl_ctx->addDecl(func_decl);
2180 VerifyDecl(func_decl);
2186 const CompilerType &result_type, llvm::ArrayRef<CompilerType> args,
2187 bool is_variadic,
unsigned type_quals, clang::CallingConv cc,
2188 clang::RefQualifierKind ref_qual) {
2192 std::vector<QualType> qual_type_args;
2194 for (
const auto &arg : args) {
2209 FunctionProtoType::ExtProtoInfo proto_info;
2210 proto_info.ExtInfo = cc;
2211 proto_info.Variadic = is_variadic;
2212 proto_info.ExceptionSpec = EST_None;
2213 proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
2214 proto_info.RefQualifier = ref_qual;
2222 const char *name,
const CompilerType ¶m_type,
int storage,
2225 auto *decl = ParmVarDecl::CreateDeserialized(ast, GlobalDeclID());
2226 decl->setDeclContext(decl_ctx);
2227 if (name && name[0])
2228 decl->setDeclName(&ast.Idents.get(name));
2230 decl->setStorageClass(
static_cast<clang::StorageClass
>(storage));
2233 decl_ctx->addDecl(decl);
2240 QualType block_type =
m_ast_up->getBlockPointerType(
2246#pragma mark Array Types
2250 std::optional<size_t> element_count,
2263 clang::ArraySizeModifier::Normal, 0));
2269 llvm::APInt ap_element_count(64, *element_count);
2271 ap_element_count,
nullptr,
2272 clang::ArraySizeModifier::Normal, 0));
2276 llvm::StringRef type_name,
2277 const std::initializer_list<std::pair<const char *, CompilerType>>
2284 lldbassert(0 &&
"Trying to create a type for an existing name");
2289 llvm::to_underlying(clang::TagTypeKind::Struct),
2292 for (
const auto &field : type_fields)
2301 llvm::StringRef type_name,
2302 const std::initializer_list<std::pair<const char *, CompilerType>>
2314#pragma mark Enumeration Types
2317 llvm::StringRef name, clang::DeclContext *decl_ctx,
2319 const CompilerType &integer_clang_type,
bool is_scoped,
2320 std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind) {
2327 EnumDecl *enum_decl = EnumDecl::CreateDeserialized(ast, GlobalDeclID());
2328 enum_decl->setDeclContext(decl_ctx);
2330 enum_decl->setDeclName(&ast.Idents.get(name));
2331 enum_decl->setScoped(is_scoped);
2332 enum_decl->setScopedUsingClassTag(is_scoped);
2333 enum_decl->setFixed(
false);
2336 decl_ctx->addDecl(enum_decl);
2340 clang::EnumExtensibilityAttr::CreateImplicit(ast, *enum_kind));
2345 enum_decl->setAccess(AS_public);
2347 return GetType(ast.getCanonicalTagType(enum_decl));
2358 if (bit_size == ast.getTypeSize(ast.SignedCharTy))
2359 return GetType(ast.SignedCharTy);
2361 if (bit_size == ast.getTypeSize(ast.ShortTy))
2364 if (bit_size == ast.getTypeSize(ast.IntTy))
2367 if (bit_size == ast.getTypeSize(ast.LongTy))
2370 if (bit_size == ast.getTypeSize(ast.LongLongTy))
2371 return GetType(ast.LongLongTy);
2373 if (bit_size == ast.getTypeSize(ast.Int128Ty))
2376 if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
2377 return GetType(ast.UnsignedCharTy);
2379 if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
2380 return GetType(ast.UnsignedShortTy);
2382 if (bit_size == ast.getTypeSize(ast.UnsignedIntTy))
2383 return GetType(ast.UnsignedIntTy);
2385 if (bit_size == ast.getTypeSize(ast.UnsignedLongTy))
2386 return GetType(ast.UnsignedLongTy);
2388 if (bit_size == ast.getTypeSize(ast.UnsignedLongLongTy))
2389 return GetType(ast.UnsignedLongLongTy);
2391 if (bit_size == ast.getTypeSize(ast.UnsignedInt128Ty))
2392 return GetType(ast.UnsignedInt128Ty);
2419 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2421 printf(
"%20s: %s\n", decl_ctx->getDeclKindName(),
2422 named_decl->getDeclName().getAsString().c_str());
2424 printf(
"%20s\n", decl_ctx->getDeclKindName());
2430 if (decl ==
nullptr)
2434 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2436 bool is_injected_class_name =
2437 llvm::isa<clang::CXXRecordDecl>(record_decl) &&
2438 llvm::cast<CXXRecordDecl>(record_decl)->isInjectedClassName();
2439 printf(
"%20s: %s%s\n", decl->getDeclKindName(),
2440 record_decl->getDeclName().getAsString().c_str(),
2441 is_injected_class_name ?
" (injected class name)" :
"");
2444 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2446 printf(
"%20s: %s\n", decl->getDeclKindName(),
2447 named_decl->getDeclName().getAsString().c_str());
2449 printf(
"%20s\n", decl->getDeclKindName());
2455 clang::Decl *decl) {
2459 ExternalASTSource *ast_source = ast->getExternalSource();
2464 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) {
2465 if (tag_decl->isCompleteDefinition())
2468 if (!tag_decl->hasExternalLexicalStorage())
2471 ast_source->CompleteType(tag_decl);
2473 return !ast->getCanonicalTagType(tag_decl)->isIncompleteType();
2474 }
else if (clang::ObjCInterfaceDecl *objc_interface_decl =
2475 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) {
2476 if (objc_interface_decl->getDefinition())
2479 if (!objc_interface_decl->hasExternalLexicalStorage())
2482 ast_source->CompleteType(objc_interface_decl);
2484 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2514std::optional<ClangASTMetadata>
2520 return std::nullopt;
2523std::optional<ClangASTMetadata>
2529 return std::nullopt;
2551 if (find(mask, type->getTypeClass()) != mask.end())
2553 switch (type->getTypeClass()) {
2556 case clang::Type::Atomic:
2557 type = cast<clang::AtomicType>(type)->getValueType();
2559 case clang::Type::Auto:
2560 case clang::Type::Decltype:
2561 case clang::Type::Paren:
2562 case clang::Type::SubstTemplateTypeParm:
2563 case clang::Type::TemplateSpecialization:
2564 case clang::Type::Typedef:
2565 case clang::Type::TypeOf:
2566 case clang::Type::TypeOfExpr:
2567 case clang::Type::Using:
2568 case clang::Type::PredefinedSugar:
2569 type = type->getLocallyUnqualifiedSingleStepDesugaredType();
2583 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2584 switch (type_class) {
2585 case clang::Type::ObjCInterface:
2586 return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())
2588 case clang::Type::ObjCObjectPointer:
2590 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
2591 ->getPointeeType());
2592 case clang::Type::Enum:
2593 case clang::Type::Record:
2594 return llvm::cast<clang::TagType>(qual_type)
2596 ->getDefinitionOrSelf();
2608static const clang::RecordType *
2610 assert(qual_type->isRecordType());
2612 const auto *tag_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
2614 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2618 if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
2621 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2622 const bool fields_loaded =
2623 cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2626 if (is_complete && fields_loaded)
2634 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2635 if (external_ast_source) {
2636 external_ast_source->CompleteType(cxx_record_decl);
2637 if (cxx_record_decl->isCompleteDefinition()) {
2638 cxx_record_decl->field_begin();
2639 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
2651 clang::QualType qual_type) {
2652 assert(qual_type->isEnumeralType());
2655 const clang::EnumType *enum_type =
2656 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
2658 auto *tag_decl = enum_type->getAsTagDecl();
2662 if (tag_decl->getDefinition())
2666 if (!tag_decl->hasExternalLexicalStorage())
2670 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2671 if (!external_ast_source)
2674 external_ast_source->CompleteType(tag_decl);
2682static const clang::ObjCObjectType *
2684 assert(qual_type->isObjCObjectType());
2687 const clang::ObjCObjectType *objc_class_type =
2688 llvm::cast<clang::ObjCObjectType>(qual_type);
2690 clang::ObjCInterfaceDecl *class_interface_decl =
2691 objc_class_type->getInterface();
2694 if (!class_interface_decl)
2695 return objc_class_type;
2698 if (class_interface_decl->getDefinition())
2699 return objc_class_type;
2702 if (!class_interface_decl->hasExternalLexicalStorage())
2706 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2707 if (!external_ast_source)
2710 external_ast_source->CompleteType(class_interface_decl);
2711 return objc_class_type;
2715 clang::QualType qual_type) {
2717 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2718 switch (type_class) {
2719 case clang::Type::ConstantArray:
2720 case clang::Type::IncompleteArray:
2721 case clang::Type::VariableArray: {
2722 const clang::ArrayType *array_type =
2723 llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2728 case clang::Type::Record: {
2730 return !RT->isIncompleteType();
2735 case clang::Type::Enum: {
2737 return !ET->isIncompleteType();
2741 case clang::Type::ObjCObject:
2742 case clang::Type::ObjCInterface: {
2744 return !OT->isIncompleteType();
2749 case clang::Type::Attributed:
2751 ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType());
2753 case clang::Type::MemberPointer:
2756 if (ast->getTargetInfo().getCXXABI().isMicrosoft()) {
2757 auto *MPT = qual_type.getTypePtr()->castAs<clang::MemberPointerType>();
2758 if (
auto *RD = MPT->getMostRecentCXXRecordDecl())
2761 return !qual_type.getTypePtr()->isIncompleteType();
2776 return !type || llvm::isa<clang::Type>(
GetQualType(type).getTypePtr());
2783 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2784 switch (type_class) {
2785 case clang::Type::IncompleteArray:
2786 case clang::Type::VariableArray:
2787 case clang::Type::ConstantArray:
2788 case clang::Type::ExtVector:
2789 case clang::Type::Vector:
2790 case clang::Type::Record:
2791 case clang::Type::ObjCObject:
2792 case clang::Type::ObjCInterface:
2804 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2805 switch (type_class) {
2806 case clang::Type::Record: {
2807 if (
const clang::RecordType *record_type =
2808 llvm::dyn_cast_or_null<clang::RecordType>(
2809 qual_type.getTypePtrOrNull())) {
2810 if (
const clang::RecordDecl *record_decl = record_type->getDecl()) {
2811 return record_decl->isAnonymousStructOrUnion();
2825 uint64_t *size,
bool *is_incomplete) {
2828 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2829 switch (type_class) {
2833 case clang::Type::ConstantArray:
2834 if (element_type_ptr)
2836 weak_from_this(), llvm::cast<clang::ConstantArrayType>(qual_type)
2840 *size = llvm::cast<clang::ConstantArrayType>(qual_type)
2842 .getLimitedValue(ULLONG_MAX);
2844 *is_incomplete =
false;
2847 case clang::Type::IncompleteArray:
2848 if (element_type_ptr)
2850 weak_from_this(), llvm::cast<clang::IncompleteArrayType>(qual_type)
2856 *is_incomplete =
true;
2859 case clang::Type::VariableArray:
2860 if (element_type_ptr)
2862 weak_from_this(), llvm::cast<clang::VariableArrayType>(qual_type)
2868 *is_incomplete =
false;
2871 case clang::Type::DependentSizedArray:
2872 if (element_type_ptr)
2875 llvm::cast<clang::DependentSizedArrayType>(qual_type)
2881 *is_incomplete =
false;
2884 if (element_type_ptr)
2885 element_type_ptr->
Clear();
2889 *is_incomplete =
false;
2897 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2898 switch (type_class) {
2899 case clang::Type::Vector: {
2900 const clang::VectorType *vector_type =
2901 qual_type->getAs<clang::VectorType>();
2904 *size = vector_type->getNumElements();
2906 *element_type =
GetType(vector_type->getElementType());
2910 case clang::Type::ExtVector: {
2911 const clang::ExtVectorType *ext_vector_type =
2912 qual_type->getAs<clang::ExtVectorType>();
2913 if (ext_vector_type) {
2915 *size = ext_vector_type->getNumElements();
2919 ext_vector_type->getElementType().getAsOpaquePtr());
2935 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2938 clang::ObjCInterfaceDecl *result_iface_decl =
2939 llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2941 std::optional<ClangASTMetadata> ast_metadata =
GetMetadata(result_iface_decl);
2945 return (ast_metadata->GetISAPtr() != 0);
2949 return GetQualType(type).getUnqualifiedType()->isCharType();
2971 if (!pointee_or_element_clang_type.
IsValid())
2974 if (type_flags.
AnySet(eTypeIsArray | eTypeIsPointer)) {
2975 if (pointee_or_element_clang_type.
IsCharType()) {
2976 if (type_flags.
Test(eTypeIsArray)) {
2979 length = llvm::cast<clang::ConstantArrayType>(
2993 if (
auto pointer_auth = qual_type.getPointerAuth())
2994 return pointer_auth.getKey();
3003 if (
auto pointer_auth = qual_type.getPointerAuth())
3004 return pointer_auth.getExtraDiscriminator();
3013 if (
auto pointer_auth = qual_type.getPointerAuth())
3014 return pointer_auth.isAddressDiscriminated();
3020 auto isFunctionType = [&](clang::QualType qual_type) {
3021 return qual_type->isFunctionType();
3035 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3036 switch (type_class) {
3037 case clang::Type::Record:
3039 const clang::CXXRecordDecl *cxx_record_decl =
3040 qual_type->getAsCXXRecordDecl();
3041 if (cxx_record_decl) {
3042 if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass())
3045 const clang::RecordType *record_type =
3046 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3048 if (
const clang::RecordDecl *record_decl =
3049 record_type->getDecl()->getDefinition()) {
3052 clang::RecordDecl::field_iterator field_pos,
3053 field_end = record_decl->field_end();
3054 uint32_t num_fields = 0;
3055 bool is_hva =
false;
3056 bool is_hfa =
false;
3057 clang::QualType base_qual_type;
3058 uint64_t base_bitwidth = 0;
3059 for (field_pos = record_decl->field_begin(); field_pos != field_end;
3061 clang::QualType field_qual_type = field_pos->getType();
3062 uint64_t field_bitwidth =
getASTContext().getTypeSize(qual_type);
3063 if (field_qual_type->isFloatingType()) {
3064 if (field_qual_type->isComplexType())
3067 if (num_fields == 0)
3068 base_qual_type = field_qual_type;
3073 if (field_qual_type.getTypePtr() !=
3074 base_qual_type.getTypePtr())
3078 }
else if (field_qual_type->isVectorType() ||
3079 field_qual_type->isExtVectorType()) {
3080 if (num_fields == 0) {
3081 base_qual_type = field_qual_type;
3082 base_bitwidth = field_bitwidth;
3087 if (base_bitwidth != field_bitwidth)
3089 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3098 CompilerType(weak_from_this(), base_qual_type.getAsOpaquePtr());
3115 const clang::FunctionProtoType *func =
3116 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3118 return func->getNumParams();
3125 const size_t index) {
3128 const clang::FunctionProtoType *func =
3129 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3131 if (index < func->getNumParams())
3132 return CompilerType(weak_from_this(), func->getParamType(index).getAsOpaquePtr());
3140 llvm::function_ref<
bool(clang::QualType)> predicate)
const {
3144 if (predicate(qual_type))
3147 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3148 switch (type_class) {
3152 case clang::Type::LValueReference:
3153 case clang::Type::RValueReference: {
3154 const clang::ReferenceType *reference_type =
3155 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3157 return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
3166 auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3167 return qual_type->isMemberFunctionPointerType();
3170 return IsTypeImpl(type, isMemberFunctionPointerType);
3175 auto isMemberDataPointerType = [](clang::QualType qual_type) {
3176 return qual_type->isMemberDataPointerType();
3179 return IsTypeImpl(type, isMemberDataPointerType);
3183 auto isFunctionPointerType = [](clang::QualType qual_type) {
3184 return qual_type->isFunctionPointerType();
3187 return IsTypeImpl(type, isFunctionPointerType);
3193 auto isBlockPointerType = [&](clang::QualType qual_type) {
3194 if (qual_type->isBlockPointerType()) {
3195 if (function_pointer_type_ptr) {
3196 const clang::BlockPointerType *block_pointer_type =
3197 qual_type->castAs<clang::BlockPointerType>();
3198 QualType pointee_type = block_pointer_type->getPointeeType();
3199 QualType function_pointer_type =
m_ast_up->getPointerType(pointee_type);
3201 weak_from_this(), function_pointer_type.getAsOpaquePtr());
3218 if (qual_type.isNull())
3227 is_signed = qual_type->isSignedIntegerType();
3235 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3239 is_signed = enum_type->isSignedIntegerOrEnumerationType();
3250 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3254 return enum_type->isScopedEnumeralType();
3265 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3266 switch (type_class) {
3267 case clang::Type::Builtin:
3268 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3271 case clang::BuiltinType::ObjCId:
3272 case clang::BuiltinType::ObjCClass:
3276 case clang::Type::ObjCObjectPointer:
3280 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3284 case clang::Type::BlockPointer:
3287 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3291 case clang::Type::Pointer:
3294 llvm::cast<clang::PointerType>(qual_type)
3298 case clang::Type::MemberPointer:
3301 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3310 pointee_type->
Clear();
3318 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3319 switch (type_class) {
3320 case clang::Type::Builtin:
3321 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
3324 case clang::BuiltinType::ObjCId:
3325 case clang::BuiltinType::ObjCClass:
3329 case clang::Type::ObjCObjectPointer:
3333 llvm::cast<clang::ObjCObjectPointerType>(qual_type)
3337 case clang::Type::BlockPointer:
3340 weak_from_this(), llvm::cast<clang::BlockPointerType>(qual_type)
3344 case clang::Type::Pointer:
3347 llvm::cast<clang::PointerType>(qual_type)
3351 case clang::Type::MemberPointer:
3354 weak_from_this(), llvm::cast<clang::MemberPointerType>(qual_type)
3358 case clang::Type::LValueReference:
3361 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3365 case clang::Type::RValueReference:
3368 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3377 pointee_type->
Clear();
3386 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3388 switch (type_class) {
3389 case clang::Type::LValueReference:
3392 weak_from_this(), llvm::cast<clang::LValueReferenceType>(qual_type)
3398 case clang::Type::RValueReference:
3401 weak_from_this(), llvm::cast<clang::RValueReferenceType>(qual_type)
3413 pointee_type->
Clear();
3422 if (qual_type.isNull())
3425 return qual_type->isFloatingType();
3433 const clang::TagType *tag_type =
3434 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3436 if (clang::TagDecl *tag_decl = tag_type->getDecl()->getDefinition())
3437 return tag_decl->isCompleteDefinition();
3440 const clang::ObjCObjectType *objc_class_type =
3441 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3442 if (objc_class_type) {
3443 clang::ObjCInterfaceDecl *class_interface_decl =
3444 objc_class_type->getInterface();
3445 if (class_interface_decl)
3446 return class_interface_decl->getDefinition() !=
nullptr;
3457 const clang::ObjCObjectPointerType *obj_pointer_type =
3458 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3460 if (obj_pointer_type)
3461 return obj_pointer_type->isObjCClassType();
3476 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3477 return (type_class == clang::Type::Record);
3484 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3485 return (type_class == clang::Type::Enum);
3491 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3492 switch (type_class) {
3493 case clang::Type::Record:
3495 if (
const auto *cxx_record_decl = qual_type->getAsCXXRecordDecl()) {
3502 return cxx_record_decl->isDynamicClass();
3516 bool check_cplusplus,
3518 if (dynamic_pointee_type)
3519 dynamic_pointee_type->
Clear();
3523 auto set_dynamic_pointee_type = [&](clang::QualType type) {
3524 if (dynamic_pointee_type)
3526 type.getAsOpaquePtr());
3529 clang::QualType pointee_qual_type;
3531 switch (qual_type->getTypeClass()) {
3532 case clang::Type::Builtin:
3533 if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() ==
3534 clang::BuiltinType::ObjCId) {
3535 set_dynamic_pointee_type(qual_type);
3540 case clang::Type::ObjCObjectPointer:
3543 if (
const auto *objc_pointee_type =
3544 qual_type->getPointeeType().getTypePtrOrNull()) {
3545 if (
const auto *objc_object_type =
3546 llvm::dyn_cast_or_null<clang::ObjCObjectType>(
3547 objc_pointee_type)) {
3548 if (objc_object_type->isObjCClass())
3552 set_dynamic_pointee_type(
3553 llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
3556 case clang::Type::Pointer:
3558 llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3561 case clang::Type::LValueReference:
3562 case clang::Type::RValueReference:
3564 llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3574 switch (pointee_qual_type.getCanonicalType()->getTypeClass()) {
3575 case clang::Type::Builtin:
3576 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) {
3577 case clang::BuiltinType::UnknownAny:
3578 case clang::BuiltinType::Void:
3579 set_dynamic_pointee_type(pointee_qual_type);
3585 case clang::Type::Record: {
3586 if (!check_cplusplus)
3588 clang::CXXRecordDecl *cxx_record_decl =
3589 pointee_qual_type->getAsCXXRecordDecl();
3590 if (!cxx_record_decl)
3594 if (cxx_record_decl->isCompleteDefinition())
3595 success = cxx_record_decl->isDynamicClass();
3597 std::optional<ClangASTMetadata> metadata =
GetMetadata(cxx_record_decl);
3598 std::optional<bool> is_dynamic =
3599 metadata ? metadata->GetIsDynamicCXXType() : std::nullopt;
3601 success = *is_dynamic;
3603 success = cxx_record_decl->isDynamicClass();
3609 set_dynamic_pointee_type(pointee_qual_type);
3613 case clang::Type::ObjCObject:
3614 case clang::Type::ObjCInterface:
3616 set_dynamic_pointee_type(pointee_qual_type);
3631 return (
GetTypeInfo(type,
nullptr) & eTypeIsScalar) != 0;
3638 ->getTypeClass() == clang::Type::Typedef;
3655 if (
auto *record_decl =
3657 return record_decl->canPassInRegisters();
3663 return TypeSystemClangSupportsLanguage(language);
3666std::optional<std::string>
3669 return std::nullopt;
3672 if (qual_type.isNull())
3673 return std::nullopt;
3675 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3676 if (!cxx_record_decl)
3677 return std::nullopt;
3679 return std::string(cxx_record_decl->getIdentifier()->getNameStart());
3687 return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() !=
nullptr;
3694 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3696 return tag_type->getDecl()->isEntityBeingDefined();
3707 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) {
3708 if (class_type_ptr) {
3709 if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) {
3710 const clang::ObjCObjectPointerType *obj_pointer_type =
3711 llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3712 if (obj_pointer_type ==
nullptr)
3713 class_type_ptr->
Clear();
3717 clang::QualType(obj_pointer_type->getInterfaceType(), 0)
3724 class_type_ptr->
Clear();
3751 {clang::Type::Typedef, clang::Type::Atomic});
3754 if (
const auto *typedef_type = qual_type->getAs<clang::TypedefType>()) {
3755 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3762 if (
auto *named_decl = qual_type->getAsTagDecl())
3774 clang::PrintingPolicy printing_policy(
getASTContext().getPrintingPolicy());
3775 printing_policy.SuppressTagKeyword =
true;
3776 printing_policy.SuppressScope =
false;
3777 printing_policy.SuppressUnwrittenScope =
true;
3778 printing_policy.SuppressInlineNamespace =
3779 llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::All);
3780 return ConstString(qual_type.getAsString(printing_policy));
3789 if (pointee_or_element_clang_type)
3790 pointee_or_element_clang_type->
Clear();
3792 clang::QualType qual_type =
3795 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3796 switch (type_class) {
3797 case clang::Type::Attributed:
3798 return GetTypeInfo(qual_type->castAs<clang::AttributedType>()
3801 pointee_or_element_clang_type);
3802 case clang::Type::BitInt: {
3803 uint32_t type_flags = eTypeIsScalar | eTypeIsInteger | eTypeHasValue;
3804 if (qual_type->isSignedIntegerType())
3805 type_flags |= eTypeIsSigned;
3809 case clang::Type::Builtin: {
3810 const clang::BuiltinType *builtin_type =
3811 llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3813 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3814 switch (builtin_type->getKind()) {
3815 case clang::BuiltinType::ObjCId:
3816 case clang::BuiltinType::ObjCClass:
3817 if (pointee_or_element_clang_type)
3821 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3824 case clang::BuiltinType::ObjCSel:
3825 if (pointee_or_element_clang_type)
3828 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3831 case clang::BuiltinType::Bool:
3832 case clang::BuiltinType::Char_U:
3833 case clang::BuiltinType::UChar:
3834 case clang::BuiltinType::WChar_U:
3835 case clang::BuiltinType::Char16:
3836 case clang::BuiltinType::Char32:
3837 case clang::BuiltinType::UShort:
3838 case clang::BuiltinType::UInt:
3839 case clang::BuiltinType::ULong:
3840 case clang::BuiltinType::ULongLong:
3841 case clang::BuiltinType::UInt128:
3842 case clang::BuiltinType::Char_S:
3843 case clang::BuiltinType::SChar:
3844 case clang::BuiltinType::WChar_S:
3845 case clang::BuiltinType::Short:
3846 case clang::BuiltinType::Int:
3847 case clang::BuiltinType::Long:
3848 case clang::BuiltinType::LongLong:
3849 case clang::BuiltinType::Int128:
3850 case clang::BuiltinType::Float:
3851 case clang::BuiltinType::Double:
3852 case clang::BuiltinType::LongDouble:
3853 builtin_type_flags |= eTypeIsScalar;
3854 if (builtin_type->isInteger()) {
3855 builtin_type_flags |= eTypeIsInteger;
3856 if (builtin_type->isSignedInteger())
3857 builtin_type_flags |= eTypeIsSigned;
3858 }
else if (builtin_type->isFloatingPoint())
3859 builtin_type_flags |= eTypeIsFloat;
3864 return builtin_type_flags;
3867 case clang::Type::BlockPointer:
3868 if (pointee_or_element_clang_type)
3870 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3871 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
3873 case clang::Type::Complex: {
3874 uint32_t complex_type_flags =
3875 eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
3876 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(
3877 qual_type->getCanonicalTypeInternal());
3879 clang::QualType complex_element_type(complex_type->getElementType());
3880 if (complex_element_type->isIntegerType())
3881 complex_type_flags |= eTypeIsInteger;
3882 else if (complex_element_type->isFloatingType())
3883 complex_type_flags |= eTypeIsFloat;
3885 return complex_type_flags;
3888 case clang::Type::ConstantArray:
3889 case clang::Type::DependentSizedArray:
3890 case clang::Type::IncompleteArray:
3891 case clang::Type::VariableArray:
3892 if (pointee_or_element_clang_type)
3894 weak_from_this(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
3897 return eTypeHasChildren | eTypeIsArray;
3899 case clang::Type::DependentName:
3901 case clang::Type::DependentSizedExtVector:
3902 return eTypeHasChildren | eTypeIsVector;
3904 case clang::Type::Enum:
3905 if (pointee_or_element_clang_type)
3907 weak_from_this(), llvm::cast<clang::EnumType>(qual_type)
3909 ->getDefinitionOrSelf()
3912 return eTypeIsEnumeration | eTypeHasValue;
3914 case clang::Type::FunctionProto:
3915 return eTypeIsFuncPrototype | eTypeHasValue;
3916 case clang::Type::FunctionNoProto:
3917 return eTypeIsFuncPrototype | eTypeHasValue;
3918 case clang::Type::InjectedClassName:
3921 case clang::Type::LValueReference:
3922 case clang::Type::RValueReference:
3923 if (pointee_or_element_clang_type)
3926 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
3929 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
3931 case clang::Type::MemberPointer:
3932 return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
3934 case clang::Type::ObjCObjectPointer:
3935 if (pointee_or_element_clang_type)
3937 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3938 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
3941 case clang::Type::ObjCObject:
3942 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3943 case clang::Type::ObjCInterface:
3944 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
3946 case clang::Type::Pointer:
3947 if (pointee_or_element_clang_type)
3949 weak_from_this(), qual_type->getPointeeType().getAsOpaquePtr());
3950 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
3952 case clang::Type::Record:
3953 if (qual_type->getAsCXXRecordDecl())
3954 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
3956 return eTypeHasChildren | eTypeIsStructUnion;
3958 case clang::Type::SubstTemplateTypeParm:
3959 return eTypeIsTemplate;
3960 case clang::Type::TemplateTypeParm:
3961 return eTypeIsTemplate;
3962 case clang::Type::TemplateSpecialization:
3963 return eTypeIsTemplate;
3965 case clang::Type::Typedef:
3966 return eTypeIsTypedef |
GetType(llvm::cast<clang::TypedefType>(qual_type)
3968 ->getUnderlyingType())
3970 case clang::Type::UnresolvedUsing:
3973 case clang::Type::ExtVector:
3974 case clang::Type::Vector: {
3975 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
3976 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(
3977 qual_type->getCanonicalTypeInternal());
3981 QualType element_type = vector_type->getElementType();
3982 if (element_type.isNull())
3985 if (element_type->isIntegerType())
3986 vector_type_flags |= eTypeIsInteger;
3987 else if (element_type->isFloatingType())
3988 vector_type_flags |= eTypeIsFloat;
3989 return vector_type_flags;
4004 if (qual_type->isAnyPointerType()) {
4005 if (qual_type->isObjCObjectPointerType())
4007 if (qual_type->getPointeeCXXRecordDecl())
4010 clang::QualType pointee_type(qual_type->getPointeeType());
4011 if (pointee_type->getPointeeCXXRecordDecl())
4013 if (pointee_type->isObjCObjectOrInterfaceType())
4015 if (pointee_type->isObjCClassType())
4017 if (pointee_type.getTypePtr() ==
4021 if (qual_type->isObjCObjectOrInterfaceType())
4023 if (qual_type->getAsCXXRecordDecl())
4025 switch (qual_type->getTypeClass()) {
4028 case clang::Type::Builtin:
4029 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4031 case clang::BuiltinType::Void:
4032 case clang::BuiltinType::Bool:
4033 case clang::BuiltinType::Char_U:
4034 case clang::BuiltinType::UChar:
4035 case clang::BuiltinType::WChar_U:
4036 case clang::BuiltinType::Char16:
4037 case clang::BuiltinType::Char32:
4038 case clang::BuiltinType::UShort:
4039 case clang::BuiltinType::UInt:
4040 case clang::BuiltinType::ULong:
4041 case clang::BuiltinType::ULongLong:
4042 case clang::BuiltinType::UInt128:
4043 case clang::BuiltinType::Char_S:
4044 case clang::BuiltinType::SChar:
4045 case clang::BuiltinType::WChar_S:
4046 case clang::BuiltinType::Short:
4047 case clang::BuiltinType::Int:
4048 case clang::BuiltinType::Long:
4049 case clang::BuiltinType::LongLong:
4050 case clang::BuiltinType::Int128:
4051 case clang::BuiltinType::Float:
4052 case clang::BuiltinType::Double:
4053 case clang::BuiltinType::LongDouble:
4056 case clang::BuiltinType::NullPtr:
4059 case clang::BuiltinType::ObjCId:
4060 case clang::BuiltinType::ObjCClass:
4061 case clang::BuiltinType::ObjCSel:
4064 case clang::BuiltinType::Dependent:
4065 case clang::BuiltinType::Overload:
4066 case clang::BuiltinType::BoundMember:
4067 case clang::BuiltinType::UnknownAny:
4071 case clang::Type::Typedef:
4072 return GetType(llvm::cast<clang::TypedefType>(qual_type)
4074 ->getUnderlyingType())
4084 return lldb::eTypeClassInvalid;
4086 clang::QualType qual_type =
4089 switch (qual_type->getTypeClass()) {
4090 case clang::Type::Atomic:
4091 case clang::Type::Auto:
4092 case clang::Type::CountAttributed:
4093 case clang::Type::Decltype:
4094 case clang::Type::Paren:
4095 case clang::Type::TypeOf:
4096 case clang::Type::TypeOfExpr:
4097 case clang::Type::Using:
4098 case clang::Type::PredefinedSugar:
4099 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4100 case clang::Type::UnaryTransform:
4102 case clang::Type::FunctionNoProto:
4103 return lldb::eTypeClassFunction;
4104 case clang::Type::FunctionProto:
4105 return lldb::eTypeClassFunction;
4106 case clang::Type::IncompleteArray:
4107 return lldb::eTypeClassArray;
4108 case clang::Type::VariableArray:
4109 return lldb::eTypeClassArray;
4110 case clang::Type::ConstantArray:
4111 return lldb::eTypeClassArray;
4112 case clang::Type::DependentSizedArray:
4113 return lldb::eTypeClassArray;
4114 case clang::Type::ArrayParameter:
4115 return lldb::eTypeClassArray;
4116 case clang::Type::DependentSizedExtVector:
4117 return lldb::eTypeClassVector;
4118 case clang::Type::DependentVector:
4119 return lldb::eTypeClassVector;
4120 case clang::Type::ExtVector:
4121 return lldb::eTypeClassVector;
4122 case clang::Type::Vector:
4123 return lldb::eTypeClassVector;
4124 case clang::Type::Builtin:
4126 case clang::Type::BitInt:
4127 case clang::Type::DependentBitInt:
4128 case clang::Type::OverflowBehavior:
4129 return lldb::eTypeClassBuiltin;
4130 case clang::Type::ObjCObjectPointer:
4131 return lldb::eTypeClassObjCObjectPointer;
4132 case clang::Type::BlockPointer:
4133 return lldb::eTypeClassBlockPointer;
4134 case clang::Type::Pointer:
4135 return lldb::eTypeClassPointer;
4136 case clang::Type::LValueReference:
4137 return lldb::eTypeClassReference;
4138 case clang::Type::RValueReference:
4139 return lldb::eTypeClassReference;
4140 case clang::Type::MemberPointer:
4141 return lldb::eTypeClassMemberPointer;
4142 case clang::Type::Complex:
4143 if (qual_type->isComplexType())
4144 return lldb::eTypeClassComplexFloat;
4146 return lldb::eTypeClassComplexInteger;
4147 case clang::Type::ObjCObject:
4148 return lldb::eTypeClassObjCObject;
4149 case clang::Type::ObjCInterface:
4150 return lldb::eTypeClassObjCInterface;
4151 case clang::Type::Record: {
4152 const clang::RecordType *record_type =
4153 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4154 const clang::RecordDecl *record_decl = record_type->getDecl();
4155 if (record_decl->isUnion())
4156 return lldb::eTypeClassUnion;
4157 else if (record_decl->isStruct())
4158 return lldb::eTypeClassStruct;
4160 return lldb::eTypeClassClass;
4162 case clang::Type::Enum:
4163 return lldb::eTypeClassEnumeration;
4164 case clang::Type::Typedef:
4165 return lldb::eTypeClassTypedef;
4166 case clang::Type::UnresolvedUsing:
4169 case clang::Type::Attributed:
4170 case clang::Type::BTFTagAttributed:
4172 case clang::Type::TemplateTypeParm:
4174 case clang::Type::SubstTemplateTypeParm:
4176 case clang::Type::SubstTemplateTypeParmPack:
4178 case clang::Type::InjectedClassName:
4180 case clang::Type::DependentName:
4182 case clang::Type::PackExpansion:
4185 case clang::Type::TemplateSpecialization:
4187 case clang::Type::DeducedTemplateSpecialization:
4189 case clang::Type::Pipe:
4193 case clang::Type::Decayed:
4195 case clang::Type::Adjusted:
4197 case clang::Type::ObjCTypeParam:
4200 case clang::Type::DependentAddressSpace:
4202 case clang::Type::MacroQualified:
4206 case clang::Type::ConstantMatrix:
4207 case clang::Type::DependentSizedMatrix:
4211 case clang::Type::PackIndexing:
4214 case clang::Type::HLSLAttributedResource:
4216 case clang::Type::HLSLInlineSpirv:
4218 case clang::Type::SubstBuiltinTemplatePack:
4222 return lldb::eTypeClassOther;
4227 return GetQualType(type).getQualifiers().getCVRQualifiers();
4239 const clang::Type *array_eletype =
4240 qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4245 return GetType(clang::QualType(array_eletype, 0));
4256 return GetType(ast_ctx.getConstantArrayType(
4257 qual_type, llvm::APInt(64, size),
nullptr,
4258 clang::ArraySizeModifier::Normal, 0));
4260 return GetType(ast_ctx.getIncompleteArrayType(
4261 qual_type, clang::ArraySizeModifier::Normal, 0));
4275 clang::QualType qual_type) {
4276 if (qual_type->isPointerType())
4277 qual_type = ast->getPointerType(
4279 else if (
const ConstantArrayType *arr =
4280 ast->getAsConstantArrayType(qual_type)) {
4281 qual_type = ast->getConstantArrayType(
4283 arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
4284 arr->getIndexTypeQualifiers().getAsOpaqueValue());
4286 qual_type = qual_type.getUnqualifiedType();
4287 qual_type.removeLocalConst();
4288 qual_type.removeLocalRestrict();
4289 qual_type.removeLocalVolatile();
4311 const clang::FunctionProtoType *func =
4314 return func->getNumParams();
4322 const clang::FunctionProtoType *func =
4323 llvm::dyn_cast<clang::FunctionProtoType>(
GetQualType(type));
4325 const uint32_t num_args = func->getNumParams();
4327 return GetType(func->getParamType(idx));
4337 const clang::FunctionProtoType *func =
4338 llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4340 return GetType(func->getReturnType());
4347 size_t num_functions = 0;
4350 switch (qual_type->getTypeClass()) {
4351 case clang::Type::Record:
4353 if (
const auto *cxx_record_decl = qual_type->getAsCXXRecordDecl())
4354 num_functions = std::distance(cxx_record_decl->method_begin(),
4355 cxx_record_decl->method_end());
4358 case clang::Type::ObjCObjectPointer: {
4359 const clang::ObjCObjectPointerType *objc_class_type =
4360 qual_type->castAs<clang::ObjCObjectPointerType>();
4361 const clang::ObjCInterfaceType *objc_interface_type =
4362 objc_class_type->getInterfaceType();
4363 if (objc_interface_type &&
4365 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4366 clang::ObjCInterfaceDecl *class_interface_decl =
4367 objc_interface_type->getDecl();
4368 if (class_interface_decl) {
4369 num_functions = std::distance(class_interface_decl->meth_begin(),
4370 class_interface_decl->meth_end());
4376 case clang::Type::ObjCObject:
4377 case clang::Type::ObjCInterface:
4379 const clang::ObjCObjectType *objc_class_type =
4380 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4381 if (objc_class_type) {
4382 clang::ObjCInterfaceDecl *class_interface_decl =
4383 objc_class_type->getInterface();
4384 if (class_interface_decl)
4385 num_functions = std::distance(class_interface_decl->meth_begin(),
4386 class_interface_decl->meth_end());
4395 return num_functions;
4407 switch (qual_type->getTypeClass()) {
4408 case clang::Type::Record:
4410 if (
const auto *cxx_record_decl = qual_type->getAsCXXRecordDecl()) {
4411 auto method_iter = cxx_record_decl->method_begin();
4412 auto method_end = cxx_record_decl->method_end();
4414 static_cast<size_t>(std::distance(method_iter, method_end))) {
4415 std::advance(method_iter, idx);
4416 clang::CXXMethodDecl *cxx_method_decl =
4417 method_iter->getCanonicalDecl();
4418 if (cxx_method_decl) {
4419 name = cxx_method_decl->getDeclName().getAsString();
4420 if (cxx_method_decl->isStatic())
4422 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4424 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4428 clang_type =
GetType(cxx_method_decl->getType());
4436 case clang::Type::ObjCObjectPointer: {
4437 const clang::ObjCObjectPointerType *objc_class_type =
4438 qual_type->castAs<clang::ObjCObjectPointerType>();
4439 const clang::ObjCInterfaceType *objc_interface_type =
4440 objc_class_type->getInterfaceType();
4441 if (objc_interface_type &&
4443 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
4444 clang::ObjCInterfaceDecl *class_interface_decl =
4445 objc_interface_type->getDecl();
4446 if (class_interface_decl) {
4447 auto method_iter = class_interface_decl->meth_begin();
4448 auto method_end = class_interface_decl->meth_end();
4450 static_cast<size_t>(std::distance(method_iter, method_end))) {
4451 std::advance(method_iter, idx);
4452 clang::ObjCMethodDecl *objc_method_decl =
4453 method_iter->getCanonicalDecl();
4454 if (objc_method_decl) {
4456 name = objc_method_decl->getSelector().getAsString();
4457 if (objc_method_decl->isClassMethod())
4468 case clang::Type::ObjCObject:
4469 case clang::Type::ObjCInterface:
4471 const clang::ObjCObjectType *objc_class_type =
4472 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4473 if (objc_class_type) {
4474 clang::ObjCInterfaceDecl *class_interface_decl =
4475 objc_class_type->getInterface();
4476 if (class_interface_decl) {
4477 auto method_iter = class_interface_decl->meth_begin();
4478 auto method_end = class_interface_decl->meth_end();
4480 static_cast<size_t>(std::distance(method_iter, method_end))) {
4481 std::advance(method_iter, idx);
4482 clang::ObjCMethodDecl *objc_method_decl =
4483 method_iter->getCanonicalDecl();
4484 if (objc_method_decl) {
4486 name = objc_method_decl->getSelector().getAsString();
4487 if (objc_method_decl->isClassMethod())
4520 return GetType(qual_type.getTypePtr()->getPointeeType());
4530 switch (qual_type.getDesugaredType(
getASTContext())->getTypeClass()) {
4531 case clang::Type::ObjCObject:
4532 case clang::Type::ObjCInterface:
4579 auto pauth = PointerAuthQualifier::fromOpaqueValue(payload);
4580 clang::QualType result =
4581 clang_ast.getPointerAuthType(
GetQualType(type), pauth);
4591 result.addVolatile();
4601 result.addRestrict();
4610 if (type && typedef_name && typedef_name[0]) {
4614 clang::DeclContext *decl_ctx =
4619 clang::TypedefDecl *decl =
4620 clang::TypedefDecl::CreateDeserialized(clang_ast, GlobalDeclID());
4621 decl->setDeclContext(decl_ctx);
4622 decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4623 decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4624 decl_ctx->addDecl(decl);
4627 clang::TagDecl *tdecl =
nullptr;
4628 if (!qual_type.isNull()) {
4629 if (
const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4630 tdecl = rt->getDecl();
4631 if (
const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4632 tdecl = et->getDecl();
4638 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4639 tdecl->setTypedefNameForAnonDecl(decl);
4641 decl->setAccess(clang::AS_public);
4644 NestedNameSpecifier Qualifier =
4645 clang::TypeName::getFullyQualifiedDeclaredContext(clang_ast, decl);
4647 clang_ast.getTypedefType(ElaboratedTypeKeyword::None, Qualifier, decl));
4655 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
4658 return GetType(typedef_type->getDecl()->getUnderlyingType());
4671 const FunctionType::ExtInfo generic_ext_info(
4680 QualType func_type = ast.getFunctionNoProtoType(ast.VoidTy, generic_ext_info);
4685const llvm::fltSemantics &
4688 const size_t bit_size = byte_size * 8;
4689 if (bit_size == ast.getTypeSize(ast.FloatTy))
4690 return ast.getFloatTypeSemantics(ast.FloatTy);
4691 else if (bit_size == ast.getTypeSize(ast.DoubleTy))
4692 return ast.getFloatTypeSemantics(ast.DoubleTy);
4694 bit_size == ast.getTypeSize(ast.Float128Ty))
4695 return ast.getFloatTypeSemantics(ast.Float128Ty);
4696 else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
4697 bit_size == llvm::APFloat::semanticsSizeInBits(
4698 ast.getFloatTypeSemantics(ast.LongDoubleTy)))
4699 return ast.getFloatTypeSemantics(ast.LongDoubleTy);
4700 else if (bit_size == ast.getTypeSize(ast.HalfTy))
4701 return ast.getFloatTypeSemantics(ast.HalfTy);
4702 else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4703 return ast.getFloatTypeSemantics(ast.Float128Ty);
4704 return llvm::APFloatBase::Bogus();
4707llvm::Expected<uint64_t>
4710 assert(qual_type->isObjCObjectOrInterfaceType());
4715 if (std::optional<uint64_t> bit_size =
4716 objc_runtime->GetTypeBitSize(
GetType(qual_type)))
4720 static bool g_printed =
false;
4725 llvm::outs() <<
"warning: trying to determine the size of type ";
4727 llvm::outs() <<
"without a valid ExecutionContext. this is not "
4728 "reliable. please file a bug against LLDB.\n";
4729 llvm::outs() <<
"backtrace:\n";
4730 llvm::sys::PrintStackTrace(llvm::outs());
4731 llvm::outs() <<
"\n";
4740llvm::Expected<uint64_t>
4743 const bool base_name_only =
true;
4745 return llvm::createStringError(
4746 "could not complete type %s",
4750 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4751 switch (type_class) {
4752 case clang::Type::ConstantArray:
4753 case clang::Type::FunctionProto:
4754 case clang::Type::Record:
4756 case clang::Type::ObjCInterface:
4757 case clang::Type::ObjCObject:
4759 case clang::Type::IncompleteArray: {
4760 const uint64_t bit_size =
getASTContext().getTypeSize(qual_type);
4763 qual_type->getArrayElementTypeNoTypeQual()
4764 ->getCanonicalTypeUnqualified());
4769 if (
const uint64_t bit_size =
getASTContext().getTypeSize(qual_type))
4773 return llvm::createStringError(
4774 "could not get size of type %s",
4778std::optional<size_t>
4792 switch (qual_type->getTypeClass()) {
4793 case clang::Type::Atomic:
4794 case clang::Type::Auto:
4795 case clang::Type::CountAttributed:
4796 case clang::Type::Decltype:
4797 case clang::Type::Paren:
4798 case clang::Type::Typedef:
4799 case clang::Type::TypeOf:
4800 case clang::Type::TypeOfExpr:
4801 case clang::Type::Using:
4802 case clang::Type::PredefinedSugar:
4803 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
4805 case clang::Type::UnaryTransform:
4808 case clang::Type::FunctionNoProto:
4809 case clang::Type::FunctionProto:
4812 case clang::Type::IncompleteArray:
4813 case clang::Type::VariableArray:
4814 case clang::Type::ArrayParameter:
4817 case clang::Type::ConstantArray:
4820 case clang::Type::DependentVector:
4821 case clang::Type::ExtVector:
4822 case clang::Type::Vector:
4825 case clang::Type::BitInt:
4826 case clang::Type::DependentBitInt:
4827 case clang::Type::OverflowBehavior:
4831 case clang::Type::Builtin:
4832 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
4833 case clang::BuiltinType::Void:
4836 case clang::BuiltinType::Char_S:
4837 case clang::BuiltinType::SChar:
4838 case clang::BuiltinType::WChar_S:
4839 case clang::BuiltinType::Short:
4840 case clang::BuiltinType::Int:
4841 case clang::BuiltinType::Long:
4842 case clang::BuiltinType::LongLong:
4843 case clang::BuiltinType::Int128:
4846 case clang::BuiltinType::Bool:
4847 case clang::BuiltinType::Char_U:
4848 case clang::BuiltinType::UChar:
4849 case clang::BuiltinType::WChar_U:
4850 case clang::BuiltinType::Char8:
4851 case clang::BuiltinType::Char16:
4852 case clang::BuiltinType::Char32:
4853 case clang::BuiltinType::UShort:
4854 case clang::BuiltinType::UInt:
4855 case clang::BuiltinType::ULong:
4856 case clang::BuiltinType::ULongLong:
4857 case clang::BuiltinType::UInt128:
4861 case clang::BuiltinType::ShortAccum:
4862 case clang::BuiltinType::Accum:
4863 case clang::BuiltinType::LongAccum:
4864 case clang::BuiltinType::UShortAccum:
4865 case clang::BuiltinType::UAccum:
4866 case clang::BuiltinType::ULongAccum:
4867 case clang::BuiltinType::ShortFract:
4868 case clang::BuiltinType::Fract:
4869 case clang::BuiltinType::LongFract:
4870 case clang::BuiltinType::UShortFract:
4871 case clang::BuiltinType::UFract:
4872 case clang::BuiltinType::ULongFract:
4873 case clang::BuiltinType::SatShortAccum:
4874 case clang::BuiltinType::SatAccum:
4875 case clang::BuiltinType::SatLongAccum:
4876 case clang::BuiltinType::SatUShortAccum:
4877 case clang::BuiltinType::SatUAccum:
4878 case clang::BuiltinType::SatULongAccum:
4879 case clang::BuiltinType::SatShortFract:
4880 case clang::BuiltinType::SatFract:
4881 case clang::BuiltinType::SatLongFract:
4882 case clang::BuiltinType::SatUShortFract:
4883 case clang::BuiltinType::SatUFract:
4884 case clang::BuiltinType::SatULongFract:
4887 case clang::BuiltinType::Half:
4888 case clang::BuiltinType::Float:
4889 case clang::BuiltinType::Float16:
4890 case clang::BuiltinType::Float128:
4891 case clang::BuiltinType::Double:
4892 case clang::BuiltinType::LongDouble:
4893 case clang::BuiltinType::BFloat16:
4894 case clang::BuiltinType::Ibm128:
4897 case clang::BuiltinType::ObjCClass:
4898 case clang::BuiltinType::ObjCId:
4899 case clang::BuiltinType::ObjCSel:
4902 case clang::BuiltinType::NullPtr:
4905 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4906 case clang::BuiltinType::Kind::BoundMember:
4907 case clang::BuiltinType::Kind::BuiltinFn:
4908 case clang::BuiltinType::Kind::Dependent:
4909 case clang::BuiltinType::Kind::OCLClkEvent:
4910 case clang::BuiltinType::Kind::OCLEvent:
4911 case clang::BuiltinType::Kind::OCLImage1dRO:
4912 case clang::BuiltinType::Kind::OCLImage1dWO:
4913 case clang::BuiltinType::Kind::OCLImage1dRW:
4914 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4915 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4916 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4917 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4918 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4919 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4920 case clang::BuiltinType::Kind::OCLImage2dRO:
4921 case clang::BuiltinType::Kind::OCLImage2dWO:
4922 case clang::BuiltinType::Kind::OCLImage2dRW:
4923 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4924 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4925 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4926 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4927 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4928 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4929 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4930 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4931 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4932 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4933 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4934 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4935 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4936 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4937 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4938 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4939 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4940 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4941 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4942 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4943 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4944 case clang::BuiltinType::Kind::OCLImage3dRO:
4945 case clang::BuiltinType::Kind::OCLImage3dWO:
4946 case clang::BuiltinType::Kind::OCLImage3dRW:
4947 case clang::BuiltinType::Kind::OCLQueue:
4948 case clang::BuiltinType::Kind::OCLReserveID:
4949 case clang::BuiltinType::Kind::OCLSampler:
4950 case clang::BuiltinType::Kind::HLSLResource:
4951 case clang::BuiltinType::Kind::ArraySection:
4952 case clang::BuiltinType::Kind::OMPArrayShaping:
4953 case clang::BuiltinType::Kind::OMPIterator:
4954 case clang::BuiltinType::Kind::Overload:
4955 case clang::BuiltinType::Kind::PseudoObject:
4956 case clang::BuiltinType::Kind::UnknownAny:
4959 case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload:
4960 case clang::BuiltinType::OCLIntelSubgroupAVCImePayload:
4961 case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload:
4962 case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload:
4963 case clang::BuiltinType::OCLIntelSubgroupAVCMceResult:
4964 case clang::BuiltinType::OCLIntelSubgroupAVCImeResult:
4965 case clang::BuiltinType::OCLIntelSubgroupAVCRefResult:
4966 case clang::BuiltinType::OCLIntelSubgroupAVCSicResult:
4967 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleReferenceStreamout:
4968 case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualReferenceStreamout:
4969 case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleReferenceStreamin:
4970 case clang::BuiltinType::OCLIntelSubgroupAVCImeDualReferenceStreamin:
4974 case clang::BuiltinType::VectorPair:
4975 case clang::BuiltinType::VectorQuad:
4976 case clang::BuiltinType::DMR1024:
4977 case clang::BuiltinType::DMR2048:
4981#define SVE_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
4982#include "clang/Basic/AArch64ACLETypes.def"
4986#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
4987#include "clang/Basic/RISCVVTypes.def"
4991 case clang::BuiltinType::WasmExternRef:
4994 case clang::BuiltinType::IncompleteMatrixIdx:
4997 case clang::BuiltinType::UnresolvedTemplate:
5001#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
5002 case clang::BuiltinType::Id:
5003#include "clang/Basic/AMDGPUTypes.def"
5009 case clang::Type::ObjCObjectPointer:
5010 case clang::Type::BlockPointer:
5011 case clang::Type::Pointer:
5012 case clang::Type::LValueReference:
5013 case clang::Type::RValueReference:
5014 case clang::Type::MemberPointer:
5016 case clang::Type::Complex: {
5018 if (qual_type->isComplexType())
5021 const clang::ComplexType *complex_type =
5022 qual_type->getAsComplexIntegerType();
5031 case clang::Type::ObjCInterface:
5033 case clang::Type::Record:
5035 case clang::Type::Enum:
5036 return qual_type->isUnsignedIntegerOrEnumerationType()
5039 case clang::Type::DependentSizedArray:
5040 case clang::Type::DependentSizedExtVector:
5041 case clang::Type::UnresolvedUsing:
5042 case clang::Type::Attributed:
5043 case clang::Type::BTFTagAttributed:
5044 case clang::Type::TemplateTypeParm:
5045 case clang::Type::SubstTemplateTypeParm:
5046 case clang::Type::SubstTemplateTypeParmPack:
5047 case clang::Type::InjectedClassName:
5048 case clang::Type::DependentName:
5049 case clang::Type::PackExpansion:
5050 case clang::Type::ObjCObject:
5052 case clang::Type::TemplateSpecialization:
5053 case clang::Type::DeducedTemplateSpecialization:
5054 case clang::Type::Adjusted:
5055 case clang::Type::Pipe:
5059 case clang::Type::Decayed:
5061 case clang::Type::ObjCTypeParam:
5064 case clang::Type::DependentAddressSpace:
5066 case clang::Type::MacroQualified:
5069 case clang::Type::ConstantMatrix:
5070 case clang::Type::DependentSizedMatrix:
5074 case clang::Type::PackIndexing:
5077 case clang::Type::HLSLAttributedResource:
5079 case clang::Type::HLSLInlineSpirv:
5081 case clang::Type::SubstBuiltinTemplatePack:
5094 switch (qual_type->getTypeClass()) {
5095 case clang::Type::Atomic:
5096 case clang::Type::Auto:
5097 case clang::Type::CountAttributed:
5098 case clang::Type::Decltype:
5099 case clang::Type::Paren:
5100 case clang::Type::Typedef:
5101 case clang::Type::TypeOf:
5102 case clang::Type::TypeOfExpr:
5103 case clang::Type::Using:
5104 case clang::Type::PredefinedSugar:
5105 llvm_unreachable(
"Handled in RemoveWrappingTypes!");
5106 case clang::Type::UnaryTransform:
5109 case clang::Type::FunctionNoProto:
5110 case clang::Type::FunctionProto:
5113 case clang::Type::IncompleteArray:
5114 case clang::Type::VariableArray:
5115 case clang::Type::ArrayParameter:
5118 case clang::Type::ConstantArray:
5121 case clang::Type::DependentVector:
5122 case clang::Type::ExtVector:
5123 case clang::Type::Vector:
5126 case clang::Type::BitInt:
5127 case clang::Type::DependentBitInt:
5128 case clang::Type::OverflowBehavior:
5132 case clang::Type::Builtin:
5133 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5134 case clang::BuiltinType::UnknownAny:
5135 case clang::BuiltinType::Void:
5136 case clang::BuiltinType::BoundMember:
5139 case clang::BuiltinType::Bool:
5141 case clang::BuiltinType::Char_S:
5142 case clang::BuiltinType::SChar:
5143 case clang::BuiltinType::WChar_S:
5144 case clang::BuiltinType::Char_U:
5145 case clang::BuiltinType::UChar:
5146 case clang::BuiltinType::WChar_U:
5148 case clang::BuiltinType::Char8:
5150 case clang::BuiltinType::Char16:
5152 case clang::BuiltinType::Char32:
5154 case clang::BuiltinType::UShort:
5156 case clang::BuiltinType::Short:
5158 case clang::BuiltinType::UInt:
5160 case clang::BuiltinType::Int:
5162 case clang::BuiltinType::ULong:
5164 case clang::BuiltinType::Long:
5166 case clang::BuiltinType::ULongLong:
5168 case clang::BuiltinType::LongLong:
5170 case clang::BuiltinType::UInt128:
5172 case clang::BuiltinType::Int128:
5174 case clang::BuiltinType::Half:
5175 case clang::BuiltinType::Float:
5176 case clang::BuiltinType::Double:
5177 case clang::BuiltinType::LongDouble:
5179 case clang::BuiltinType::Float128:
5185 case clang::Type::ObjCObjectPointer:
5187 case clang::Type::BlockPointer:
5189 case clang::Type::Pointer:
5191 case clang::Type::LValueReference:
5192 case clang::Type::RValueReference:
5194 case clang::Type::MemberPointer:
5196 case clang::Type::Complex: {
5197 if (qual_type->isComplexType())
5202 case clang::Type::ObjCInterface:
5204 case clang::Type::Record:
5206 case clang::Type::Enum:
5208 case clang::Type::DependentSizedArray:
5209 case clang::Type::DependentSizedExtVector:
5210 case clang::Type::UnresolvedUsing:
5211 case clang::Type::Attributed:
5212 case clang::Type::BTFTagAttributed:
5213 case clang::Type::TemplateTypeParm:
5214 case clang::Type::SubstTemplateTypeParm:
5215 case clang::Type::SubstTemplateTypeParmPack:
5216 case clang::Type::InjectedClassName:
5217 case clang::Type::DependentName:
5218 case clang::Type::PackExpansion:
5219 case clang::Type::ObjCObject:
5221 case clang::Type::TemplateSpecialization:
5222 case clang::Type::DeducedTemplateSpecialization:
5223 case clang::Type::Adjusted:
5224 case clang::Type::Pipe:
5228 case clang::Type::Decayed:
5230 case clang::Type::ObjCTypeParam:
5233 case clang::Type::DependentAddressSpace:
5235 case clang::Type::MacroQualified:
5239 case clang::Type::ConstantMatrix:
5240 case clang::Type::DependentSizedMatrix:
5244 case clang::Type::PackIndexing:
5247 case clang::Type::HLSLAttributedResource:
5249 case clang::Type::HLSLInlineSpirv:
5251 case clang::Type::SubstBuiltinTemplatePack:
5259 while (class_interface_decl) {
5260 if (class_interface_decl->ivar_size() > 0)
5263 class_interface_decl = class_interface_decl->getSuperClass();
5268static std::optional<SymbolFile::ArrayInfo>
5270 clang::QualType qual_type,
5272 if (qual_type->isIncompleteArrayType())
5273 if (std::optional<ClangASTMetadata> metadata =
5277 return std::nullopt;
5280llvm::Expected<uint32_t>
5282 bool omit_empty_base_classes,
5285 return llvm::createStringError(
"invalid clang type");
5287 uint32_t num_children = 0;
5289 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5290 switch (type_class) {
5291 case clang::Type::Builtin:
5292 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5293 case clang::BuiltinType::ObjCId:
5294 case clang::BuiltinType::ObjCClass:
5303 case clang::Type::Complex:
5305 case clang::Type::Record:
5307 const clang::RecordType *record_type =
5308 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5309 const clang::RecordDecl *record_decl =
5310 record_type->getDecl()->getDefinitionOrSelf();
5311 const clang::CXXRecordDecl *cxx_record_decl =
5312 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5316 num_children += std::distance(record_decl->field_begin(),
5317 record_decl->field_end());
5319 return llvm::createStringError(
5322 case clang::Type::ObjCObject:
5323 case clang::Type::ObjCInterface:
5325 const clang::ObjCObjectType *objc_class_type =
5326 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5327 assert(objc_class_type);
5328 if (objc_class_type) {
5329 clang::ObjCInterfaceDecl *class_interface_decl =
5330 objc_class_type->getInterface();
5332 if (class_interface_decl) {
5334 clang::ObjCInterfaceDecl *superclass_interface_decl =
5335 class_interface_decl->getSuperClass();
5336 if (superclass_interface_decl) {
5337 if (omit_empty_base_classes) {
5344 num_children += class_interface_decl->ivar_size();
5350 case clang::Type::LValueReference:
5351 case clang::Type::RValueReference:
5352 case clang::Type::ObjCObjectPointer: {
5355 uint32_t num_pointee_children = 0;
5357 auto num_children_or_err =
5358 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5359 if (!num_children_or_err)
5360 return num_children_or_err;
5361 num_pointee_children = *num_children_or_err;
5364 if (num_pointee_children == 0)
5367 num_children = num_pointee_children;
5370 case clang::Type::Vector:
5371 case clang::Type::ExtVector:
5373 llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5376 case clang::Type::ConstantArray:
5377 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())
5381 case clang::Type::IncompleteArray:
5382 if (
auto array_info =
5385 num_children = array_info->element_orders.size()
5386 ? array_info->element_orders.back().value_or(0)
5390 case clang::Type::Pointer: {
5391 const clang::PointerType *pointer_type =
5392 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5393 clang::QualType pointee_type(pointer_type->getPointeeType());
5395 uint32_t num_pointee_children = 0;
5397 auto num_children_or_err =
5398 pointee_clang_type.
GetNumChildren(omit_empty_base_classes, exe_ctx);
5399 if (!num_children_or_err)
5400 return num_children_or_err;
5401 num_pointee_children = *num_children_or_err;
5403 if (num_pointee_children == 0) {
5408 num_children = num_pointee_children;
5414 return num_children;
5421 if (name_ref.consume_front(
"unsigned _BitInt(") ||
5422 name_ref.consume_front(
"_BitInt(")) {
5424 if (name_ref.consumeInteger(10, bit_size))
5427 if (!name_ref.consume_front(
")"))
5431 name.
GetStringRef().starts_with(
"unsigned"), bit_size));
5440 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5441 if (type_class == clang::Type::Builtin) {
5442 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
5443 case clang::BuiltinType::Void:
5445 case clang::BuiltinType::Bool:
5447 case clang::BuiltinType::Char_S:
5449 case clang::BuiltinType::Char_U:
5451 case clang::BuiltinType::Char8:
5453 case clang::BuiltinType::Char16:
5455 case clang::BuiltinType::Char32:
5457 case clang::BuiltinType::UChar:
5459 case clang::BuiltinType::SChar:
5461 case clang::BuiltinType::WChar_S:
5463 case clang::BuiltinType::WChar_U:
5465 case clang::BuiltinType::Short:
5467 case clang::BuiltinType::UShort:
5469 case clang::BuiltinType::Int:
5471 case clang::BuiltinType::UInt:
5473 case clang::BuiltinType::Long:
5475 case clang::BuiltinType::ULong:
5477 case clang::BuiltinType::LongLong:
5479 case clang::BuiltinType::ULongLong:
5481 case clang::BuiltinType::Int128:
5483 case clang::BuiltinType::UInt128:
5486 case clang::BuiltinType::Half:
5488 case clang::BuiltinType::Float:
5490 case clang::BuiltinType::Double:
5492 case clang::BuiltinType::LongDouble:
5494 case clang::BuiltinType::Float128:
5497 case clang::BuiltinType::NullPtr:
5499 case clang::BuiltinType::ObjCId:
5501 case clang::BuiltinType::ObjCClass:
5503 case clang::BuiltinType::ObjCSel:
5517 const llvm::APSInt &value)>
const &callback) {
5518 const clang::EnumType *enum_type =
5521 const clang::EnumDecl *enum_decl =
5522 enum_type->getDecl()->getDefinitionOrSelf();
5526 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5527 for (enum_pos = enum_decl->enumerator_begin(),
5528 enum_end_pos = enum_decl->enumerator_end();
5529 enum_pos != enum_end_pos; ++enum_pos) {
5530 ConstString name(enum_pos->getNameAsString().c_str());
5531 if (!callback(integer_type, name, enum_pos->getInitVal()))
5538#pragma mark Aggregate Types
5546 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5547 switch (type_class) {
5548 case clang::Type::Record:
5550 const clang::RecordType *record_type =
5551 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5553 clang::RecordDecl *record_decl =
5554 record_type->getDecl()->getDefinition();
5556 count = std::distance(record_decl->field_begin(),
5557 record_decl->field_end());
5563 case clang::Type::ObjCObjectPointer: {
5564 const clang::ObjCObjectPointerType *objc_class_type =
5565 qual_type->castAs<clang::ObjCObjectPointerType>();
5566 const clang::ObjCInterfaceType *objc_interface_type =
5567 objc_class_type->getInterfaceType();
5568 if (objc_interface_type &&
5570 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5571 clang::ObjCInterfaceDecl *class_interface_decl =
5572 objc_interface_type->getDecl();
5573 if (class_interface_decl) {
5574 count = class_interface_decl->ivar_size();
5580 case clang::Type::ObjCObject:
5581 case clang::Type::ObjCInterface:
5583 const clang::ObjCObjectType *objc_class_type =
5584 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5585 if (objc_class_type) {
5586 clang::ObjCInterfaceDecl *class_interface_decl =
5587 objc_class_type->getInterface();
5589 if (class_interface_decl)
5590 count = class_interface_decl->ivar_size();
5603 clang::ObjCInterfaceDecl *class_interface_decl,
size_t idx,
5604 std::string &name, uint64_t *bit_offset_ptr,
5605 uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) {
5606 if (class_interface_decl) {
5607 if (idx < (class_interface_decl->ivar_size())) {
5608 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
5609 ivar_end = class_interface_decl->ivar_end();
5610 uint32_t ivar_idx = 0;
5612 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
5613 ++ivar_pos, ++ivar_idx) {
5614 if (ivar_idx == idx) {
5615 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
5617 clang::QualType ivar_qual_type(ivar_decl->getType());
5619 name.assign(ivar_decl->getNameAsString());
5621 if (bit_offset_ptr) {
5622 const clang::ASTRecordLayout &interface_layout =
5623 ast->getASTObjCInterfaceLayout(class_interface_decl);
5624 *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx);
5627 const bool is_bitfield = ivar_pos->isBitField();
5629 if (bitfield_bit_size_ptr) {
5630 *bitfield_bit_size_ptr = 0;
5632 if (is_bitfield && ast) {
5633 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5634 clang::Expr::EvalResult result;
5635 if (bitfield_bit_size_expr &&
5636 bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
5637 llvm::APSInt bitfield_apsint = result.Val.getInt();
5638 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5642 if (is_bitfield_ptr)
5643 *is_bitfield_ptr = is_bitfield;
5645 return ivar_qual_type.getAsOpaquePtr();
5654 size_t idx, std::string &name,
5655 uint64_t *bit_offset_ptr,
5656 uint32_t *bitfield_bit_size_ptr,
5657 bool *is_bitfield_ptr) {
5662 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5663 switch (type_class) {
5664 case clang::Type::Record:
5666 const clang::RecordType *record_type =
5667 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5668 const clang::RecordDecl *record_decl =
5669 record_type->getDecl()->getDefinitionOrSelf();
5670 uint32_t field_idx = 0;
5671 clang::RecordDecl::field_iterator field, field_end;
5672 for (field = record_decl->field_begin(),
5673 field_end = record_decl->field_end();
5674 field != field_end; ++field, ++field_idx) {
5675 if (idx == field_idx) {
5678 name.assign(field->getNameAsString());
5682 if (bit_offset_ptr) {
5683 const clang::ASTRecordLayout &record_layout =
5685 *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
5688 const bool is_bitfield = field->isBitField();
5690 if (bitfield_bit_size_ptr) {
5691 *bitfield_bit_size_ptr = 0;
5694 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5695 clang::Expr::EvalResult result;
5696 if (bitfield_bit_size_expr &&
5697 bitfield_bit_size_expr->EvaluateAsInt(result,
5699 llvm::APSInt bitfield_apsint = result.Val.getInt();
5700 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5704 if (is_bitfield_ptr)
5705 *is_bitfield_ptr = is_bitfield;
5707 return GetType(field->getType());
5713 case clang::Type::ObjCObjectPointer: {
5714 const clang::ObjCObjectPointerType *objc_class_type =
5715 qual_type->castAs<clang::ObjCObjectPointerType>();
5716 const clang::ObjCInterfaceType *objc_interface_type =
5717 objc_class_type->getInterfaceType();
5718 if (objc_interface_type &&
5720 const_cast<clang::ObjCInterfaceType *
>(objc_interface_type)))) {
5721 clang::ObjCInterfaceDecl *class_interface_decl =
5722 objc_interface_type->getDecl();
5723 if (class_interface_decl) {
5727 name, bit_offset_ptr, bitfield_bit_size_ptr,
5734 case clang::Type::ObjCObject:
5735 case clang::Type::ObjCInterface:
5737 const clang::ObjCObjectType *objc_class_type =
5738 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5739 assert(objc_class_type);
5740 if (objc_class_type) {
5741 clang::ObjCInterfaceDecl *class_interface_decl =
5742 objc_class_type->getInterface();
5746 name, bit_offset_ptr, bitfield_bit_size_ptr,
5762 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5763 switch (type_class) {
5764 case clang::Type::Record:
5766 const clang::CXXRecordDecl *cxx_record_decl =
5767 qual_type->getAsCXXRecordDecl();
5768 if (cxx_record_decl)
5769 count = cxx_record_decl->getNumBases();
5773 case clang::Type::ObjCObjectPointer:
5777 case clang::Type::ObjCObject:
5779 const clang::ObjCObjectType *objc_class_type =
5780 qual_type->getAsObjCQualifiedInterfaceType();
5781 if (objc_class_type) {
5782 clang::ObjCInterfaceDecl *class_interface_decl =
5783 objc_class_type->getInterface();
5785 if (class_interface_decl && class_interface_decl->getSuperClass())
5790 case clang::Type::ObjCInterface:
5792 const clang::ObjCInterfaceType *objc_interface_type =
5793 qual_type->getAs<clang::ObjCInterfaceType>();
5794 if (objc_interface_type) {
5795 clang::ObjCInterfaceDecl *class_interface_decl =
5796 objc_interface_type->getInterface();
5798 if (class_interface_decl && class_interface_decl->getSuperClass())
5814 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5815 switch (type_class) {
5816 case clang::Type::Record:
5818 const clang::CXXRecordDecl *cxx_record_decl =
5819 qual_type->getAsCXXRecordDecl();
5820 if (cxx_record_decl)
5821 count = cxx_record_decl->getNumVBases();
5834 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5835 switch (type_class) {
5836 case clang::Type::Record:
5838 const clang::CXXRecordDecl *cxx_record_decl =
5839 qual_type->getAsCXXRecordDecl();
5840 if (cxx_record_decl) {
5841 uint32_t curr_idx = 0;
5842 clang::CXXRecordDecl::base_class_const_iterator base_class,
5844 for (base_class = cxx_record_decl->bases_begin(),
5845 base_class_end = cxx_record_decl->bases_end();
5846 base_class != base_class_end; ++base_class, ++curr_idx) {
5847 if (curr_idx == idx) {
5848 if (bit_offset_ptr) {
5849 const clang::ASTRecordLayout &record_layout =
5851 const clang::CXXRecordDecl *base_class_decl =
5852 llvm::cast<clang::CXXRecordDecl>(
5853 base_class->getType()
5854 ->castAs<clang::RecordType>()
5856 if (base_class->isVirtual())
5858 record_layout.getVBaseClassOffset(base_class_decl)
5863 record_layout.getBaseClassOffset(base_class_decl)
5867 return GetType(base_class->getType());
5874 case clang::Type::ObjCObjectPointer:
5877 case clang::Type::ObjCObject:
5879 const clang::ObjCObjectType *objc_class_type =
5880 qual_type->getAsObjCQualifiedInterfaceType();
5881 if (objc_class_type) {
5882 clang::ObjCInterfaceDecl *class_interface_decl =
5883 objc_class_type->getInterface();
5885 if (class_interface_decl) {
5886 clang::ObjCInterfaceDecl *superclass_interface_decl =
5887 class_interface_decl->getSuperClass();
5888 if (superclass_interface_decl) {
5890 *bit_offset_ptr = 0;
5892 superclass_interface_decl));
5898 case clang::Type::ObjCInterface:
5900 const clang::ObjCObjectType *objc_interface_type =
5901 qual_type->getAs<clang::ObjCInterfaceType>();
5902 if (objc_interface_type) {
5903 clang::ObjCInterfaceDecl *class_interface_decl =
5904 objc_interface_type->getInterface();
5906 if (class_interface_decl) {
5907 clang::ObjCInterfaceDecl *superclass_interface_decl =
5908 class_interface_decl->getSuperClass();
5909 if (superclass_interface_decl) {
5911 *bit_offset_ptr = 0;
5913 superclass_interface_decl));
5929 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5930 switch (type_class) {
5931 case clang::Type::Record:
5933 const clang::CXXRecordDecl *cxx_record_decl =
5934 qual_type->getAsCXXRecordDecl();
5935 if (cxx_record_decl) {
5936 uint32_t curr_idx = 0;
5937 clang::CXXRecordDecl::base_class_const_iterator base_class,
5939 for (base_class = cxx_record_decl->vbases_begin(),
5940 base_class_end = cxx_record_decl->vbases_end();
5941 base_class != base_class_end; ++base_class, ++curr_idx) {
5942 if (curr_idx == idx) {
5943 if (bit_offset_ptr) {
5944 const clang::ASTRecordLayout &record_layout =
5946 const clang::CXXRecordDecl *base_class_decl =
5947 llvm::cast<clang::CXXRecordDecl>(
5948 base_class->getType()
5949 ->castAs<clang::RecordType>()
5952 record_layout.getVBaseClassOffset(base_class_decl)
5956 return GetType(base_class->getType());
5971 llvm::StringRef name) {
5973 switch (qual_type->getTypeClass()) {
5974 case clang::Type::Record: {
5978 const clang::RecordType *record_type =
5979 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5980 const clang::RecordDecl *record_decl =
5981 record_type->getDecl()->getDefinitionOrSelf();
5983 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
5984 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
5985 auto *var_decl = dyn_cast<clang::VarDecl>(decl);
5986 if (!var_decl || var_decl->getStorageClass() != clang::SC_Static)
6010 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6011 switch (type_class) {
6012 case clang::Type::Builtin:
6013 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
6014 case clang::BuiltinType::UnknownAny:
6015 case clang::BuiltinType::Void:
6016 case clang::BuiltinType::NullPtr:
6017 case clang::BuiltinType::OCLEvent:
6018 case clang::BuiltinType::OCLImage1dRO:
6019 case clang::BuiltinType::OCLImage1dWO:
6020 case clang::BuiltinType::OCLImage1dRW:
6021 case clang::BuiltinType::OCLImage1dArrayRO:
6022 case clang::BuiltinType::OCLImage1dArrayWO:
6023 case clang::BuiltinType::OCLImage1dArrayRW:
6024 case clang::BuiltinType::OCLImage1dBufferRO:
6025 case clang::BuiltinType::OCLImage1dBufferWO:
6026 case clang::BuiltinType::OCLImage1dBufferRW:
6027 case clang::BuiltinType::OCLImage2dRO:
6028 case clang::BuiltinType::OCLImage2dWO:
6029 case clang::BuiltinType::OCLImage2dRW:
6030 case clang::BuiltinType::OCLImage2dArrayRO:
6031 case clang::BuiltinType::OCLImage2dArrayWO:
6032 case clang::BuiltinType::OCLImage2dArrayRW:
6033 case clang::BuiltinType::OCLImage3dRO:
6034 case clang::BuiltinType::OCLImage3dWO:
6035 case clang::BuiltinType::OCLImage3dRW:
6036 case clang::BuiltinType::OCLSampler:
6037 case clang::BuiltinType::HLSLResource:
6039 case clang::BuiltinType::Bool:
6040 case clang::BuiltinType::Char_U:
6041 case clang::BuiltinType::UChar:
6042 case clang::BuiltinType::WChar_U:
6043 case clang::BuiltinType::Char16:
6044 case clang::BuiltinType::Char32:
6045 case clang::BuiltinType::UShort:
6046 case clang::BuiltinType::UInt:
6047 case clang::BuiltinType::ULong:
6048 case clang::BuiltinType::ULongLong:
6049 case clang::BuiltinType::UInt128:
6050 case clang::BuiltinType::Char_S:
6051 case clang::BuiltinType::SChar:
6052 case clang::BuiltinType::WChar_S:
6053 case clang::BuiltinType::Short:
6054 case clang::BuiltinType::Int:
6055 case clang::BuiltinType::Long:
6056 case clang::BuiltinType::LongLong:
6057 case clang::BuiltinType::Int128:
6058 case clang::BuiltinType::Float:
6059 case clang::BuiltinType::Double:
6060 case clang::BuiltinType::LongDouble:
6061 case clang::BuiltinType::Float128:
6062 case clang::BuiltinType::Dependent:
6063 case clang::BuiltinType::Overload:
6064 case clang::BuiltinType::ObjCId:
6065 case clang::BuiltinType::ObjCClass:
6066 case clang::BuiltinType::ObjCSel:
6067 case clang::BuiltinType::BoundMember:
6068 case clang::BuiltinType::Half:
6069 case clang::BuiltinType::ARCUnbridgedCast:
6070 case clang::BuiltinType::PseudoObject:
6071 case clang::BuiltinType::BuiltinFn:
6072 case clang::BuiltinType::ArraySection:
6079 case clang::Type::Complex:
6081 case clang::Type::Pointer:
6083 case clang::Type::BlockPointer:
6086 case clang::Type::LValueReference:
6088 case clang::Type::RValueReference:
6090 case clang::Type::MemberPointer:
6092 case clang::Type::ConstantArray:
6094 case clang::Type::IncompleteArray:
6096 case clang::Type::VariableArray:
6098 case clang::Type::DependentSizedArray:
6100 case clang::Type::DependentSizedExtVector:
6102 case clang::Type::Vector:
6104 case clang::Type::ExtVector:
6106 case clang::Type::FunctionProto:
6108 case clang::Type::FunctionNoProto:
6110 case clang::Type::UnresolvedUsing:
6112 case clang::Type::Record:
6114 case clang::Type::Enum:
6116 case clang::Type::TemplateTypeParm:
6118 case clang::Type::SubstTemplateTypeParm:
6120 case clang::Type::TemplateSpecialization:
6122 case clang::Type::InjectedClassName:
6124 case clang::Type::DependentName:
6126 case clang::Type::ObjCObject:
6128 case clang::Type::ObjCInterface:
6130 case clang::Type::ObjCObjectPointer:
6140 std::string &deref_name, uint32_t &deref_byte_size,
6141 int32_t &deref_byte_offset,
ValueObject *valobj, uint64_t &language_flags) {
6145 return llvm::createStringError(
"not a pointer, reference or array type");
6146 uint32_t child_bitfield_bit_size = 0;
6147 uint32_t child_bitfield_bit_offset = 0;
6148 bool child_is_base_class;
6149 bool child_is_deref_of_parent;
6151 type, exe_ctx, 0,
false,
true,
false, deref_name, deref_byte_size,
6152 deref_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
6153 child_is_base_class, child_is_deref_of_parent, valobj, language_flags);
6158 bool transparent_pointers,
bool omit_empty_base_classes,
6159 bool ignore_array_bounds, std::string &child_name,
6160 uint32_t &child_byte_size, int32_t &child_byte_offset,
6161 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6162 bool &child_is_base_class,
bool &child_is_deref_of_parent,
6165 return llvm::createStringError(
"invalid type");
6167 auto get_exe_scope = [&exe_ctx]() {
6171 clang::QualType parent_qual_type(
6173 const clang::Type::TypeClass parent_type_class =
6174 parent_qual_type->getTypeClass();
6175 child_bitfield_bit_size = 0;
6176 child_bitfield_bit_offset = 0;
6177 child_is_base_class =
false;
6180 auto num_children_or_err =
6182 if (!num_children_or_err)
6183 return num_children_or_err.takeError();
6185 const bool idx_is_valid = idx < *num_children_or_err;
6187 switch (parent_type_class) {
6188 case clang::Type::Builtin:
6190 return llvm::createStringError(
"invalid index");
6192 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) {
6193 case clang::BuiltinType::ObjCId:
6194 case clang::BuiltinType::ObjCClass:
6205 case clang::Type::Record: {
6207 return llvm::createStringError(
"invalid index");
6209 return llvm::createStringError(
"cannot complete type");
6211 const clang::RecordType *record_type =
6212 llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6213 const clang::RecordDecl *record_decl =
6214 record_type->getDecl()->getDefinitionOrSelf();
6215 const clang::ASTRecordLayout &record_layout =
6217 uint32_t child_idx = 0;
6219 const clang::CXXRecordDecl *cxx_record_decl =
6220 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6221 if (cxx_record_decl) {
6223 clang::CXXRecordDecl::base_class_const_iterator base_class,
6225 for (base_class = cxx_record_decl->bases_begin(),
6226 base_class_end = cxx_record_decl->bases_end();
6227 base_class != base_class_end; ++base_class) {
6228 const clang::CXXRecordDecl *base_class_decl =
nullptr;
6231 if (omit_empty_base_classes) {
6233 llvm::cast<clang::CXXRecordDecl>(
6234 base_class->getType()->getAs<clang::RecordType>()->getDecl())
6235 ->getDefinitionOrSelf();
6240 if (idx == child_idx) {
6241 if (base_class_decl ==
nullptr)
6242 base_class_decl = llvm::cast<clang::CXXRecordDecl>(
6243 base_class->getType()
6244 ->getAs<clang::RecordType>()
6246 ->getDefinitionOrSelf();
6248 if (base_class->isVirtual()) {
6249 bool handled =
false;
6251 clang::VTableContextBase *vtable_ctx =
6255 cxx_record_decl, base_class_decl,
6259 bit_offset = record_layout.getVBaseClassOffset(base_class_decl)
6263 bit_offset = record_layout.getBaseClassOffset(base_class_decl)
6268 child_byte_offset = bit_offset / 8;
6271 auto size_or_err = base_class_clang_type.
GetBitSize(get_exe_scope());
6273 return llvm::joinErrors(
6274 llvm::createStringError(
"no size info for base class"),
6275 size_or_err.takeError());
6277 uint64_t base_class_clang_type_bit_size = *size_or_err;
6280 assert(base_class_clang_type_bit_size % 8 == 0);
6281 child_byte_size = base_class_clang_type_bit_size / 8;
6282 child_is_base_class =
true;
6283 return base_class_clang_type;
6291 uint32_t field_idx = 0;
6292 clang::RecordDecl::field_iterator field, field_end;
6293 for (field = record_decl->field_begin(),
6294 field_end = record_decl->field_end();
6295 field != field_end; ++field, ++field_idx, ++child_idx) {
6296 if (idx == child_idx) {
6299 child_name.assign(field->getNameAsString());
6304 assert(field_idx < record_layout.getFieldCount());
6305 auto size_or_err = field_clang_type.
GetByteSize(get_exe_scope());
6307 return llvm::joinErrors(
6308 llvm::createStringError(
"no size info for field"),
6309 size_or_err.takeError());
6311 child_byte_size = *size_or_err;
6312 const uint32_t child_bit_size = child_byte_size * 8;
6316 bit_offset = record_layout.getFieldOffset(field_idx);
6318 child_bitfield_bit_offset = bit_offset % child_bit_size;
6319 const uint32_t child_bit_offset =
6320 bit_offset - child_bitfield_bit_offset;
6321 child_byte_offset = child_bit_offset / 8;
6323 child_byte_offset = bit_offset / 8;
6326 return field_clang_type;
6330 case clang::Type::ObjCObject:
6331 case clang::Type::ObjCInterface: {
6333 return llvm::createStringError(
"invalid index");
6335 return llvm::createStringError(
"cannot complete type");
6337 const clang::ObjCObjectType *objc_class_type =
6338 llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6339 assert(objc_class_type);
6340 if (!objc_class_type)
6341 return llvm::createStringError(
"unexpected object type");
6343 uint32_t child_idx = 0;
6344 clang::ObjCInterfaceDecl *class_interface_decl =
6345 objc_class_type->getInterface();
6347 if (!class_interface_decl)
6348 return llvm::createStringError(
"cannot get interface decl");
6350 const clang::ASTRecordLayout &interface_layout =
6351 getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
6352 clang::ObjCInterfaceDecl *superclass_interface_decl =
6353 class_interface_decl->getSuperClass();
6354 if (superclass_interface_decl) {
6355 if (omit_empty_base_classes) {
6357 getASTContext().getObjCInterfaceType(superclass_interface_decl));
6358 if (llvm::expectedToOptional(base_class_clang_type.
GetNumChildren(
6359 omit_empty_base_classes, exe_ctx))
6362 clang::QualType ivar_qual_type(
getASTContext().getObjCInterfaceType(
6363 superclass_interface_decl));
6365 child_name.assign(superclass_interface_decl->getNameAsString());
6367 clang::TypeInfo ivar_type_info =
6370 child_byte_size = ivar_type_info.Width / 8;
6371 child_byte_offset = 0;
6372 child_is_base_class =
true;
6374 return GetType(ivar_qual_type);
6383 const uint32_t superclass_idx = child_idx;
6385 if (idx < (child_idx + class_interface_decl->ivar_size())) {
6386 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6387 ivar_end = class_interface_decl->ivar_end();
6389 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end;
6391 if (child_idx == idx) {
6392 clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6394 clang::QualType ivar_qual_type(ivar_decl->getType());
6396 child_name.assign(ivar_decl->getNameAsString());
6398 clang::TypeInfo ivar_type_info =
6401 child_byte_size = ivar_type_info.Width / 8;
6417 if (objc_runtime !=
nullptr) {
6420 parent_ast_type, ivar_decl->getNameAsString().c_str());
6428 if (child_byte_offset ==
6431 interface_layout.getFieldOffset(child_idx - superclass_idx);
6432 child_byte_offset = bit_offset / 8;
6444 interface_layout.getFieldOffset(child_idx - superclass_idx);
6446 child_bitfield_bit_offset = bit_offset % 8;
6448 return GetType(ivar_qual_type);
6455 case clang::Type::ObjCObjectPointer: {
6457 return llvm::createStringError(
"invalid index");
6461 child_is_deref_of_parent =
false;
6462 bool tmp_child_is_deref_of_parent =
false;
6464 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6465 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6466 child_bitfield_bit_size, child_bitfield_bit_offset,
6467 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6470 child_is_deref_of_parent =
true;
6471 const char *parent_name =
6474 child_name.assign(1,
'*');
6475 child_name += parent_name;
6480 auto size_or_err = pointee_clang_type.
GetByteSize(get_exe_scope());
6482 return size_or_err.takeError();
6483 child_byte_size = *size_or_err;
6484 child_byte_offset = 0;
6485 return pointee_clang_type;
6490 case clang::Type::Vector:
6491 case clang::Type::ExtVector: {
6493 return llvm::createStringError(
"invalid index");
6494 const clang::VectorType *array =
6495 llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6497 return llvm::createStringError(
"unexpected vector type");
6501 return llvm::createStringError(
"cannot complete type");
6503 char element_name[64];
6504 ::snprintf(element_name,
sizeof(element_name),
"[%" PRIu64
"]",
6505 static_cast<uint64_t
>(idx));
6506 child_name.assign(element_name);
6507 auto size_or_err = element_type.
GetByteSize(get_exe_scope());
6509 return size_or_err.takeError();
6510 child_byte_size = *size_or_err;
6511 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6512 return element_type;
6514 case clang::Type::ConstantArray:
6515 case clang::Type::IncompleteArray: {
6516 if (!ignore_array_bounds && !idx_is_valid)
6517 return llvm::createStringError(
"invalid index");
6518 const clang::ArrayType *array =
GetQualType(type)->getAsArrayTypeUnsafe();
6520 return llvm::createStringError(
"unexpected array type");
6523 return llvm::createStringError(
"cannot complete type");
6525 child_name = std::string(llvm::formatv(
"[{0}]", idx));
6526 auto size_or_err = element_type.
GetByteSize(get_exe_scope());
6528 return size_or_err.takeError();
6529 child_byte_size = *size_or_err;
6530 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6531 return element_type;
6533 case clang::Type::Pointer: {
6538 return llvm::createStringError(
"cannot dereference void *");
6541 child_is_deref_of_parent =
false;
6542 bool tmp_child_is_deref_of_parent =
false;
6544 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6545 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6546 child_bitfield_bit_size, child_bitfield_bit_offset,
6547 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6550 child_is_deref_of_parent =
true;
6554 child_name.assign(1,
'*');
6555 child_name += parent_name;
6560 auto size_or_err = pointee_clang_type.
GetByteSize(get_exe_scope());
6562 return size_or_err.takeError();
6563 child_byte_size = *size_or_err;
6564 child_byte_offset = 0;
6565 return pointee_clang_type;
6570 case clang::Type::LValueReference:
6571 case clang::Type::RValueReference: {
6573 return llvm::createStringError(
"invalid index");
6574 const clang::ReferenceType *reference_type =
6575 llvm::cast<clang::ReferenceType>(
6579 child_is_deref_of_parent =
false;
6580 bool tmp_child_is_deref_of_parent =
false;
6582 exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
6583 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6584 child_bitfield_bit_size, child_bitfield_bit_offset,
6585 child_is_base_class, tmp_child_is_deref_of_parent, valobj,
6590 child_name.assign(1,
'&');
6591 child_name += parent_name;
6596 auto size_or_err = pointee_clang_type.
GetByteSize(get_exe_scope());
6598 return size_or_err.takeError();
6599 child_byte_size = *size_or_err;
6600 child_byte_offset = 0;
6601 return pointee_clang_type;
6608 return llvm::createStringError(
"cannot enumerate children");
6612 const clang::RecordDecl *record_decl,
6613 const clang::CXXBaseSpecifier *base_spec,
6614 bool omit_empty_base_classes) {
6615 uint32_t child_idx = 0;
6617 const clang::CXXRecordDecl *cxx_record_decl =
6618 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6620 if (cxx_record_decl) {
6621 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6622 for (base_class = cxx_record_decl->bases_begin(),
6623 base_class_end = cxx_record_decl->bases_end();
6624 base_class != base_class_end; ++base_class) {
6625 if (omit_empty_base_classes) {
6630 if (base_class == base_spec)
6640 const clang::RecordDecl *record_decl, clang::NamedDecl *canonical_decl,
6641 bool omit_empty_base_classes) {
6643 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6644 omit_empty_base_classes);
6646 clang::RecordDecl::field_iterator field, field_end;
6647 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6648 field != field_end; ++field, ++child_idx) {
6649 if (field->getCanonicalDecl() == canonical_decl)
6691 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
6692 if (type && !name.empty()) {
6694 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6695 switch (type_class) {
6696 case clang::Type::Record:
6698 const clang::RecordType *record_type =
6699 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6700 const clang::RecordDecl *record_decl =
6701 record_type->getDecl()->getDefinitionOrSelf();
6703 assert(record_decl);
6704 uint32_t child_idx = 0;
6706 const clang::CXXRecordDecl *cxx_record_decl =
6707 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6710 clang::RecordDecl::field_iterator field, field_end;
6711 for (field = record_decl->field_begin(),
6712 field_end = record_decl->field_end();
6713 field != field_end; ++field, ++child_idx) {
6714 llvm::StringRef field_name = field->getName();
6715 if (field_name.empty()) {
6717 std::vector<uint32_t> save_indices = child_indexes;
6718 child_indexes.push_back(
6720 cxx_record_decl, omit_empty_base_classes));
6722 name, omit_empty_base_classes, child_indexes))
6723 return child_indexes.size();
6724 child_indexes = std::move(save_indices);
6725 }
else if (field_name == name) {
6727 child_indexes.push_back(
6729 cxx_record_decl, omit_empty_base_classes));
6730 return child_indexes.size();
6734 if (cxx_record_decl) {
6735 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6738 clang::IdentifierInfo &ident_ref =
getASTContext().Idents.get(name);
6739 clang::DeclarationName decl_name(&ident_ref);
6741 clang::CXXBasePaths paths;
6742 if (cxx_record_decl->lookupInBases(
6743 [decl_name](
const clang::CXXBaseSpecifier *specifier,
6744 clang::CXXBasePath &path) {
6745 CXXRecordDecl *record =
6746 specifier->getType()->getAsCXXRecordDecl();
6747 auto r = record->lookup(decl_name);
6748 path.Decls = r.begin();
6752 clang::CXXBasePaths::const_paths_iterator path,
6753 path_end = paths.end();
6754 for (path = paths.begin(); path != path_end; ++path) {
6755 const size_t num_path_elements = path->size();
6756 for (
size_t e = 0; e < num_path_elements; ++e) {
6757 clang::CXXBasePathElement elem = (*path)[e];
6760 omit_empty_base_classes);
6762 child_indexes.clear();
6765 child_indexes.push_back(child_idx);
6766 parent_record_decl = elem.Base->getType()
6767 ->castAs<clang::RecordType>()
6769 ->getDefinitionOrSelf();
6772 for (clang::DeclContext::lookup_iterator I = path->Decls, E;
6775 parent_record_decl, *I, omit_empty_base_classes);
6777 child_indexes.clear();
6780 child_indexes.push_back(child_idx);
6784 return child_indexes.size();
6790 case clang::Type::ObjCObject:
6791 case clang::Type::ObjCInterface:
6793 llvm::StringRef name_sref(name);
6794 const clang::ObjCObjectType *objc_class_type =
6795 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6796 assert(objc_class_type);
6797 if (objc_class_type) {
6798 uint32_t child_idx = 0;
6799 clang::ObjCInterfaceDecl *class_interface_decl =
6800 objc_class_type->getInterface();
6802 if (class_interface_decl) {
6803 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6804 ivar_end = class_interface_decl->ivar_end();
6805 clang::ObjCInterfaceDecl *superclass_interface_decl =
6806 class_interface_decl->getSuperClass();
6808 for (ivar_pos = class_interface_decl->ivar_begin();
6809 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6810 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6812 if (ivar_decl->getName() == name_sref) {
6813 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6814 (omit_empty_base_classes &&
6818 child_indexes.push_back(child_idx);
6819 return child_indexes.size();
6823 if (superclass_interface_decl) {
6827 child_indexes.push_back(0);
6831 superclass_interface_decl));
6833 name, omit_empty_base_classes, child_indexes)) {
6836 return child_indexes.size();
6841 child_indexes.pop_back();
6848 case clang::Type::ObjCObjectPointer: {
6850 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6851 ->getPointeeType());
6853 name, omit_empty_base_classes, child_indexes);
6856 case clang::Type::LValueReference:
6857 case clang::Type::RValueReference: {
6858 const clang::ReferenceType *reference_type =
6859 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6860 clang::QualType pointee_type(reference_type->getPointeeType());
6865 name, omit_empty_base_classes, child_indexes);
6869 case clang::Type::Pointer: {
6874 name, omit_empty_base_classes, child_indexes);
6889llvm::Expected<uint32_t>
6891 llvm::StringRef name,
6892 bool omit_empty_base_classes) {
6893 if (type && !name.empty()) {
6896 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6898 switch (type_class) {
6899 case clang::Type::Record:
6901 const clang::RecordType *record_type =
6902 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6903 const clang::RecordDecl *record_decl =
6904 record_type->getDecl()->getDefinitionOrSelf();
6906 assert(record_decl);
6907 uint32_t child_idx = 0;
6909 const clang::CXXRecordDecl *cxx_record_decl =
6910 llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6912 if (cxx_record_decl) {
6913 clang::CXXRecordDecl::base_class_const_iterator base_class,
6915 for (base_class = cxx_record_decl->bases_begin(),
6916 base_class_end = cxx_record_decl->bases_end();
6917 base_class != base_class_end; ++base_class) {
6919 clang::CXXRecordDecl *base_class_decl =
6920 llvm::cast<clang::CXXRecordDecl>(
6921 base_class->getType()
6922 ->castAs<clang::RecordType>()
6924 ->getDefinitionOrSelf();
6925 if (omit_empty_base_classes &&
6930 std::string base_class_type_name(
6932 if (base_class_type_name == name)
6939 clang::RecordDecl::field_iterator field, field_end;
6940 for (field = record_decl->field_begin(),
6941 field_end = record_decl->field_end();
6942 field != field_end; ++field, ++child_idx) {
6943 if (field->getName() == name)
6949 case clang::Type::ObjCObject:
6950 case clang::Type::ObjCInterface:
6952 const clang::ObjCObjectType *objc_class_type =
6953 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6954 assert(objc_class_type);
6955 if (objc_class_type) {
6956 uint32_t child_idx = 0;
6957 clang::ObjCInterfaceDecl *class_interface_decl =
6958 objc_class_type->getInterface();
6960 if (class_interface_decl) {
6961 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos,
6962 ivar_end = class_interface_decl->ivar_end();
6963 clang::ObjCInterfaceDecl *superclass_interface_decl =
6964 class_interface_decl->getSuperClass();
6966 for (ivar_pos = class_interface_decl->ivar_begin();
6967 ivar_pos != ivar_end; ++ivar_pos, ++child_idx) {
6968 const clang::ObjCIvarDecl *ivar_decl = *ivar_pos;
6970 if (ivar_decl->getName() == name) {
6971 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6972 (omit_empty_base_classes &&
6980 if (superclass_interface_decl) {
6981 if (superclass_interface_decl->getName() == name)
6989 case clang::Type::ObjCObjectPointer: {
6991 llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
6992 ->getPointeeType());
6994 name, omit_empty_base_classes);
6997 case clang::Type::LValueReference:
6998 case clang::Type::RValueReference: {
6999 const clang::ReferenceType *reference_type =
7000 llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
7005 omit_empty_base_classes);
7009 case clang::Type::Pointer: {
7010 const clang::PointerType *pointer_type =
7011 llvm::cast<clang::PointerType>(qual_type.getTypePtr());
7016 omit_empty_base_classes);
7024 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
7029 llvm::StringRef name) {
7030 if (!type || name.empty())
7034 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7036 switch (type_class) {
7037 case clang::Type::Record: {
7040 const clang::RecordType *record_type =
7041 llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7042 const clang::RecordDecl *record_decl =
7043 record_type->getDecl()->getDefinitionOrSelf();
7045 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7046 for (NamedDecl *decl : record_decl->lookup(decl_name)) {
7047 if (
auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
7049 if (
auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl))
7051 ElaboratedTypeKeyword::None, std::nullopt,
7067 if (
auto *cxx_record_decl = dyn_cast<clang::TagType>(clang_type))
7068 return isa<clang::ClassTemplateSpecializationDecl>(
7069 cxx_record_decl->getDecl());
7080 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7081 switch (type_class) {
7082 case clang::Type::Record:
7084 const clang::CXXRecordDecl *cxx_record_decl =
7085 qual_type->getAsCXXRecordDecl();
7086 if (cxx_record_decl) {
7087 const clang::ClassTemplateSpecializationDecl *template_decl =
7088 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7090 if (template_decl) {
7091 const auto &template_arg_list = template_decl->getTemplateArgs();
7092 size_t num_args = template_arg_list.size();
7093 assert(num_args &&
"template specialization without any args");
7094 if (expand_pack && num_args) {
7095 const auto &pack = template_arg_list[num_args - 1];
7096 if (pack.getKind() == clang::TemplateArgument::Pack)
7097 num_args += pack.pack_size() - 1;
7112const clang::ClassTemplateSpecializationDecl *
7119 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7120 switch (type_class) {
7121 case clang::Type::Record: {
7124 const clang::CXXRecordDecl *cxx_record_decl =
7125 qual_type->getAsCXXRecordDecl();
7126 if (!cxx_record_decl)
7128 return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
7137const TemplateArgument *
7139 size_t idx,
bool expand_pack) {
7140 const auto &args = decl->getTemplateArgs();
7141 const size_t args_size = args.size();
7143 assert(args_size &&
"template specialization without any args");
7147 const size_t last_idx = args_size - 1;
7156 if (!expand_pack || args[last_idx].getKind() != clang::TemplateArgument::Pack)
7157 return idx >= args.size() ? nullptr : &args[idx];
7162 const auto &pack = args[last_idx];
7163 const size_t pack_idx = idx - last_idx;
7164 if (pack_idx >= pack.pack_size())
7166 return &pack.pack_elements()[pack_idx];
7171 size_t arg_idx,
bool expand_pack) {
7172 const clang::ClassTemplateSpecializationDecl *template_decl =
7181 switch (arg->getKind()) {
7182 case clang::TemplateArgument::Null:
7185 case clang::TemplateArgument::NullPtr:
7188 case clang::TemplateArgument::Type:
7191 case clang::TemplateArgument::Declaration:
7194 case clang::TemplateArgument::Integral:
7197 case clang::TemplateArgument::Template:
7200 case clang::TemplateArgument::TemplateExpansion:
7203 case clang::TemplateArgument::Expression:
7206 case clang::TemplateArgument::Pack:
7209 case clang::TemplateArgument::StructuralValue:
7212 llvm_unreachable(
"Unhandled clang::TemplateArgument::ArgKind");
7217 size_t idx,
bool expand_pack) {
7218 const clang::ClassTemplateSpecializationDecl *template_decl =
7224 if (!arg || arg->getKind() != clang::TemplateArgument::Type)
7227 return GetType(arg->getAsType());
7230std::optional<CompilerType::IntegralTemplateArgument>
7232 size_t idx,
bool expand_pack) {
7233 const clang::ClassTemplateSpecializationDecl *template_decl =
7236 return std::nullopt;
7240 return std::nullopt;
7242 switch (arg->getKind()) {
7243 case clang::TemplateArgument::Integral:
7244 return {{arg->getAsIntegral(),
GetType(arg->getIntegralType())}};
7245 case clang::TemplateArgument::StructuralValue: {
7246 clang::APValue value = arg->getAsStructuralValue();
7249 if (value.isFloat())
7250 return {{value.getFloat(), type}};
7253 return {{value.getInt(), type}};
7255 return std::nullopt;
7258 return std::nullopt;
7283 const clang::EnumType *enutype =
7286 return enutype->getDecl()->getDefinitionOrSelf();
7291 const clang::RecordType *record_type =
7294 return record_type->getDecl()->getDefinitionOrSelf();
7302clang::TypedefNameDecl *
7304 const clang::TypedefType *typedef_type =
7307 return typedef_type->getDecl();
7311clang::CXXRecordDecl *
7316clang::ObjCInterfaceDecl *
7318 const clang::ObjCObjectType *objc_class_type =
7319 llvm::dyn_cast<clang::ObjCObjectType>(
7321 if (objc_class_type)
7322 return objc_class_type->getInterface();
7328 const CompilerType &field_clang_type, uint32_t bitfield_bit_size) {
7334 clang::ASTContext &clang_ast = ast->getASTContext();
7335 clang::IdentifierInfo *ident =
nullptr;
7337 ident = &clang_ast.Idents.get(name);
7339 clang::FieldDecl *field =
nullptr;
7341 clang::Expr *bit_width =
nullptr;
7342 if (bitfield_bit_size != 0) {
7343 if (clang_ast.IntTy.isNull()) {
7346 "{0} failed: builtin ASTContext types have not been initialized");
7350 llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
7352 bit_width =
new (clang_ast)
7353 clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
7354 clang_ast.IntTy, clang::SourceLocation());
7355 bit_width = clang::ConstantExpr::Create(
7356 clang_ast, bit_width, APValue(llvm::APSInt(bitfield_bit_size_apint)));
7359 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7361 field = clang::FieldDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7362 field->setDeclContext(record_decl);
7363 field->setDeclName(ident);
7366 field->setBitWidth(bit_width);
7372 if (
const clang::TagType *TagT =
7373 field->getType()->getAs<clang::TagType>()) {
7374 if (clang::RecordDecl *Rec =
7375 llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7376 if (!Rec->getDeclName()) {
7377 Rec->setAnonymousStructOrUnion(
true);
7378 field->setImplicit();
7384 field->setAccess(AS_public);
7386 record_decl->addDecl(field);
7391 clang::ObjCInterfaceDecl *class_interface_decl =
7392 ast->GetAsObjCInterfaceDecl(type);
7394 if (class_interface_decl) {
7395 const bool is_synthesized =
false;
7400 clang::ObjCIvarDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7401 ivar->setDeclContext(class_interface_decl);
7402 ivar->setDeclName(ident);
7404 ivar->setAccessControl(ObjCIvarDecl::AccessControl::Public);
7406 ivar->setBitWidth(bit_width);
7407 ivar->setSynthesize(is_synthesized);
7412 class_interface_decl->addDecl(field);
7429 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7434 typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7436 IndirectFieldVector indirect_fields;
7437 clang::RecordDecl::field_iterator field_pos;
7438 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7439 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7440 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos;
7441 last_field_pos = field_pos++) {
7442 if (field_pos->isAnonymousStructOrUnion()) {
7443 clang::QualType field_qual_type = field_pos->getType();
7445 const clang::RecordType *field_record_type =
7446 field_qual_type->getAs<clang::RecordType>();
7448 if (!field_record_type)
7451 clang::RecordDecl *field_record_decl =
7452 field_record_type->getDecl()->getDefinition();
7454 if (!field_record_decl)
7457 for (clang::RecordDecl::decl_iterator
7458 di = field_record_decl->decls_begin(),
7459 de = field_record_decl->decls_end();
7461 if (clang::FieldDecl *nested_field_decl =
7462 llvm::dyn_cast<clang::FieldDecl>(*di)) {
7463 clang::NamedDecl **chain =
7464 new (ast->getASTContext()) clang::NamedDecl *[2];
7465 chain[0] = *field_pos;
7466 chain[1] = nested_field_decl;
7467 clang::IndirectFieldDecl *indirect_field =
7468 clang::IndirectFieldDecl::Create(
7469 ast->getASTContext(), record_decl, clang::SourceLocation(),
7470 nested_field_decl->getIdentifier(),
7471 nested_field_decl->getType(), {chain, 2});
7474 indirect_field->setImplicit();
7476 indirect_field->setAccess(AS_public);
7478 indirect_fields.push_back(indirect_field);
7479 }
else if (clang::IndirectFieldDecl *nested_indirect_field_decl =
7480 llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
7481 size_t nested_chain_size =
7482 nested_indirect_field_decl->getChainingSize();
7483 clang::NamedDecl **chain =
new (ast->getASTContext())
7484 clang::NamedDecl *[nested_chain_size + 1];
7485 chain[0] = *field_pos;
7487 int chain_index = 1;
7488 for (clang::IndirectFieldDecl::chain_iterator
7489 nci = nested_indirect_field_decl->chain_begin(),
7490 nce = nested_indirect_field_decl->chain_end();
7492 chain[chain_index] = *nci;
7496 clang::IndirectFieldDecl *indirect_field =
7497 clang::IndirectFieldDecl::Create(
7498 ast->getASTContext(), record_decl, clang::SourceLocation(),
7499 nested_indirect_field_decl->getIdentifier(),
7500 nested_indirect_field_decl->getType(),
7501 {chain, nested_chain_size + 1});
7504 indirect_field->setImplicit();
7506 indirect_field->setAccess(AS_public);
7508 indirect_fields.push_back(indirect_field);
7516 if (last_field_pos != field_end_pos) {
7517 if (last_field_pos->getType()->isIncompleteArrayType())
7518 record_decl->hasFlexibleArrayMember();
7521 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(),
7522 ife = indirect_fields.end();
7524 record_decl->addDecl(*ifi);
7537 record_decl->addAttr(
7538 clang::PackedAttr::CreateImplicit(ast->getASTContext()));
7545 llvm::StringRef name,
7554 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7558 clang::VarDecl *var_decl =
nullptr;
7559 clang::IdentifierInfo *ident =
nullptr;
7561 ident = &ast->getASTContext().Idents.get(name);
7564 clang::VarDecl::CreateDeserialized(ast->getASTContext(), GlobalDeclID());
7565 var_decl->setDeclContext(record_decl);
7566 var_decl->setDeclName(ident);
7568 var_decl->setStorageClass(clang::SC_Static);
7573 var_decl->setAccess(AS_public);
7574 record_decl->addDecl(var_decl);
7576 VerifyDecl(var_decl);
7582 VarDecl *var,
const llvm::APInt &init_value) {
7583 assert(!var->hasInit() &&
"variable already initialized");
7585 clang::ASTContext &ast = var->getASTContext();
7586 QualType qt = var->getType();
7587 assert(qt->isIntegralOrEnumerationType() &&
7588 "only integer or enum types supported");
7591 if (
const EnumType *enum_type = qt->getAs<EnumType>()) {
7592 const EnumDecl *enum_decl = enum_type->getDecl()->getDefinitionOrSelf();
7593 qt = enum_decl->getIntegerType();
7597 if (qt->isSpecificBuiltinType(BuiltinType::Bool)) {
7598 var->setInit(CXXBoolLiteralExpr::Create(
7599 ast, !init_value.isZero(), qt.getUnqualifiedType(), SourceLocation()));
7601 var->setInit(IntegerLiteral::Create(
7602 ast, init_value, qt.getUnqualifiedType(), SourceLocation()));
7607 clang::VarDecl *var,
const llvm::APFloat &init_value) {
7608 assert(!var->hasInit() &&
"variable already initialized");
7610 clang::ASTContext &ast = var->getASTContext();
7611 QualType qt = var->getType();
7612 assert(qt->isFloatingType() &&
"only floating point types supported");
7613 var->setInit(FloatingLiteral::Create(
7614 ast, init_value,
true, qt.getUnqualifiedType(), SourceLocation()));
7617llvm::SmallVector<clang::ParmVarDecl *>
7619 clang::FunctionDecl *func,
const clang::FunctionProtoType &prototype,
7620 const llvm::SmallVector<llvm::StringRef> ¶meter_names) {
7622 assert(parameter_names.empty() ||
7623 parameter_names.size() == prototype.getNumParams());
7625 llvm::SmallVector<clang::ParmVarDecl *> params;
7626 for (
unsigned param_index = 0; param_index < prototype.getNumParams();
7628 llvm::StringRef name =
7629 !parameter_names.empty() ? parameter_names[param_index] :
"";
7633 GetType(prototype.getParamType(param_index)),
7634 clang::SC_None,
false);
7637 params.push_back(param);
7645 llvm::StringRef asm_label,
const CompilerType &method_clang_type,
7646 bool is_virtual,
bool is_static,
bool is_inline,
bool is_explicit,
7647 bool is_attr_used,
bool is_artificial) {
7648 if (!type || !method_clang_type.
IsValid() || name.empty())
7653 clang::CXXRecordDecl *cxx_record_decl =
7654 record_qual_type->getAsCXXRecordDecl();
7656 if (cxx_record_decl ==
nullptr)
7661 clang::CXXMethodDecl *cxx_method_decl =
nullptr;
7663 clang::DeclarationName decl_name(&
getASTContext().Idents.get(name));
7665 const clang::FunctionType *function_type =
7666 llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7668 if (function_type ==
nullptr)
7671 const clang::FunctionProtoType *method_function_prototype(
7672 llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7674 if (!method_function_prototype)
7677 unsigned int num_params = method_function_prototype->getNumParams();
7679 clang::CXXDestructorDecl *cxx_dtor_decl(
nullptr);
7680 clang::CXXConstructorDecl *cxx_ctor_decl(
nullptr);
7685 const clang::ExplicitSpecifier explicit_spec(
7686 nullptr , is_explicit ? clang::ExplicitSpecKind::ResolvedTrue
7687 : clang::ExplicitSpecKind::ResolvedFalse);
7689 if (name.starts_with(
"~")) {
7690 cxx_dtor_decl = clang::CXXDestructorDecl::CreateDeserialized(
7692 cxx_dtor_decl->setDeclContext(cxx_record_decl);
7693 cxx_dtor_decl->setDeclName(
7696 cxx_dtor_decl->setType(method_qual_type);
7697 cxx_dtor_decl->setImplicit(is_artificial);
7698 cxx_dtor_decl->setInlineSpecified(is_inline);
7699 cxx_dtor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7700 cxx_method_decl = cxx_dtor_decl;
7701 }
else if (decl_name == cxx_record_decl->getDeclName()) {
7702 cxx_ctor_decl = clang::CXXConstructorDecl::CreateDeserialized(
7704 cxx_ctor_decl->setDeclContext(cxx_record_decl);
7705 cxx_ctor_decl->setDeclName(
7708 cxx_ctor_decl->setType(method_qual_type);
7709 cxx_ctor_decl->setImplicit(is_artificial);
7710 cxx_ctor_decl->setInlineSpecified(is_inline);
7711 cxx_ctor_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7712 cxx_ctor_decl->setNumCtorInitializers(0);
7713 cxx_ctor_decl->setExplicitSpecifier(explicit_spec);
7714 cxx_method_decl = cxx_ctor_decl;
7716 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7717 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7720 if (op_kind != clang::NUM_OVERLOADED_OPERATORS) {
7725 const bool is_method =
true;
7727 is_method, op_kind, num_params))
7729 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7731 cxx_method_decl->setDeclContext(cxx_record_decl);
7732 cxx_method_decl->setDeclName(
7733 getASTContext().DeclarationNames.getCXXOperatorName(op_kind));
7734 cxx_method_decl->setType(method_qual_type);
7735 cxx_method_decl->setStorageClass(SC);
7736 cxx_method_decl->setInlineSpecified(is_inline);
7737 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7738 }
else if (num_params == 0) {
7740 auto *cxx_conversion_decl =
7741 clang::CXXConversionDecl::CreateDeserialized(
getASTContext(),
7743 cxx_conversion_decl->setDeclContext(cxx_record_decl);
7744 cxx_conversion_decl->setDeclName(
7745 getASTContext().DeclarationNames.getCXXConversionFunctionName(
7747 function_type->getReturnType())));
7748 cxx_conversion_decl->setType(method_qual_type);
7749 cxx_conversion_decl->setInlineSpecified(is_inline);
7750 cxx_conversion_decl->setExplicitSpecifier(explicit_spec);
7751 cxx_conversion_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7752 cxx_method_decl = cxx_conversion_decl;
7756 if (cxx_method_decl ==
nullptr) {
7757 cxx_method_decl = clang::CXXMethodDecl::CreateDeserialized(
7759 cxx_method_decl->setDeclContext(cxx_record_decl);
7760 cxx_method_decl->setDeclName(decl_name);
7761 cxx_method_decl->setType(method_qual_type);
7762 cxx_method_decl->setInlineSpecified(is_inline);
7763 cxx_method_decl->setStorageClass(SC);
7764 cxx_method_decl->setConstexprKind(ConstexprSpecKind::Unspecified);
7769 cxx_method_decl->setAccess(AS_public);
7770 cxx_method_decl->setVirtualAsWritten(is_virtual);
7773 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(
getASTContext()));
7775 if (!asm_label.empty())
7776 cxx_method_decl->addAttr(
7777 clang::AsmLabelAttr::CreateImplicit(
getASTContext(), asm_label));
7782 cxx_method_decl, *method_function_prototype, {}));
7784 cxx_record_decl->addDecl(cxx_method_decl);
7793 if (is_artificial) {
7794 if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() &&
7795 cxx_record_decl->hasTrivialDefaultConstructor()) ||
7796 (cxx_ctor_decl->isCopyConstructor() &&
7797 cxx_record_decl->hasTrivialCopyConstructor()) ||
7798 (cxx_ctor_decl->isMoveConstructor() &&
7799 cxx_record_decl->hasTrivialMoveConstructor()))) {
7800 cxx_ctor_decl->setDefaulted();
7801 cxx_ctor_decl->setTrivial(
true);
7802 }
else if (cxx_dtor_decl) {
7803 if (cxx_record_decl->hasTrivialDestructor()) {
7804 cxx_dtor_decl->setDefaulted();
7805 cxx_dtor_decl->setTrivial(
true);
7807 }
else if ((cxx_method_decl->isCopyAssignmentOperator() &&
7808 cxx_record_decl->hasTrivialCopyAssignment()) ||
7809 (cxx_method_decl->isMoveAssignmentOperator() &&
7810 cxx_record_decl->hasTrivialMoveAssignment())) {
7811 cxx_method_decl->setDefaulted();
7812 cxx_method_decl->setTrivial(
true);
7816 VerifyDecl(cxx_method_decl);
7818 return cxx_method_decl;
7824 for (
auto *method : record->methods())
7825 addOverridesForMethod(method);
7828#pragma mark C++ Base Classes
7830std::unique_ptr<clang::CXXBaseSpecifier>
7833 bool base_of_class) {
7837 return std::make_unique<clang::CXXBaseSpecifier>(
7838 clang::SourceRange(), is_virtual, base_of_class,
7841 clang::SourceLocation());
7846 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) {
7850 if (!cxx_record_decl)
7852 std::vector<clang::CXXBaseSpecifier *> raw_bases;
7853 raw_bases.reserve(bases.size());
7857 for (
auto &b : bases)
7858 raw_bases.push_back(b.get());
7859 cxx_record_decl->setBases(raw_bases.data(), raw_bases.size());
7868 clang::ASTContext &clang_ast = ast->getASTContext();
7870 if (type && superclass_clang_type.
IsValid() &&
7872 clang::ObjCInterfaceDecl *class_interface_decl =
7874 clang::ObjCInterfaceDecl *super_interface_decl =
7876 if (class_interface_decl && super_interface_decl) {
7877 class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
7878 clang_ast.getObjCInterfaceType(super_interface_decl)));
7887 const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl,
7888 const char *property_setter_name,
const char *property_getter_name,
7890 if (!type || !property_clang_type.
IsValid() || property_name ==
nullptr ||
7891 property_name[0] ==
'\0')
7896 clang::ASTContext &clang_ast = ast->getASTContext();
7899 if (!class_interface_decl)
7904 if (property_clang_type.
IsValid())
7905 property_clang_type_to_access = property_clang_type;
7907 property_clang_type_to_access = ast->GetType(ivar_decl->getType());
7909 if (!class_interface_decl || !property_clang_type_to_access.
IsValid())
7912 clang::TypeSourceInfo *prop_type_source;
7914 prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
7916 prop_type_source = clang_ast.getTrivialTypeSourceInfo(
7919 clang::ObjCPropertyDecl *property_decl =
7920 clang::ObjCPropertyDecl::CreateDeserialized(clang_ast, GlobalDeclID());
7921 property_decl->setDeclContext(class_interface_decl);
7922 property_decl->setDeclName(&clang_ast.Idents.get(property_name));
7923 property_decl->setType(ivar_decl
7924 ? ivar_decl->getType()
7932 ast->SetMetadata(property_decl, metadata);
7934 class_interface_decl->addDecl(property_decl);
7936 clang::Selector setter_sel, getter_sel;
7938 if (property_setter_name) {
7939 std::string property_setter_no_colon(property_setter_name,
7940 strlen(property_setter_name) - 1);
7941 const clang::IdentifierInfo *setter_ident =
7942 &clang_ast.Idents.get(property_setter_no_colon);
7943 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
7944 }
else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
7945 std::string setter_sel_string(
"set");
7946 setter_sel_string.push_back(::toupper(property_name[0]));
7947 setter_sel_string.append(&property_name[1]);
7948 const clang::IdentifierInfo *setter_ident =
7949 &clang_ast.Idents.get(setter_sel_string);
7950 setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
7952 property_decl->setSetterName(setter_sel);
7953 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
7955 if (property_getter_name !=
nullptr) {
7956 const clang::IdentifierInfo *getter_ident =
7957 &clang_ast.Idents.get(property_getter_name);
7958 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
7960 const clang::IdentifierInfo *getter_ident =
7961 &clang_ast.Idents.get(property_name);
7962 getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
7964 property_decl->setGetterName(getter_sel);
7965 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
7968 property_decl->setPropertyIvarDecl(ivar_decl);
7970 if (property_attributes & DW_APPLE_PROPERTY_readonly)
7971 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
7972 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
7973 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
7974 if (property_attributes & DW_APPLE_PROPERTY_assign)
7975 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
7976 if (property_attributes & DW_APPLE_PROPERTY_retain)
7977 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
7978 if (property_attributes & DW_APPLE_PROPERTY_copy)
7979 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
7980 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
7981 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
7982 if (property_attributes & ObjCPropertyAttribute::kind_nullability)
7983 property_decl->setPropertyAttributes(
7984 ObjCPropertyAttribute::kind_nullability);
7985 if (property_attributes & ObjCPropertyAttribute::kind_null_resettable)
7986 property_decl->setPropertyAttributes(
7987 ObjCPropertyAttribute::kind_null_resettable);
7988 if (property_attributes & ObjCPropertyAttribute::kind_class)
7989 property_decl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
7991 const bool isInstance =
7992 (property_attributes & ObjCPropertyAttribute::kind_class) == 0;
7994 clang::ObjCMethodDecl *getter =
nullptr;
7995 if (!getter_sel.isNull())
7996 getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
7997 : class_interface_decl->lookupClassMethod(getter_sel);
7998 if (!getter_sel.isNull() && !getter) {
7999 const bool isVariadic =
false;
8000 const bool isPropertyAccessor =
true;
8001 const bool isSynthesizedAccessorStub =
false;
8002 const bool isImplicitlyDeclared =
true;
8003 const bool isDefined =
false;
8004 const clang::ObjCImplementationControl impControl =
8005 clang::ObjCImplementationControl::None;
8006 const bool HasRelatedResultType =
false;
8009 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8010 getter->setDeclName(getter_sel);
8012 getter->setDeclContext(class_interface_decl);
8013 getter->setInstanceMethod(isInstance);
8014 getter->setVariadic(isVariadic);
8015 getter->setPropertyAccessor(isPropertyAccessor);
8016 getter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8017 getter->setImplicit(isImplicitlyDeclared);
8018 getter->setDefined(isDefined);
8019 getter->setDeclImplementation(impControl);
8020 getter->setRelatedResultType(HasRelatedResultType);
8024 ast->SetMetadata(getter, metadata);
8026 getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
8027 llvm::ArrayRef<clang::SourceLocation>());
8028 class_interface_decl->addDecl(getter);
8032 getter->setPropertyAccessor(
true);
8033 property_decl->setGetterMethodDecl(getter);
8036 clang::ObjCMethodDecl *setter =
nullptr;
8037 setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8038 : class_interface_decl->lookupClassMethod(setter_sel);
8039 if (!setter_sel.isNull() && !setter) {
8040 clang::QualType result_type = clang_ast.VoidTy;
8041 const bool isVariadic =
false;
8042 const bool isPropertyAccessor =
true;
8043 const bool isSynthesizedAccessorStub =
false;
8044 const bool isImplicitlyDeclared =
true;
8045 const bool isDefined =
false;
8046 const clang::ObjCImplementationControl impControl =
8047 clang::ObjCImplementationControl::None;
8048 const bool HasRelatedResultType =
false;
8051 clang::ObjCMethodDecl::CreateDeserialized(clang_ast, GlobalDeclID());
8052 setter->setDeclName(setter_sel);
8053 setter->setReturnType(result_type);
8054 setter->setDeclContext(class_interface_decl);
8055 setter->setInstanceMethod(isInstance);
8056 setter->setVariadic(isVariadic);
8057 setter->setPropertyAccessor(isPropertyAccessor);
8058 setter->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8059 setter->setImplicit(isImplicitlyDeclared);
8060 setter->setDefined(isDefined);
8061 setter->setDeclImplementation(impControl);
8062 setter->setRelatedResultType(HasRelatedResultType);
8066 ast->SetMetadata(setter, metadata);
8068 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8069 params.push_back(clang::ParmVarDecl::Create(
8070 clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8073 clang::SC_Auto,
nullptr));
8075 setter->setMethodParams(clang_ast,
8076 llvm::ArrayRef<clang::ParmVarDecl *>(params),
8077 llvm::ArrayRef<clang::SourceLocation>());
8079 class_interface_decl->addDecl(setter);
8083 setter->setPropertyAccessor(
true);
8084 property_decl->setSetterMethodDecl(setter);
8095 const CompilerType &method_clang_type,
bool is_artificial,
bool is_variadic,
8096 bool is_objc_direct_call) {
8097 if (!type || !method_clang_type.
IsValid())
8102 if (class_interface_decl ==
nullptr)
8105 if (lldb_ast ==
nullptr)
8107 clang::ASTContext &ast = lldb_ast->getASTContext();
8109 const char *selector_start = ::strchr(name,
' ');
8110 if (selector_start ==
nullptr)
8114 llvm::SmallVector<const clang::IdentifierInfo *, 12> selector_idents;
8119 unsigned num_selectors_with_args = 0;
8120 for (start = selector_start; start && *start !=
'\0' && *start !=
']';
8122 len = ::strcspn(start,
":]");
8123 bool has_arg = (start[len] ==
':');
8125 ++num_selectors_with_args;
8126 selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
8131 if (selector_idents.size() == 0)
8134 clang::Selector method_selector = ast.Selectors.getSelector(
8135 num_selectors_with_args ? selector_idents.size() : 0,
8136 selector_idents.data());
8141 const clang::Type *method_type(method_qual_type.getTypePtr());
8143 if (method_type ==
nullptr)
8146 const clang::FunctionProtoType *method_function_prototype(
8147 llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8149 if (!method_function_prototype)
8152 const bool isInstance = (name[0] ==
'-');
8153 const bool isVariadic = is_variadic;
8154 const bool isPropertyAccessor =
false;
8155 const bool isSynthesizedAccessorStub =
false;
8157 const bool isImplicitlyDeclared =
true;
8158 const bool isDefined =
false;
8159 const clang::ObjCImplementationControl impControl =
8160 clang::ObjCImplementationControl::None;
8161 const bool HasRelatedResultType =
false;
8163 const unsigned num_args = method_function_prototype->getNumParams();
8165 if (num_args != num_selectors_with_args)
8169 auto *objc_method_decl =
8170 clang::ObjCMethodDecl::CreateDeserialized(ast, GlobalDeclID());
8171 objc_method_decl->setDeclName(method_selector);
8172 objc_method_decl->setReturnType(method_function_prototype->getReturnType());
8173 objc_method_decl->setDeclContext(
8175 objc_method_decl->setInstanceMethod(isInstance);
8176 objc_method_decl->setVariadic(isVariadic);
8177 objc_method_decl->setPropertyAccessor(isPropertyAccessor);
8178 objc_method_decl->setSynthesizedAccessorStub(isSynthesizedAccessorStub);
8179 objc_method_decl->setImplicit(isImplicitlyDeclared);
8180 objc_method_decl->setDefined(isDefined);
8181 objc_method_decl->setDeclImplementation(impControl);
8182 objc_method_decl->setRelatedResultType(HasRelatedResultType);
8185 if (objc_method_decl ==
nullptr)
8189 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8191 for (
unsigned param_index = 0; param_index < num_args; ++param_index) {
8192 params.push_back(clang::ParmVarDecl::Create(
8193 ast, objc_method_decl, clang::SourceLocation(),
8194 clang::SourceLocation(),
8196 method_function_prototype->getParamType(param_index),
nullptr,
8197 clang::SC_Auto,
nullptr));
8200 objc_method_decl->setMethodParams(
8201 ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
8202 llvm::ArrayRef<clang::SourceLocation>());
8205 if (is_objc_direct_call) {
8208 objc_method_decl->addAttr(
8209 clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
8214 objc_method_decl->createImplicitParams(ast, class_interface_decl);
8217 class_interface_decl->addDecl(objc_method_decl);
8219 VerifyDecl(objc_method_decl);
8221 return objc_method_decl;
8231 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8232 switch (type_class) {
8233 case clang::Type::Record: {
8234 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8235 if (cxx_record_decl) {
8236 cxx_record_decl->setHasExternalLexicalStorage(has_extern);
8237 cxx_record_decl->setHasExternalVisibleStorage(has_extern);
8242 case clang::Type::Enum: {
8243 clang::EnumDecl *enum_decl =
8244 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8246 enum_decl->setHasExternalLexicalStorage(has_extern);
8247 enum_decl->setHasExternalVisibleStorage(has_extern);
8252 case clang::Type::ObjCObject:
8253 case clang::Type::ObjCInterface: {
8254 const clang::ObjCObjectType *objc_class_type =
8255 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8256 assert(objc_class_type);
8257 if (objc_class_type) {
8258 clang::ObjCInterfaceDecl *class_interface_decl =
8259 objc_class_type->getInterface();
8261 if (class_interface_decl) {
8262 class_interface_decl->setHasExternalLexicalStorage(has_extern);
8263 class_interface_decl->setHasExternalVisibleStorage(has_extern);
8279 if (!qual_type.isNull()) {
8280 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8282 clang::TagDecl *tag_decl = tag_type->getDecl();
8284 tag_decl->startDefinition();
8289 const clang::ObjCObjectType *object_type =
8290 qual_type->getAs<clang::ObjCObjectType>();
8292 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8293 if (interface_decl) {
8294 interface_decl->startDefinition();
8305 if (qual_type.isNull())
8309 if (lldb_ast ==
nullptr)
8315 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8317 clang::TagDecl *tag_decl = tag_type->getDecl()->getDefinitionOrSelf();
8319 if (
auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
8329 if (cxx_record_decl->hasUserDeclaredMoveConstructor() ||
8330 cxx_record_decl->hasUserDeclaredMoveAssignment()) {
8331 if (cxx_record_decl->needsImplicitCopyConstructor())
8332 cxx_record_decl->setImplicitCopyConstructorIsDeleted();
8333 if (cxx_record_decl->needsImplicitCopyAssignment())
8334 cxx_record_decl->setImplicitCopyAssignmentIsDeleted();
8337 if (!cxx_record_decl->isCompleteDefinition())
8338 cxx_record_decl->completeDefinition();
8339 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(
true);
8340 cxx_record_decl->setHasExternalLexicalStorage(
false);
8341 cxx_record_decl->setHasExternalVisibleStorage(
false);
8346 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8350 clang::EnumDecl *enum_decl = enutype->getDecl()->getDefinitionOrSelf();
8352 if (enum_decl->isCompleteDefinition())
8355 QualType integer_type(enum_decl->getIntegerType());
8356 if (!integer_type.isNull()) {
8357 clang::ASTContext &ast = lldb_ast->getASTContext();
8359 unsigned NumNegativeBits = 0;
8360 unsigned NumPositiveBits = 0;
8361 ast.computeEnumBits(enum_decl->enumerators(), NumNegativeBits,
8364 clang::QualType BestPromotionType;
8365 clang::QualType BestType;
8366 ast.computeBestEnumTypes(
false, NumNegativeBits,
8367 NumPositiveBits, BestType, BestPromotionType);
8369 enum_decl->completeDefinition(enum_decl->getIntegerType(),
8370 BestPromotionType, NumPositiveBits,
8378 const llvm::APSInt &value) {
8389 if (!enum_opaque_compiler_type)
8392 clang::QualType enum_qual_type(
8395 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8400 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8405 clang::EnumConstantDecl *enumerator_decl =
8406 clang::EnumConstantDecl::CreateDeserialized(
getASTContext(),
8408 clang::EnumDecl *enum_decl = enutype->getDecl()->getDefinitionOrSelf();
8409 enumerator_decl->setDeclContext(enum_decl);
8410 if (name && name[0])
8411 enumerator_decl->setDeclName(&
getASTContext().Idents.get(name));
8412 enumerator_decl->setType(clang::QualType(enutype, 0));
8414 enumerator_decl->setAccess(AS_public);
8420 enum_decl->addDecl(enumerator_decl);
8422 VerifyDecl(enumerator_decl);
8423 return enumerator_decl;
8428 uint64_t enum_value, uint32_t enum_value_bit_size) {
8430 llvm::APSInt value(enum_value_bit_size,
8439 const clang::Type *clang_type = qt.getTypePtrOrNull();
8440 const auto *enum_type = llvm::dyn_cast_or_null<clang::EnumType>(clang_type);
8444 return GetType(enum_type->getDecl()->getDefinitionOrSelf()->getIntegerType());
8450 if (type && pointee_type.
IsValid() &&
8455 return ast->GetType(ast->getASTContext().getMemberPointerType(
8464#define DEPTH_INCREMENT 2
8467LLVM_DUMP_METHOD
void
8477struct ScopedASTColor {
8478 ScopedASTColor(clang::ASTContext &ast,
bool show_colors)
8479 : ast(ast), old_show_colors(ast.getDiagnostics().getShowColors()) {
8480 ast.getDiagnostics().setShowColors(show_colors);
8483 ~ScopedASTColor() { ast.getDiagnostics().setShowColors(old_show_colors); }
8485 clang::ASTContext *
8486 const bool old_show_colors;
8495 clang::CreateASTDumper(output, filter,
8499 false, clang::ADOF_Default);
8502 consumer->HandleTranslationUnit(*
m_ast_up);
8506 llvm::StringRef symbol_name) {
8513 symfile->
GetTypes(
nullptr, eTypeClassAny, type_list);
8514 size_t ntypes = type_list.
GetSize();
8516 for (
size_t i = 0; i < ntypes; ++i) {
8519 if (!symbol_name.empty())
8520 if (symbol_name != type->GetName().GetStringRef())
8523 s << type->GetName() <<
"\n";
8526 if (clang::TagDecl *tag_decl =
GetAsTagDecl(full_type)) {
8534 if (
auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8536 if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8548 size_t byte_size, uint32_t bitfield_bit_offset,
8549 uint32_t bitfield_bit_size) {
8550 const clang::EnumType *enutype =
8551 llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8552 const clang::EnumDecl *enum_decl = enutype->getDecl()->getDefinitionOrSelf();
8554 bool qual_type_is_signed = qual_type->isSignedIntegerOrEnumerationType();
8555 const uint64_t enum_svalue =
8558 bitfield_bit_offset)
8560 bitfield_bit_offset);
8561 bool can_be_bitfield =
true;
8562 uint64_t covered_bits = 0;
8563 int num_enumerators = 0;
8571 clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
8572 if (enumerators.empty())
8573 can_be_bitfield =
false;
8575 for (
auto *enumerator : enumerators) {
8576 llvm::APSInt init_val = enumerator->getInitVal();
8577 uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
8578 : init_val.getZExtValue();
8579 if (qual_type_is_signed)
8580 val = llvm::SignExtend64(val, 8 * byte_size);
8581 if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8582 can_be_bitfield =
false;
8583 covered_bits |= val;
8585 if (val == enum_svalue) {
8594 offset = byte_offset;
8596 &offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
8600 if (!can_be_bitfield) {
8601 if (qual_type_is_signed)
8602 s.
Printf(
"%" PRIi64, enum_svalue);
8604 s.
Printf(
"%" PRIu64, enum_uvalue);
8611 s.
Printf(
"0x%" PRIx64, enum_uvalue);
8615 uint64_t remaining_value = enum_uvalue;
8616 std::vector<std::pair<uint64_t, llvm::StringRef>> values;
8617 values.reserve(num_enumerators);
8618 for (
auto *enumerator : enum_decl->enumerators())
8619 if (
auto val = enumerator->getInitVal().getZExtValue())
8620 values.emplace_back(val, enumerator->getName());
8625 llvm::stable_sort(values, [](
const auto &a,
const auto &b) {
8626 return llvm::popcount(a.first) > llvm::popcount(b.first);
8629 for (
const auto &val : values) {
8630 if ((remaining_value & val.first) != val.first)
8632 remaining_value &= ~val.first;
8634 if (remaining_value)
8640 if (remaining_value)
8641 s.
Printf(
"0x%" PRIx64, remaining_value);
8649 size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
8658 switch (qual_type->getTypeClass()) {
8659 case clang::Type::Typedef: {
8660 clang::QualType typedef_qual_type =
8661 llvm::cast<clang::TypedefType>(qual_type)
8663 ->getUnderlyingType();
8666 format = typedef_clang_type.
GetFormat();
8667 clang::TypeInfo typedef_type_info =
8669 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
8679 bitfield_bit_offset,
8684 case clang::Type::Enum:
8689 return DumpEnumValue(qual_type, s, data, byte_offset, byte_size,
8690 bitfield_bit_offset, bitfield_bit_size);
8698 uint32_t item_count = 1;
8738 item_count = byte_size;
8743 item_count = byte_size / 2;
8748 item_count = byte_size / 4;
8754 bitfield_bit_size, bitfield_bit_offset,
8770 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(clang_type)) {
8779 clang::QualType qual_type =
8782 llvm::SmallVector<char, 1024> buf;
8783 llvm::raw_svector_ostream llvm_ostrm(buf);
8785 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8786 switch (type_class) {
8787 case clang::Type::ObjCObject:
8788 case clang::Type::ObjCInterface: {
8791 auto *objc_class_type =
8792 llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8793 assert(objc_class_type);
8794 if (!objc_class_type)
8796 clang::ObjCInterfaceDecl *class_interface_decl =
8797 objc_class_type->getInterface();
8798 if (!class_interface_decl)
8801 class_interface_decl->dump(llvm_ostrm);
8803 class_interface_decl->print(llvm_ostrm,
8808 case clang::Type::Typedef: {
8809 auto *typedef_type = qual_type->getAs<clang::TypedefType>();
8812 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8814 typedef_decl->dump(llvm_ostrm);
8817 if (!clang_typedef_name.empty()) {
8824 case clang::Type::Record: {
8827 auto *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8828 const clang::RecordDecl *record_decl = record_type->getDecl();
8830 record_decl->dump(llvm_ostrm);
8832 record_decl->print(llvm_ostrm,
getASTContext().getPrintingPolicy(),
8838 if (
auto *tag_type =
8839 llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) {
8840 if (clang::TagDecl *tag_decl = tag_type->getDecl()) {
8842 tag_decl->dump(llvm_ostrm);
8844 tag_decl->print(llvm_ostrm, 0);
8850 std::string clang_type_name(qual_type.getAsString());
8851 if (!clang_type_name.empty())
8858 if (buf.size() > 0) {
8859 s.
Write(buf.data(), buf.size());
8866 clang::QualType qual_type(
8869 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8870 switch (type_class) {
8871 case clang::Type::Record: {
8872 const clang::CXXRecordDecl *cxx_record_decl =
8873 qual_type->getAsCXXRecordDecl();
8874 if (cxx_record_decl)
8875 printf(
"class %s", cxx_record_decl->getName().str().c_str());
8878 case clang::Type::Enum: {
8879 clang::EnumDecl *enum_decl =
8880 llvm::cast<clang::EnumType>(qual_type)->getDecl();
8882 printf(
"enum %s", enum_decl->getName().str().c_str());
8886 case clang::Type::ObjCObject:
8887 case clang::Type::ObjCInterface: {
8888 const clang::ObjCObjectType *objc_class_type =
8889 llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
8890 if (objc_class_type) {
8891 clang::ObjCInterfaceDecl *class_interface_decl =
8892 objc_class_type->getInterface();
8896 if (class_interface_decl)
8897 printf(
"@class %s", class_interface_decl->getName().str().c_str());
8901 case clang::Type::Typedef:
8902 printf(
"typedef %s", llvm::cast<clang::TypedefType>(qual_type)
8909 case clang::Type::Auto:
8912 llvm::cast<clang::AutoType>(qual_type)
8914 .getAsOpaquePtr()));
8916 case clang::Type::Paren:
8920 llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
8923 printf(
"TypeSystemClang::DumpTypeName() type_class = %u", type_class);
8931 const char *parent_name,
int tag_decl_kind,
8933 if (template_param_infos.
IsValid()) {
8934 std::string template_basename(parent_name);
8936 if (
auto i = template_basename.find(
'<'); i != std::string::npos)
8937 template_basename.erase(i);
8940 template_basename.c_str(), tag_decl_kind,
8941 template_param_infos);
8956 clang::ObjCInterfaceDecl *decl) {
8980 std::make_unique<npdb::PdbAstBuilderClang>(*
this);
8985 const clang::RecordDecl *record_decl, uint64_t &bit_size,
8986 uint64_t &alignment,
8987 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8988 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
8990 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
9003 field_offsets, base_offsets, vbase_offsets);
9010 clang::NamedDecl *nd =
9011 llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl);
9021 if (!label_or_err) {
9022 llvm::consumeError(label_or_err.takeError());
9026 llvm::StringRef mangled = label_or_err->lookup_name;
9034 clang::NamedDecl *nd = llvm::dyn_cast_or_null<clang::NamedDecl>(
9035 static_cast<clang::Decl *
>(opaque_decl));
9037 if (!nd || llvm::isa<clang::ObjCMethodDecl>(nd))
9041 if (!mc || !mc->shouldMangleCXXName(nd))
9046 if (
const auto *label = nd->getAttr<AsmLabelAttr>())
9051 llvm::SmallVector<char, 1024> buf;
9052 llvm::raw_svector_ostream llvm_ostrm(buf);
9053 if (llvm::isa<clang::CXXConstructorDecl>(nd)) {
9055 clang::GlobalDecl(llvm::dyn_cast<clang::CXXConstructorDecl>(nd),
9058 }
else if (llvm::isa<clang::CXXDestructorDecl>(nd)) {
9060 clang::GlobalDecl(llvm::dyn_cast<clang::CXXDestructorDecl>(nd),
9064 mc->mangleName(nd, llvm_ostrm);
9080 if (clang::FunctionDecl *func_decl =
9081 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9082 return GetType(func_decl->getReturnType());
9083 if (clang::ObjCMethodDecl *objc_method =
9084 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9085 return GetType(objc_method->getReturnType());
9091 if (clang::FunctionDecl *func_decl =
9092 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl))
9093 return func_decl->param_size();
9094 if (clang::ObjCMethodDecl *objc_method =
9095 llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl))
9096 return objc_method->param_size();
9102 clang::DeclContext
const *decl_ctx) {
9103 switch (clang_kind) {
9104 case Decl::TranslationUnit:
9106 case Decl::Namespace:
9117 if (decl_ctx->isFunctionOrMethod())
9119 if (decl_ctx->isRecord())
9129 std::vector<lldb_private::CompilerContext> &context) {
9130 if (decl_ctx ==
nullptr)
9133 clang::Decl::Kind clang_kind = decl_ctx->getDeclKind();
9134 if (clang_kind == Decl::TranslationUnit)
9139 context.push_back({compiler_kind, decl_ctx_name});
9142std::vector<lldb_private::CompilerContext>
9144 std::vector<lldb_private::CompilerContext> context;
9147 clang::Decl *decl = (clang::Decl *)opaque_decl;
9149 clang::DeclContext *decl_ctx = decl->getDeclContext();
9152 auto compiler_kind =
9154 context.push_back({compiler_kind, decl_name});
9161 if (clang::FunctionDecl *func_decl =
9162 llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) {
9163 if (idx < func_decl->param_size()) {
9164 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9166 return GetType(var_decl->getOriginalType());
9168 }
else if (clang::ObjCMethodDecl *objc_method =
9169 llvm::dyn_cast<clang::ObjCMethodDecl>(
9170 (clang::Decl *)opaque_decl)) {
9171 if (idx < objc_method->param_size())
9172 return GetType(objc_method->parameters()[idx]->getOriginalType());
9178 clang::Decl *decl =
static_cast<clang::Decl *
>(opaque_decl);
9179 clang::VarDecl *var_decl = llvm::dyn_cast<clang::VarDecl>(decl);
9182 clang::Expr *init_expr = var_decl->getInit();
9185 std::optional<llvm::APSInt> value =
9195 void *opaque_decl_ctx,
ConstString name,
const bool ignore_using_decls) {
9196 std::vector<CompilerDecl> found_decls;
9198 if (opaque_decl_ctx && symbol_file) {
9199 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9200 std::set<DeclContext *> searched;
9201 std::multimap<DeclContext *, DeclContext *> search_queue;
9203 for (clang::DeclContext *decl_context = root_decl_ctx;
9204 decl_context !=
nullptr && found_decls.empty();
9205 decl_context = decl_context->getParent()) {
9206 search_queue.insert(std::make_pair(decl_context, decl_context));
9208 for (
auto it = search_queue.find(decl_context); it != search_queue.end();
9210 if (!searched.insert(it->second).second)
9215 for (clang::Decl *child : it->second->decls()) {
9216 if (clang::UsingDirectiveDecl *ud =
9217 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9218 if (ignore_using_decls)
9220 clang::DeclContext *from = ud->getCommonAncestor();
9221 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9222 search_queue.insert(
9223 std::make_pair(from, ud->getNominatedNamespace()));
9224 }
else if (clang::UsingDecl *ud =
9225 llvm::dyn_cast<clang::UsingDecl>(child)) {
9226 if (ignore_using_decls)
9228 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9229 clang::Decl *target = usd->getTargetDecl();
9230 if (clang::NamedDecl *nd =
9231 llvm::dyn_cast<clang::NamedDecl>(target)) {
9232 IdentifierInfo *ii = nd->getIdentifier();
9233 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9237 }
else if (clang::NamedDecl *nd =
9238 llvm::dyn_cast<clang::NamedDecl>(child)) {
9239 IdentifierInfo *ii = nd->getIdentifier();
9240 if (ii !=
nullptr && ii->getName() == name.
AsCString(
nullptr))
9291 clang::DeclContext *child_decl_ctx,
9295 if (frame_decl_ctx && symbol_file) {
9296 std::set<DeclContext *> searched;
9297 std::multimap<DeclContext *, DeclContext *> search_queue;
9300 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9304 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx !=
nullptr;
9305 decl_ctx = decl_ctx->getParent()) {
9306 if (!decl_ctx->isLookupContext())
9308 if (decl_ctx == parent_decl_ctx)
9311 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9312 for (
auto it = search_queue.find(decl_ctx); it != search_queue.end();
9314 if (searched.find(it->second) != searched.end())
9322 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9325 searched.insert(it->second);
9329 for (clang::Decl *child : it->second->decls()) {
9330 if (clang::UsingDirectiveDecl *ud =
9331 llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) {
9332 clang::DeclContext *ns = ud->getNominatedNamespace();
9333 if (ns == parent_decl_ctx)
9336 clang::DeclContext *from = ud->getCommonAncestor();
9337 if (searched.find(ns) == searched.end())
9338 search_queue.insert(std::make_pair(from, ns));
9339 }
else if (child_name) {
9340 if (clang::UsingDecl *ud =
9341 llvm::dyn_cast<clang::UsingDecl>(child)) {
9342 for (clang::UsingShadowDecl *usd : ud->shadows()) {
9343 clang::Decl *target = usd->getTargetDecl();
9344 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9348 IdentifierInfo *ii = nd->getIdentifier();
9349 if (ii ==
nullptr ||
9350 ii->getName() != child_name->
AsCString(
nullptr))
9373 if (opaque_decl_ctx) {
9374 clang::NamedDecl *named_decl =
9375 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9378 llvm::raw_string_ostream stream{name};
9380 policy.AlwaysIncludeTypeForTemplateArgument =
true;
9381 named_decl->getNameForDiagnostic(stream, policy,
false);
9390 if (opaque_decl_ctx) {
9391 clang::NamedDecl *named_decl =
9392 llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9400 if (!opaque_decl_ctx)
9403 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9404 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9406 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9408 }
else if (clang::FunctionDecl *fun_decl =
9409 llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9410 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9411 return metadata->HasObjectPtr();
9417std::vector<lldb_private::CompilerContext>
9419 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9420 std::vector<lldb_private::CompilerContext> context;
9426 void *opaque_decl_ctx,
void *other_opaque_decl_ctx) {
9427 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9428 auto *other = (clang::DeclContext *)other_opaque_decl_ctx;
9432 auto is_transparent_lookup_allowed = [](clang::DeclContext *DC) {
9433 if (DC->isInlineNamespace())
9436 if (
auto const *NS = dyn_cast<NamespaceDecl>(DC))
9437 return NS->isAnonymousNamespace();
9444 if (decl_ctx == other)
9446 }
while (is_transparent_lookup_allowed(other) &&
9447 (other = other->getParent()));
9454 if (!opaque_decl_ctx)
9457 auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
9458 if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
9460 }
else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
9462 }
else if (
auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
9463 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(fun_decl))
9464 return metadata->GetObjectPtrLanguage();
9484 return llvm::dyn_cast<clang::ObjCMethodDecl>(
9492 return llvm::dyn_cast<clang::CXXMethodDecl>(
9497clang::FunctionDecl *
9500 return llvm::dyn_cast<clang::FunctionDecl>(
9505clang::NamespaceDecl *
9508 return llvm::dyn_cast<clang::NamespaceDecl>(
9513std::optional<ClangASTMetadata>
9515 const Decl *
object) {
9523 llvm::dyn_cast_or_null<TypeSystemClang>(dc.
GetTypeSystem());
9546 lldbassert(started &&
"Unable to start a class type definition.");
9551 ts->SetDeclIsForcefullyCompleted(td);
9565 SpecializedScratchAST(llvm::StringRef name, llvm::Triple triple,
9566 std::unique_ptr<ClangASTSource> ast_source)
9568 m_scratch_ast_source_up(std::move(ast_source)) {
9570 m_scratch_ast_source_up->InstallASTContext(*
this);
9571 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source =
9572 m_scratch_ast_source_up->CreateProxy();
9573 SetExternalSource(proxy_ast_source);
9577 std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
9585 llvm::Triple triple)
9592 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source =
9604 std::optional<IsolatedASTKind> ast_kind,
9605 bool create_on_demand) {
9608 if (
auto err = type_system_or_err.takeError()) {
9610 "Couldn't get scratch TypeSystemClang: {0}");
9613 auto ts_sp = *type_system_or_err;
9615 llvm::dyn_cast_or_null<ScratchTypeSystemClang>(ts_sp.get());
9620 return std::static_pointer_cast<TypeSystemClang>(ts_sp);
9622 return std::static_pointer_cast<TypeSystemClang>(
9627static llvm::StringRef
9631 return "C++ modules";
9633 llvm_unreachable(
"Unimplemented IsolatedASTKind?");
9637 llvm::StringRef filter,
bool show_color) {
9639 output <<
"State of scratch Clang type system:\n";
9643 typedef std::pair<IsolatedASTKey, TypeSystem *> KeyAndTS;
9644 std::vector<KeyAndTS> sorted_typesystems;
9646 sorted_typesystems.emplace_back(a.first, a.second.get());
9647 llvm::stable_sort(sorted_typesystems, llvm::less_first());
9650 for (
const auto &a : sorted_typesystems) {
9653 output <<
"State of scratch Clang type subsystem "
9655 a.second->Dump(output, filter, show_color);
9660 llvm::StringRef expr, llvm::StringRef prefix,
SourceLanguage language,
9668 desired_type, options, ctx_obj);
9673 const ValueList &arg_value_list,
const char *name) {
9678 Process *process = target_sp->GetProcessSP().get();
9683 arg_value_list, name);
9686std::unique_ptr<UtilityFunction>
9693 return std::make_unique<ClangUtilityFunction>(
9694 *target_sp.get(), std::move(text), std::move(name),
9695 target_sp->GetDebugUtilityExpression());
9709 importer.
ForgetSource(&a.second->getASTContext(), src_ctx);
9713 return std::make_unique<ClangASTSource>(
9718static llvm::StringRef
9722 return "scratch ASTContext for C++ module types";
9724 llvm_unreachable(
"Unimplemented ASTFeature kind?");
9731 return *found_ast->second;
9734 std::shared_ptr<TypeSystemClang> new_ast_sp =
9744 const clang::RecordType *record_type =
9745 llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
9747 const clang::RecordDecl *record_decl =
9748 record_type->getDecl()->getDefinitionOrSelf();
9749 if (std::optional<ClangASTMetadata> metadata =
GetMetadata(record_decl))
9750 return metadata->IsForcefullyCompleted();
9759 std::optional<ClangASTMetadata> metadata =
GetMetadata(td);
9763 metadata->SetIsForcefullyCompleted();
9771 LLDB_LOG(log,
"Created new TypeSystem for (ASTContext*){0:x} '{1}'",
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s, const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_offset, uint32_t bitfield_bit_size)
static lldb::opaque_compiler_type_t GetObjCFieldAtIndex(clang::ASTContext *ast, clang::ObjCInterfaceDecl *class_interface_decl, size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr)
static void ParseLangArgs(LangOptions &Opts, ArchSpec arch)
static const clang::EnumType * GetCompleteEnumType(const clang::ASTContext *ast, clang::QualType qual_type)
Returns the clang::EnumType of the specified qual_type.
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 const clang::RecordType * GetCompleteRecordType(const clang::ASTContext *ast, clang::QualType qual_type)
Returns the clang::RecordType of the specified qual_type.
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)
static lldb::addr_t GetVTableAddress(Process &process, VTableContextBase &vtable_ctx, ValueObject &valobj, const ASTRecordLayout &record_layout)
static std::optional< SymbolFile::ArrayInfo > GetDynamicArrayInfo(TypeSystemClang &ast, SymbolFile *sym_file, clang::QualType qual_type, const ExecutionContext *exe_ctx)
static ConstString ExtractMangledNameFromFunctionCallLabel(llvm::StringRef label)
static bool GetCompleteQualType(const clang::ASTContext *ast, clang::QualType qual_type)
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 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...
static const clang::ObjCObjectType * GetCompleteObjCObjectType(const clang::ASTContext *ast, QualType qual_type)
Returns the clang::ObjCObjectType of the specified qual_type.
#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
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
bool IsEnumerationType(bool &is_signed) const
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
void SetCompilerType(lldb::TypeSystemWP type_system, lldb::opaque_compiler_type_t type)
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.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
lldb::Encoding GetEncoding() const
uint32_t GetNumDirectBaseClasses() const
ConstString GetTypeName(bool BaseOnly=false) const
bool IsEnumerationIntegerTypeSigned() const
bool DumpTypeValue(Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope)
bool IsAggregateType() const
lldb::Format GetFormat() const
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) const
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
bool GetCompleteType() const
Type Completion.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
llvm::Expected< uint32_t > GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
llvm::Expected< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
A class that describes the declaration location of a lldb object.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
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)
static bool IsMangledName(llvm::StringRef name)
A class that describes an executable image and its associated object and symbol files.
virtual size_t GetByteOffsetForIvar(CompilerType &parent_qual_type, const char *ivar_name)
static ObjCLanguageRuntime * Get(Process &process)
unsigned GetValue() const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
uint32_t GetAddressByteSize() const
void Finalize() override
Free up any resources associated with this TypeSystem.
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
llvm::Triple m_triple
The target triple.
std::unique_ptr< ClangASTSource > CreateASTSource()
lldb::TargetWP m_target_wp
TypeSystemClang & GetIsolatedAST(IsolatedASTKind feature)
Returns the requested sub-AST.
UserExpression * GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, Expression::ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj) override
std::unique_ptr< ClangASTSource > m_scratch_ast_source_up
The ExternalASTSource that performs lookups and completes minimally imported types.
IsolatedASTKind
The different kinds of isolated ASTs within the scratch TypeSystem.
@ CppModules
The isolated AST for declarations/types from expressions that imported type information from a C++ mo...
void Dump(llvm::raw_ostream &output, llvm::StringRef filter, bool show_color) override
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).
static const std::nullopt_t DefaultAST
Alias for requesting the default scratch TypeSystemClang in GetForTarget.
ScratchTypeSystemClang(Target &target, llvm::Triple triple)
llvm::DenseMap< IsolatedASTKey, std::shared_ptr< TypeSystemClang > > m_isolated_asts
Map from IsolatedASTKind to their actual TypeSystemClang instance.
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
Provides public interface for all SymbolFiles.
virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx)
virtual bool CompleteType(CompilerType &compiler_type)=0
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list)=0
virtual std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx)=0
If type_uid points to an array type, return its characteristics.
llvm::Expected< lldb::TypeSystemSP > GetScratchTypeSystemForLanguage(lldb::LanguageType language, bool create_on_demand=true)
const ArchSpec & GetArchitecture() const
void Insert(_KeyType k, _ValueType v)
_ValueType Lookup(_KeyType k)
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
The implementation of lldb::Type's m_payload field for TypeSystemClang.
void SetIsCompleteObjCClass(bool is_complete_objc_class)
bool IsCompleteObjCClass()
Type::Payload m_payload
The payload is used for typedefs and ptrauth types.
TypePayloadClang()=default
void SetOwningModule(OptionalClangModuleID id)
static constexpr unsigned ObjCClassBit
llvm::ArrayRef< clang::TemplateArgument > GetParameterPackArgs() const
clang::TemplateArgument const & Front() const
llvm::StringRef GetPackName() const
bool hasParameterPack() const
TemplateParameterInfos const & GetParameterPack() const
llvm::ArrayRef< const char * > GetNames() const
llvm::ArrayRef< clang::TemplateArgument > GetArgs() const
A TypeSystem implementation based on Clang.
bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override
clang::ClassTemplateDecl * CreateClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef class_name, int kind, const TemplateParameterInfos &infos)
clang::ClassTemplateDecl * ParseClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const char *parent_name, int tag_decl_kind, const TypeSystemClang::TemplateParameterInfos &template_param_infos)
CompilerType GetTypeForIdentifier(const clang::ASTContext &Ctx, llvm::StringRef type_name, clang::DeclContext *decl_context=nullptr)
llvm::Expected< uint64_t > GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
CompilerType CreateFunctionType(const CompilerType &result_type, llvm::ArrayRef< CompilerType > args, bool is_variadic, unsigned type_quals, clang::CallingConv cc=clang::CC_C, clang::RefQualifierKind ref_qual=clang::RQ_None)
size_t GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) override
static clang::TypedefNameDecl * GetAsTypedefDecl(const CompilerType &type)
std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl, bool qualified=true)
Returns the internal type name for the given NamedDecl using the type printing policy.
static clang::ObjCInterfaceDecl * GetAsObjCInterfaceDecl(const CompilerType &type)
uint32_t m_pointer_byte_size
bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope) override
std::string m_display_name
A string describing what this TypeSystemClang represents (e.g., AST for debug information,...
ConstString GetTypeName(lldb::opaque_compiler_type_t type, bool base_only) override
static void SetOwningModule(clang::Decl *decl, OptionalClangModuleID owning_module)
Set the owning module for decl.
llvm::Expected< uint64_t > GetObjCBitSize(clang::QualType qual_type, ExecutionContextScope *exe_scope)
std::unique_ptr< clang::TargetInfo > m_target_info_up
std::unique_ptr< clang::LangOptions > m_language_options_up
Scalar DeclGetConstantValue(void *opaque_decl) override
llvm::Expected< CompilerType > GetDereferencedType(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, std::string &deref_name, uint32_t &deref_byte_size, int32_t &deref_byte_offset, ValueObject *valobj, uint64_t &language_flags) override
bool BaseSpecifierIsEmpty(const clang::CXXBaseSpecifier *b)
static uint32_t GetNumPointeeChildren(clang::QualType type)
ConstString DeclGetMangledName(void *opaque_decl) override
CompilerType GetBasicType(lldb::BasicType type)
std::unique_ptr< clang::HeaderSearchOptions > m_header_search_opts_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
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 *)
std::shared_ptr< clang::TargetOptions > & getTargetOptions()
static TypeSystemClang * GetASTContext(clang::ASTContext *ast_ctx)
bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) override
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
const char * GetTargetTriple()
TypeSystemClang(llvm::StringRef name, llvm::Triple triple)
Constructs a TypeSystemClang with an ASTContext using the given triple.
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, Module *module, Target *target)
clang::TargetInfo * getTargetInfo()
clang::FunctionTemplateDecl * CreateFunctionTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos)
CompilerType CreateArrayType(const CompilerType &element_type, std::optional< size_t > element_count, bool is_vector)
static bool AreTypesSame(CompilerType type1, CompilerType type2, bool ignore_qualifiers=false)
CompilerType GetArrayType(lldb::opaque_compiler_type_t type, uint64_t size) override
bool IsFunctionType(lldb::opaque_compiler_type_t type) override
CompilerType GetFunctionReturnType(lldb::opaque_compiler_type_t type) override
std::optional< ClangASTMetadata > GetMetadata(const clang::Decl *object)
CompilerType GetLValueReferenceType(lldb::opaque_compiler_type_t type) override
bool SetDeclIsForcefullyCompleted(const clang::TagDecl *td)
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override
bool CanPassInRegisters(const CompilerType &type) override
CompilerDecl GetStaticFieldWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name) override
static clang::DeclContext * GetDeclContextForType(clang::QualType type)
bool 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
std::unique_ptr< npdb::PdbAstBuilderClang > m_native_pdb_ast_parser_up
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override
static bool IsOperator(llvm::StringRef name, clang::OverloadedOperatorKind &op_kind)
bool IsCharType(lldb::opaque_compiler_type_t type) override
CompilerType CreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
static void SetFloatingInitializerForVariable(clang::VarDecl *var, const llvm::APFloat &init_value)
Initializes a variable with a floating point value.
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type) override
llvm::Expected< CompilerType > GetChildCompilerTypeAtIndex(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, uint32_t &child_byte_size, int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags) override
CompilerType GetType(clang::QualType qt)
Creates a CompilerType from the given QualType with the current TypeSystemClang instance as the Compi...
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override
std::string m_target_triple
bool TransferBaseClasses(lldb::opaque_compiler_type_t type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier > > bases)
bool IsBeingDefined(lldb::opaque_compiler_type_t type) override
CompilerType GetPromotedIntegerType(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
CompilerType CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *class_template_specialization_decl)
bool IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) override
std::unique_ptr< clang::DiagnosticOptions > m_diagnostic_options_up
void CreateFunctionTemplateSpecializationInfo(clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template, const TemplateParameterInfos &infos)
clang::EnumConstantDecl * AddEnumerationValueToEnumerationType(const CompilerType &enum_type, const Declaration &decl, const char *name, uint64_t enum_value, uint32_t enum_value_bit_size)
llvm::StringRef getDisplayName() const
Returns the display name of this TypeSystemClang that indicates what purpose it serves in LLDB.
static clang::VarDecl * AddVariableToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &var_type)
bool IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length)
CompilerType GetRValueReferenceType(lldb::opaque_compiler_type_t type) override
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
unsigned GetPtrAuthDiscriminator(lldb::opaque_compiler_type_t type) override
CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override
bool GetCompleteType(lldb::opaque_compiler_type_t type) override
bool IsBlockPointerType(lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) override
bool IsConst(lldb::opaque_compiler_type_t type) override
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
const llvm::fltSemantics & GetFloatTypeSemantics(size_t byte_size, lldb::Format format) override
bool IsFloatingPointType(lldb::opaque_compiler_type_t type) override
llvm::Expected< uint32_t > GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name, bool omit_empty_base_classes) override
void setSema(clang::Sema *s)
uint32_t GetPointerByteSize() override
bool IsCompleteType(lldb::opaque_compiler_type_t type) override
CompilerType GetIntTypeFromBitSize(size_t bit_size, bool is_signed)
clang::MangleContext * getMangleContext()
void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *)
unsigned GetPtrAuthKey(lldb::opaque_compiler_type_t type) override
static void DumpDeclContextHiearchy(clang::DeclContext *decl_ctx)
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
CompilerType GetTypeForFormatters(void *type) override
void SetMetadataAsUserID(const clang::Decl *decl, lldb::user_id_t user_id)
bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override
This is used by swift.
static LanguageSet GetSupportedLanguagesForExpressions()
clang::FunctionDecl * CreateFunctionDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, const CompilerType &function_Type, clang::StorageClass storage, bool is_inline, llvm::StringRef asm_label)
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
bool IsMemberDataPointerType(lldb::opaque_compiler_type_t type) 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)
bool HasPointerAuthQualifier(lldb::opaque_compiler_type_t type) override
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)
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)
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override
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)
llvm::SmallVector< clang::ParmVarDecl * > CreateParameterDeclarations(clang::FunctionDecl *context, const clang::FunctionProtoType &prototype, const llvm::SmallVector< llvm::StringRef > ¶m_names)
For each parameter type of prototype, creates a clang::ParmVarDecl whose clang::DeclContext is contex...
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
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, llvm::StringRef asm_label, const CompilerType &method_type, 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
LLVM_DUMP_METHOD void dump(lldb::opaque_compiler_type_t type) const override
Convenience LLVM-style dump method for use in the debugger only.
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)
static clang::CXXRecordDecl * GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type)
CompilerType GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name) override
static bool SetObjCSuperClass(const CompilerType &type, const CompilerType &superclass_compiler_type)
clang::UsingDirectiveDecl * CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::NamespaceDecl *ns_decl)
static lldb::opaque_compiler_type_t GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type)
bool IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) override
void DumpFromSymbolFile(Stream &s, llvm::StringRef symbol_name)
Dump clang AST types from the symbol file.
CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override
static void DumpDeclHiearchy(clang::Decl *decl)
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
static clang::FunctionDecl * DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc)
bool IsScalarType(lldb::opaque_compiler_type_t type) override
bool GetPtrAuthAddressDiversity(lldb::opaque_compiler_type_t type) override
std::shared_ptr< clang::TargetOptions > m_target_options_rp
lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override
static bool IsClassType(lldb::opaque_compiler_type_t type)
bool IsDefined(lldb::opaque_compiler_type_t type) override
static bool IsObjCClassType(const CompilerType &type)
TypeMetadataMap m_type_metadata
Maps Types to their associated ClangASTMetadata.
CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override
bool RecordHasFields(const clang::RecordDecl *record_decl)
CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index) override
static std::optional< ClangASTMetadata > DeclContextGetMetaData(const CompilerDeclContext &dc, const clang::Decl *object)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override
CompilerType GetPointerDiffType(bool is_signed) override
static clang::ObjCMethodDecl * AddMethodToObjCObjectType(const CompilerType &type, const char *name, const CompilerType &method_compiler_type, bool is_artificial, bool is_variadic, bool is_objc_direct_call)
~TypeSystemClang() override
CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override
bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, void *other_opaque_decl_ctx) override
CompilerType AddPtrAuthModifier(lldb::opaque_compiler_type_t type, uint32_t payload) override
static bool AddObjCClassProperty(const CompilerType &type, const char *property_name, const CompilerType &property_compiler_type, clang::ObjCIvarDecl *ivar_decl, const char *property_setter_name, const char *property_getter_name, uint32_t property_attributes, ClangASTMetadata metadata)
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
void SetMetadata(const clang::Decl *object, ClangASTMetadata meta_data)
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)
CompilerType CreateEnumerationType(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const Declaration &decl, const CompilerType &integer_qual_type, bool is_scoped, std::optional< clang::EnumExtensibilityAttr::Kind > enum_kind=std::nullopt)
npdb::PdbAstBuilder * GetNativePDBParser() override
std::unique_ptr< clang::DiagnosticConsumer > m_diagnostic_consumer_up
CompilerType CreateObjCClass(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool isInternal, std::optional< ClangASTMetadata > metadata=std::nullopt)
CompilerType GetTypeForDecl(clang::NamedDecl *decl)
CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) override
CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override
static clang::DeclContext * DeclContextGetAsDeclContext(const CompilerDeclContext &dc)
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
void Dump(llvm::raw_ostream &output, llvm::StringRef filter, bool show_color) 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 clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, uint32_t bitfield_bit_size)
CompilerType GetOrCreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
void LogCreation() const
Emits information about this TypeSystem into the expression log.
static llvm::StringRef GetPluginNameStatic()
clang::Sema * m_sema
The sema associated that is currently used to build this ASTContext.
size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override
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 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
static bool IsObjCObjectOrInterfaceType(const CompilerType &type)
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx, uint32_t opaque_payload) override
Using the current type, create a new typedef to that type using "typedef_name" as the name and "decl_...
llvm::Expected< uint32_t > GetNumChildren(lldb::opaque_compiler_type_t type, bool omit_empty_base_classes, const ExecutionContext *exe_ctx) override
CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override
clang::TemplateTemplateParmDecl * CreateTemplateTemplateParmDecl(const char *template_name)
lldb::TemplateArgumentKind GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx, bool expand_pack) override
clang::ASTContext & getASTContext() const
Returns the clang::ASTContext instance managed by this TypeSystemClang.
std::vector< lldb_private::CompilerContext > DeclGetCompilerContext(void *opaque_decl) override
static CompilerType CreateMemberPointerType(const CompilerType &type, const CompilerType &pointee_type)
std::vector< lldb_private::CompilerContext > DeclContextGetCompilerContext(void *opaque_decl_ctx) override
void CreateASTContext()
Creates the internal ASTContext.
void SetExternalSource(llvm::IntrusiveRefCntPtr< clang::ExternalASTSource > ast_source_sp)
CompilerType GetCStringType(bool is_const)
bool IsAggregateType(lldb::opaque_compiler_type_t type) override
bool IsPromotableIntegerType(lldb::opaque_compiler_type_t type) 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
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)
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
AddressType GetAddressTypeOfChildren()
CompilerType GetCompilerType()
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.
@ eFormatFloat128
Disambiguate between 128-bit long double (which uses eFormatFloat) and __float128 (which uses eFormat...
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)
static llvm::Expected< FunctionCallLabel > fromString(llvm::StringRef label)
Decodes the specified function label into a FunctionCallLabel.
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
void Insert(lldb::LanguageType language)
A type-erased pair of llvm::dwarf::SourceLanguageName and version.