Skip to content

Commit febedf4

Browse files
authored
Merge pull request #65363 from DougGregor/macro-compound-introduced-names-5.9
[5.9] [Macros] Improve parsing, representation, and serialization of role attributes
2 parents 73a3827 + cbb0e48 commit febedf4

File tree

15 files changed

+244
-242
lines changed

15 files changed

+244
-242
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,6 @@ ERROR(foreign_diagnostic,none,
20282028
//------------------------------------------------------------------------------
20292029
// MARK: macros
20302030
//------------------------------------------------------------------------------
2031-
ERROR(expected_macro_value_type,PointsToFirstBadToken,
2032-
"expected macro value type following ':'", ())
20332031
ERROR(expected_lparen_macro,PointsToFirstBadToken,
20342032
"expected '(' for macro parameters or ':' for a value-like macro", ())
20352033
ERROR(expected_type_macro_result,PointsToFirstBadToken,
@@ -2042,12 +2040,13 @@ ERROR(macro_expansion_expr_expected_macro_identifier,PointsToFirstBadToken,
20422040
ERROR(macro_expansion_decl_expected_macro_identifier,PointsToFirstBadToken,
20432041
"expected a macro identifier for a pound literal declaration", ())
20442042

2045-
ERROR(declaration_attr_expected_kind,PointsToFirstBadToken,
2046-
"expected a declaration macro kind ('freestanding' or 'attached')", ())
2047-
20482043
ERROR(macro_role_attr_expected_kind,PointsToFirstBadToken,
20492044
"expected %select{a freestanding|an attached}0 macro role such as "
20502045
"%select{'expression'|'accessor'}0", (bool))
2046+
ERROR(macro_role_attr_expected_attached_kind,PointsToFirstBadToken,
2047+
"expected an attached macro role such as 'peer'", ())
2048+
ERROR(macro_role_attr_expected_freestanding_kind,PointsToFirstBadToken,
2049+
"expected a freestanding macro role such as 'expression'", ())
20512050
ERROR(macro_role_syntax_mismatch,PointsToFirstBadToken,
20522051
"%select{a freestanding|an attached}0 macro cannot have the %1 role",
20532052
(bool, Identifier))
@@ -2056,14 +2055,14 @@ ERROR(macro_attribute_unknown_label,PointsToFirstBadToken,
20562055
(bool, Identifier))
20572056
ERROR(macro_attribute_duplicate_label,PointsToFirstBadToken,
20582057
"@%select{freestanding|attached}0 already has an argument with "
2059-
"label %1", (bool, Identifier))
2060-
ERROR(macro_attribute_missing_label,PointsToFirstBadToken,
2058+
"label %1", (bool, StringRef))
2059+
ERROR(macro_attribute_missing_label,none,
20612060
"@%select{freestanding|attached}0 argument is missing label '%1'",
20622061
(bool, StringRef))
20632062
ERROR(macro_attribute_unknown_name_kind,PointsToFirstBadToken,
20642063
"unknown introduced name kind %0", (Identifier))
20652064
ERROR(macro_attribute_unknown_argument_form,PointsToFirstBadToken,
2066-
"introduced name argument should be an identifier", ())
2065+
"introduced name argument should be a name", ())
20672066
ERROR(macro_attribute_introduced_name_requires_argument,PointsToFirstBadToken,
20682067
"introduced name kind %0 requires a single argument '(name)'", (Identifier))
20692068
ERROR(macro_attribute_introduced_name_requires_no_argument,PointsToFirstBadToken,

include/swift/AST/MacroDeclaration.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ class MacroIntroducedDeclName {
111111

112112
private:
113113
Kind kind;
114-
Identifier identifier;
114+
DeclName name;
115115

116116
public:
117-
MacroIntroducedDeclName(Kind kind, Identifier identifier = Identifier())
118-
: kind(kind), identifier(identifier) {};
117+
MacroIntroducedDeclName(Kind kind, DeclName name = DeclName())
118+
: kind(kind), name(name) {};
119119

120-
static MacroIntroducedDeclName getNamed(Identifier name) {
120+
static MacroIntroducedDeclName getNamed(DeclName name) {
121121
return MacroIntroducedDeclName(Kind::Named, name);
122122
}
123123

@@ -138,7 +138,7 @@ class MacroIntroducedDeclName {
138138
}
139139

140140
Kind getKind() const { return kind; }
141-
Identifier getIdentifier() const { return identifier; }
141+
DeclName getName() const { return name; }
142142
};
143143

144144
}

lib/AST/Attr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,9 +1382,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13821382
[&](MacroIntroducedDeclName name) {
13831383
Printer << getMacroIntroducedDeclNameString(name.getKind());
13841384
if (macroIntroducedNameRequiresArgument(name.getKind())) {
1385-
StringRef nameText = name.getIdentifier().str();
1386-
bool shouldEscape = escapeKeywordInContext(
1387-
nameText, PrintNameContext::Normal) || nameText == "$";
1385+
SmallString<32> buffer;
1386+
StringRef nameText = name.getName().getString(buffer);
1387+
bool shouldEscape = nameText == "$";
13881388
Printer << "(";
13891389
if (shouldEscape)
13901390
Printer << "`";

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10256,7 +10256,7 @@ void MacroDecl::getIntroducedNames(MacroRole role, ValueDecl *attachedTo,
1025610256
for (auto expandedName : attr->getNames()) {
1025710257
switch (expandedName.getKind()) {
1025810258
case MacroIntroducedDeclNameKind::Named: {
10259-
names.push_back(DeclName(expandedName.getIdentifier()));
10259+
names.push_back(DeclName(expandedName.getName()));
1026010260
break;
1026110261
}
1026210262

@@ -10276,7 +10276,7 @@ void MacroDecl::getIntroducedNames(MacroRole role, ValueDecl *attachedTo,
1027610276
std::string prefixedName;
1027710277
{
1027810278
llvm::raw_string_ostream out(prefixedName);
10279-
out << expandedName.getIdentifier();
10279+
out << expandedName.getName();
1028010280
out << baseName.getIdentifier();
1028110281
}
1028210282

@@ -10294,7 +10294,7 @@ void MacroDecl::getIntroducedNames(MacroRole role, ValueDecl *attachedTo,
1029410294
{
1029510295
llvm::raw_string_ostream out(suffixedName);
1029610296
out << baseName.getIdentifier();
10297-
out << expandedName.getIdentifier();
10297+
out << expandedName.getName();
1029810298
}
1029910299

1030010300
Identifier nameId = ctx.getIdentifier(suffixedName);

0 commit comments

Comments
 (0)