Skip to content

Commit 3caf703

Browse files
committed
Narrow the Clang importer's importDeclName to just importIdentifier. NFC
We never used it for non-identifier names, and the former is somewhat ambiguous with the new importFullName.
1 parent a861a73 commit 3caf703

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,22 +1489,22 @@ DeclName ClangImporter::Implementation::importFullName(
14891489
}
14901490

14911491
Identifier
1492-
ClangImporter::Implementation::importDeclName(clang::DeclarationName name,
1493-
StringRef removePrefix) {
1494-
// FIXME: At some point, we'll be able to import operators as well.
1495-
if (!name || name.getNameKind() != clang::DeclarationName::Identifier)
1496-
return Identifier();
1492+
ClangImporter::Implementation::importIdentifier(
1493+
const clang::IdentifierInfo *identifier,
1494+
StringRef removePrefix)
1495+
{
1496+
if (!identifier) return Identifier();
14971497

1498-
StringRef nameStr = name.getAsIdentifierInfo()->getName();
1498+
StringRef name = identifier->getName();
14991499
// Remove the prefix, if any.
15001500
if (!removePrefix.empty()) {
1501-
if (nameStr.startswith(removePrefix)) {
1502-
nameStr = nameStr.slice(removePrefix.size(), nameStr.size());
1501+
if (name.startswith(removePrefix)) {
1502+
name = name.slice(removePrefix.size(), name.size());
15031503
}
15041504
}
15051505

15061506
// Get the Swift identifier.
1507-
return SwiftContext.getIdentifier(nameStr);
1507+
return SwiftContext.getIdentifier(name);
15081508
}
15091509

15101510
Identifier
@@ -1518,7 +1518,7 @@ ClangImporter::Implementation::importName(const clang::NamedDecl *D,
15181518
return Identifier();
15191519
}
15201520

1521-
Identifier result = importDeclName(D->getDeclName(), removePrefix);
1521+
Identifier result = importIdentifier(D->getIdentifier(), removePrefix);
15221522
if (result.empty())
15231523
return result;
15241524

@@ -2820,7 +2820,7 @@ void ClangImporter::lookupVisibleDecls(VisibleDeclConsumer &Consumer) const {
28202820
for (auto I = ClangPP.macro_begin(), E = ClangPP.macro_end(); I != E; ++I) {
28212821
if (!I->first->hasMacroDefinition())
28222822
continue;
2823-
auto Name = Impl.importDeclName(I->first);
2823+
auto Name = Impl.importIdentifier(I->first);
28242824
if (Name.empty())
28252825
continue;
28262826
if (auto *Imported = Impl.importMacro(

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5108,7 +5108,7 @@ namespace {
51085108
name,
51095109
None);
51105110
result->computeType();
5111-
addObjCAttribute(result, Impl.importDeclName(decl->getDeclName()));
5111+
addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier()));
51125112

51135113
if (declaredNative)
51145114
markMissingSwiftDecl(result);
@@ -5193,7 +5193,7 @@ namespace {
51935193
result->setSuperclass(Type());
51945194
result->setCheckedInheritanceClause();
51955195
result->setAddedImplicitInitializers(); // suppress all initializers
5196-
addObjCAttribute(result, Impl.importDeclName(decl->getDeclName()));
5196+
addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier()));
51975197
Impl.registerExternalDecl(result);
51985198
return result;
51995199
};
@@ -5262,7 +5262,7 @@ namespace {
52625262
Impl.ImportedDecls[decl->getCanonicalDecl()] = result;
52635263
result->setCircularityCheck(CircularityCheck::Checked);
52645264
result->setAddedImplicitInitializers();
5265-
addObjCAttribute(result, Impl.importDeclName(decl->getDeclName()));
5265+
addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier()));
52665266

52675267
if (declaredNative)
52685268
markMissingSwiftDecl(result);

lib/ClangImporter/ImporterImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,15 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
734734
/// \sa importName(clang::DeclarationName, StringRef)
735735
Identifier importName(const clang::NamedDecl *D, StringRef removePrefix = "");
736736

737-
/// \brief Import the given Clang name into Swift.
737+
/// \brief Import the given Clang identifier into Swift.
738738
///
739-
/// \param name The Clang name to map into Swift.
739+
/// \param identifier The Clang identifier to map into Swift.
740740
///
741741
/// \param removePrefix The prefix to remove from the Clang name to produce
742742
/// the Swift name. If the Clang name does not start with this prefix,
743743
/// nothing is removed.
744-
Identifier importDeclName(clang::DeclarationName name,
745-
StringRef removePrefix = "");
744+
Identifier importIdentifier(const clang::IdentifierInfo *identifier,
745+
StringRef removePrefix = "");
746746

747747
/// Import an Objective-C selector.
748748
ObjCSelector importSelector(clang::Selector selector);

0 commit comments

Comments
 (0)