diff options
author | Chris Bieneman <chris.bieneman@me.com> | 2022-09-01 16:31:23 -0500 |
---|---|---|
committer | Chris Bieneman <chris.bieneman@me.com> | 2022-09-02 13:57:39 -0500 |
commit | 5b5329bd41ba977459fcd7abb7cf438fd98c98e0 (patch) | |
tree | 5bf4a8bc736e4856001d32a74339e2ee96fd8a5b /clang/lib/Sema | |
parent | 1491282165bfb87b15bd806ab53b3e9910ee7b29 (diff) | |
download | llvm-5b5329bd41ba977459fcd7abb7cf438fd98c98e0.zip llvm-5b5329bd41ba977459fcd7abb7cf438fd98c98e0.tar.gz llvm-5b5329bd41ba977459fcd7abb7cf438fd98c98e0.tar.bz2 |
[NFC] Make MultiplexExternalSemaSource own sources
This change refactors the MuiltiplexExternalSemaSource to take ownership
of the underlying sources. As a result it makes a larger cleanup of
external source ownership in Sema and the ChainedIncludesSource.
Reviewed By: aaron.ballman, aprantl
Differential Revision: https://reviews.llvm.org/D133158
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/MultiplexExternalSemaSource.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 4 |
3 files changed, 30 insertions, 30 deletions
diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp index 0727756..55e0154 100644 --- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -16,24 +16,30 @@ using namespace clang; char MultiplexExternalSemaSource::ID; -///Constructs a new multiplexing external sema source and appends the +/// Constructs a new multiplexing external sema source and appends the /// given element to it. /// -MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1, - ExternalSemaSource &s2){ - Sources.push_back(&s1); - Sources.push_back(&s2); +MultiplexExternalSemaSource::MultiplexExternalSemaSource( + ExternalSemaSource *S1, ExternalSemaSource *S2) { + S1->Retain(); + S2->Retain(); + Sources.push_back(S1); + Sources.push_back(S2); } // pin the vtable here. -MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {} +MultiplexExternalSemaSource::~MultiplexExternalSemaSource() { + for (auto *S : Sources) + S->Release(); +} -///Appends new source to the source list. +/// Appends new source to the source list. /// ///\param[in] source - An ExternalSemaSource. /// -void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) { - Sources.push_back(&source); +void MultiplexExternalSemaSource::AddSource(ExternalSemaSource *Source) { + Source->Retain(); + Sources.push_back(Source); } //===----------------------------------------------------------------------===// diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 0410032..1158685 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -185,11 +185,10 @@ const uint64_t Sema::MaximumAlignment; Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter) - : ExternalSource(nullptr), isMultiplexExternalSource(false), - CurFPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp), - Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()), - SourceMgr(PP.getSourceManager()), CollectStats(false), - CodeCompleter(CodeCompleter), CurContext(nullptr), + : ExternalSource(nullptr), CurFPFeatures(pp.getLangOpts()), + LangOpts(pp.getLangOpts()), PP(pp), Context(ctxt), Consumer(consumer), + Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), + CollectStats(false), CodeCompleter(CodeCompleter), CurContext(nullptr), OriginalLexicalContext(nullptr), MSStructPragmaOn(false), MSPointerToMemberRepresentationMethod( LangOpts.getMSPointerToMemberRepresentationMethod()), @@ -473,10 +472,6 @@ Sema::~Sema() { = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) ExternalSema->ForgetSema(); - // If Sema's ExternalSource is the multiplexer - we own it. - if (isMultiplexExternalSource) - delete ExternalSource; - // Delete cached satisfactions. std::vector<ConstraintSatisfaction *> Satisfactions; Satisfactions.reserve(Satisfactions.size()); @@ -550,12 +545,10 @@ void Sema::addExternalSource(ExternalSemaSource *E) { return; } - if (isMultiplexExternalSource) - static_cast<MultiplexExternalSemaSource*>(ExternalSource)->addSource(*E); - else { - ExternalSource = new MultiplexExternalSemaSource(*ExternalSource, *E); - isMultiplexExternalSource = true; - } + if (auto *Ex = dyn_cast<MultiplexExternalSemaSource>(ExternalSource)) + Ex->AddSource(E); + else + ExternalSource = new MultiplexExternalSemaSource(ExternalSource.get(), E); } /// Print out statistics about the semantic analysis. @@ -1291,8 +1284,8 @@ void Sema::ActOnEndOfTranslationUnit() { // translation unit, with an initializer equal to 0. llvm::SmallSet<VarDecl *, 32> Seen; for (TentativeDefinitionsType::iterator - T = TentativeDefinitions.begin(ExternalSource), - TEnd = TentativeDefinitions.end(); + T = TentativeDefinitions.begin(ExternalSource.get()), + TEnd = TentativeDefinitions.end(); T != TEnd; ++T) { VarDecl *VD = (*T)->getActingDefinition(); @@ -1336,8 +1329,9 @@ void Sema::ActOnEndOfTranslationUnit() { if (!Diags.hasErrorOccurred() && TUKind != TU_Module) { // Output warning for unused file scoped decls. for (UnusedFileScopedDeclsType::iterator - I = UnusedFileScopedDecls.begin(ExternalSource), - E = UnusedFileScopedDecls.end(); I != E; ++I) { + I = UnusedFileScopedDecls.begin(ExternalSource.get()), + E = UnusedFileScopedDecls.end(); + I != E; ++I) { if (ShouldRemoveFromUnused(this, *I)) continue; diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 04d06c1..76db4e5 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -18183,8 +18183,8 @@ void Sema::CheckDelegatingCtorCycles() { llvm::SmallPtrSet<CXXConstructorDecl*, 4> Valid, Invalid, Current; for (DelegatingCtorDeclsType::iterator - I = DelegatingCtorDecls.begin(ExternalSource), - E = DelegatingCtorDecls.end(); + I = DelegatingCtorDecls.begin(ExternalSource.get()), + E = DelegatingCtorDecls.end(); I != E; ++I) DelegatingCycleHelper(*I, Valid, Invalid, Current, *this); |