Skip to content

Commit

Permalink
[ClangExpressionParser] Add ClangDeclVendor
Browse files Browse the repository at this point in the history
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

llvm-svn: 369424
  • Loading branch information
bulbazord committed Aug 20, 2019
1 parent cf2b872 commit 1271521
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 29 deletions.
21 changes: 11 additions & 10 deletions lldb/include/lldb/Symbol/DeclVendor.h
Expand Up @@ -12,8 +12,6 @@
#include "lldb/Core/ClangForward.h"
#include "lldb/lldb-defines.h"

#include "clang/AST/ExternalASTMerger.h"

#include <vector>

namespace lldb_private {
Expand All @@ -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.
///
Expand Down Expand Up @@ -60,16 +66,11 @@ class DeclVendor {
/// 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
Expand Down
14 changes: 6 additions & 8 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
Expand Up @@ -100,17 +100,15 @@ void ClangASTSource::InstallASTContext(clang::ASTContext &ast_context,
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;
Expand Down
42 changes: 42 additions & 0 deletions 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
Expand Up @@ -147,7 +147,8 @@ void StoringDiagnosticConsumer::DumpDiagnostics(Stream &error_stream) {
}
}

ClangModulesDeclVendor::ClangModulesDeclVendor() {}
ClangModulesDeclVendor::ClangModulesDeclVendor()
: ClangDeclVendor(eClangModuleDeclVendor) {}

ClangModulesDeclVendor::~ClangModulesDeclVendor() {}

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -151,12 +151,13 @@ class lldb_private::AppleObjCExternalASTSource
};

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(
Expand Down
Expand Up @@ -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;

Expand Down

0 comments on commit 1271521

Please sign in to comment.