mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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,9 @@ namespace swift {
|
||||
/// \seealso Token::canBeArgumentLabel()
|
||||
bool canBeArgumentLabel(StringRef identifier);
|
||||
|
||||
/// Determine whether the given string can be the name of a member.
|
||||
bool canBeMemberName(StringRef identifier);
|
||||
|
||||
/// Describes the kind of preposition a word is.
|
||||
enum PrepositionKind {
|
||||
PK_None = 0,
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -96,8 +96,8 @@
|
||||
// Note: property name stripping property type.
|
||||
// CHECK-FOUNDATION: var uppercased: String
|
||||
|
||||
// Note: don't map base name down to a keyword.
|
||||
// CHECK-FOUNDATION: func doSelector(_: Selector!)
|
||||
// Note: ok to map base name down to a keyword.
|
||||
// CHECK-FOUNDATION: func `do`(_: Selector!)
|
||||
|
||||
// Note: Strip names preceded by a gerund.
|
||||
// CHECK-FOUNDATION: func startSquashing(_: Bee)
|
||||
@@ -287,7 +287,7 @@
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func objectAtIndexedSubscript(_: UInt) -> AnyObject
|
||||
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func exportPresets(bestMatching: String)
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func isCompatibleWith(_: String)
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func `is`(compatibleWith: String)
|
||||
|
||||
// CHECK-OMIT-NEEDLESS-WORDS: func add(_: AnyObject)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user