Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H

#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "clang/Basic/ASTSourceDescriptor.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/MultiplexExternalSemaSource.h"
Expand All @@ -30,7 +29,7 @@ namespace lldb_private {
/// Wraps an ExternalASTSource into an ExternalSemaSource.
///
/// Assumes shared ownership of the underlying source.
class ExternalASTSourceWrapper : public ImporterBackedASTSource {
class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
llvm::IntrusiveRefCntPtr<ExternalASTSource> m_Source;

public:
Expand Down Expand Up @@ -281,7 +280,7 @@ class ASTConsumerForwarder : public clang::SemaConsumer {
/// provide more accurate replies to the requests, but might not be able to
/// answer all requests. The debug information will be used as a fallback then
/// to provide information that is not in the C++ module.
class SemaSourceWithPriorities : public ImporterBackedASTSource {
class SemaSourceWithPriorities : public clang::ExternalSemaSource {

private:
/// The sources ordered in decreasing priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "lldb/Core/Module.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/LLDBLog.h"
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
#include "Plugins/ExpressionParser/Clang/NameSearchContext.h"
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Target/Target.h"
#include "clang/AST/ExternalASTSource.h"
Expand All @@ -31,7 +30,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 ImporterBackedASTSource,
class ClangASTSource : public clang::ExternalASTSource,
public ClangASTImporter::MapCompleter {
public:
/// Constructor
Expand Down Expand Up @@ -210,7 +209,7 @@ class ClangASTSource : public ImporterBackedASTSource,
///
/// Clang AST contexts like to own their AST sources, so this is a state-
/// free proxy object.
class ClangASTSourceProxy : public ImporterBackedASTSource {
class ClangASTSourceProxy : public clang::ExternalASTSource {
public:
ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H

#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "clang/Basic/ASTSourceDescriptor.h"
#include <optional>
Expand All @@ -22,15 +21,13 @@ class Module;

namespace lldb_private {

class ClangExternalASTSourceCallbacks : public ImporterBackedASTSource {
class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {
/// LLVM RTTI support.
static char ID;

public:
/// LLVM RTTI support.
bool isA(const void *ClassID) const override {
return ClassID == &ID || ImporterBackedASTSource::isA(ClassID);
}
bool isA(const void *ClassID) const override { return ClassID == &ID; }
static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); }

ClangExternalASTSourceCallbacks(TypeSystemClang &ast) : m_ast(ast) {}
Expand Down
10 changes: 0 additions & 10 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
return qual_type->getAsTagDecl();
}

clang::Decl *ClangUtil::GetFirstDecl(clang::Decl *d) {
if (!d)
return nullptr;
if (auto *td = llvm::dyn_cast<clang::TagDecl>(d))
return td->getFirstDecl();
if (auto *od = llvm::dyn_cast<clang::ObjCInterfaceDecl>(d))
return od->getFirstDecl();
return d;
}

clang::ObjCInterfaceDecl *ClangUtil::GetAsObjCDecl(const CompilerType &type) {
clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
if (qual_type.isNull())
Expand Down
9 changes: 0 additions & 9 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ struct ClangUtil {

static clang::TagDecl *GetAsTagDecl(const CompilerType &type);

/// If the given Decl is redeclarable, return the first declaration in its
/// redeclaration chain. Otherwise return d itself.
static clang::Decl *GetFirstDecl(clang::Decl *d);

/// \see ClangUtil::GetFirstDecl
static const clang::Decl *GetFirstDecl(const clang::Decl *d) {
return GetFirstDecl(const_cast<clang::Decl *>(d));
}

static clang::ObjCInterfaceDecl *GetAsObjCDecl(const CompilerType &type);

/// Returns a textual representation of the given Decl's AST. Does not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "lldb/Core/Module.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
Expand All @@ -25,7 +24,7 @@
using namespace lldb_private;

class lldb_private::AppleObjCExternalASTSource
: public ImporterBackedASTSource {
: public clang::ExternalASTSource {
public:
AppleObjCExternalASTSource(AppleObjCDeclVendor &decl_vendor)
: m_decl_vendor(decl_vendor) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "DWARFDebugInfo.h"
#include "DWARFDeclContext.h"
#include "DWARFDefines.h"
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "SymbolFileDWARF.h"
#include "SymbolFileDWARFDebugMap.h"
Expand Down Expand Up @@ -2033,9 +2032,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
m_ast.SetMetadata(class_template_decl, metadata);
m_ast.SetMetadata(class_specialization_decl, metadata);
RegisterDIE(die.GetDIE(), clang_type);
if (auto *source = llvm::dyn_cast_or_null<ImporterBackedASTSource>(
m_ast.getASTContext().getExternalSource()))
source->MarkRedeclChainsAsOutOfDate(m_ast.getASTContext());
}

if (!clang_type) {
Expand Down
1 change: 0 additions & 1 deletion lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_lldb_library(lldbPluginTypeSystemClang PLUGIN
ImporterBackedASTSource.cpp
TypeSystemClang.cpp

LINK_COMPONENTS
Expand Down

This file was deleted.

46 changes: 0 additions & 46 deletions lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.h

This file was deleted.

123 changes: 6 additions & 117 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,18 +1186,11 @@ CompilerType TypeSystemClang::GetTypeForDecl(clang::NamedDecl *decl) {
}

CompilerType TypeSystemClang::GetTypeForDecl(TagDecl *decl) {
// Create the type for the TagDecl. Pass the previous decl to make sure that
// all redeclarations share the same type.
return GetType(
getASTContext().getTypeDeclType(decl, decl->getPreviousDecl()));
return GetType(getASTContext().getTagDeclType(decl));
}

CompilerType TypeSystemClang::GetTypeForDecl(const ObjCInterfaceDecl *decl) {
// FIXME: getObjCInterfaceType second parameter could be const.
// Create the type for the ObjCInterfaceDecl. Pass the previous decl to make
// sure that all redeclarations share the same type.
return GetType(getASTContext().getObjCInterfaceType(
decl, const_cast<ObjCInterfaceDecl *>(decl->getPreviousDecl())));
return GetType(getASTContext().getObjCInterfaceType(decl));
}

CompilerType TypeSystemClang::GetTypeForDecl(clang::ValueDecl *value_decl) {
Expand Down Expand Up @@ -1716,13 +1709,6 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
class_template_specialization_decl->setSpecializationKind(
TSK_ExplicitSpecialization);

// Store the information that is needed to later redeclare this exact
// template specialization.
ClassTemplateRedeclInfo redecl_info;
redecl_info.m_template_args = template_param_infos;
m_class_template_redecl_infos[class_template_specialization_decl] =
redecl_info;

return class_template_specialization_decl;
}

Expand Down Expand Up @@ -2539,17 +2525,9 @@ void TypeSystemClang::SetMetadataAsUserID(const clang::Type *type,
SetMetadata(type, meta_data);
}

/// Returns the Decl in a redeclaration chain that is used to store the
/// the ClangASTMetadata in the metadata map.
static const clang::Decl *GetDeclForMetadataStorage(const clang::Decl *d) {
// Only the first Decl never changes and never requires any loading from
// the ExternalASTSource, so it can be a stable key for the map.
return ClangUtil::GetFirstDecl(d);
}

void TypeSystemClang::SetMetadata(const clang::Decl *object,
ClangASTMetadata metadata) {
m_decl_metadata[GetDeclForMetadataStorage(object)] = metadata;
m_decl_metadata[object] = metadata;
}

void TypeSystemClang::SetMetadata(const clang::Type *object,
Expand All @@ -2559,7 +2537,7 @@ void TypeSystemClang::SetMetadata(const clang::Type *object,

std::optional<ClangASTMetadata>
TypeSystemClang::GetMetadata(const clang::Decl *object) {
auto It = m_decl_metadata.find(GetDeclForMetadataStorage(object));
auto It = m_decl_metadata.find(object);
if (It != m_decl_metadata.end())
return It->second;

Expand Down Expand Up @@ -8463,11 +8441,7 @@ bool TypeSystemClang::StartTagDeclarationDefinition(const CompilerType &type) {
if (tag_type) {
clang::TagDecl *tag_decl = tag_type->getDecl();
if (tag_decl) {
// There are several declarations in the redeclaration chain that could
// define this type. The most logical declaration that we could turn
// into a definition is the most recent one.
clang::TagDecl *def = tag_decl->getMostRecentDecl();
def->startDefinition();
tag_decl->startDefinition();
return true;
}
}
Expand All @@ -8477,11 +8451,7 @@ bool TypeSystemClang::StartTagDeclarationDefinition(const CompilerType &type) {
if (object_type) {
clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
if (interface_decl) {
// There are several declarations in the redeclaration chain that could
// define this type. The most logical declaration that we could turn
// into a definition is the most recent one.
clang::ObjCInterfaceDecl *def = interface_decl->getMostRecentDecl();
def->startDefinition();
interface_decl->startDefinition();
return true;
}
}
Expand Down Expand Up @@ -9154,87 +9124,6 @@ void TypeSystemClang::CompleteObjCInterfaceDecl(
}
}

/// Appends an existing declaration to the redeclaration chain.
/// \param ts The TypeSystemClang that contains the two declarations.
/// \param prev The most recent existing declaration.
/// \param redecl The new declaration which should be appended to the end of
/// redeclaration chain.
template <typename T>
static void ConnectRedeclToPrev(TypeSystemClang &ts, T *prev, T *redecl) {
assert(&ts.getASTContext() == &prev->getASTContext() && "Not ");
redecl->setPreviousDecl(prev);
// Now that the redecl chain is done, create the type explicitly via
// the TypeSystemClang interface that will reuse the type of the previous
// decl.
ts.GetTypeForDecl(redecl);
// The previous decl and the redeclaration both declare the same type.
// FIXME: rdar://123500660, this is causing large number of test failures.
// assert(prev->getTypeForDecl() == redecl->getTypeForDecl());
}

/// Returns the ClangModuleID for the given declaration.
static OptionalClangModuleID GetModuleForDecl(clang::Decl *d) {
if (!d->isFromASTFile() || !d->getOwningModuleID())
return OptionalClangModuleID();
return OptionalClangModuleID(d->getOwningModuleID());
}

CompilerType TypeSystemClang::CreateRedeclaration(CompilerType ct) {
// All the cases below just check for a specific declaration kind, create
// a new declaration with matching data. We don't care about metadata which
// should only be tracked in the first redeclaration and should be identical
// for all redeclarations.

if (clang::ObjCInterfaceDecl *interface = ClangUtil::GetAsObjCDecl(ct)) {
clang::NamedDecl *res = CreateObjCDecl(
interface->getName(), interface->getDeclContext()->getRedeclContext(),
GetModuleForDecl(interface), interface->isImplicit());
clang::ObjCInterfaceDecl *redecl = llvm::cast<ObjCInterfaceDecl>(res);
ConnectRedeclToPrev(*this, interface, redecl);
return GetTypeForDecl(redecl);
}

clang::TagDecl *tag_decl = ClangUtil::GetAsTagDecl(ct);
if (!tag_decl)
return {};

if (clang::EnumDecl *enum_decl = dyn_cast<EnumDecl>(tag_decl)) {
Declaration decl;
clang::EnumDecl *redecl = CreateEnumerationDecl(
enum_decl->getNameAsString().c_str(),
tag_decl->getDeclContext()->getRedeclContext(),
GetModuleForDecl(enum_decl), decl, GetType(enum_decl->getIntegerType()),
enum_decl->isScoped());
ConnectRedeclToPrev(*this, enum_decl, redecl);
return GetTypeForDecl(redecl);
}

if (auto *template_decl =
dyn_cast<ClassTemplateSpecializationDecl>(tag_decl)) {
auto redecl_info = m_class_template_redecl_infos.find(template_decl);
// If we are asked to redeclare a template that we haven't declared, then
// there is nothing we can do.
assert(redecl_info != m_class_template_redecl_infos.end());
TemplateParameterInfos template_infos = redecl_info->second.m_template_args;
auto *redecl = CreateClassTemplateSpecializationDecl(
tag_decl->getDeclContext()->getRedeclContext(),
GetModuleForDecl(template_decl),
template_decl->getSpecializedTemplate(),
llvm::to_underlying(tag_decl->getTagKind()), template_infos);
ConnectRedeclToPrev(*this, template_decl, redecl);
return GetType(clang::QualType(redecl->getTypeForDecl(), 0U));
}

assert(llvm::isa<RecordDecl>(tag_decl));
clang::NamedDecl *redecl_record = CreateRecordDecl(
tag_decl->getDeclContext()->getRedeclContext(),
GetModuleForDecl(tag_decl), lldb::eAccessPublic, tag_decl->getName(),
llvm::to_underlying(tag_decl->getTagKind()), eLanguageTypeC_plus_plus);
clang::TagDecl *redecl = llvm::cast<TagDecl>(redecl_record);
ConnectRedeclToPrev(*this, tag_decl, redecl);
return GetTypeForDecl(redecl);
}

DWARFASTParser *TypeSystemClang::GetDWARFParser() {
if (!m_dwarf_ast_parser_up)
m_dwarf_ast_parser_up = std::make_unique<DWARFASTParserClang>(*this);
Expand Down
Loading