1 //===--- Diagnostic.h - Framework for clang diagnostics tools --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // Structures supporting diagnostics and refactorings that span multiple
12 // translation units. Indicate diagnostics reports and replacements
13 // suggestions for the analyzed sources.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
18 #define LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
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"
30 /// 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 = "");
35 /// Constructs a diagnostic message with anoffset to the diagnostic
36 /// within the file where the problem occurred.
38 /// \param Loc Should be a file location, it is not meaningful for a macro
41 DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources,
48 /// Represents the diagnostic with the level of severity and possible
49 /// fixes to be applied.
52 Warning = DiagnosticsEngine::Warning,
53 Error = DiagnosticsEngine::Error
56 Diagnostic() = default;
58 Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel,
59 StringRef BuildDirectory);
61 Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message,
62 const llvm::StringMap<Replacements> &Fix,
63 const SmallVector<DiagnosticMessage, 1> &Notes, Level DiagLevel,
64 llvm::StringRef BuildDirectory);
66 /// Name identifying the Diagnostic.
67 std::string DiagnosticName;
69 /// Message associated to the diagnostic.
70 DiagnosticMessage Message;
72 /// Fixes to apply, grouped by file path.
73 llvm::StringMap<Replacements> Fix;
75 /// Potential notes about the diagnostic.
76 SmallVector<DiagnosticMessage, 1> Notes;
78 /// Diagnostic level. Can indicate either an error or a warning.
81 /// A build directory of the diagnostic source file.
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.
87 /// Note: it is empty in unittest.
88 std::string BuildDirectory;
91 /// 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;
98 } // end namespace tooling
99 } // end namespace clang
100 #endif // LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H