@@ -179,6 +179,53 @@ fileprivate func identifierFromStringLiteral(_ node: ExprSyntax) -> String? {
179179 return stringSegment. content. text
180180}
181181
182+ /// Checks if the macro expression used as an default argument has any issues.
183+ ///
184+ /// - Returns: `true` if all restrictions are satisfied, `false` if diagnostics
185+ /// are emitted.
186+ @_cdecl ( " swift_ASTGen_checkDefaultArgumentMacroExpression " )
187+ func checkDefaultArgumentMacroExpression(
188+ diagEnginePtr: UnsafeMutableRawPointer ,
189+ sourceFilePtr: UnsafeRawPointer ,
190+ macroLocationPtr: UnsafePointer < UInt8 >
191+ ) -> Bool {
192+ let sourceFilePtr = sourceFilePtr. bindMemory ( to: ExportedSourceFile . self, capacity: 1 )
193+
194+ // Find the macro expression.
195+ guard
196+ let macroExpr = findSyntaxNodeInSourceFile (
197+ sourceFilePtr: sourceFilePtr,
198+ sourceLocationPtr: macroLocationPtr,
199+ type: MacroExpansionExprSyntax . self
200+ )
201+ else {
202+ // FIXME: Produce an error
203+ return false
204+ }
205+
206+ do {
207+ try macroExpr. checkDefaultArgumentMacroExpression ( )
208+ return true
209+ } catch let errDiags as DiagnosticsError {
210+ let srcMgr = SourceManager ( cxxDiagnosticEngine: diagEnginePtr)
211+ srcMgr. insert ( sourceFilePtr)
212+ for diag in errDiags. diagnostics {
213+ srcMgr. diagnose ( diagnostic: diag)
214+ }
215+ return false
216+ } catch let error {
217+ let srcMgr = SourceManager ( cxxDiagnosticEngine: diagEnginePtr)
218+ srcMgr. insert ( sourceFilePtr)
219+ srcMgr. diagnose (
220+ diagnostic: . init(
221+ node: macroExpr,
222+ message: ASTGenMacroDiagnostic . thrownError ( error)
223+ )
224+ )
225+ return false
226+ }
227+ }
228+
182229/// Check a macro definition, producing a description of that macro definition
183230/// for use in macro expansion.
184231///
0 commit comments