diff options
author | Justin Lebar <jlebar@google.com> | 2016-10-10 16:26:08 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-10-10 16:26:08 +0000 |
commit | 28f09c50e2f0712c39438b4363361ada90726b39 (patch) | |
tree | fde595734ed6bc062985a8c1ceab037cbe8e1a98 /clang/lib | |
parent | 11091971567af8a1609a81082eb8cfafaa5d4bda (diff) | |
download | llvm-28f09c50e2f0712c39438b4363361ada90726b39.zip llvm-28f09c50e2f0712c39438b4363361ada90726b39.tar.gz llvm-28f09c50e2f0712c39438b4363361ada90726b39.tar.bz2 |
[Sema] Use unique_ptr instead of raw pointers in the late-parsed templates map.
Summary:
This is possible now that MapVector supports move-only values.
Depends on D25404.
Reviewers: timshen
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D25405
llvm-svn: 283766
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/MultiplexExternalSemaSource.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 10 |
6 files changed, 17 insertions, 15 deletions
diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp index eee4c00..077a56f 100644 --- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -285,7 +285,8 @@ void MultiplexExternalSemaSource::ReadPendingInstantiations( } void MultiplexExternalSemaSource::ReadLateParsedTemplates( - llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { + llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> + &LPTMap) { for (size_t i = 0; i < Sources.size(); ++i) Sources[i]->ReadLateParsedTemplates(LPTMap); } diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 9ea5cba..fac608d 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -259,7 +259,6 @@ void Sema::Initialize() { } Sema::~Sema() { - llvm::DeleteContainerSeconds(LateParsedTemplateMap); if (VisContext) FreeVisContext(); // Kill all the active scopes. for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 7061f07..0a03f8e 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -8668,12 +8668,12 @@ void Sema::MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, if (!FD) return; - LateParsedTemplate *LPT = new LateParsedTemplate; + auto LPT = llvm::make_unique<LateParsedTemplate>(); // Take tokens to avoid allocations LPT->Toks.swap(Toks); LPT->D = FnD; - LateParsedTemplateMap.insert(std::make_pair(FD, LPT)); + LateParsedTemplateMap.insert(std::make_pair(FD, std::move(LPT))); FD->setLateTemplateParsed(true); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index cc8f56b..09068d7 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3622,9 +3622,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, if (PatternDecl->isFromASTFile()) ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap); - LateParsedTemplate *LPT = LateParsedTemplateMap.lookup(PatternDecl); - assert(LPT && "missing LateParsedTemplate"); - LateTemplateParser(OpaqueParser, *LPT); + auto LPTIter = LateParsedTemplateMap.find(PatternDecl); + assert(LPTIter != LateParsedTemplateMap.end() && + "missing LateParsedTemplate"); + LateTemplateParser(OpaqueParser, *LPTIter->second); Pattern = PatternDecl->getBody(PatternDecl); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d12dda6..52e06e4 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -7556,12 +7556,13 @@ void ASTReader::ReadPendingInstantiations( } void ASTReader::ReadLateParsedTemplates( - llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { + llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> + &LPTMap) { for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; /* In loop */) { FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); - LateParsedTemplate *LT = new LateParsedTemplate; + auto LT = llvm::make_unique<LateParsedTemplate>(); LT->D = GetDecl(LateParsedTemplates[Idx++]); ModuleFile *F = getOwningModuleFile(LT->D); @@ -7572,7 +7573,7 @@ void ASTReader::ReadLateParsedTemplates( for (unsigned T = 0; T < TokN; ++T) LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); - LPTMap.insert(std::make_pair(FD, LT)); + LPTMap.insert(std::make_pair(FD, std::move(LT))); } LateParsedTemplates.clear(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index da513a7..335a932 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4009,14 +4009,14 @@ void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { return; RecordData Record; - for (auto LPTMapEntry : LPTMap) { + for (auto &LPTMapEntry : LPTMap) { const FunctionDecl *FD = LPTMapEntry.first; - LateParsedTemplate *LPT = LPTMapEntry.second; + LateParsedTemplate &LPT = *LPTMapEntry.second; AddDeclRef(FD, Record); - AddDeclRef(LPT->D, Record); - Record.push_back(LPT->Toks.size()); + AddDeclRef(LPT.D, Record); + Record.push_back(LPT.Toks.size()); - for (const auto &Tok : LPT->Toks) { + for (const auto &Tok : LPT.Toks) { AddToken(Tok, Record); } } |