@@ -45,13 +45,13 @@ extern "C" ptrdiff_t swift_ASTGen_evaluateMacro(
45
45
// / Produce the mangled name for the nominal type descriptor of a type
46
46
// / referenced by its module and type name.
47
47
static std::string mangledNameForTypeMetadataAccessor (
48
- StringRef moduleName, StringRef typeName) {
48
+ StringRef moduleName, StringRef typeName, Node::Kind typeKind ) {
49
49
using namespace Demangle ;
50
50
51
51
// kind=Global
52
52
// kind=NominalTypeDescriptor
53
53
// kind=Type
54
- // kind=Structure
54
+ // kind=Structure|Enum|Class
55
55
// kind=Module, text=moduleName
56
56
// kind=Identifier, text=typeName
57
57
Demangle::Demangler D;
@@ -64,7 +64,7 @@ static std::string mangledNameForTypeMetadataAccessor(
64
64
{
65
65
auto *module = D.createNode (Node::Kind::Module, moduleName);
66
66
auto *identifier = D.createNode (Node::Kind::Identifier, typeName);
67
- auto *structNode = D.createNode (Node::Kind::Structure );
67
+ auto *structNode = D.createNode (typeKind );
68
68
structNode->addChild (module , D);
69
69
structNode->addChild (identifier, D);
70
70
type->addChild (structNode, D);
@@ -82,9 +82,22 @@ static std::string mangledNameForTypeMetadataAccessor(
82
82
// / Look for macro's type metadata given its external module and type name.
83
83
static void const *lookupMacroTypeMetadataByExternalName (
84
84
ASTContext &ctx, StringRef moduleName, StringRef typeName) {
85
- // Look up the type metadata accessor.
86
- auto symbolName = mangledNameForTypeMetadataAccessor (moduleName, typeName);
87
- auto accessorAddr = ctx.getAddressOfSymbol (symbolName.c_str ());
85
+ // Look up the type metadata accessor as a struct, enum, or class.
86
+ const Demangle::Node::Kind typeKinds[] = {
87
+ Demangle::Node::Kind::Structure,
88
+ Demangle::Node::Kind::Enum,
89
+ Demangle::Node::Kind::Class
90
+ };
91
+
92
+ void *accessorAddr = nullptr ;
93
+ for (auto typeKind : typeKinds) {
94
+ auto symbolName = mangledNameForTypeMetadataAccessor (
95
+ moduleName, typeName, typeKind);
96
+ accessorAddr = ctx.getAddressOfSymbol (symbolName.c_str ());
97
+ if (accessorAddr)
98
+ break ;
99
+ }
100
+
88
101
if (!accessorAddr)
89
102
return nullptr ;
90
103
0 commit comments