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);
112 RewrittenFiles->push_back(std::make_pair(Entry->
getName(), Filename));
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
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)
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.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
ID
Defines the set of possible language-specific address spaces.
Represents a character-granular source range.
SourceLocation getEnd() const
void Clear()
Clear out the current diagnostic.
bool BeforePreviousInsertions
bool overwriteChangedFiles()
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. Empty for an insertion hint.
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token. Return false if the end o...
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. The SourceManager can decode this to get at the full include stack...
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
bool InsertText(SourceLocation Loc, StringRef Str, bool InsertAfter=true, bool indentNewLines=false)
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
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. Note that it isn't safe to...
bool commit(const Commit &commit)
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. Return the name of the file that is okay to write to...
A SourceLocation and its associated SourceManager.
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