clang  14.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 
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 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::FileByteRange)
26 
27 namespace llvm {
28 namespace yaml {
29 
30 template <> struct MappingTraits<clang::tooling::FileByteRange> {
31  static void mapping(IO &Io, clang::tooling::FileByteRange &R) {
32  Io.mapRequired("FilePath", R.FilePath);
33  Io.mapRequired("FileOffset", R.FileOffset);
34  Io.mapRequired("Length", R.Length);
35  }
36 };
37 
38 template <> struct MappingTraits<clang::tooling::DiagnosticMessage> {
39  static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M) {
40  Io.mapRequired("Message", M.Message);
41  Io.mapOptional("FilePath", M.FilePath);
42  Io.mapOptional("FileOffset", M.FileOffset);
43  std::vector<clang::tooling::Replacement> Fixes;
44  for (auto &Replacements : M.Fix) {
45  for (auto &Replacement : Replacements.second)
46  Fixes.push_back(Replacement);
47  }
48  Io.mapRequired("Replacements", Fixes);
49  for (auto &Fix : Fixes) {
50  llvm::Error Err = M.Fix[Fix.getFilePath()].add(Fix);
51  if (Err) {
52  // FIXME: Implement better conflict handling.
53  llvm::errs() << "Fix conflicts with existing fix: "
54  << llvm::toString(std::move(Err)) << "\n";
55  }
56  }
57  Io.mapOptional("Ranges", M.Ranges);
58  }
59 };
60 
61 template <> struct MappingTraits<clang::tooling::Diagnostic> {
62  /// Helper to (de)serialize a Diagnostic since we don't have direct
63  /// access to its data members.
64  class NormalizedDiagnostic {
65  public:
67  : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
68 
70  : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
71  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
72 
74  return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
75  DiagLevel, BuildDirectory);
76  }
77 
83  };
84 
85  static void mapping(IO &Io, clang::tooling::Diagnostic &D) {
86  MappingNormalization<NormalizedDiagnostic, clang::tooling::Diagnostic> Keys(
87  Io, D);
88  Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
89  Io.mapRequired("DiagnosticMessage", Keys->Message);
90  Io.mapOptional("Notes", Keys->Notes);
91  Io.mapOptional("Level", Keys->DiagLevel);
92  Io.mapOptional("BuildDirectory", Keys->BuildDirectory);
93  }
94 };
95 
96 /// Specialized MappingTraits to describe how a
97 /// TranslationUnitDiagnostics is (de)serialized.
98 template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
100  Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
101  Io.mapRequired("Diagnostics", Doc.Diagnostics);
102  }
103 };
104 
105 template <> struct ScalarEnumerationTraits<clang::tooling::Diagnostic::Level> {
107  IO.enumCase(Value, "Warning", clang::tooling::Diagnostic::Warning);
108  IO.enumCase(Value, "Error", clang::tooling::Diagnostic::Error);
109  IO.enumCase(Value, "Remark", clang::tooling::Diagnostic::Remark);
110  }
111 };
112 
113 } // end namespace yaml
114 } // end namespace llvm
115 
116 #endif // LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagLevel
clang::tooling::Diagnostic::Level DiagLevel
Definition: DiagnosticsYaml.h:81
clang::tooling::Diagnostic
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:68
llvm
Definition: Dominators.h:30
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::tooling::DiagnosticMessage::Message
std::string Message
Definition: Diagnostic.h:54
llvm::SmallVector< clang::tooling::DiagnosticMessage, 1 >
clang::tooling::DiagnosticMessage::FilePath
std::string FilePath
Definition: Diagnostic.h:55
Diagnostic.h
clang::tooling::DiagnosticMessage::Fix
llvm::StringMap< Replacements > Fix
Fixes for this diagnostic, grouped by file path.
Definition: Diagnostic.h:59
clang::tooling::FileByteRange::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:36
clang::tooling::TranslationUnitDiagnostics::MainSourceFile
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:109
clang::tooling::FileByteRange::FilePath
std::string FilePath
Definition: Diagnostic.h:35
clang::tooling::Diagnostic::Warning
@ Warning
Definition: Diagnostic.h:71
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
ReplacementsYaml.h
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::denormalize
clang::tooling::Diagnostic denormalize(const IO &)
Definition: DiagnosticsYaml.h:73
clang::tooling::DiagnosticMessage::Ranges
llvm::SmallVector< FileByteRange, 1 > Ranges
Extra source ranges associated with the note, in addition to the location of the Message itself.
Definition: Diagnostic.h:63
clang::tooling::DiagnosticMessage::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:56
llvm::yaml::MappingTraits< clang::tooling::TranslationUnitDiagnostics >::mapping
static void mapping(IO &Io, clang::tooling::TranslationUnitDiagnostics &Doc)
Definition: DiagnosticsYaml.h:99
llvm::yaml::ScalarEnumerationTraits< clang::tooling::Diagnostic::Level >::enumeration
static void enumeration(IO &IO, clang::tooling::Diagnostic::Level &Value)
Definition: DiagnosticsYaml.h:106
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
Definition: DiagnosticsYaml.h:69
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Message
clang::tooling::DiagnosticMessage Message
Definition: DiagnosticsYaml.h:79
clang::tooling::Diagnostic::Level
Level
Definition: Diagnostic.h:69
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::NormalizedDiagnostic
NormalizedDiagnostic(const IO &)
Definition: DiagnosticsYaml.h:66
llvm::yaml::MappingTraits< clang::tooling::FileByteRange >::mapping
static void mapping(IO &Io, clang::tooling::FileByteRange &R)
Definition: DiagnosticsYaml.h:31
Value
Value
Definition: UninitializedValues.cpp:102
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::DiagnosticName
std::string DiagnosticName
Definition: DiagnosticsYaml.h:78
llvm::yaml::MappingTraits< clang::tooling::DiagnosticMessage >::mapping
static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M)
Definition: DiagnosticsYaml.h:39
clang
Definition: CalledOnceCheck.h:17
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::tooling::FileByteRange::Length
unsigned Length
Definition: Diagnostic.h:37
clang::tooling::TranslationUnitDiagnostics::Diagnostics
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:110
clang::tooling::TranslationUnitDiagnostics
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:107
clang::tooling::FileByteRange
Represents a range within a specific source file.
Definition: Diagnostic.h:30
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::Notes
SmallVector< clang::tooling::DiagnosticMessage, 1 > Notes
Definition: DiagnosticsYaml.h:80
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::mapping
static void mapping(IO &Io, clang::tooling::Diagnostic &D)
Definition: DiagnosticsYaml.h:85
clang::tooling::DiagnosticMessage
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:42
clang::tooling::Diagnostic::Error
@ Error
Definition: Diagnostic.h:72
llvm::yaml::MappingTraits< clang::tooling::Diagnostic >::NormalizedDiagnostic::BuildDirectory
std::string BuildDirectory
Definition: DiagnosticsYaml.h:82
clang::tooling::Diagnostic::Remark
@ Remark
Definition: Diagnostic.h:70