souffle  2.0.2-371-g6315b36
Sequence.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file Sequence.h
12  *
13  * Defines the interface for RAM transformation passes.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ram/TranslationUnit.h"
20 #include "ram/transform/Meta.h"
21 #include <cassert>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 namespace souffle::ram::transform {
27 
28 /**
29  * @Class TransformerSequence
30  * @Brief Composite sequence transformer
31  *
32  * A sequence of transformations is applied to a translation unit
33  * sequentially. The last transformation decides the outcome whether
34  * the code has been changed.
35  *
36  */
37 class TransformerSequence : public MetaTransformer {
38 public:
39  template <typename... Tfs>
40  TransformerSequence(Own<Tfs>&&... tf) : TransformerSequence() {
41  Own<Transformer> tmp[] = {std::move(tf)...};
42  for (auto& cur : tmp) {
43  transformers.emplace_back(std::move(cur));
44  }
45  for (const auto& cur : transformers) {
46  (void)cur;
47  assert(cur);
48  }
49  }
50  TransformerSequence() = default;
51  std::string getName() const override {
52  return "TransformerSequence";
53  }
54  bool transform(TranslationUnit& tU) override {
55  bool changed = false;
56  // The last transformer decides the status
57  // of the change flag.
58  // Note that for other semantics, new transformer
59  // sequence class needs to be introduced.
60  for (auto const& cur : transformers) {
61  changed = cur->apply(tU);
62  }
63  return changed;
64  }
65 
66 protected:
67  /** sequence of transformers */
69 };
70 
71 } // namespace souffle::ram::transform
souffle::ram::transform
Definition: ChoiceConversion.cpp:30
souffle::ram::transform::TransformerSequence::TransformerSequence
TransformerSequence()=default
Meta.h
souffle::ram::TranslationUnit
Translating a RAM program.
Definition: TranslationUnit.h:55
souffle::ram::transform::TransformerSequence::getName
std::string getName() const override
@Brief get name of the transformer
Definition: Sequence.h:63
souffle::ram::transform::TransformerSequence::transformers
VecOwn< Transformer > transformers
sequence of transformers
Definition: Sequence.h:80
TranslationUnit.h
souffle::ram::transform::TransformerSequence::transform
bool transform(TranslationUnit &tU) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: Sequence.h:66
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45