souffle  2.0.2-371-g6315b36
AbstractConditional.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. 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 AbstractConditional.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Condition.h"
18 #include "ram/NestedOperation.h"
19 #include "ram/Node.h"
20 #include "ram/Operation.h"
21 #include "ram/utility/NodeMapper.h"
23 #include <cassert>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace souffle::ram {
30 
31 /**
32  * @class AbstractConditional
33  * @brief Abstract conditional statement
34  */
35 class AbstractConditional : public NestedOperation {
36 public:
37  AbstractConditional(Own<Condition> cond, Own<Operation> nested, std::string profileText = "")
38  : NestedOperation(std::move(nested), std::move(profileText)), condition(std::move(cond)) {
39  assert(condition != nullptr && "Condition is a null-pointer");
40  }
41 
42  AbstractConditional* clone() const override = 0;
43 
44  /** @brief Get condition that must be satisfied */
45  const Condition& getCondition() const {
46  assert(condition != nullptr && "condition of conditional operation is a null-pointer");
47  return *condition;
48  }
49 
50  std::vector<const Node*> getChildNodes() const override {
51  auto res = NestedOperation::getChildNodes();
52  res.push_back(condition.get());
53  return res;
54  }
55 
56  void apply(const NodeMapper& map) override {
58  condition = map(std::move(condition));
59  }
60 
61 protected:
62  bool equal(const Node& node) const override {
63  const auto& other = static_cast<const AbstractConditional&>(node);
64  return NestedOperation::equal(node) && equal_ptr(condition, other.condition);
65  }
66 
67  /** Condition */
69 };
70 
71 } // namespace souffle::ram
souffle::ram::NestedOperation::profileText
const std::string profileText
Text used by the profiler.
Definition: NestedOperation.h:93
NestedOperation.h
souffle::ram::NestedOperation::NestedOperation
NestedOperation(Own< Operation > nested, std::string profileText="")
Definition: NestedOperation.h:54
souffle::ram::AbstractConditional::AbstractConditional
AbstractConditional(Own< Condition > cond, Own< Operation > nested, std::string profileText="")
Definition: AbstractConditional.h:41
souffle::ram::NestedOperation::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: NestedOperation.h:75
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
MiscUtil.h
souffle::ram::Condition
Abstract class for conditions and boolean values in RAM.
Definition: Condition.h:35
souffle::ram::AbstractConditional::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: AbstractConditional.h:54
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
souffle::ram::AbstractConditional::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: AbstractConditional.h:60
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
souffle::ram::NestedOperation::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: NestedOperation.h:84
Condition.h
souffle::equal_ptr
bool equal_ptr(const T *a, const T *b)
Compares two values referenced by a pointer where the case where both pointers are null is also consi...
Definition: MiscUtil.h:130
souffle::ram::AbstractConditional::clone
AbstractConditional * clone() const override=0
Create a clone (i.e.
souffle::ram::AbstractConditional::getCondition
const Condition & getCondition() const
Get condition that must be satisfied.
Definition: AbstractConditional.h:49
Node.h
std
Definition: Brie.h:3053
Operation.h
souffle::ram::AbstractConditional::condition
Own< Condition > condition
Condition.
Definition: AbstractConditional.h:72
souffle::ram::AbstractConditional
Abstract conditional statement.
Definition: AbstractConditional.h:39
souffle::ram::AbstractConditional::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: AbstractConditional.h:66
souffle::ram::NestedOperation::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: NestedOperation.h:71