souffle  2.0.2-371-g6315b36
Conditional.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 Conditional.h
12  *
13  * Defines the interface for RAM transformation passes.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ram/Program.h"
20 #include "ram/TranslationUnit.h"
21 #include "ram/transform/Meta.h"
23 #include <functional>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 
28 namespace souffle::ram::transform {
29 
30 /**
31  * @Class ConditionalTransformer
32  * @Brief Composite conditional transformer
33  *
34  * A transformation is invoked if a condition holds.
35  */
36 class ConditionalTransformer : public MetaTransformer {
37 public:
38  ConditionalTransformer(std::function<bool()> fn, Own<Transformer> tb)
39  : func(std::move(fn)), body(std::move(tb)) {}
40  std::string getName() const override {
41  return "ConditionalTransformer";
42  }
43  bool transform(TranslationUnit& tU) override {
44  if (func()) {
45  return body->apply(tU);
46  } else {
47  return false;
48  }
49  }
50 
51 protected:
52  std::function<bool()> func;
54 };
55 
56 } // namespace souffle::ram::transform
souffle::ram::transform
Definition: ChoiceConversion.cpp:30
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram::transform::ConditionalTransformer::ConditionalTransformer
ConditionalTransformer(std::function< bool()> fn, Own< Transformer > tb)
Definition: Conditional.h:50
Program.h
Meta.h
souffle::ram::TranslationUnit
Translating a RAM program.
Definition: TranslationUnit.h:55
souffle::ram::transform::ConditionalTransformer::getName
std::string getName() const override
@Brief get name of the transformer
Definition: Conditional.h:52
TranslationUnit.h
Transformer.h
std
Definition: Brie.h:3053
souffle::ram::transform::ConditionalTransformer::transform
bool transform(TranslationUnit &tU) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: Conditional.h:55
souffle::ram::transform::ConditionalTransformer::body
Own< Transformer > body
Definition: Conditional.h:65
souffle::ram::transform::ConditionalTransformer::func
std::function< bool()> func
Definition: Conditional.h:64