From: Daniel Dunbar Date: Thu, 12 Nov 2009 07:28:44 +0000 (+0000) Subject: Move warning options into DiagnosticOptions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6907943901e0aae5be7618c36c0f8275634e6ab5;p=clang Move warning options into DiagnosticOptions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86968 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/DiagnosticOptions.h b/include/clang/Frontend/DiagnosticOptions.h index 39dc48ebfe..704769ec12 100644 --- a/include/clang/Frontend/DiagnosticOptions.h +++ b/include/clang/Frontend/DiagnosticOptions.h @@ -19,6 +19,10 @@ namespace clang { /// engine. class 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. @@ -35,16 +39,24 @@ public: /// testing and analysis. std::string DumpBuildInformation; + /// The list of -W... options used to alter the diagnostic mappings, with the + /// prefixes removed. + std::vector Warnings; + public: DiagnosticOptions() { - ShowColumn = 1; - ShowLocation = 1; + IgnoreWarnings = 0; + MessageLength = 0; + NoRewriteMacros = 0; + Pedantic = 0; + PedanticErrors = 0; ShowCarets = 1; + ShowColors = 0; + ShowColumn = 1; ShowFixits = 1; - ShowSourceRanges = 0; + ShowLocation = 1; ShowOptionNames = 0; - ShowColors = 0; - MessageLength = 0; + ShowSourceRanges = 0; } }; diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 4bda8bd71d..27c14c9170 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -29,6 +29,7 @@ class ASTConsumer; class Decl; class DependencyOutputOptions; class Diagnostic; +class DiagnosticOptions; class HeaderSearch; class HeaderSearchOptions; class IdentifierTable; @@ -59,10 +60,7 @@ void InitializePreprocessor(Preprocessor &PP, /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. -bool ProcessWarningOptions(Diagnostic &Diags, - std::vector &Warnings, - bool Pedantic, bool PedanticErrors, - bool NoWarnings); +bool ProcessWarningOptions(Diagnostic &Diags, const DiagnosticOptions &Opts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS, diff --git a/lib/Frontend/Warnings.cpp b/lib/Frontend/Warnings.cpp index 3f442c8a7f..ff44c90516 100644 --- a/lib/Frontend/Warnings.cpp +++ b/lib/Frontend/Warnings.cpp @@ -24,6 +24,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Sema/SemaDiagnostic.h" #include "clang/Lex/LexDiagnostic.h" +#include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include #include @@ -32,26 +33,24 @@ using namespace clang; bool clang::ProcessWarningOptions(Diagnostic &Diags, - std::vector &Warnings, - bool Pedantic, bool PedanticErrors, - bool NoWarnings) { + const DiagnosticOptions &Opts) { Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers - Diags.setIgnoreAllWarnings(NoWarnings); + Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings); // If -pedantic or -pedantic-errors was specified, then we want to map all // extension diagnostics onto WARNING or ERROR unless the user has futz'd // around with them explicitly. - if (PedanticErrors) + if (Opts.PedanticErrors) Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Error); - else if (Pedantic) + else if (Opts.Pedantic) Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Warn); else Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore); // FIXME: -Wfatal-errors / -Wfatal-errors=foo - for (unsigned i = 0, e = Warnings.size(); i != e; ++i) { - const std::string &Opt = Warnings[i]; + for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) { + const std::string &Opt = Opts.Warnings[i]; const char *OptStart = &Opt[0]; const char *OptEnd = OptStart+Opt.size(); assert(*OptEnd == 0 && "Expect null termination for lower-bound search"); diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 7c716406ce..de2122a892 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -245,6 +245,18 @@ NoDiagnosticsFixIt("fno-diagnostics-fixit-info", llvm::cl::desc("Do not include fixit information in" " diagnostics")); +static llvm::cl::opt OptNoWarnings("w"); + +static llvm::cl::opt OptPedantic("pedantic"); + +static llvm::cl::opt OptPedanticErrors("pedantic-errors"); + +// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The +// driver has stripped off -Wa,foo etc. The driver has also translated -W to +// -Wextra, so we don't need to worry about it. +static llvm::cl::list +OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); + static llvm::cl::opt PrintSourceRangeInfo("fdiagnostics-print-source-range-info", llvm::cl::desc("Print source range spans in numeric form")); @@ -263,6 +275,10 @@ static llvm::cl::opt PrintColorDiagnostic("fcolor-diagnostics", llvm::cl::desc("Use colors in diagnostics")); +static llvm::cl::opt +SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), + llvm::cl::desc("Silence ObjC rewriting warnings")); + } //===----------------------------------------------------------------------===// @@ -664,8 +680,14 @@ void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) { void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) { using namespace diagnosticoptions; + Opts.Warnings.insert(Opts.Warnings.begin(), + OptWarnings.begin(), OptWarnings.end()); Opts.DumpBuildInformation = DumpBuildInformation; + Opts.IgnoreWarnings = OptNoWarnings; Opts.MessageLength = MessageLength; + Opts.NoRewriteMacros = SilenceRewriteMacroWarning; + Opts.Pedantic = OptPedantic; + Opts.PedanticErrors = OptPedanticErrors; Opts.ShowCarets = !NoCaretDiagnostics; Opts.ShowColors = PrintColorDiagnostic; Opts.ShowColumn = !NoShowColumn; @@ -1106,4 +1128,3 @@ clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) { Opts.ShowComments = EnableCommentOutput; Opts.ShowMacroComments = EnableMacroCommentOutput; } - diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index f2b38401e7..ad55753527 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -427,28 +427,6 @@ static llvm::cl::list FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), llvm::cl::desc("Perform Fix-It modifications at the given source location")); -//===----------------------------------------------------------------------===// -// ObjC Rewriter Options -//===----------------------------------------------------------------------===// - -static llvm::cl::opt -SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), - llvm::cl::desc("Silence ObjC rewriting warnings")); - -//===----------------------------------------------------------------------===// -// Warning Options -//===----------------------------------------------------------------------===// - -// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The -// driver has stripped off -Wa,foo etc. The driver has also translated -W to -// -Wextra, so we don't need to worry about it. -static llvm::cl::list -OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); - -static llvm::cl::opt OptPedantic("pedantic"); -static llvm::cl::opt OptPedanticErrors("pedantic-errors"); -static llvm::cl::opt OptNoWarnings("w"); - //===----------------------------------------------------------------------===// // Dump Build Information //===----------------------------------------------------------------------===// @@ -596,7 +574,8 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, case RewriteObjC: OS.reset(ComputeOutFile(CompOpts, InFile, "cpp", true, OutPath)); return CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(), - PP.getLangOptions(), SilenceRewriteMacroWarning); + PP.getLangOptions(), + CompOpts.getDiagnosticOpts().NoRewriteMacros); case RewriteBlocks: return CreateBlockRewriter(InFile, PP.getDiagnostics(), @@ -1079,8 +1058,7 @@ static Diagnostic *CreateDiagnosticEngine(const DiagnosticOptions &Opts, // Configure our handling of diagnostics. Diagnostic *Diags = new Diagnostic(DiagClient.take()); - if (ProcessWarningOptions(*Diags, OptWarnings, OptPedantic, OptPedanticErrors, - OptNoWarnings)) + if (ProcessWarningOptions(*Diags, Opts)) return 0; // Set an error handler, so that any LLVM backend diagnostics go through our