souffle  2.0.2-371-g6315b36
ListStatement.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 ListStatement.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Node.h"
18 #include "ram/Statement.h"
19 #include "ram/utility/NodeMapper.h"
21 #include <cassert>
22 #include <memory>
23 #include <utility>
24 #include <vector>
25 
26 namespace souffle::ram {
27 
28 /**
29  * @class ListStatement
30  * @brief Abstract class for a list of RAM statements
31  */
32 class ListStatement : public Statement {
33 public:
34  ListStatement() = default;
35  ListStatement(VecOwn<Statement> statements) : statements(std::move(statements)) {}
36 
37  template <typename... Stmts>
38  ListStatement(Own<Stmts>&&... stmts) {
39  Own<Statement> tmp[] = {std::move(stmts)...};
40  for (auto& cur : tmp) {
41  assert(cur.get() != nullptr && "statement is a null-pointer");
42  statements.emplace_back(std::move(cur));
43  }
44  }
45 
46  /** @brief Get statements */
47  std::vector<Statement*> getStatements() const {
48  return toPtrVector(statements);
49  }
50 
51  std::vector<const Node*> getChildNodes() const override {
52  std::vector<const Node*> res;
53  for (const auto& cur : statements) {
54  res.push_back(cur.get());
55  }
56  return res;
57  }
58 
59  void apply(const NodeMapper& map) override {
60  for (auto& stmt : statements) {
61  stmt = map(std::move(stmt));
62  }
63  }
64 
65 protected:
66  bool equal(const Node& node) const override {
67  const auto& other = static_cast<const ListStatement&>(node);
68  return equal_targets(statements, other.statements);
69  }
70 
71 protected:
72  /** Ordered list of RAM statements */
74 };
75 
76 } // namespace souffle::ram
souffle::ram::ListStatement::getStatements
std::vector< Statement * > getStatements() const
Get statements.
Definition: ListStatement.h:51
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ram::ListStatement::ListStatement
ListStatement()=default
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
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::ListStatement::statements
VecOwn< Statement > statements
Ordered list of RAM statements.
Definition: ListStatement.h:77
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
NodeMapper.h
ContainerUtil.h
souffle::equal_targets
bool equal_targets(const Container &a, const Container &b, const Comparator &comp)
A function testing whether two containers are equal with the given Comparator.
Definition: ContainerUtil.h:433
souffle::ram::ListStatement::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: ListStatement.h:70
souffle::ram::ListStatement::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: ListStatement.h:55
Node.h
souffle::ram::ListStatement::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: ListStatement.h:63
std
Definition: Brie.h:3053
Statement.h
souffle::ram::ListStatement
Abstract class for a list of RAM statements.
Definition: ListStatement.h:36
souffle::toPtrVector
std::vector< T * > toPtrVector(const std::vector< std::unique_ptr< T >> &v)
A utility function enabling the creation of a vector of pointers.
Definition: ContainerUtil.h:146
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45