diff --git a/include/clang/Frontend/CommandLineSourceLoc.h b/include/clang/Frontend/CommandLineSourceLoc.h index 59f70ede91..d5a0598dfa 100644 --- a/include/clang/Frontend/CommandLineSourceLoc.h +++ b/include/clang/Frontend/CommandLineSourceLoc.h @@ -1,3 +1,4 @@ + //===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===// // // The LLVM Compiler Infrastructure @@ -37,7 +38,7 @@ namespace llvm { class parser : public basic_parser { public: - bool parse(Option &O, StringRef ArgName, StringRef ArgValue, + inline bool parse(Option &O, StringRef ArgName, StringRef ArgValue, clang::ParsedSourceLocation &Val); }; diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index da177bc037..27897a240f 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -10,6 +10,7 @@ #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H +#include "clang/Frontend/CommandLineSourceLoc.h" #include #include @@ -36,6 +37,9 @@ public: /// If given, the name for a C++ class to view the inheritance of. std::string ViewClassInheritance; + /// A list of locations to apply fix-its at. + std::vector FixItLocations; + public: FrontendOptions() { DisableFree = 0; diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 9469abf92c..7181b7c89a 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -313,6 +313,10 @@ InheritanceViewCls("cxx-inheritance-view", static llvm::cl::opt FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source")); +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")); + static llvm::cl::opt OutputFile("o", llvm::cl::value_desc("path"), @@ -757,6 +761,7 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) { Opts.DisableFree = DisableFree; Opts.EmptyInputOnly = EmptyInputOnly; Opts.FixItAll = FixItAll; + Opts.FixItLocations = FixItAtLocations; Opts.RelocatablePCH = RelocatablePCH; Opts.ShowStats = Stats; Opts.ShowTimers = TimeReport; diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 2d04ab1a85..1b9578c743 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -210,14 +210,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Rewrite Blocks to C"), clEnumValEnd)); -//===----------------------------------------------------------------------===// -// Frontend Options -//===----------------------------------------------------------------------===// - -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")); - //===----------------------------------------------------------------------===// // Language Options //===----------------------------------------------------------------------===// @@ -445,20 +437,21 @@ static llvm::raw_ostream *ComputeOutFile(const CompilerInvocation &CompOpts, /// 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) { + FileManager &FileMgr, + const std::vector &Locs) { bool AddedFixItLocation = false; - for (unsigned i = 0, e = FixItAtLocations.size(); i != e; ++i) { - if (const FileEntry *File = FileMgr.getFile(FixItAtLocations[i].FileName)) { + 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 = FixItAtLocations[i].Line; - Requested.Column = FixItAtLocations[i].Column; + Requested.Line = Locs[i].Line; + Requested.Column = Locs[i].Column; FixItRewrite->addFixItLocation(Requested); AddedFixItLocation = true; } else { llvm::errs() << "FIX-IT could not find file \"" - << FixItAtLocations[i].FileName << "\"\n"; + << Locs[i].FileName << "\"\n"; } } @@ -517,7 +510,7 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, } // Fix-its can change semantics, disallow with any IRgen action. - if (FEOpts.FixItAll || !FixItAtLocations.empty()) { + if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) { PP.getDiagnostics().Report(diag::err_fe_no_fixit_and_codegen); return 0; } @@ -655,12 +648,13 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, } // Check if we want a fix-it rewriter. - if (FEOpts.FixItAll || !FixItAtLocations.empty()) { + if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) { FixItRewrite = new FixItRewriter(PP.getDiagnostics(), PP.getSourceManager(), PP.getLangOptions()); - if (!FixItAtLocations.empty() && - !AddFixItLocations(FixItRewrite, PP.getFileManager())) { + 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;