Skip to content

[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName #30606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,10 @@ class ValueDecl : public Decl {
/// names.
DeclBaseName getBaseName() const { return Name.getBaseName(); }

Identifier getBaseIdentifier() const {
return Name.getBaseIdentifier();
}

/// Generates a DeclNameRef referring to this declaration with as much
/// specificity as possible.
DeclNameRef createNameRef() const {
Expand Down Expand Up @@ -2824,12 +2828,12 @@ class TypeDecl : public ValueDecl {
ValueDecl(K, context, name, NameLoc), Inherited(inherited) {}

public:
Identifier getName() const { return getFullName().getBaseIdentifier(); }
Identifier getName() const { return getBaseIdentifier(); }

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

/// The type of this declaration's values. For the type of the
Expand Down Expand Up @@ -4911,12 +4915,12 @@ class VarDecl : public AbstractStorageDecl {

SourceRange getSourceRange() const;

Identifier getName() const { return getFullName().getBaseIdentifier(); }
Identifier getName() const { return getBaseIdentifier(); }

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

/// Get the type of the variable within its context. If the context is generic,
Expand Down Expand Up @@ -5891,7 +5895,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
assert(!getFullName().isSpecial() && "Cannot get string for special names");
return hasName() ? getBaseName().getIdentifier().str() : "_";
return hasName() ? getBaseIdentifier().str() : "_";
}

/// Should this declaration be treated as if annotated with transparent
Expand Down Expand Up @@ -6239,8 +6243,6 @@ class FuncDecl : public AbstractFunctionDecl {
TypeLoc FnRetType, DeclContext *Parent,
ClangNode ClangN = ClangNode());

Identifier getName() const { return getFullName().getBaseIdentifier(); }

bool isStatic() const;

/// \returns the way 'static'/'class' was spelled in the source.
Expand Down Expand Up @@ -6583,12 +6585,10 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
LiteralExpr *RawValueExpr,
DeclContext *DC);

Identifier getName() const { return getFullName().getBaseIdentifier(); }

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

Type getArgumentInterfaceType() const;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
}
void visitEnumIsCaseExpr(EnumIsCaseExpr *E) {
printCommon(E, "enum_is_case_expr") << ' ' <<
E->getEnumElement()->getName() << "\n";
E->getEnumElement()->getBaseIdentifier() << "\n";
printRec(E->getSubExpr());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2876,7 +2876,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
if (!decl->hasName()) {
Printer << "<anonymous>";
} else {
Printer.printName(decl->getName(),
Printer.printName(decl->getBaseIdentifier(),
getTypeMemberPrintNameContext(decl));
if (decl->isOperator())
Printer << " ";
Expand Down Expand Up @@ -2949,7 +2949,8 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
void PrintAST::printEnumElement(EnumElementDecl *elt) {
recordDeclLoc(elt,
[&]{
Printer.printName(elt->getName(), getTypeMemberPrintNameContext(elt));
Printer.printName(elt->getBaseIdentifier(),
getTypeMemberPrintNameContext(elt));
});

if (auto *PL = elt->getParameterList()) {
Expand Down
15 changes: 8 additions & 7 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ bool Decl::hasUnderscoredNaming() const {
}

if (!VD->getBaseName().isSpecial() &&
VD->getBaseName().getIdentifier().str().startswith("_")) {
VD->getBaseIdentifier().str().startswith("_")) {
return true;
}

Expand Down Expand Up @@ -3167,7 +3167,7 @@ bool ValueDecl::shouldHideFromEditor() const {

// '$__' names are reserved by compiler internal.
if (!getBaseName().isSpecial() &&
getBaseName().getIdentifier().str().startswith("$__"))
getBaseIdentifier().str().startswith("$__"))
return true;

return false;
Expand Down Expand Up @@ -3586,8 +3586,8 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
return result;
}

if (int result = type1->getBaseName().getIdentifier().str().compare(
type2->getBaseName().getIdentifier().str()))
if (int result = type1->getBaseIdentifier().str().compare(
type2->getBaseIdentifier().str()))
return result;

// Error case: two type declarations that cannot be distinguished.
Expand Down Expand Up @@ -6833,7 +6833,7 @@ AbstractFunctionDecl::getObjCSelector(DeclName preferredName,
return destructor->getObjCSelector();
} else if (auto func = dyn_cast<FuncDecl>(this)) {
// Otherwise cast this to be able to access getName()
baseNameStr = func->getName().str();
baseNameStr = func->getBaseIdentifier().str();
} else if (isa<ConstructorDecl>(this)) {
baseNameStr = "init";
} else {
Expand Down Expand Up @@ -7341,7 +7341,8 @@ SelfAccessKind FuncDecl::getSelfAccessKind() const {
}

bool FuncDecl::isCallAsFunctionMethod() const {
return getName() == getASTContext().Id_callAsFunction && isInstanceMember();
return getBaseIdentifier() == getASTContext().Id_callAsFunction &&
isInstanceMember();
}

ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
Expand Down Expand Up @@ -7838,7 +7839,7 @@ PrecedenceGroupDecl *InfixOperatorDecl::getPrecedenceGroup() const {
}

bool FuncDecl::isDeferBody() const {
return getName() == getASTContext().getIdentifier("$defer");
return getBaseIdentifier() == getASTContext().getIdentifier("$defer");
}

bool FuncDecl::isPotentialIBActionTarget() const {
Expand Down
12 changes: 4 additions & 8 deletions lib/AST/FrontendSourceFileDepGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ template <typename DeclT> static std::string getBaseName(const DeclT *decl) {
return decl->getBaseName().userFacingName().str();
}

template <typename DeclT> static std::string getName(const DeclT *decl) {
return DeclBaseName(decl->getName()).userFacingName().str();
}

static std::string mangleTypeAsContext(const NominalTypeDecl *NTD) {
Mangle::ASTMangler Mangler;
return !NTD ? "" : Mangler.mangleTypeAsContextUSR(NTD);
Expand Down Expand Up @@ -188,22 +184,22 @@ std::string
DependencyKey::computeNameForProvidedEntity<NodeKind::topLevel,
PrecedenceGroupDecl const *>(
const PrecedenceGroupDecl *D) {
return ::getName(D);
return D->getName().str().str();
}
template <>
std::string DependencyKey::computeNameForProvidedEntity<
NodeKind::topLevel, FuncDecl const *>(const FuncDecl *D) {
return ::getName(D);
return getBaseName(D);
}
template <>
std::string DependencyKey::computeNameForProvidedEntity<
NodeKind::topLevel, OperatorDecl const *>(const OperatorDecl *D) {
return ::getName(D);
return D->getName().str().str();
}
template <>
std::string DependencyKey::computeNameForProvidedEntity<
NodeKind::topLevel, NominalTypeDecl const *>(const NominalTypeDecl *D) {
return ::getName(D);
return D->getName().str().str();
}
template <>
std::string DependencyKey::computeNameForProvidedEntity<
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
return anonTypedef->getIdentifier()->getName();
}

return VD->getBaseName().getIdentifier().str();
return VD->getBaseIdentifier().str();
}

std::string swift::objc_translation::
Expand Down Expand Up @@ -90,7 +90,7 @@ printSwiftEnumElemNameInObjC(const EnumElementDecl *EL, llvm::raw_ostream &OS,
}
OS << getNameForObjC(EL->getDeclContext()->getSelfEnumDecl());
if (PreferredName.empty())
ElemName = EL->getName().str();
ElemName = EL->getBaseIdentifier().str();
else
ElemName = PreferredName.str();

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,

auto ClangMacroInfo = ClangN.getAsMacro();
bool Ignore = clang::index::generateUSRForMacro(
D->getBaseName().getIdentifier().str(),
D->getBaseIdentifier().str(),
ClangMacroInfo->getDefinitionLoc(),
Importer.getClangASTContext().getSourceManager(), Buffer);
if (!Ignore)
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ class DarwinLegacyFilterDeclConsumer : public swift::VisibleDeclConsumer {
if (clangModule->Name == "MacTypes") {
if (!VD->hasName() || VD->getBaseName().isSpecial())
return true;
return llvm::StringSwitch<bool>(VD->getBaseName().getIdentifier().str())
return llvm::StringSwitch<bool>(VD->getBaseIdentifier().str())
.Cases("OSErr", "OSStatus", "OptionBits", false)
.Cases("FourCharCode", "OSType", false)
.Case("Boolean", false)
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ namespace {
// context.
if (errorWrapper) {
auto enumeratorValue = cast<ValueDecl>(enumeratorDecl);
auto name = enumeratorValue->getBaseName().getIdentifier();
auto name = enumeratorValue->getBaseIdentifier();
auto alias = importEnumCaseAlias(name,
constant,
enumeratorValue,
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/ReferenceDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ ProvidesEmitter::emitTopLevelNames() const {
for (const Decl *D : SF->getTopLevelDecls())
emitTopLevelDecl(D, cpd);
for (auto *operatorFunction : cpd.memberOperatorDecls)
out << "- \"" << escape(operatorFunction->getName()) << "\"\n";
out << "- \"" << escape(operatorFunction->getBaseIdentifier()) << "\"\n";
return cpd;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
VD->shouldHideFromEditor())
return;

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

CommandWordsPairs Pairs;
Expand Down Expand Up @@ -2576,11 +2576,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

void addMethodCall(const FuncDecl *FD, DeclVisibilityKind Reason,
DynamicLookupInfo dynamicLookupInfo) {
if (FD->getName().empty())
if (FD->getBaseIdentifier().empty())
return;
foundFunction(FD);

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

Type FunctionType = getTypeOfMember(FD, dynamicLookupInfo);
Expand Down Expand Up @@ -2944,7 +2944,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
setAssociatedDecl(EED, Builder);
setClangDeclKeywords(EED, Pairs, Builder);
addLeadingDot(Builder);
addValueBaseName(Builder, EED->getName());
addValueBaseName(Builder, EED->getBaseIdentifier());

// Enum element is of function type; (Self.type) -> Self or
// (Self.Type) -> (Args...) -> Self.
Expand Down
5 changes: 3 additions & 2 deletions lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ isApplicable(ResolvedRangeInfo Info, DiagnosticEngine &Diag) {
}

bool checkName(FuncDecl *FD) {
auto Name = FD->getName().str();
const auto Name = FD->getBaseIdentifier().str();
return Name == "~="
|| Name == "=="
|| Name == "__derived_enum_equals"
Expand Down Expand Up @@ -2391,7 +2391,8 @@ bool RefactoringActionConvertToSwitchStmt::performChange() {
bool isFunctionNameAllowed(BinaryExpr *E) {
auto FunctionBody = dyn_cast<DotSyntaxCallExpr>(E->getFn())->getFn();
auto FunctionDeclaration = dyn_cast<DeclRefExpr>(FunctionBody)->getDecl();
auto FunctionName = dyn_cast<FuncDecl>(FunctionDeclaration)->getName().str();
const auto FunctionName = dyn_cast<FuncDecl>(FunctionDeclaration)
->getBaseIdentifier().str();
return FunctionName == "~="
|| FunctionName == "=="
|| FunctionName == "__derived_enum_equals"
Expand Down
5 changes: 3 additions & 2 deletions lib/IDE/SyntaxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
// as members of the enum case decl. Walk them manually here so that they
// end up as child nodes of enum case.
for (auto *EnumElemD : EnumCaseD->getElements()) {
if (EnumElemD->getName().empty())
if (EnumElemD->getBaseIdentifier().empty())
continue;
SyntaxStructureNode SN;
setDecl(SN, EnumElemD);
Expand All @@ -1060,7 +1060,8 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
SN.NameRange = charSourceRangeFromSourceRange(SM, NameRange);
} else {
SN.NameRange = CharSourceRange(EnumElemD->getNameLoc(),
EnumElemD->getName().getLength());
EnumElemD->getBaseIdentifier()
.getLength());
}

if (auto *E = EnumElemD->getRawValueUnchecked()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6917,7 +6917,7 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type,
auto bitPattern = strategy->getBitPatternForNoPayloadElement(elt.decl);
assert(bitPattern.size() == fixedTI->getFixedSize().getValueInBits());
LLVM_DEBUG(llvm::dbgs() << " no-payload case "
<< elt.decl->getName().str()
<< elt.decl->getBaseIdentifier().str()
<< ":\t";
displayBitMask(bitPattern));

Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
}

if (IGM.IRGen.Opts.EnableReflectionNames) {
auto name = value->getBaseName().getIdentifier().str();
auto name = value->getBaseIdentifier().str();
auto fieldName = IGM.getAddrOfFieldName(name);
B.addRelativeAddress(fieldName);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
}

if (FD.hasName())
return FD.getName().str();
return FD.getBaseIdentifier().str();

return StringRef();
}
Expand Down Expand Up @@ -947,8 +947,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
Alignment(1), true, false);
}
unsigned Offset = 0;
auto MTy = createMemberType(ElemDbgTy, ElemDecl->getName().str(), Offset,
Scope, File, Flags);
auto MTy = createMemberType(ElemDbgTy, ElemDecl->getBaseIdentifier().str(),
Offset, Scope, File, Flags);
Elements.push_back(MTy);
}
return DBuilder.getOrCreateArray(Elements);
Expand Down
2 changes: 1 addition & 1 deletion lib/Index/IndexSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static bool isUnitTest(const ValueDecl *D) {
return false;

// 6. ...and starts with "test".
if (FD->getName().str().startswith("test"))
if (FD->getBaseIdentifier().str().startswith("test"))
return true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
for (auto *D: TopDecls) {
if (auto *FD = dyn_cast<FuncDecl>(D)) {
InsertedFunctions.insert(
std::string(FD->getBaseName().getIdentifier()));
std::string(FD->getBaseIdentifier()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ void Parser::setLocalDiscriminator(ValueDecl *D) {
if (!getScopeInfo().isInactiveConfigBlock())
SF.LocalTypeDecls.insert(TD);

Identifier name = D->getBaseName().getIdentifier();
const Identifier name = D->getBaseIdentifier();
unsigned discriminator = CurLocalContext->claimNextNamedDiscriminator(name);
D->setLocalDiscriminator(discriminator);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PrintAsObjC/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class DeclAndTypePrinter::Implementation
// name.
os << " ";
if (printSwiftEnumElemNameInObjC(Elt, os)) {
os << " SWIFT_COMPILE_NAME(\"" << Elt->getName() << "\")";
os << " SWIFT_COMPILE_NAME(\"" << Elt->getBaseIdentifier() << "\")";
}

// Print the raw values, even the ones that we synthesize.
Expand Down
Loading