clang 23.0.0git
DiagnosticOptions.h
Go to the documentation of this file.
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
17namespace llvm {
18namespace opt {
19class ArgList;
20} // namespace opt
21} // namespace llvm
22
23namespace clang {
24class DiagnosticsEngine;
25
26/// Controls whether to show colors in diagnostic output.
27enum class ShowColorsKind : unsigned {
28 /// Emit colors only if the output stream is detected to support them.
30 /// Always emit colors regardless of the output stream.
32 /// Never emit colors regardless of the output stream.
34};
35
36/// Specifies which overload candidates to display when overload
37/// resolution fails.
38enum OverloadsShown : unsigned {
39 /// Show all overloads.
41
42 /// Show just the "best" overload candidates.
44};
45
46/// A bitmask representing the diagnostic levels used by
47/// VerifyDiagnosticConsumer.
48enum class DiagnosticLevelMask : unsigned {
49 None = 0,
50 Note = 1 << 0,
51 Remark = 1 << 1,
52 Warning = 1 << 2,
53 Error = 1 << 3,
55};
56
58 using UT = std::underlying_type_t<DiagnosticLevelMask>;
59 return static_cast<DiagnosticLevelMask>(~static_cast<UT>(M));
60}
61
64 using UT = std::underlying_type_t<DiagnosticLevelMask>;
65 return static_cast<DiagnosticLevelMask>(
66 static_cast<UT>(LHS) | static_cast<UT>(RHS));
67}
68
71 using UT = std::underlying_type_t<DiagnosticLevelMask>;
72 return static_cast<DiagnosticLevelMask>(
73 static_cast<UT>(LHS) & static_cast<UT>(RHS));
74}
75
76raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
77
78/// Options for controlling the compiler diagnostics engine.
80 friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
82
83 friend class CompilerInvocation;
85
86public:
88
89 // Default values.
90 enum {
99 };
100
101 // Define simple diagnostic options (with no accessors).
102#define DIAGOPT(Name, Bits, Default) unsigned Name : Bits;
103#define ENUM_DIAGOPT(Name, Type, Bits, Default)
104#include "clang/Basic/DiagnosticOptions.def"
105
106protected:
107 // Define diagnostic options of enumeration type. These are private, and will
108 // have accessors (below).
109#define DIAGOPT(Name, Bits, Default)
110#define ENUM_DIAGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
111#include "clang/Basic/DiagnosticOptions.def"
112
113public:
114 /// The file to log diagnostic output to.
115 std::string DiagnosticLogFile;
116
117 /// The file to serialize diagnostics to (non-appending).
119
120 /// Path for the file that defines diagnostic suppression mappings.
122
123 /// The list of -W... options used to alter the diagnostic mappings, with the
124 /// prefixes removed.
125 std::vector<std::string> Warnings;
126
127 /// The list of prefixes from -Wundef-prefix=... used to generate warnings
128 /// for undefined macros.
129 std::vector<std::string> UndefPrefixes;
130
131 /// The list of -R... options used to alter the diagnostic mappings, with the
132 /// prefixes removed.
133 std::vector<std::string> Remarks;
134
135 /// The prefixes for comment directives sought by -verify ("expected" by
136 /// default).
137 std::vector<std::string> VerifyPrefixes;
138
139 /// The list of -Wsystem-headers-in-module=... options used to override
140 /// whether -Wsystem-headers is enabled on a per-module basis.
141 std::vector<std::string> SystemHeaderWarningsModules;
142
143public:
144 // Define accessors/mutators for diagnostic options of enumeration type.
145#define DIAGOPT(Name, Bits, Default)
146#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
147 Type get##Name() const { return static_cast<Type>(Name); } \
148 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
149#include "clang/Basic/DiagnosticOptions.def"
150
152#define DIAGOPT(Name, Bits, Default) Name = Default;
153#define ENUM_DIAGOPT(Name, Type, Bits, Default) set##Name(Default);
154#include "clang/Basic/DiagnosticOptions.def"
155 }
156
157 /// Resolve the color mode against a stream's capability.
158 bool showColors(bool StreamHasColors) const {
159 switch (getShowColors()) {
161 return true;
163 return false;
165 return StreamHasColors;
166 }
167 return false;
168 }
169};
170
172
173} // namespace clang
174
175#endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
std::string DiagnosticSuppressionMappingsFile
Path for the file that defines diagnostic suppression mappings.
std::vector< std::string > Remarks
The list of -R... options used to alter the diagnostic mappings, with the prefixes removed.
friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &, clang::DiagnosticsEngine *, bool)
Fill out Opts based on the options given in Args.
std::vector< std::string > Warnings
The list of -W... options used to alter the diagnostic mappings, with the prefixes removed.
bool showColors(bool StreamHasColors) const
Resolve the color mode against a stream's capability.
std::string DiagnosticLogFile
The file to log diagnostic output to.
std::vector< std::string > VerifyPrefixes
The prefixes for comment directives sought by -verify ("expected" by default).
std::vector< std::string > UndefPrefixes
The list of prefixes from -Wundef-prefix=... used to generate warnings for undefined macros.
std::vector< std::string > SystemHeaderWarningsModules
The list of -Wsystem-headers-in-module=... options used to override whether -Wsystem-headers is enabl...
std::string DiagnosticSerializationFile
The file to serialize diagnostics to (non-appending).
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:234
The JSON file list parser is used to communicate input to InstallAPI.
DiagnosticLevelMask
A bitmask representing the diagnostic levels used by VerifyDiagnosticConsumer.
DiagnosticOptions::TextDiagnosticFormat TextDiagnosticFormat
DiagnosticLevelMask operator&(DiagnosticLevelMask LHS, DiagnosticLevelMask RHS)
OverloadsShown
Specifies which overload candidates to display when overload resolution fails.
@ Ovl_All
Show all overloads.
@ Ovl_Best
Show just the "best" overload candidates.
DiagnosticLevelMask operator~(DiagnosticLevelMask M)
DiagnosticLevelMask operator|(DiagnosticLevelMask LHS, DiagnosticLevelMask RHS)
ShowColorsKind
Controls whether to show colors in diagnostic output.
@ Auto
Emit colors only if the output stream is detected to support them.
@ On
Always emit colors regardless of the output stream.
@ Off
Never emit colors regardless of the output stream.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30