diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2010-04-15 06:46:58 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2010-04-15 06:46:58 +0000 |
commit | a1e20de9084036fa2977004a31abf5ff490d8c8d (patch) | |
tree | 531a63f1c83892c45d1476793901a248daa35e1e /clang/lib/Frontend/FrontendActions.cpp | |
parent | 72ac9505f0ea4c97e440f3c59b1847b24dcfb88a (diff) | |
download | bcm5719-llvm-a1e20de9084036fa2977004a31abf5ff490d8c8d.tar.gz bcm5719-llvm-a1e20de9084036fa2977004a31abf5ff490d8c8d.zip |
Teach -fixit to modify all of its inputs instead of just the main file, unless
-fixit-at specified a particular fixit to fix, or the -o flag was used.
llvm-svn: 101359
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 6d7c6a8460b..ce3e841b904 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -134,6 +134,23 @@ static bool AddFixItLocations(CompilerInstance &CI, FixItRewrite.addFixItLocation(Requested); } + const std::string &OutputFile = CI.getFrontendOpts().OutputFile; + if (Locs.empty() && !OutputFile.empty()) { + // FIXME: we will issue "FIX-IT applied suggested code changes" for every + // input, but only the main file will actually be rewritten. + const std::vector<std::pair<FrontendOptions::InputKind, std::string> > &Inputs = + CI.getFrontendOpts().Inputs; + for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { + const FileEntry *File = CI.getFileManager().getFile(Inputs[i].second); + assert(File && "Input file not found in FileManager"); + RequestedSourceLocation Requested; + Requested.File = File; + Requested.Line = 0; + Requested.Column = 0; + FixItRewrite.addFixItLocation(Requested); + } + } + return true; } @@ -149,7 +166,34 @@ bool FixItAction::BeginSourceFileAction(CompilerInstance &CI, void FixItAction::EndSourceFileAction() { const FrontendOptions &FEOpts = getCompilerInstance().getFrontendOpts(); - Rewriter->WriteFixedFile(getCurrentFile(), FEOpts.OutputFile); + if (!FEOpts.OutputFile.empty()) { + // When called with 'clang -fixit -o filename' output only the main file. + + const SourceManager &SM = getCompilerInstance().getSourceManager(); + FileID MainFileID = SM.getMainFileID(); + if (!Rewriter->IsModified(MainFileID)) { + getCompilerInstance().getDiagnostics().Report( + diag::note_fixit_main_file_unchanged); + return; + } + + llvm::OwningPtr<llvm::raw_ostream> OwnedStream; + llvm::raw_ostream *OutFile; + if (FEOpts.OutputFile == "-") { + OutFile = &llvm::outs(); + } else { + std::string Err; + OutFile = new llvm::raw_fd_ostream(FEOpts.OutputFile.c_str(), Err, + llvm::raw_fd_ostream::F_Binary); + OwnedStream.reset(OutFile); + } + + Rewriter->WriteFixedFile(MainFileID, *OutFile); + return; + } + + // Otherwise rewrite all files. + Rewriter->WriteFixedFiles(); } ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, |