Skip to content
Snippets Groups Projects
Commit 661f8fec authored by David Blaikie's avatar David Blaikie
Browse files

Use default ref capture to simplify local lambdas, use a template to avoid...

Use default ref capture to simplify local lambdas, use a template to avoid std::function overhead, other cleanup

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300461 91177308-0d34-0410-b5e6-96231b3b80d8
parent 9a22a287
No related branches found
No related tags found
No related merge requests found
......@@ -89,25 +89,21 @@ bool IsForwardDeclaration(Decl *D) {
}
}
template <typename CallbackType>
void ForEachMatchingDC(
const DeclContext *DC,
llvm::ArrayRef<ExternalASTMerger::ImporterPair> Importers,
std::function<void(const ExternalASTMerger::ImporterPair &IP,
Source<const DeclContext *> SourceDC)>
Callback) {
CallbackType Callback) {
for (const ExternalASTMerger::ImporterPair &IP : Importers) {
Source<TranslationUnitDecl *> SourceTU(
IP.Forward->getFromContext().getTranslationUnitDecl());
Source<const DeclContext *> SourceDC =
LookupSameContext(SourceTU, DC, *IP.Reverse);
if (SourceDC.get()) {
Source<TranslationUnitDecl *> SourceTU =
IP.Forward->getFromContext().getTranslationUnitDecl();
if (auto SourceDC = LookupSameContext(SourceTU, DC, *IP.Reverse))
Callback(IP, SourceDC);
}
}
}
bool HasDeclOfSameType(llvm::ArrayRef<Candidate> Decls, const Candidate &C) {
return std::any_of(Decls.begin(), Decls.end(), [&C](const Candidate &D) {
return llvm::any_of(Decls, [&](const Candidate &D) {
return C.first.get()->getKind() == D.first.get()->getKind();
});
}
......@@ -139,15 +135,15 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC,
}
};
ForEachMatchingDC(DC, Importers, [Name, &FilterFoundDecl](
const ImporterPair &IP,
Source<const DeclContext *> SourceDC) {
DeclarationName FromName = IP.Reverse->Import(Name);
DeclContextLookupResult Result = SourceDC.get()->lookup(FromName);
for (NamedDecl *FromD : Result) {
FilterFoundDecl(std::make_pair(FromD, IP.Forward.get()));
}
});
ForEachMatchingDC(
DC, Importers,
[&](const ImporterPair &IP, Source<const DeclContext *> SourceDC) {
DeclarationName FromName = IP.Reverse->Import(Name);
DeclContextLookupResult Result = SourceDC.get()->lookup(FromName);
for (NamedDecl *FromD : Result) {
FilterFoundDecl(std::make_pair(FromD, IP.Forward.get()));
}
});
llvm::ArrayRef<Candidate> DeclsToReport =
CompleteDecls.empty() ? ForwardDecls : CompleteDecls;
......@@ -170,15 +166,14 @@ void ExternalASTMerger::FindExternalLexicalDecls(
const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
SmallVectorImpl<Decl *> &Result) {
ForEachMatchingDC(
DC, Importers, [DC, IsKindWeWant](const ImporterPair &IP,
Source<const DeclContext *> SourceDC) {
DC, Importers,
[&](const ImporterPair &IP, Source<const DeclContext *> SourceDC) {
for (const Decl *SourceDecl : SourceDC.get()->decls()) {
if (IsKindWeWant(SourceDecl->getKind())) {
Decl *ImportedDecl =
IP.Forward->Import(const_cast<Decl *>(SourceDecl));
assert(ImportedDecl->getDeclContext() == DC);
(void)ImportedDecl;
(void)DC;
}
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment