//===----------------------------------------------------------------------===//
#include "Core/Transforms.h"
-#include "LoopConvert/LoopConvert.h"
-#include "UseNullptr/UseNullptr.h"
-#include "UseAuto/UseAuto.h"
+#include "Core/Transform.h"
namespace cl = llvm::cl;
-template <typename T>
-Transform *ConstructTransform() {
- return new T();
-}
-
Transforms::~Transforms() {
for (std::vector<Transform*>::iterator I = ChosenTransforms.begin(),
E = ChosenTransforms.end(); I != E; ++I) {
}
}
-void Transforms::createTransformOpts() {
- Options.push_back(
- OptionVec::value_type(
- new cl::opt<bool>("loop-convert",
- cl::desc("Make use of range-based for loops where possible")),
- &ConstructTransform<LoopConvertTransform>));
-
- Options.push_back(
- OptionVec::value_type(
- new cl::opt<bool>("use-nullptr",
- cl::desc("Make use of nullptr keyword where possible")),
- &ConstructTransform<UseNullptrTransform>));
-
- Options.push_back(
- OptionVec::value_type(
- new cl::opt<bool>("use-auto",
- cl::desc("Use of 'auto' type specifier")),
- &ConstructTransform<UseAutoTransform>));
-
- // Add more transform options here.
+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));
}
void Transforms::createSelectedTransforms() {
#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
#include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/StringRef.h"
#include <vector>
// Forward declarations
class Transform;
typedef Transform *(*TransformCreator)();
+template <typename T>
+Transform *ConstructTransform() {
+ return new T();
+}
/// \brief Class encapsulating the creation of command line bool options
/// for each transform and instantiating transforms chosen by the user.
~Transforms();
- /// \brief Create command line options using LLVM's command line library.
+ /// \brief Registers a transform causing the transform to be made available
+ /// on the command line.
///
- /// Be sure to call *before* parsing options.
- void createTransformOpts();
+ /// Be sure to register all transforms *before* parsing command line options.
+ void registerTransform(llvm::StringRef OptName, llvm::StringRef Description,
+ TransformCreator Creator);
/// \brief Instantiate all transforms that were selected on the command line.
///
#include "Core/Transforms.h"
#include "Core/Transform.h"
+#include "LoopConvert/LoopConvert.h"
+#include "UseNullptr/UseNullptr.h"
+#include "UseAuto/UseAuto.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
llvm::sys::PrintStackTraceOnErrorSignal();
Transforms TransformManager;
- TransformManager.createTransformOpts();
+ TransformManager.registerTransform(
+ "loop-convert", "Make use of range-based for loops where possible",
+ &ConstructTransform<LoopConvertTransform>);
+ TransformManager.registerTransform(
+ "use-nullptr", "Make use of nullptr keyword where possible",
+ &ConstructTransform<UseNullptrTransform>);
+ TransformManager.registerTransform(
+ "use-auto", "Use of 'auto' type specifier",
+ &ConstructTransform<UseAutoTransform>);
+ // Add more transform options here.
// This causes options to be parsed.
CommonOptionsParser OptionsParser(argc, argv);