diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2010-04-24 01:30:46 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2010-04-24 01:30:46 +0000 |
commit | ba5f6eced29937e4e4851a2c0980744768413d66 (patch) | |
tree | 7c65077ea2d105c3761012d52510063c5ce36530 /include/clang | |
parent | 970c618c3f9ce7e010a30587118afc03434cfd99 (diff) |
Teach clang -fixit to modify files in-place, or -fixit=suffix to create new
files with the additional suffix in the middle.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102230 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Driver/CC1Options.td | 4 | ||||
-rw-r--r-- | include/clang/Frontend/FixItRewriter.h | 34 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendActions.h | 2 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendOptions.h | 4 |
4 files changed, 18 insertions, 26 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index e45cfa9920..9fd21e97a0 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -245,8 +245,6 @@ def x : Separate<"-x">, HelpText<"Input language type">; def cxx_inheritance_view : Separate<"-cxx-inheritance-view">, MetaVarName<"<class name>">, HelpText<"View C++ inheritance for a specified class">; -def fixit_at : Separate<"-fixit-at">, MetaVarName<"<source location>">, - HelpText<"Perform Fix-It modifications at the given source location">; def o : Separate<"-o">, MetaVarName<"<path>">, HelpText<"Specify output file">; def load : Separate<"-load">, MetaVarName<"<dsopath>">, HelpText<"Load the named plugin (dynamic shared object)">; @@ -279,6 +277,8 @@ def fsyntax_only : Flag<"-fsyntax-only">, HelpText<"Run parser and perform semantic analysis">; def fixit : Flag<"-fixit">, HelpText<"Apply fix-it advice to the input source">; +def fixit_EQ : Joined<"-fixit=">, + HelpText<"Apply fix-it advice creating a file with the given suffix">; def parse_print_callbacks : Flag<"-parse-print-callbacks">, HelpText<"Run parser and print each callback invoked">; def emit_html : Flag<"-emit-html">, diff --git a/include/clang/Frontend/FixItRewriter.h b/include/clang/Frontend/FixItRewriter.h index 95fd3da3c6..b432d747de 100644 --- a/include/clang/Frontend/FixItRewriter.h +++ b/include/clang/Frontend/FixItRewriter.h @@ -27,16 +27,13 @@ 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. A line and column of zero -/// indicates the whole file. -/// -/// 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 { @@ -51,30 +48,23 @@ 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; diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index 8c9ebca887..3ddd77dc39 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -16,6 +16,7 @@ namespace clang { class FixItRewriter; +class FixItPathRewriter; //===----------------------------------------------------------------------===// // Custom Consumer Actions @@ -76,6 +77,7 @@ protected: class FixItAction : public ASTFrontendAction { private: llvm::OwningPtr<FixItRewriter> Rewriter; + llvm::OwningPtr<FixItPathRewriter> PathRewriter; protected: diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 9f3e00dbc9..60512edd6c 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -92,8 +92,8 @@ public: /// If given, the name for a C++ class to view the inheritance of. std::string ViewClassInheritance; - /// A list of locations to apply fix-its at. - std::vector<ParsedSourceLocation> FixItLocations; + /// If given, the new suffix for fix-it rewritten files. + std::string FixItSuffix; /// If given, enable code completion at the provided location. ParsedSourceLocation CodeCompletionAt; |