#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.
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.
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) {
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);
" 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());
" 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;
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());
}