checkFilters(Info.getLocation());
}
-void ClangTidyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
- const Preprocessor *PP) {
- // Before the first translation unit we don't need HeaderFilter, as we
- // shouldn't get valid source locations in diagnostics.
- HeaderFilter.reset(new llvm::Regex(*Context.getOptions().HeaderFilterRegex));
-}
-
bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
unsigned LineNumber) const {
if (Context.getGlobalOptions().LineFilter.empty())
}
StringRef FileName(File->getName());
- assert(LastErrorRelatesToUserCode || Sources.isInMainFile(Location) ||
- HeaderFilter != nullptr);
LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
- HeaderFilter->match(FileName);
+ getHeaderFilter()->match(FileName);
unsigned LineNumber = Sources.getExpansionLineNumber(Location);
LastErrorPassesLineFilter =
LastErrorPassesLineFilter || passesLineFilter(FileName, LineNumber);
}
+llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
+ if (!HeaderFilter)
+ HeaderFilter.reset(
+ new llvm::Regex(*Context.getOptions().HeaderFilterRegex));
+ return HeaderFilter.get();
+}
+
namespace {
struct LessClangTidyError {
bool operator()(const ClangTidyError *LHS, const ClangTidyError *RHS) const {
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info) override;
- /// \brief Sets \c HeaderFilter to the value configured for this file.
- void BeginSourceFile(const LangOptions &LangOpts,
- const Preprocessor *PP) override;
-
/// \brief Flushes the internal diagnostics buffer to the ClangTidyContext.
void finish() override;
private:
void finalizeLastError();
+ /// \brief Returns the \c HeaderFilter constructed for the options set in the
+ /// context.
+ llvm::Regex* getHeaderFilter();
+
/// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
/// according to the diagnostic \p Location.
void checkFilters(SourceLocation Location);