23#include "clang/AST/ASTContext.h"
24#include "clang/Basic/SourceManager.h"
39class ScopedLexicalDeclEraser {
41 ScopedLexicalDeclEraser(std::set<const clang::Decl *> &decls,
42 const clang::Decl *decl)
43 : m_active_lexical_decls(decls), m_decl(decl) {}
45 ~ScopedLexicalDeclEraser() { m_active_lexical_decls.erase(m_decl); }
48 std::set<const clang::Decl *> &m_active_lexical_decls;
49 const clang::Decl *m_decl;
55 const std::shared_ptr<ClangASTImporter> &importer)
87 llvm::cast<ScratchTypeSystemClang>(scratch_ts_sp.get());
96 m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
97 m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
102 const DeclContext *decl_ctx, DeclarationName clang_decl_name,
103 const clang::DeclContext *original_dc) {
105 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
109 std::string decl_name(clang_decl_name.getAsString());
111 switch (clang_decl_name.getNameKind()) {
113 case DeclarationName::Identifier: {
114 clang::IdentifierInfo *identifier_info =
115 clang_decl_name.getAsIdentifierInfo();
117 if (!identifier_info || identifier_info->getBuiltinID() != 0) {
118 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
124 case DeclarationName::CXXOperatorName:
125 case DeclarationName::CXXLiteralOperatorName:
130 case DeclarationName::CXXUsingDirective:
131 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
134 case DeclarationName::ObjCZeroArgSelector:
135 case DeclarationName::ObjCOneArgSelector:
136 case DeclarationName::ObjCMultiArgSelector: {
137 llvm::SmallVector<NamedDecl *, 1> method_decls;
140 clang_decl_name, decl_ctx);
144 SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, method_decls);
145 return (method_decls.size() > 0);
148 case DeclarationName::CXXConstructorName:
149 case DeclarationName::CXXDestructorName:
150 case DeclarationName::CXXConversionFunctionName:
151 case DeclarationName::CXXDeductionGuideName:
152 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
159 if (!decl_name.empty() && decl_name[0] ==
'$') {
162 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
169 const char *uniqued_const_decl_name = const_decl_name.
GetCString();
173 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
177 llvm::SmallVector<NamedDecl *, 4> name_decls;
179 clang_decl_name, decl_ctx);
181 SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, name_decls);
183 return (name_decls.size() != 0);
189 if (
const NamespaceDecl *namespace_context =
190 dyn_cast<NamespaceDecl>(decl->getDeclContext())) {
197 LLDB_LOGV(log,
" CTD Inspecting namespace map{0:x} ({1} entries)",
198 namespace_map.get(), namespace_map->size());
201 LLDB_LOG(log,
" CTD Searching namespace {0} in module {1}",
202 item.second.GetName(), item.first->GetFileSpec().GetFilename());
211 item.first->FindTypes(query, results);
214 CompilerType clang_type(type_sp->GetFullCompilerType());
219 const TagType *tag_type =
225 TagDecl *candidate_tag_decl =
226 tag_type->getOriginalDecl()->getDefinitionOrSelf();
229 &candidate_tag_decl->getASTContext(), candidate_tag_decl))
230 return candidate_tag_decl;
239 module_list.
FindTypes(
nullptr, query, results);
242 CompilerType clang_type(type_sp->GetFullCompilerType());
247 const TagType *tag_type =
253 TagDecl *candidate_tag_decl =
254 tag_type->getOriginalDecl()->getDefinitionOrSelf();
258 return candidate_tag_decl;
269 " CompleteTagDecl on (ASTContext*){0} Completing "
270 "(TagDecl*){1:x} named {2}",
272 tag_decl->getName());
297 " [CompleteObjCInterfaceDecl] on (ASTContext*){0:x} '{1}' "
298 "Completing an ObjCInterfaceDecl named {2}",
300 interface_decl->getName());
301 LLDB_LOG(log,
" [COID] Before:\n{0}",
306 if (original.
Valid()) {
307 if (ObjCInterfaceDecl *original_iface_decl =
308 dyn_cast<ObjCInterfaceDecl>(original.
decl)) {
309 ObjCInterfaceDecl *complete_iface_decl =
312 if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
320 if (interface_decl->getSuperClass() &&
321 interface_decl->getSuperClass() != interface_decl)
329 const clang::ObjCInterfaceDecl *interface_decl) {
337 if (!language_runtime)
340 ConstString class_name(interface_decl->getNameAsString().c_str());
345 if (!complete_type_sp)
353 if (!complete_opaque_type)
356 const clang::Type *complete_clang_type =
357 QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
358 const ObjCInterfaceType *complete_interface_type =
359 dyn_cast<ObjCInterfaceType>(complete_clang_type);
361 if (!complete_interface_type)
364 ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl());
366 return complete_iface_decl;
370 const DeclContext *decl_context,
371 llvm::function_ref<
bool(Decl::Kind)> predicate,
376 const Decl *context_decl = dyn_cast<Decl>(decl_context);
388 if (
const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
390 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in "
391 "'{2}' ({3}Decl*){4}",
393 context_named_decl->getNameAsString().c_str(),
394 context_decl->getDeclKindName(),
395 static_cast<const void *
>(context_decl));
396 else if (context_decl)
398 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in "
401 context_decl->getDeclKindName(),
402 static_cast<const void *
>(context_decl));
405 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in a "
412 if (!original.
Valid())
415 LLDB_LOG(log,
" FELD Original decl (ASTContext*){0:x} (Decl*){1:x}:\n{2}",
416 static_cast<void *
>(original.
ctx),
417 static_cast<void *
>(original.
decl),
420 if (ObjCInterfaceDecl *original_iface_decl =
421 dyn_cast<ObjCInterfaceDecl>(original.
decl)) {
422 ObjCInterfaceDecl *complete_iface_decl =
425 if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
426 original.
decl = complete_iface_decl;
427 original.
ctx = &complete_iface_decl->getASTContext();
433 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original.
decl)) {
434 ExternalASTSource *external_source = original.
ctx->getExternalSource();
437 external_source->CompleteType(original_tag_decl);
440 const DeclContext *original_decl_context =
441 dyn_cast<DeclContext>(original.
decl);
443 if (!original_decl_context)
447 bool SkippedDecls =
false;
448 for (Decl *decl : original_decl_context->decls()) {
452 if (predicate(decl->getKind())) {
455 if (
const NamedDecl *context_named_decl =
456 dyn_cast<NamedDecl>(context_decl))
457 LLDB_LOG(log,
" FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}",
458 context_named_decl->getDeclKindName(),
459 context_named_decl->getName(), decl->getDeclKindName(),
462 LLDB_LOG(log,
" FELD Adding lexical {0}Decl {1}",
463 decl->getDeclKindName(), ast_dump);
480 if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) {
481 QualType copied_field_type = copied_field->getType();
494 decl_context->setHasExternalLexicalStorage(
true);
498 const_cast<DeclContext *
>(decl_context)->setMustBuildLookupTable();
512 "ClangASTSource::FindExternalVisibleDecls on "
513 "(ASTContext*){0:x} '{1}' for '{2}' in a NULL DeclContext",
515 else if (
const NamedDecl *context_named_decl =
518 "ClangASTSource::FindExternalVisibleDecls on "
519 "(ASTContext*){0:x} '{1}' for '{2}' in '{3}'",
521 context_named_decl->getName());
524 "ClangASTSource::FindExternalVisibleDecls on "
525 "(ASTContext*){0:x} '{1}' for '{2}' in a '{3}'",
540 LLDB_LOG(log,
" CAS::FEVD Searching the root namespace");
547 LLDB_LOG(log,
" CAS::FEVD Registering namespace map {0:x} ({1} entries)",
550 NamespaceDecl *clang_namespace_decl =
553 if (clang_namespace_decl)
554 clang_namespace_decl->setHasExternalVisibleStorage();
563 bool ignore_all_dollar_names) {
568 if (name == id_name || name == Class_name)
574 return name_string_ref.empty() ||
575 (ignore_all_dollar_names && name_string_ref.starts_with(
"$")) ||
576 name_string_ref.starts_with(
"_$");
602 if (module_sp && namespace_decl) {
604 TypeQuery query(namespace_decl, name, TypeQueryOptions::e_find_one);
605 module_sp->FindTypes(query, results);
610 TypeQueryOptions::e_find_one);
611 m_target->GetImages().FindTypes(
nullptr, query, results);
617 const char *name_string = type_sp->GetName().GetCString();
619 LLDB_LOG(log,
" CAS::FEVD Matching type found for \"{0}\": {1}", name,
620 (name_string ? name_string :
"<anonymous>"));
623 CompilerType full_type = type_sp->GetFullCompilerType();
627 if (!copied_clang_type) {
628 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type");
656 if (module_sp && namespace_decl) {
659 if (
SymbolFile *symbol_file = module_sp->GetSymbolFile()) {
660 found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl);
662 if (found_namespace_decl) {
664 std::pair<lldb::ModuleSP, CompilerDeclContext>(
665 module_sp, found_namespace_decl));
667 LLDB_LOG(log,
" CAS::FEVD Found namespace {0} in module {1}", name,
668 module_sp->GetFileSpec().GetFilename());
680 SymbolFile *symbol_file = image->GetSymbolFile();
692 const bool find_root_namespaces =
696 name, namespace_decl, find_root_namespaces);
698 if (found_namespace_decl) {
700 std::pair<lldb::ModuleSP, CompilerDeclContext>(image,
701 found_namespace_decl));
703 LLDB_LOG(log,
" CAS::FEVD Found namespace {0} in module {1}", name,
704 image->GetFileSpec().GetFilename());
711 const char *log_info) {
712 const DeclarationName &decl_name(context.
m_decl_name);
713 clang::ASTContext *original_ctx = &original_interface_decl->getASTContext();
715 Selector original_selector;
717 if (decl_name.isObjCZeroArgSelector()) {
718 const IdentifierInfo *ident =
719 &original_ctx->Idents.get(decl_name.getAsString());
720 original_selector = original_ctx->Selectors.getSelector(0, &ident);
721 }
else if (decl_name.isObjCOneArgSelector()) {
722 const std::string &decl_name_string = decl_name.getAsString();
723 std::string decl_name_string_without_colon(decl_name_string.c_str(),
724 decl_name_string.length() - 1);
725 const IdentifierInfo *ident =
726 &original_ctx->Idents.get(decl_name_string_without_colon);
727 original_selector = original_ctx->Selectors.getSelector(1, &ident);
729 SmallVector<const IdentifierInfo *, 4> idents;
731 clang::Selector sel = decl_name.getObjCSelector();
733 unsigned num_args = sel.getNumArgs();
735 for (
unsigned i = 0; i != num_args; ++i) {
736 idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
740 original_ctx->Selectors.getSelector(num_args, idents.data());
743 DeclarationName original_decl_name(original_selector);
745 llvm::SmallVector<NamedDecl *, 1> methods;
749 if (ObjCMethodDecl *instance_method_decl =
750 original_interface_decl->lookupInstanceMethod(original_selector)) {
751 methods.push_back(instance_method_decl);
752 }
else if (ObjCMethodDecl *class_method_decl =
753 original_interface_decl->lookupClassMethod(
754 original_selector)) {
755 methods.push_back(class_method_decl);
758 if (methods.empty()) {
762 for (NamedDecl *named_decl : methods) {
766 ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl);
771 Decl *copied_decl =
CopyDecl(result_method);
776 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
778 if (!copied_method_decl)
783 LLDB_LOG(log,
" CAS::FOMD found ({0}) {1}", log_info,
796 std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
798 if (!modules_decl_vendor)
802 uint32_t max_matches = 1;
803 std::vector<clang::NamedDecl *> decls;
805 if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
808 LLDB_LOG(log,
" CAS::FEVD Matching entity found for \"{0}\" in the modules",
811 clang::NamedDecl *
const decl_from_modules = decls[0];
813 if (llvm::isa<clang::TypeDecl>(decl_from_modules) ||
814 llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
815 llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) {
816 clang::Decl *copied_decl =
CopyDecl(decl_from_modules);
817 clang::NamedDecl *copied_named_decl =
818 copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) :
nullptr;
820 if (!copied_named_decl) {
821 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type from the modules");
843 if (!language_runtime)
852 uint32_t max_matches = 1;
853 std::vector<clang::NamedDecl *> decls;
855 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
856 if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls))
859 LLDB_LOG(log,
" CAS::FEVD Matching type found for \"{0}\" in the runtime",
862 clang::Decl *copied_decl =
CopyDecl(decls[0]);
863 clang::NamedDecl *copied_named_decl =
864 copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) :
nullptr;
866 if (!copied_named_decl) {
867 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type from the runtime");
878 const DeclarationName &decl_name(context.
m_decl_name);
881 const ObjCInterfaceDecl *interface_decl =
882 dyn_cast<ObjCInterfaceDecl>(decl_ctx);
890 if (!original.
Valid())
893 ObjCInterfaceDecl *original_interface_decl =
894 dyn_cast<ObjCInterfaceDecl>(original.
decl);
903 if (decl_name.isObjCZeroArgSelector()) {
904 ss.
Printf(
"%s", decl_name.getAsString().c_str());
905 }
else if (decl_name.isObjCOneArgSelector()) {
906 ss.
Printf(
"%s", decl_name.getAsString().c_str());
908 clang::Selector sel = decl_name.getObjCSelector();
910 for (
unsigned i = 0, e = sel.getNumArgs(); i != e; ++i) {
911 llvm::StringRef r = sel.getNameForSlot(i);
912 ss.
Printf(
"%s:", r.str().c_str());
923 "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0:x} '{1}' "
924 "for selector [{2} {3}]",
926 interface_decl->getName(), selector_name);
933 std::string interface_name = interface_decl->getNameAsString();
937 ms.
Printf(
"-[%s %s]", interface_name.c_str(), selector_name.
AsCString());
942 m_target->GetImages().FindFunctions(instance_method_name,
943 lldb::eFunctionNameTypeFull,
944 function_options, sc_list);
950 ms.
Printf(
"+[%s %s]", interface_name.c_str(), selector_name.
AsCString());
955 m_target->GetImages().FindFunctions(class_method_name,
956 lldb::eFunctionNameTypeFull,
957 function_options, sc_list);
968 m_target->GetImages().FindFunctions(selector_name,
969 lldb::eFunctionNameTypeSelector,
970 function_options, candidate_sc_list);
972 for (
const SymbolContext &candidate_sc : candidate_sc_list) {
973 if (!candidate_sc.function)
976 const char *candidate_name = candidate_sc.function->GetName().AsCString();
978 const char *cursor = candidate_name;
980 if (*cursor !=
'+' && *cursor !=
'-')
990 size_t interface_len = interface_name.length();
992 if (strncmp(cursor, interface_name.c_str(), interface_len))
995 cursor += interface_len;
997 if (*cursor ==
' ' || *cursor ==
'(')
998 sc_list.
Append(candidate_sc);
1010 if (!function_decl_ctx)
1013 ObjCMethodDecl *method_decl =
1019 ObjCInterfaceDecl *found_interface_decl =
1020 method_decl->getClassInterface();
1022 if (!found_interface_decl)
1025 if (found_interface_decl->getName() == interface_decl->getName()) {
1026 Decl *copied_decl =
CopyDecl(method_decl);
1031 ObjCMethodDecl *copied_method_decl =
1032 dyn_cast<ObjCMethodDecl>(copied_decl);
1034 if (!copied_method_decl)
1037 LLDB_LOG(log,
" CAS::FOMD found (in symbols)\n{0}",
1051 const_cast<ObjCInterfaceDecl *
>(interface_decl));
1053 if (!complete_interface_decl)
1060 complete_interface_decl);
1062 if (complete_interface_decl == interface_decl)
1066 "CAS::FOPD trying origin "
1067 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1068 complete_interface_decl, &complete_iface_decl->getASTContext());
1080 if (std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
1082 ConstString interface_name(interface_decl->getNameAsString().c_str());
1083 bool append =
false;
1084 uint32_t max_matches = 1;
1085 std::vector<clang::NamedDecl *> decls;
1087 if (!modules_decl_vendor->FindDecls(interface_name, append, max_matches,
1091 ObjCInterfaceDecl *interface_decl_from_modules =
1092 dyn_cast<ObjCInterfaceDecl>(decls[0]);
1094 if (!interface_decl_from_modules)
1114 if (!language_runtime)
1122 ConstString interface_name(interface_decl->getNameAsString().c_str());
1123 bool append =
false;
1124 uint32_t max_matches = 1;
1125 std::vector<clang::NamedDecl *> decls;
1127 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
1128 if (!clang_decl_vendor->FindDecls(interface_name, append, max_matches,
1132 ObjCInterfaceDecl *runtime_interface_decl =
1133 dyn_cast<ObjCInterfaceDecl>(decls[0]);
1135 if (!runtime_interface_decl)
1151 std::string name_str = context.
m_decl_name.getAsString();
1152 StringRef name(name_str);
1153 IdentifierInfo &name_identifier(
1154 origin_iface_decl->getASTContext().Idents.get(name));
1157 origin_iface_decl->FindPropertyDeclaration(
1158 &name_identifier, ObjCPropertyQueryKind::OBJC_PR_query_instance));
1162 if (origin_property_decl.
IsValid()) {
1165 if (parser_property_decl.
IsValid()) {
1166 LLDB_LOG(log,
" CAS::FOPD found\n{0}",
1175 origin_iface_decl->getIvarDecl(&name_identifier));
1177 if (origin_ivar_decl.
IsValid()) {
1180 if (parser_ivar_decl.
IsValid()) {
1181 LLDB_LOG(log,
" CAS::FOPD found\n{0}",
1200 ConstString class_name(parser_iface_decl->getNameAsString().c_str());
1203 "ClangASTSource::FindObjCPropertyAndIvarDecls on "
1204 "(ASTContext*){0:x} '{1}' for '{2}.{3}'",
1206 parser_iface_decl->getName(), context.
m_decl_name.getAsString());
1212 "CAS::FOPD couldn't find the property on origin "
1213 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}, searching "
1215 origin_iface_decl.
decl, &origin_iface_decl->getASTContext());
1222 const_cast<ObjCInterfaceDecl *
>(parser_iface_decl.
decl));
1224 if (!complete_interface_decl)
1231 complete_interface_decl);
1233 if (complete_iface_decl.
decl == origin_iface_decl.
decl)
1237 "CAS::FOPD trying origin "
1238 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1239 complete_iface_decl.
decl, &complete_iface_decl->getASTContext());
1250 std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
1253 if (!modules_decl_vendor)
1256 bool append =
false;
1257 uint32_t max_matches = 1;
1258 std::vector<clang::NamedDecl *> decls;
1260 if (!modules_decl_vendor->FindDecls(class_name, append, max_matches, decls))
1264 dyn_cast<ObjCInterfaceDecl>(decls[0]));
1266 if (!interface_decl_from_modules.
IsValid())
1270 "CAS::FOPD[{0:x}] trying module "
1271 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1272 interface_decl_from_modules.
decl,
1273 &interface_decl_from_modules->getASTContext());
1276 interface_decl_from_modules))
1291 if (!language_runtime)
1299 bool append =
false;
1300 uint32_t max_matches = 1;
1301 std::vector<clang::NamedDecl *> decls;
1303 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
1304 if (!clang_decl_vendor->FindDecls(class_name, append, max_matches, decls))
1308 dyn_cast<ObjCInterfaceDecl>(decls[0]));
1310 if (!interface_decl_from_runtime.
IsValid())
1314 "CAS::FOPD[{0:x}] trying runtime "
1315 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1316 interface_decl_from_runtime.
decl,
1317 &interface_decl_from_runtime->getASTContext());
1320 interface_decl_from_runtime))
1326 const NamespaceDecl *namespace_context =
1334 LLDB_LOGV(log,
" CAS::FEVD Inspecting namespace map {0:x} ({1} entries)",
1335 namespace_map.get(), namespace_map->size());
1340 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
1341 e = namespace_map->end();
1343 LLDB_LOG(log,
" CAS::FEVD Searching namespace {0} in module {1}",
1344 i->second.GetName(), i->first->GetFileSpec().GetFilename());
1351 const RecordDecl *record, uint64_t &size, uint64_t &alignment,
1352 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
1353 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
1355 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
1356 &virtual_base_offsets) {
1358 record, size, alignment, field_offsets, base_offsets,
1359 virtual_base_offsets);
1369 if (parent_map && parent_map->size())
1371 "CompleteNamespaceMap on (ASTContext*){0:x} '{1}' Searching "
1372 "for namespace {2} in namespace {3}",
1374 parent_map->begin()->second.GetName());
1377 "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching "
1378 "for namespace {2}",
1383 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(),
1384 e = parent_map->end();
1391 SymbolFile *symbol_file = module_sp->GetSymbolFile();
1396 found_namespace_decl =
1397 symbol_file->
FindNamespace(name, module_parent_namespace_decl);
1399 if (!found_namespace_decl)
1402 namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
1403 module_sp, found_namespace_decl));
1405 LLDB_LOG(log,
" CMN Found namespace {0} in module {1}", name,
1406 module_sp->GetFileSpec().GetFilename());
1416 SymbolFile *symbol_file = image->GetSymbolFile();
1421 found_namespace_decl =
1424 if (!found_namespace_decl)
1427 namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
1428 image, found_namespace_decl));
1430 LLDB_LOG(log,
" CMN[{0}] Found namespace {0} in module {1}", name,
1431 image->GetFileSpec().GetFilename());
1439 if (!namespace_decls)
1444 clang::ASTContext *src_ast =
1448 clang::NamespaceDecl *src_namespace_decl =
1451 if (!src_namespace_decl)
1454 Decl *copied_decl =
CopyDecl(src_namespace_decl);
1459 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
1461 if (!copied_namespace_decl)
1464 context.
m_decls.push_back(copied_namespace_decl);
1469 return dyn_cast<NamespaceDecl>(copied_decl);
1488 if (copied_qual_type.getAsOpaquePtr() &&
1489 copied_qual_type->getCanonicalTypeInternal().isNull())
1497std::shared_ptr<ClangModulesDeclVendor>
1499 auto persistent_vars = llvm::cast<ClangPersistentVariables>(
1501 return persistent_vars->GetClangModulesDeclVendor();
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGV(log,...)
std::shared_ptr< NamespaceMap > NamespaceMapSP
std::pair< lldb::ModuleSP, CompilerDeclContext > NamespaceMapItem
std::set< const char * > m_active_lookups
void LookupInNamespace(NameSearchContext &context)
Performs lookup into a namespace.
void SetLookupsEnabled(bool lookups_enabled)
clang::TagDecl * FindCompleteType(const clang::TagDecl *decl)
clang::ASTContext * m_ast_context
The AST context requests are coming in for.
ClangASTSource(const lldb::TargetSP &target, const std::shared_ptr< ClangASTImporter > &importer)
Constructor.
std::set< const clang::Decl * > m_active_lexical_decls
void FindExternalLexicalDecls(const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Decls) override
Enumerate all Decls in a given lexical context.
bool layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &BaseOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &VirtualBaseOffsets) override
Specify the layout of the contents of a RecordDecl.
clang::Decl * CopyDecl(clang::Decl *src_decl)
Copies a single Decl into the parser's AST context.
bool IgnoreName(const ConstString name, bool ignore_all_dollar_names)
Returns true if a name should be ignored by name lookup.
virtual void FindExternalVisibleDecls(NameSearchContext &context)
The worker function for FindExternalVisibleDeclsByName.
void FindObjCPropertyAndIvarDecls(NameSearchContext &context)
Find all Objective-C properties and ivars with a given name.
friend struct NameSearchContext
ClangASTImporter::DeclOrigin GetDeclOrigin(const clang::Decl *decl)
Determined the origin of a single Decl, if it can be found.
bool FindObjCPropertyAndIvarDeclsWithOrigin(NameSearchContext &context, DeclFromUser< const clang::ObjCInterfaceDecl > &origin_iface_decl)
bool FindObjCMethodDeclsWithOrigin(NameSearchContext &context, clang::ObjCInterfaceDecl *original_interface_decl, const char *log_info)
std::shared_ptr< ClangModulesDeclVendor > GetClangModulesDeclVendor()
void CompleteNamespaceMap(ClangASTImporter::NamespaceMapSP &namespace_map, ConstString name, ClangASTImporter::NamespaceMapSP &parent_map) const override
Look up the modules containing a given namespace and put the appropriate entries in the namespace map...
void FindDeclInObjCRuntime(NameSearchContext &context, ConstString name)
void CompleteType(clang::TagDecl *Tag) override
Complete a TagDecl.
~ClangASTSource() override
Destructor.
void FillNamespaceMap(NameSearchContext &context, lldb::ModuleSP module_sp, const CompilerDeclContext &namespace_decl)
Fills the namespace map of the given NameSearchContext.
CompilerType GuardedCopyType(const CompilerType &src_type)
A wrapper for TypeSystemClang::CopyType that sets a flag that indicates that we should not respond to...
void FindDeclInModules(NameSearchContext &context, ConstString name)
bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name, const clang::DeclContext *OriginalDC) override
Look up all Decls that match a particular name.
clang::NamespaceDecl * AddNamespace(NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
std::shared_ptr< ClangASTImporter > m_ast_importer_sp
The target's AST importer.
void InstallASTContext(TypeSystemClang &ast_context)
TypeSystemClang * m_clang_ast_context
The TypeSystemClang for m_ast_context.
void FindObjCMethodDecls(NameSearchContext &context)
Find all Objective-C methods matching a given selector.
const lldb::TargetSP m_target
The target to use in finding variables and types.
clang::ObjCInterfaceDecl * GetCompleteObjCInterface(const clang::ObjCInterfaceDecl *interface_decl)
Look for the complete version of an Objective-C interface, and return it if found.
void StartTranslationUnit(clang::ASTConsumer *Consumer) override
Called on entering a translation unit.
clang::FileManager * m_file_manager
The file manager paired with the AST context.
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
DeclFromUser< D > GetOrigin(ClangASTImporter &importer)
DeclFromParser< D > Import(clang::ASTContext *dest_ctx, ClangASTImporter &importer)
virtual DeclVendor * GetDeclVendor()
A collection class for Module objects.
void FindTypes(Module *search_first, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
lldb::TypeSP LookupInCompleteClassCache(ConstString &name)
static ObjCLanguageRuntime * Get(Process &process)
The TypeSystemClang instance used for the scratch ASTContext in a lldb::Target.
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.
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.
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
void Clear()
Clear the object's state.
Defines a symbol context baton that can be handed other debug core functions.
Provides public interface for all SymbolFiles.
virtual CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces=false)
Finds a namespace of name name and whose parent context is parent_decl_ctx.
TypeIterable Types() const
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
lldb::TypeSP GetFirstType() const
A TypeSystem implementation based on Clang.
llvm::StringRef getDisplayName() const
Returns the display name of this TypeSystemClang that indicates what purpose it serves in LLDB.
static clang::ASTContext * DeclContextGetTypeSystemClang(const CompilerDeclContext &dc)
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
static clang::NamespaceDecl * DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc)
bool GetCompleteDecl(clang::Decl *decl)
clang::ASTContext & getASTContext() const
Returns the clang::ASTContext instance managed by this TypeSystemClang.
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.
TaggedASTType< 1 > TypeFromUser
void * opaque_compiler_type_t
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
static clang::QualType GetQualType(const CompilerType &ct)
static std::string DumpDecl(const clang::Decl *d)
Returns a textual representation of the given Decl's AST.
static bool IsClangType(const CompilerType &ct)
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.
clang::NamedDecl * AddTypeDecl(const CompilerType &compiler_type)
Create a TypeDecl with the name being searched for and the provided type and register it in the right...
const clang::DeclarationName m_decl_name
The name being looked for.
llvm::SmallVectorImpl< clang::NamedDecl * > & m_decls
The list of declarations already constructed.
const clang::DeclContext * m_decl_context
The DeclContext to put declarations into.
void AddNamedDecl(clang::NamedDecl *decl)
Add a NamedDecl to the list of results.
ClangASTImporter::NamespaceMapSP m_namespace_map
The mapping of all namespaces found for this request back to their modules.