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 "llvm/ADT/IntrusiveRefCntPtr.h"
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17 
18 namespace llvm {
19 namespace opt {
20 class ArgList;
21 } // namespace opt
22 } // namespace llvm
23 
24 namespace clang {
25 class DiagnosticsEngine;
26 
27 /// Specifies which overload candidates to display when overload
28 /// resolution fails.
29 enum OverloadsShown : unsigned {
30   /// Show all overloads.
31   Ovl_All,
32 
33   /// Show just the "best" overload candidates.
34   Ovl_Best
35 };
36 
37 /// A bitmask representing the diagnostic levels used by
38 /// VerifyDiagnosticConsumer.
39 enum class DiagnosticLevelMask : unsigned {
40   None    = 0,
41   Note    = 1 << 0,
42   Remark  = 1 << 1,
43   Warning = 1 << 2,
44   Error   = 1 << 3,
45   All     = Note | Remark | Warning | Error
46 };
47 
48 inline DiagnosticLevelMask operator~(DiagnosticLevelMask M) {
49   using UT = std::underlying_type_t<DiagnosticLevelMask>;
50   return static_cast<DiagnosticLevelMask>(~static_cast<UT>(M));
51 }
52 
53 inline DiagnosticLevelMask operator|(DiagnosticLevelMask LHS,
54                                      DiagnosticLevelMask RHS) {
55   using UT = std::underlying_type_t<DiagnosticLevelMask>;
56   return static_cast<DiagnosticLevelMask>(
57     static_cast<UT>(LHS) | static_cast<UT>(RHS));
58 }
59 
60 inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
61                                      DiagnosticLevelMask RHS) {
62   using UT = std::underlying_type_t<DiagnosticLevelMask>;
63   return static_cast<DiagnosticLevelMask>(
64     static_cast<UT>(LHS) & static_cast<UT>(RHS));
65 }
66 
67 raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
68 
69 /// Options for controlling the compiler diagnostics engine.
70 class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
71   friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
72                                   clang::DiagnosticsEngine *, bool);
73 
74   friend class CompilerInvocation;
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   /// The list of -W... options used to alter the diagnostic mappings, with the
111   /// prefixes removed.
112   std::vector<std::string> Warnings;
113 
114   /// The list of prefixes from -Wundef-prefix=... used to generate warnings
115   /// for undefined macros.
116   std::vector<std::string> UndefPrefixes;
117 
118   /// The list of -R... options used to alter the diagnostic mappings, with the
119   /// prefixes removed.
120   std::vector<std::string> Remarks;
121 
122   /// The prefixes for comment directives sought by -verify ("expected" by
123   /// default).
124   std::vector<std::string> VerifyPrefixes;
125 
126 public:
127   // Define accessors/mutators for diagnostic options of enumeration type.
128 #define DIAGOPT(Name, Bits, Default)
129 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
130   Type get##Name() const { return static_cast<Type>(Name); } \
131   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
132 #include "clang/Basic/DiagnosticOptions.def"
133 
134   DiagnosticOptions() {
135 #define DIAGOPT(Name, Bits, Default) Name = Default;
136 #define ENUM_DIAGOPT(Name, Type, Bits, Default) set##Name(Default);
137 #include "clang/Basic/DiagnosticOptions.def"
138   }
139 };
140 
141 using TextDiagnosticFormat = DiagnosticOptions::TextDiagnosticFormat;
142 
143 } // namespace clang
144 
145 #endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
146