@@ -101,16 +101,9 @@ void FileSpecificDiagnosticConsumer::computeConsumersOrderedByRange(
101
101
" overlapping ranges despite having distinct files" );
102
102
}
103
103
104
- Optional<DiagnosticConsumer *>
105
- FileSpecificDiagnosticConsumer::consumerForLocation (SourceManager &SM,
106
- SourceLoc loc) const {
107
- // If there's only one consumer, we'll use it no matter what, because...
108
- // - ...all diagnostics within the file will go to that consumer.
109
- // - ...all diagnostics not within the file will not be claimed by any
110
- // consumer, and so will go to all (one) consumers.
111
- if (SubConsumers.size () == 1 )
112
- return SubConsumers.front ().second .get ();
113
-
104
+ Optional<FileSpecificDiagnosticConsumer::ConsumerSpecificInformation *>
105
+ FileSpecificDiagnosticConsumer::consumerSpecificInformationForLocation (
106
+ SourceManager &SM, SourceLoc loc) const {
114
107
// Diagnostics with invalid locations always go to every consumer.
115
108
if (loc.isInvalid ())
116
109
return None;
@@ -141,17 +134,19 @@ FileSpecificDiagnosticConsumer::consumerForLocation(SourceManager &SM,
141
134
// that /might/ contain 'loc'. Specifically, since the ranges are sorted
142
135
// by end location, it's looking for the first range where the end location
143
136
// is greater than or equal to 'loc'.
144
- auto possiblyContainingRangeIter = std::lower_bound (
145
- ConsumersOrderedByRange.begin (), ConsumersOrderedByRange.end (), loc,
146
- [](const ConsumerSpecificInformation &entry, SourceLoc loc) -> bool {
147
- auto compare = std::less<const char *>();
148
- return compare (getRawLoc (entry.range .getEnd ()).getPointer (),
149
- getRawLoc (loc).getPointer ());
150
- });
137
+ const ConsumerSpecificInformation *possiblyContainingRangeIter =
138
+ std::lower_bound (
139
+ ConsumersOrderedByRange.begin (), ConsumersOrderedByRange.end (), loc,
140
+ [](const ConsumerSpecificInformation &entry, SourceLoc loc) -> bool {
141
+ auto compare = std::less<const char *>();
142
+ return compare (getRawLoc (entry.range .getEnd ()).getPointer (),
143
+ getRawLoc (loc).getPointer ());
144
+ });
151
145
152
146
if (possiblyContainingRangeIter != ConsumersOrderedByRange.end () &&
153
147
possiblyContainingRangeIter->range .contains (loc)) {
154
- return possiblyContainingRangeIter->consumer ;
148
+ return const_cast <ConsumerSpecificInformation *>(
149
+ possiblyContainingRangeIter);
155
150
}
156
151
157
152
return None;
@@ -162,31 +157,36 @@ void FileSpecificDiagnosticConsumer::handleDiagnostic(
162
157
StringRef FormatString, ArrayRef<DiagnosticArgument> FormatArgs,
163
158
const DiagnosticInfo &Info) {
164
159
165
- Optional<DiagnosticConsumer *> specificConsumer ;
160
+ Optional<ConsumerSpecificInformation *> consumerSpecificInfo ;
166
161
switch (Kind) {
167
162
case DiagnosticKind::Error:
168
163
case DiagnosticKind::Warning:
169
164
case DiagnosticKind::Remark:
170
- specificConsumer = consumerForLocation (SM, Loc);
171
- ConsumerForSubsequentNotes = specificConsumer ;
165
+ consumerSpecificInfo = consumerSpecificInformationForLocation (SM, Loc);
166
+ ConsumerSpecificInfoForSubsequentNotes = consumerSpecificInfo ;
172
167
break ;
173
168
case DiagnosticKind::Note:
174
- specificConsumer = ConsumerForSubsequentNotes ;
169
+ consumerSpecificInfo = ConsumerSpecificInfoForSubsequentNotes ;
175
170
break ;
176
171
}
177
-
178
- if (!specificConsumer.hasValue ()) {
172
+ if (!consumerSpecificInfo.hasValue ()) {
179
173
for (auto &subConsumer : SubConsumers) {
180
174
if (subConsumer.second ) {
181
175
subConsumer.second ->handleDiagnostic (SM, Loc, Kind, FormatString,
182
176
FormatArgs, Info);
183
177
}
184
178
}
185
- } else if (DiagnosticConsumer *c = specificConsumer. getValue ())
186
- c-> handleDiagnostic (SM, Loc, Kind, FormatString, FormatArgs, Info);
187
- else
179
+ return ;
180
+ }
181
+ if (!consumerSpecificInfo. getValue ()-> consumer ) {
188
182
WasAnErrorSuppressed =
189
183
true ; // Suppress non-primary diagnostic in batch mode.
184
+ return ;
185
+ }
186
+ consumerSpecificInfo.getValue ()->consumer ->handleDiagnostic (
187
+ SM, Loc, Kind, FormatString, FormatArgs, Info);
188
+ consumerSpecificInfo.getValue ()->hasAnErrorBeenEmitted |=
189
+ Kind == DiagnosticKind::Error;
190
190
}
191
191
192
192
bool FileSpecificDiagnosticConsumer::finishProcessing (SourceManager &SM) {
0 commit comments