@@ -102,6 +102,12 @@ class ClangTidyContext {
102102 // / \brief Initializes \c ClangTidyContext instance.
103103 ClangTidyContext (std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
104104 bool AllowEnablingAnalyzerAlphaCheckers = false );
105+ // / Sets the DiagnosticsEngine that diag() will emit diagnostics to.
106+ // FIXME: this is required initialization, and should be a constructor param.
107+ // Fix the context -> diag engine -> consumer -> context initialization cycle.
108+ void setDiagnosticsEngine (DiagnosticsEngine *DiagEngine) {
109+ this ->DiagEngine = DiagEngine;
110+ }
105111
106112 ~ClangTidyContext ();
107113
@@ -160,12 +166,6 @@ class ClangTidyContext {
160166 // / counters.
161167 const ClangTidyStats &getStats () const { return Stats; }
162168
163- // / \brief Returns all collected errors.
164- ArrayRef<ClangTidyError> getErrors () const { return Errors; }
165-
166- // / \brief Clears collected errors.
167- void clearErrors () { Errors.clear (); }
168-
169169 // / \brief Control profile collection in clang-tidy.
170170 void setEnableProfiling (bool Profile);
171171 bool getEnableProfiling () const { return Profile; }
@@ -192,18 +192,9 @@ class ClangTidyContext {
192192 }
193193
194194private:
195- // Calls setDiagnosticsEngine() and storeError() .
195+ // Writes to Stats .
196196 friend class ClangTidyDiagnosticConsumer ;
197- friend class ClangTidyPluginAction ;
198-
199- // / \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated
200- // / correctly.
201- void setDiagnosticsEngine (DiagnosticsEngine *Engine);
202197
203- // / \brief Store an \p Error.
204- void storeError (const ClangTidyError &Error);
205-
206- std::vector<ClangTidyError> Errors;
207198 DiagnosticsEngine *DiagEngine;
208199 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
209200
@@ -243,27 +234,25 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
243234 void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel,
244235 const Diagnostic &Info) override ;
245236
246- // / \brief Flushes the internal diagnostics buffer to the ClangTidyContext .
247- void finish () override ;
237+ // Retrieve the diagnostics that were captured .
238+ std::vector<ClangTidyError> take () ;
248239
249240private:
250241 void finalizeLastError ();
251-
252- void removeIncompatibleErrors (SmallVectorImpl<ClangTidyError> &Errors) const ;
242+ void removeIncompatibleErrors ();
253243
254244 // / \brief Returns the \c HeaderFilter constructed for the options set in the
255245 // / context.
256246 llvm::Regex *getHeaderFilter ();
257247
258248 // / \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
259249 // / according to the diagnostic \p Location.
260- void checkFilters (SourceLocation Location);
250+ void checkFilters (SourceLocation Location, const SourceManager& Sources );
261251 bool passesLineFilter (StringRef FileName, unsigned LineNumber) const ;
262252
263253 ClangTidyContext &Context;
264254 bool RemoveIncompatibleErrors;
265- std::unique_ptr<DiagnosticsEngine> Diags;
266- SmallVector<ClangTidyError, 8 > Errors;
255+ std::vector<ClangTidyError> Errors;
267256 std::unique_ptr<llvm::Regex> HeaderFilter;
268257 bool LastErrorRelatesToUserCode;
269258 bool LastErrorPassesLineFilter;
0 commit comments