[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 81779. Alpha added a comment. It was tested against the clang extra unit tests, but not tests run with check-clang-tools. Updated Yaml test files to match the new format, this might need further review. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp tools/extra/test/clang-apply-replacements/Inputs/basic/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/basic/file2.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file2.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file3.yaml tools/extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/format/no.yaml tools/extra/test/clang-apply-replacements/Inputs/format/yes.yaml unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,46 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message),
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Ping. Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 82860. Alpha added a comment. Rebase on top of HEAD. Ping. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp tools/extra/test/clang-apply-replacements/Inputs/basic/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/basic/file2.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file2.yaml tools/extra/test/clang-apply-replacements/Inputs/conflict/file3.yaml tools/extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml tools/extra/test/clang-apply-replacements/Inputs/format/no.yaml tools/extra/test/clang-apply-replacements/Inputs/format/yes.yaml unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,46 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sour
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Thanks for the review! Comment at: tools/extra/clang-tidy/ClangTidy.cpp:106 void reportDiagnostic(const ClangTidyError &Error) { -const ClangTidyMessage &Message = Error.Message; +const ClangTidyMessage Message = Error.Message; SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset); alexfh wrote: > alexfh wrote: > > Why this change? > Assuming, it was unintentional, changing back to reference. It is indeed unintentional. Comment at: tools/extra/clang-tidy/ClangTidy.h:245 /// output stream. -void exportReplacements(const std::vector &Errors, +void exportReplacements(const StringRef MainFilePath, +const std::vector &Errors, alexfh wrote: > Top-level const on function parameters in function declarations is useless > (it's not a part of the function prototype and it tells nothing to the > function users). It might make sense on a function definition, if used > consistently (same way as on local variables). However, is not very common in > LLVM/Clang. Ok, this is good to know. Comment at: tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:36 -/// \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; -}; +typedef clang::tooling::DiagnosticMessage ClangTidyMessage; alexfh wrote: > alexfh wrote: > > Do we actually need this typedef? How much is the old type name used? > Removed. I was quite hesitant with this one, wondering if it would be better to keep clang-tidy specific naming in that case. Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Ping Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha marked 10 inline comments as done. Alpha added inline comments. Comment at: include/clang/Tooling/DiagnosticsYaml.h:79 + for (auto &Diagnostic : Doc.Diagnostics) { +if (Diagnostic.Fix.size() > 0) { + Diagnostics.push_back(Diagnostic); alexfh wrote: > Should we copy all diagnostics instead? I am not sure about that. Copying all diagnostics will mean having empty entries in the replacement files with just a check name. This might seem useless, the problem being that at the moment, the only useful exported information in diagnostics are the replacements. I think that if all diagnostics are copied, it must be done in a different patch, with a proper export of all the meaningful information about the diagnostics. Then, the exported info in clang-tidy will not solely be fixes, but every diagnostic info (which could mean changing the name and meaning of output file and option). What is your feeling about this? Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 79899. Herald added a subscriber: JDevlieghere. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel, StringRef BuildDirectory) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + DiagnosticMessage &Message, + llvm::St
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 79904. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel, StringRef BuildDirectory) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + DiagnosticMessage &Message, + llvm::StringMap &Fix, + Sma
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 79917. Alpha added a comment. Rebase on top of HEAD. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel, StringRef BuildDirectory) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + DiagnosticMessage &Message, + l
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. I don't have commit access. Thank you for the review @alexfh Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 80732. Alpha added a comment. Rebase on top of HEAD. Ping. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel, StringRef BuildDirectory) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + DiagnosticMessage &Message, +
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 80874. Alpha added a comment. Fix clang compilation warnings. These didn't appear when compiled on Windows. Tested on a Linux distribution, should be fixed. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/Core/Replacement.h include/clang/Tooling/DiagnosticsYaml.h include/clang/Tooling/ReplacementsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp unittests/Tooling/ReplacementsYamlTest.cpp Index: unittests/Tooling/ReplacementsYamlTest.cpp === --- unittests/Tooling/ReplacementsYamlTest.cpp +++ unittests/Tooling/ReplacementsYamlTest.cpp @@ -22,11 +22,10 @@ TranslationUnitReplacements Doc; Doc.MainSourceFile = "/path/to/source.cpp"; - Doc.Context = "some context"; - Doc.Replacements - .push_back(Replacement("/path/to/file1.h", 232, 56, "replacement #1")); - Doc.Replacements - .push_back(Replacement("/path/to/file2.h", 301, 2, "replacement #2")); + Doc.Replacements.push_back( + Replacement("/path/to/file1.h", 232, 56, "replacement #1")); + Doc.Replacements.push_back( + Replacement("/path/to/file2.h", 301, 2, "replacement #2")); std::string YamlContent; llvm::raw_string_ostream YamlContentStream(YamlContent); @@ -37,7 +36,6 @@ // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" "MainSourceFile: /path/to/source.cpp\n" - "Context: some context\n" "Replacements:\n" // Extra whitespace here! " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -54,7 +52,6 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" "MainSourceFile: /path/to/source.cpp\n" -"Context: some context\n" "Replacements:\n" " - FilePath:/path/to/file1.h\n" "Offset: 232\n" @@ -71,7 +68,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ(2u, DocActual.Replacements.size()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); - ASSERT_EQ("some context", DocActual.Context); ASSERT_EQ("/path/to/file1.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(232u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(56u, DocActual.Replacements[0].getLength()); @@ -98,7 +94,6 @@ ASSERT_FALSE(YAML.error()); ASSERT_EQ("/path/to/source.cpp", DocActual.MainSourceFile); ASSERT_EQ(1u, DocActual.Replacements.size()); - ASSERT_EQ(std::string(), DocActual.Context); ASSERT_EQ("target_file.h", DocActual.Replacements[0].getFilePath()); ASSERT_EQ(1u, DocActual.Replacements[0].getOffset()); ASSERT_EQ(10u, DocActual.Replacements[0].getLength()); Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics tools --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// Implements classes to support/store diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel, StringRef BuildDirectory) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm: