[cfe-commits] r88757 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Frontend/FrontendOptions.h tools/clang-cc/Options.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 13 20:39:30 PST 2009


Author: ddunbar
Date: Fri Nov 13 22:39:29 2009
New Revision: 88757

URL: http://llvm.org/viewvc/llvm-project?rev=88757&view=rev
Log:
Turn -fixit it back into a mode, but make -fixit-at imply that mode this time
(instead of running it with arbitrary consumers).
 - Also, turn any -fixit-at lookup failure into an error.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/tools/clang-cc/Options.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=88757&r1=88756&r2=88757&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Nov 13 22:39:29 2009
@@ -26,6 +26,8 @@
     "'%0' cannot be used with '%1'">, DefaultFatal;
 def err_fe_no_fixit_and_codegen : Error<
     "FIX-ITs cannot be applied when generating code">;
+def err_fe_unable_to_find_fixit_file : Error<
+    "FIX-IT could not find file '%0'">;
 
 def err_verify_bogus_characters : Error<
     "bogus characters before '{{' in expected string">;

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=88757&r1=88756&r2=88757&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Fri Nov 13 22:39:29 2009
@@ -41,8 +41,6 @@
   unsigned EmptyInputOnly : 1;             ///< Force input files to be treated
                                            /// as if they were empty, for timing
                                            /// the frontend startup.
-  unsigned FixItAll : 1;                   ///< Apply FIX-IT advice to the input
-                                           /// source files.
   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
                                            /// instruct the PCH writer to create
                                            /// relocatable PCH files.
@@ -80,7 +78,6 @@
     DebugCodeCompletionPrinter = 0;
     DisableFree = 0;
     EmptyInputOnly = 0;
-    FixItAll = 0;
     RelocatablePCH = 0;
     ShowMacrosInCodeCompletion = 0;
     ShowStats = 0;

Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=88757&r1=88756&r2=88757&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Fri Nov 13 22:39:29 2009
@@ -372,9 +372,6 @@
                    llvm::cl::value_desc("class name"),
                   llvm::cl::desc("View C++ inheritance for a specified class"));
 
-static llvm::cl::opt<bool>
-FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source"));
-
 static llvm::cl::list<ParsedSourceLocation>
 FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
    llvm::cl::desc("Perform Fix-It modifications at the given source location"));
@@ -832,7 +829,6 @@
   Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
   Opts.DisableFree = DisableFree;
   Opts.EmptyInputOnly = EmptyInputOnly;
-  Opts.FixItAll = FixItAll;
   Opts.FixItLocations = FixItAtLocations;
   Opts.OutputFile = OutputFile;
   Opts.RelocatablePCH = RelocatablePCH;
@@ -856,7 +852,6 @@
       if (IK == FrontendOptions::IK_None)
         IK = FrontendOptions::getInputKindForExtension(Ext);
       Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
-                                           
     }
   }
 }

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=88757&r1=88756&r2=88757&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Nov 13 22:39:29 2009
@@ -90,6 +90,7 @@
   DumpRecordLayouts,            // Dump record layout information.
   ParsePrintCallbacks,          // Parse and print each callback.
   ParseSyntaxOnly,              // Parse and perform semantic analysis.
+  FixIt,                        // Parse and apply any fixits to the source.
   ParseNoop,                    // Parse with noop callbacks.
   RunPreprocessorOnly,          // Just lex, no output.
   PrintPreprocessedInput,       // -E mode.
@@ -119,6 +120,8 @@
                         "Run parser with noop callbacks (for timings)"),
              clEnumValN(ParseSyntaxOnly, "fsyntax-only",
                         "Run parser and perform semantic analysis"),
+             clEnumValN(FixIt, "fixit",
+                        "Apply fix-it advice to the input source"),
              clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
                         "Run parser and print each callback invoked"),
              clEnumValN(EmitHTML, "emit-html",
@@ -234,27 +237,27 @@
 llvm::Timer *ClangFrontendTimer = 0;
 
 /// AddFixItLocations - Add any individual user specified "fix-it" locations,
-/// and return true on success (if any were added).
-static bool AddFixItLocations(FixItRewriter *FixItRewrite,
-                              FileManager &FileMgr,
-                              const std::vector<ParsedSourceLocation> &Locs) {
-  bool AddedFixItLocation = false;
-
+/// and return true on success.
+static bool AddFixItLocations(CompilerInstance &CI,
+                              FixItRewriter &FixItRewrite) {
+  const std::vector<ParsedSourceLocation> &Locs =
+    CI.getFrontendOpts().FixItLocations;
   for (unsigned i = 0, e = Locs.size(); i != e; ++i) {
-    if (const FileEntry *File = FileMgr.getFile(Locs[i].FileName)) {
-      RequestedSourceLocation Requested;
-      Requested.File = File;
-      Requested.Line = Locs[i].Line;
-      Requested.Column = Locs[i].Column;
-      FixItRewrite->addFixItLocation(Requested);
-      AddedFixItLocation = true;
-    } else {
-      llvm::errs() << "FIX-IT could not find file \""
-                   << Locs[i].FileName << "\"\n";
+    const FileEntry *File = CI.getFileManager().getFile(Locs[i].FileName);
+    if (!File) {
+      CI.getDiagnostics().Report(diag::err_fe_unable_to_find_fixit_file)
+        << Locs[i].FileName;
+      return false;
     }
+
+    RequestedSourceLocation Requested;
+    Requested.File = File;
+    Requested.Line = Locs[i].Line;
+    Requested.Column = Locs[i].Column;
+    FixItRewrite.addFixItLocation(Requested);
   }
 
-  return AddedFixItLocation;
+  return true;
 }
 
 static ASTConsumer *CreateConsumerAction(CompilerInstance &CI,
@@ -305,12 +308,6 @@
       OS.reset(CI.createDefaultOutputFile(true, InFile, "bc"));
     }
 
-    // Fix-its can change semantics, disallow with any IRgen action.
-    if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
-      PP.getDiagnostics().Report(diag::err_fe_no_fixit_and_codegen);
-      return 0;
-    }
-
     return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(),
                                  CI.getCodeGenOpts(), InFile, OS.take(),
                                  CI.getLLVMContext());
@@ -326,6 +323,9 @@
     return CreateBlockRewriter(InFile, PP.getDiagnostics(),
                                PP.getLangOptions());
 
+  case FixIt:
+    return new ASTConsumer();
+
   case ParseSyntaxOnly:
     return new ASTConsumer();
 
@@ -340,7 +340,7 @@
   Preprocessor &PP = CI.getPreprocessor();
   const FrontendOptions &FEOpts = CI.getFrontendOpts();
   llvm::OwningPtr<ASTConsumer> Consumer;
-  FixItRewriter *FixItRewrite = 0;
+  llvm::OwningPtr<FixItRewriter> FixItRewrite;
   bool CompleteTranslationUnit = true;
 
   switch (PA) {
@@ -393,17 +393,12 @@
   }
 
   // Check if we want a fix-it rewriter.
-  if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
-    FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
-                                     PP.getSourceManager(),
-                                     PP.getLangOptions());
-    if (!FEOpts.FixItLocations.empty() &&
-        !AddFixItLocations(FixItRewrite, PP.getFileManager(),
-                           FEOpts.FixItLocations)) {
-      // All of the fix-it locations were bad. Don't fix anything.
-      delete FixItRewrite;
-      FixItRewrite = 0;
-    }
+  if (PA == FixIt) {
+    FixItRewrite.reset(new FixItRewriter(PP.getDiagnostics(),
+                                         PP.getSourceManager(),
+                                         PP.getLangOptions()));
+    if (!AddFixItLocations(CI, *FixItRewrite))
+      return;
   }
 
   if (Consumer) {
@@ -731,9 +726,11 @@
   if (Clang.getFrontendOpts().ShowTimers)
     ClangFrontendTimer = new llvm::Timer("Clang front-end time");
 
-  // C++ visualization?
+  // Enforce certain implications.
   if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
     ProgAction = InheritanceView;
+  if (!Clang.getFrontendOpts().FixItLocations.empty())
+    ProgAction = FixIt;
 
   // Create the source manager.
   Clang.createSourceManager();





More information about the cfe-commits mailing list