Skip to content

Commit 35222e1

Browse files
committed
Use preprocessor metaprogramming for macro roles in the demangle node printer
1 parent 19d578e commit 35222e1

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

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 #",

0 commit comments

Comments
 (0)