Skip to content

Commit 630d0f6

Browse files
authored
Merge pull request swiftlang#30606 from AnthonyLatsis/rename-getfullname
[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName
2 parents 1331ac5 + c63b737 commit 630d0f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+99
-97
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 10 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 Name.getBaseIdentifier();
2501+
}
2502+
24992503
/// Generates a DeclNameRef referring to this declaration with as much
25002504
/// specificity as possible.
25012505
DeclNameRef createNameRef() const {
@@ -2824,12 +2828,12 @@ class TypeDecl : public ValueDecl {
28242828
ValueDecl(K, context, name, NameLoc), Inherited(inherited) {}
28252829

28262830
public:
2827-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
2831+
Identifier getName() const { return getBaseIdentifier(); }
28282832

28292833
/// Returns the string for the base name, or "_" if this is unnamed.
28302834
StringRef getNameStr() const {
28312835
assert(!getFullName().isSpecial() && "Cannot get string for special names");
2832-
return hasName() ? getBaseName().getIdentifier().str() : "_";
2836+
return hasName() ? getBaseIdentifier().str() : "_";
28332837
}
28342838

28352839
/// The type of this declaration's values. For the type of the
@@ -4929,12 +4933,12 @@ class VarDecl : public AbstractStorageDecl {
49294933

49304934
SourceRange getSourceRange() const;
49314935

4932-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4936+
Identifier getName() const { return getBaseIdentifier(); }
49334937

49344938
/// Returns the string for the base name, or "_" if this is unnamed.
49354939
StringRef getNameStr() const {
49364940
assert(!getFullName().isSpecial() && "Cannot get string for special names");
4937-
return hasName() ? getBaseName().getIdentifier().str() : "_";
4941+
return hasName() ? getBaseIdentifier().str() : "_";
49384942
}
49394943

49404944
/// Get the type of the variable within its context. If the context is generic,
@@ -5909,7 +5913,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59095913
/// Returns the string for the base name, or "_" if this is unnamed.
59105914
StringRef getNameStr() const {
59115915
assert(!getFullName().isSpecial() && "Cannot get string for special names");
5912-
return hasName() ? getBaseName().getIdentifier().str() : "_";
5916+
return hasName() ? getBaseIdentifier().str() : "_";
59135917
}
59145918

59155919
/// Should this declaration be treated as if annotated with transparent
@@ -6257,8 +6261,6 @@ class FuncDecl : public AbstractFunctionDecl {
62576261
TypeLoc FnRetType, DeclContext *Parent,
62586262
ClangNode ClangN = ClangNode());
62596263

6260-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
6261-
62626264
bool isStatic() const;
62636265

62646266
/// \returns the way 'static'/'class' was spelled in the source.
@@ -6601,12 +6603,10 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
66016603
LiteralExpr *RawValueExpr,
66026604
DeclContext *DC);
66036605

6604-
Identifier getName() const { return getFullName().getBaseIdentifier(); }
6605-
66066606
/// Returns the string for the base name, or "_" if this is unnamed.
66076607
StringRef getNameStr() const {
66086608
assert(!getFullName().isSpecial() && "Cannot get string for special names");
6609-
return hasName() ? getBaseName().getIdentifier().str() : "_";
6609+
return hasName() ? getBaseIdentifier().str() : "_";
66106610
}
66116611

66126612
Type getArgumentInterfaceType() const;

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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ bool Decl::hasUnderscoredNaming() const {
760760
}
761761

762762
if (!VD->getBaseName().isSpecial() &&
763-
VD->getBaseName().getIdentifier().str().startswith("_")) {
763+
VD->getBaseIdentifier().str().startswith("_")) {
764764
return true;
765765
}
766766

@@ -3167,7 +3167,7 @@ bool ValueDecl::shouldHideFromEditor() const {
31673167

31683168
// '$__' names are reserved by compiler internal.
31693169
if (!getBaseName().isSpecial() &&
3170-
getBaseName().getIdentifier().str().startswith("$__"))
3170+
getBaseIdentifier().str().startswith("$__"))
31713171
return true;
31723172

31733173
return false;
@@ -3586,8 +3586,8 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
35863586
return result;
35873587
}
35883588

3589-
if (int result = type1->getBaseName().getIdentifier().str().compare(
3590-
type2->getBaseName().getIdentifier().str()))
3589+
if (int result = type1->getBaseIdentifier().str().compare(
3590+
type2->getBaseIdentifier().str()))
35913591
return result;
35923592

35933593
// Error case: two type declarations that cannot be distinguished.
@@ -6868,7 +6868,7 @@ AbstractFunctionDecl::getObjCSelector(DeclName preferredName,
68686868
return destructor->getObjCSelector();
68696869
} else if (auto func = dyn_cast<FuncDecl>(this)) {
68706870
// Otherwise cast this to be able to access getName()
6871-
baseNameStr = func->getName().str();
6871+
baseNameStr = func->getBaseIdentifier().str();
68726872
} else if (isa<ConstructorDecl>(this)) {
68736873
baseNameStr = "init";
68746874
} else {
@@ -7376,7 +7376,8 @@ SelfAccessKind FuncDecl::getSelfAccessKind() const {
73767376
}
73777377

73787378
bool FuncDecl::isCallAsFunctionMethod() const {
7379-
return getName() == getASTContext().Id_callAsFunction && isInstanceMember();
7379+
return getBaseIdentifier() == getASTContext().Id_callAsFunction &&
7380+
isInstanceMember();
73807381
}
73817382

73827383
ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
@@ -7873,7 +7874,7 @@ PrecedenceGroupDecl *InfixOperatorDecl::getPrecedenceGroup() const {
78737874
}
78747875

78757876
bool FuncDecl::isDeferBody() const {
7876-
return getName() == getASTContext().getIdentifier("$defer");
7877+
return getBaseIdentifier() == getASTContext().getIdentifier("$defer");
78777878
}
78787879

78797880
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
4949
return anonTypedef->getIdentifier()->getName();
5050
}
5151

52-
return VD->getBaseName().getIdentifier().str();
52+
return VD->getBaseIdentifier().str();
5353
}
5454

5555
std::string swift::objc_translation::
@@ -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/AST/USRGeneration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
225225

226226
auto ClangMacroInfo = ClangN.getAsMacro();
227227
bool Ignore = clang::index::generateUSRForMacro(
228-
D->getBaseName().getIdentifier().str(),
228+
D->getBaseIdentifier().str(),
229229
ClangMacroInfo->getDefinitionLoc(),
230230
Importer.getClangASTContext().getSourceManager(), Buffer);
231231
if (!Ignore)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ class DarwinLegacyFilterDeclConsumer : public swift::VisibleDeclConsumer {
24142414
if (clangModule->Name == "MacTypes") {
24152415
if (!VD->hasName() || VD->getBaseName().isSpecial())
24162416
return true;
2417-
return llvm::StringSwitch<bool>(VD->getBaseName().getIdentifier().str())
2417+
return llvm::StringSwitch<bool>(VD->getBaseIdentifier().str())
24182418
.Cases("OSErr", "OSStatus", "OptionBits", false)
24192419
.Cases("FourCharCode", "OSType", false)
24202420
.Case("Boolean", false)

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,7 @@ namespace {
32023202
// context.
32033203
if (errorWrapper) {
32043204
auto enumeratorValue = cast<ValueDecl>(enumeratorDecl);
3205-
auto name = enumeratorValue->getBaseName().getIdentifier();
3205+
auto name = enumeratorValue->getBaseIdentifier();
32063206
auto alias = importEnumCaseAlias(name,
32073207
constant,
32083208
enumeratorValue,

lib/FrontendTool/ReferenceDependencies.cpp

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

0 commit comments

Comments
 (0)