xiaobai created this revision.
xiaobai added reviewers: JDevlieghere, clayborg, jingham, labath.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: LLDB.

This introduces a layer between DeclVendor and the currently implemented
DeclVendors (ClangModulesDeclVendor and AppleObjCDeclVendor). This
allows the removal of DeclVendor::GetImporterSource which is extremely
clang-specific, freeing up the interface to be more general.

A good follow up to this would be to remove the remaining instances of
clang in DeclVendor, either by moving things to ClangDeclVendor or by
using wrappers (e.g. CompilerDecl instead of clang::NamedDecl).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66451

Files:
  lldb/include/lldb/Symbol/DeclVendor.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h

Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h
@@ -10,19 +10,23 @@
 #define liblldb_AppleObjCDeclVendor_h_
 
 #include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/DeclVendor.h"
 #include "lldb/lldb-private.h"
 
+#include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
 
 namespace lldb_private {
 
 class AppleObjCExternalASTSource;
 
-class AppleObjCDeclVendor : public DeclVendor {
+class AppleObjCDeclVendor : public ClangDeclVendor {
 public:
   AppleObjCDeclVendor(ObjCLanguageRuntime &runtime);
 
+  static bool classof(const DeclVendor *vendor) {
+    return vendor->GetKind() == eAppleObjCDeclVendor;
+  }
+
   uint32_t FindDecls(ConstString name, bool append, uint32_t max_matches,
                      std::vector<clang::NamedDecl *> &decls) override;
 
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -151,12 +151,13 @@
 };
 
 AppleObjCDeclVendor::AppleObjCDeclVendor(ObjCLanguageRuntime &runtime)
-    : DeclVendor(), m_runtime(runtime), m_ast_ctx(runtime.GetProcess()
-                                                      ->GetTarget()
-                                                      .GetArchitecture()
-                                                      .GetTriple()
-                                                      .getTriple()
-                                                      .c_str()),
+    : ClangDeclVendor(eAppleObjCDeclVendor), m_runtime(runtime),
+      m_ast_ctx(runtime.GetProcess()
+                    ->GetTarget()
+                    .GetArchitecture()
+                    .GetTriple()
+                    .getTriple()
+                    .c_str()),
       m_type_realizer_sp(m_runtime.GetEncodingToType()) {
   m_external_source = new AppleObjCExternalASTSource(*this);
   llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> external_source_owning_ptr(
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
@@ -10,22 +10,27 @@
 #define liblldb_ClangModulesDeclVendor_h
 
 #include "lldb/Core/ClangForward.h"
-#include "lldb/Symbol/DeclVendor.h"
 #include "lldb/Symbol/SourceModule.h"
 #include "lldb/Target/Platform.h"
 
+#include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
+
 #include <set>
 #include <vector>
 
 namespace lldb_private {
 
-class ClangModulesDeclVendor : public DeclVendor {
+class ClangModulesDeclVendor : public ClangDeclVendor {
 public:
   // Constructors and Destructors
   ClangModulesDeclVendor();
 
   ~ClangModulesDeclVendor() override;
 
+  static bool classof(const DeclVendor *vendor) {
+    return vendor->GetKind() == eClangModuleDeclVendor;
+  }
+
   static ClangModulesDeclVendor *Create(Target &target);
 
   typedef std::vector<ConstString> ModulePath;
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -147,7 +147,8 @@
   }
 }
 
-ClangModulesDeclVendor::ClangModulesDeclVendor() {}
+ClangModulesDeclVendor::ClangModulesDeclVendor()
+    : ClangDeclVendor(eClangModuleDeclVendor) {}
 
 ClangModulesDeclVendor::~ClangModulesDeclVendor() {}
 
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
===================================================================
--- /dev/null
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
@@ -0,0 +1,42 @@
+//===-- ClangDeclVendor.h ---------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ClangDeclVendor_h_
+#define liblldb_ClangDeclVendor_h_
+
+#include "lldb/Symbol/DeclVendor.h"
+
+#include "clang/AST/ExternalASTMerger.h"
+
+namespace lldb_private {
+
+// A clang specialized extension to DeclVendor.
+class ClangDeclVendor : public DeclVendor {
+public:
+  ClangDeclVendor(DeclVendorKind kind) : DeclVendor(kind) {}
+
+  virtual ~ClangDeclVendor() {}
+
+  /// Interface for ExternalASTMerger. Returns an ImporterSource allowing type
+  /// completion.
+  ///
+  /// \return
+  ///     An ImporterSource for this ClangDeclVendor.
+  virtual clang::ExternalASTMerger::ImporterSource GetImporterSource() = 0;
+
+  static bool classof(const DeclVendor *vendor) {
+    return vendor->GetKind() >= eClangDeclVendor &&
+           vendor->GetKind() < eLastClangDeclVendor;
+  }
+
+private:
+  DISALLOW_COPY_AND_ASSIGN(ClangDeclVendor);
+};
+}; // namespace lldb_private
+
+#endif
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -100,17 +100,15 @@
       if (!language_runtime)
         break;
 
-      DeclVendor *runtime_decl_vendor = language_runtime->GetDeclVendor();
-
-      if (!runtime_decl_vendor)
-        break;
-
-      sources.push_back(runtime_decl_vendor->GetImporterSource());
+      if (auto *runtime_decl_vendor = llvm::dyn_cast_or_null<ClangDeclVendor>(
+              language_runtime->GetDeclVendor())) {
+        sources.push_back(runtime_decl_vendor->GetImporterSource());
+      }
     } while (false);
 
     do {
-      DeclVendor *modules_decl_vendor =
-          m_target->GetClangModulesDeclVendor();
+      auto *modules_decl_vendor = llvm::cast<ClangModulesDeclVendor>(
+          m_target->GetClangModulesDeclVendor());
 
       if (!modules_decl_vendor)
         break;
Index: lldb/include/lldb/Symbol/DeclVendor.h
===================================================================
--- lldb/include/lldb/Symbol/DeclVendor.h
+++ lldb/include/lldb/Symbol/DeclVendor.h
@@ -12,8 +12,6 @@
 #include "lldb/Core/ClangForward.h"
 #include "lldb/lldb-defines.h"
 
-#include "clang/AST/ExternalASTMerger.h"
-
 #include <vector>
 
 namespace lldb_private {
@@ -22,11 +20,19 @@
 // declarations that are not necessarily backed by a specific symbol file.
 class DeclVendor {
 public:
+  enum DeclVendorKind {
+    eClangDeclVendor,
+    eClangModuleDeclVendor,
+    eAppleObjCDeclVendor,
+    eLastClangDeclVendor,
+  };
   // Constructors and Destructors
-  DeclVendor() {}
+  DeclVendor(DeclVendorKind kind) : m_kind(kind) {}
 
   virtual ~DeclVendor() {}
 
+  DeclVendorKind GetKind() const { return m_kind; }
+
   /// Look up the set of Decls that the DeclVendor currently knows about
   /// matching a given name.
   ///
@@ -60,16 +66,11 @@
   ///     The vector of CompilerTypes that was found.
   std::vector<CompilerType> FindTypes(ConstString name, uint32_t max_matches);
 
-  /// Interface for ExternalASTMerger.  Returns an ImporterSource 
-  /// allowing type completion.
-  ///
-  /// \return
-  ///     An ImporterSource for this DeclVendor.
-  virtual clang::ExternalASTMerger::ImporterSource GetImporterSource() = 0;
-
 private:
   // For DeclVendor only
   DISALLOW_COPY_AND_ASSIGN(DeclVendor);
+
+  const DeclVendorKind m_kind;
 };
 
 } // namespace lldb_private
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to