Skip to content

[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
wants to merge 18 commits into from
Closed

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Jul 5, 2021

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 and location 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.)

beccadax and others added 16 commits July 5, 2021 16:57
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.
• Now prints accessor names in a more helpful way
• Now always uses double quotes, even for anonymous decls
beccadax and others added 2 commits July 7, 2021 00:52
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.
@beccadax
Copy link
Contributor Author

Obsoleted by #68438.

@beccadax beccadax closed this Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant