[clang-tools-extra] r290893 - [clang-tidy] Add check name to YAML export (clang-tools-extra part)
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 3 06:36:14 PST 2017
Author: alexfh
Date: Tue Jan 3 08:36:13 2017
New Revision: 290893
URL: http://llvm.org/viewvc/llvm-project?rev=290893&view=rev
Log:
[clang-tidy] Add check name to YAML export (clang-tools-extra part)
Add a field indicating the associated check for every replacement to the YAML
report generated with the '-export-fixes' option. Update
clang-apply-replacements to handle the new format.
Patch by Alpha Abdoulaye!
Differential revision: https://reviews.llvm.org/D26137
Modified:
clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
Modified: clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h Tue Jan 3 08:36:13 2017
@@ -16,6 +16,7 @@
#ifndef LLVM_CLANG_APPLYREPLACEMENTS_H
#define LLVM_CLANG_APPLYREPLACEMENTS_H
+#include "clang/Tooling/Core/Diagnostic.h"
#include "clang/Tooling/Refactoring.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
@@ -43,6 +44,9 @@ typedef std::vector<clang::tooling::Tran
/// \brief Collection of TranslationUnitReplacement files.
typedef std::vector<std::string> TUReplacementFiles;
+/// \brief Collection of TranslationUniDiagnostics.
+typedef std::vector<clang::tooling::TranslationUnitDiagnostics> TUDiagnostics;
+
/// \brief Map mapping file name to Replacements targeting that file.
typedef llvm::DenseMap<const clang::FileEntry *,
std::vector<clang::tooling::Replacement>>
@@ -58,8 +62,8 @@ typedef llvm::DenseMap<const clang::File
/// \param[in] Directory Directory to begin search for serialized
/// TranslationUnitReplacements.
/// \param[out] TUs Collection of all found and deserialized
-/// TranslationUnitReplacements.
-/// \param[out] TURFiles Collection of all TranslationUnitReplacement files
+/// TranslationUnitReplacements or TranslationUnitDiagnostics.
+/// \param[out] TUFiles Collection of all TranslationUnitReplacement files
/// found in \c Directory.
/// \param[in] Diagnostics DiagnosticsEngine used for error output.
///
@@ -67,7 +71,11 @@ typedef llvm::DenseMap<const clang::File
/// directory structure.
std::error_code collectReplacementsFromDirectory(
const llvm::StringRef Directory, TUReplacements &TUs,
- TUReplacementFiles &TURFiles, clang::DiagnosticsEngine &Diagnostics);
+ TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics);
+
+std::error_code collectReplacementsFromDirectory(
+ const llvm::StringRef Directory, TUDiagnostics &TUs,
+ TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics);
/// \brief Deduplicate, check for conflicts, and apply all Replacements stored
/// in \c TUs. If conflicts occur, no Replacements are applied.
@@ -75,7 +83,8 @@ std::error_code collectReplacementsFromD
/// \post For all (key,value) in GroupedReplacements, value[i].getOffset() <=
/// value[i+1].getOffset().
///
-/// \param[in] TUs Collection of TranslationUnitReplacements to merge,
+/// \param[in] TUs Collection of TranslationUnitReplacements or
+/// TranslationUnitDiagnostics to merge,
/// deduplicate, and test for conflicts.
/// \param[out] GroupedReplacements Container grouping all Replacements by the
/// file they target.
@@ -88,6 +97,10 @@ bool mergeAndDeduplicate(const TUReplace
FileToReplacementsMap &GroupedReplacements,
clang::SourceManager &SM);
+bool mergeAndDeduplicate(const TUDiagnostics &TUs,
+ FileToReplacementsMap &GroupedReplacements,
+ clang::SourceManager &SM);
+
// FIXME: Remove this function after changing clang-apply-replacements to use
// Replacements class.
bool applyAllReplacements(const std::vector<tooling::Replacement> &Replaces,
Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp Tue Jan 3 08:36:13 2017
@@ -20,6 +20,7 @@
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"
#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/FileSystem.h"
@@ -37,7 +38,7 @@ namespace replace {
std::error_code collectReplacementsFromDirectory(
const llvm::StringRef Directory, TUReplacements &TUs,
- TUReplacementFiles &TURFiles, clang::DiagnosticsEngine &Diagnostics) {
+ TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
using namespace llvm::sys::fs;
using namespace llvm::sys::path;
@@ -54,7 +55,7 @@ std::error_code collectReplacementsFromD
if (extension(I->path()) != ".yaml")
continue;
- TURFiles.push_back(I->path());
+ TUFiles.push_back(I->path());
ErrorOr<std::unique_ptr<MemoryBuffer>> Out =
MemoryBuffer::getFile(I->path());
@@ -79,6 +80,51 @@ std::error_code collectReplacementsFromD
return ErrorCode;
}
+std::error_code
+collectReplacementsFromDirectory(const llvm::StringRef Directory,
+ TUDiagnostics &TUs, TUReplacementFiles &TUFiles,
+ clang::DiagnosticsEngine &Diagnostics) {
+ using namespace llvm::sys::fs;
+ using namespace llvm::sys::path;
+
+ std::error_code ErrorCode;
+
+ for (recursive_directory_iterator I(Directory, ErrorCode), E;
+ I != E && !ErrorCode; I.increment(ErrorCode)) {
+ if (filename(I->path())[0] == '.') {
+ // Indicate not to descend into directories beginning with '.'
+ I.no_push();
+ continue;
+ }
+
+ if (extension(I->path()) != ".yaml")
+ continue;
+
+ TUFiles.push_back(I->path());
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> Out =
+ MemoryBuffer::getFile(I->path());
+ if (std::error_code BufferError = Out.getError()) {
+ errs() << "Error reading " << I->path() << ": " << BufferError.message()
+ << "\n";
+ continue;
+ }
+
+ yaml::Input YIn(Out.get()->getBuffer(), nullptr, &eatDiagnostics);
+ tooling::TranslationUnitDiagnostics TU;
+ YIn >> TU;
+ if (YIn.error()) {
+ // File doesn't appear to be a header change description. Ignore it.
+ continue;
+ }
+
+ // Only keep files that properly parse.
+ TUs.push_back(TU);
+ }
+
+ return ErrorCode;
+}
+
/// \brief Dumps information for a sequence of conflicting Replacements.
///
/// \param[in] File FileEntry for the file the conflicting Replacements are
@@ -252,6 +298,34 @@ bool mergeAndDeduplicate(const TUReplace
}
}
+ // Ask clang to deduplicate and report conflicts.
+ return !deduplicateAndDetectConflicts(GroupedReplacements, SM);
+}
+
+bool mergeAndDeduplicate(const TUDiagnostics &TUs,
+ FileToReplacementsMap &GroupedReplacements,
+ clang::SourceManager &SM) {
+
+ // Group all replacements by target file.
+ std::set<StringRef> Warned;
+ for (const auto &TU : TUs) {
+ for (const auto &D : TU.Diagnostics) {
+ for (const auto &Fix : D.Fix) {
+ for (const tooling::Replacement &R : Fix.second) {
+ // Use the file manager to deduplicate paths. FileEntries are
+ // automatically canonicalized.
+ const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath());
+ if (!Entry && Warned.insert(R.getFilePath()).second) {
+ errs() << "Described file '" << R.getFilePath()
+ << "' doesn't exist. Ignoring...\n";
+ continue;
+ }
+ GroupedReplacements[Entry].push_back(R);
+ }
+ }
+ }
+ }
+
// Ask clang to deduplicate and report conflicts.
return !deduplicateAndDetectConflicts(GroupedReplacements, SM);
}
Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp Tue Jan 3 08:36:13 2017
@@ -66,7 +66,7 @@ static cl::opt<std::string>
cl::init("LLVM"), cl::cat(FormattingCategory));
namespace {
-// Helper object to remove the TUReplacement files (triggered by
+// Helper object to remove the TUReplacement and TUDiagnostic (triggered by
// "remove-change-desc-files" command line option) when exiting current scope.
class ScopedFileRemover {
public:
@@ -211,11 +211,16 @@ int main(int argc, char **argv) {
if (DoFormat)
FormatStyle = format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM");
- TUReplacements TUs;
- TUReplacementFiles TURFiles;
+ TUReplacements TURs;
+ TUReplacementFiles TUFiles;
std::error_code ErrorCode =
- collectReplacementsFromDirectory(Directory, TUs, TURFiles, Diagnostics);
+ collectReplacementsFromDirectory(Directory, TURs, TUFiles, Diagnostics);
+
+ TUDiagnostics TUDs;
+ TUFiles.clear();
+ ErrorCode =
+ collectReplacementsFromDirectory(Directory, TUDs, TUFiles, Diagnostics);
if (ErrorCode) {
errs() << "Trouble iterating over directory '" << Directory
@@ -227,13 +232,15 @@ int main(int argc, char **argv) {
// command line option) when exiting main().
std::unique_ptr<ScopedFileRemover> Remover;
if (RemoveTUReplacementFiles)
- Remover.reset(new ScopedFileRemover(TURFiles, Diagnostics));
+ Remover.reset(new ScopedFileRemover(TUFiles, Diagnostics));
FileManager Files((FileSystemOptions()));
SourceManager SM(Diagnostics, Files);
FileToReplacementsMap GroupedReplacements;
- if (!mergeAndDeduplicate(TUs, GroupedReplacements, SM))
+ if (!mergeAndDeduplicate(TURs, GroupedReplacements, SM))
+ return 1;
+ if (!mergeAndDeduplicate(TUDs, GroupedReplacements, SM))
return 1;
Rewriter ReplacementsRewriter(SM, LangOptions());
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Tue Jan 3 08:36:13 2017
@@ -35,6 +35,7 @@
#include "clang/Rewrite/Frontend/FrontendActions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "clang/Tooling/Tooling.h"
@@ -102,14 +103,14 @@ public:
SourceManager &getSourceManager() { return SourceMgr; }
void reportDiagnostic(const ClangTidyError &Error) {
- const ClangTidyMessage &Message = Error.Message;
+ const tooling::DiagnosticMessage &Message = Error.Message;
SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
// Contains a pair for each attempted fix: location and whether the fix was
// applied successfully.
SmallVector<std::pair<SourceLocation, bool>, 4> FixLocations;
{
auto Level = static_cast<DiagnosticsEngine::Level>(Error.DiagLevel);
- std::string Name = Error.CheckName;
+ std::string Name = Error.DiagnosticName;
if (Error.IsWarningAsError) {
Name += ",-warnings-as-errors";
Level = DiagnosticsEngine::Error;
@@ -177,7 +178,7 @@ public:
Diags.Report(Fix.first, Fix.second ? diag::note_fixit_applied
: diag::note_fixit_failed);
}
- for (const ClangTidyMessage &Note : Error.Notes)
+ for (const auto &Note : Error.Notes)
reportNote(Note);
}
@@ -229,10 +230,9 @@ private:
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
}
- void reportNote(const ClangTidyMessage &Message) {
+ void reportNote(const tooling::DiagnosticMessage &Message) {
SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
- DiagnosticBuilder Diag =
- Diags.Report(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
+ Diags.Report(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
<< Message.Message;
}
@@ -562,18 +562,18 @@ void handleErrors(const std::vector<Clan
WarningsAsErrorsCount += Reporter.getWarningsAsErrorsCount();
}
-void exportReplacements(const std::vector<ClangTidyError> &Errors,
+void exportReplacements(const llvm::StringRef MainFilePath,
+ const std::vector<ClangTidyError> &Errors,
raw_ostream &OS) {
- TranslationUnitReplacements TUR;
- for (const ClangTidyError &Error : Errors) {
- for (const auto &FileAndFixes : Error.Fix)
- TUR.Replacements.insert(TUR.Replacements.end(),
- FileAndFixes.second.begin(),
- FileAndFixes.second.end());
+ TranslationUnitDiagnostics TUD;
+ TUD.MainSourceFile = MainFilePath;
+ for (const auto &Error : Errors) {
+ tooling::Diagnostic Diag = Error;
+ TUD.Diagnostics.insert(TUD.Diagnostics.end(), Diag);
}
yaml::Output YAML(OS);
- YAML << TUR;
+ YAML << TUD;
}
} // namespace tidy
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Tue Jan 3 08:36:13 2017
@@ -242,7 +242,8 @@ void handleErrors(const std::vector<Clan
/// \brief Serializes replacements into YAML and writes them to the specified
/// output stream.
-void exportReplacements(const std::vector<ClangTidyError> &Errors,
+void exportReplacements(StringRef MainFilePath,
+ const std::vector<ClangTidyError> &Errors,
raw_ostream &OS);
} // end namespace tidy
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Tue Jan 3 08:36:13 2017
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
///
-/// \file This file implements ClangTidyDiagnosticConsumer, ClangTidyMessage,
-/// ClangTidyContext and ClangTidyError classes.
+/// \file This file implements ClangTidyDiagnosticConsumer, ClangTidyContext
+/// and ClangTidyError classes.
///
/// This tool uses the Clang Tooling infrastructure, see
/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
@@ -45,13 +45,13 @@ protected:
// FIXME: Remove this once there's a better way to pass check names than
// appending the check name to the message in ClangTidyContext::diag and
// using getCustomDiagID.
- std::string CheckNameInMessage = " [" + Error.CheckName + "]";
+ std::string CheckNameInMessage = " [" + Error.DiagnosticName + "]";
if (Message.endswith(CheckNameInMessage))
Message = Message.substr(0, Message.size() - CheckNameInMessage.size());
- ClangTidyMessage TidyMessage = Loc.isValid()
- ? ClangTidyMessage(Message, *SM, Loc)
- : ClangTidyMessage(Message);
+ auto TidyMessage = Loc.isValid()
+ ? tooling::DiagnosticMessage(Message, *SM, Loc)
+ : tooling::DiagnosticMessage(Message);
if (Level == DiagnosticsEngine::Note) {
Error.Notes.push_back(TidyMessage);
return;
@@ -110,23 +110,11 @@ private:
};
} // end anonymous namespace
-ClangTidyMessage::ClangTidyMessage(StringRef Message)
- : Message(Message), FileOffset(0) {}
-
-ClangTidyMessage::ClangTidyMessage(StringRef Message,
- const SourceManager &Sources,
- SourceLocation Loc)
- : Message(Message) {
- assert(Loc.isValid() && Loc.isFileID());
- FilePath = Sources.getFilename(Loc);
- FileOffset = Sources.getFileOffset(Loc);
-}
-
ClangTidyError::ClangTidyError(StringRef CheckName,
ClangTidyError::Level DiagLevel,
- bool IsWarningAsError, StringRef BuildDirectory)
- : CheckName(CheckName), BuildDirectory(BuildDirectory),
- DiagLevel(DiagLevel), IsWarningAsError(IsWarningAsError) {}
+ StringRef BuildDirectory, bool IsWarningAsError)
+ : tooling::Diagnostic(CheckName, DiagLevel, BuildDirectory),
+ IsWarningAsError(IsWarningAsError) {}
// Returns true if GlobList starts with the negative indicator ('-'), removes it
// from the GlobList.
@@ -260,7 +248,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDi
void ClangTidyDiagnosticConsumer::finalizeLastError() {
if (!Errors.empty()) {
ClangTidyError &Error = Errors.back();
- if (!Context.getChecksFilter().contains(Error.CheckName) &&
+ if (!Context.getChecksFilter().contains(Error.DiagnosticName) &&
Error.DiagLevel != ClangTidyError::Error) {
++Context.Stats.ErrorsIgnoredCheckFilter;
Errors.pop_back();
@@ -366,8 +354,8 @@ void ClangTidyDiagnosticConsumer::Handle
bool IsWarningAsError =
DiagLevel == DiagnosticsEngine::Warning &&
Context.getWarningAsErrorFilter().contains(CheckName);
- Errors.push_back(ClangTidyError(CheckName, Level, IsWarningAsError,
- Context.getCurrentBuildDirectory()));
+ Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
+ IsWarningAsError);
}
ClangTidyDiagnosticRenderer Converter(
@@ -532,10 +520,9 @@ void ClangTidyDiagnosticConsumer::remove
// FIXME: Handle empty intervals, such as those from insertions.
if (Begin == End)
continue;
- FileEvents[FilePath].push_back(
- Event(Begin, End, Event::ET_Begin, I, Sizes[I]));
- FileEvents[FilePath].push_back(
- Event(Begin, End, Event::ET_End, I, Sizes[I]));
+ auto &Events = FileEvents[FilePath];
+ Events.emplace_back(Begin, End, Event::ET_Begin, I, Sizes[I]);
+ Events.emplace_back(Begin, End, Event::ET_End, I, Sizes[I]);
}
}
}
@@ -562,9 +549,8 @@ void ClangTidyDiagnosticConsumer::remove
for (unsigned I = 0; I < Errors.size(); ++I) {
if (!Apply[I]) {
Errors[I].Fix.clear();
- Errors[I].Notes.push_back(
- ClangTidyMessage("this fix will not be applied because"
- " it overlaps with another fix"));
+ Errors[I].Notes.emplace_back(
+ "this fix will not be applied because it overlaps with another fix");
}
}
}
@@ -572,8 +558,8 @@ void ClangTidyDiagnosticConsumer::remove
namespace {
struct LessClangTidyError {
bool operator()(const ClangTidyError &LHS, const ClangTidyError &RHS) const {
- const ClangTidyMessage &M1 = LHS.Message;
- const ClangTidyMessage &M2 = RHS.Message;
+ const tooling::DiagnosticMessage &M1 = LHS.Message;
+ const tooling::DiagnosticMessage &M2 = RHS.Message;
return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
std::tie(M2.FilePath, M2.FileOffset, M2.Message);
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Tue Jan 3 08:36:13 2017
@@ -13,6 +13,7 @@
#include "ClangTidyOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Diagnostic.h"
#include "clang/Tooling/Refactoring.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
@@ -32,18 +33,6 @@ class CompilationDatabase;
namespace tidy {
-/// \brief A message from a clang-tidy check.
-///
-/// Note that this is independent of a \c SourceManager.
-struct ClangTidyMessage {
- ClangTidyMessage(StringRef Message = "");
- ClangTidyMessage(StringRef Message, const SourceManager &Sources,
- SourceLocation Loc);
- std::string Message;
- std::string FilePath;
- unsigned FileOffset;
-};
-
/// \brief A detected error complete with information to display diagnostic and
/// automatic fix.
///
@@ -51,31 +40,10 @@ struct ClangTidyMessage {
/// dependency on a SourceManager.
///
/// FIXME: Make Diagnostics flexible enough to support this directly.
-struct ClangTidyError {
- enum Level {
- Warning = DiagnosticsEngine::Warning,
- Error = DiagnosticsEngine::Error
- };
-
- ClangTidyError(StringRef CheckName, Level DiagLevel, bool IsWarningAsError,
- StringRef BuildDirectory);
-
- std::string CheckName;
- ClangTidyMessage Message;
- // Fixes grouped by file path.
- llvm::StringMap<tooling::Replacements> Fix;
- SmallVector<ClangTidyMessage, 1> Notes;
-
- // A build directory of the diagnostic source file.
- //
- // It's an absolute path which is `directory` field of the source file in
- // compilation database. If users don't specify the compilation database
- // directory, it is the current directory where clang-tidy runs.
- //
- // Note: it is empty in unittest.
- std::string BuildDirectory;
+struct ClangTidyError : tooling::Diagnostic {
+ ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
+ bool IsWarningAsError);
- Level DiagLevel;
bool IsWarningAsError;
};
Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Tue Jan 3 08:36:13 2017
@@ -403,7 +403,7 @@ static int clangTidyMain(int argc, const
llvm::errs() << "Error opening output file: " << EC.message() << '\n';
return 1;
}
- exportReplacements(Errors, OS);
+ exportReplacements(FilePath.str(), Errors, OS);
}
printStats(Stats);
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml Tue Jan 3 08:36:13 2017
@@ -1,20 +1,22 @@
---
MainSourceFile: source1.cpp
-Replacements:
- - FilePath: $(path)/basic.h
- Offset: 242
- Length: 26
- ReplacementText: 'auto & elem : ints'
- - FilePath: $(path)/basic.h
- Offset: 276
- Length: 22
- ReplacementText: ''
- - FilePath: $(path)/basic.h
- Offset: 298
- Length: 1
- ReplacementText: elem
- - FilePath: $(path)/../basic/basic.h
- Offset: 148
- Length: 0
- ReplacementText: 'override '
+Diagnostics:
+ - DiagnosticName: test-basic
+ Replacements:
+ - FilePath: $(path)/basic.h
+ Offset: 242
+ Length: 26
+ ReplacementText: 'auto & elem : ints'
+ - FilePath: $(path)/basic.h
+ Offset: 276
+ Length: 22
+ ReplacementText: ''
+ - FilePath: $(path)/basic.h
+ Offset: 298
+ Length: 1
+ ReplacementText: elem
+ - FilePath: $(path)/../basic/basic.h
+ Offset: 148
+ Length: 0
+ ReplacementText: 'override '
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml Tue Jan 3 08:36:13 2017
@@ -1,8 +1,10 @@
---
MainSourceFile: source2.cpp
-Replacements:
- - FilePath: $(path)/basic.h
- Offset: 148
- Length: 0
- ReplacementText: 'override '
+Diagnostics:
+ - DiagnosticName: test-basic
+ Replacements:
+ - FilePath: $(path)/basic.h
+ Offset: 148
+ Length: 0
+ ReplacementText: 'override '
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml Tue Jan 3 08:36:13 2017
@@ -1,16 +1,18 @@
---
MainSourceFile: source1.cpp
-Replacements:
- - FilePath: $(path)/common.h
- Offset: 106
- Length: 26
- ReplacementText: 'auto & i : ints'
- - FilePath: $(path)/common.h
- Offset: 140
- Length: 7
- ReplacementText: i
- - FilePath: $(path)/common.h
- Offset: 160
- Length: 12
- ReplacementText: ''
+Diagnostics:
+ - DiagnosticName: test-conflict
+ Replacements:
+ - FilePath: $(path)/common.h
+ Offset: 106
+ Length: 26
+ ReplacementText: 'auto & i : ints'
+ - FilePath: $(path)/common.h
+ Offset: 140
+ Length: 7
+ ReplacementText: i
+ - FilePath: $(path)/common.h
+ Offset: 160
+ Length: 12
+ ReplacementText: ''
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml Tue Jan 3 08:36:13 2017
@@ -1,16 +1,18 @@
---
MainSourceFile: source2.cpp
-Replacements:
- - FilePath: $(path)/common.h
- Offset: 106
- Length: 26
- ReplacementText: 'int & elem : ints'
- - FilePath: $(path)/common.h
- Offset: 140
- Length: 7
- ReplacementText: elem
- - FilePath: $(path)/common.h
- Offset: 169
- Length: 1
- ReplacementText: nullptr
+Diagnostics:
+ - DiagnosticName: test-conflict
+ Replacements:
+ - FilePath: $(path)/common.h
+ Offset: 106
+ Length: 26
+ ReplacementText: 'int & elem : ints'
+ - FilePath: $(path)/common.h
+ Offset: 140
+ Length: 7
+ ReplacementText: elem
+ - FilePath: $(path)/common.h
+ Offset: 169
+ Length: 1
+ ReplacementText: nullptr
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml Tue Jan 3 08:36:13 2017
@@ -1,8 +1,10 @@
---
MainSourceFile: source1.cpp
-Replacements:
- - FilePath: $(path)/common.h
- Offset: 169
- Length: 0
- ReplacementText: "(int*)"
+Diagnostics:
+ - DiagnosticName: test-conflict
+ Replacements:
+ - FilePath: $(path)/common.h
+ Offset: 169
+ Length: 0
+ ReplacementText: "(int*)"
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml Tue Jan 3 08:36:13 2017
@@ -1,8 +1,10 @@
---
MainSourceFile: source1.cpp
-Replacements:
- - FilePath: $(path)/crlf.cpp
- Offset: 79
- Length: 1
- ReplacementText: nullptr
+Diagnostics:
+ - DiagnosticName: test-crlf
+ Replacements:
+ - FilePath: $(path)/crlf.cpp
+ Offset: 79
+ Length: 1
+ ReplacementText: nullptr
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml Tue Jan 3 08:36:13 2017
@@ -1,8 +1,10 @@
---
MainSourceFile: no.cpp
-Replacements:
- - FilePath: $(path)/no.cpp
- Offset: 94
- Length: 3
- ReplacementText: 'auto '
+Diagnostics:
+ - DiagnosticName: test-no
+ Replacements:
+ - FilePath: $(path)/no.cpp
+ Offset: 94
+ Length: 3
+ ReplacementText: 'auto '
...
Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml?rev=290893&r1=290892&r2=290893&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml Tue Jan 3 08:36:13 2017
@@ -2,21 +2,23 @@
# so that formatting happens correctly.
---
MainSourceFile: yes.cpp
-Replacements:
- - FilePath: $(path)/yes.cpp
- Offset: 494
- Length: 1
- ReplacementText: nullptr
- - FilePath: $(path)/yes.cpp
- Offset: 410
- Length: 1
- ReplacementText: nullptr
- - FilePath: $(path)/yes.cpp
- Offset: 454
- Length: 1
- ReplacementText: nullptr
- - FilePath: $(path)/yes.cpp
- Offset: 108
- Length: 38
- ReplacementText: 'auto '
+Diagnostics:
+ - DiagnosticName: test-yes
+ Replacements:
+ - FilePath: $(path)/yes.cpp
+ Offset: 494
+ Length: 1
+ ReplacementText: nullptr
+ - FilePath: $(path)/yes.cpp
+ Offset: 410
+ Length: 1
+ ReplacementText: nullptr
+ - FilePath: $(path)/yes.cpp
+ Offset: 454
+ Length: 1
+ ReplacementText: nullptr
+ - FilePath: $(path)/yes.cpp
+ Offset: 108
+ Length: 38
+ ReplacementText: 'auto '
...
More information about the cfe-commits
mailing list