Sitelet https://web.archive.org/web/20231122070918/https://github.com/github/codeql/pull/14796
Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Swift: extract MacroDecl #14796

wants to merge 9 commits into from

Conversation

AlexDenisov
Copy link
Contributor

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).

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
}
```
Copy link
Contributor

@MathiasVP MathiasVP left a 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 {
Copy link
Contributor

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.

Comment on lines 1 to 10
#-----| [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)
Copy link
Contributor

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

@AlexDenisov
Copy link
Contributor Author

Thank you @MathiasVP, these are great suggestions, I updated PR 🙌

Comment on lines +1370 to +1371
kind: int | doc("kind of this macro role (declaration, expression, member, etc.)")
macro_syntax: int | doc("#freestanding or @attached")
Copy link
Contributor

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)

Copy link
Contributor Author

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, _)
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants