[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:
Doug Gregor
2023-04-20 08:23:26 -07:00
parent 1c3667b52a
commit ae4a5ded8f
15 changed files with 254 additions and 252 deletions

View File

@@ -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;
}