@@ -27,6 +27,7 @@ using namespace swift;
27
27
#if SWIFT_BUILD_SWIFT_SYNTAX
28
28
// / Enqueue a diagnostic with ASTGen's diagnostic rendering.
29
29
static void addQueueDiagnostic (void *queuedDiagnostics,
30
+ void *perFrontendState,
30
31
const DiagnosticInfo &info, SourceManager &SM) {
31
32
llvm::SmallString<256 > text;
32
33
{
@@ -69,7 +70,8 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
69
70
documentationPath = info.EducationalNotePaths [0 ];
70
71
71
72
// FIXME: Translate Fix-Its.
72
- swift_ASTGen_addQueuedDiagnostic (queuedDiagnostics, text.data (), text.size (),
73
+ swift_ASTGen_addQueuedDiagnostic (queuedDiagnostics, perFrontendState,
74
+ text.data (), text.size (),
73
75
severity, info.Loc .getOpaquePointerValue (),
74
76
info.Category .data (),
75
77
info.Category .size (),
@@ -82,20 +84,25 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
82
84
// argument to `swift_ASTGen_addQueuedDiagnostic` but that requires
83
85
// bridging of `Note` structure and new serialization.
84
86
for (auto *childNote : info.ChildDiagnosticInfo ) {
85
- addQueueDiagnostic (queuedDiagnostics, *childNote, SM);
87
+ addQueueDiagnostic (queuedDiagnostics, perFrontendState, *childNote, SM);
86
88
}
87
89
}
88
90
89
91
void DiagnosticBridge::enqueueDiagnostic (SourceManager &SM,
90
92
const DiagnosticInfo &Info,
91
93
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
+
92
99
// If there are no enqueued diagnostics, or we have hit a non-note
93
100
// diagnostic, flush any enqueued diagnostics and start fresh.
94
101
if (!queuedDiagnostics)
95
102
queuedDiagnostics = swift_ASTGen_createQueuedDiagnostics ();
96
103
97
104
queueBuffer (SM, innermostBufferID);
98
- addQueueDiagnostic (queuedDiagnostics, Info, SM);
105
+ addQueueDiagnostic (queuedDiagnostics, perFrontendState, Info, SM);
99
106
}
100
107
101
108
void DiagnosticBridge::flush (llvm::raw_ostream &OS, bool includeTrailingBreak,
@@ -120,6 +127,22 @@ void DiagnosticBridge::flush(llvm::raw_ostream &OS, bool includeTrailingBreak,
120
127
OS << " \n " ;
121
128
}
122
129
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
+
123
146
void *DiagnosticBridge::getSourceFileSyntax (SourceManager &sourceMgr,
124
147
unsigned bufferID,
125
148
StringRef displayName) {
@@ -199,6 +222,10 @@ DiagnosticBridge::getSourceBufferStack(SourceManager &sourceMgr,
199
222
}
200
223
201
224
DiagnosticBridge::~DiagnosticBridge () {
225
+ if (perFrontendState) {
226
+ swift_ASTGen_destroyPerFrontendDiagnosticState (perFrontendState);
227
+ }
228
+
202
229
assert (!queuedDiagnostics && " unflushed diagnostics" );
203
230
for (const auto &sourceFileSyntax : sourceFileSyntax) {
204
231
swift_ASTGen_destroySourceFile (sourceFileSyntax.second );
0 commit comments