summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-modernize/Core/Transforms.h
blob: 18369407ddaf099dee7639746ef894cf0a3d3c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===-- Core/Transforms.h - class Transforms Def'n --------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the definition for class Transforms which is
/// responsible for defining the command-line arguments exposing
/// transformations to the user and applying requested transforms.
///
//===----------------------------------------------------------------------===//

#ifndef CPP11_MIGRATE_TRANSFORMS_H
#define CPP11_MIGRATE_TRANSFORMS_H

#include "llvm/Support/CommandLine.h"
#include "llvm/ADT/StringRef.h"

#include <vector>

// Forward declarations
namespace llvm {
namespace cl {
class Option;
} // namespace cl
} // namespace llvm
class Transform;
struct TransformOptions;
struct CompilerVersions;

typedef Transform *(*TransformCreator)(const TransformOptions &);
template <typename T>
Transform *ConstructTransform(const TransformOptions &Options) {
  return new T(Options);
}

/// \brief Class encapsulating the creation of command line bool options
/// for each transform and instantiating transforms chosen by the user.
class Transforms {
public:
  typedef std::vector<Transform*> TransformVec;
  typedef TransformVec::const_iterator const_iterator;

public:

  ~Transforms();

  /// \brief Registers all available transforms causing them to be made
  /// available on the command line.
  ///
  /// Be sure to register all transforms *before* parsing command line options.
  void registerTransforms();

  /// \brief Instantiate all transforms that were selected on the command line.
  ///
  /// Call *after* parsing options.
  void createSelectedTransforms(const TransformOptions &Options,
                                const CompilerVersions &RequiredVersions);

  /// \brief Return an iterator to the start of a container of instantiated
  /// transforms.
  const_iterator begin() const { return ChosenTransforms.begin(); }

  /// \brief Return an iterator to the end of a container of instantiated
  /// transforms.
  const_iterator end() const { return ChosenTransforms.end(); }

private:
  bool hasAnyExplicitOption() const;

  typedef llvm::StringMap<llvm::cl::opt<bool> *> OptionMap;

private:
  TransformVec ChosenTransforms;
  OptionMap Options;
};

#endif // CPP11_MIGRATE_TRANSFORMS_H
OpenPOWER on IntegriCloud