Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[Sema] Use unique_ptr instead of raw pointers in the late-parsed temp…
Browse files Browse the repository at this point in the history
…lates 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283766 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Justin Lebar committed Oct 10, 2016
1 parent 46257d7 commit 1f062cd
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion include/clang/Sema/ExternalSemaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class ExternalSemaSource : public ExternalASTSource {
/// external source should take care not to introduce the same map entries
/// repeatedly.
virtual void ReadLateParsedTemplates(
llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
&LPTMap) {}

/// \copydoc Sema::CorrectTypo
/// \note LookupKind must correspond to a valid Sema::LookupNameKind
Expand Down
4 changes: 2 additions & 2 deletions include/clang/Sema/MultiplexExternalSemaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
/// external source should take care not to introduce the same map entries
/// repeatedly.
void ReadLateParsedTemplates(
llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
override;
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
&LPTMap) override;

/// \copydoc ExternalSemaSource::CorrectTypo
/// \note Returns the first nonempty correction.
Expand Down
3 changes: 2 additions & 1 deletion include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ class Sema {
SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2>
DelayedDefaultedMemberExceptionSpecs;

typedef llvm::MapVector<const FunctionDecl *, LateParsedTemplate *>
typedef llvm::MapVector<const FunctionDecl *,
std::unique_ptr<LateParsedTemplate>>
LateParsedTemplateMapT;
LateParsedTemplateMapT LateParsedTemplateMap;

Expand Down
4 changes: 2 additions & 2 deletions include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,8 @@ class ASTReader
SourceLocation> > &Pending) override;

void ReadLateParsedTemplates(
llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
override;
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
&LPTMap) override;

/// \brief Load a selector from disk, registering its ID if it exists.
void LoadSelector(Selector Sel);
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/MultiplexExternalSemaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 1f062cd

Please sign in to comment.