summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/Core
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core')
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/Transform.cpp4
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/Transform.h32
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/Transforms.cpp8
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/Transforms.h9
4 files changed, 33 insertions, 20 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
index cfb316bb0b0..97597d63047 100644
--- a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
+++ b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
@@ -37,7 +37,7 @@ void collectResults(clang::Rewriter &Rewrite,
}
bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
- if (!EnableTiming)
+ if (!Options().EnableTiming)
return true;
Timings.push_back(std::make_pair(Filename.str(), llvm::TimeRecord()));
@@ -46,7 +46,7 @@ bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
}
void Transform::handleEndSource() {
- if (!EnableTiming)
+ if (!Options().EnableTiming)
return;
Timings.back().second += llvm::TimeRecord::getCurrentTime(false);
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.h b/clang-tools-extra/cpp11-migrate/Core/Transform.h
index 1297ec1becd..264b59526a7 100644
--- a/clang-tools-extra/cpp11-migrate/Core/Transform.h
+++ b/clang-tools-extra/cpp11-migrate/Core/Transform.h
@@ -17,6 +17,7 @@
#include <string>
#include <vector>
+#include "IncludeExcludeInfo.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/Timer.h"
@@ -105,24 +106,32 @@ private:
clang::Rewriter Rewrite;
};
+/// \brief Container for global options affecting all transforms.
+struct TransformOptions {
+ /// \brief Enable the use of performance timers.
+ bool EnableTiming;
+
+ /// \brief Maximum allowed level of risk.
+ RiskLevel MaxRiskLevel;
+};
+
/// \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.
+/// 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 {
public:
/// \brief Constructor
/// \param Name Name of the transform for human-readable purposes (e.g. -help
/// text)
- /// \param EnableTiming Enable the timing of the duration between calls to
- /// handleBeginSource() and handleEndSource(). 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.
- Transform(llvm::StringRef Name, bool EnableTiming)
- : Name(Name), EnableTiming(EnableTiming) {
+ /// \param Options Collection of options that affect all transforms.
+ Transform(llvm::StringRef Name, const TransformOptions &Options)
+ : Name(Name), GlobalOptions(Options) {
Reset();
}
@@ -136,7 +145,6 @@ public:
/// Upon return, \p ResultStates shall contain the result of performing this
/// transform on the files listed in \p SourcePaths.
virtual int apply(const FileContentsByPath &InputStates,
- RiskLevel MaxRiskLevel,
const clang::tooling::CompilationDatabase &Database,
const std::vector<std::string> &SourcePaths,
FileContentsByPath &ResultStates) = 0;
@@ -214,9 +222,11 @@ protected:
/// data for all sources processed by this transform.
void addTiming(llvm::StringRef Label, llvm::TimeRecord Duration);
+ const TransformOptions &Options() { return GlobalOptions; }
+
private:
const std::string Name;
- bool EnableTiming;
+ const TransformOptions &GlobalOptions;
TimingVec Timings;
unsigned AcceptedChanges;
unsigned RejectedChanges;
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp b/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp
index 85c0e2103a7..4347e4e46df 100644
--- a/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp
+++ b/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp
@@ -32,14 +32,16 @@ void Transforms::registerTransform(llvm::StringRef OptName,
llvm::StringRef Description,
TransformCreator Creator) {
Options.push_back(OptionVec::value_type(
- new cl::opt<bool>(OptName.data(), cl::desc(Description.data())), Creator));
+ new cl::opt<bool>(OptName.data(), cl::desc(Description.data())),
+ Creator));
}
-void Transforms::createSelectedTransforms(bool EnableTiming) {
+void
+Transforms::createSelectedTransforms(const TransformOptions &GlobalOptions) {
for (OptionVec::iterator I = Options.begin(),
E = Options.end(); I != E; ++I) {
if (*I->first) {
- ChosenTransforms.push_back(I->second(EnableTiming));
+ ChosenTransforms.push_back(I->second(GlobalOptions));
}
}
}
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transforms.h b/clang-tools-extra/cpp11-migrate/Core/Transforms.h
index b19b0316d90..c07df992574 100644
--- a/clang-tools-extra/cpp11-migrate/Core/Transforms.h
+++ b/clang-tools-extra/cpp11-migrate/Core/Transforms.h
@@ -27,11 +27,12 @@ class Option;
} // namespace cl
} // namespace llvm
class Transform;
+struct TransformOptions;
-typedef Transform *(*TransformCreator)(bool);
+typedef Transform *(*TransformCreator)(const TransformOptions &);
template <typename T>
-Transform *ConstructTransform(bool EnableTiming) {
- return new T(EnableTiming);
+Transform *ConstructTransform(const TransformOptions &Options) {
+ return new T(Options);
}
/// \brief Class encapsulating the creation of command line bool options
@@ -55,7 +56,7 @@ public:
/// \brief Instantiate all transforms that were selected on the command line.
///
/// Call *after* parsing options.
- void createSelectedTransforms(bool EnableTiming);
+ void createSelectedTransforms(const TransformOptions &Options);
/// \brief Return an iterator to the start of a container of instantiated
/// transforms.
OpenPOWER on IntegriCloud