From: Raphael Isemann Date: Sat, 28 Dec 2019 13:35:07 +0000 (+0100) Subject: [lldb][NFC] Remove GetASTContext call in ClangDeclVendor X-Git-Tag: llvmorg-11-init~1284 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8612e92ed590e615f9f56e4fb86a1fdaf3a39e15;p=platform%2Fupstream%2Fllvm.git [lldb][NFC] Remove GetASTContext call in ClangDeclVendor Instead of returning NamedDecls and then calling GetASTContext to find back the ClangASTContext we used can just implement the FindDecl variant that returns CompilerDecls (and implement the other function by throwing away the ClangASTContext part of the compiler decl). --- diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp index c59722b..0c57966 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp @@ -15,16 +15,17 @@ using namespace lldb_private; uint32_t ClangDeclVendor::FindDecls(ConstString name, bool append, uint32_t max_matches, - std::vector &decls) { + std::vector &decls) { if (!append) decls.clear(); - std::vector named_decls; - uint32_t ret = FindDecls(name, /*append*/ false, max_matches, named_decls); - for (auto *named_decl : named_decls) { - decls.push_back(CompilerDecl( - ClangASTContext::GetASTContext(&named_decl->getASTContext()), - named_decl)); + std::vector compiler_decls; + uint32_t ret = FindDecls(name, /*append*/ false, max_matches, compiler_decls); + for (CompilerDecl compiler_decl : compiler_decls) { + clang::Decl *d = + reinterpret_cast(compiler_decl.GetOpaqueDecl()); + clang::NamedDecl *nd = llvm::cast(d); + decls.push_back(nd); } return ret; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h index 85a1040..0c888de 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h @@ -21,12 +21,10 @@ public: virtual ~ClangDeclVendor() {} - uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches, - std::vector &decls) override; + using DeclVendor::FindDecls; - virtual uint32_t FindDecls(ConstString name, bool append, - uint32_t max_matches, - std::vector &decls) = 0; + uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches, + std::vector &decls); static bool classof(const DeclVendor *vendor) { return vendor->GetKind() >= eClangDeclVendor && diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index ff0905d..0696c66 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -80,7 +80,7 @@ public: Stream &error_stream) override; uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches, - std::vector &decls) override; + std::vector &decls) override; void ForEachMacro(const ModuleVector &modules, std::function handler) override; @@ -356,7 +356,7 @@ bool ClangModulesDeclVendorImpl::AddModulesForCompileUnit( uint32_t ClangModulesDeclVendorImpl::FindDecls(ConstString name, bool append, uint32_t max_matches, - std::vector &decls) { + std::vector &decls) { if (!m_enabled) { return 0; } @@ -382,7 +382,7 @@ ClangModulesDeclVendorImpl::FindDecls(ConstString name, bool append, if (num_matches >= max_matches) return num_matches; - decls.push_back(named_decl); + decls.push_back(CompilerDecl(m_ast_context.get(), named_decl)); ++num_matches; } diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp index 54f8397..29930c30 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp @@ -537,10 +537,9 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) { return true; } -uint32_t -AppleObjCDeclVendor::FindDecls(ConstString name, bool append, - uint32_t max_matches, - std::vector &decls) { +uint32_t AppleObjCDeclVendor::FindDecls(ConstString name, bool append, + uint32_t max_matches, + std::vector &decls) { static unsigned int invocation_id = 0; unsigned int current_id = invocation_id++; @@ -587,7 +586,7 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append, current_id, result_iface_type.getAsString(), isa_value); } - decls.push_back(result_iface_decl); + decls.push_back(CompilerDecl(&m_ast_ctx, result_iface_decl)); ret++; break; } else { @@ -630,7 +629,7 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append, new_iface_type.getAsString(), (uint64_t)isa); } - decls.push_back(iface_decl); + decls.push_back(CompilerDecl(&m_ast_ctx, iface_decl)); ret++; break; } while (false); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h index 311113a..f49ca35 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h @@ -28,7 +28,7 @@ public: } uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches, - std::vector &decls) override; + std::vector &decls) override; friend class AppleObjCExternalASTSource;