[Lldb-commits] [lldb] r369424 - [ClangExpressionParser] Add ClangDeclVendor

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 20 11:47:30 PDT 2019


Author: xiaobai
Date: Tue Aug 20 11:47:30 2019
New Revision: 369424

URL: http://llvm.org/viewvc/llvm-project?rev=369424&view=rev
Log:
[ClangExpressionParser] Add ClangDeclVendor

Summary:
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).

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

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

Modified: lldb/trunk/include/lldb/Symbol/DeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DeclVendor.h?rev=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/DeclVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/DeclVendor.h Tue Aug 20 11:47:30 2019
@@ -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 @@ namespace lldb_private {
 // 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 @@ public:
   ///     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

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=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue Aug 20 11:47:30 2019
@@ -100,17 +100,15 @@ void ClangASTSource::InstallASTContext(c
       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;

Added: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h?rev=369424&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h (added)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.h Tue Aug 20 11:47:30 2019
@@ -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

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Tue Aug 20 11:47:30 2019
@@ -147,7 +147,8 @@ void StoringDiagnosticConsumer::DumpDiag
   }
 }
 
-ClangModulesDeclVendor::ClangModulesDeclVendor() {}
+ClangModulesDeclVendor::ClangModulesDeclVendor()
+    : ClangDeclVendor(eClangModuleDeclVendor) {}
 
 ClangModulesDeclVendor::~ClangModulesDeclVendor() {}
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h?rev=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h Tue Aug 20 11:47:30 2019
@@ -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;

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp?rev=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp Tue Aug 20 11:47:30 2019
@@ -151,12 +151,13 @@ private:
 };
 
 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(

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h?rev=369424&r1=369423&r2=369424&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h Tue Aug 20 11:47:30 2019
@@ -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;
 




More information about the lldb-commits mailing list