Use a .def file for most of the diagnostic options.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166520 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/ARCMigrate/ARCMT.h b/include/clang/ARCMigrate/ARCMT.h
index 0bb91aa..cce8661 100644
--- a/include/clang/ARCMigrate/ARCMT.h
+++ b/include/clang/ARCMigrate/ARCMT.h
@@ -12,6 +12,7 @@
#include "clang/ARCMigrate/FileRemapper.h"
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/SourceLocation.h"
namespace clang {
class ASTContext;
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index e32da94..9990222 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -16,6 +16,7 @@
#define LLVM_CLANG_DIAGNOSTIC_H
#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
@@ -161,13 +162,6 @@
ak_qualtype_pair ///< pair<QualType, QualType>
};
- /// \brief Specifies which overload candidates to display when overload
- /// resolution fails.
- enum OverloadsShown {
- Ovl_All, ///< Show all overloads.
- Ovl_Best ///< Show just the "best" overload candidates.
- };
-
/// \brief Represents on argument value, which is a union discriminated
/// by ArgumentKind, with a value.
typedef std::pair<ArgumentKind, intptr_t> ArgumentValue;
diff --git a/include/clang/Basic/DiagnosticOptions.def b/include/clang/Basic/DiagnosticOptions.def
new file mode 100644
index 0000000..600ed03
--- /dev/null
+++ b/include/clang/Basic/DiagnosticOptions.def
@@ -0,0 +1,61 @@
+//===--- DiagOptions.def - Diagnostic option database ------------- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the diagnostic options. Users of this file
+// must define the DIAGOPT macro to make use of this information.
+// Optionally, the user may also define ENUM_DIAGOPT (for options
+// that have enumeration type and VALUE_DIAGOPT (for options that
+// describe a value rather than a flag).
+//
+//===----------------------------------------------------------------------===//
+#ifndef DIAGOPT
+# error Define the DIAGOPT macro to handle language options
+#endif
+
+#ifndef VALUE_DIAGOPT
+# define VALUE_DIAGOPT(Name, Bits, Default) \
+DIAGOPT(Name, Bits, Default)
+#endif
+
+#ifndef ENUM_DIAGOPT
+# define ENUM_DIAGOPT(Name, Type, Bits, Default) \
+DIAGOPT(Name, Bits, Default)
+#endif
+
+DIAGOPT(IgnoreWarnings, 1, 0) /// -w
+DIAGOPT(NoRewriteMacros, 1, 0) /// -Wno-rewrite-macros
+DIAGOPT(Pedantic, 1, 0) /// -pedantic
+DIAGOPT(PedanticErrors, 1, 0) /// -pedantic-errors
+DIAGOPT(ShowColumn, 1, 1) /// Show column number on diagnostics.
+DIAGOPT(ShowLocation, 1, 1) /// Show source location information.
+DIAGOPT(ShowCarets, 1, 1) /// Show carets in diagnostics.
+DIAGOPT(ShowFixits, 1, 1) /// Show fixit information.
+DIAGOPT(ShowSourceRanges, 1, 0) /// Show source ranges in numeric form.
+DIAGOPT(ShowParseableFixits, 1, 0) /// Show machine parseable fix-its.
+DIAGOPT(ShowOptionNames, 1, 0) /// Show the option name for mappable
+ /// diagnostics.
+DIAGOPT(ShowNoteIncludeStack, 1, 0) /// Show include stacks for notes.
+VALUE_DIAGOPT(ShowCategories, 2, 0) /// Show categories: 0 -> none, 1 -> Number,
+ /// 2 -> Full Name.
+
+ENUM_DIAGOPT(Format, TextDiagnosticFormat, 2, Clang) /// Format for diagnostics:
+
+DIAGOPT(ShowColors, 1, 0) /// Show diagnostics with ANSI color sequences.
+ENUM_DIAGOPT(ShowOverloads, OverloadsShown, 1,
+ Ovl_All) /// Overload candidates to show.
+DIAGOPT(VerifyDiagnostics, 1, 0) /// Check that diagnostics match the expected
+ /// diagnostics, indicated by markers in the
+ /// input source file.
+
+DIAGOPT(ElideType, 1, 0) /// Elide identical types in template diffing
+DIAGOPT(ShowTemplateTree, 1, 0) /// Print a template tree when diffing
+
+#undef DIAGOPT
+#undef ENUM_DIAGOPT
+#undef VALUE_DIAGOPT
diff --git a/include/clang/Basic/DiagnosticOptions.h b/include/clang/Basic/DiagnosticOptions.h
index 77a8476..775d87b 100644
--- a/include/clang/Basic/DiagnosticOptions.h
+++ b/include/clang/Basic/DiagnosticOptions.h
@@ -10,7 +10,6 @@
#ifndef LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
#define LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
-#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include <string>
@@ -18,39 +17,32 @@
namespace clang {
+/// \brief Specifies which overload candidates to display when overload
+/// resolution fails.
+enum OverloadsShown {
+ Ovl_All, ///< Show all overloads.
+ Ovl_Best ///< Show just the "best" overload candidates.
+};
+
/// DiagnosticOptions - Options for controlling the compiler diagnostics
/// engine.
class DiagnosticOptions : public llvm::RefCountedBase<DiagnosticOptions>{
public:
- unsigned IgnoreWarnings : 1; /// -w
- unsigned NoRewriteMacros : 1; /// -Wno-rewrite-macros
- unsigned Pedantic : 1; /// -pedantic
- unsigned PedanticErrors : 1; /// -pedantic-errors
- unsigned ShowColumn : 1; /// Show column number on diagnostics.
- unsigned ShowLocation : 1; /// Show source location information.
- unsigned ShowCarets : 1; /// Show carets in diagnostics.
- unsigned ShowFixits : 1; /// Show fixit information.
- unsigned ShowSourceRanges : 1; /// Show source ranges in numeric form.
- unsigned ShowParseableFixits : 1; /// Show machine parseable fix-its.
- unsigned ShowOptionNames : 1; /// Show the option name for mappable
- /// diagnostics.
- unsigned ShowNoteIncludeStack : 1; /// Show include stacks for notes.
- unsigned ShowCategories : 2; /// Show categories: 0 -> none, 1 -> Number,
- /// 2 -> Full Name.
-
- unsigned Format : 2; /// Format for diagnostics:
enum TextDiagnosticFormat { Clang, Msvc, Vi };
-
- unsigned ShowColors : 1; /// Show diagnostics with ANSI color sequences.
- unsigned ShowOverloads : 1; /// Overload candidates to show. Values from
- /// DiagnosticsEngine::OverloadsShown
- unsigned VerifyDiagnostics: 1; /// Check that diagnostics match the expected
- /// diagnostics, indicated by markers in the
- /// input source file.
- unsigned ElideType: 1; /// Elide identical types in template diffing
- unsigned ShowTemplateTree: 1; /// Print a template tree when diffing
+ // Define simple diagnostic options (with no accessors).
+#define DIAGOPT(Name, Bits, Default) unsigned Name : Bits;
+#define ENUM_DIAGOPT(Name, Type, Bits, Default)
+#include "clang/Basic/DiagnosticOptions.def"
+protected:
+ // Define diagnostic options of enumeration type. These are private, and will
+ // have accessors (below).
+#define DIAGOPT(Name, Bits, Default)
+#define ENUM_DIAGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
+#include "clang/Basic/DiagnosticOptions.def"
+
+public:
unsigned ErrorLimit; /// Limit # errors emitted.
unsigned MacroBacktraceLimit; /// Limit depth of macro expansion backtrace.
unsigned TemplateBacktraceLimit; /// Limit depth of instantiation backtrace.
@@ -81,25 +73,20 @@
std::vector<std::string> Warnings;
public:
+ // Define accessors/mutators for diagnostic options of enumeration type.
+#define DIAGOPT(Name, Bits, Default)
+#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
+ Type get##Name() const { return static_cast<Type>(Name); } \
+ void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
+#include "clang/Basic/DiagnosticOptions.def"
+
DiagnosticOptions() {
- IgnoreWarnings = 0;
- TabStop = DefaultTabStop;
+#define DIAGOPT(Name, Bits, Default) Name = Default;
+#define ENUM_DIAGOPT(Name, Type, Bits, Default) set##Name(Default);
+#include "clang/Basic/DiagnosticOptions.def"
+
MessageLength = 0;
- NoRewriteMacros = 0;
- Pedantic = 0;
- PedanticErrors = 0;
- ShowCarets = 1;
- ShowColors = 0;
- ShowOverloads = DiagnosticsEngine::Ovl_All;
- ShowColumn = 1;
- ShowFixits = 1;
- ShowLocation = 1;
- ShowOptionNames = 0;
- ShowCategories = 0;
- Format = Clang;
- ShowSourceRanges = 0;
- ShowParseableFixits = 0;
- VerifyDiagnostics = 0;
+ TabStop = DefaultTabStop;
ErrorLimit = 0;
TemplateBacktraceLimit = DefaultTemplateBacktraceLimit;
MacroBacktraceLimit = DefaultMacroBacktraceLimit;
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index 6736d1a..548ff86 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -11,6 +11,7 @@
#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/ModuleLoader.h"
#include "llvm/ADT/ArrayRef.h"
diff --git a/lib/ARCMigrate/Internals.h b/lib/ARCMigrate/Internals.h
index 935fc9b..1966a98 100644
--- a/lib/ARCMigrate/Internals.h
+++ b/lib/ARCMigrate/Internals.h
@@ -11,8 +11,10 @@
#define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
#include "clang/ARCMigrate/ARCMT.h"
+#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
+#include <list>
namespace clang {
class Sema;
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index ed47296..ae11805 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -378,7 +378,7 @@
Res.push_back("-fdiagnostics-show-category=id");
else if (Opts.ShowCategories == 2)
Res.push_back("-fdiagnostics-show-category=name");
- switch (Opts.Format) {
+ switch (Opts.getFormat()) {
case DiagnosticOptions::Clang:
Res.push_back("-fdiagnostics-format=clang"); break;
case DiagnosticOptions::Msvc:
@@ -1395,9 +1395,9 @@
StringRef ShowOverloads =
Args.getLastArgValue(OPT_fshow_overloads_EQ, "all");
if (ShowOverloads == "best")
- Opts.ShowOverloads = DiagnosticsEngine::Ovl_Best;
+ Opts.setShowOverloads(Ovl_Best);
else if (ShowOverloads == "all")
- Opts.ShowOverloads = DiagnosticsEngine::Ovl_All;
+ Opts.setShowOverloads(Ovl_All);
else {
Success = false;
if (Diags)
@@ -1425,11 +1425,11 @@
StringRef Format =
Args.getLastArgValue(OPT_fdiagnostics_format, "clang");
if (Format == "clang")
- Opts.Format = DiagnosticOptions::Clang;
+ Opts.setFormat(DiagnosticOptions::Clang);
else if (Format == "msvc")
- Opts.Format = DiagnosticOptions::Msvc;
+ Opts.setFormat(DiagnosticOptions::Msvc);
else if (Format == "vi")
- Opts.Format = DiagnosticOptions::Vi;
+ Opts.setFormat(DiagnosticOptions::Vi);
else {
Success = false;
if (Diags)
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp
index 5baaf22..5982388 100644
--- a/lib/Frontend/TextDiagnostic.cpp
+++ b/lib/Frontend/TextDiagnostic.cpp
@@ -809,7 +809,7 @@
OS.changeColor(savedColor, true);
OS << PLoc.getFilename();
- switch (DiagOpts->Format) {
+ switch (DiagOpts->getFormat()) {
case DiagnosticOptions::Clang: OS << ':' << LineNo; break;
case DiagnosticOptions::Msvc: OS << '(' << LineNo; break;
case DiagnosticOptions::Vi: OS << " +" << LineNo; break;
@@ -818,14 +818,14 @@
if (DiagOpts->ShowColumn)
// Compute the column number.
if (unsigned ColNo = PLoc.getColumn()) {
- if (DiagOpts->Format == DiagnosticOptions::Msvc) {
+ if (DiagOpts->getFormat() == DiagnosticOptions::Msvc) {
OS << ',';
ColNo--;
} else
OS << ':';
OS << ColNo;
}
- switch (DiagOpts->Format) {
+ switch (DiagOpts->getFormat()) {
case DiagnosticOptions::Clang:
case DiagnosticOptions::Vi: OS << ':'; break;
case DiagnosticOptions::Msvc: OS << ") : "; break;
diff --git a/lib/Frontend/Warnings.cpp b/lib/Frontend/Warnings.cpp
index a60fe95..f789b7f 100644
--- a/lib/Frontend/Warnings.cpp
+++ b/lib/Frontend/Warnings.cpp
@@ -51,8 +51,7 @@
const DiagnosticOptions &Opts) {
Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers
Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
- Diags.setShowOverloads(
- static_cast<DiagnosticsEngine::OverloadsShown>(Opts.ShowOverloads));
+ Diags.setShowOverloads(Opts.getShowOverloads());
Diags.setElideType(Opts.ElideType);
Diags.setPrintTemplateTree(Opts.ShowTemplateTree);
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index c7d378f..13a33b7 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -1187,8 +1187,7 @@
DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
// FIXME: Magic number for max shown overloads stolen from
// OverloadCandidateSet::NoteCandidates.
- if (ShownOverloads >= 4 &&
- S.Diags.getShowOverloads() == DiagnosticsEngine::Ovl_Best) {
+ if (ShownOverloads >= 4 && S.Diags.getShowOverloads() == Ovl_Best) {
++SuppressedOverloads;
continue;
}
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 4d392ed..a080031 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -8832,8 +8832,7 @@
bool ReportedAmbiguousConversions = false;
SmallVectorImpl<OverloadCandidate*>::iterator I, E;
- const DiagnosticsEngine::OverloadsShown ShowOverloads =
- S.Diags.getShowOverloads();
+ const OverloadsShown ShowOverloads = S.Diags.getShowOverloads();
unsigned CandsShown = 0;
for (I = Cands.begin(), E = Cands.end(); I != E; ++I) {
OverloadCandidate *Cand = *I;
@@ -8841,7 +8840,7 @@
// Set an arbitrary limit on the number of candidate functions we'll spam
// the user with. FIXME: This limit should depend on details of the
// candidate list.
- if (CandsShown >= 4 && ShowOverloads == DiagnosticsEngine::Ovl_Best) {
+ if (CandsShown >= 4 && ShowOverloads == Ovl_Best) {
break;
}
++CandsShown;