@@ -17,17 +17,6 @@ import SwiftSyntaxBuilder
1717/// Interface to extract information about the context in which a given
1818/// macro is expanded.
1919public protocol MacroExpansionContext : AnyObject {
20- /// Generate a unique name for use in the macro.
21- ///
22- /// - Parameters:
23- /// - name: The name to use as a basis for the uniquely-generated name,
24- /// which will appear in the unique name that's produced here.
25- ///
26- /// - Returns: an identifier token containing a unique name that will not
27- /// conflict with any other name in a well-formed program.
28- @available ( * , renamed: " makeUniqueName(_:) " )
29- func createUniqueName( _ name: String ) -> TokenSyntax
30-
3120 /// Generate a unique name for use in the macro.
3221 ///
3322 /// - Parameters:
@@ -53,26 +42,6 @@ public protocol MacroExpansionContext: AnyObject {
5342 /// - Returns: the source location within the given node, or `nil` if the
5443 /// given syntax node is not rooted in a source file that the macro
5544 /// expansion context knows about.
56- @available ( * , deprecated, message: " Please use AbstractSourceLocation version " )
57- func location< Node: SyntaxProtocol > (
58- of node: Node ,
59- at position: PositionInSyntaxNode ,
60- filePathMode: SourceLocationFilePathMode
61- ) -> SourceLocation ?
62-
63- /// Retrieve a source location for the given syntax node.
64- ///
65- /// - Parameters:
66- /// - node: The syntax node whose source location to produce.
67- /// - position: The position within the syntax node for the resulting
68- /// location.
69- /// - filePathMode: How the file name contained in the source location is
70- /// formed.
71- ///
72- /// - Returns: the source location within the given node, or `nil` if the
73- /// given syntax node is not rooted in a source file that the macro
74- /// expansion context knows about.
75- @_disfavoredOverload
7645 func location< Node: SyntaxProtocol > (
7746 of node: Node ,
7847 at position: PositionInSyntaxNode ,
@@ -90,87 +59,13 @@ extension MacroExpansionContext {
9059 /// - Returns: the source location within the given node, or `nil` if the
9160 /// given syntax node is not rooted in a source file that the macro
9261 /// expansion context knows about.
93- @available ( * , deprecated, message: " Please use AbstractSourceLocation version " )
94- public func location< Node: SyntaxProtocol > (
95- of node: Node
96- ) -> SourceLocation ? {
97- return location ( of: node, at: . afterLeadingTrivia, filePathMode: . fileID)
98- }
99-
100- /// Retrieve a source location for the given syntax node's starting token
101- /// (after leading trivia) using file naming according to `#fileID`.
102- ///
103- /// - Parameters:
104- /// - node: The syntax node whose source location to produce.
105- ///
106- /// - Returns: the source location within the given node, or `nil` if the
107- /// given syntax node is not rooted in a source file that the macro
108- /// expansion context knows about.
109- @_disfavoredOverload
11062 public func location< Node: SyntaxProtocol > (
11163 of node: Node
11264 ) -> AbstractSourceLocation ? {
11365 return location ( of: node, at: . afterLeadingTrivia, filePathMode: . fileID)
11466 }
11567}
11668
117- extension MacroExpansionContext {
118- /// Retrieve a source location for the given syntax node.
119- ///
120- /// - Parameters:
121- /// - node: The syntax node whose source location to produce.
122- /// - position: The position within the syntax node for the resulting
123- /// location.
124- /// - filePathMode: How the file name contained in the source location is
125- /// formed.
126- ///
127- /// - Returns: the source location within the given node, or `nil` if the
128- /// given syntax node is not rooted in a source file that the macro
129- /// expansion context knows about.
130- @_disfavoredOverload
131- @available ( * , deprecated, message: " Please use AbstractSourceLocation version " )
132- public func location< Node: SyntaxProtocol > (
133- of node: Node ,
134- at position: PositionInSyntaxNode ,
135- filePathMode: SourceLocationFilePathMode
136- ) -> AbstractSourceLocation ? {
137- guard let sourceLoc: SourceLocation = location ( of: node, at: position, filePathMode: filePathMode) else {
138- return nil
139- }
140-
141- return AbstractSourceLocation (
142- file: " \( literal: sourceLoc. file) " ,
143- line: " \( literal: sourceLoc. line) " ,
144- column: " \( literal: sourceLoc. column) "
145- )
146- }
147-
148- /// Generate a unique name for use in the macro.
149- ///
150- /// - Parameters:
151- /// - name: The name to use as a basis for the uniquely-generated name,
152- /// which will appear in the unique name that's produced here.
153- ///
154- /// - Returns: an identifier token containing a unique name that will not
155- /// conflict with any other name in a well-formed program.
156- @available ( * , renamed: " makeUniqueName(_:) " )
157- public func createUniqueName( _ name: String ) -> TokenSyntax {
158- makeUniqueName ( name)
159- }
160-
161- /// Generate a unique name for use in the macro.
162- ///
163- /// - Parameters:
164- /// - name: The name to use as a basis for the uniquely-generated name,
165- /// which will appear in the unique name that's produced here.
166- ///
167- /// - Returns: an identifier token containing a unique name that will not
168- /// conflict with any other name in a well-formed program.
169- public func makeUniqueName( _ name: String ) -> TokenSyntax {
170- createUniqueName ( name)
171- }
172- }
173-
17469/// Diagnostic message used for thrown errors.
17570private struct ThrownErrorDiagnostic : DiagnosticMessage {
17671 let message : String
0 commit comments