-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NFC-ish] Overhaul ASTDumper #38257
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
Closed
Closed
[NFC-ish] Overhaul ASTDumper #38257
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PrintType had the ability to print a label before the node type. Extend the other dumps to do the same, and adopt it in various places where we previously printed fake AST nodes or used other odd, ad-hoc labeling. At the same time, modify PrintType to bring its call patterns surrounding labels in line with the other printers.
This makes us do a better job of passing around contexts and making them available during dumping.
This is an RAII class that represents a single node (i.e. pair of parentheses in the S-expression output) in the AST dump. It automatically manages the indentation and printing of closing parens. This commit converts PrintPattern, PrintDecl, PrintStmt, PrintExpr, and PrintTypeRepr to use it. We must further harmonize with PrintType’s semantics before it can be incorporated. I’ve made minor changes to the way various nodes are printed, so tests have been updated to match.
Prevents some common mistakes.
• Now prints accessor names in a more helpful way • Now always uses double quotes, even for anonymous decls
Rather than scattering lots of getWhateverString() calls around, we’re now calling printFlag() and letting it convert the value into a string. We’ve also basically eliminated ad-hoc printing code from ASTDumper.
Also tweaks the printing of TypeAttributes and differentiates methods for recursively printing arrays from ones for recursively printing single elements.
Obsoleted by #68438. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR pretty much rips apart ASTDumper.cpp and puts it back together again in a way that is much less ad-hoc and hopefully easier to maintain.
The primary goal here is to reduce iostream boilerplate and get rid of persistent formatting bugs (e.g. missing parens, misplaced newlines, ambiguous field delimiting). This part is already yielding some benefits; for instance, fields are now generally single-quoted unless you specifically opt out of that by calling a different printing function.
I hope to eventually reach a place where AST dumps are consistent enough to be machine-parseable (or perhaps even where we can hook up an alternate JSON-dumping backend to ASTDumper or something). We're not at that point yet because there are still parts of the file where we're printing to the underlying
raw_ostream
directly, but we're getting there.There are still a few things I'd like to do, e.g. move the
range
andlocation
fields to the end of the line so that more useful/compact info appears closer to the front of the line.This PR is "NFC-ish" because it only affects the output of
-dump-parse
and-dump-ast
, which are used in some tests but are not a supported feature of the compiler.Because test coverage on the AST dumper is very thin, this may cause some regressions in dumping behavior. That's why it's a draft PR. (Also 'cause I'm not done yet.)