Skip to content

Remove getName method from ValueDecl #9977

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 1 commit into from
Jun 17, 2017
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
14 changes: 11 additions & 3 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2121,13 +2121,13 @@ class ValueDecl : public Decl {
}

bool hasName() const { return bool(Name); }
/// TODO: Rename to getSimpleName?
Identifier getName() const { return Name.getBaseName(); }
bool isOperator() const { return Name.isOperator(); }

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

/// Retrieve the full name of the declaration.
Expand Down Expand Up @@ -2356,6 +2356,8 @@ class TypeDecl : public ValueDecl {
}

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

/// The type of this declaration's values. For the type of the
/// declaration itself, use getInterfaceType(), which returns a
/// metatype.
Expand Down Expand Up @@ -4348,6 +4350,8 @@ class VarDecl : public AbstractStorageDecl {

SourceRange getSourceRange() const;

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

TypeLoc &getTypeLoc() { return typeLoc; }
TypeLoc getTypeLoc() const { return typeLoc; }

Expand Down Expand Up @@ -4817,6 +4821,8 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
}

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

/// \brief Should this declaration be treated as if annotated with transparent
/// attribute.
bool isTransparent() const;
Expand Down Expand Up @@ -5446,6 +5452,8 @@ class EnumElementDecl : public ValueDecl {
EnumElementDeclBits.HasArgumentType = HasArgumentType;
}

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

/// \returns false if there was an error during the computation rendering the
/// EnumElementDecl invalid, true otherwise.
bool computeType();
Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
}

SmallVector<char, 64> Buf;
StringRef Name = (VD->getName().str() + Twine(Kind)).toStringRef(Buf);
// TODO: Handle special names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subscripts can definitely get here, so we'll need to have some way of handling it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled in #9979 by calling through to userFacingStr once it exists. That's why I put the TODO there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I got the order of patches mixed up. Makes sense.

StringRef Name = (VD->getBaseName().getIdentifier().str() +
Twine(Kind)).toStringRef(Buf);
return BumpAllocatedString(Name);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ void Parser::diagnoseRedefinition(ValueDecl *Prev, ValueDecl *New) {
assert(New != Prev && "Cannot conflict with self");
diagnose(New->getLoc(), diag::decl_redefinition, New->isDefinition());
diagnose(Prev->getLoc(), diag::previous_decldef, Prev->isDefinition(),
Prev->getName());
Prev->getBaseName());
}

struct ParserUnit::Implementation {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4951,7 +4951,7 @@ static bool diagnoseTupleParameterMismatch(CalleeCandidateInfo &CCI,
// Constructors/descructors and subscripts don't really have names.
if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
isa<SubscriptDecl>(decl))) {
name = decl->getName();
name = decl->getBaseName().getIdentifier();
}

TC.diagnose(argExpr->getLoc(), diag::single_tuple_parameter_mismatch,
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ bool WitnessChecker::findBestWitness(

auto lookupOptions = defaultUnqualifiedLookupOptions;
lookupOptions |= NameLookupFlags::KnownPrivate;
auto lookup = TC.lookupUnqualified(overlay, requirement->getName(),
auto lookup = TC.lookupUnqualified(overlay, requirement->getBaseName(),
SourceLoc(), lookupOptions);
for (auto candidate : lookup)
witnesses.push_back(candidate.Decl);
Expand Down