aboutsummaryrefslogtreecommitdiff
path: root/source/Expression/ClangASTSource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Expression/ClangASTSource.cpp')
-rw-r--r--source/Expression/ClangASTSource.cpp239
1 files changed, 187 insertions, 52 deletions
diff --git a/source/Expression/ClangASTSource.cpp b/source/Expression/ClangASTSource.cpp
index d488993b90d7..9a6d6e532255 100644
--- a/source/Expression/ClangASTSource.cpp
+++ b/source/Expression/ClangASTSource.cpp
@@ -708,6 +708,8 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
else
m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, types);
+ bool found_a_type = false;
+
if (types.GetSize())
{
lldb::TypeSP type_sp = types.GetTypeAtIndex(0);
@@ -736,8 +738,62 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
}
context.AddTypeDecl(copied_clang_type);
+
+ found_a_type = true;
}
- else
+
+ if (!found_a_type)
+ {
+ // Try the modules next.
+
+ do
+ {
+ if (ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor())
+ {
+ bool append = false;
+ uint32_t max_matches = 1;
+ std::vector <clang::NamedDecl *> decls;
+
+ if (!modules_decl_vendor->FindDecls(name,
+ append,
+ max_matches,
+ decls))
+ break;
+
+ if (log)
+ {
+ log->Printf(" CAS::FEVD[%u] Matching entity found for \"%s\" in the modules",
+ current_id,
+ name.GetCString());
+ }
+
+ clang::NamedDecl *const decl_from_modules = decls[0];
+
+ if (llvm::isa<clang::TypeDecl>(decl_from_modules) ||
+ llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
+ llvm::isa<clang::EnumConstantDecl>(decl_from_modules))
+ {
+ clang::Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &decl_from_modules->getASTContext(), decl_from_modules);
+ clang::NamedDecl *copied_named_decl = copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
+
+ if (!copied_named_decl)
+ {
+ if (log)
+ log->Printf(" CAS::FEVD[%u] - Couldn't export a type from the modules",
+ current_id);
+
+ break;
+ }
+
+ context.AddNamedDecl(copied_named_decl);
+
+ found_a_type = true;
+ }
+ }
+ } while (0);
+ }
+
+ if (!found_a_type)
{
do
{
@@ -753,19 +809,19 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
if (!language_runtime)
break;
- TypeVendor *type_vendor = language_runtime->GetTypeVendor();
+ DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
- if (!type_vendor)
+ if (!decl_vendor)
break;
bool append = false;
uint32_t max_matches = 1;
- std::vector <ClangASTType> types;
+ std::vector <clang::NamedDecl *> decls;
- if (!type_vendor->FindTypes(name,
+ if (!decl_vendor->FindDecls(name,
append,
max_matches,
- types))
+ decls))
break;
if (log)
@@ -774,10 +830,11 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
current_id,
name.GetCString());
}
-
- ClangASTType copied_clang_type (GuardedCopyType(types[0]));
-
- if (!copied_clang_type)
+
+ clang::Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &decls[0]->getASTContext(), decls[0]);
+ clang::NamedDecl *copied_named_decl = copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
+
+ if (!copied_named_decl)
{
if (log)
log->Printf(" CAS::FEVD[%u] - Couldn't export a type from the runtime",
@@ -786,7 +843,7 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
break;
}
- context.AddTypeDecl(copied_clang_type);
+ context.AddNamedDecl(copied_named_decl);
}
while(0);
}
@@ -895,31 +952,44 @@ FindObjCMethodDeclsWithOrigin (unsigned int current_id,
}
DeclarationName original_decl_name(original_selector);
-
- ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name);
-
- if (result.empty())
- return false;
-
- if (!result[0])
+
+ llvm::SmallVector<NamedDecl *, 1> methods;
+
+ ClangASTContext::GetCompleteDecl(original_ctx, original_interface_decl);
+
+ if (ObjCMethodDecl *instance_method_decl = original_interface_decl->lookupInstanceMethod(original_selector))
+ {
+ methods.push_back(instance_method_decl);
+ }
+ else if (ObjCMethodDecl *class_method_decl = original_interface_decl->lookupClassMethod(original_selector))
+ {
+ methods.push_back(class_method_decl);
+ }
+
+ if (methods.empty())
+ {
return false;
-
- for (NamedDecl *named_decl : result)
+ }
+
+ for (NamedDecl *named_decl : methods)
{
+ if (!named_decl)
+ continue;
+
ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl);
if (!result_method)
- return false;
+ continue;
Decl *copied_decl = ast_importer->CopyDecl(ast_context, &result_method->getASTContext(), result_method);
if (!copied_decl)
- return false;
+ continue;
ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
if (!copied_method_decl)
- return false;
+ continue;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -1169,10 +1239,43 @@ ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
return;
}
while (0);
+
+ do
+ {
+ // Check the modules only if the debug information didn't have a complete interface.
+
+ if (ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor())
+ {
+ ConstString interface_name(interface_decl->getNameAsString().c_str());
+ bool append = false;
+ uint32_t max_matches = 1;
+ std::vector <clang::NamedDecl *> decls;
+
+ if (!modules_decl_vendor->FindDecls(interface_name,
+ append,
+ max_matches,
+ decls))
+ break;
+
+ ObjCInterfaceDecl *interface_decl_from_modules = dyn_cast<ObjCInterfaceDecl>(decls[0]);
+
+ if (!interface_decl_from_modules)
+ break;
+
+ if (FindObjCMethodDeclsWithOrigin(current_id,
+ context,
+ interface_decl_from_modules,
+ m_ast_context,
+ m_ast_importer,
+ "in modules"))
+ return;
+ }
+ }
+ while (0);
do
{
- // Check the runtime only if the debug information didn't have a complete interface.
+ // Check the runtime only if the debug information didn't have a complete interface and the modules don't get us anywhere.
lldb::ProcessSP process(m_target->GetProcessSP());
@@ -1184,31 +1287,27 @@ ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
if (!language_runtime)
break;
- TypeVendor *type_vendor = language_runtime->GetTypeVendor();
+ DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
- if (!type_vendor)
+ if (!decl_vendor)
break;
ConstString interface_name(interface_decl->getNameAsString().c_str());
bool append = false;
uint32_t max_matches = 1;
- std::vector <ClangASTType> types;
+ std::vector <clang::NamedDecl *> decls;
- if (!type_vendor->FindTypes(interface_name,
+ if (!decl_vendor->FindDecls(interface_name,
append,
max_matches,
- types))
+ decls))
break;
- const clang::Type *runtime_clang_type = QualType::getFromOpaquePtr(types[0].GetOpaqueQualType()).getTypePtr();
-
- const ObjCInterfaceType *runtime_interface_type = dyn_cast<ObjCInterfaceType>(runtime_clang_type);
-
- if (!runtime_interface_type)
+ ObjCInterfaceDecl *runtime_interface_decl = dyn_cast<ObjCInterfaceDecl>(decls[0]);
+
+ if (!runtime_interface_decl)
break;
- ObjCInterfaceDecl *runtime_interface_decl = runtime_interface_type->getDecl();
-
FindObjCMethodDeclsWithOrigin(current_id,
context,
runtime_interface_decl,
@@ -1339,10 +1438,50 @@ ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context)
return;
}
while(0);
+
+ do
+ {
+ // Check the modules only if the debug information didn't have a complete interface.
+
+ ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor();
+
+ if (!modules_decl_vendor)
+ break;
+
+ bool append = false;
+ uint32_t max_matches = 1;
+ std::vector <clang::NamedDecl *> decls;
+
+ if (!modules_decl_vendor->FindDecls(class_name,
+ append,
+ max_matches,
+ decls))
+ break;
+
+ DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_modules(dyn_cast<ObjCInterfaceDecl>(decls[0]));
+
+ if (!interface_decl_from_modules.IsValid())
+ break;
+
+ if (log)
+ log->Printf("CAS::FOPD[%d] trying module (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
+ current_id,
+ static_cast<const void*>(interface_decl_from_modules.decl),
+ static_cast<void*>(&interface_decl_from_modules->getASTContext()));
+
+ if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
+ context,
+ *m_ast_context,
+ m_ast_importer,
+ interface_decl_from_modules))
+ return;
+ }
+ while(0);
do
{
- // Check the runtime only if the debug information didn't have a complete interface.
+ // Check the runtime only if the debug information didn't have a complete interface
+ // and nothing was in the modules.
lldb::ProcessSP process(m_target->GetProcessSP());
@@ -1354,41 +1493,37 @@ ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context)
if (!language_runtime)
return;
- TypeVendor *type_vendor = language_runtime->GetTypeVendor();
+ DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
- if (!type_vendor)
+ if (!decl_vendor)
break;
bool append = false;
uint32_t max_matches = 1;
- std::vector <ClangASTType> types;
+ std::vector <clang::NamedDecl *> decls;
- if (!type_vendor->FindTypes(class_name,
+ if (!decl_vendor->FindDecls(class_name,
append,
max_matches,
- types))
+ decls))
break;
- const clang::Type *runtime_clang_type = QualType::getFromOpaquePtr(types[0].GetOpaqueQualType()).getTypePtr();
-
- const ObjCInterfaceType *runtime_interface_type = dyn_cast<ObjCInterfaceType>(runtime_clang_type);
-
- if (!runtime_interface_type)
+ DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_runtime(dyn_cast<ObjCInterfaceDecl>(decls[0]));
+
+ if (!interface_decl_from_runtime.IsValid())
break;
- DeclFromUser<const ObjCInterfaceDecl> runtime_iface_decl(runtime_interface_type->getDecl());
-
if (log)
log->Printf("CAS::FOPD[%d] trying runtime (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
current_id,
- static_cast<const void*>(runtime_iface_decl.decl),
- static_cast<void*>(&runtime_iface_decl->getASTContext()));
+ static_cast<const void*>(interface_decl_from_runtime.decl),
+ static_cast<void*>(&interface_decl_from_runtime->getASTContext()));
if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
context,
*m_ast_context,
m_ast_importer,
- runtime_iface_decl))
+ interface_decl_from_runtime))
return;
}
while(0);