Swift: extract MacroDecl#14796
Conversation
They only appear in an intermediate AST and disappear as soon as the
macro is expanded.
The only way to get these in is to construct an "incorrect" AST, e.g.:
```
let x = #does_not_exist() // MacroExpansionExpr
struct S {
#does_not_exist() // MacroExpansionDecl
}
```
MathiasVP
left a comment
There was a problem hiding this comment.
A couple of suggestions, but otherwise this LGTM!
|
|
||
| private import codeql.swift.generated.MacroRole | ||
|
|
||
| class MacroRole extends Generated::MacroRole { |
There was a problem hiding this comment.
Could you add some QLDoc to describe what a MacroRole is? 🙏
It looks like you added it to the autogenerated class via the schena.py file (which is awesome!), but I think we should port it to the user-facing file as well.
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(expression) | ||
| #-----| [MacroRole] #freestanding(declaration) | ||
| #-----| [MacroRole] #freestanding(declaration) |
There was a problem hiding this comment.
It looks like we should add MacroRole to the list of things that shouldn't be printed by PrintAST, no?
FWIW, that list of things is here: https://github.com/github/codeql/blob/main/swift/ql/lib/codeql/swift/printast/PrintAstNode.qll#L23
|
Thank you @MathiasVP, these are great suggestions, I updated PR 🙌 |
redsun82
left a comment
There was a problem hiding this comment.
LGTM! Sorry again for the code generation bug.
The other three elements are skipped (
MacroExpansionExpr,MacroExpansionDecl,MissingDecl) as they only appear in cases when a macro is not expanded (due to an error).