summaryrefslogtreecommitdiffstats
path: root/include/clang/Tooling/DiagnosticsYaml.h
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-01-03 14:35:47 +0000
committerAlexander Kornienko <alexfh@google.com>2017-01-03 14:35:47 +0000
commitfb9bfeea738853fc73d0f74fec0f30909beaeb73 (patch)
tree1fa5b6c2355a57b69c524c9bfda46459082cee74 /include/clang/Tooling/DiagnosticsYaml.h
parent48194d104cad1bd83e71e0e95ccfa7e796bad5b2 (diff)
[clang-tidy] Add check name to YAML export
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290892 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Tooling/DiagnosticsYaml.h')
-rw-r--r--include/clang/Tooling/DiagnosticsYaml.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/include/clang/Tooling/DiagnosticsYaml.h b/include/clang/Tooling/DiagnosticsYaml.h
new file mode 100644
index 0000000000..f32b9fa9c9
--- /dev/null
+++ b/include/clang/Tooling/DiagnosticsYaml.h
@@ -0,0 +1,101 @@
+//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file defines the structure of a YAML document for serializing
+/// diagnostics.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
+#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
+
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "llvm/Support/YAMLTraits.h"
+#include <string>
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic)
+
+namespace llvm {
+namespace yaml {
+
+template <> struct MappingTraits<clang::tooling::Diagnostic> {
+ /// \brief Helper to (de)serialize a Diagnostic since we don't have direct
+ /// access to its data members.
+ class NormalizedDiagnostic {
+ public:
+ NormalizedDiagnostic(const IO &)
+ : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
+
+ NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
+ : DiagnosticName(D.DiagnosticName), Message(D.Message), Fix(D.Fix),
+ Notes(D.Notes), DiagLevel(D.DiagLevel),
+ BuildDirectory(D.BuildDirectory) {}
+
+ clang::tooling::Diagnostic denormalize(const IO &) {
+ return clang::tooling::Diagnostic(DiagnosticName, Message, Fix, Notes,
+ DiagLevel, BuildDirectory);
+ }
+
+ std::string DiagnosticName;
+ clang::tooling::DiagnosticMessage Message;
+ llvm::StringMap<clang::tooling::Replacements> Fix;
+ SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
+ clang::tooling::Diagnostic::Level DiagLevel;
+ std::string BuildDirectory;
+ };
+
+ static void mapping(IO &Io, clang::tooling::Diagnostic &D) {
+ MappingNormalization<NormalizedDiagnostic, clang::tooling::Diagnostic> Keys(
+ Io, D);
+ Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
+
+ // FIXME: Export properly all the different fields.
+
+ std::vector<clang::tooling::Replacement> Fixes;
+ for (auto &Replacements : Keys->Fix) {
+ for (auto &Replacement : Replacements.second) {
+ Fixes.push_back(Replacement);
+ }
+ }
+ Io.mapRequired("Replacements", Fixes);
+ for (auto &Fix : Fixes) {
+ llvm::Error Err = Keys->Fix[Fix.getFilePath()].add(Fix);
+ if (Err) {
+ // FIXME: Implement better conflict handling.
+ llvm::errs() << "Fix conflicts with existing fix: "
+ << llvm::toString(std::move(Err)) << "\n";
+ }
+ }
+ }
+};
+
+/// \brief Specialized MappingTraits to describe how a
+/// TranslationUnitDiagnostics is (de)serialized.
+template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
+ static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc) {
+ Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
+
+ std::vector<clang::tooling::Diagnostic> Diagnostics;
+ for (auto &Diagnostic : Doc.Diagnostics) {
+ // FIXME: Export all diagnostics, not just the ones with fixes.
+ // Update MappingTraits<clang::tooling::Diagnostic>::mapping.
+ if (Diagnostic.Fix.size() > 0) {
+ Diagnostics.push_back(Diagnostic);
+ }
+ }
+ Io.mapRequired("Diagnostics", Diagnostics);
+ Doc.Diagnostics = Diagnostics;
+ }
+};
+} // end namespace yaml
+} // end namespace llvm
+
+#endif // LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H