Files
swift-mirror/test/Frontend/DiagnosticVerifier/Inputs/macro/unstringify-macro.swift
Henrik G. Olsson 040c9e6729 [macros] add -Rmacro-expansions
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.
2025-11-05 18:45:34 -08:00

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)")]
}
}
}