diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-06-17 18:18:15 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-06-17 18:18:15 +0000 |
commit | 4e11abb59b44dc9eab2f50e6e29f16d3d029bda6 (patch) | |
tree | c1d39bb0e772f9bb62a4987f8937a0779a59e4d9 /clang-tools-extra/cpp11-migrate/Core/Transform.h | |
parent | 862c4a06ee0cfb7662bdba9d8dbb853342975bbf (diff) | |
download | bcm5719-llvm-4e11abb59b44dc9eab2f50e6e29f16d3d029bda6.tar.gz bcm5719-llvm-4e11abb59b44dc9eab2f50e6e29f16d3d029bda6.zip |
cpp11-migrate: Transform now responsible for file content overriding
To better support per-translation unit replacements, any real work is being
moved out of ActionFactory and into Transform. In this revision, that means
file override application.
For simplification, Transform no longer inherits from SourceFileCallbacks.
TransformTest required updating as a result.
llvm-svn: 184098
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core/Transform.h')
-rw-r--r-- | clang-tools-extra/cpp11-migrate/Core/Transform.h | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.h b/clang-tools-extra/cpp11-migrate/Core/Transform.h index d990b4ec65c..d9135e78e2f 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transform.h +++ b/clang-tools-extra/cpp11-migrate/Core/Transform.h @@ -19,8 +19,6 @@ #include <vector> #include "Core/IncludeExcludeInfo.h" #include "Core/FileOverrides.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Tooling/Tooling.h" #include "llvm/Support/Timer.h" // For RewriterContainer @@ -48,8 +46,10 @@ enum RiskLevel { // Forward declarations namespace clang { +class CompilerInstance; namespace tooling { class CompilationDatabase; +class FrontendActionFactory; } // namespace tooling namespace ast_matchers { class MatchFinder; @@ -112,21 +112,21 @@ struct TransformOptions { /// \brief Abstract base class for all C++11 migration transforms. /// -/// Per-source performance timing is handled by the callbacks -/// handleBeginSource() and handleEndSource() if timing is enabled. See -/// clang::tooling::newFrontendActionFactory() for how to register a Transform -/// object for callbacks. When a Transform object is registered for -/// FrontendAction source file callbacks, this behaviour can be used to time -/// the application of a MatchFinder by subclasses. Durations are automatically -/// stored in a TimingVec. -class Transform : public clang::tooling::SourceFileCallbacks { +/// Subclasses must call createActionFactory() to create a +/// FrontendActionFactory to pass to ClangTool::run(). Subclasses are also +/// responsible for calling setOverrides() before calling ClangTool::run(). +/// +/// If timing is enabled (see TransformOptions), per-source performance timing +/// is recorded and stored in a TimingVec for later access with timing_begin() +/// and timing_end(). +class Transform { public: /// \brief Constructor /// \param Name Name of the transform for human-readable purposes (e.g. -help /// text) /// \param Options Collection of options that affect all transforms. Transform(llvm::StringRef Name, const TransformOptions &Options) - : Name(Name), GlobalOptions(Options) { + : Name(Name), GlobalOptions(Options), InputState(0) { Reset(); } @@ -175,17 +175,21 @@ public: DeferredChanges = 0; } - /// \brief Callback for notification of the start of processing of a source - /// file by a FrontendAction. Starts a performance timer if timing was - /// enabled. + /// \brief Called before parsing a translation unit for a FrontendAction. + /// + /// Transform uses this function to apply file overrides and start + /// performance timers. Subclasses overriding this function must call it + /// before returning. virtual bool handleBeginSource(clang::CompilerInstance &CI, - llvm::StringRef Filename) LLVM_OVERRIDE; + llvm::StringRef Filename); - /// \brief Callback for notification of the end of processing of a source - /// file by a FrontendAction. Stops a performance timer if timing was enabled - /// and records the elapsed time. For a given source, handleBeginSource() and - /// handleEndSource() are expected to be called in pairs. - virtual void handleEndSource() LLVM_OVERRIDE; + /// \brief Called after FrontendAction has been run over a translation unit. + /// + /// Transform uses this function to stop performance timers. Subclasses + /// overriding this function must call it before returning. A call to + /// handleEndSource() for a given translation unit is expected to be called + /// immediately after the corresponding handleBeginSource() call. + virtual void handleEndSource(); /// \brief Performance timing data is stored as a vector of pairs. Pairs are /// formed of: @@ -219,17 +223,26 @@ protected: const TransformOptions &Options() { return GlobalOptions; } - /// \brief Subclasses call this function to create a FrontendActionFactory to - /// pass to ClangTool. The factory returned by this function is responsible - /// for overriding source file contents with results of previous transforms. + /// \brief Allows a subclass to provide file contents overrides before + /// applying frontend actions. + /// + /// It is an error not to call this function before calling ClangTool::run() + /// with the factory provided by createActionFactory(). + void setOverrides(const FileOverrides &Overrides) { InputState = &Overrides; } + + /// \brief Subclasses must call this function to create a + /// FrontendActionFactory to pass to ClangTool. + /// + /// The factory returned by this function is responsible for calling back to + /// Transform to call handleBeginSource() and handleEndSource(). clang::tooling::FrontendActionFactory * - createActionFactory(clang::ast_matchers::MatchFinder &Finder, - const FileOverrides &InputStates); + createActionFactory(clang::ast_matchers::MatchFinder &Finder); private: const std::string Name; const TransformOptions &GlobalOptions; TimingVec Timings; + const FileOverrides *InputState; unsigned AcceptedChanges; unsigned RejectedChanges; unsigned DeferredChanges; |