souffle  2.0.2-371-g6315b36
Loop.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 Loop.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Node.h"
18 #include "ram/Statement.h"
19 #include "ram/utility/NodeMapper.h"
23 #include <cassert>
24 #include <memory>
25 #include <ostream>
26 #include <utility>
27 #include <vector>
28 
29 namespace souffle::ram {
30 
31 /**
32  * @class Loop
33  * @brief Execute statement until statement terminates loop via an exit statement
34  *
35  * For example:
36  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
37  * LOOP
38  * PARALLEL
39  * ...
40  * END PARALLEL
41  * END LOOP
42  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
43  */
44 class Loop : public Statement {
45 public:
46  Loop(Own<Statement> b) : body(std::move(b)) {
47  assert(body != nullptr && "Loop body is a null-pointer");
48  }
49 
50  /** @brief Get loop body */
51  const Statement& getBody() const {
52  return *body;
53  }
54 
55  std::vector<const Node*> getChildNodes() const override {
56  return {body.get()};
57  }
58 
59  Loop* clone() const override {
60  return new Loop(souffle::clone(body));
61  }
62 
63  void apply(const NodeMapper& map) override {
64  body = map(std::move(body));
65  }
66 
67 protected:
68  void print(std::ostream& os, int tabpos) const override {
69  os << times(" ", tabpos) << "LOOP" << std::endl;
70  Statement::print(body.get(), os, tabpos + 1);
71  os << times(" ", tabpos) << "END LOOP" << std::endl;
72  }
73 
74  bool equal(const Node& node) const override {
75  const auto& other = static_cast<const Loop&>(node);
76  return equal_ptr(body, other.body);
77  }
78 
79  /** Loop body */
81 };
82 
83 } // namespace souffle::ram
souffle::ram::Loop::Loop
Loop(Own< Statement > b)
Definition: Loop.h:50
souffle::ram::Loop::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Loop.h:67
souffle::ram::Loop
Execute statement until statement terminates loop via an exit statement.
Definition: Loop.h:48
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram::Loop::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: Loop.h:78
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::Loop::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: Loop.h:59
souffle::ram
Definition: AstToRamTranslator.h:54
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::Loop::clone
Loop * clone() const override
Create a clone (i.e.
Definition: Loop.h:63
souffle::ram::Statement::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Statement.h:42
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::Loop::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: Loop.h:72
souffle::ram::Loop::body
Own< Statement > body
Loop body.
Definition: Loop.h:84
souffle::ram::Statement
Abstract class for RAM statements.
Definition: Statement.h:37
Node.h
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
std
Definition: Brie.h:3053
StreamUtil.h
Statement.h
souffle::ram::Loop::getBody
const Statement & getBody() const
Get loop body.
Definition: Loop.h:55