|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import SwiftSyntax |
| 14 | +import SwiftSyntaxMacros |
| 15 | + |
| 16 | +public struct NativeFileIDMacro: ExpressionMacro { |
| 17 | + public static func expansion( |
| 18 | + of node: some FreestandingMacroExpansionSyntax, |
| 19 | + in context: some MacroExpansionContext |
| 20 | + ) -> ExprSyntax { |
| 21 | + return context.location( |
| 22 | + of: node, |
| 23 | + at: .afterLeadingTrivia, |
| 24 | + filePathMode: .fileID |
| 25 | + )!.file |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +public struct NativeFilePathMacro: ExpressionMacro { |
| 30 | + public static func expansion( |
| 31 | + of node: some FreestandingMacroExpansionSyntax, |
| 32 | + in context: some MacroExpansionContext |
| 33 | + ) -> ExprSyntax { |
| 34 | + return context.location( |
| 35 | + of: node, |
| 36 | + at: .afterLeadingTrivia, |
| 37 | + filePathMode: .filePath |
| 38 | + )!.file |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +public struct NativeLineMacro: ExpressionMacro { |
| 43 | + public static func expansion( |
| 44 | + of node: some FreestandingMacroExpansionSyntax, |
| 45 | + in context: some MacroExpansionContext |
| 46 | + ) -> ExprSyntax { |
| 47 | + return context.location(of: node)!.line |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +public struct NativeColumnMacro: ExpressionMacro { |
| 52 | + public static func expansion( |
| 53 | + of node: some FreestandingMacroExpansionSyntax, |
| 54 | + in context: some MacroExpansionContext |
| 55 | + ) -> ExprSyntax { |
| 56 | + return context.location(of: node)!.column |
| 57 | + } |
| 58 | +} |
0 commit comments