summaryrefslogtreecommitdiffstats
path: root/include/clang/Frontend/FixItRewriter.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Frontend/FixItRewriter.h')
-rw-r--r--include/clang/Frontend/FixItRewriter.h59
1 files changed, 34 insertions, 25 deletions
diff --git a/include/clang/Frontend/FixItRewriter.h b/include/clang/Frontend/FixItRewriter.h
index fac87af..b432d74 100644
--- a/include/clang/Frontend/FixItRewriter.h
+++ b/include/clang/Frontend/FixItRewriter.h
@@ -16,23 +16,24 @@
#define LLVM_CLANG_FRONTEND_FIX_IT_REWRITER_H
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
#include "clang/Rewrite/Rewriter.h"
#include "llvm/ADT/SmallVector.h"
+namespace llvm { class raw_ostream; }
+
namespace clang {
class SourceManager;
class FileEntry;
-/// \brief Stores a source location in the form that it shows up on
-/// the Clang command line, e.g., file:line:column.
-///
-/// FIXME: Would prefer to use real SourceLocations, but I don't see a
-/// good way to resolve them during parsing.
-struct RequestedSourceLocation {
- const FileEntry *File;
- unsigned Line;
- unsigned Column;
+class FixItPathRewriter {
+public:
+ virtual ~FixItPathRewriter();
+
+ /// \brief This file is about to be rewritten. Return the name of the file
+ /// that is okay to write to.
+ virtual std::string RewriteFilename(const std::string &Filename) = 0;
};
class FixItRewriter : public DiagnosticClient {
@@ -47,38 +48,46 @@ class FixItRewriter : public DiagnosticClient {
/// of error messages.
DiagnosticClient *Client;
+ /// \brief Turn an input path into an output path. NULL implies overwriting
+ /// the original.
+ FixItPathRewriter *PathRewriter;
+
/// \brief The number of rewriter failures.
unsigned NumFailures;
- /// \brief Locations at which we should perform fix-its.
- ///
- /// When empty, perform fix-it modifications everywhere.
- llvm::SmallVector<RequestedSourceLocation, 4> FixItLocations;
-
public:
+ typedef Rewriter::buffer_iterator iterator;
+
/// \brief Initialize a new fix-it rewriter.
FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
- const LangOptions &LangOpts);
+ const LangOptions &LangOpts, FixItPathRewriter *PathRewriter);
/// \brief Destroy the fix-it rewriter.
~FixItRewriter();
- /// \brief Add a location where fix-it modifications should be
- /// performed.
- void addFixItLocation(RequestedSourceLocation Loc) {
- FixItLocations.push_back(Loc);
+ /// \brief Check whether there are modifications for a given file.
+ bool IsModified(FileID ID) const {
+ return Rewrite.getRewriteBufferFor(ID) != NULL;
}
- /// \brief Write the modified source file.
+ // Iteration over files with changes.
+ iterator buffer_begin() { return Rewrite.buffer_begin(); }
+ iterator buffer_end() { return Rewrite.buffer_end(); }
+
+ /// \brief Write a single modified source file.
+ ///
+ /// \returns true if there was an error, false otherwise.
+ bool WriteFixedFile(FileID ID, llvm::raw_ostream &OS);
+
+ /// \brief Write the modified source files.
///
/// \returns true if there was an error, false otherwise.
- bool WriteFixedFile(const std::string &InFileName,
- const std::string &OutFileName = std::string());
+ bool WriteFixedFiles();
/// IncludeInDiagnosticCounts - This method (whose default implementation
- /// returns true) indicates whether the diagnostics handled by this
- /// DiagnosticClient should be included in the number of diagnostics
- /// reported by Diagnostic.
+ /// returns true) indicates whether the diagnostics handled by this
+ /// DiagnosticClient should be included in the number of diagnostics
+ /// reported by Diagnostic.
virtual bool IncludeInDiagnosticCounts() const;
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
OpenPOWER on IntegriCloud