Skip to content

Commit 7e0fa80

Browse files
committed
[Misc] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on `ValueDecl` will be removed and pushed down to nominal declarations whose name is guaranteed not to be special. Prepare for this by calling to `DeclBaseName getBaseName()` instead where appropriate.
1 parent 40a0d31 commit 7e0fa80

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,8 +2581,9 @@ class ModuleWriter {
25812581
assert(*lhs != *rhs && "duplicate top-level decl");
25822582

25832583
auto getSortName = [](const Decl *D) -> StringRef {
2584+
// TODO: Handle special names
25842585
if (auto VD = dyn_cast<ValueDecl>(D))
2585-
return VD->getName().str();
2586+
return VD->getBaseName().getIdentifier().str();
25862587

25872588
if (auto ED = dyn_cast<ExtensionDecl>(D)) {
25882589
auto baseClass = ED->getExtendedType()->getClassOrBoundGenericClass();

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ class SemanticAnnotator : public SourceEntityWalker {
786786
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
787787
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef, Type T,
788788
ReferenceMetaData Data) override {
789-
if (isa<VarDecl>(D) && D->hasName() && D->getName().str() == "self")
789+
if (isa<VarDecl>(D) && D->hasName() &&
790+
D->getFullName() == D->getASTContext().Id_self)
790791
return true;
791792

792793
// Do not annotate references to unavailable decls.

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
465465
// For now we use UnqualifiedLookup to fetch other declarations with the same
466466
// base name.
467467
auto TypeResolver = VD->getASTContext().getLazyResolver();
468-
UnqualifiedLookup Lookup(VD->getName(), VD->getDeclContext(), TypeResolver);
468+
UnqualifiedLookup Lookup(VD->getBaseName(), VD->getDeclContext(),
469+
TypeResolver);
469470
for (auto result : Lookup.Results) {
470471
ValueDecl *RelatedVD = result.getValueDecl();
471472
if (RelatedVD->getAttrs().isUnavailable(VD->getASTContext()))
@@ -941,9 +942,9 @@ static DeclName getSwiftDeclName(const ValueDecl *VD,
941942
auto &Ctx = VD->getDeclContext()->getASTContext();
942943
assert(SwiftLangSupport::getNameKindForUID(Info.NameKind) == NameKind::Swift);
943944
DeclName OrigName = VD->getFullName();
944-
Identifier BaseName = Info.BaseName.empty()
945-
? OrigName.getBaseName()
946-
: Ctx.getIdentifier(Info.BaseName);
945+
DeclBaseName BaseName = Info.BaseName.empty()
946+
? OrigName.getBaseName()
947+
: Ctx.getIdentifier(Info.BaseName);
947948
auto OrigArgs = OrigName.getArgumentNames();
948949
SmallVector<Identifier, 8> Args(OrigArgs.begin(), OrigArgs.end());
949950
if (Info.ArgNames.size() > OrigArgs.size())

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,9 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty) :
10551055
TypeAttrs.push_back(TypeAttrKind::TAK_noescape);
10561056
}
10571057

1058+
// TODO: Handle special names
10581059
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD) : Ctx(Ctx),
1059-
Name(VD->hasName() ? VD->getName().str() : Ctx.buffer("_")),
1060+
Name(VD->hasName() ? VD->getBaseName().getIdentifier().str() : Ctx.buffer("_")),
10601061
PrintedName(getPrintedName(Ctx, VD)), DKind(VD->getKind()),
10611062
USR(calculateUsr(Ctx, VD)), Location(calculateLocation(Ctx, VD)),
10621063
ModuleName(VD->getModuleContext()->getName().str()),
@@ -1165,7 +1166,7 @@ static bool shouldIgnore(Decl *D) {
11651166
if (auto VD = dyn_cast<ValueDecl>(D)) {
11661167
if (VD->isOperator())
11671168
return true;
1168-
if (VD->getName().empty())
1169+
if (VD->getBaseName().empty())
11691170
return true;
11701171
switch (VD->getFormalAccess()) {
11711172
case Accessibility::Internal:

0 commit comments

Comments
 (0)