mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Improve parsing, representation, and serialization of role attributes
Parse compound and special names in the macro role attributes (`@freestanding` and `@attached`). This allows both compound names and initializers, e.g., `init(coding:)`. Fixes rdar://107967344.
This commit is contained in:
@@ -3041,17 +3041,27 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
auto rawMacroRole =
|
||||
getRawStableMacroRole(theAttr->getMacroRole());
|
||||
SmallVector<IdentifierID, 4> introducedDeclNames;
|
||||
for (auto name : theAttr->getNames()) {
|
||||
for (auto introducedName : theAttr->getNames()) {
|
||||
introducedDeclNames.push_back(IdentifierID(
|
||||
getRawStableMacroIntroducedDeclNameKind(name.getKind())));
|
||||
introducedDeclNames.push_back(
|
||||
S.addDeclBaseNameRef(name.getIdentifier()));
|
||||
getRawStableMacroIntroducedDeclNameKind(introducedName.getKind())));
|
||||
|
||||
auto name = introducedName.getName();
|
||||
introducedDeclNames.push_back(S.addDeclBaseNameRef(name.getBaseName()));
|
||||
if (name.isSimpleName()) {
|
||||
introducedDeclNames.push_back(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto argumentLabels = name.getArgumentNames();
|
||||
introducedDeclNames.push_back(argumentLabels.size() + 1);
|
||||
for (auto label : argumentLabels)
|
||||
introducedDeclNames.push_back(S.addDeclBaseNameRef(label));
|
||||
}
|
||||
|
||||
MacroRoleDeclAttrLayout::emitRecord(
|
||||
S.Out, S.ScratchRecord, abbrCode, theAttr->isImplicit(),
|
||||
static_cast<uint8_t>(theAttr->getMacroSyntax()),
|
||||
rawMacroRole, theAttr->getNames().size(),
|
||||
rawMacroRole, introducedDeclNames.size(),
|
||||
introducedDeclNames);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user