Skip to content

Commit 8b9be30

Browse files
committed
[Macros] Add a new macro role for synthesized member macros.
1 parent 336af60 commit 8b9be30

File tree

9 files changed

+20
-3
lines changed

9 files changed

+20
-3
lines changed

include/swift/AST/MacroDeclaration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ enum class MacroRole: uint32_t {
3535
/// An attached macro that generates attributes for the
3636
/// members inside the declaration.
3737
MemberAttribute = 0x08,
38+
/// An attached macro that generates synthesized members
39+
/// inside the declaration.
40+
SynthesizedMembers = 0x10,
3841
};
3942

4043
/// The contexts in which a particular macro declaration can be used.

include/swift/Basic/SourceManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class GeneratedSourceInfo {
4444
/// The expansion of a member attribute attached macro.
4545
MemberAttributeMacroExpansion,
4646

47+
/// The expansion of a synthesized member macro.
48+
SynthesizedMemberMacroExpansion,
49+
4750
/// A new function body that is replacing an existing function body.
4851
ReplacedFunctionBody,
4952

lib/AST/Decl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9703,6 +9703,9 @@ StringRef swift::getMacroRoleString(MacroRole role) {
97039703

97049704
case MacroRole::MemberAttribute:
97059705
return "memberAttributes";
9706+
9707+
case MacroRole::SynthesizedMembers:
9708+
return "synthesizedMembers";
97069709
}
97079710
}
97089711

@@ -9745,8 +9748,10 @@ static MacroRoles freestandingMacroRoles =
97459748
(MacroRoles() |
97469749
MacroRole::Expression |
97479750
MacroRole::FreestandingDeclaration);
9748-
static MacroRoles attachedMacroRoles = (MacroRoles() | MacroRole::Accessor |
9749-
MacroRole::MemberAttribute);
9751+
static MacroRoles attachedMacroRoles = (MacroRoles() |
9752+
MacroRole::Accessor |
9753+
MacroRole::MemberAttribute |
9754+
MacroRole::SynthesizedMembers);
97509755

97519756
bool swift::isFreestandingMacro(MacroRoles contexts) {
97529757
return bool(contexts & freestandingMacroRoles);

lib/AST/DiagnosticEngine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,8 @@ std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
13141314
case GeneratedSourceInfo::ExpressionMacroExpansion:
13151315
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
13161316
case GeneratedSourceInfo::AccessorMacroExpansion:
1317-
case GeneratedSourceInfo::MemberAttributeMacroExpansion: {
1317+
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
1318+
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion: {
13181319
SourceRange origRange = expansionNode.getSourceRange();
13191320
DeclName macroName;
13201321
if (auto customAttr = generatedInfo->attachedMacroCustomAttr) {

lib/Basic/SourceLoc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ void SourceManager::setGeneratedSourceInfo(
314314
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
315315
case GeneratedSourceInfo::AccessorMacroExpansion:
316316
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
317+
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
317318
case GeneratedSourceInfo::PrettyPrinted:
318319
break;
319320

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,7 @@ static Optional<MacroRole> getMacroRole(
22252225
.Case("expression", MacroRole::Expression)
22262226
.Case("accessor", MacroRole::Accessor)
22272227
.Case("memberAttributes", MacroRole::MemberAttribute)
2228+
.Case("synthesizedMembers", MacroRole::SynthesizedMembers)
22282229
.Default(None);
22292230

22302231
if (!role) {

lib/Parse/ParseRequests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ SourceFileParsingResult ParseSourceFileRequest::evaluate(Evaluator &evaluator,
174174
switch (generatedInfo->kind) {
175175
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
176176
case GeneratedSourceInfo::ExpressionMacroExpansion:
177+
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
177178
case GeneratedSourceInfo::ReplacedFunctionBody:
178179
case GeneratedSourceInfo::PrettyPrinted: {
179180
parser.parseTopLevelItems(items);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ enum class MacroRole : uint8_t {
613613
FreestandingDeclaration,
614614
Accessor,
615615
MemberAttribute,
616+
SynthesizedMembers,
616617
};
617618
using MacroRoleField = BCFixed<3>;
618619

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,7 @@ static uint8_t getRawStableMacroRole(swift::MacroRole context) {
22272227
CASE(FreestandingDeclaration)
22282228
CASE(Accessor)
22292229
CASE(MemberAttribute)
2230+
CASE(SynthesizedMembers)
22302231
}
22312232
#undef CASE
22322233
llvm_unreachable("bad result declaration macro kind");

0 commit comments

Comments
 (0)