@@ -79,7 +79,7 @@ class DiagnosticConsumer {
7979
8080public:
8181 virtual ~DiagnosticConsumer ();
82-
82+
8383 // / Invoked whenever the frontend emits a diagnostic.
8484 // /
8585 // / \param SM The source manager associated with the source locations in
@@ -94,11 +94,20 @@ class DiagnosticConsumer {
9494 // / \param FormatArgs The diagnostic format string arguments.
9595 // /
9696 // / \param Info Extra information associated with the diagnostic.
97- virtual void handleDiagnostic (SourceManager &SM, SourceLoc Loc,
98- DiagnosticKind Kind,
99- StringRef FormatString,
100- ArrayRef<DiagnosticArgument> FormatArgs,
101- const DiagnosticInfo &Info) = 0;
97+ // /
98+ // / \param bufferIndirectlyCausingDiagnostic Only used when directing
99+ // / diagnostics to different outputs.
100+ // / In batch mode a diagnostic may be
101+ // / located in a non-primary file, but there will be no .dia file for a
102+ // / non-primary. If valid, this argument contains a location within a buffer
103+ // / that corresponds to a primary input. The .dia file for that primary can be
104+ // / used for the diagnostic, as if it had occurred at this location.
105+ virtual void
106+ handleDiagnostic (SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
107+ StringRef FormatString,
108+ ArrayRef<DiagnosticArgument> FormatArgs,
109+ const DiagnosticInfo &Info,
110+ SourceLoc bufferIndirectlyCausingDiagnostic) = 0 ;
102111
103112 // / \returns true if an error occurred while finishing-up.
104113 virtual bool finishProcessing () { return false ; }
@@ -116,11 +125,11 @@ class DiagnosticConsumer {
116125// / DiagnosticConsumer that discards all diagnostics.
117126class NullDiagnosticConsumer : public DiagnosticConsumer {
118127public:
119- void handleDiagnostic (SourceManager &SM, SourceLoc Loc,
120- DiagnosticKind Kind,
128+ void handleDiagnostic (SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
121129 StringRef FormatString,
122130 ArrayRef<DiagnosticArgument> FormatArgs,
123- const DiagnosticInfo &Info) override ;
131+ const DiagnosticInfo &Info,
132+ SourceLoc bufferIndirectlyCausingDiagnostic) override ;
124133};
125134
126135// / DiagnosticConsumer that forwards diagnostics to the consumers of
@@ -129,11 +138,11 @@ class ForwardingDiagnosticConsumer : public DiagnosticConsumer {
129138 DiagnosticEngine &TargetEngine;
130139public:
131140 ForwardingDiagnosticConsumer (DiagnosticEngine &Target);
132- void handleDiagnostic (SourceManager &SM, SourceLoc Loc,
133- DiagnosticKind Kind,
141+ void handleDiagnostic (SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
134142 StringRef FormatString,
135143 ArrayRef<DiagnosticArgument> FormatArgs,
136- const DiagnosticInfo &Info) override ;
144+ const DiagnosticInfo &Info,
145+ SourceLoc bufferIndirectlyCausingDiagnostic) override ;
137146};
138147
139148// / DiagnosticConsumer that funnels diagnostics in certain files to
@@ -175,8 +184,12 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
175184 std::string inputFileName;
176185
177186 // / The consumer (if any) for diagnostics associated with the inputFileName.
178- // / A null pointer for the DiagnosticConsumer means that diagnostics for
179- // / this file should not be emitted.
187+ // / A null pointer for the DiagnosticConsumer means that this file is a
188+ // / non-primary one in batch mode and we have no .dia file for it.
189+ // / If there is a responsible primary when the diagnostic is handled
190+ // / it will be shunted to that primary's .dia file.
191+ // / Otherwise it will be suppressed, assuming that the diagnostic will
192+ // / surface in another frontend job that compiles that file as a primary.
180193 std::unique_ptr<DiagnosticConsumer> consumer;
181194
182195 // Has this subconsumer ever handled a diagnostic that is an error?
@@ -191,16 +204,16 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
191204 std::unique_ptr<DiagnosticConsumer> consumer)
192205 : inputFileName(inputFileName), consumer(std::move(consumer)) {}
193206
194- void handleDiagnostic (SourceManager &SM, SourceLoc Loc,
195- DiagnosticKind Kind,
207+ void handleDiagnostic (SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
196208 StringRef FormatString,
197209 ArrayRef<DiagnosticArgument> FormatArgs,
198- const DiagnosticInfo &Info) {
210+ const DiagnosticInfo &Info,
211+ const SourceLoc bufferIndirectlyCausingDiagnostic) {
199212 if (!getConsumer ())
200213 return ;
201214 hasAnErrorBeenConsumed |= Kind == DiagnosticKind::Error;
202215 getConsumer ()->handleDiagnostic (SM, Loc, Kind, FormatString, FormatArgs,
203- Info);
216+ Info, bufferIndirectlyCausingDiagnostic );
204217 }
205218
206219 void informDriverOfIncompleteBatchModeCompilation () {
@@ -287,11 +300,11 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
287300 SmallVectorImpl<Subconsumer> &consumers);
288301
289302public:
290- void handleDiagnostic (SourceManager &SM, SourceLoc Loc,
291- DiagnosticKind Kind,
303+ void handleDiagnostic (SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
292304 StringRef FormatString,
293305 ArrayRef<DiagnosticArgument> FormatArgs,
294- const DiagnosticInfo &Info) override ;
306+ const DiagnosticInfo &Info,
307+ SourceLoc bufferIndirectlyCausingDiagnostic) override ;
295308
296309 bool finishProcessing () override ;
297310
@@ -309,6 +322,14 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
309322 // / a particular consumer if diagnostic goes there.
310323 Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
311324 subconsumerForLocation (SourceManager &SM, SourceLoc loc);
325+
326+ Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
327+ findSubconsumer (SourceManager &SM, SourceLoc loc, DiagnosticKind Kind,
328+ SourceLoc bufferIndirectlyCausingDiagnostic);
329+
330+ Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
331+ findSubconsumerForNonNote (SourceManager &SM, SourceLoc loc,
332+ SourceLoc bufferIndirectlyCausingDiagnostic);
312333};
313334
314335} // end namespace swift
0 commit comments