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)
56 : m_lookups_enabled(false), m_target(target), m_ast_context(nullptr),
57 m_ast_importer_sp(importer), m_active_lexical_decls(),
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 const_cast<TagDecl *
>(tag_type->getDecl());
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 =
const_cast<TagDecl *
>(tag_type->getDecl());
257 return candidate_tag_decl;
268 " CompleteTagDecl on (ASTContext*){0} Completing "
269 "(TagDecl*){1:x} named {2}",
271 tag_decl->getName());
296 " [CompleteObjCInterfaceDecl] on (ASTContext*){0:x} '{1}' "
297 "Completing an ObjCInterfaceDecl named {2}",
299 interface_decl->getName());
300 LLDB_LOG(log,
" [COID] Before:\n{0}",
305 if (original.
Valid()) {
306 if (ObjCInterfaceDecl *original_iface_decl =
307 dyn_cast<ObjCInterfaceDecl>(original.
decl)) {
308 ObjCInterfaceDecl *complete_iface_decl =
311 if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
319 if (interface_decl->getSuperClass() &&
320 interface_decl->getSuperClass() != interface_decl)
328 const clang::ObjCInterfaceDecl *interface_decl) {
336 if (!language_runtime)
339 ConstString class_name(interface_decl->getNameAsString().c_str());
344 if (!complete_type_sp)
352 if (!complete_opaque_type)
355 const clang::Type *complete_clang_type =
356 QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
357 const ObjCInterfaceType *complete_interface_type =
358 dyn_cast<ObjCInterfaceType>(complete_clang_type);
360 if (!complete_interface_type)
363 ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl());
365 return complete_iface_decl;
369 const DeclContext *decl_context,
370 llvm::function_ref<
bool(Decl::Kind)> predicate,
375 const Decl *context_decl = dyn_cast<Decl>(decl_context);
387 if (
const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
389 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in "
390 "'{2}' ({3}Decl*){4}",
392 context_named_decl->getNameAsString().c_str(),
393 context_decl->getDeclKindName(),
394 static_cast<const void *
>(context_decl));
395 else if (context_decl)
397 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in "
400 context_decl->getDeclKindName(),
401 static_cast<const void *
>(context_decl));
404 "FindExternalLexicalDecls on (ASTContext*){0:x} '{1}' in a "
411 if (!original.
Valid())
414 LLDB_LOG(log,
" FELD Original decl (ASTContext*){0:x} (Decl*){1:x}:\n{2}",
415 static_cast<void *
>(original.
ctx),
416 static_cast<void *
>(original.
decl),
419 if (ObjCInterfaceDecl *original_iface_decl =
420 dyn_cast<ObjCInterfaceDecl>(original.
decl)) {
421 ObjCInterfaceDecl *complete_iface_decl =
424 if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
425 original.
decl = complete_iface_decl;
426 original.
ctx = &complete_iface_decl->getASTContext();
432 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original.
decl)) {
433 ExternalASTSource *external_source = original.
ctx->getExternalSource();
436 external_source->CompleteType(original_tag_decl);
439 const DeclContext *original_decl_context =
440 dyn_cast<DeclContext>(original.
decl);
442 if (!original_decl_context)
446 bool SkippedDecls =
false;
447 for (Decl *decl : original_decl_context->decls()) {
451 if (predicate(decl->getKind())) {
454 if (
const NamedDecl *context_named_decl =
455 dyn_cast<NamedDecl>(context_decl))
456 LLDB_LOG(log,
" FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}",
457 context_named_decl->getDeclKindName(),
458 context_named_decl->getName(), decl->getDeclKindName(),
461 LLDB_LOG(log,
" FELD Adding lexical {0}Decl {1}",
462 decl->getDeclKindName(), ast_dump);
479 if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) {
480 QualType copied_field_type = copied_field->getType();
493 decl_context->setHasExternalLexicalStorage(
true);
497 const_cast<DeclContext *
>(decl_context)->setMustBuildLookupTable();
511 "ClangASTSource::FindExternalVisibleDecls on "
512 "(ASTContext*){0:x} '{1}' for '{2}' in a NULL DeclContext",
514 else if (
const NamedDecl *context_named_decl =
517 "ClangASTSource::FindExternalVisibleDecls on "
518 "(ASTContext*){0:x} '{1}' for '{2}' in '{3}'",
520 context_named_decl->getName());
523 "ClangASTSource::FindExternalVisibleDecls on "
524 "(ASTContext*){0:x} '{1}' for '{2}' in a '{3}'",
539 LLDB_LOG(log,
" CAS::FEVD Searching the root namespace");
546 LLDB_LOG(log,
" CAS::FEVD Registering namespace map {0:x} ({1} entries)",
549 NamespaceDecl *clang_namespace_decl =
552 if (clang_namespace_decl)
553 clang_namespace_decl->setHasExternalVisibleStorage();
562 bool ignore_all_dollar_names) {
567 if (name == id_name || name == Class_name)
573 return name_string_ref.empty() ||
574 (ignore_all_dollar_names && name_string_ref.starts_with(
"$")) ||
575 name_string_ref.starts_with(
"_$");
601 if (module_sp && namespace_decl) {
603 TypeQuery query(namespace_decl, name, TypeQueryOptions::e_find_one);
604 module_sp->FindTypes(query, results);
609 TypeQueryOptions::e_find_one);
610 m_target->GetImages().FindTypes(
nullptr, query, results);
616 const char *name_string = type_sp->GetName().GetCString();
618 LLDB_LOG(log,
" CAS::FEVD Matching type found for \"{0}\": {1}", name,
619 (name_string ? name_string :
"<anonymous>"));
622 CompilerType full_type = type_sp->GetFullCompilerType();
626 if (!copied_clang_type) {
627 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type");
655 if (module_sp && namespace_decl) {
658 if (
SymbolFile *symbol_file = module_sp->GetSymbolFile()) {
659 found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl);
661 if (found_namespace_decl) {
663 std::pair<lldb::ModuleSP, CompilerDeclContext>(
664 module_sp, found_namespace_decl));
666 LLDB_LOG(log,
" CAS::FEVD Found namespace {0} in module {1}", name,
667 module_sp->GetFileSpec().GetFilename());
679 SymbolFile *symbol_file = image->GetSymbolFile();
691 const bool find_root_namespaces =
695 name, namespace_decl, find_root_namespaces);
697 if (found_namespace_decl) {
699 std::pair<lldb::ModuleSP, CompilerDeclContext>(image,
700 found_namespace_decl));
702 LLDB_LOG(log,
" CAS::FEVD Found namespace {0} in module {1}", name,
703 image->GetFileSpec().GetFilename());
710 const char *log_info) {
711 const DeclarationName &decl_name(context.
m_decl_name);
712 clang::ASTContext *original_ctx = &original_interface_decl->getASTContext();
714 Selector original_selector;
716 if (decl_name.isObjCZeroArgSelector()) {
717 const IdentifierInfo *ident =
718 &original_ctx->Idents.get(decl_name.getAsString());
719 original_selector = original_ctx->Selectors.getSelector(0, &ident);
720 }
else if (decl_name.isObjCOneArgSelector()) {
721 const std::string &decl_name_string = decl_name.getAsString();
722 std::string decl_name_string_without_colon(decl_name_string.c_str(),
723 decl_name_string.length() - 1);
724 const IdentifierInfo *ident =
725 &original_ctx->Idents.get(decl_name_string_without_colon);
726 original_selector = original_ctx->Selectors.getSelector(1, &ident);
728 SmallVector<const IdentifierInfo *, 4> idents;
730 clang::Selector sel = decl_name.getObjCSelector();
732 unsigned num_args = sel.getNumArgs();
734 for (
unsigned i = 0; i != num_args; ++i) {
735 idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
739 original_ctx->Selectors.getSelector(num_args, idents.data());
742 DeclarationName original_decl_name(original_selector);
744 llvm::SmallVector<NamedDecl *, 1> methods;
748 if (ObjCMethodDecl *instance_method_decl =
749 original_interface_decl->lookupInstanceMethod(original_selector)) {
750 methods.push_back(instance_method_decl);
751 }
else if (ObjCMethodDecl *class_method_decl =
752 original_interface_decl->lookupClassMethod(
753 original_selector)) {
754 methods.push_back(class_method_decl);
757 if (methods.empty()) {
761 for (NamedDecl *named_decl : methods) {
765 ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl);
770 Decl *copied_decl =
CopyDecl(result_method);
775 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
777 if (!copied_method_decl)
782 LLDB_LOG(log,
" CAS::FOMD found ({0}) {1}", log_info,
795 std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
797 if (!modules_decl_vendor)
801 uint32_t max_matches = 1;
802 std::vector<clang::NamedDecl *> decls;
804 if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
807 LLDB_LOG(log,
" CAS::FEVD Matching entity found for \"{0}\" in the modules",
810 clang::NamedDecl *
const decl_from_modules = decls[0];
812 if (llvm::isa<clang::TypeDecl>(decl_from_modules) ||
813 llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
814 llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) {
815 clang::Decl *copied_decl =
CopyDecl(decl_from_modules);
816 clang::NamedDecl *copied_named_decl =
817 copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) :
nullptr;
819 if (!copied_named_decl) {
820 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type from the modules");
842 if (!language_runtime)
851 uint32_t max_matches = 1;
852 std::vector<clang::NamedDecl *> decls;
854 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
855 if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls))
858 LLDB_LOG(log,
" CAS::FEVD Matching type found for \"{0}\" in the runtime",
861 clang::Decl *copied_decl =
CopyDecl(decls[0]);
862 clang::NamedDecl *copied_named_decl =
863 copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) :
nullptr;
865 if (!copied_named_decl) {
866 LLDB_LOG(log,
" CAS::FEVD - Couldn't export a type from the runtime");
877 const DeclarationName &decl_name(context.
m_decl_name);
880 const ObjCInterfaceDecl *interface_decl =
881 dyn_cast<ObjCInterfaceDecl>(decl_ctx);
889 if (!original.
Valid())
892 ObjCInterfaceDecl *original_interface_decl =
893 dyn_cast<ObjCInterfaceDecl>(original.
decl);
902 if (decl_name.isObjCZeroArgSelector()) {
903 ss.
Printf(
"%s", decl_name.getAsString().c_str());
904 }
else if (decl_name.isObjCOneArgSelector()) {
905 ss.
Printf(
"%s", decl_name.getAsString().c_str());
907 clang::Selector sel = decl_name.getObjCSelector();
909 for (
unsigned i = 0, e = sel.getNumArgs(); i != e; ++i) {
910 llvm::StringRef r = sel.getNameForSlot(i);
911 ss.
Printf(
"%s:", r.str().c_str());
922 "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0:x} '{1}' "
923 "for selector [{2} {3}]",
925 interface_decl->getName(), selector_name);
932 std::string interface_name = interface_decl->getNameAsString();
936 ms.
Printf(
"-[%s %s]", interface_name.c_str(), selector_name.
AsCString());
941 m_target->GetImages().FindFunctions(instance_method_name,
942 lldb::eFunctionNameTypeFull,
943 function_options, sc_list);
949 ms.
Printf(
"+[%s %s]", interface_name.c_str(), selector_name.
AsCString());
954 m_target->GetImages().FindFunctions(class_method_name,
955 lldb::eFunctionNameTypeFull,
956 function_options, sc_list);
967 m_target->GetImages().FindFunctions(selector_name,
968 lldb::eFunctionNameTypeSelector,
969 function_options, candidate_sc_list);
971 for (
const SymbolContext &candidate_sc : candidate_sc_list) {
972 if (!candidate_sc.function)
975 const char *candidate_name = candidate_sc.function->GetName().AsCString();
977 const char *cursor = candidate_name;
979 if (*cursor !=
'+' && *cursor !=
'-')
989 size_t interface_len = interface_name.length();
991 if (strncmp(cursor, interface_name.c_str(), interface_len))
994 cursor += interface_len;
996 if (*cursor ==
' ' || *cursor ==
'(')
997 sc_list.
Append(candidate_sc);
1009 if (!function_decl_ctx)
1012 ObjCMethodDecl *method_decl =
1018 ObjCInterfaceDecl *found_interface_decl =
1019 method_decl->getClassInterface();
1021 if (!found_interface_decl)
1024 if (found_interface_decl->getName() == interface_decl->getName()) {
1025 Decl *copied_decl =
CopyDecl(method_decl);
1030 ObjCMethodDecl *copied_method_decl =
1031 dyn_cast<ObjCMethodDecl>(copied_decl);
1033 if (!copied_method_decl)
1036 LLDB_LOG(log,
" CAS::FOMD found (in symbols)\n{0}",
1050 const_cast<ObjCInterfaceDecl *
>(interface_decl));
1052 if (!complete_interface_decl)
1059 complete_interface_decl);
1061 if (complete_interface_decl == interface_decl)
1065 "CAS::FOPD trying origin "
1066 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1067 complete_interface_decl, &complete_iface_decl->getASTContext());
1079 if (std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
1081 ConstString interface_name(interface_decl->getNameAsString().c_str());
1082 bool append =
false;
1083 uint32_t max_matches = 1;
1084 std::vector<clang::NamedDecl *> decls;
1086 if (!modules_decl_vendor->FindDecls(interface_name, append, max_matches,
1090 ObjCInterfaceDecl *interface_decl_from_modules =
1091 dyn_cast<ObjCInterfaceDecl>(decls[0]);
1093 if (!interface_decl_from_modules)
1113 if (!language_runtime)
1121 ConstString interface_name(interface_decl->getNameAsString().c_str());
1122 bool append =
false;
1123 uint32_t max_matches = 1;
1124 std::vector<clang::NamedDecl *> decls;
1126 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
1127 if (!clang_decl_vendor->FindDecls(interface_name, append, max_matches,
1131 ObjCInterfaceDecl *runtime_interface_decl =
1132 dyn_cast<ObjCInterfaceDecl>(decls[0]);
1134 if (!runtime_interface_decl)
1150 std::string name_str = context.
m_decl_name.getAsString();
1151 StringRef name(name_str);
1152 IdentifierInfo &name_identifier(
1153 origin_iface_decl->getASTContext().Idents.get(name));
1156 origin_iface_decl->FindPropertyDeclaration(
1157 &name_identifier, ObjCPropertyQueryKind::OBJC_PR_query_instance));
1161 if (origin_property_decl.
IsValid()) {
1164 if (parser_property_decl.
IsValid()) {
1165 LLDB_LOG(log,
" CAS::FOPD found\n{0}",
1174 origin_iface_decl->getIvarDecl(&name_identifier));
1176 if (origin_ivar_decl.
IsValid()) {
1179 if (parser_ivar_decl.
IsValid()) {
1180 LLDB_LOG(log,
" CAS::FOPD found\n{0}",
1199 ConstString class_name(parser_iface_decl->getNameAsString().c_str());
1202 "ClangASTSource::FindObjCPropertyAndIvarDecls on "
1203 "(ASTContext*){0:x} '{1}' for '{2}.{3}'",
1205 parser_iface_decl->getName(), context.
m_decl_name.getAsString());
1211 "CAS::FOPD couldn't find the property on origin "
1212 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}, searching "
1214 origin_iface_decl.
decl, &origin_iface_decl->getASTContext());
1221 const_cast<ObjCInterfaceDecl *
>(parser_iface_decl.
decl));
1223 if (!complete_interface_decl)
1230 complete_interface_decl);
1232 if (complete_iface_decl.
decl == origin_iface_decl.
decl)
1236 "CAS::FOPD trying origin "
1237 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1238 complete_iface_decl.
decl, &complete_iface_decl->getASTContext());
1249 std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
1252 if (!modules_decl_vendor)
1255 bool append =
false;
1256 uint32_t max_matches = 1;
1257 std::vector<clang::NamedDecl *> decls;
1259 if (!modules_decl_vendor->FindDecls(class_name, append, max_matches, decls))
1263 dyn_cast<ObjCInterfaceDecl>(decls[0]));
1265 if (!interface_decl_from_modules.
IsValid())
1269 "CAS::FOPD[{0:x}] trying module "
1270 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1271 interface_decl_from_modules.
decl,
1272 &interface_decl_from_modules->getASTContext());
1275 interface_decl_from_modules))
1290 if (!language_runtime)
1298 bool append =
false;
1299 uint32_t max_matches = 1;
1300 std::vector<clang::NamedDecl *> decls;
1302 auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
1303 if (!clang_decl_vendor->FindDecls(class_name, append, max_matches, decls))
1307 dyn_cast<ObjCInterfaceDecl>(decls[0]));
1309 if (!interface_decl_from_runtime.
IsValid())
1313 "CAS::FOPD[{0:x}] trying runtime "
1314 "(ObjCInterfaceDecl*){0:x}/(ASTContext*){1:x}...",
1315 interface_decl_from_runtime.
decl,
1316 &interface_decl_from_runtime->getASTContext());
1319 interface_decl_from_runtime))
1325 const NamespaceDecl *namespace_context =
1333 LLDB_LOGV(log,
" CAS::FEVD Inspecting namespace map {0:x} ({1} entries)",
1334 namespace_map.get(), namespace_map->size());
1339 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
1340 e = namespace_map->end();
1342 LLDB_LOG(log,
" CAS::FEVD Searching namespace {0} in module {1}",
1343 i->second.GetName(), i->first->GetFileSpec().GetFilename());
1350 const RecordDecl *record, uint64_t &size, uint64_t &alignment,
1351 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
1352 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
1354 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
1355 &virtual_base_offsets) {
1357 record, size, alignment, field_offsets, base_offsets,
1358 virtual_base_offsets);
1368 if (parent_map && parent_map->size())
1370 "CompleteNamespaceMap on (ASTContext*){0:x} '{1}' Searching "
1371 "for namespace {2} in namespace {3}",
1373 parent_map->begin()->second.GetName());
1376 "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching "
1377 "for namespace {2}",
1382 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(),
1383 e = parent_map->end();
1390 SymbolFile *symbol_file = module_sp->GetSymbolFile();
1395 found_namespace_decl =
1396 symbol_file->
FindNamespace(name, module_parent_namespace_decl);
1398 if (!found_namespace_decl)
1401 namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
1402 module_sp, found_namespace_decl));
1404 LLDB_LOG(log,
" CMN Found namespace {0} in module {1}", name,
1405 module_sp->GetFileSpec().GetFilename());
1415 SymbolFile *symbol_file = image->GetSymbolFile();
1420 found_namespace_decl =
1423 if (!found_namespace_decl)
1426 namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
1427 image, found_namespace_decl));
1429 LLDB_LOG(log,
" CMN[{0}] Found namespace {0} in module {1}", name,
1430 image->GetFileSpec().GetFilename());
1438 if (!namespace_decls)
1443 clang::ASTContext *src_ast =
1447 clang::NamespaceDecl *src_namespace_decl =
1450 if (!src_namespace_decl)
1453 Decl *copied_decl =
CopyDecl(src_namespace_decl);
1458 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
1460 if (!copied_namespace_decl)
1463 context.
m_decls.push_back(copied_namespace_decl);
1468 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.
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.
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Generic representation of a type in a programming language.
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.
CompilerType GetType(clang::QualType qt)
Creates a CompilerType from the given QualType with the current TypeSystemClang instance as the Compi...
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.
"lldb/Expression/ClangASTSource.h" Container for all objects relevant to a single name lookup
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.