clang  9.0.0svn
DiagnosticsYaml.h
Go to the documentation of this file.
1 //===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file defines the structure of a YAML document for serializing
12 /// diagnostics.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
17 #define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
18 
21 #include "llvm/Support/YAMLTraits.h"
22 #include <string>
23 
24 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic)
25 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::DiagnosticMessage)
26 
27 namespace llvm {
28 namespace yaml {
29 
30 template <> struct MappingTraits<clang::tooling::DiagnosticMessage> {
31  static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M) {
32  Io.mapRequired("Message", M.Message);
33  Io.mapOptional("FilePath", M.FilePath);
34  Io.mapOptional("FileOffset", M.FileOffset);
35  }
36 };
37 
38 template <> struct MappingTraits<clang::tooling::Diagnostic> {
39  /// Helper to (de)serialize a Diagnostic since we don't have direct
40  /// access to its data members.
41  class NormalizedDiagnostic {
42  public:
44  : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
45 
47  : DiagnosticName(D.DiagnosticName), Message(D.Message), Fix(D.Fix),
48  Notes(D.Notes), DiagLevel(D.DiagLevel),
49  BuildDirectory(D.BuildDirectory) {}
50 
52  return clang::tooling::Diagnostic(DiagnosticName, Message, Fix, Notes,
53  DiagLevel, BuildDirectory);
54  }
55 
56  std::string DiagnosticName;
58  llvm::StringMap<clang::tooling::Replacements> Fix;
61  std::string BuildDirectory;
62  };
63 
64  static void mapping(IO &Io, clang::tooling::Diagnostic &D) {
65  MappingNormalization<NormalizedDiagnostic, clang::tooling::Diagnostic> Keys(
66  Io, D);
67  Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
68  Io.mapRequired("Message", Keys->Message.Message);
69  Io.mapRequired("FileOffset", Keys->Message.FileOffset);
70  Io.mapRequired("FilePath", Keys->Message.FilePath);
71  Io.mapOptional("Notes", Keys->Notes);
72 
73  // FIXME: Export properly all the different fields.
74 
75  std::vector<clang::tooling::Replacement> Fixes;
76  for (auto &Replacements : Keys->Fix) {
77  for (auto &Replacement : Replacements.second) {
78  Fixes.push_back(Replacement);
79  }
80  }
81  Io.mapRequired("Replacements", Fixes);
82  for (auto &Fix : Fixes) {
83  llvm::Error Err = Keys->Fix[Fix.getFilePath()].add(Fix);
84  if (Err) {
85  // FIXME: Implement better conflict handling.
86  llvm::errs() << "Fix conflicts with existing fix: "
87  << llvm::toString(std::move(Err)) << "\n";
88  }
89  }
90  }
91 };
92 
93 /// Specialized MappingTraits to describe how a
94 /// TranslationUnitDiagnostics is (de)serialized.
95 template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
97  Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
98  Io.mapRequired("Diagnostics", Doc.Diagnostics);
99  }
100 };
101 } // end namespace yaml
102 } // end namespace llvm
103 
104 #endif // LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
static void mapping(IO &Io, clang::tooling::Diagnostic &D)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:50
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc)
NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:94
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:92
static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M)
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
Dataflow Directional Tag Classes.
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:95
This file defines the structure of a YAML document for serializing replacements.