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