Skip to content

Conversation

@MathiasVP
Copy link
Collaborator

This PR rewrites the PowerShell AST to be much more like the other languages. It also fixes up all the subsequent analyses like control-flow, dataflow, api graphs and models-as-data. Although there are still some parts of API graphs that need to be modified.

In particular, this means that:

  • The right-hand side of an AssignStmt is now finally an Expr instead of a Stmt. In the Powershell parser this decision probably came from the fact that the right-hand side of an AssignStmt can be a pipeline, and a pipeline is produced by a statement (for example, by a call to a command like Foo).
  • All "calls" are now expressions, and there's a unified Expr class representing calls. Previously, Cmds were Stmts and member calls where Exprs.
  • There is no longer a DataFlow::Node::asStmt predicate 🥳 This was necessary because of the above points, but now that pipelines are produced by Exprs this is no longer needed

I've got more plans for what kinds of rewrites we can do on the AST, but I think this is good enough to merge for now.

The main tool for producing a better AST is the synthesis framework I added in 7f30050 and subsequent commits extend the Synthesis class to perform rewrites.

Additionally, I've also fixed a couple of issues in the extractor in the first commit: We now recognize more files as Powershell source files, and we've fixed an off-by-one issue in the locations relation.

…e extracted AST these are just variables with special names. We insert synthesized AST elements that represent these special variables.
…refers to the individual elements in the pipeline. Add a synthesized variable access that represents this.
@MathiasVP MathiasVP force-pushed the powershell-ipa-the-ast branch from 1791d9d to 0fc5778 Compare March 27, 2025 16:01
@MathiasVP MathiasVP marked this pull request as ready for review March 27, 2025 16:06
@MathiasVP MathiasVP merged commit cea435c into main Mar 27, 2025
3 checks passed
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.

3 participants