Go to the documentation of this file.
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/Support/FileSystem.h"
28 #include "llvm/Support/raw_ostream.h"
32 #include <system_error>
35 using namespace clang;
40 : Diags(Diags), Editor(SourceMgr, LangOpts),
Rewrite(SourceMgr, LangOpts),
41 FixItOpts(FixItOpts) {
48 Diags.
setClient(Client, Owner.release() !=
nullptr);
53 if (!RewriteBuf)
return true;
54 RewriteBuf->
write(OS);
79 std::vector<std::pair<std::string, std::string>> *RewrittenFiles) {
91 Rewrite.overwriteChangedFiles();
101 std::unique_ptr<llvm::raw_fd_ostream> OS;
103 OS.reset(
new llvm::raw_fd_ostream(fd,
true));
105 OS.reset(
new llvm::raw_fd_ostream(
Filename, EC, llvm::sys::fs::OF_None));
108 Diags.
Report(clang::diag::err_fe_unable_to_open_output) <<
Filename
113 RewriteBuf.
write(*OS);
117 RewrittenFiles->push_back(
138 PrevDiagSilenced =
false;
140 PrevDiagSilenced =
true;
183 if (++NumFailures == 1)
189 if (!Editor.
commit(commit)) {
205 Diags.
Report(Loc, DiagID);
unsigned getNumFixItHints() const
Level
The level of the diagnostic, after it has been through mapping.
SourceLocation getBegin() const
A SourceLocation and its associated SourceManager.
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
~FixItRewriter() override
Destroy the fix-it rewriter.
bool InPlace
True if files should be updated in place.
bool insertFromRange(SourceLocation loc, CharSourceRange range, bool afterToken=false, bool beforePreviousInsertions=false)
Encodes a location in the source.
bool WriteFixedFile(FileID ID, raw_ostream &OS)
Write a single modified source file.
bool insert(SourceLocation loc, StringRef text, bool afterToken=false, bool beforePreviousInsertions=false)
bool FixWhatYouCan
Whether to abort fixing a file when not all errors could be fixed.
raw_ostream & write(raw_ostream &Stream) const
Write to Stream the result of applying all changes to the original buffer.
bool replace(CharSourceRange range, StringRef text)
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
bool IncludeInDiagnosticCounts() const override
IncludeInDiagnosticCounts - This method (whose default implementation returns true) indicates whether...
Concrete class used by the front-end to report problems and issues.
void applyRewrites(EditsReceiver &receiver, bool adjustRemovals=true)
bool FixOnlyWarnings
Whether to only fix warnings and not errors.
This class handles loading and caching of source files into memory.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
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.
std::unique_ptr< DiagnosticConsumer > takeClient()
Return the current diagnostic client along with ownership of that client.
void Clear()
Clear out the current diagnostic.
bool BeforePreviousInsertions
DiagnosticConsumer * getClient()
bool Silent
If true, only pass the diagnostic to the actual diagnostic consumer if it is an error or a fixit was ...
CharSourceRange InsertFromRange
Code in the specific range that should be inserted in the insertion location.
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Cached information about one file (either on disk or in the virtual file system).
std::string CodeToInsert
The actual code to insert at the insertion location, as a string.
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
const SourceLocation & getLocation() const
const FixItHint & getFixItHint(unsigned Idx) const
Represents a character-granular source range.
SourceLocation getEnd() const
bool commit(const Commit &commit)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
virtual std::string RewriteFilename(const std::string &Filename, int &fd)=0
This file is about to be rewritten.
const RewriteBuffer * getRewriteBufferFor(FileID FID) const
getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
Rewriter::buffer_iterator iterator
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
bool isCommitable() const
void Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic via the adapted diagnostic client.
StringRef getName() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Rewriter - This is the main interface to the rewrite buffers.
FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr, const LangOptions &LangOpts, FixItOptions *FixItOpts)
Initialize a new fix-it rewriter.
CharSourceRange RemoveRange
Code that should be replaced to correct the error.
bool WriteFixedFiles(std::vector< std::pair< std::string, std::string >> *RewrittenFiles=nullptr)
Write the modified source files.
bool remove(CharSourceRange range)
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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...