clang 10.0.0git

DiagnosticsYaml.h
Go to the documentation of this file.
1 //===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the structure of a YAML document for serializing
11 /// diagnostics.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
16 #define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
17
18 #include "clang/Tooling/Core/Diagnostic.h"
19 #include "clang/Tooling/ReplacementsYaml.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include <string>
22
23 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic)
24 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::DiagnosticMessage)
25
26 namespace llvm {
27 namespace yaml {
28
29 template <> struct MappingTraits<clang::tooling::DiagnosticMessage> {
30 static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M) {
31 Io.mapRequired("Message", M.Message);
32 Io.mapOptional("FilePath", M.FilePath);
33 Io.mapOptional("FileOffset", M.FileOffset);
34 std::vector<clang::tooling::Replacement> Fixes;
35 for (auto &Replacements : M.Fix) {
36 for (auto &Replacement : Replacements.second)
37 Fixes.push_back(Replacement);
38 }
39 Io.mapRequired("Replacements", Fixes);
40 for (auto &Fix : Fixes) {
41 llvm::Error Err = M.Fix[Fix.getFilePath()].add(Fix);
42 if (Err) {
43 // FIXME: Implement better conflict handling.
44 llvm::errs() << "Fix conflicts with existing fix: "
45 << llvm::toString(std::move(Err)) << "\n";
46 }
47 }
48 }
49 };
50
51 template <> struct MappingTraits<clang::tooling::Diagnostic> {
52 /// Helper to (de)serialize a Diagnostic since we don't have direct
53 /// access to its data members.
54 class NormalizedDiagnostic {
55 public:
56 NormalizedDiagnostic(const IO &)
57 : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
58
59 NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
60 : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
61 DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
62
63 clang::tooling::Diagnostic denormalize(const IO &) {
64 return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
65 DiagLevel, BuildDirectory);
66 }
67
68 std::string DiagnosticName;
69 clang::tooling::DiagnosticMessage Message;
70 llvm::StringMap<clang::tooling::Replacements> Fix;
71 SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
72 clang::tooling::Diagnostic::Level DiagLevel;
73 std::string BuildDirectory;
74 };
75
76 static void mapping(IO &Io, clang::tooling::Diagnostic &D) {
77 MappingNormalization<NormalizedDiagnostic, clang::tooling::Diagnostic> Keys(
78 Io, D);
79 Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
80 Io.mapRequired("DiagnosticMessage", Keys->Message);
81 Io.mapOptional("Notes", Keys->Notes);
82
83 // FIXME: Export properly all the different fields.
84 }
85 };
86
87 /// Specialized MappingTraits to describe how a
88 /// TranslationUnitDiagnostics is (de)serialized.
89 template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
90 static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc) {
91 Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
92 Io.mapRequired("Diagnostics", Doc.Diagnostics);
93 }
94 };
95 } // end namespace yaml
96 } // end namespace llvm
97
98 #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:76
llvm
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Fix
llvm::StringMap< clang::tooling::Replacements > Fix
Definition: DiagnosticsYaml.h:70
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagLevel
clang::tooling::Diagnostic::Level DiagLevel
Definition: DiagnosticsYaml.h:72
clang::tooling::DiagnosticMessage::Message
std::string Message
Definition: Diagnostic.h:42
clang::tooling::Diagnostic
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:52
toString
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Definition: SanitizerArgs.cpp:856
clang::tooling::DiagnosticMessage::FilePath
std::string FilePath
Definition: Diagnostic.h:43
Diagnostic.h
llvm::yaml::MappingTraits< clang::tooling::TranslationUnitDiagnostics >::mapping
static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc)
Definition: DiagnosticsYaml.h:90
clang::tooling::DiagnosticMessage::Fix
llvm::StringMap< Replacements > Fix
Fixes for this diagnostic, grouped by file path.
Definition: Diagnostic.h:47
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
Definition: DiagnosticsYaml.h:59
clang::tooling::TranslationUnitDiagnostics::MainSourceFile
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:92
clang::tooling::Diagnostic::Level
Level
Definition: Diagnostic.h:53
clang::tooling::DiagnosticMessage::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:44
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &)
Definition: DiagnosticsYaml.h:56
clang::tooling::TranslationUnitDiagnostics
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:90
llvm::yaml::MappingTraits< clang::tooling::DiagnosticMessage >::mapping
static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M)
Definition: DiagnosticsYaml.h:30
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagnosticName
std::string DiagnosticName
Definition: DiagnosticsYaml.h:68
clang::tooling::DiagnosticMessage
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:31
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::denormalize
clang::tooling::Diagnostic denormalize(const IO &)
Definition: DiagnosticsYaml.h:63
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Notes
SmallVector< clang::tooling::DiagnosticMessage, 1 > Notes
Definition: DiagnosticsYaml.h:71
llvm::SmallVector< clang::tooling::DiagnosticMessage, 1 >
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::BuildDirectory
std::string BuildDirectory
Definition: DiagnosticsYaml.h:73
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Message
clang::tooling::DiagnosticMessage Message
Definition: DiagnosticsYaml.h:69
clang::tooling::TranslationUnitDiagnostics::Diagnostics
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:93
ReplacementsYaml.h
This file defines the structure of a YAML document for serializing replacements.
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26