[cfe-commits] r111020 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/FrontendOptions.h include/clang/Rewrite/FixItRewriter.h include/clang/Rewrite/FrontendActions.h lib/Frontend/CompilerInvocation.cpp lib/Rewrite/FixItRewriter.cpp lib/Rewrite/FrontendActions.cpp

Nick Lewycky nicholas at mxc.ca
Fri Aug 13 10:31:00 PDT 2010


Author: nicholas
Date: Fri Aug 13 12:31:00 2010
New Revision: 111020

URL: http://llvm.org/viewvc/llvm-project?rev=111020&view=rev
Log:
Add a new cc1 option -fix-what-you-can which when combined with the fix-it mode
will apply all fixes even when there were other errors in the file.

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/include/clang/Rewrite/FixItRewriter.h
    cfe/trunk/include/clang/Rewrite/FrontendActions.h
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Rewrite/FixItRewriter.cpp
    cfe/trunk/lib/Rewrite/FrontendActions.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Aug 13 12:31:00 2010
@@ -358,9 +358,10 @@
   HelpText<"Print performance metrics and statistics">;
 def ftime_report : Flag<"-ftime-report">,
   HelpText<"Print the amount of time each phase of compilation takes">;
-
 def fdump_record_layouts : Flag<"-fdump-record-layouts">,
   HelpText<"Dump record layout information">;
+def fix_what_you_can : Flag<"-fix-what-you-can">,
+  HelpText<"Apply fix-it advice even in the presence of unfixable errors">;
 
 // Generic forwarding to LLVM options. This should only be used for debugging
 // and experimental features.

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Fri Aug 13 12:31:00 2010
@@ -74,6 +74,8 @@
   unsigned ShowTimers : 1;                 ///< Show timers for individual
                                            /// actions.
   unsigned ShowVersion : 1;                ///< Show the -version text.
+  unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
+                                           /// unfixable errors.
 
   /// The input files and their types.
   std::vector<std::pair<InputKind, std::string> > Inputs;

Modified: cfe/trunk/include/clang/Rewrite/FixItRewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/FixItRewriter.h?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/FixItRewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/FixItRewriter.h Fri Aug 13 12:31:00 2010
@@ -27,13 +27,16 @@
 class SourceManager;
 class FileEntry;
 
-class FixItPathRewriter {
+class FixItOptions {
 public:
-  virtual ~FixItPathRewriter();
+  virtual ~FixItOptions();
 
   /// \brief This file is about to be rewritten. Return the name of the file
   /// that is okay to write to.
   virtual std::string RewriteFilename(const std::string &Filename) = 0;
+
+  /// \brief Whether to abort fixing a file when not all errors could be fixed.
+  bool FixWhatYouCan;
 };
 
 class FixItRewriter : public DiagnosticClient {
@@ -50,7 +53,7 @@
 
   /// \brief Turn an input path into an output path. NULL implies overwriting
   /// the original.
-  FixItPathRewriter *PathRewriter;
+  FixItOptions *FixItOpts;
 
   /// \brief The number of rewriter failures.
   unsigned NumFailures;
@@ -60,7 +63,7 @@
 
   /// \brief Initialize a new fix-it rewriter.
   FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
-                const LangOptions &LangOpts, FixItPathRewriter *PathRewriter);
+                const LangOptions &LangOpts, FixItOptions *FixItOpts);
 
   /// \brief Destroy the fix-it rewriter.
   ~FixItRewriter();

Modified: cfe/trunk/include/clang/Rewrite/FrontendActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/FrontendActions.h?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Rewrite/FrontendActions.h Fri Aug 13 12:31:00 2010
@@ -16,7 +16,7 @@
 
 namespace clang {
 class FixItRewriter;
-class FixItPathRewriter;
+class FixItOptions;
 
 //===----------------------------------------------------------------------===//
 // AST Consumer Actions
@@ -31,7 +31,7 @@
 class FixItAction : public ASTFrontendAction {
 protected:
   llvm::OwningPtr<FixItRewriter> Rewriter;
-  llvm::OwningPtr<FixItPathRewriter> PathRewriter;
+  llvm::OwningPtr<FixItOptions> FixItOpts;
 
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
                                          llvm::StringRef InFile);

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Aug 13 12:31:00 2010
@@ -369,6 +369,8 @@
     Res.push_back("-ftime-report");
   if (Opts.ShowVersion)
     Res.push_back("-version");
+  if (Opts.FixWhatYouCan)
+    Res.push_back("-fix-what-you-can");
 
   bool NeedLang = false;
   for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i)
@@ -1051,6 +1053,7 @@
   Opts.ViewClassInheritance = Args.getLastArgValue(OPT_cxx_inheritance_view);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
+  Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
 
   InputKind DashX = IK_None;
   if (const Arg *A = Args.getLastArg(OPT_x)) {

Modified: cfe/trunk/lib/Rewrite/FixItRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/FixItRewriter.cpp?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/FixItRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/FixItRewriter.cpp Fri Aug 13 12:31:00 2010
@@ -27,10 +27,10 @@
 
 FixItRewriter::FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
                              const LangOptions &LangOpts,
-                             FixItPathRewriter *PathRewriter)
+                             FixItOptions *FixItOpts)
   : Diags(Diags),
     Rewrite(SourceMgr, LangOpts),
-    PathRewriter(PathRewriter),
+    FixItOpts(FixItOpts),
     NumFailures(0) {
   Client = Diags.getClient();
   Diags.setClient(this);
@@ -49,7 +49,7 @@
 }
 
 bool FixItRewriter::WriteFixedFiles() {
-  if (NumFailures > 0) {
+  if (NumFailures > 0 && !FixItOpts->FixWhatYouCan) {
     Diag(FullSourceLoc(), diag::warn_fixit_no_changes);
     return true;
   }
@@ -57,8 +57,8 @@
   for (iterator I = buffer_begin(), E = buffer_end(); I != E; ++I) {
     const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
     std::string Filename = Entry->getName();
-    if (PathRewriter)
-      Filename = PathRewriter->RewriteFilename(Filename);
+    if (FixItOpts)
+      Filename = FixItOpts->RewriteFilename(Filename);
     std::string Err;
     llvm::raw_fd_ostream OS(Filename.c_str(), Err,
                             llvm::raw_fd_ostream::F_Binary);
@@ -164,4 +164,4 @@
   Diags.setClient(this);
 }
 
-FixItPathRewriter::~FixItPathRewriter() {}
+FixItOptions::~FixItOptions() {}

Modified: cfe/trunk/lib/Rewrite/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/FrontendActions.cpp?rev=111020&r1=111019&r2=111020&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Rewrite/FrontendActions.cpp Fri Aug 13 12:31:00 2010
@@ -42,12 +42,14 @@
   return new ASTConsumer();
 }
 
-class FixItActionSuffixInserter : public FixItPathRewriter {
+class FixItActionSuffixInserter : public FixItOptions {
   std::string NewSuffix;
 
 public:
-  explicit FixItActionSuffixInserter(std::string NewSuffix)
-    : NewSuffix(NewSuffix) {}
+  FixItActionSuffixInserter(std::string NewSuffix, bool FixWhatYouCan)
+    : NewSuffix(NewSuffix) {
+      this->FixWhatYouCan = FixWhatYouCan;
+  }
 
   std::string RewriteFilename(const std::string &Filename) {
     llvm::sys::Path Path(Filename);
@@ -62,12 +64,13 @@
                                         llvm::StringRef Filename) {
   const FrontendOptions &FEOpts = getCompilerInstance().getFrontendOpts();
   if (!FEOpts.FixItSuffix.empty()) {
-    PathRewriter.reset(new FixItActionSuffixInserter(FEOpts.FixItSuffix));
+    FixItOpts.reset(new FixItActionSuffixInserter(FEOpts.FixItSuffix,
+                                                  FEOpts.FixWhatYouCan));
   } else {
-    PathRewriter.reset();
+    FixItOpts.reset();
   }
   Rewriter.reset(new FixItRewriter(CI.getDiagnostics(), CI.getSourceManager(),
-                                   CI.getLangOpts(), PathRewriter.get()));
+                                   CI.getLangOpts(), FixItOpts.get()));
   return true;
 }
 





More information about the cfe-commits mailing list