Skip to content

Commit 9a44bbf

Browse files
committed
[lldb][NFC] Add an ImporterBackedASTSource that serves as base class for LLDB ExternalASTSources that use the ASTImporter
This gives all ExternalASTSource classes a common base class that allows other classes (in LLDB's case ClangASTImporter) to invalidate the redeclaration chains in an ASTContext. The implementation just calls the (private) function to bump the generation counter which is how we track whether a redeclaration chain is out of date. This is used in D101950 to let the ClangASTImporter mark redeclaration chains as out-of-date so that they update themselves via the ExternalASTSource. Patch itself is NFC as it just changes the inheritance of a bunch of classes and changes the LLVM RTTI to make sure we can reliably cast to it. Will be merged with its dependent patch that lets the ClangASTImporter handle redeclaration chains.
1 parent b650764 commit 9a44bbf

File tree

7 files changed

+73
-6
lines changed

7 files changed

+73
-6
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
1111

1212
#include "clang/Basic/ASTSourceDescriptor.h"
13+
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
14+
#include "clang/Basic/Module.h"
1315
#include "clang/Sema/Lookup.h"
1416
#include "clang/Sema/MultiplexExternalSemaSource.h"
1517
#include "clang/Sema/Sema.h"
@@ -26,7 +28,7 @@ namespace lldb_private {
2628

2729
/// Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take
2830
/// ownership of the provided source.
29-
class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
31+
class ExternalASTSourceWrapper : public ImporterBackedASTSource {
3032
ExternalASTSource *m_Source;
3133

3234
public:
@@ -246,7 +248,7 @@ class ASTConsumerForwarder : public clang::SemaConsumer {
246248
/// provide more accurate replies to the requests, but might not be able to
247249
/// answer all requests. The debug information will be used as a fallback then
248250
/// to provide information that is not in the C++ module.
249-
class SemaSourceWithPriorities : public clang::ExternalSemaSource {
251+
class SemaSourceWithPriorities : public ImporterBackedASTSource {
250252

251253
private:
252254
/// The sources ordered in decreasing priority.

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
1515
#include "Plugins/ExpressionParser/Clang/NameSearchContext.h"
16+
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
1617
#include "lldb/Symbol/CompilerType.h"
1718
#include "lldb/Target/Target.h"
1819
#include "clang/AST/ExternalASTSource.h"
@@ -30,7 +31,7 @@ namespace lldb_private {
3031
/// knows the name it is looking for, but nothing else. The ExternalSemaSource
3132
/// class provides Decls (VarDecl, FunDecl, TypeDecl) to Clang for these
3233
/// names, consulting the ClangExpressionDeclMap to do the actual lookups.
33-
class ClangASTSource : public clang::ExternalASTSource,
34+
class ClangASTSource : public ImporterBackedASTSource,
3435
public ClangASTImporter::MapCompleter {
3536
public:
3637
/// Constructor

lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H
1010
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H
1111

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

2223
namespace lldb_private {
2324

24-
class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {
25+
class ClangExternalASTSourceCallbacks : public ImporterBackedASTSource {
2526
/// LLVM RTTI support.
2627
static char ID;
2728

2829
public:
2930
/// LLVM RTTI support.
30-
bool isA(const void *ClassID) const override { return ClassID == &ID; }
31+
bool isA(const void *ClassID) const override {
32+
return ClassID == &ID || ImporterBackedASTSource::isA(ClassID);
33+
}
3134
static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); }
3235

3336
ClangExternalASTSourceCallbacks(TypeSystemClang &ast) : m_ast(ast) {}

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
1212
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
1313
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
14+
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
1415
#include "lldb/Core/Module.h"
1516
#include "lldb/Target/Process.h"
1617
#include "lldb/Target/Target.h"
@@ -24,7 +25,7 @@
2425
using namespace lldb_private;
2526

2627
class lldb_private::AppleObjCExternalASTSource
27-
: public clang::ExternalASTSource {
28+
: public ImporterBackedASTSource {
2829
public:
2930
AppleObjCExternalASTSource(AppleObjCDeclVendor &decl_vendor)
3031
: m_decl_vendor(decl_vendor) {}

lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_library(lldbPluginTypeSystemClang PLUGIN
2+
ImporterBackedASTSource.cpp
23
TypeSystemClang.cpp
34

45
LINK_LIBS
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- ImporterBackedASTSource.cpp ---------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h"
10+
11+
using namespace lldb_private;
12+
13+
char ImporterBackedASTSource::ID;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===-- ImporterBackedASTSource.h -------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE
10+
#define LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE
11+
12+
#include "clang/AST/ASTContext.h"
13+
#include "clang/Sema/ExternalSemaSource.h"
14+
15+
namespace lldb_private {
16+
17+
/// The base class of all ExternalASTSources in LLDB that use the
18+
/// ClangASTImporter to move declarations from other ASTs to the ASTContext they
19+
/// are attached to.
20+
class ImporterBackedASTSource : public clang::ExternalSemaSource {
21+
/// LLVM RTTI support.
22+
static char ID;
23+
24+
public:
25+
/// LLVM RTTI support.
26+
bool isA(const void *ClassID) const override {
27+
return ClassID == &ID || ExternalSemaSource::isA(ClassID);
28+
}
29+
static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); }
30+
31+
/// This marks all redeclaration chains in the ASTContext as out-of-date and
32+
/// that this ExternalASTSource should be consulted to get the complete
33+
/// redeclaration chain.
34+
///
35+
/// \see ExternalASTSource::CompleteRedeclChain
36+
void MarkRedeclChainsAsOutOfDate(clang::ASTContext &c) {
37+
// This invalidates redeclaration chains but also other things such as
38+
// identifiers. There isn't a more precise way at the moment that only
39+
// affects redecl chains.
40+
incrementGeneration(c);
41+
}
42+
};
43+
44+
} // namespace lldb_private
45+
46+
#endif // LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE

0 commit comments

Comments
 (0)