Skip to content

Commit abcc952

Browse files
authored
Merge pull request #2138 from ahoppen/ahoppen/macroexpansion-renames
Rename some properties on `FreestandingMacroExpansionSyntax`
2 parents 9e798fa + a16fd42 commit abcc952

File tree

15 files changed

+55
-25
lines changed

15 files changed

+55
-25
lines changed

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public let TRAITS: [Trait] = [
6262
Trait(
6363
traitName: "FreestandingMacroExpansion",
6464
children: [
65-
Child(name: "poundToken", kind: .token(choices: [.token(.pound)])),
66-
Child(name: "macro", kind: .token(choices: [.token(.identifier)])),
65+
Child(name: "pound", deprecatedName: "poundToken", kind: .token(choices: [.token(.pound)])),
66+
Child(name: "macroName", deprecatedName: "macro", kind: .token(choices: [.token(.identifier)])),
6767
Child(name: "genericArgumentClause", kind: .node(kind: .genericArgumentClause), isOptional: true),
6868
Child(name: "leftParen", kind: .token(choices: [.token(.leftParen)]), isOptional: true),
69-
Child(name: "argumentList", kind: .node(kind: .labeledExprList)),
69+
Child(name: "arguments", deprecatedName: "argumentList", kind: .node(kind: .labeledExprList)),
7070
Child(name: "rightParen", kind: .token(choices: [.token(.rightParen)]), isOptional: true),
7171
Child(name: "trailingClosure", kind: .node(kind: .closureExpr), isOptional: true),
7272
Child(name: "additionalTrailingClosures", kind: .node(kind: .multipleTrailingClosureElementList)),

Examples/Sources/ExamplePlugin/Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct EchoExpressionMacro: ExpressionMacro {
1111
of node: Node,
1212
in context: Context
1313
) throws -> ExprSyntax {
14-
let expr: ExprSyntax = node.argumentList.first!.expression
14+
let expr: ExprSyntax = node.arguments.first!.expression
1515
return expr.with(\.leadingTrivia, [.blockComment("/* echo */")])
1616
}
1717
}
@@ -137,7 +137,7 @@ struct PrintAnyMacro: CodeItemMacro {
137137
of node: some FreestandingMacroExpansionSyntax,
138138
in context: some MacroExpansionContext
139139
) throws -> [CodeBlockItemSyntax] {
140-
guard let expr = node.argumentList.first?.expression else {
140+
guard let expr = node.arguments.first?.expression else {
141141
return []
142142
}
143143
return ["print(\(expr))"]

Examples/Sources/MacroExamples/Implementation/AddBlocker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public struct AddBlocker: ExpressionMacro {
101101
context.diagnose(diag)
102102
}
103103

104-
return result.asProtocol(FreestandingMacroExpansionSyntax.self)!.argumentList.first!.expression
104+
return result.asProtocol(FreestandingMacroExpansionSyntax.self)!.arguments.first!.expression
105105
}
106106
}

Examples/Sources/MacroExamples/Implementation/FontLiteralMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct FontLiteralMacro: ExpressionMacro {
2222
in context: some MacroExpansionContext
2323
) -> ExprSyntax {
2424
let argList = replaceFirstLabel(
25-
of: macro.argumentList,
25+
of: macro.arguments,
2626
with: "fontLiteralName"
2727
)
2828
return ".init(\(argList))"

Examples/Sources/MacroExamples/Implementation/StringifyMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct StringifyMacro: ExpressionMacro {
2828
of node: some FreestandingMacroExpansionSyntax,
2929
in context: some MacroExpansionContext
3030
) -> ExprSyntax {
31-
guard let argument = node.argumentList.first?.expression else {
31+
guard let argument = node.arguments.first?.expression else {
3232
fatalError("compiler bug: the macro does not have any arguments")
3333
}
3434

Examples/Sources/MacroExamples/Implementation/URLMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct URLMacro: ExpressionMacro {
2222
in context: some MacroExpansionContext
2323
) throws -> ExprSyntax {
2424

25-
guard let argument = node.argumentList.first?.expression,
25+
guard let argument = node.arguments.first?.expression,
2626
let segments = argument.as(StringLiteralExprSyntax.self)?.segments,
2727
segments.count == 1,
2828
case .stringSegment(let literalSegment)? = segments.first

Examples/Sources/MacroExamples/Implementation/WarningMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct WarningMacro: ExpressionMacro {
2121
of macro: some FreestandingMacroExpansionSyntax,
2222
in context: some MacroExpansionContext
2323
) throws -> ExprSyntax {
24-
guard let firstElement = macro.argumentList.first,
24+
guard let firstElement = macro.arguments.first,
2525
let stringLiteral = firstElement.expression
2626
.as(StringLiteralExprSyntax.self),
2727
stringLiteral.segments.count == 1,

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ public extension DeclGroupSyntax {
5151
}
5252

5353
public extension FreestandingMacroExpansionSyntax {
54+
@available(*, deprecated, renamed: "pound")
55+
public var poundToken: TokenSyntax {
56+
get {
57+
return pound
58+
}
59+
set {
60+
pound = newValue
61+
}
62+
}
63+
64+
@available(*, deprecated, renamed: "macroName")
65+
public var macro: TokenSyntax {
66+
get {
67+
return macroName
68+
}
69+
set {
70+
macroName = newValue
71+
}
72+
}
73+
5474
@available(*, deprecated, renamed: "genericArgumentClause")
5575
var genericArguments: GenericArgumentClauseSyntax? {
5676
get {
@@ -60,6 +80,16 @@ public extension FreestandingMacroExpansionSyntax {
6080
genericArgumentClause = newValue
6181
}
6282
}
83+
84+
@available(*, deprecated, renamed: "arguments")
85+
public var argumentList: LabeledExprListSyntax {
86+
get {
87+
return arguments
88+
}
89+
set {
90+
arguments = newValue
91+
}
92+
}
6393
}
6494

6595
extension GenericRequirementSyntax {

Sources/SwiftSyntax/generated/SyntaxTraits.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ public extension SyntaxProtocol {
173173

174174

175175
public protocol FreestandingMacroExpansionSyntax: SyntaxProtocol {
176-
var poundToken: TokenSyntax {
176+
var pound: TokenSyntax {
177177
get
178178
set
179179
}
180180

181-
var macro: TokenSyntax {
181+
var macroName: TokenSyntax {
182182
get
183183
set
184184
}
@@ -193,7 +193,7 @@ public protocol FreestandingMacroExpansionSyntax: SyntaxProtocol {
193193
set
194194
}
195195

196-
var argumentList: LabeledExprListSyntax {
196+
var arguments: LabeledExprListSyntax {
197197
get
198198
set
199199
}

Sources/SwiftSyntaxMacroExpansion/MacroReplacement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ extension MacroDeclSyntax {
278278
replacements: [MacroDefinition.Replacement]
279279
) -> ExprSyntax {
280280
return expand(
281-
argumentList: node.argumentList,
281+
argumentList: node.arguments,
282282
definition: definition,
283283
replacements: replacements
284284
)

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ extension MacroApplication {
851851
expandMacro: (_ macro: Macro.Type, _ node: any FreestandingMacroExpansionSyntax) throws -> ExpandedMacroType?
852852
) -> ExpandedMacroType? {
853853
guard let node,
854-
let macro = macroSystem.lookup(node.macro.text)
854+
let macro = macroSystem.lookup(node.macroName.text)
855855
else {
856856
return nil
857857
}

Tests/SwiftSyntaxMacroExpansionTest/CodeItemMacroTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fileprivate struct DeclsFromStringsMacro: DeclarationMacro {
3131
in context: some MacroExpansionContext
3232
) throws -> [DeclSyntax] {
3333
var strings: [String] = []
34-
for arg in node.argumentList {
34+
for arg in node.arguments {
3535
guard let value = arg.expression.as(StringLiteralExprSyntax.self)?.representedLiteralValue else {
3636
continue
3737
}
@@ -51,11 +51,11 @@ final class CodeItemMacroTests: XCTestCase {
5151
of node: some FreestandingMacroExpansionSyntax,
5252
in context: some MacroExpansionContext
5353
) throws -> [CodeBlockItemSyntax] {
54-
guard !node.argumentList.isEmpty else {
54+
guard !node.arguments.isEmpty else {
5555
throw MacroExpansionErrorMessage("'#unwrap' requires arguments")
5656
}
5757
let errorThrower = node.trailingClosure
58-
let identifiers = try node.argumentList.map { argument in
58+
let identifiers = try node.arguments.map { argument in
5959
guard let tupleElement = argument.as(LabeledExprSyntax.self),
6060
let declReferenceExpr = tupleElement.expression.as(DeclReferenceExprSyntax.self)
6161
else {

Tests/SwiftSyntaxMacroExpansionTest/DeclarationMacroTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fileprivate struct DeclsFromStringsMacro: DeclarationMacro {
3131
in context: some MacroExpansionContext
3232
) throws -> [DeclSyntax] {
3333
var strings: [String] = []
34-
for arg in node.argumentList {
34+
for arg in node.arguments {
3535
guard let value = arg.expression.as(StringLiteralExprSyntax.self)?.representedLiteralValue else {
3636
continue
3737
}
@@ -51,7 +51,7 @@ final class DeclarationMacroTests: XCTestCase {
5151
of node: some FreestandingMacroExpansionSyntax,
5252
in context: some MacroExpansionContext
5353
) throws -> [DeclSyntax] {
54-
guard let firstElement = node.argumentList.first,
54+
guard let firstElement = node.arguments.first,
5555
let stringLiteral = firstElement.expression
5656
.as(StringLiteralExprSyntax.self),
5757
stringLiteral.segments.count == 1,
@@ -106,7 +106,7 @@ final class DeclarationMacroTests: XCTestCase {
106106
of node: some FreestandingMacroExpansionSyntax,
107107
in context: some MacroExpansionContext
108108
) throws -> [DeclSyntax] {
109-
guard let stringLiteral = node.argumentList.first?.expression.as(StringLiteralExprSyntax.self),
109+
guard let stringLiteral = node.arguments.first?.expression.as(StringLiteralExprSyntax.self),
110110
stringLiteral.segments.count == 1,
111111
case let .stringSegment(prefix) = stringLiteral.segments.first
112112
else {
@@ -153,7 +153,7 @@ final class DeclarationMacroTests: XCTestCase {
153153
in context: some MacroExpansionContext
154154
) throws -> [DeclSyntax] {
155155
var strings: [String] = []
156-
for arg in node.argumentList {
156+
for arg in node.arguments {
157157
guard let value = arg.expression.as(StringLiteralExprSyntax.self)?.representedLiteralValue else {
158158
continue
159159
}

Tests/SwiftSyntaxMacroExpansionTest/ExpressionMacroTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fileprivate struct StringifyMacro: ExpressionMacro {
2929
of macro: some FreestandingMacroExpansionSyntax,
3030
in context: some MacroExpansionContext
3131
) throws -> ExprSyntax {
32-
guard let argument = macro.argumentList.first?.expression else {
32+
guard let argument = macro.arguments.first?.expression else {
3333
throw MacroExpansionErrorMessage("missing argument")
3434
}
3535

@@ -77,7 +77,7 @@ final class ExpressionMacroTests: XCTestCase {
7777
of macro: some FreestandingMacroExpansionSyntax,
7878
in context: some MacroExpansionContext
7979
) -> ExprSyntax {
80-
var argList = macro.argumentList
80+
var argList = macro.arguments
8181
argList[argList.startIndex].label = .identifier("_colorLiteralRed")
8282
let initSyntax: ExprSyntax = ".init(\(argList))"
8383
return initSyntax

Tests/SwiftSyntaxMacroExpansionTest/ExtensionMacroTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fileprivate struct DeclsFromStringsMacro: DeclarationMacro {
3131
in context: some MacroExpansionContext
3232
) throws -> [DeclSyntax] {
3333
var strings: [String] = []
34-
for arg in node.argumentList {
34+
for arg in node.arguments {
3535
guard let value = arg.expression.as(StringLiteralExprSyntax.self)?.representedLiteralValue else {
3636
continue
3737
}

0 commit comments

Comments
 (0)