]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Tooling/Core/Diagnostic.h
Merge llvm, clang, lld and lldb trunk r291012, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Tooling / Core / Diagnostic.h
1 //===--- Diagnostic.h - Framework for clang diagnostics tools --*- 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 //  Structures supporting diagnostics and refactorings that span multiple
12 //  translation units. Indicate diagnostics reports and replacements
13 //  suggestions for the analyzed sources.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
18 #define LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
19
20 #include "Replacement.h"
21 #include "clang/Basic/Diagnostic.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include <string>
26
27 namespace clang {
28 namespace tooling {
29
30 /// \brief Represents the diagnostic message with the error message associated
31 /// and the information on the location of the problem.
32 struct DiagnosticMessage {
33   DiagnosticMessage(llvm::StringRef Message = "");
34
35   /// \brief Constructs a diagnostic message with anoffset to the diagnostic
36   /// within the file where the problem occured.
37   ///
38   /// \param Loc Should be a file location, it is not meaningful for a macro
39   /// location.
40   ///
41   DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources,
42                     SourceLocation Loc);
43   std::string Message;
44   std::string FilePath;
45   unsigned FileOffset;
46 };
47
48 /// \brief Represents the diagnostic with the level of severity and possible
49 /// fixes to be applied.
50 struct Diagnostic {
51   enum Level {
52     Warning = DiagnosticsEngine::Warning,
53     Error = DiagnosticsEngine::Error
54   };
55
56   Diagnostic() = default;
57
58   Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel,
59              StringRef BuildDirectory);
60
61   Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message,
62              llvm::StringMap<Replacements> &Fix,
63              SmallVector<DiagnosticMessage, 1> &Notes, Level DiagLevel,
64              llvm::StringRef BuildDirectory);
65
66   /// \brief Name identifying the Diagnostic.
67   std::string DiagnosticName;
68
69   /// \brief Message associated to the diagnostic.
70   DiagnosticMessage Message;
71
72   /// \brief Fixes to apply, grouped by file path.
73   llvm::StringMap<Replacements> Fix;
74
75   /// \brief Potential notes about the diagnostic.
76   SmallVector<DiagnosticMessage, 1> Notes;
77
78   /// \brief Diagnostic level. Can indicate either an error or a warning.
79   Level DiagLevel;
80
81   /// \brief A build directory of the diagnostic source file.
82   ///
83   /// It's an absolute path which is `directory` field of the source file in
84   /// compilation database. If users don't specify the compilation database
85   /// directory, it is the current directory where clang-tidy runs.
86   ///
87   /// Note: it is empty in unittest.
88   std::string BuildDirectory;
89 };
90
91 /// \brief Collection of Diagnostics generated from a single translation unit.
92 struct TranslationUnitDiagnostics {
93   /// Name of the main source for the translation unit.
94   std::string MainSourceFile;
95   std::vector<Diagnostic> Diagnostics;
96 };
97
98 } // end namespace tooling
99 } // end namespace clang
100 #endif // LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H