souffle  2.0.2-371-g6315b36
Conjunction.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 Conjunction.h
12  *
13  * Defines a class for evaluating conditions in the Relational Algebra
14  * Machine.
15  *
16  ***********************************************************************/
17 
18 #pragma once
19 
20 #include "ram/Condition.h"
21 #include "ram/Node.h"
22 #include "ram/utility/NodeMapper.h"
25 #include <cassert>
26 #include <memory>
27 #include <sstream>
28 #include <utility>
29 #include <vector>
30 
31 namespace souffle::ram {
32 
33 /**
34  * @class Conjunction
35  * @brief A conjunction of conditions
36  *
37  * Condition of the form "LHS and RHS", where LHS
38  * and RHS are conditions
39  *
40  * For example:
41  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
42  * C1 AND C2 AND C3
43  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  * Is a Conjunction, which may have LHS "C1"
45  * and RHS "C2 AND C3"
46  */
47 class Conjunction : public Condition {
48 public:
49  Conjunction(Own<Condition> l, Own<Condition> r) : lhs(std::move(l)), rhs(std::move(r)) {
50  assert(lhs != nullptr && "left-hand side of conjunction is a nullptr");
51  assert(rhs != nullptr && "right-hand side of conjunction is a nullptr");
52  }
53 
54  /** @brief Get left-hand side of conjunction */
55  const Condition& getLHS() const {
56  return *lhs;
57  }
58 
59  /** @brief Get right-hand side of conjunction */
60  const Condition& getRHS() const {
61  return *rhs;
62  }
63 
64  std::vector<const Node*> getChildNodes() const override {
65  return {lhs.get(), rhs.get()};
66  }
67 
68  Conjunction* clone() const override {
70  }
71 
72  void apply(const NodeMapper& map) override {
73  lhs = map(std::move(lhs));
74  rhs = map(std::move(rhs));
75  }
76 
77 protected:
78  void print(std::ostream& os) const override {
79  os << "(" << *lhs << " AND " << *rhs << ")";
80  }
81 
82  bool equal(const Node& node) const override {
83  const auto& other = static_cast<const Conjunction&>(node);
84  return equal_ptr(lhs, other.lhs) && equal_ptr(rhs, other.rhs);
85  }
86 
87  /** Left-hand side of conjunction */
89 
90  /** Right-hand side of conjunction */
92 };
93 
94 } // namespace souffle::ram
souffle::ram::Conjunction::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: Conjunction.h:71
souffle::ram::Conjunction::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: Conjunction.h:89
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram::Conjunction::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Conjunction.h:79
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::Conjunction::getLHS
const Condition & getLHS() const
Get left-hand side of conjunction.
Definition: Conjunction.h:62
souffle::ram::Conjunction::clone
Conjunction * clone() const override
Create a clone (i.e.
Definition: Conjunction.h:75
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Conjunction
A conjunction of conditions.
Definition: Conjunction.h:54
l
var l
Definition: htmlJsChartistMin.h:15
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
ContainerUtil.h
Condition.h
souffle::ram::Conjunction::Conjunction
Conjunction(Own< Condition > l, Own< Condition > r)
Definition: Conjunction.h:56
souffle::ram::Conjunction::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Conjunction.h:85
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
Node.h
std
Definition: Brie.h:3053
souffle::ram::Conjunction::lhs
Own< Condition > lhs
Left-hand side of conjunction.
Definition: Conjunction.h:95
souffle::ram::Conjunction::getRHS
const Condition & getRHS() const
Get right-hand side of conjunction.
Definition: Conjunction.h:67
souffle::ram::Conjunction::rhs
Own< Condition > rhs
Right-hand side of conjunction.
Definition: Conjunction.h:98