-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Introduce a special DeclBaseName for "deinit" #10965
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,7 +420,7 @@ bool Decl::isPrivateStdlibDecl(bool whitelistProtocols) const { | |
if (auto AFD = dyn_cast<AbstractFunctionDecl>(D)) { | ||
// Hide '~>' functions (but show the operator, because it defines | ||
// precedence). | ||
if (AFD->getNameStr() == "~>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reference to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, yes, that's gone now that we have protocol extensions. Still, removing it entirely should probably be a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll have a look how much of it can be removed later on. |
||
if (isa<FuncDecl>(AFD) && AFD->getNameStr() == "~>") | ||
return true; | ||
|
||
// If it's a function with a parameter with leading underscore, it's a | ||
|
@@ -2557,8 +2557,7 @@ ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc, | |
} | ||
|
||
DestructorDecl *ClassDecl::getDestructor() { | ||
auto name = getASTContext().Id_deinit; | ||
auto results = lookupDirect(name); | ||
auto results = lookupDirect(DeclBaseName::createDestructor()); | ||
assert(!results.empty() && "Class without destructor?"); | ||
assert(results.size() == 1 && "More than one destructor?"); | ||
return cast<DestructorDecl>(results.front()); | ||
|
@@ -4572,7 +4571,20 @@ ObjCSelector AbstractFunctionDecl::getObjCSelector( | |
} | ||
|
||
auto &ctx = getASTContext(); | ||
auto baseName = getName(); | ||
|
||
Identifier baseName; | ||
if (isa<DestructorDecl>(this)) { | ||
// Deinitializers are always called "dealloc". | ||
return ObjCSelector(ctx, 0, ctx.Id_dealloc); | ||
} else if (auto func = dyn_cast<FuncDecl>(this)) { | ||
// Otherwise cast this to be able to access getName() | ||
baseName = func->getName(); | ||
} else if (auto ctor = dyn_cast<ConstructorDecl>(this)) { | ||
baseName = ctor->getName(); | ||
} else { | ||
llvm_unreachable("Unknown subclass of AbstractFunctionDecl"); | ||
} | ||
|
||
auto argNames = getFullName().getArgumentNames(); | ||
|
||
// Use the preferred name if specified | ||
|
@@ -4596,11 +4608,6 @@ ObjCSelector AbstractFunctionDecl::getObjCSelector( | |
} | ||
} | ||
|
||
// Deinitializers are always called "dealloc". | ||
if (isa<DestructorDecl>(this)) { | ||
return ObjCSelector(ctx, 0, ctx.Id_dealloc); | ||
} | ||
|
||
|
||
// If this is a zero-parameter initializer with a long selector | ||
// name, form that selector. | ||
|
@@ -4960,9 +4967,10 @@ bool ConstructorDecl::isObjCZeroParameterWithLongSelector() const { | |
return params->get(0)->getInterfaceType()->isVoid(); | ||
} | ||
|
||
DestructorDecl::DestructorDecl(Identifier NameHack, SourceLoc DestructorLoc, | ||
ParamDecl *selfDecl, DeclContext *Parent) | ||
: AbstractFunctionDecl(DeclKind::Destructor, Parent, NameHack, DestructorLoc, | ||
DestructorDecl::DestructorDecl(SourceLoc DestructorLoc, ParamDecl *selfDecl, | ||
DeclContext *Parent) | ||
: AbstractFunctionDecl(DeclKind::Destructor, Parent, | ||
DeclBaseName::createDestructor(), DestructorLoc, | ||
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), | ||
/*NumParameterLists=*/1, nullptr) { | ||
setSelfDecl(selfDecl); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,8 @@ static void printValueDecl(ValueDecl *Decl, raw_ostream &OS) { | |
|
||
if (Decl->isOperator()) { | ||
OS << '"' << Decl->getBaseName() << '"'; | ||
} else if (Decl->getBaseName() == "subscript") { | ||
} else if (Decl->getBaseName() == "subscript" || | ||
Decl->getBaseName() == "deinit") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure if we should escape There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I forgot @swiftix was out on vacation. He'll be back tomorrow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Jordan. Escaping all keywords seems like the right conservative answer. |
||
OS << '`' << Decl->getBaseName() << '`'; | ||
} else { | ||
OS << Decl->getBaseName(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually use this one? It's always going to be
Id_init
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it in for consistency. You can call
getName()
on all Decls that are guaranteed to be backed by Identifiers. But I don't think it's actually used. Long term goal would be to remove it once/ifId_init
becomes a special name as well.