diff options
Diffstat (limited to 'include/clang/Rewrite')
-rw-r--r-- | include/clang/Rewrite/ASTConsumers.h | 5 | ||||
-rw-r--r-- | include/clang/Rewrite/FixItRewriter.h | 28 | ||||
-rw-r--r-- | include/clang/Rewrite/FrontendActions.h | 15 | ||||
-rw-r--r-- | include/clang/Rewrite/TokenRewriter.h | 2 |
4 files changed, 45 insertions, 5 deletions
diff --git a/include/clang/Rewrite/ASTConsumers.h b/include/clang/Rewrite/ASTConsumers.h index 7a636e5..c9c92e3 100644 --- a/include/clang/Rewrite/ASTConsumers.h +++ b/include/clang/Rewrite/ASTConsumers.h @@ -31,6 +31,11 @@ ASTConsumer *CreateObjCRewriter(const std::string &InFile, DiagnosticsEngine &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning); +ASTConsumer *CreateModernObjCRewriter(const std::string &InFile, + raw_ostream *OS, + DiagnosticsEngine &Diags, + const LangOptions &LOpts, + bool SilenceRewriteMacroWarning); /// CreateHTMLPrinter - Create an AST consumer which rewrites source code to /// HTML with syntax highlighting suitable for viewing in a web-browser. diff --git a/include/clang/Rewrite/FixItRewriter.h b/include/clang/Rewrite/FixItRewriter.h index bf7e791..44f0611 100644 --- a/include/clang/Rewrite/FixItRewriter.h +++ b/include/clang/Rewrite/FixItRewriter.h @@ -18,6 +18,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "clang/Rewrite/Rewriter.h" +#include "clang/Edit/EditedSource.h" namespace clang { @@ -26,20 +27,38 @@ class FileEntry; class FixItOptions { public: + FixItOptions() : FixWhatYouCan(false), + FixOnlyWarnings(false), Silent(false) { } + virtual ~FixItOptions(); /// \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; + /// + /// \param fd out parameter for file descriptor. After the call it may be set + /// to an open file descriptor for the returned filename, or it will be -1 + /// otherwise. + /// + virtual std::string RewriteFilename(const std::string &Filename, int &fd) = 0; /// \brief Whether to abort fixing a file when not all errors could be fixed. bool FixWhatYouCan; + + /// \brief Whether to only fix warnings and not errors. + bool FixOnlyWarnings; + + /// \brief If true, only pass the diagnostic to the actual diagnostic consumer + /// if it is an error or a fixit was applied as part of the diagnostic. + /// It basically silences warnings without accompanying fixits. + bool Silent; }; class FixItRewriter : public DiagnosticConsumer { /// \brief The diagnostics machinery. DiagnosticsEngine &Diags; + edit::EditedSource Editor; + /// \brief The rewriter used to perform the various code /// modifications. Rewriter Rewrite; @@ -47,6 +66,7 @@ class FixItRewriter : public DiagnosticConsumer { /// \brief The diagnostic client that performs the actual formatting /// of error messages. DiagnosticConsumer *Client; + bool OwnsClient; /// \brief Turn an input path into an output path. NULL implies overwriting /// the original. @@ -55,6 +75,9 @@ class FixItRewriter : public DiagnosticConsumer { /// \brief The number of rewriter failures. unsigned NumFailures; + /// \brief Whether the previous diagnostic was not passed to the consumer. + bool PrevDiagSilenced; + public: typedef Rewriter::buffer_iterator iterator; @@ -82,7 +105,8 @@ public: /// \brief Write the modified source files. /// /// \returns true if there was an error, false otherwise. - bool WriteFixedFiles(); + bool WriteFixedFiles( + std::vector<std::pair<std::string, std::string> > *RewrittenFiles = 0); /// IncludeInDiagnosticCounts - This method (whose default implementation /// returns true) indicates whether the diagnostics handled by this diff --git a/include/clang/Rewrite/FrontendActions.h b/include/clang/Rewrite/FrontendActions.h index f7aeefa..6e9ecac 100644 --- a/include/clang/Rewrite/FrontendActions.h +++ b/include/clang/Rewrite/FrontendActions.h @@ -28,8 +28,8 @@ protected: class FixItAction : public ASTFrontendAction { protected: - llvm::OwningPtr<FixItRewriter> Rewriter; - llvm::OwningPtr<FixItOptions> FixItOpts; + OwningPtr<FixItRewriter> Rewriter; + OwningPtr<FixItOptions> FixItOpts; virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef InFile); @@ -46,6 +46,17 @@ public: ~FixItAction(); }; +/// \brief Emits changes to temporary files and uses them for the original +/// frontend action. +class FixItRecompile : public WrapperFrontendAction { +public: + FixItRecompile(FrontendAction *WrappedAction) + : WrapperFrontendAction(WrappedAction) {} + +protected: + virtual bool BeginInvocation(CompilerInstance &CI); +}; + class RewriteObjCAction : public ASTFrontendAction { protected: virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, diff --git a/include/clang/Rewrite/TokenRewriter.h b/include/clang/Rewrite/TokenRewriter.h index 62ea12a..9ebd33a 100644 --- a/include/clang/Rewrite/TokenRewriter.h +++ b/include/clang/Rewrite/TokenRewriter.h @@ -41,7 +41,7 @@ namespace clang { /// ScratchBuf - This is the buffer that we create scratch tokens from. /// - llvm::OwningPtr<ScratchBuffer> ScratchBuf; + OwningPtr<ScratchBuffer> ScratchBuf; TokenRewriter(const TokenRewriter&); // DO NOT IMPLEMENT void operator=(const TokenRewriter&); // DO NOT IMPLEMENT. |