Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#56350 - Give Identifier a hasUnderscoredNaming() helper #72048

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class Identifier {
return str().startswith("$") && !(getLength() == 1);
}

bool hasUnderscoredNaming() const {
return str().startswith("_");
}

const void *getAsOpaquePointer() const {
return static_cast<const void *>(Pointer);
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/IDE/CompletionLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
void includeInstanceMembers() { IncludeInstanceMembers = true; }

bool isHiddenModuleName(Identifier Name) {
return (Name.str().startswith("_") || Name == Ctx.SwiftShimsModuleName ||
return (Name.hasUnderscoredNaming() || Name == Ctx.SwiftShimsModuleName ||
Name.str() == SWIFT_ONONE_SUPPORT);
}

Expand Down
3 changes: 1 addition & 2 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,7 @@ class UseWrappedValue final : public ConstraintFix {
PropertyWrapper(propertyWrapper), Base(base), Wrapper(wrapper) {}

bool usingProjection() const {
auto nameStr = PropertyWrapper->getName().str();
return !nameStr.startswith("_");
return !PropertyWrapper->getName().hasUnderscoredNaming();
}

public:
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ bool Decl::hasUnderscoredNaming() const {
}

if (!VD->getBaseName().isSpecial() &&
VD->getBaseIdentifier().str().startswith("_")) {
VD->getBaseIdentifier().hasUnderscoredNaming()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ void ModuleDecl::findDeclaredCrossImportOverlaysTransitive(
for (Identifier overlay: overlays) {
// We don't present non-underscored overlays as part of the underlying
// module, so ignore them.
if (!overlay.str().startswith("_"))
if (!overlay.hasUnderscoredNaming())
continue;
ModuleDecl *overlayMod =
getASTContext().getModuleByName(overlay.str());
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2422,7 +2422,7 @@ static void installPropertyWrapperMembersIfNeeded(NominalTypeDecl *target,
return;

if ((!baseName.getIdentifier().str().startswith("$") &&
!baseName.getIdentifier().str().startswith("_")) ||
!baseName.getIdentifier().hasUnderscoredNaming()) ||
baseName.getIdentifier().str().size() <= 1) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PrintAsClang/ModuleContentsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ class ModuleWriter {
[&](const ValueDecl *vd) {
return !printer.isVisible(vd) || vd->isObjC() ||
(vd->isStdlibDecl() && !vd->getName().isSpecial() &&
vd->getBaseIdentifier().str().startswith("_")) ||
vd->getBaseIdentifier().hasUnderscoredNaming()) ||
(vd->isStdlibDecl() && isa<StructDecl>(vd)) ||
(vd->isStdlibDecl() &&
vd->getASTContext().getErrorDecl() == vd);
Expand Down