souffle  2.0.2-371-g6315b36
Negation.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 Negation.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 Negation
35  * @brief Negates a given condition
36  *
37  * For example:
38  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
39  * (NOT t0 IN A)
40  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
41  */
42 class Negation : public Condition {
43 public:
44  Negation(Own<Condition> op) : operand(std::move(op)) {
45  assert(operand != nullptr && "operand of negation is a null-pointer");
46  }
47 
48  /** @brief Get operand of negation */
49  const Condition& getOperand() const {
50  return *operand;
51  }
52 
53  std::vector<const Node*> getChildNodes() const override {
54  return {operand.get()};
55  }
56 
57  Negation* clone() const override {
58  return new Negation(souffle::clone(operand));
59  }
60 
61  void apply(const NodeMapper& map) override {
62  operand = map(std::move(operand));
63  }
64 
65 protected:
66  void print(std::ostream& os) const override {
67  os << "(NOT " << *operand << ")";
68  }
69 
70  bool equal(const Node& node) const override {
71  const auto& other = static_cast<const Negation&>(node);
72  return equal_ptr(operand, other.operand);
73  }
74 
75  /** Operand */
77 };
78 
79 } // namespace souffle::ram
souffle::ram::Negation::clone
Negation * clone() const override
Create a clone (i.e.
Definition: Negation.h:64
souffle::ram::Negation::Negation
Negation(Own< Condition > op)
Definition: Negation.h:51
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::Negation::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: Negation.h:60
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Negation::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Negation.h:73
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::Negation::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: Negation.h:77
souffle::ram::Negation::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Negation.h:68
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::Negation
Negates a given condition.
Definition: Negation.h:49
Node.h
std
Definition: Brie.h:3053
souffle::ram::Negation::operand
Own< Condition > operand
Operand.
Definition: Negation.h:83
souffle::ram::Negation::getOperand
const Condition & getOperand() const
Get operand of negation.
Definition: Negation.h:56