souffle  2.0.2-371-g6315b36
Exit.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 Exit.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Condition.h"
18 #include "ram/Node.h"
19 #include "ram/Statement.h"
20 #include "ram/utility/NodeMapper.h"
24 #include <cassert>
25 #include <memory>
26 #include <ostream>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class Exit
34  * @brief Exit statement for a loop
35  *
36  * Exits a loop if exit condition holds.
37  *
38  * The following example will exit the loop given
39  * that A is the empty set:
40  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
41  * EXIT (A = ∅)
42  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
43  */
44 class Exit : public Statement {
45 public:
46  Exit(Own<Condition> c) : condition(std::move(c)) {
47  assert(condition && "condition is a nullptr");
48  }
49 
50  /** @brief Get exit condition */
51  const Condition& getCondition() const {
52  return *condition;
53  }
54 
55  std::vector<const Node*> getChildNodes() const override {
56  return {condition.get()};
57  }
58 
59  Exit* clone() const override {
60  return new Exit(souffle::clone(condition));
61  }
62 
63  void apply(const NodeMapper& map) override {
64  condition = map(std::move(condition));
65  }
66 
67 protected:
68  void print(std::ostream& os, int tabpos) const override {
69  os << times(" ", tabpos) << "EXIT " << getCondition() << std::endl;
70  }
71 
72  bool equal(const Node& node) const override {
73  const auto& other = static_cast<const Exit&>(node);
74  return equal_ptr(condition, other.condition);
75  }
76 
77  /** Exit condition */
79 };
80 
81 } // namespace souffle::ram
souffle::ram::Exit::clone
Exit * clone() const override
Create a clone (i.e.
Definition: Exit.h:63
souffle::ram::Exit
Exit statement for a loop.
Definition: Exit.h:48
souffle::ram::Exit::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: Exit.h:76
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
Definition: AstToRamTranslator.h:54
souffle::ram::Exit::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: Exit.h:72
souffle::ram::Exit::condition
Own< Condition > condition
Exit condition.
Definition: Exit.h:82
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
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
ContainerUtil.h
souffle::ram::Exit::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Exit.h:67
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
Node.h
std
Definition: Brie.h:3053
souffle::ram::Exit::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: Exit.h:59
StreamUtil.h
Statement.h
souffle::ram::Exit::getCondition
const Condition & getCondition() const
Get exit condition.
Definition: Exit.h:55
souffle::ram::Exit::Exit
Exit(Own< Condition > c)
Definition: Exit.h:50