-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTPrinter] Print expressions #40691
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
Printer << " "; | ||
visit(stmt->getBody()); | ||
} | ||
|
||
void PrintAST::visitRepeatWhileStmt(RepeatWhileStmt *stmt) { | ||
Printer << tok::kw_do << " "; | ||
Printer << tok::kw_repeat << " "; |
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 while
has been renamed to repeat while
for a few years now... 🙂
@@ -1,4 +1,4 @@ | |||
// RUN: %target-swift-frontend -print-ast %s 2>&1 | %FileCheck %s | |||
// RUN: %target-swift-frontend -print-ast-decl %s 2>&1 | %FileCheck %s |
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.
It might be useful to add tests for the synthesized bodies for Equatable
/Hashable
/etc. But this existing test just wants to check the access level. Using the new -print-ast-decl
makes this the least disruptive.
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.
Great to see this being added! I have some more comments, but otherwise this LGTM
void PrintAST::visitUnresolvedSpecializeExpr(UnresolvedSpecializeExpr *expr) { | ||
visit(expr->getSubExpr()); | ||
} |
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 print the generic arguments here?
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 couldn't find an example where this expression is created.
Generally, I'd like to merge this even if some expressions aren't printed 100% correct yet (there certainly are more parts missing).
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.
It's created by the parser for e.g Array<Int>
, before the types have been resolved. It gets rewritten by the type-checker though, so I don't believe the current frontend printing option will come across it. But if we ever wanted to print the AST prior to type-checking, I think we should print the generic arguments. But yeah, that doesn't need to hold up this PR.
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.
Couple of extra comments, but I'm happy for them to be done in a follow-up
// CHECK: @_hasInitialValue private let conditional: Archivable? = a as? Archivable | ||
// CHECK: @_hasInitialValue private let forced: Archivable = a as! Archivable |
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 don't think we'll want to print access modifiers here
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.
It's really only used for debugging right now. If this was to be presented to a user, we'd want to filter this so it becomes:
let conditional = a as? Archivable
(removing @_hasInitialValue private
and the explicit type annotation, if possible)
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.
Right yeah, my main concern was just that e.g:
func foo() {
private let x = 0
}
isn't valid code
_ = test(payload: payload) | ||
} | ||
// CHECK-LABEL: internal func process(payload: Payload) { | ||
// CHECK-LABEL: if .empty = payload { |
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.
Looks like the case
keyword was dropped here
@swift-ci please test |
Build failed |
Add new `-print-ast-decl` frontend option for only printing declarations, to match existing behavior. Some tests want to print the AST, but don't care about expressions. The existing `-print-ast` option now prints function bodies and expressions. Not all expressions are printed yet, but most common ones are.
@swift-ci please test |
Build failed |
@swift-ci please test |
Add new
-print-ast-decl
frontend option for only printing declarations,to match existing behavior.
Some tests want to print the AST, but don't care about expressions.
The existing
-print-ast
option now prints function bodies and expressions.Not all expressions are printed yet, but most common ones are.