forked from OSchip/llvm-project
[lldb][NFC] Remove ClangExternalASTSourceCommon
ClangExternalASTSourceCommon's purpose is to store a map from Decl*/Type* to ClangASTMetadata. Usually this data is accessed via the ClangASTContext interface which then grabs the current ExternalASTSource of its ASTContext, tries to cast it to ClangExternalASTSourceCommon and then accesses the metadata map. If the casting fails the setter does nothing and the getter returns a nullptr as if there was no known metadata for a type/decl. This system breaks as soon as any non-LLDB ExternalASTSource is added via a multiplexer to our existing ExternalASTSource (in which case we suddenly loose all out metadata as the casting always fails with an ExternalASTSource that is not inheriting from ClangExternalASTSourceCommon). This patch moves the metadata map to the ClangASTContext. This gets rid of all the fragile casting, the requirement that every ExternalASTSource in LLDB has to inherit from ClangExternalASTSourceCommon and simplifies the metadata implementation to a simple map lookup. As ClangExternalASTSourceCommon had no other purpose than storing metadata, this patch deletes this class and replaces all uses with clang::ExternalASTSource. No other code changes in this commit beside the AppleObjCDeclVendor which was the only code that did not use the ClangASTContext interface but directly accessed the ClangExternalASTSourceCommon.
This commit is contained in:
parent
8131c04836
commit
4657a397c2
|
@ -966,6 +966,15 @@ protected:
|
|||
std::unique_ptr<clang::MangleContext> m_mangle_ctx_up;
|
||||
uint32_t m_pointer_byte_size = 0;
|
||||
bool m_ast_owned = false;
|
||||
|
||||
typedef llvm::DenseMap<const clang::Decl *, ClangASTMetadata> DeclMetadataMap;
|
||||
/// Maps Decls to their associated ClangASTMetadata.
|
||||
DeclMetadataMap m_decl_metadata;
|
||||
|
||||
typedef llvm::DenseMap<const clang::Type *, ClangASTMetadata> TypeMetadataMap;
|
||||
/// Maps Types to their associated ClangASTMetadata.
|
||||
TypeMetadataMap m_type_metadata;
|
||||
|
||||
/// The sema associated that is currently used to build this ASTContext.
|
||||
/// May be null if we are already done parsing this ASTContext or the
|
||||
/// ASTContext wasn't created by parsing source code.
|
||||
|
|
|
@ -9,13 +9,14 @@
|
|||
#ifndef liblldb_ClangExternalASTSourceCallbacks_h_
|
||||
#define liblldb_ClangExternalASTSourceCallbacks_h_
|
||||
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "clang/AST/ExternalASTSource.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
class ClangASTContext;
|
||||
|
||||
class ClangExternalASTSourceCallbacks : public ClangExternalASTSourceCommon {
|
||||
class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {
|
||||
public:
|
||||
ClangExternalASTSourceCallbacks(ClangASTContext &ast) : m_ast(ast) {}
|
||||
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
//===-- ClangExternalASTSourceCommon.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_ClangExternalASTSourceCommon_h
|
||||
#define liblldb_ClangExternalASTSourceCommon_h
|
||||
|
||||
// Clang headers like to use NDEBUG inside of them to enable/disable debug
|
||||
// related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
|
||||
// or another. This is bad because it means that if clang was built in release
|
||||
// mode, it assumes that you are building in release mode which is not always
|
||||
// the case. You can end up with functions that are defined as empty in header
|
||||
// files when NDEBUG is not defined, and this can cause link errors with the
|
||||
// clang .a files that you have since you might be missing functions in the .a
|
||||
// file. So we have to define NDEBUG when including clang headers to avoid any
|
||||
// mismatches. This is covered by rdar://problem/8691220
|
||||
|
||||
#if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
|
||||
#define LLDB_DEFINED_NDEBUG_FOR_CLANG
|
||||
#define NDEBUG
|
||||
// Need to include assert.h so it is as clang would expect it to be (disabled)
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
|
||||
#undef NDEBUG
|
||||
#undef LLDB_DEFINED_NDEBUG_FOR_CLANG
|
||||
// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#include "clang/AST/ExternalASTSource.h"
|
||||
|
||||
#include "lldb/Core/dwarf.h"
|
||||
#include "lldb/Symbol/ClangASTMetadata.h"
|
||||
#include "lldb/lldb-defines.h"
|
||||
#include "lldb/lldb-enumerations.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
|
||||
|
||||
/// LLVM-style RTTI.
|
||||
static char ID;
|
||||
|
||||
public:
|
||||
~ClangExternalASTSourceCommon() override;
|
||||
|
||||
ClangASTMetadata *GetMetadata(const clang::Decl *object);
|
||||
void SetMetadata(const clang::Decl *object,
|
||||
const ClangASTMetadata &metadata) {
|
||||
m_decl_metadata[object] = metadata;
|
||||
}
|
||||
|
||||
ClangASTMetadata *GetMetadata(const clang::Type *object);
|
||||
void SetMetadata(const clang::Type *object,
|
||||
const ClangASTMetadata &metadata) {
|
||||
m_type_metadata[object] = metadata;
|
||||
}
|
||||
|
||||
/// LLVM-style RTTI.
|
||||
/// \{
|
||||
bool isA(const void *ClassID) const override {
|
||||
return ClassID == &ID || ExternalASTSource::isA(ClassID);
|
||||
}
|
||||
static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
|
||||
/// \}
|
||||
private:
|
||||
typedef llvm::DenseMap<const clang::Decl *, ClangASTMetadata> DeclMetadataMap;
|
||||
typedef llvm::DenseMap<const clang::Type *, ClangASTMetadata> TypeMetadataMap;
|
||||
|
||||
DeclMetadataMap m_decl_metadata;
|
||||
TypeMetadataMap m_type_metadata;
|
||||
};
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif // liblldb_ClangExternalASTSourceCommon_h
|
|
@ -12,9 +12,9 @@
|
|||
#include <set>
|
||||
|
||||
#include "lldb/Symbol/ClangASTImporter.h"
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Symbol/CompilerType.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
#include "clang/AST/ExternalASTSource.h"
|
||||
#include "clang/Basic/IdentifierTable.h"
|
||||
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
|
@ -29,7 +29,7 @@ namespace lldb_private {
|
|||
/// knows the name it is looking for, but nothing else. The ExternalSemaSource
|
||||
/// class provides Decls (VarDecl, FunDecl, TypeDecl) to Clang for these
|
||||
/// names, consulting the ClangExpressionDeclMap to do the actual lookups.
|
||||
class ClangASTSource : public ClangExternalASTSourceCommon,
|
||||
class ClangASTSource : public clang::ExternalASTSource,
|
||||
public ClangASTImporter::MapCompleter {
|
||||
public:
|
||||
/// Constructor
|
||||
|
@ -211,7 +211,7 @@ public:
|
|||
///
|
||||
/// Clang AST contexts like to own their AST sources, so this is a state-
|
||||
/// free proxy object.
|
||||
class ClangASTSourceProxy : public ClangExternalASTSourceCommon {
|
||||
class ClangASTSourceProxy : public clang::ExternalASTSource {
|
||||
public:
|
||||
ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "lldb/Host/HostInfo.h"
|
||||
#include "lldb/Symbol/Block.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "lldb/Symbol/ClangASTMetadata.h"
|
||||
#include "lldb/Symbol/CompileUnit.h"
|
||||
#include "lldb/Symbol/Function.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Core/Module.h"
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Symbol/ClangASTMetadata.h"
|
||||
#include "lldb/Symbol/ClangUtil.h"
|
||||
#include "lldb/Target/Process.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
|
@ -18,12 +18,12 @@
|
|||
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
|
||||
#include "clang/AST/ExternalASTSource.h"
|
||||
|
||||
using namespace lldb_private;
|
||||
|
||||
class lldb_private::AppleObjCExternalASTSource
|
||||
: public ClangExternalASTSourceCommon {
|
||||
: public clang::ExternalASTSource {
|
||||
public:
|
||||
AppleObjCExternalASTSource(AppleObjCDeclVendor &decl_vendor)
|
||||
: m_decl_vendor(decl_vendor) {}
|
||||
|
@ -182,7 +182,7 @@ AppleObjCDeclVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa) {
|
|||
|
||||
ClangASTMetadata meta_data;
|
||||
meta_data.SetISAPtr(isa);
|
||||
m_external_source->SetMetadata(new_iface_decl, meta_data);
|
||||
m_ast_ctx.SetMetadata(new_iface_decl, meta_data);
|
||||
|
||||
new_iface_decl->setHasExternalVisibleStorage();
|
||||
new_iface_decl->setHasExternalLexicalStorage();
|
||||
|
@ -413,7 +413,7 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
|
|||
Log *log(GetLogIfAllCategoriesSet(
|
||||
LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropriate log channel?
|
||||
|
||||
ClangASTMetadata *metadata = m_external_source->GetMetadata(interface_decl);
|
||||
ClangASTMetadata *metadata = m_ast_ctx.GetMetadata(interface_decl);
|
||||
ObjCLanguageRuntime::ObjCISA objc_isa = 0;
|
||||
if (metadata)
|
||||
objc_isa = metadata->GetISAPtr();
|
||||
|
@ -577,8 +577,7 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
|
|||
ast_ctx.getObjCInterfaceType(result_iface_decl);
|
||||
|
||||
uint64_t isa_value = LLDB_INVALID_ADDRESS;
|
||||
ClangASTMetadata *metadata =
|
||||
m_external_source->GetMetadata(result_iface_decl);
|
||||
ClangASTMetadata *metadata = m_ast_ctx.GetMetadata(result_iface_decl);
|
||||
if (metadata)
|
||||
isa_value = metadata->GetISAPtr();
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ add_lldb_library(lldbSymbol
|
|||
ClangASTImporter.cpp
|
||||
ClangASTMetadata.cpp
|
||||
ClangExternalASTSourceCallbacks.cpp
|
||||
ClangExternalASTSourceCommon.cpp
|
||||
ClangUtil.cpp
|
||||
CompactUnwindInfo.cpp
|
||||
CompileUnit.cpp
|
||||
|
|
|
@ -53,8 +53,8 @@
|
|||
#include "lldb/Core/ThreadSafeDenseMap.h"
|
||||
#include "lldb/Core/UniqueCStringMap.h"
|
||||
#include "lldb/Symbol/ClangASTImporter.h"
|
||||
#include "lldb/Symbol/ClangASTMetadata.h"
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Symbol/ClangUtil.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/SymbolFile.h"
|
||||
|
@ -2340,31 +2340,29 @@ void ClangASTContext::SetMetadataAsUserID(const clang::Type *type,
|
|||
|
||||
void ClangASTContext::SetMetadata(const clang::Decl *object,
|
||||
ClangASTMetadata &metadata) {
|
||||
if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
|
||||
getASTContext().getExternalSource()))
|
||||
A->SetMetadata(object, metadata);
|
||||
m_decl_metadata[object] = metadata;
|
||||
}
|
||||
|
||||
void ClangASTContext::SetMetadata(const clang::Type *object,
|
||||
ClangASTMetadata &metadata) {
|
||||
if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
|
||||
getASTContext().getExternalSource()))
|
||||
A->SetMetadata(object, metadata);
|
||||
m_type_metadata[object] = metadata;
|
||||
}
|
||||
|
||||
ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
|
||||
const clang::Decl *object) {
|
||||
if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
|
||||
ast->getExternalSource()))
|
||||
return A->GetMetadata(object);
|
||||
ClangASTContext *self = GetASTContext(ast);
|
||||
auto It = self->m_decl_metadata.find(object);
|
||||
if (It != self->m_decl_metadata.end())
|
||||
return &It->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
|
||||
const clang::Type *object) {
|
||||
if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
|
||||
ast->getExternalSource()))
|
||||
return A->GetMetadata(object);
|
||||
ClangASTContext *self = GetASTContext(ast);
|
||||
auto It = self->m_type_metadata.find(object);
|
||||
if (It != self->m_type_metadata.end())
|
||||
return &It->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
//===-- ClangExternalASTSourceCommon.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 "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Utility/Stream.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
using namespace lldb_private;
|
||||
|
||||
char ClangExternalASTSourceCommon::ID;
|
||||
|
||||
ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() {}
|
||||
|
||||
ClangASTMetadata *
|
||||
ClangExternalASTSourceCommon::GetMetadata(const clang::Decl *object) {
|
||||
auto It = m_decl_metadata.find(object);
|
||||
if (It != m_decl_metadata.end())
|
||||
return &It->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ClangASTMetadata *
|
||||
ClangExternalASTSourceCommon::GetMetadata(const clang::Type *object) {
|
||||
auto It = m_type_metadata.find(object);
|
||||
if (It != m_type_metadata.end())
|
||||
return &It->second;
|
||||
return nullptr;
|
||||
}
|
Loading…
Reference in New Issue