Skip to content

Commit aa95565

Browse files
authored
Merge pull request #72048 from Jamezzzb/#56350
#56350 - Give Identifier a hasUnderscoredNaming() helper
2 parents 10255b3 + 2c28120 commit aa95565

File tree

7 files changed

+10
-7
lines changed

7 files changed

+10
-7
lines changed

include/swift/AST/Identifier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class Identifier {
177177
return str().startswith("$") && !(getLength() == 1);
178178
}
179179

180+
bool hasUnderscoredNaming() const {
181+
return str().startswith("_");
182+
}
183+
180184
const void *getAsOpaquePointer() const {
181185
return static_cast<const void *>(Pointer);
182186
}

include/swift/IDE/CompletionLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
304304
void includeInstanceMembers() { IncludeInstanceMembers = true; }
305305

306306
bool isHiddenModuleName(Identifier Name) {
307-
return (Name.str().startswith("_") || Name == Ctx.SwiftShimsModuleName ||
307+
return (Name.hasUnderscoredNaming() || Name == Ctx.SwiftShimsModuleName ||
308308
Name.str() == SWIFT_ONONE_SUPPORT);
309309
}
310310

include/swift/Sema/CSFix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,7 @@ class UseWrappedValue final : public ConstraintFix {
13351335
PropertyWrapper(propertyWrapper), Base(base), Wrapper(wrapper) {}
13361336

13371337
bool usingProjection() const {
1338-
auto nameStr = PropertyWrapper->getName().str();
1339-
return !nameStr.startswith("_");
1338+
return !PropertyWrapper->getName().hasUnderscoredNaming();
13401339
}
13411340

13421341
public:

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ bool Decl::hasUnderscoredNaming() const {
10831083
}
10841084

10851085
if (!VD->getBaseName().isSpecial() &&
1086-
VD->getBaseIdentifier().str().startswith("_")) {
1086+
VD->getBaseIdentifier().hasUnderscoredNaming()) {
10871087
return true;
10881088
}
10891089

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ void ModuleDecl::findDeclaredCrossImportOverlaysTransitive(
22972297
for (Identifier overlay: overlays) {
22982298
// We don't present non-underscored overlays as part of the underlying
22992299
// module, so ignore them.
2300-
if (!overlay.str().startswith("_"))
2300+
if (!overlay.hasUnderscoredNaming())
23012301
continue;
23022302
ModuleDecl *overlayMod =
23032303
getASTContext().getModuleByName(overlay.str());

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ static void installPropertyWrapperMembersIfNeeded(NominalTypeDecl *target,
24202420
return;
24212421

24222422
if ((!baseName.getIdentifier().str().startswith("$") &&
2423-
!baseName.getIdentifier().str().startswith("_")) ||
2423+
!baseName.getIdentifier().hasUnderscoredNaming()) ||
24242424
baseName.getIdentifier().str().size() <= 1) {
24252425
return;
24262426
}

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class ModuleWriter {
834834
[&](const ValueDecl *vd) {
835835
return !printer.isVisible(vd) || vd->isObjC() ||
836836
(vd->isStdlibDecl() && !vd->getName().isSpecial() &&
837-
vd->getBaseIdentifier().str().startswith("_")) ||
837+
vd->getBaseIdentifier().hasUnderscoredNaming()) ||
838838
(vd->isStdlibDecl() && isa<StructDecl>(vd)) ||
839839
(vd->isStdlibDecl() &&
840840
vd->getASTContext().getErrorDecl() == vd);

0 commit comments

Comments
 (0)