WaSH Docs
refactor.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "arguments.hpp"
14 #include "common.hpp"
15 
16 // #include "forces/forces.hpp"
17 // #include "halo_exchange/kernel_dependency_detector.hpp"
18 // #include "meta/meta.hpp"
19 // #include "variables/variables.hpp"
20 
21 namespace ws2st {
22 
23  namespace refactor {
24 
29  class WashMatchCallback : public tooling::RefactoringCallback {
30  private:
31  WashCallbackFn callback_ptr; // Pointer to function called when there's a match
32  public:
33  WashMatchCallback(WashCallbackFn callback_ptr) : callback_ptr(callback_ptr), RefactoringCallback() {}
34 
35  virtual void run(const MatchFinder::MatchResult& Result) { callback_ptr(Result, this->getReplacements()); }
36 
37  WashCallbackFn getCallback() { return callback_ptr; }
38 
39  friend std::ostream& operator<<(std::ostream& os, const WashMatchCallback& obj) {
40  os << "WashMatchCallback[ WashCallbackFn(" << obj.callback_ptr << ")->"
41  << reinterpret_cast<const void*>(obj.callback_ptr) << "]";
42  return os;
43  }
44  };
45 
50  private:
51  // Matchers can be one of many types -- currently just Statement/Declaration -- TODO: Add more as needed
52  std::variant<StatementMatcher*, DeclarationMatcher*> matcher;
53  WashCallbackFn callbackfn_ptr; // Function pointer to use
54  public:
55  WashRefactoringAction(StatementMatcher* matcher_ptr, WashCallbackFn callback_ptr)
56  : matcher(matcher_ptr), callbackfn_ptr(callback_ptr) {}
57 
58  WashRefactoringAction(DeclarationMatcher* matcher_ptr, WashCallbackFn callback_ptr)
59  : matcher(matcher_ptr), callbackfn_ptr(callback_ptr) {}
60 
61  WashCallbackFn getCallbackFn() { return callbackfn_ptr; }
62 
63  std::variant<StatementMatcher*, DeclarationMatcher*> getMatcher() { return matcher; }
64  };
65 
71  WashComputeFn computefn_ptr;
72 
73  public:
74  WashComputationAction(WashComputeFn computefn_ptr) : computefn_ptr(computefn_ptr) {}
75 
76  WashComputeFn getComputeFn() { return computefn_ptr; }
77  };
78 
82  class RefactorPass {
83  private:
84  const std::vector<std::string>* applicable_subset;
85  std::vector<WashRefactoringAction> ref_act;
86  std::vector<WashComputationAction> com_act;
87 
88  public:
89  RefactorPass(std::initializer_list<
90  std::variant<std::vector<std::string>*, WashRefactoringAction, WashComputationAction>>
91  actions)
92  : applicable_subset(std::holds_alternative<std::vector<std::string>*>(*actions.begin())
93  ? std::get<std::vector<std::string>*>(*actions.begin())
94  : &AllFiles) {
95  for (auto i = actions.begin() + 1; i != actions.end(); i++) {
96  if (std::holds_alternative<WashRefactoringAction>(*i)) {
97  ref_act.push_back(std::get<WashRefactoringAction>(*i));
98  } else if (std::holds_alternative<WashComputationAction>(*i)) {
99  com_act.push_back(std::get<WashComputationAction>(*i));
100  }
101  }
102  }
103 
104  const std::vector<WashRefactoringAction>& actions() const { return ref_act; }
105 
106  const std::vector<WashComputationAction>& computations() const { return com_act; }
107 
108  const std::vector<std::string>* files() const { return applicable_subset; }
109  };
110 
116  private:
117  std::vector<RefactorPass> refactoring_stages;
118 
119  public:
120  RefactoringToolConfiguration(std::initializer_list<RefactorPass> passes)
121  : refactoring_stages(passes.begin(), passes.end()) {}
122 
123  bool run(const WashOptions& opts) const;
124  };
125 
130  void runRefactoring(const WashOptions& opts);
131 
132  namespace config {
133 
139  const RefactoringToolConfiguration& getConfigurationForImplementation(Implementations impl);
140 
141  }
142  }
143 
144 }
We configure the whole tool by a series of refactoring passes.
Definition: refactor.hpp:115
Developer defined registration of a refactoring action - a (<T>Matcher, CallbackFn) pair...
Definition: refactor.hpp:49
void runRefactoring(const WashOptions &opts)
Runs the wash refactoring application.
Definition: refactor.cpp:151
Define a function to be run at the end of the refactor pass. Computation Actions will be run in the o...
Definition: refactor.hpp:70
Options about how the Wash analysis will behave.
Definition: common.hpp:45
Contains methods to do with command line arugments and running on the command line.
A specialised refactoring callback type for Wash using custom function pointers instead of subclassin...
Definition: refactor.hpp:29
A pass of a refactoring tool over the source files running a series of actions defined.
Definition: refactor.hpp:82
Definition: arguments.cpp:3