Skip to content

Commit 5886bc1

Browse files
authored
Merge pull request #9579 from jrose-apple/members-through-the-ages
[ClangImporter] Import ObjC members under Swift 3 and 4 names.
2 parents caf5f68 + ec23dca commit 5886bc1

File tree

13 files changed

+364
-185
lines changed

13 files changed

+364
-185
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,37 +3041,30 @@ void ClangImporter::Implementation::lookupObjCMembers(
30413041
// If the entry is not visible, skip it.
30423042
if (!isVisibleClangEntry(clangCtx, clangDecl)) continue;
30433043

3044-
// Import the declaration.
3045-
auto decl =
3046-
cast_or_null<ValueDecl>(importDeclReal(clangDecl, CurrentVersion));
3047-
if (!decl)
3048-
continue;
3049-
3050-
// If the name we found matches, report the declaration.
3051-
bool matchedAny = false;
3052-
if (decl->getFullName().matchesRef(name)) {
3053-
consumer.foundDecl(decl, DeclVisibilityKind::DynamicLookup);
3054-
matchedAny = true;
3055-
}
3044+
forEachDistinctName(clangDecl,
3045+
[&](ImportedName importedName,
3046+
ImportNameVersion nameVersion) {
3047+
// Import the declaration.
3048+
auto decl =
3049+
cast_or_null<ValueDecl>(importDeclReal(clangDecl, nameVersion));
3050+
if (!decl)
3051+
return;
30563052

3057-
// Check for an alternate declaration; if it's name matches,
3058-
// report it.
3059-
for (auto alternate : getAlternateDecls(decl)) {
3060-
if (alternate->getFullName().matchesRef(name)) {
3061-
consumer.foundDecl(alternate, DeclVisibilityKind::DynamicLookup);
3062-
matchedAny = true;
3053+
// If the name we found matches, report the declaration.
3054+
// FIXME: If we didn't need to check alternate decls here, we could avoid
3055+
// importing the member at all by checking importedName ahead of time.
3056+
if (decl->getFullName().matchesRef(name)) {
3057+
consumer.foundDecl(decl, DeclVisibilityKind::DynamicLookup);
30633058
}
3064-
}
30653059

3066-
// If we didn't find anything, try under the Swift 2 name.
3067-
if (!matchedAny) {
3068-
if (auto swift2Decl = cast_or_null<ValueDecl>(
3069-
importDeclReal(clangDecl, Version::Swift2))) {
3070-
if (swift2Decl->getFullName().matchesRef(name)) {
3071-
consumer.foundDecl(swift2Decl, DeclVisibilityKind::DynamicLookup);
3060+
// Check for an alternate declaration; if its name matches,
3061+
// report it.
3062+
for (auto alternate : getAlternateDecls(decl)) {
3063+
if (alternate->getFullName().matchesRef(name)) {
3064+
consumer.foundDecl(alternate, DeclVisibilityKind::DynamicLookup);
30723065
}
30733066
}
3074-
}
3067+
});
30753068
}
30763069
}
30773070

0 commit comments

Comments
 (0)