| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Refactors the C# QL libraries to simplify the SwitchStmt / CaseStmt AST surface and move prior switch/case “shape” handling into CFG construction, aiming to preserve overall behavior while reducing AST complexity.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll | Adds internal switch helpers and updates CFG construction to use them instead of AST “weirdness.” |
| csharp/ql/lib/semmle/code/csharp/Stmt.qll | Simplifies SwitchStmt/CaseStmt APIs by removing implicit reordering/body logic from the AST layer. |
csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll:353
/**
* Gets the `i`th statement in the body of this `switch` statement.
*
* Example:
*
* ```csharp
* switch (x) {
* case "abc": // i = 0
* return 0;
* case int i when i > 0: // i = 1
* return 1;
* case string s: // i = 2
* Console.WriteLine(s);
* return 2; // i = 3
* default: // i = 4
* return 3; // i = 5
* }
* ```
*
* Note that each non-`default` case is a labeled statement, so the statement
* that follows is a child of the labeled statement, and not the `switch` block.
*/
You can also share your feedback on Copilot code review. Take the survey.
Sorry, something went wrong.
| cached | ||
| private module SwithStmtInternal { | ||
| // Reorders default to be last if needed |
There was a problem hiding this comment.
The identifier SwithStmtInternal looks like a typo (missing 'c' in 'Switch'). Since this module is private to this file, consider renaming it to SwitchStmtInternal and updating the local references for clarity/searchability.
Sorry, something went wrong.
| // `getChild` includes both labeled statements and the targeted | ||
| // statements of labeled statement as separate children, but we | ||
| // only want the labeled statement | ||
| s = getLabeledStmt(ss, j) |
There was a problem hiding this comment.
This comment says "getChild includes ..." but the code here uses getChildStmt. Consider updating the wording to match the actual API and to describe the current structure (case labels and section statements are separate children) so future readers aren't misled.
This issue also appears on line 332 of the same file.
Sorry, something went wrong.
|
I don't care much about the quality issues in ControlFlowGraphImpl.qll (which were simply copied from Stmt.qll) - I intend to replace that entire CFG implementation soon anyway. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks plausible to me!
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
| cached |
There was a problem hiding this comment.
Caching should no longer be needed now that it is only used in the CFG construction.
Sorry, something went wrong.
There was a problem hiding this comment.
Right, but I went for minimal changes, as I'm going to delete the entire contents of that file soon anyway.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The C# AST for SwitchStmt and CaseStmt had some weird mangling, which was ultimately only used in the CFG construction. So this refactor moves that complexity into the CFG and simplifies the AST classes.
Technically, this is a breaking change for any use of the AST predicates that depended on the weirdness, but I think such uses are unlikely, and indeed the only uses we had were in ControlFlowGraphImpl, so I expect this to be completely behaviour-preserving.