clang 8.0.0

Diagnostic.h
Go to the documentation of this file.
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 /// 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 /// Constructs a diagnostic message with anoffset to the diagnostic
36 /// within the file where the problem occurred.
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 /// 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, const DiagnosticMessage &Message,
62 const llvm::StringMap<Replacements> &Fix,
63 const SmallVector<DiagnosticMessage, 1> &Notes, Level DiagLevel,
64 llvm::StringRef BuildDirectory);
65
66 /// Name identifying the Diagnostic.
67 std::string DiagnosticName;
68
69 /// Message associated to the diagnostic.
70 DiagnosticMessage Message;
71
72 /// Fixes to apply, grouped by file path.
73 llvm::StringMap<Replacements> Fix;
74
75 /// Potential notes about the diagnostic.
76 SmallVector<DiagnosticMessage, 1> Notes;
77
78 /// Diagnostic level. Can indicate either an error or a warning.
79 Level DiagLevel;
80
81 /// 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 /// 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
clang::tooling::DiagnosticMessage::DiagnosticMessage
DiagnosticMessage(llvm::StringRef Message="")
Definition: Diagnostic.cpp:20
clang::tooling::Diagnostic::DiagLevel
Level DiagLevel
Diagnostic level. Can indicate either an error or a warning.
Definition: Diagnostic.h:79
clang::tooling::DiagnosticMessage::Message
std::string Message
Definition: Diagnostic.h:43
clang::tooling::Diagnostic
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:50
clang::tooling::DiagnosticMessage::FilePath
std::string FilePath
Definition: Diagnostic.h:44
clang::tooling::Diagnostic::BuildDirectory
std::string BuildDirectory
A build directory of the diagnostic source file.
Definition: Diagnostic.h:88
Diagnostic.h
Defines the Diagnostic-related interfaces.
clang::tooling::Diagnostic::DiagnosticName
std::string DiagnosticName
Name identifying the Diagnostic.
Definition: Diagnostic.h:67
clang::tooling::TranslationUnitDiagnostics::MainSourceFile
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:94
clang::tooling::Diagnostic::Level
Level
Definition: Diagnostic.h:51
clang::tooling::DiagnosticMessage::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:45
clang::tooling::TranslationUnitDiagnostics
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:92
clang::tooling::Diagnostic::Notes
SmallVector< DiagnosticMessage, 1 > Notes
Potential notes about the diagnostic.
Definition: Diagnostic.h:76
clang::tooling::DiagnosticMessage
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
llvm::SmallVector
Definition: LLVM.h:36
clang::tooling::Diagnostic::Message
DiagnosticMessage Message
Message associated to the diagnostic.
Definition: Diagnostic.h:70
Replacement.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::tooling::Diagnostic::Fix
llvm::StringMap< Replacements > Fix
Fixes to apply, grouped by file path.
Definition: Diagnostic.h:73
clang::DiagnosticsEngine::Warning
Definition: Diagnostic.h:156
clang::DiagnosticsEngine::Error
Definition: Diagnostic.h:157
clang::tooling::TranslationUnitDiagnostics::Diagnostics
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:95
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582