Unified: Generate PrintAst helper and implement PrintAst query#22067
Merged
Conversation
Auto-generating a helper for implementing the PrintAST query on top of the generated AST.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a generated PrintAst “child enumeration” helper for tree-sitter–generated AST libraries and wires it up to a new Unified PrintAst query intended for IDE contextual use (and reuse outside the IDE) via a PrintAstConfiguration.
Changes:
- Extend the tree-sitter QL generator to emit a
PrintAst::getChild(node, name, i)predicate and add QL AST casting support in the generator’s expression model. - Add a configurable Unified
codeql/unified/printAstlibrary that exposesnodes/edges/graphPropertiesfor a tree graph view. - Add an IDE contextual query
unified/print-astthat restricts output to the selected source file via a sharedgetFileBySourceArchiveNamehelper.
Show a summary per file
| File | Description |
|---|---|
| unified/ql/lib/ide-contextual-queries/printAst.ql | New IDE contextual query entry point for printing a selected file’s Unified AST. |
| unified/ql/lib/codeql/unified/printAst.qll | New configurable PrintAst “graph” query predicates (nodes, edges, graphProperties) for Unified ASTs. |
| unified/ql/lib/codeql/unified/Ast.qll | Adds generated Unified::PrintAst::getChild mapping AST nodes to named children. |
| unified/ql/lib/codeql/IDEContextual.qll | Adds a shared helper to map VS Code source-archive names to File. |
| shared/tree-sitter-extractor/src/generator/ql.rs | Extends generator AST for QL emission (integer type widened; adds cast expression rendering). |
| shared/tree-sitter-extractor/src/generator/ql_gen.rs | Generates the new PrintAst module and updates integer literal construction. |
| shared/tree-sitter-extractor/src/generator/mod.rs | Ensures the generated QL output includes the new PrintAst module. |
| ruby/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll | Adds generated PrintAst::getChild for Ruby/ERB raw tree-sitter AST. |
| ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll | Adds generated PrintAst::getChild for QL/related raw tree-sitter ASTs. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 0
- Review effort level: Low
Comment on lines
+14
to
+16
| /** | ||
| * The source file to generate an AST from. | ||
| */ |
The previous commit was generated from a wrong checkout
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
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 changes the tree-sitter extractor to generate a helper predicate for implementing
PrintAstfor the generated AST.In unified we then use this to implement PrintAst. The code is deliberately made to follow the conventions from order languages, e.g. it uses the
PrintAstConfigurationso the query can be used outside the ide-contextual-query as well.For Ruby and QL4QL the generated helpers exist aren't currently used because a separate PrintAst implementation exists for the facade AST. I considered disabling the code generation for these languages, but I think a separate PrintAST query for the raw AST could be useful for debugging the desugaring layer, so I decided to just leave it in.