Author: alexfh Date: Tue Nov 20 17:06:32 2018 New Revision: 347371 URL: http://llvm.org/viewvc/llvm-project?rev=347371&view=rev Log: Implement YAML serialization of notes in clang::tooling::Diagnostic.
Modified: cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Modified: cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h?rev=347371&r1=347370&r2=347371&view=diff ============================================================================== --- cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h (original) +++ cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h Tue Nov 20 17:06:32 2018 @@ -22,10 +22,19 @@ #include <string> LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::DiagnosticMessage) namespace llvm { namespace yaml { +template <> struct MappingTraits<clang::tooling::DiagnosticMessage> { + static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M) { + Io.mapRequired("Message", M.Message); + Io.mapOptional("FilePath", M.FilePath); + Io.mapOptional("FileOffset", M.FileOffset); + } +}; + template <> struct MappingTraits<clang::tooling::Diagnostic> { /// Helper to (de)serialize a Diagnostic since we don't have direct /// access to its data members. @@ -59,6 +68,7 @@ template <> struct MappingTraits<clang:: Io.mapRequired("Message", Keys->Message.Message); Io.mapRequired("FileOffset", Keys->Message.FileOffset); Io.mapRequired("FilePath", Keys->Message.FilePath); + Io.mapOptional("Notes", Keys->Notes); // FIXME: Export properly all the different fields. Modified: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp?rev=347371&r1=347370&r2=347371&view=diff ============================================================================== --- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp (original) +++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Tue Nov 20 17:06:32 2018 @@ -20,16 +20,21 @@ using namespace llvm; using namespace clang::tooling; using clang::tooling::Diagnostic; -static Diagnostic makeDiagnostic(StringRef DiagnosticName, - const std::string &Message, int FileOffset, - const std::string &FilePath, - const StringMap<Replacements> &Fix) { +static DiagnosticMessage makeMessage(const std::string &Message, int FileOffset, + const std::string &FilePath) { DiagnosticMessage DiagMessage; DiagMessage.Message = Message; DiagMessage.FileOffset = FileOffset; DiagMessage.FilePath = FilePath; - return Diagnostic(DiagnosticName, DiagMessage, Fix, {}, Diagnostic::Warning, - "path/to/build/directory"); + return DiagMessage; +} + +static Diagnostic makeDiagnostic(StringRef DiagnosticName, + const std::string &Message, int FileOffset, + const std::string &FilePath, + const StringMap<Replacements> &Fix) { + return Diagnostic(DiagnosticName, makeMessage(Message, FileOffset, FilePath), + Fix, {}, Diagnostic::Warning, "path/to/build/directory"); } TEST(DiagnosticsYamlTest, serializesDiagnostics) { @@ -50,6 +55,10 @@ TEST(DiagnosticsYamlTest, serializesDiag TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72, "path/to/source2.cpp", {})); + TUD.Diagnostics.back().Notes.push_back( + makeMessage("Note1", 88, "path/to/note1.cpp")); + TUD.Diagnostics.back().Notes.push_back( + makeMessage("Note2", 99, "path/to/note2.cpp")); std::string YamlContent; raw_string_ostream YamlContentStream(YamlContent); @@ -82,6 +91,13 @@ TEST(DiagnosticsYamlTest, serializesDiag " Message: 'message #3'\n" " FileOffset: 72\n" " FilePath: 'path/to/source2.cpp'\n" + " Notes: \n" + " - Message: Note1\n" + " FilePath: 'path/to/note1.cpp'\n" + " FileOffset: 88\n" + " - Message: Note2\n" + " FilePath: 'path/to/note2.cpp'\n" + " FileOffset: 99\n" " Replacements: []\n" "...\n", YamlContentStream.str()); @@ -113,6 +129,13 @@ TEST(DiagnosticsYamlTest, deserializesDi " Message: 'message #3'\n" " FileOffset: 98\n" " FilePath: path/to/source.cpp\n" + " Notes:\n" + " - Message: Note1\n" + " FilePath: 'path/to/note1.cpp'\n" + " FileOffset: 66\n" + " - Message: Note2\n" + " FilePath: 'path/to/note2.cpp'\n" + " FileOffset: 77\n" " Replacements: []\n" "...\n"; TranslationUnitDiagnostics TUDActual; @@ -162,6 +185,13 @@ TEST(DiagnosticsYamlTest, deserializesDi EXPECT_EQ("message #3", D3.Message.Message); EXPECT_EQ(98u, D3.Message.FileOffset); EXPECT_EQ("path/to/source.cpp", D3.Message.FilePath); + EXPECT_EQ(2u, D3.Notes.size()); + EXPECT_EQ("Note1", D3.Notes[0].Message); + EXPECT_EQ(66u, D3.Notes[0].FileOffset); + EXPECT_EQ("path/to/note1.cpp", D3.Notes[0].FilePath); + EXPECT_EQ("Note2", D3.Notes[1].Message); + EXPECT_EQ(77u, D3.Notes[1].FileOffset); + EXPECT_EQ("path/to/note2.cpp", D3.Notes[1].FilePath); std::vector<Replacement> Fixes3 = getFixes(D3.Fix); EXPECT_TRUE(Fixes3.empty()); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits