clang 8.0.0

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
19 #include "clang/Tooling/Core/Diagnostic.h"
20 #include "clang/Tooling/ReplacementsYaml.h"
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:
43 NormalizedDiagnostic(const IO &)
44 : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
45
46 NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
47 : DiagnosticName(D.DiagnosticName), Message(D.Message), Fix(D.Fix),
48 Notes(D.Notes), DiagLevel(D.DiagLevel),
49 BuildDirectory(D.BuildDirectory) {}
50
51 clang::tooling::Diagnostic denormalize(const IO &) {
52 return clang::tooling::Diagnostic(DiagnosticName, Message, Fix, Notes,
53 DiagLevel, BuildDirectory);
54 }
55
56 std::string DiagnosticName;
57 clang::tooling::DiagnosticMessage Message;
58 llvm::StringMap<clang::tooling::Replacements> Fix;
59 SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
60 clang::tooling::Diagnostic::Level DiagLevel;
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> {
96 static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc) {
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
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::mapping
static void mapping(IO &Io, clang::tooling::Diagnostic &D)
Definition: DiagnosticsYaml.h:64
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Fix
llvm::StringMap< clang::tooling::Replacements > Fix
Definition: DiagnosticsYaml.h:58
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagLevel
clang::tooling::Diagnostic::Level DiagLevel
Definition: DiagnosticsYaml.h:60
clang::tooling::DiagnosticMessage::Message
std::string Message
Definition: Diagnostic.h:43
clang::tooling::Diagnostic
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:50
toString
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Definition: SanitizerArgs.cpp:775
clang::tooling::DiagnosticMessage::FilePath
std::string FilePath
Definition: Diagnostic.h:44
Diagnostic.h
llvm::yaml::MappingTraits< clang::tooling::TranslationUnitDiagnostics >::mapping
static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc)
Definition: DiagnosticsYaml.h:96
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
Definition: DiagnosticsYaml.h:46
clang::tooling::TranslationUnitDiagnostics::MainSourceFile
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:94
clang::tooling::Diagnostic::Level
Level
Definition: Diagnostic.h:51
clang::tooling::DiagnosticMessage::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:45
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &)
Definition: DiagnosticsYaml.h:43
clang::tooling::TranslationUnitDiagnostics
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:92
llvm::yaml::MappingTraits< clang::tooling::DiagnosticMessage >::mapping
static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M)
Definition: DiagnosticsYaml.h:31
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagnosticName
std::string DiagnosticName
Definition: DiagnosticsYaml.h:56
clang::tooling::DiagnosticMessage
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::denormalize
clang::tooling::Diagnostic denormalize(const IO &)
Definition: DiagnosticsYaml.h:51
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Notes
SmallVector< clang::tooling::DiagnosticMessage, 1 > Notes
Definition: DiagnosticsYaml.h:59
llvm::SmallVector< clang::tooling::DiagnosticMessage, 1 >
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::BuildDirectory
std::string BuildDirectory
Definition: DiagnosticsYaml.h:61
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Message
clang::tooling::DiagnosticMessage Message
Definition: DiagnosticsYaml.h:57
clang::tooling::TranslationUnitDiagnostics::Diagnostics
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:95
ReplacementsYaml.h
This file defines the structure of a YAML document for serializing replacements.
clang::prec::Level
Level
Definition: OperatorPrecedence.h:27