Skip to content
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

WIP AST node visitor #1922

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

duckdoom5
Copy link
Contributor

@duckdoom5 duckdoom5 commented Mar 6, 2025

Draft implementation for using clang's AST node visitor. (Not fully functional nor complete)

The current implementation is based on clang's JSONNodeDumper, but the plan is to replace all the stringified properties with setting the raw data on nodes.

So this works like:

  • <clang does node iteration>
  • <clang calls Visit(const clang::<BaseType>*)> (eg. void ASTNodeVisitor::Visit(const Stmt* S))
  • We call InnerStmtVisitor::Visit()
  • <clang does inner node iteration>
  • <clang calls Visit<MostDerivedType>>
  • We override this visitor call (See visitor implementation starting here)
  • We check if the node has already been processed
  • If not add a new node, and call Convert<MostDerivedType>(clang::<NodeType>, AST::<NodeType>)
  • Convert... will then call Convert...Impl on itself and it's base types
  • See the conversion implementations, starting here
    • Also not that the Convert...Impl is the exact same code as is generated into ParseExpr/Stmt.h, in other words, with a little bit of work it should be possible to apply this for expr/stmt parsing right now

@duckdoom5 duckdoom5 marked this pull request as draft March 6, 2025 09:44
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