[cfe-commits] r166520 - in /cfe/trunk: include/clang/ARCMigrate/ARCMT.h include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticOptions.def include/clang/Basic/DiagnosticOptions.h include/clang/Frontend/CompilerInstance.h lib/ARCMigrate/Internals.h lib/Frontend/CompilerInvocation.cpp lib/Frontend/TextDiagnostic.cpp lib/Frontend/Warnings.cpp lib/Sema/Sema.cpp lib/Sema/SemaOverload.cpp

Douglas Gregor dgregor at apple.com
Tue Oct 23 16:11:24 PDT 2012


Author: dgregor
Date: Tue Oct 23 18:11:23 2012
New Revision: 166520

URL: http://llvm.org/viewvc/llvm-project?rev=166520&view=rev
Log:
Use a .def file for most of the diagnostic options.

Added:
    cfe/trunk/include/clang/Basic/DiagnosticOptions.def
Modified:
    cfe/trunk/include/clang/ARCMigrate/ARCMT.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Basic/DiagnosticOptions.h
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/lib/ARCMigrate/Internals.h
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/TextDiagnostic.cpp
    cfe/trunk/lib/Frontend/Warnings.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/ARCMigrate/ARCMT.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMT.h?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/include/clang/ARCMigrate/ARCMT.h (original)
+++ cfe/trunk/include/clang/ARCMigrate/ARCMT.h Tue Oct 23 18:11:23 2012
@@ -12,6 +12,7 @@
 
 #include "clang/ARCMigrate/FileRemapper.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/SourceLocation.h"
 
 namespace clang {
   class ASTContext;

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Oct 23 18:11:23 2012
@@ -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;

Added: cfe/trunk/include/clang/Basic/DiagnosticOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticOptions.def?rev=166520&view=auto
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticOptions.def (added)
+++ cfe/trunk/include/clang/Basic/DiagnosticOptions.def Tue Oct 23 18:11:23 2012
@@ -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

Modified: cfe/trunk/include/clang/Basic/DiagnosticOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticOptions.h?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticOptions.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticOptions.h Tue Oct 23 18:11:23 2012
@@ -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;

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Oct 23 18:11:23 2012
@@ -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"

Modified: cfe/trunk/lib/ARCMigrate/Internals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Internals.h?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Internals.h (original)
+++ cfe/trunk/lib/ARCMigrate/Internals.h Tue Oct 23 18:11:23 2012
@@ -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;

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Oct 23 18:11:23 2012
@@ -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)

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Tue Oct 23 18:11:23 2012
@@ -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;

Modified: cfe/trunk/lib/Frontend/Warnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Warnings.cpp?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Warnings.cpp (original)
+++ cfe/trunk/lib/Frontend/Warnings.cpp Tue Oct 23 18:11:23 2012
@@ -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);

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Oct 23 18:11:23 2012
@@ -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;
     }

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=166520&r1=166519&r2=166520&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Oct 23 18:11:23 2012
@@ -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;





More information about the cfe-commits mailing list