]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Tooling/Refactoring.h
Vendor import of clang RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1):
[FreeBSD/FreeBSD.git] / include / clang / Tooling / Refactoring.h
1 //===--- Refactoring.h - Framework for clang refactoring tools --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Interfaces supporting refactorings that span multiple translation units.
11 //  While single translation unit refactorings are supported via the Rewriter,
12 //  when refactoring multiple translation units changes must be stored in a
13 //  SourceManager independent form, duplicate changes need to be removed, and
14 //  all changes must be applied at once at the end of the refactoring so that
15 //  the code is always parseable.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CLANG_TOOLING_REFACTORING_H
20 #define LLVM_CLANG_TOOLING_REFACTORING_H
21
22 #include "clang/Tooling/Core/Replacement.h"
23 #include "clang/Tooling/Tooling.h"
24 #include <string>
25
26 namespace clang {
27
28 class Rewriter;
29
30 namespace tooling {
31
32 /// \brief A tool to run refactorings.
33 ///
34 /// This is a refactoring specific version of \see ClangTool. FrontendActions
35 /// passed to run() and runAndSave() should add replacements to
36 /// getReplacements().
37 class RefactoringTool : public ClangTool {
38 public:
39   /// \see ClangTool::ClangTool.
40   RefactoringTool(const CompilationDatabase &Compilations,
41                   ArrayRef<std::string> SourcePaths);
42
43   /// \brief Returns the set of replacements to which replacements should
44   /// be added during the run of the tool.
45   Replacements &getReplacements();
46
47   /// \brief Call run(), apply all generated replacements, and immediately save
48   /// the results to disk.
49   ///
50   /// \returns 0 upon success. Non-zero upon failure.
51   int runAndSave(FrontendActionFactory *ActionFactory);
52
53   /// \brief Apply all stored replacements to the given Rewriter.
54   ///
55   /// Replacement applications happen independently of the success of other
56   /// applications.
57   ///
58   /// \returns true if all replacements apply. false otherwise.
59   bool applyAllReplacements(Rewriter &Rewrite);
60
61 private:
62   /// \brief Write all refactored files to disk.
63   int saveRewrittenFiles(Rewriter &Rewrite);
64
65 private:
66   Replacements Replace;
67 };
68
69 } // end namespace tooling
70 } // end namespace clang
71
72 #endif // LLVM_CLANG_TOOLING_REFACTORING_H