Skip to content

Commit ece660f

Browse files
committed
Remove getName from ValueDecl
Push the getName method from ValueDecl down to only those types that are guaranteed to have a name that is backed by an identifier and that will not be special.
1 parent faa1720 commit ece660f

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.
@@ -2346,6 +2346,8 @@ class TypeDecl : public ValueDecl {
23462346
}
23472347

23482348
public:
2349+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
2350+
23492351
/// The type of this declaration's values. For the type of the
23502352
/// declaration itself, use getInterfaceType(), which returns a
23512353
/// metatype.
@@ -4335,6 +4337,8 @@ class VarDecl : public AbstractStorageDecl {
43354337

43364338
SourceRange getSourceRange() const;
43374339

4340+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4341+
43384342
TypeLoc &getTypeLoc() { return typeLoc; }
43394343
TypeLoc getTypeLoc() const { return typeLoc; }
43404344

@@ -4804,6 +4808,8 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
48044808
}
48054809

48064810
public:
4811+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4812+
48074813
/// \brief Should this declaration be treated as if annotated with transparent
48084814
/// attribute.
48094815
bool isTransparent() const;
@@ -5433,6 +5439,8 @@ class EnumElementDecl : public ValueDecl {
54335439
EnumElementDeclBits.HasArgumentType = HasArgumentType;
54345440
}
54355441

5442+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
5443+
54365444
/// \returns false if there was an error during the computation rendering the
54375445
/// EnumElementDecl invalid, true otherwise.
54385446
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
@@ -4931,7 +4931,7 @@ static bool diagnoseTupleParameterMismatch(CalleeCandidateInfo &CCI,
49314931
// Constructors/descructors and subscripts don't really have names.
49324932
if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
49334933
isa<SubscriptDecl>(decl))) {
4934-
name = decl->getName();
4934+
name = decl->getBaseName().getIdentifier();
49354935
}
49364936

49374937
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)