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

[Macros] Introduce member declaration macros. #1207

Merged
merged 9 commits into from
Jan 11, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 10, 2023

An initial implementation for member declaration macros.

Member declaration macros are represented as custom attributes, and expanding a member macro for a given declaration can produce a set of new members to add to that declaration. For example:

@addBackingStorage
struct S {
  var value: Int
}

Expanding @addBackingStorage adds var _storage to S:

struct S {
  var value: Int
  var _storage: Storage<Self>
}

return DeclSyntax(expandMembers(of: node))
}

override func visit(_ node: ProtocolDeclSyntax) -> DeclSyntax {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about enums? And... should this use DeclGroupSyntax?

}

do {
try newMembers.append(contentsOf: memberMacro.expansion(of: customAttribute,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked out really nicely.

Sources/_SwiftSyntaxMacros/MemberDeclarationMacro.swift Outdated Show resolved Hide resolved
@hborla
Copy link
Member Author

hborla commented Jan 10, 2023

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 10, 2023

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 10, 2023

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 10, 2023

@swift-ci please test

@hborla hborla merged commit 50a322c into swiftlang:main Jan 11, 2023
@hborla hborla deleted the member-declaration-macros branch January 11, 2023 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants