[lldb][NFC] Remove GetASTContext call in ClangDeclVendor
authorRaphael Isemann <teemperor@gmail.com>
Sat, 28 Dec 2019 13:35:07 +0000 (14:35 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Sat, 28 Dec 2019 14:20:19 +0000 (15:20 +0100)
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).

lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h

index c59722b..0c57966 100644 (file)
@@ -15,16 +15,17 @@ using namespace lldb_private;
 
 uint32_t ClangDeclVendor::FindDecls(ConstString name, bool append,
                                     uint32_t max_matches,
-                                    std::vector<CompilerDecl> &decls) {
+                                    std::vector<clang::NamedDecl *> &decls) {
   if (!append)
     decls.clear();
 
-  std::vector<clang::NamedDecl *> 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<CompilerDecl> compiler_decls;
+  uint32_t ret = FindDecls(name, /*append*/ false, max_matches, compiler_decls);
+  for (CompilerDecl compiler_decl : compiler_decls) {
+    clang::Decl *d =
+        reinterpret_cast<clang::Decl *>(compiler_decl.GetOpaqueDecl());
+    clang::NamedDecl *nd = llvm::cast<clang::NamedDecl>(d);
+    decls.push_back(nd);
   }
   return ret;
 }
index 85a1040..0c888de 100644 (file)
@@ -21,12 +21,10 @@ public:
 
   virtual ~ClangDeclVendor() {}
 
-  uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
-                     std::vector<CompilerDecl> &decls) override;
+  using DeclVendor::FindDecls;
 
-  virtual uint32_t FindDecls(ConstString name, bool append,
-                             uint32_t max_matches,
-                             std::vector<clang::NamedDecl *> &decls) = 0;
+  uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
+                     std::vector<clang::NamedDecl *> &decls);
 
   static bool classof(const DeclVendor *vendor) {
     return vendor->GetKind() >= eClangDeclVendor &&
index ff0905d..0696c66 100644 (file)
@@ -80,7 +80,7 @@ public:
                                 Stream &error_stream) override;
 
   uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
-                     std::vector<clang::NamedDecl *> &decls) override;
+                     std::vector<CompilerDecl> &decls) override;
 
   void ForEachMacro(const ModuleVector &modules,
                     std::function<bool(const std::string &)> handler) override;
@@ -356,7 +356,7 @@ bool ClangModulesDeclVendorImpl::AddModulesForCompileUnit(
 uint32_t
 ClangModulesDeclVendorImpl::FindDecls(ConstString name, bool append,
                                       uint32_t max_matches,
-                                      std::vector<clang::NamedDecl *> &decls) {
+                                      std::vector<CompilerDecl> &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;
   }
 
index 54f8397..29930c3 100644 (file)
@@ -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<clang::NamedDecl *> &decls) {
+uint32_t AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
+                                        uint32_t max_matches,
+                                        std::vector<CompilerDecl> &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);
index 311113a..f49ca35 100644 (file)
@@ -28,7 +28,7 @@ public:
   }
 
   uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
-                     std::vector<clang::NamedDecl *> &decls) override;
+                     std::vector<CompilerDecl> &decls) override;
 
   friend class AppleObjCExternalASTSource;