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
Swift: extract MacroDecl
#14796
base: main
Are you sure you want to change the base?
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
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙌 |
| kind: int | doc("kind of this macro role (declaration, expression, member, etc.)") | ||
| macro_syntax: int | doc("#freestanding or @attached") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should probably be marked | ql.internal: we generally don't want to expose magic enumeration numbers, and we usually hide them either behind predicates (for example isDeclarationMacro etc and isAttached/isFreestanding)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind either way. Should I hide these and add predicates for all the cases?
| or | ||
| error = "Macro declarations removed during database downgrade. Please update your CodeQL code." and | ||
| property = "" and | ||
| macro_decls(e, _) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't macro_roles missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they can be safely deleted as they are only referenced by macro decls?
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).