mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This adds the -Rmacro-expansions flag. It provides similar functionality to -dump-macro-expansions, but instead of dumping the macro expansion to stderr, it emits it line by line as remarks. This is useful for testing with -verify, where both macro expansion content and warnings need to be tested at the same time.
20 lines
634 B
Swift
20 lines
634 B
Swift
import SwiftSyntax
|
|
import SwiftSyntaxBuilder
|
|
import SwiftSyntaxMacros
|
|
|
|
public struct UnstringifyPeerMacro: PeerMacro {
|
|
public static func expansion(
|
|
of node: AttributeSyntax,
|
|
providingPeersOf declaration: some DeclSyntaxProtocol,
|
|
in context: some MacroExpansionContext
|
|
) throws -> [DeclSyntax] {
|
|
do {
|
|
let argumentList = node.arguments!.as(LabeledExprListSyntax.self)!
|
|
let arguments = [LabeledExprSyntax](argumentList)
|
|
let arg = arguments.first!.expression.as(StringLiteralExprSyntax.self)!
|
|
let content = arg.representedLiteralValue!
|
|
return [DeclSyntax("\(raw: content)")]
|
|
}
|
|
}
|
|
}
|