23 #include "llvm/Support/Path.h"
24 #include "llvm/Support/raw_ostream.h"
28 using namespace clang;
34 Editor(SourceMgr, LangOpts),
35 Rewrite(SourceMgr, LangOpts),
38 PrevDiagSilenced(
false) {
45 Diags.
setClient(Client, Owner.release() !=
nullptr);
50 if (!RewriteBuf)
return true;
51 RewriteBuf->
write(OS);
62 RewritesReceiver(
Rewriter &Rewrite) : Rewrite(Rewrite) { }
68 Rewrite.ReplaceText(range.
getBegin(), Rewrite.getRangeSize(range),
text);
75 std::vector<std::pair<std::string, std::string> > *RewrittenFiles) {
81 RewritesReceiver Rec(Rewrite);
96 std::unique_ptr<llvm::raw_fd_ostream> OS;
98 OS.reset(
new llvm::raw_fd_ostream(fd,
true));
100 OS.reset(
new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None));
103 Diags.
Report(clang::diag::err_fe_unable_to_open_output) << Filename
108 RewriteBuf.
write(*OS);
132 PrevDiagSilenced =
false;
134 PrevDiagSilenced =
true;
177 if (++NumFailures == 1)
183 if (!Editor.
commit(commit)) {
199 Diags.
Report(Loc, DiagID);
bool remove(CharSourceRange range)
DiagnosticConsumer * getClient()
SourceLocation getBegin() const
SourceManager & getSourceMgr() const
Defines the clang::FileManager interface and associated types.
Defines the SourceManager interface.
const RewriteBuffer * getRewriteBufferFor(FileID FID) const
getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
std::string CodeToInsert
The actual code to insert at the insertion location, as a string.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool insertFromRange(SourceLocation loc, CharSourceRange range, bool afterToken=false, bool beforePreviousInsertions=false)
std::unique_ptr< DiagnosticConsumer > takeClient()
Return the current diagnostic client along with ownership of that client.
bool WriteFixedFiles(std::vector< std::pair< std::string, std::string > > *RewrittenFiles=nullptr)
Write the modified source files.
bool FixOnlyWarnings
Whether to only fix warnings and not errors.
void applyRewrites(EditsReceiver &receiver)
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
bool insert(SourceLocation loc, StringRef text, bool afterToken=false, bool beforePreviousInsertions=false)
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
bool isCommitable() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool Silent
If true, only pass the diagnostic to the actual diagnostic consumer if it is an error or a fixit was ...
bool replace(CharSourceRange range, StringRef text)
const SourceLocation & getLocation() const
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Concrete class used by the front-end to report problems and issues.
~FixItRewriter() override
Destroy the fix-it rewriter.
detail::InMemoryDirectory::const_iterator I
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Represents a character-granular source range.
SourceLocation getEnd() const
void Clear()
Clear out the current diagnostic.
bool BeforePreviousInsertions
bool overwriteChangedFiles()
overwriteChangedFiles - Save all changed files to disk.
CharSourceRange InsertFromRange
Code in the specific range that should be inserted in the insertion location.
bool WriteFixedFile(FileID ID, raw_ostream &OS)
Write a single modified source file.
CharSourceRange RemoveRange
Code that should be replaced to correct the error.
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr, const LangOptions &LangOpts, FixItOptions *FixItOpts)
Initialize a new fix-it rewriter.
const char * getName() const
Encodes a location in the source.
bool FixWhatYouCan
Whether to abort fixing a file when not all errors could be fixed.
Cached information about one file (either on disk or in the virtual file system). ...
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
HandleDiagnostic - Handle this diagnostic, reporting it to the user or capturing it to a log as neede...
bool InsertText(SourceLocation Loc, StringRef Str, bool InsertAfter=true, bool indentNewLines=false)
InsertText - Insert the specified string at the specified location in the original buffer...
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Rewriter::buffer_iterator iterator
detail::InMemoryDirectory::const_iterator E
const FixItHint & getFixItHint(unsigned Idx) const
void Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic via the adapted diagnostic client.
raw_ostream & write(raw_ostream &Stream) const
Write to Stream the result of applying all changes to the original buffer.
bool commit(const Commit &commit)
Rewriter - This is the main interface to the rewrite buffers.
Defines the clang::SourceLocation class and associated facilities.
Level
The level of the diagnostic, after it has been through mapping.
unsigned getNumFixItHints() const
virtual std::string RewriteFilename(const std::string &Filename, int &fd)=0
This file is about to be rewritten.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
A SourceLocation and its associated SourceManager.
bool InPlace
True if files should be updated in place.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
This class handles loading and caching of source files into memory.
bool IncludeInDiagnosticCounts() const override
IncludeInDiagnosticCounts - This method (whose default implementation returns true) indicates whether...