Skip to content

Commit 5cda94b

Browse files
authored
Merge pull request #9977 from ahoppen/pdm-remove-get-name
Remove getName method from ValueDecl
2 parents fc81cd0 + 2078ec6 commit 5cda94b

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

include/swift/AST/Decl.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,13 +2121,13 @@ class ValueDecl : public Decl {
21212121
}
21222122

21232123
bool hasName() const { return bool(Name); }
2124-
/// TODO: Rename to getSimpleName?
2125-
Identifier getName() const { return Name.getBaseName(); }
21262124
bool isOperator() const { return Name.isOperator(); }
21272125

21282126
/// Returns the string for the base name, or "_" if this is unnamed.
21292127
StringRef getNameStr() const {
2130-
return hasName() ? getName().str() : "_";
2128+
// TODO: Check if this function is called for special names
2129+
assert(!Name.isSpecial() && "Cannot get string for special names");
2130+
return hasName() ? Name.getBaseName().getIdentifier().str() : "_";
21312131
}
21322132

21332133
/// Retrieve the full name of the declaration.
@@ -2356,6 +2356,8 @@ class TypeDecl : public ValueDecl {
23562356
}
23572357

23582358
public:
2359+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
2360+
23592361
/// The type of this declaration's values. For the type of the
23602362
/// declaration itself, use getInterfaceType(), which returns a
23612363
/// metatype.
@@ -4348,6 +4350,8 @@ class VarDecl : public AbstractStorageDecl {
43484350

43494351
SourceRange getSourceRange() const;
43504352

4353+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4354+
43514355
TypeLoc &getTypeLoc() { return typeLoc; }
43524356
TypeLoc getTypeLoc() const { return typeLoc; }
43534357

@@ -4817,6 +4821,8 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
48174821
}
48184822

48194823
public:
4824+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4825+
48204826
/// \brief Should this declaration be treated as if annotated with transparent
48214827
/// attribute.
48224828
bool isTransparent() const;
@@ -5446,6 +5452,8 @@ class EnumElementDecl : public ValueDecl {
54465452
EnumElementDeclBits.HasArgumentType = HasArgumentType;
54475453
}
54485454

5455+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
5456+
54495457
/// \returns false if there was an error during the computation rendering the
54505458
/// EnumElementDecl invalid, true otherwise.
54515459
bool computeType();

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
400400
}
401401

402402
SmallVector<char, 64> Buf;
403-
StringRef Name = (VD->getName().str() + Twine(Kind)).toStringRef(Buf);
403+
// TODO: Handle special names
404+
StringRef Name = (VD->getBaseName().getIdentifier().str() +
405+
Twine(Kind)).toStringRef(Buf);
404406
return BumpAllocatedString(Name);
405407
}
406408

lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void Parser::diagnoseRedefinition(ValueDecl *Prev, ValueDecl *New) {
770770
assert(New != Prev && "Cannot conflict with self");
771771
diagnose(New->getLoc(), diag::decl_redefinition, New->isDefinition());
772772
diagnose(Prev->getLoc(), diag::previous_decldef, Prev->isDefinition(),
773-
Prev->getName());
773+
Prev->getBaseName());
774774
}
775775

776776
struct ParserUnit::Implementation {

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4950,7 +4950,7 @@ static bool diagnoseTupleParameterMismatch(CalleeCandidateInfo &CCI,
49504950
// Constructors/descructors and subscripts don't really have names.
49514951
if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
49524952
isa<SubscriptDecl>(decl))) {
4953-
name = decl->getName();
4953+
name = decl->getBaseName().getIdentifier();
49544954
}
49554955

49564956
TC.diagnose(argExpr->getLoc(), diag::single_tuple_parameter_mismatch,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ bool WitnessChecker::findBestWitness(
13911391

13921392
auto lookupOptions = defaultUnqualifiedLookupOptions;
13931393
lookupOptions |= NameLookupFlags::KnownPrivate;
1394-
auto lookup = TC.lookupUnqualified(overlay, requirement->getName(),
1394+
auto lookup = TC.lookupUnqualified(overlay, requirement->getBaseName(),
13951395
SourceLoc(), lookupOptions);
13961396
for (auto candidate : lookup)
13971397
witnesses.push_back(candidate.Decl);

0 commit comments

Comments
 (0)