clang  6.0.0svn
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 /// \brief Represents the diagnostic message with the error message associated
31 /// and the information on the location of the problem.
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 {
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  /// \brief Name identifying the Diagnostic.
67  std::string DiagnosticName;
68 
69  /// \brief Message associated to the diagnostic.
71 
72  /// \brief Fixes to apply, grouped by file path.
73  llvm::StringMap<Replacements> Fix;
74 
75  /// \brief Potential notes about the diagnostic.
77 
78  /// \brief Diagnostic level. Can indicate either an error or a warning.
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.
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
DiagnosticMessage(llvm::StringRef Message="")
Definition: Diagnostic.cpp:20
Level DiagLevel
Diagnostic level. Can indicate either an error or a warning.
Definition: Diagnostic.h:79
Represents the diagnostic with the level of severity and possible fixes to be applied.
Definition: Diagnostic.h:50
std::string BuildDirectory
A build directory of the diagnostic source file.
Definition: Diagnostic.h:88
Defines the Diagnostic-related interfaces.
std::string DiagnosticName
Name identifying the Diagnostic.
Definition: Diagnostic.h:67
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Diagnostic.h:94
Collection of Diagnostics generated from a single translation unit.
Definition: Diagnostic.h:92
SmallVector< DiagnosticMessage, 1 > Notes
Potential notes about the diagnostic.
Definition: Diagnostic.h:76
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
Encodes a location in the source.
DiagnosticMessage Message
Message associated to the diagnostic.
Definition: Diagnostic.h:70
Dataflow Directional Tag Classes.
llvm::StringMap< Replacements > Fix
Fixes to apply, grouped by file path.
Definition: Diagnostic.h:73
std::vector< Diagnostic > Diagnostics
Definition: Diagnostic.h:95
This class handles loading and caching of source files into memory.