Skip to content

Commit 395a5e8

Browse files
authored
Merge pull request swiftlang#70033 from DougGregor/yet-more-macro-role-metaprogramming
Yet more macro role metaprogramming
2 parents 10aa58f + 9c35b08 commit 395a5e8

File tree

3 files changed

+14
-50
lines changed

3 files changed

+14
-50
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11065,7 +11065,7 @@ MacroRoles swift::getAttachedMacroRoles() {
1106511065

1106611066
bool swift::isMacroSupported(MacroRole role, ASTContext &ctx) {
1106711067
switch (role) {
11068-
#define EXPERIMENTAL_ATTACHED_MACRO_ROLE(Name, Description, FeatureName) \
11068+
#define EXPERIMENTAL_ATTACHED_MACRO_ROLE(Name, Description, MangledChar, FeatureName) \
1106911069
case MacroRole::Name: \
1107011070
return ctx.LangOpts.hasFeature(Feature::FeatureName);
1107111071

@@ -11076,7 +11076,7 @@ bool swift::isMacroSupported(MacroRole role, ASTContext &ctx) {
1107611076

1107711077
#include "swift/Basic/MacroRoles.def"
1107811078

11079-
#define EXPERIMENTAL_ATTACHED_MACRO_ROLE(Name, Description, FeatureName)
11079+
#define EXPERIMENTAL_ATTACHED_MACRO_ROLE(Name, Description, MangledChar, FeatureName)
1108011080
#define EXPERIMENTAL_FREESTANDING_MACRO_ROLE(Name, Description, FeatureName)
1108111081
#define MACRO_ROLE(Name, Description) case MacroRole::Name:
1108211082
#include "swift/Basic/MacroRoles.def"

lib/Demangling/NodePrinter.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,46 +1448,19 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14481448
Node->getNumChildren() == 3? TypePrinting::WithColon
14491449
: TypePrinting::FunctionStyle,
14501450
/*hasName*/ true);
1451-
case Node::Kind::AccessorAttachedMacroExpansion:
1452-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1453-
/*hasName*/true,
1454-
("accessor macro @" +
1455-
nodeToString(Node->getChild(2)) + " expansion #"),
1451+
#define FREESTANDING_MACRO_ROLE(Name, Description)
1452+
#define ATTACHED_MACRO_ROLE(Name, Description, MangledChar) \
1453+
case Node::Kind::Name##AttachedMacroExpansion: \
1454+
return printEntity(Node, depth, asPrefixContext, \
1455+
TypePrinting::NoType, /*hasName*/true, \
1456+
(Description " macro @" + \
1457+
nodeToString(Node->getChild(2)) + " expansion #"), \
14561458
(int)Node->getChild(3)->getIndex() + 1);
1459+
#include "swift/Basic/MacroRoles.def"
14571460
case Node::Kind::FreestandingMacroExpansion:
14581461
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
14591462
/*hasName*/true, "freestanding macro expansion #",
14601463
(int)Node->getChild(2)->getIndex() + 1);
1461-
case Node::Kind::MemberAttributeAttachedMacroExpansion:
1462-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1463-
/*hasName*/true,
1464-
("member attribute macro @" +
1465-
nodeToString(Node->getChild(2)) + " expansion #"),
1466-
(int)Node->getChild(3)->getIndex() + 1);
1467-
case Node::Kind::MemberAttachedMacroExpansion:
1468-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1469-
/*hasName*/true,
1470-
("member macro @" + nodeToString(Node->getChild(2)) +
1471-
" expansion #"),
1472-
(int)Node->getChild(3)->getIndex() + 1);
1473-
case Node::Kind::PeerAttachedMacroExpansion:
1474-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1475-
/*hasName*/true,
1476-
("peer macro @" + nodeToString(Node->getChild(2)) +
1477-
" expansion #"),
1478-
(int)Node->getChild(3)->getIndex() + 1);
1479-
case Node::Kind::ConformanceAttachedMacroExpansion:
1480-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1481-
/*hasName*/true,
1482-
("conformance macro @" + nodeToString(Node->getChild(2)) +
1483-
" expansion #"),
1484-
(int)Node->getChild(3)->getIndex() + 1);
1485-
case Node::Kind::ExtensionAttachedMacroExpansion:
1486-
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
1487-
/*hasName*/true,
1488-
("extension macro @" + nodeToString(Node->getChild(2)) +
1489-
" expansion #"),
1490-
(int)Node->getChild(3)->getIndex() + 1);
14911464
case Node::Kind::MacroExpansionUniqueName:
14921465
return printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
14931466
/*hasName*/true, "unique name #",

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,19 +2981,10 @@ getActualDifferentiabilityKind(uint8_t diffKind) {
29812981

29822982
static llvm::Optional<swift::MacroRole> getActualMacroRole(uint8_t context) {
29832983
switch (context) {
2984-
#define CASE(THE_DK) \
2985-
case (uint8_t)serialization::MacroRole::THE_DK: \
2986-
return swift::MacroRole::THE_DK;
2987-
CASE(Expression)
2988-
CASE(Declaration)
2989-
CASE(Accessor)
2990-
CASE(MemberAttribute)
2991-
CASE(Member)
2992-
CASE(Peer)
2993-
CASE(Conformance)
2994-
CASE(CodeItem)
2995-
CASE(Extension)
2996-
#undef CASE
2984+
#define MACRO_ROLE(Name, Description) \
2985+
case (uint8_t)serialization::MacroRole::Name: \
2986+
return swift::MacroRole::Name;
2987+
#include "swift/Basic/MacroRoles.def"
29972988
}
29982989
return llvm::None;
29992990
}

0 commit comments

Comments
 (0)