Skip to content

Commit d0ae3ee

Browse files
committed
[AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier
1 parent f724d1f commit d0ae3ee

25 files changed

+56
-54
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,10 @@ class ValueDecl : public Decl {
24962496
/// names.
24972497
DeclBaseName getBaseName() const { return Name.getBaseName(); }
24982498

2499+
Identifier getBaseIdentifier() const {
2500+
return getFullName().getBaseIdentifier();
2501+
}
2502+
24992503
/// Generates a DeclNameRef referring to this declaration with as much
25002504
/// specificity as possible.
25012505
DeclNameRef createNameRef() const {
@@ -6239,8 +6243,6 @@ class FuncDecl : public AbstractFunctionDecl {
62396243
TypeLoc FnRetType, DeclContext *Parent,
62406244
ClangNode ClangN = ClangNode());
62416245

6242-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
6243-
62446246
bool isStatic() const;
62456247

62466248
/// \returns the way 'static'/'class' was spelled in the source.
@@ -6583,8 +6585,6 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
65836585
LiteralExpr *RawValueExpr,
65846586
DeclContext *DC);
65856587

6586-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
6587-
65886588
/// Returns the string for the base name, or "_" if this is unnamed.
65896589
StringRef getNameStr() const {
65906590
assert(!getFullName().isSpecial() && "Cannot get string for special names");

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
26132613
}
26142614
void visitEnumIsCaseExpr(EnumIsCaseExpr *E) {
26152615
printCommon(E, "enum_is_case_expr") << ' ' <<
2616-
E->getEnumElement()->getName() << "\n";
2616+
E->getEnumElement()->getBaseIdentifier() << "\n";
26172617
printRec(E->getSubExpr());
26182618
PrintWithColorRAII(OS, ParenthesisColor) << ')';
26192619
}

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
28762876
if (!decl->hasName()) {
28772877
Printer << "<anonymous>";
28782878
} else {
2879-
Printer.printName(decl->getName(),
2879+
Printer.printName(decl->getBaseIdentifier(),
28802880
getTypeMemberPrintNameContext(decl));
28812881
if (decl->isOperator())
28822882
Printer << " ";
@@ -2949,7 +2949,8 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
29492949
void PrintAST::printEnumElement(EnumElementDecl *elt) {
29502950
recordDeclLoc(elt,
29512951
[&]{
2952-
Printer.printName(elt->getName(), getTypeMemberPrintNameContext(elt));
2952+
Printer.printName(elt->getBaseIdentifier(),
2953+
getTypeMemberPrintNameContext(elt));
29532954
});
29542955

29552956
if (auto *PL = elt->getParameterList()) {

lib/AST/Decl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6833,7 +6833,7 @@ AbstractFunctionDecl::getObjCSelector(DeclName preferredName,
68336833
return destructor->getObjCSelector();
68346834
} else if (auto func = dyn_cast<FuncDecl>(this)) {
68356835
// Otherwise cast this to be able to access getName()
6836-
baseNameStr = func->getName().str();
6836+
baseNameStr = func->getBaseIdentifier().str();
68376837
} else if (isa<ConstructorDecl>(this)) {
68386838
baseNameStr = "init";
68396839
} else {
@@ -7341,7 +7341,8 @@ SelfAccessKind FuncDecl::getSelfAccessKind() const {
73417341
}
73427342

73437343
bool FuncDecl::isCallAsFunctionMethod() const {
7344-
return getName() == getASTContext().Id_callAsFunction && isInstanceMember();
7344+
return getBaseIdentifier() == getASTContext().Id_callAsFunction &&
7345+
isInstanceMember();
73457346
}
73467347

73477348
ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
@@ -7838,7 +7839,7 @@ PrecedenceGroupDecl *InfixOperatorDecl::getPrecedenceGroup() const {
78387839
}
78397840

78407841
bool FuncDecl::isDeferBody() const {
7841-
return getName() == getASTContext().getIdentifier("$defer");
7842+
return getBaseIdentifier() == getASTContext().getIdentifier("$defer");
78427843
}
78437844

78447845
bool FuncDecl::isPotentialIBActionTarget() const {

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ template <typename DeclT> static std::string getBaseName(const DeclT *decl) {
5959
return decl->getBaseName().userFacingName().str();
6060
}
6161

62-
template <typename DeclT> static std::string getName(const DeclT *decl) {
63-
return DeclBaseName(decl->getName()).userFacingName().str();
64-
}
65-
6662
static std::string mangleTypeAsContext(const NominalTypeDecl *NTD) {
6763
Mangle::ASTMangler Mangler;
6864
return !NTD ? "" : Mangler.mangleTypeAsContextUSR(NTD);
@@ -188,22 +184,22 @@ std::string
188184
DependencyKey::computeNameForProvidedEntity<NodeKind::topLevel,
189185
PrecedenceGroupDecl const *>(
190186
const PrecedenceGroupDecl *D) {
191-
return ::getName(D);
187+
return D->getName().str().str();
192188
}
193189
template <>
194190
std::string DependencyKey::computeNameForProvidedEntity<
195191
NodeKind::topLevel, FuncDecl const *>(const FuncDecl *D) {
196-
return ::getName(D);
192+
return getBaseName(D);
197193
}
198194
template <>
199195
std::string DependencyKey::computeNameForProvidedEntity<
200196
NodeKind::topLevel, OperatorDecl const *>(const OperatorDecl *D) {
201-
return ::getName(D);
197+
return D->getName().str().str();
202198
}
203199
template <>
204200
std::string DependencyKey::computeNameForProvidedEntity<
205201
NodeKind::topLevel, NominalTypeDecl const *>(const NominalTypeDecl *D) {
206-
return ::getName(D);
202+
return D->getName().str().str();
207203
}
208204
template <>
209205
std::string DependencyKey::computeNameForProvidedEntity<

lib/AST/SwiftNameTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ printSwiftEnumElemNameInObjC(const EnumElementDecl *EL, llvm::raw_ostream &OS,
9090
}
9191
OS << getNameForObjC(EL->getDeclContext()->getSelfEnumDecl());
9292
if (PreferredName.empty())
93-
ElemName = EL->getName().str();
93+
ElemName = EL->getBaseIdentifier().str();
9494
else
9595
ElemName = PreferredName.str();
9696

lib/FrontendTool/ReferenceDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ ProvidesEmitter::emitTopLevelNames() const {
254254
for (const Decl *D : SF->getTopLevelDecls())
255255
emitTopLevelDecl(D, cpd);
256256
for (auto *operatorFunction : cpd.memberOperatorDecls)
257-
out << "- \"" << escape(operatorFunction->getName()) << "\"\n";
257+
out << "- \"" << escape(operatorFunction->getBaseIdentifier()) << "\"\n";
258258
return cpd;
259259
}
260260

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21772177
VD->shouldHideFromEditor())
21782178
return;
21792179

2180-
Identifier Name = VD->getName();
2180+
const Identifier Name = VD->getName();
21812181
assert(!Name.empty() && "name should not be empty");
21822182

21832183
CommandWordsPairs Pairs;
@@ -2576,11 +2576,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25762576

25772577
void addMethodCall(const FuncDecl *FD, DeclVisibilityKind Reason,
25782578
DynamicLookupInfo dynamicLookupInfo) {
2579-
if (FD->getName().empty())
2579+
if (FD->getBaseIdentifier().empty())
25802580
return;
25812581
foundFunction(FD);
25822582

2583-
Identifier Name = FD->getName();
2583+
const Identifier Name = FD->getBaseIdentifier();
25842584
assert(!Name.empty() && "name should not be empty");
25852585

25862586
Type FunctionType = getTypeOfMember(FD, dynamicLookupInfo);
@@ -2944,7 +2944,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29442944
setAssociatedDecl(EED, Builder);
29452945
setClangDeclKeywords(EED, Pairs, Builder);
29462946
addLeadingDot(Builder);
2947-
addValueBaseName(Builder, EED->getName());
2947+
addValueBaseName(Builder, EED->getBaseIdentifier());
29482948

29492949
// Enum element is of function type; (Self.type) -> Self or
29502950
// (Self.Type) -> (Args...) -> Self.

lib/IDE/Refactoring.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ isApplicable(ResolvedRangeInfo Info, DiagnosticEngine &Diag) {
22782278
}
22792279

22802280
bool checkName(FuncDecl *FD) {
2281-
auto Name = FD->getName().str();
2281+
const auto Name = FD->getBaseIdentifier().str();
22822282
return Name == "~="
22832283
|| Name == "=="
22842284
|| Name == "__derived_enum_equals"
@@ -2391,7 +2391,8 @@ bool RefactoringActionConvertToSwitchStmt::performChange() {
23912391
bool isFunctionNameAllowed(BinaryExpr *E) {
23922392
auto FunctionBody = dyn_cast<DotSyntaxCallExpr>(E->getFn())->getFn();
23932393
auto FunctionDeclaration = dyn_cast<DeclRefExpr>(FunctionBody)->getDecl();
2394-
auto FunctionName = dyn_cast<FuncDecl>(FunctionDeclaration)->getName().str();
2394+
const auto FunctionName = dyn_cast<FuncDecl>(FunctionDeclaration)
2395+
->getBaseIdentifier().str();
23952396
return FunctionName == "~="
23962397
|| FunctionName == "=="
23972398
|| FunctionName == "__derived_enum_equals"

lib/IDE/SyntaxModel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
10471047
// as members of the enum case decl. Walk them manually here so that they
10481048
// end up as child nodes of enum case.
10491049
for (auto *EnumElemD : EnumCaseD->getElements()) {
1050-
if (EnumElemD->getName().empty())
1050+
if (EnumElemD->getBaseIdentifier().empty())
10511051
continue;
10521052
SyntaxStructureNode SN;
10531053
setDecl(SN, EnumElemD);
@@ -1060,7 +1060,8 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
10601060
SN.NameRange = charSourceRangeFromSourceRange(SM, NameRange);
10611061
} else {
10621062
SN.NameRange = CharSourceRange(EnumElemD->getNameLoc(),
1063-
EnumElemD->getName().getLength());
1063+
EnumElemD->getBaseIdentifier()
1064+
.getLength());
10641065
}
10651066

10661067
if (auto *E = EnumElemD->getRawValueUnchecked()) {

0 commit comments

Comments
 (0)