1 //===- DiagnosticOptions.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H 10 #define LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H 11 12 #include "clang/Basic/LLVM.h" 13 #include <string> 14 #include <type_traits> 15 #include <vector> 16 17 namespace llvm { 18 namespace opt { 19 class ArgList; 20 } // namespace opt 21 } // namespace llvm 22 23 namespace clang { 24 class DiagnosticsEngine; 25 26 /// Specifies which overload candidates to display when overload 27 /// resolution fails. 28 enum OverloadsShown : unsigned { 29 /// Show all overloads. 30 Ovl_All, 31 32 /// Show just the "best" overload candidates. 33 Ovl_Best 34 }; 35 36 /// A bitmask representing the diagnostic levels used by 37 /// VerifyDiagnosticConsumer. 38 enum class DiagnosticLevelMask : unsigned { 39 None = 0, 40 Note = 1 << 0, 41 Remark = 1 << 1, 42 Warning = 1 << 2, 43 Error = 1 << 3, 44 All = Note | Remark | Warning | Error 45 }; 46 47 inline DiagnosticLevelMask operator~(DiagnosticLevelMask M) { 48 using UT = std::underlying_type_t<DiagnosticLevelMask>; 49 return static_cast<DiagnosticLevelMask>(~static_cast<UT>(M)); 50 } 51 52 inline DiagnosticLevelMask operator|(DiagnosticLevelMask LHS, 53 DiagnosticLevelMask RHS) { 54 using UT = std::underlying_type_t<DiagnosticLevelMask>; 55 return static_cast<DiagnosticLevelMask>( 56 static_cast<UT>(LHS) | static_cast<UT>(RHS)); 57 } 58 59 inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS, 60 DiagnosticLevelMask RHS) { 61 using UT = std::underlying_type_t<DiagnosticLevelMask>; 62 return static_cast<DiagnosticLevelMask>( 63 static_cast<UT>(LHS) & static_cast<UT>(RHS)); 64 } 65 66 raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M); 67 68 /// Options for controlling the compiler diagnostics engine. 69 class DiagnosticOptions { 70 friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &, 71 clang::DiagnosticsEngine *, bool); 72 73 friend class CompilerInvocation; 74 friend class CompilerInvocationBase; 75 76 public: 77 enum TextDiagnosticFormat { Clang, MSVC, Vi, SARIF }; 78 79 // Default values. 80 enum { 81 DefaultTabStop = 8, 82 MaxTabStop = 100, 83 DefaultMacroBacktraceLimit = 6, 84 DefaultTemplateBacktraceLimit = 10, 85 DefaultConstexprBacktraceLimit = 10, 86 DefaultSpellCheckingLimit = 50, 87 DefaultSnippetLineLimit = 16, 88 DefaultShowLineNumbers = 1, 89 }; 90 91 // Define simple diagnostic options (with no accessors). 92 #define DIAGOPT(Name, Bits, Default) unsigned Name : Bits; 93 #define ENUM_DIAGOPT(Name, Type, Bits, Default) 94 #include "clang/Basic/DiagnosticOptions.def" 95 96 protected: 97 // Define diagnostic options of enumeration type. These are private, and will 98 // have accessors (below). 99 #define DIAGOPT(Name, Bits, Default) 100 #define ENUM_DIAGOPT(Name, Type, Bits, Default) unsigned Name : Bits; 101 #include "clang/Basic/DiagnosticOptions.def" 102 103 public: 104 /// The file to log diagnostic output to. 105 std::string DiagnosticLogFile; 106 107 /// The file to serialize diagnostics to (non-appending). 108 std::string DiagnosticSerializationFile; 109 110 /// Path for the file that defines diagnostic suppression mappings. 111 std::string DiagnosticSuppressionMappingsFile; 112 113 /// The list of -W... options used to alter the diagnostic mappings, with the 114 /// prefixes removed. 115 std::vector<std::string> Warnings; 116 117 /// The list of prefixes from -Wundef-prefix=... used to generate warnings 118 /// for undefined macros. 119 std::vector<std::string> UndefPrefixes; 120 121 /// The list of -R... options used to alter the diagnostic mappings, with the 122 /// prefixes removed. 123 std::vector<std::string> Remarks; 124 125 /// The prefixes for comment directives sought by -verify ("expected" by 126 /// default). 127 std::vector<std::string> VerifyPrefixes; 128 129 /// The list of -Wsystem-headers-in-module=... options used to override 130 /// whether -Wsystem-headers is enabled on a per-module basis. 131 std::vector<std::string> SystemHeaderWarningsModules; 132 133 public: 134 // Define accessors/mutators for diagnostic options of enumeration type. 135 #define DIAGOPT(Name, Bits, Default) 136 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ 137 Type get##Name() const { return static_cast<Type>(Name); } \ 138 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 139 #include "clang/Basic/DiagnosticOptions.def" 140 DiagnosticOptions()141 DiagnosticOptions() { 142 #define DIAGOPT(Name, Bits, Default) Name = Default; 143 #define ENUM_DIAGOPT(Name, Type, Bits, Default) set##Name(Default); 144 #include "clang/Basic/DiagnosticOptions.def" 145 } 146 }; 147 148 using TextDiagnosticFormat = DiagnosticOptions::TextDiagnosticFormat; 149 150 } // namespace clang 151 152 #endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H 153