@@ -211,11 +211,52 @@ public func expandFreestandingMacro(
211211/// - Returns: A list of expanded source text. Upon failure (i.e.
212212/// `definition.expansion()` throws) returns `nil`, and the diagnostics
213213/// representing the `Error` are guaranteed to be added to context.
214+ @available ( * , deprecated, message: " Change the 'declarationNode' argument label to 'node' " )
214215public func expandAttachedMacroWithoutCollapsing< Context: MacroExpansionContext > (
215216 definition: Macro . Type ,
216217 macroRole: MacroRole ,
217218 attributeNode: AttributeSyntax ,
218- declarationNode: some SyntaxProtocol ,
219+ declarationNode: DeclSyntax ,
220+ parentDeclNode: DeclSyntax ? ,
221+ extendedType: TypeSyntax ? ,
222+ conformanceList: InheritedTypeListSyntax ? ,
223+ in context: Context ,
224+ indentationWidth: Trivia ? = nil
225+ ) -> [ String ] ? {
226+ expandAttachedMacroWithoutCollapsing (
227+ definition: definition,
228+ macroRole: macroRole,
229+ attributeNode: attributeNode,
230+ node: declarationNode,
231+ parentDeclNode: parentDeclNode,
232+ extendedType: extendedType,
233+ conformanceList: conformanceList,
234+ in: context,
235+ indentationWidth: indentationWidth
236+ )
237+ }
238+
239+ /// Expand `@attached(XXX)` macros.
240+ ///
241+ /// - Parameters:
242+ /// - definition: a type that conforms to one or more attached `Macro` protocols.
243+ /// - macroRole: indicates which `Macro` protocol expansion should be performed
244+ /// - attributeNode: attribute syntax node (e.g. `@macroName(argument)`).
245+ /// - node: target syntax node to apply the expansion. This is either a declaration
246+ /// or a closure syntax node.
247+ /// - parentDeclNode: Only used for `MacroRole.memberAttribute`. The parent
248+ /// context node of `declarationNode`.
249+ /// - context: context of the expansion.
250+ /// - indentationWidth: The indentation that should be added for each additional
251+ /// nesting level
252+ /// - Returns: A list of expanded source text. Upon failure (i.e.
253+ /// `definition.expansion()` throws) returns `nil`, and the diagnostics
254+ /// representing the `Error` are guaranteed to be added to context.
255+ public func expandAttachedMacroWithoutCollapsing< Context: MacroExpansionContext > (
256+ definition: Macro . Type ,
257+ macroRole: MacroRole ,
258+ attributeNode: AttributeSyntax ,
259+ node: some SyntaxProtocol ,
219260 parentDeclNode: DeclSyntax ? ,
220261 extendedType: TypeSyntax ? ,
221262 conformanceList: InheritedTypeListSyntax ? ,
@@ -225,7 +266,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
225266 do {
226267 switch ( definition, macroRole) {
227268 case ( let attachedMacro as AccessorMacro . Type , . accessor) :
228- let declarationNode = declarationNode . cast ( DeclSyntax . self)
269+ let declarationNode = node . cast ( DeclSyntax . self)
229270 let accessors = try attachedMacro. expansion (
230271 of: attributeNode,
231272 providingAccessorsOf: declarationNode,
@@ -236,7 +277,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
236277 }
237278
238279 case ( let attachedMacro as MemberAttributeMacro . Type , . memberAttribute) :
239- let declarationNode = declarationNode . cast ( DeclSyntax . self)
280+ let declarationNode = node . cast ( DeclSyntax . self)
240281 guard
241282 let parentDeclGroup = parentDeclNode? . asProtocol ( DeclGroupSyntax . self)
242283 else {
@@ -257,7 +298,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
257298 }
258299
259300 case ( let attachedMacro as MemberMacro . Type , . member) :
260- guard let declGroup = declarationNode . asProtocol ( DeclGroupSyntax . self)
301+ guard let declGroup = node . asProtocol ( DeclGroupSyntax . self)
261302 else {
262303 // Compiler error: declNode for member macro must be DeclGroupSyntax.
263304 throw MacroExpansionError . declarationNotDeclGroup
@@ -276,7 +317,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
276317 }
277318
278319 case ( let attachedMacro as PeerMacro . Type , . peer) :
279- let declarationNode = declarationNode . cast ( DeclSyntax . self)
320+ let declarationNode = node . cast ( DeclSyntax . self)
280321 let peers = try attachedMacro. expansion (
281322 of: attributeNode,
282323 providingPeersOf: declarationNode,
@@ -289,15 +330,15 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
289330 }
290331
291332 case ( let attachedMacro as ExtensionMacro . Type , . extension) :
292- guard let declGroup = declarationNode . asProtocol ( DeclGroupSyntax . self) else {
333+ guard let declGroup = node . asProtocol ( DeclGroupSyntax . self) else {
293334 // Compiler error: type mismatch.
294335 throw MacroExpansionError . declarationNotDeclGroup
295336 }
296337
297338 let extensionOf : TypeSyntax
298339 if let extendedType {
299340 extensionOf = extendedType
300- } else if let identified = declarationNode . asProtocol ( NamedDeclSyntax . self) {
341+ } else if let identified = node . asProtocol ( NamedDeclSyntax . self) {
301342 // Fallback for old compilers with a new plugin, where
302343 extensionOf = TypeSyntax ( IdentifierTypeSyntax ( name: identified. name) )
303344 } else {
@@ -321,7 +362,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
321362
322363 case ( let attachedMacro as PreambleMacro . Type , . preamble) :
323364 guard
324- let declToPass = Syntax ( declarationNode ) . asProtocol ( SyntaxProtocol . self)
365+ let declToPass = Syntax ( node ) . asProtocol ( SyntaxProtocol . self)
325366 as? ( DeclSyntaxProtocol & WithOptionalCodeBlockSyntax )
326367 else {
327368 // Compiler error: declaration must have a body.
@@ -339,13 +380,13 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
339380
340381 case ( let attachedMacro as BodyMacro . Type , . body) :
341382 let body : [ CodeBlockItemSyntax ]
342- if let closureSyntax = declarationNode . as ( ClosureExprSyntax . self) {
383+ if let closureSyntax = node . as ( ClosureExprSyntax . self) {
343384 body = try attachedMacro. expansion (
344385 of: attributeNode,
345386 providingBodyFor: closureSyntax,
346387 in: context
347388 )
348- } else if let declToPass = Syntax ( declarationNode ) . asProtocol ( SyntaxProtocol . self)
389+ } else if let declToPass = Syntax ( node ) . asProtocol ( SyntaxProtocol . self)
349390 as? ( DeclSyntaxProtocol & WithOptionalCodeBlockSyntax )
350391 {
351392 body = try attachedMacro. expansion (
@@ -386,11 +427,52 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
386427/// - Returns: expanded source text. Upon failure (i.e. `defintion.expansion()`
387428/// throws) returns `nil`, and the diagnostics representing the `Error` are
388429/// guaranteed to be added to context.
430+ @available ( * , deprecated, message: " Change the 'declarationNode' argument label to 'node' " )
431+ public func expandAttachedMacro< Context: MacroExpansionContext > (
432+ definition: Macro . Type ,
433+ macroRole: MacroRole ,
434+ attributeNode: AttributeSyntax ,
435+ declarationNode: DeclSyntax ,
436+ parentDeclNode: DeclSyntax ? ,
437+ extendedType: TypeSyntax ? ,
438+ conformanceList: InheritedTypeListSyntax ? ,
439+ in context: Context ,
440+ indentationWidth: Trivia ? = nil
441+ ) -> String ? {
442+ expandAttachedMacro (
443+ definition: definition,
444+ macroRole: macroRole,
445+ attributeNode: attributeNode,
446+ node: declarationNode,
447+ parentDeclNode: parentDeclNode,
448+ extendedType: extendedType,
449+ conformanceList: conformanceList,
450+ in: context,
451+ indentationWidth: indentationWidth
452+ )
453+ }
454+
455+ /// Expand `@attached(XXX)` macros.
456+ ///
457+ /// - Parameters:
458+ /// - definition: a type that conforms to one or more attached `Macro` protocols.
459+ /// - macroRole: indicates which `Macro` protocol expansion should be performed
460+ /// - attributeNode: attribute syntax node (e.g. `@macroName(argument)`).
461+ /// - node: target declaration syntax node to apply the expansion. This is either
462+ /// a declaration or a closure syntax node.
463+ /// - parentDeclNode: Only used for `MacroRole.memberAttribute`. The parent
464+ /// context node of `declarationNode`.
465+ /// - context: context of the expansion.
466+ /// - indentationWidth: The indentation that should be added for each additional
467+ /// nesting level
468+ /// - Returns: expanded source text. Upon failure (i.e. `defintion.expansion()`
469+ /// throws) returns `nil`, and the diagnostics representing the `Error` are
470+ /// guaranteed to be added to context.
389471public func expandAttachedMacro< Context: MacroExpansionContext > (
390472 definition: Macro . Type ,
391473 macroRole: MacroRole ,
392474 attributeNode: AttributeSyntax ,
393- declarationNode : some SyntaxProtocol ,
475+ node : some SyntaxProtocol ,
394476 parentDeclNode: DeclSyntax ? ,
395477 extendedType: TypeSyntax ? ,
396478 conformanceList: InheritedTypeListSyntax ? ,
@@ -401,7 +483,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
401483 definition: definition,
402484 macroRole: macroRole,
403485 attributeNode: attributeNode,
404- declarationNode : declarationNode ,
486+ node : node ,
405487 parentDeclNode: parentDeclNode,
406488 extendedType: extendedType,
407489 conformanceList: conformanceList,
@@ -421,7 +503,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
421503 return collapse (
422504 expansions: expandedSources,
423505 for: macroRole,
424- attachedTo: declarationNode ,
506+ attachedTo: node ,
425507 indentationWidth: collapseIndentationWidth
426508 )
427509 }
0 commit comments