diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
commit | 9092c3e0fa01f3139b016d05d267a89e3b07747a (patch) | |
tree | 137ebebcae16fb0ce7ab4af456992bbd8d22fced /lib/Frontend/FixItRewriter.cpp | |
parent | 4981926bf654fe5a2c3893f24ca44106b217e71e (diff) | |
download | FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.zip FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.tar.gz |
Update clang to r84119.
Diffstat (limited to 'lib/Frontend/FixItRewriter.cpp')
-rw-r--r-- | lib/Frontend/FixItRewriter.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/Frontend/FixItRewriter.cpp b/lib/Frontend/FixItRewriter.cpp index 1ed89d7..dddcaa9 100644 --- a/lib/Frontend/FixItRewriter.cpp +++ b/lib/Frontend/FixItRewriter.cpp @@ -16,10 +16,11 @@ #include "clang/Frontend/FixItRewriter.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" +#include "llvm/ADT/OwningPtr.h" +#include <cstdio> + using namespace clang; FixItRewriter::FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr, @@ -33,7 +34,7 @@ FixItRewriter::~FixItRewriter() { Diags.setClient(Client); } -bool FixItRewriter::WriteFixedFile(const std::string &InFileName, +bool FixItRewriter::WriteFixedFile(const std::string &InFileName, const std::string &OutFileName) { if (NumFailures > 0) { Diag(FullSourceLoc(), diag::warn_fixit_no_changes); @@ -44,10 +45,8 @@ bool FixItRewriter::WriteFixedFile(const std::string &InFileName, llvm::raw_ostream *OutFile; if (!OutFileName.empty()) { std::string Err; - OutFile = new llvm::raw_fd_ostream(OutFileName.c_str(), - // set binary mode (critical for Windoze) - true, - Err); + OutFile = new llvm::raw_fd_ostream(OutFileName.c_str(), Err, + llvm::raw_fd_ostream::F_Binary); OwnedStream.reset(OutFile); } else if (InFileName == "-") { OutFile = &llvm::outs(); @@ -57,15 +56,13 @@ bool FixItRewriter::WriteFixedFile(const std::string &InFileName, Path.eraseSuffix(); Path.appendSuffix("fixit." + Suffix); std::string Err; - OutFile = new llvm::raw_fd_ostream(Path.toString().c_str(), - // set binary mode (critical for Windoze) - true, - Err); + OutFile = new llvm::raw_fd_ostream(Path.c_str(), Err, + llvm::raw_fd_ostream::F_Binary); OwnedStream.reset(OutFile); - } + } FileID MainFileID = Rewrite.getSourceMgr().getMainFileID(); - if (const RewriteBuffer *RewriteBuf = + if (const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(MainFileID)) { *OutFile << std::string(RewriteBuf->begin(), RewriteBuf->end()); } else { @@ -102,7 +99,7 @@ void FixItRewriter::HandleDiagnostic(Diagnostic::Level DiagLevel, // See if the location of the error is one that matches what the // user requested. bool AcceptableLocation = false; - const FileEntry *File + const FileEntry *File = Rewrite.getSourceMgr().getFileEntryForID( Info.getLocation().getFileID()); unsigned Line = Info.getLocation().getSpellingLineNumber(); @@ -132,14 +129,14 @@ void FixItRewriter::HandleDiagnostic(Diagnostic::Level DiagLevel, break; } - if (Hint.InsertionLoc.isValid() && + if (Hint.InsertionLoc.isValid() && !Rewrite.isRewritable(Hint.InsertionLoc)) { CanRewrite = false; break; } } - if (!CanRewrite) { + if (!CanRewrite) { if (Info.getNumCodeModificationHints() > 0) Diag(Info.getLocation(), diag::note_fixit_in_macro); @@ -152,29 +149,28 @@ void FixItRewriter::HandleDiagnostic(Diagnostic::Level DiagLevel, } bool Failed = false; - for (unsigned Idx = 0, Last = Info.getNumCodeModificationHints(); + for (unsigned Idx = 0, Last = Info.getNumCodeModificationHints(); Idx < Last; ++Idx) { const CodeModificationHint &Hint = Info.getCodeModificationHint(Idx); if (!Hint.RemoveRange.isValid()) { // We're adding code. - if (Rewrite.InsertStrBefore(Hint.InsertionLoc, Hint.CodeToInsert)) + if (Rewrite.InsertTextBefore(Hint.InsertionLoc, Hint.CodeToInsert)) Failed = true; continue; } - + if (Hint.CodeToInsert.empty()) { // We're removing code. if (Rewrite.RemoveText(Hint.RemoveRange.getBegin(), Rewrite.getRangeSize(Hint.RemoveRange))) Failed = true; continue; - } - + } + // We're replacing code. if (Rewrite.ReplaceText(Hint.RemoveRange.getBegin(), Rewrite.getRangeSize(Hint.RemoveRange), - Hint.CodeToInsert.c_str(), - Hint.CodeToInsert.size())) + Hint.CodeToInsert)) Failed = true; } @@ -195,5 +191,5 @@ void FixItRewriter::Diag(FullSourceLoc Loc, unsigned DiagID) { Diags.setClient(Client); Diags.Clear(); Diags.Report(Loc, DiagID); - Diags.setClient(this); + Diags.setClient(this); } |