-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTPrinter] Intorduce 'IntroducerKeyword' name kind #38521
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
Conversation
@swift-ci Please smoke test |
lib/AST/ASTPrinter.cpp
Outdated
if (!Options.SkipIntroducerKeywords) { | ||
if (decl->isExplicitActor()) { | ||
Printer.printKeyword("actor", Options, " "); | ||
} else { | ||
Printer << tok::kw_class << " "; | ||
} | ||
} | ||
if (!Options.SkipIntroducerKeywords) | ||
Printer.printIntroducerKeyword( | ||
decl->isExplicitActor() ? "actor" : "class"); |
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.
Since actor
is not declared as a keyword, not all introducer are "keyword". There's no reason to use tok::kw_*
for introducer printing anymore.
include/swift/AST/ASTPrinter.h
Outdated
@@ -217,6 +219,14 @@ class ASTPrinter { | |||
*this << Suffix; | |||
} | |||
|
|||
void printIntroducerKeyword(StringRef name, | |||
StringRef Suffix = " ") { |
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 think we should keep the default Suffix
the same between printKeyword
and printIntroducerKeyword
, otherwise it's confusing.
@@ -1292,9 +1293,8 @@ void PrintAST::printPattern(const Pattern *pattern) { | |||
|
|||
case PatternKind::Binding: | |||
if (!Options.SkipIntroducerKeywords) | |||
Printer << (cast<BindingPattern>(pattern)->isLet() ? tok::kw_let |
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.
Should we move checking SkipIntroducerKeywords
into printIntroducerKeyword
? That way you cannot forget, and also we could give the method the same signature as printKeyword
, which also takes options.
9222db0
to
c535893
Compare
@swift-ci Please smoke test |
lib/AST/ASTPrinter.cpp
Outdated
Printer.printKeyword("__consuming", Options, " "); | ||
} | ||
Printer << tok::kw_func << " "; | ||
printMutabilityModifiersIfNeeded(decl); |
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.
Will these (mutability and __consuming) now get printed in places they didn't used to due to not checking SkipIntroducerKeywords
? Not sure if that's desirable or not 🤔
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.
Renamed printMutabilityModifiersIfNeeded()
to printSelfAccessKindModifiersIfNeeded()
and moved __consuming
printing into it. Also, added a printing option whether to print mutating
/nonmutating
/__consuming
.
So far SkipIntroducerKeywords
is used only in <RelatedName />
printing in SourceKit.
d5ae9c9
to
c113ba0
Compare
@swift-ci Please smoke test |
For more fine grained annoations. For now, it's handled as the same as 'Keyword' name kind. Fix an issue where 'extension' wasn't marked as "keyword". Also, move 'static' priting out of 'SkipIntroducerKeywords' guard because 'static' is not an declaration introducer.
c113ba0
to
6e69a44
Compare
@swift-ci Please smoke test |
break; | ||
case SelfAccessKind::NonMutating: | ||
if (AD && AD->isExplicitNonMutating() && | ||
!Options.excludeAttrKind(DAK_NonMutating)) |
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.
This was checking DAK_Mutating
before, which seems like a latent bug, but I don't think it's observable since the only place I found that adds DAK_Mutating
but not DAK_NonMutating
is protocol conformance diagnostics for non-accessors, but this code only prints nonmutating
on accessors. Oh well, at least it's correct now 🤷
For more fine grained annotations. For now, it's handled as the same as
Keyword
name kind.Fix an issue where
extension
wasn't marked as "keyword".Also, move
static
priting out ofSkipIntroducerKeywords
guard because 'static' is not an declaration introducer.(Preparation for #38453)