clang  10.0.0svn
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 
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:
57  : DiagLevel(clang::tooling::Diagnostic::Level::Warning) {}
58 
60  : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
61  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
62 
64  return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
65  DiagLevel, BuildDirectory);
66  }
67 
68  std::string DiagnosticName;
70  llvm::StringMap<clang::tooling::Replacements> Fix;
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> {
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
static void mapping(IO &Io, clang::tooling::Diagnostic &D)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:52
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)
llvm::StringMap< Replacements > Fix
Fixes for this diagnostic, grouped by file path.
Definition: Diagnostic.h:47
NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:92
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:90
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:31
Dataflow Directional Tag Classes.
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:93
This file defines the structure of a YAML document for serializing replacements.