mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Omit needless words] Don't avoid keywords that will be allowed after '.'.
In anticipation of SE-0071, teach the Clang importer to only avoid dynamicType/self/Protocol/init as base names. Fixes rdar://problem/25399965.
This commit is contained in:
@@ -34,6 +34,16 @@ bool swift::canBeArgumentLabel(StringRef identifier) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool swift::canBeMemberName(StringRef identifier) {
|
||||
return llvm::StringSwitch<bool>(identifier)
|
||||
.Case("dynamicType", false)
|
||||
.Case("init", false)
|
||||
.Case("Protocol", false)
|
||||
.Case("self", false)
|
||||
.Case("Type", false)
|
||||
.Default(true);
|
||||
}
|
||||
|
||||
PrepositionKind swift::getPrepositionKind(StringRef word) {
|
||||
#define DIRECTIONAL_PREPOSITION(Word) \
|
||||
if (word.equals_lower(#Word)) \
|
||||
@@ -334,15 +344,6 @@ size_t camel_case::findWord(StringRef string, StringRef word) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine whether the given identifier is a keyword.
|
||||
static bool isKeyword(StringRef identifier) {
|
||||
return llvm::StringSwitch<bool>(identifier)
|
||||
#define KEYWORD(kw) .Case(#kw, true)
|
||||
#define SIL_KEYWORD(kw)
|
||||
#include "swift/Parse/Tokens.def"
|
||||
.Default(false);
|
||||
}
|
||||
|
||||
/// Skip a type suffix that can be dropped.
|
||||
static Optional<StringRef> skipTypeSuffix(StringRef typeName) {
|
||||
if (typeName.empty()) return None;
|
||||
@@ -810,9 +811,9 @@ static StringRef omitNeedlessWords(StringRef name,
|
||||
case NameRole::BaseName:
|
||||
case NameRole::BaseNameSelf:
|
||||
case NameRole::Property:
|
||||
// If we ended up with a keyword for a property name or base name,
|
||||
// If we ended up with something that can't be a member name, do nothing.
|
||||
// do nothing.
|
||||
if (isKeyword(name))
|
||||
if (!canBeMemberName(name))
|
||||
return origName;
|
||||
|
||||
// If we ended up with a vacuous name like "get" or "set", do nothing.
|
||||
@@ -1093,7 +1094,7 @@ static bool splitBaseNameAfterLastPreposition(
|
||||
{
|
||||
auto newWords = camel_case::getWords(newBaseName);
|
||||
auto newWordsIter = newWords.begin();
|
||||
bool isKeyword = ::isKeyword(*newWordsIter);
|
||||
bool isKeyword = !canBeMemberName(*newWordsIter);
|
||||
bool isVacuous = isVacuousName(*newWordsIter);
|
||||
if (isKeyword || isVacuous) {
|
||||
// Just one word?
|
||||
|
||||
Reference in New Issue
Block a user