@@ -27,6 +27,7 @@ using namespace swift;
2727#if SWIFT_BUILD_SWIFT_SYNTAX
2828// / Enqueue a diagnostic with ASTGen's diagnostic rendering.
2929static void addQueueDiagnostic (void *queuedDiagnostics,
30+ void *perFrontendState,
3031 const DiagnosticInfo &info, SourceManager &SM) {
3132 llvm::SmallString<256 > text;
3233 {
@@ -69,7 +70,8 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
6970 documentationPath = info.EducationalNotePaths [0 ];
7071
7172 // FIXME: Translate Fix-Its.
72- swift_ASTGen_addQueuedDiagnostic (queuedDiagnostics, text.data (), text.size (),
73+ swift_ASTGen_addQueuedDiagnostic (queuedDiagnostics, perFrontendState,
74+ text.data (), text.size (),
7375 severity, info.Loc .getOpaquePointerValue (),
7476 info.Category .data (),
7577 info.Category .size (),
@@ -82,20 +84,25 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
8284 // argument to `swift_ASTGen_addQueuedDiagnostic` but that requires
8385 // bridging of `Note` structure and new serialization.
8486 for (auto *childNote : info.ChildDiagnosticInfo ) {
85- addQueueDiagnostic (queuedDiagnostics, *childNote, SM);
87+ addQueueDiagnostic (queuedDiagnostics, perFrontendState, *childNote, SM);
8688 }
8789}
8890
8991void DiagnosticBridge::enqueueDiagnostic (SourceManager &SM,
9092 const DiagnosticInfo &Info,
9193 unsigned innermostBufferID) {
94+ // If we didn't have per-frontend state before, create it now.
95+ if (!perFrontendState) {
96+ perFrontendState = swift_ASTGen_createPerFrontendDiagnosticState ();
97+ }
98+
9299 // If there are no enqueued diagnostics, or we have hit a non-note
93100 // diagnostic, flush any enqueued diagnostics and start fresh.
94101 if (!queuedDiagnostics)
95102 queuedDiagnostics = swift_ASTGen_createQueuedDiagnostics ();
96103
97104 queueBuffer (SM, innermostBufferID);
98- addQueueDiagnostic (queuedDiagnostics, Info, SM);
105+ addQueueDiagnostic (queuedDiagnostics, perFrontendState, Info, SM);
99106}
100107
101108void DiagnosticBridge::flush (llvm::raw_ostream &OS, bool includeTrailingBreak,
@@ -120,6 +127,22 @@ void DiagnosticBridge::flush(llvm::raw_ostream &OS, bool includeTrailingBreak,
120127 OS << " \n " ;
121128}
122129
130+ void DiagnosticBridge::printCategoryFootnotes (llvm::raw_ostream &os,
131+ bool forceColors) {
132+ if (!perFrontendState)
133+ return ;
134+
135+ BridgedStringRef bridgedRenderedString{nullptr , 0 };
136+ swift_ASTGen_renderCategoryFootnotes (
137+ perFrontendState, forceColors ? 1 : 0 , &bridgedRenderedString);
138+
139+ auto renderedString = bridgedRenderedString.unbridged ();
140+ if (auto renderedData = renderedString.data ()) {
141+ os.write (renderedData, renderedString.size ());
142+ swift_ASTGen_freeBridgedString (renderedString);
143+ }
144+ }
145+
123146void *DiagnosticBridge::getSourceFileSyntax (SourceManager &sourceMgr,
124147 unsigned bufferID,
125148 StringRef displayName) {
@@ -199,6 +222,10 @@ DiagnosticBridge::getSourceBufferStack(SourceManager &sourceMgr,
199222}
200223
201224DiagnosticBridge::~DiagnosticBridge () {
225+ if (perFrontendState) {
226+ swift_ASTGen_destroyPerFrontendDiagnosticState (perFrontendState);
227+ }
228+
202229 assert (!queuedDiagnostics && " unflushed diagnostics" );
203230 for (const auto &sourceFileSyntax : sourceFileSyntax) {
204231 swift_ASTGen_destroySourceFile (sourceFileSyntax.second );
0 commit comments