ASTContext: Add a utility to retrieve the '+' function decl for RangeReplaceableCollection in the stdlib. NFC (#11964)

This commit is contained in:
Xi Ge
2017-09-15 18:47:25 -07:00
committed by GitHub
parent 3b38edd828
commit 73e5d66c7d
3 changed files with 31 additions and 1 deletions

View File

@@ -129,6 +129,9 @@ struct ASTContext::Implementation {
DECL_CLASS *NAME##Decl = nullptr;
#include "swift/AST/KnownStdlibTypes.def"
/// The declaration of '+' function for two RangeReplaceableCollection.
FuncDecl *PlusFunctionOnRangeReplaceableCollection = nullptr;
/// The declaration of Swift.Optional<T>.Some.
EnumElementDecl *OptionalSomeDecl = nullptr;
@@ -545,6 +548,30 @@ static NominalTypeDecl *findStdlibType(const ASTContext &ctx, StringRef name,
return nullptr;
}
FuncDecl *ASTContext::getPlusFunctionOnRangeReplaceableCollection() const {
if (Impl.PlusFunctionOnRangeReplaceableCollection) {
return Impl.PlusFunctionOnRangeReplaceableCollection;
}
// Find all of the declarations with this name in the Swift module.
SmallVector<ValueDecl *, 1> Results;
lookupInSwiftModule("+", Results);
for (auto Result : Results) {
if (auto *FD = dyn_cast<FuncDecl>(Result)) {
if(!FD->getOperatorDecl())
continue;
for (auto Req: FD->getGenericRequirements()) {
if (Req.getKind() == RequirementKind::Conformance &&
Req.getSecondType()->getNominalOrBoundGenericNominal() ==
getRangeReplaceableCollectionDecl()) {
Impl.PlusFunctionOnRangeReplaceableCollection = FD;
}
}
}
}
return Impl.PlusFunctionOnRangeReplaceableCollection;
}
#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
DECL_CLASS *ASTContext::get##NAME##Decl() const { \
if (!Impl.NAME##Decl) \