[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
authorSam McCall <sam.mccall@gmail.com>
Fri, 2 Nov 2018 10:01:59 +0000 (10:01 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 2 Nov 2018 10:01:59 +0000 (10:01 +0000)
commitcb50e23ba86ecfbb22f0eb1eec2fde9cc0c55569
tree1b20436cdd349fdeebc06a52c670ee1d07b4ea09
parent31d012eb2f2d839c0e37bf65bb868441b90b3e33
[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC

Summary:
Currently ClangTidyContext::diag() sends the diagnostics to a
DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer,
which is supposed to go back and populate ClangTidyContext::Errors.

After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer
itself and can be retrieved from there.

Why?
 - the round-trip from context -> engine -> consumer -> context is confusing
   and makes it harder to establish layering between these things.
 - context does too many things, and makes it hard to use clang-tidy as a library
 - everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer

The most natural implementation (ClangTidyDiagnosticsConsumer::take()
finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp
asserts that clang-tidy exits successfully when trying to process a file
that doesn't exist.
In clang-tidy today, this happens because finish() is never called, so the
diagnostic is never flushed. This looks like a bug to me.
For now, this patch carefully preserves that behavior, but I'll ping the
authors to see whether it's deliberate and worth preserving.

Reviewers: hokein

Subscribers: xazax.hun, cfe-commits, alexfh

Differential Revision: https://reviews.llvm.org/D53953

llvm-svn: 345961
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidy.h
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/test/clang-tidy/clang-tidy-run-with-database.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h