Commit Graph

173 Commits

Author SHA1 Message Date
Rose
0a380cbba3 Fix DeclarationMacro deprecations
These deprecations are simple renames, but this PR should get rid of the warnings.
2023-01-25 13:50:02 -05:00
Holly Borla
14f11727f2 [ASTScopeCreation] Teach ASTScope to find the enclosing type context for
synthesized member macro expansion buffers.
2023-01-24 19:45:22 -08:00
Holly Borla
e04a791ad7 [Macros] Allow synthesized member macros to add member type and method decls. 2023-01-24 19:45:22 -08:00
Holly Borla
e5ba38925a [Macros] Allow one attached macro declaration to fulfill multiple roles. 2023-01-23 17:56:48 -08:00
Holly Borla
f1742fd721 [Macros] Initial implementation for synthesized member macro expansion. 2023-01-23 17:56:48 -08:00
Holly Borla
6fcd3f6557 [Macros] Enable composition of member attribute macros and accessor macros. 2023-01-17 18:54:16 -08:00
Erik Eckstein
bfa14e64dd Revert "[Macros] Enable composition of member attribute macros and accessor macros."
It causes crashes in some Sema/SwiftUI tests in some configurations.

rdar://104297642

This reverts commit b8d65e1ed9.
2023-01-17 13:30:27 +01:00
Holly Borla
0d7109710f [Macros] Pass the parent declaration of the member-to-expand to member
attribute macro expansions.
2023-01-15 11:36:47 -08:00
Holly Borla
b8d65e1ed9 [Macros] Enable composition of member attribute macros and accessor macros. 2023-01-15 10:11:00 -08:00
Holly Borla
4f8e1daa26 [Macros] Implement the skeleton of attribute macro expansion.
Attribute macros are expanded during AttachedSemanticAttrsRequest. This
change invokves the expansion, but it does nothing with the result yet.
The next step is to parse back in the attribute list, type check it, and
return the resulting attributes back to the request to add to the semantic
attribute list.
2023-01-15 10:11:00 -08:00
Doug Gregor
91ee109c2f [Macros] Start expanding accessor macros attached to a storage declaration.
Accessor macros are attached macros (written with attribute syntax)
that can generate accessors for a property or subscript. Recognize
custom attributes that are accessor macros when written on a storage
declaration, and expand those macros.

This is very much a work in progress, and the result of the expansion
isn't yet parsed or wired into the AST.
2023-01-13 10:12:25 -08:00
Alex Hoppen
e2842c7022 Merge pull request #62961 from ahoppen/ahoppen/merge-binary-operators
[Macros] Adjustments for merging `spacedBinaryOperator` and `unspacedBinaryOperator` in SwiftSyntax
2023-01-11 19:32:08 +01:00
Alex Hoppen
ee9033b41d [Macros] Adjustments for merging spacedBinaryOperator and unspacedBinaryOperator in SwiftSyntax 2023-01-11 08:07:53 +01:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Doug Gregor
dfa3ed910d Teach DeclContext::getParentSourceFile() to return the innermost source file
With macro expansions, and really any code generation that produces
proper source locations, the parent source file of a declaration
context will be a generated source file rather than the source file
near the top of the declaration-context stack. Adjust the
implementation of `getParentSourceFile()` to return that innermost
source file by doing location-based lookup.
2023-01-08 11:40:02 -08:00
Doug Gregor
bbb5c7a690 [Macros] Allow enums and classes/actors to be macro definitions, too 2023-01-02 21:22:04 -08:00
Doug Gregor
222bc03c0a [Macros] Prevent recursive expansion of macros. 2023-01-02 21:22:04 -08:00
Doug Gregor
921e61b2fa Emit "in expansion of macro" notes for diagnostics within macro expansion buffers 2022-12-15 13:37:29 -08:00
Doug Gregor
387a79c47b [Macro test] Handle source locations in macro diagnostics better.
"Relink" the folded syntax node back into the primary syntax node. When
we do this, we get consistent source locations that do not require any
adjustment.

Test this by adding a Fix-It to the silly AddBlocker macro, replacing
the `+` with a `-`.
2022-12-14 16:13:49 -08:00
Doug Gregor
14aebcab1b Bridge swift-syntax diagnostics to the C++ diagnostic engine's diagnostics.
Implement an ASTGen operation to bridge swift-syntax diagnostics, as
produced by the parser, operator folding, and macros, over to the C++
diagnostic engine infrastructure. Use this to wire up macro expansion
diagnostics.
2022-12-05 11:49:42 -08:00
Doug Gregor
728ba4eada [Macros] Adapt to rename of ExpressionMacro.expansion(of:in:). 2022-12-05 09:34:54 -08:00
Doug Gregor
5bd94d680e [Macros] Adapt to macro API changes and switch more testing to use it.
The API provided by macro evaluation has changed a bit. Adapt ASTGen to
the new API, and use this as an opportunity to start moving more tests
to using the shared libraries built into the toolchain.
2022-12-02 16:35:14 -08:00
Doug Gregor
811595394f [Macros] Build and test a macro plugin based on SwiftSyntax 2022-12-01 23:20:56 -08:00