[Lldb-commits] [lldb] r369735 - [Symbol] Decouple clang from DeclVendor

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 22 23:11:33 PDT 2019


Author: xiaobai
Date: Thu Aug 22 23:11:32 2019
New Revision: 369735

URL: http://llvm.org/viewvc/llvm-project?rev=369735&view=rev
Log:
[Symbol] Decouple clang from DeclVendor

Summary:
This removes DeclVendor's dependency on clang (and ClangASTContext).
DeclVendor has no need to know about specific TypeSystems.

Differential Revision: https://reviews.llvm.org/D66628

Added:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/Symbol/DeclVendor.h
    lldb/trunk/include/lldb/Symbol/TypeSystem.h
    lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/source/Symbol/DeclVendor.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Aug 22 23:11:32 2019
@@ -465,6 +465,8 @@ public:
   CompilerType DeclGetFunctionArgumentType(void *opaque_decl,
                                            size_t arg_idx) override;
 
+  CompilerType GetTypeForDecl(void *opaque_decl) override;
+
   // CompilerDeclContext override functions
 
   std::vector<CompilerDecl>

Modified: lldb/trunk/include/lldb/Symbol/DeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DeclVendor.h?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/DeclVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/DeclVendor.h Thu Aug 22 23:11:32 2019
@@ -9,7 +9,6 @@
 #ifndef liblldb_DeclVendor_h_
 #define liblldb_DeclVendor_h_
 
-#include "lldb/Core/ClangForward.h"
 #include "lldb/lldb-defines.h"
 
 #include <vector>
@@ -51,7 +50,7 @@ public:
   ///     max_matches.
   virtual uint32_t FindDecls(ConstString name, bool append,
                              uint32_t max_matches,
-                             std::vector<clang::NamedDecl *> &decls) = 0;
+                             std::vector<CompilerDecl> &decls) = 0;
 
   /// Look up the types that the DeclVendor currently knows about matching a
   /// given name.

Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Thu Aug 22 23:11:32 2019
@@ -126,6 +126,8 @@ public:
   virtual CompilerType DeclGetFunctionArgumentType(void *opaque_decl,
                                                    size_t arg_idx);
 
+  virtual CompilerType GetTypeForDecl(void *opaque_decl) = 0;
+
   // CompilerDeclContext functions
 
   virtual std::vector<CompilerDecl>

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt Thu Aug 22 23:11:32 2019
@@ -8,6 +8,7 @@ add_lldb_library(lldbPluginExpressionPar
   ASTStructExtractor.cpp
   ASTUtils.cpp
   ClangASTSource.cpp
+  ClangDeclVendor.cpp
   ClangExpressionDeclMap.cpp
   ClangExpressionParser.cpp
   ClangExpressionSourceCode.cpp

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Thu Aug 22 23:11:32 2019
@@ -9,6 +9,7 @@
 #include "ClangASTSource.h"
 
 #include "ASTDumper.h"
+#include "ClangDeclVendor.h"
 #include "ClangModulesDeclVendor.h"
 
 #include "lldb/Core/Module.h"
@@ -971,7 +972,8 @@ void ClangASTSource::FindExternalVisible
         uint32_t max_matches = 1;
         std::vector<clang::NamedDecl *> decls;
 
-        if (!decl_vendor->FindDecls(name, append, max_matches, decls))
+        auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
+        if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls))
           break;
 
         if (log) {
@@ -1423,7 +1425,9 @@ void ClangASTSource::FindObjCMethodDecls
     uint32_t max_matches = 1;
     std::vector<clang::NamedDecl *> decls;
 
-    if (!decl_vendor->FindDecls(interface_name, append, max_matches, decls))
+    auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
+    if (!clang_decl_vendor->FindDecls(interface_name, append, max_matches,
+                                      decls))
       break;
 
     ObjCInterfaceDecl *runtime_interface_decl =
@@ -1612,7 +1616,8 @@ void ClangASTSource::FindObjCPropertyAnd
     uint32_t max_matches = 1;
     std::vector<clang::NamedDecl *> decls;
 
-    if (!decl_vendor->FindDecls(class_name, append, max_matches, decls))
+    auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor);
+    if (!clang_decl_vendor->FindDecls(class_name, append, max_matches, decls))
       break;
 
     DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_runtime(

Added: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp?rev=369735&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp (added)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp Thu Aug 22 23:11:32 2019
@@ -0,0 +1,30 @@
+//===-- ClangDeclVendor.cpp -------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
+
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Utility/ConstString.h"
+
+using namespace lldb_private;
+
+uint32_t ClangDeclVendor::FindDecls(ConstString name, bool append,
+                                    uint32_t max_matches,
+                                    std::vector<CompilerDecl> &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));
+  }
+  return ret;
+}

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h Thu Aug 22 23:11:32 2019
@@ -9,6 +9,7 @@
 #ifndef liblldb_ClangDeclVendor_h_
 #define liblldb_ClangDeclVendor_h_
 
+#include "lldb/Core/ClangForward.h"
 #include "lldb/Symbol/DeclVendor.h"
 
 #include "clang/AST/ExternalASTMerger.h"
@@ -29,6 +30,13 @@ public:
   ///     An ImporterSource for this ClangDeclVendor.
   virtual clang::ExternalASTMerger::ImporterSource GetImporterSource() = 0;
 
+  uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
+                     std::vector<CompilerDecl> &decls) override;
+
+  virtual uint32_t FindDecls(ConstString name, bool append,
+                             uint32_t max_matches,
+                             std::vector<clang::NamedDecl *> &decls) = 0;
+
   static bool classof(const DeclVendor *vendor) {
     return vendor->GetKind() >= eClangDeclVendor &&
            vendor->GetKind() < eLastClangDeclVendor;

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h Thu Aug 22 23:11:32 2019
@@ -17,6 +17,7 @@
 #include "llvm/Support/Casting.h"
 
 #include "lldb/Breakpoint/BreakpointPrecondition.h"
+#include "lldb/Core/ClangForward.h"
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Core/ThreadSafeDenseMap.h"
 #include "lldb/Symbol/CompilerType.h"

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Aug 22 23:11:32 2019
@@ -1473,6 +1473,16 @@ bool ClangASTContext::AreTypesSame(Compi
   return ast->getASTContext()->hasSameType(type1_qual, type2_qual);
 }
 
+CompilerType ClangASTContext::GetTypeForDecl(void *opaque_decl) {
+  if (!opaque_decl)
+    return CompilerType();
+
+  clang::Decl *decl = static_cast<clang::Decl *>(opaque_decl);
+  if (auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl))
+    return GetTypeForDecl(named_decl);
+  return CompilerType();
+}
+
 CompilerType ClangASTContext::GetTypeForDecl(clang::NamedDecl *decl) {
   if (clang::ObjCInterfaceDecl *interface_decl =
           llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))

Modified: lldb/trunk/source/Symbol/DeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/DeclVendor.cpp?rev=369735&r1=369734&r2=369735&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/DeclVendor.cpp (original)
+++ lldb/trunk/source/Symbol/DeclVendor.cpp Thu Aug 22 23:11:32 2019
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Symbol/DeclVendor.h"
-
-#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/CompilerDecl.h"
+#include "lldb/Symbol/TypeSystem.h"
 
 #include <vector>
 
@@ -20,10 +20,11 @@ std::vector<CompilerType> DeclVendor::Fi
   // FIXME: This depends on clang, but should be able to support any
   // TypeSystem.
   std::vector<CompilerType> ret;
-  std::vector<clang::NamedDecl *> decls;
+  std::vector<CompilerDecl> decls;
   if (FindDecls(name, /*append*/ true, max_matches, decls))
-    for (auto *decl : decls)
-      if (auto type = ClangASTContext::GetTypeForDecl(decl))
+    for (auto decl : decls)
+      if (auto type =
+              decl.GetTypeSystem()->GetTypeForDecl(decl.GetOpaqueDecl()))
         ret.push_back(type);
   return ret;
 }




More information about the lldb-commits mailing list