|
|
|||
File indexing completed on 2026-05-10 08:37:10
0001 //===--- Diagnostic.h - Framework for clang diagnostics tools --*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // \file 0010 // Structures supporting diagnostics and refactorings that span multiple 0011 // translation units. Indicate diagnostics reports and replacements 0012 // suggestions for the analyzed sources. 0013 // 0014 //===----------------------------------------------------------------------===// 0015 0016 #ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H 0017 #define LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H 0018 0019 #include "Replacement.h" 0020 #include "clang/Basic/Diagnostic.h" 0021 #include "llvm/ADT/SmallVector.h" 0022 #include "llvm/ADT/StringMap.h" 0023 #include "llvm/ADT/StringRef.h" 0024 #include <string> 0025 0026 namespace clang { 0027 namespace tooling { 0028 0029 /// Represents a range within a specific source file. 0030 struct FileByteRange { 0031 FileByteRange() = default; 0032 0033 FileByteRange(const SourceManager &Sources, CharSourceRange Range); 0034 0035 std::string FilePath; 0036 unsigned FileOffset; 0037 unsigned Length; 0038 }; 0039 0040 /// Represents the diagnostic message with the error message associated 0041 /// and the information on the location of the problem. 0042 struct DiagnosticMessage { 0043 DiagnosticMessage(llvm::StringRef Message = ""); 0044 0045 /// Constructs a diagnostic message with anoffset to the diagnostic 0046 /// within the file where the problem occurred. 0047 /// 0048 /// \param Loc Should be a file location, it is not meaningful for a macro 0049 /// location. 0050 /// 0051 DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources, 0052 SourceLocation Loc); 0053 0054 std::string Message; 0055 std::string FilePath; 0056 unsigned FileOffset; 0057 0058 /// Fixes for this diagnostic, grouped by file path. 0059 llvm::StringMap<Replacements> Fix; 0060 0061 /// Extra source ranges associated with the note, in addition to the location 0062 /// of the Message itself. 0063 llvm::SmallVector<FileByteRange, 1> Ranges; 0064 }; 0065 0066 /// Represents the diagnostic with the level of severity and possible 0067 /// fixes to be applied. 0068 struct Diagnostic { 0069 enum Level { 0070 Remark = DiagnosticsEngine::Remark, 0071 Warning = DiagnosticsEngine::Warning, 0072 Error = DiagnosticsEngine::Error 0073 }; 0074 0075 Diagnostic() = default; 0076 0077 Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel, 0078 StringRef BuildDirectory); 0079 0080 Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message, 0081 const SmallVector<DiagnosticMessage, 1> &Notes, Level DiagLevel, 0082 llvm::StringRef BuildDirectory); 0083 0084 /// Name identifying the Diagnostic. 0085 std::string DiagnosticName; 0086 0087 /// Message associated to the diagnostic. 0088 DiagnosticMessage Message; 0089 0090 /// Potential notes about the diagnostic. 0091 SmallVector<DiagnosticMessage, 1> Notes; 0092 0093 /// Diagnostic level. Can indicate either an error or a warning. 0094 Level DiagLevel; 0095 0096 /// A build directory of the diagnostic source file. 0097 /// 0098 /// It's an absolute path which is `directory` field of the source file in 0099 /// compilation database. If users don't specify the compilation database 0100 /// directory, it is the current directory where clang-tidy runs. 0101 /// 0102 /// Note: it is empty in unittest. 0103 std::string BuildDirectory; 0104 }; 0105 0106 /// Collection of Diagnostics generated from a single translation unit. 0107 struct TranslationUnitDiagnostics { 0108 /// Name of the main source for the translation unit. 0109 std::string MainSourceFile; 0110 std::vector<Diagnostic> Diagnostics; 0111 }; 0112 0113 /// Get the first fix to apply for this diagnostic. 0114 /// \returns nullptr if no fixes are attached to the diagnostic. 0115 const llvm::StringMap<Replacements> *selectFirstFix(const Diagnostic& D); 0116 0117 } // end namespace tooling 0118 } // end namespace clang 0119 #endif // LLVM_CLANG_TOOLING_CORE_DIAGNOSTIC_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|