souffle  2.0.2-371-g6315b36
NestedOperation.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 NestedOperation.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Node.h"
18 #include "ram/Operation.h"
19 #include "ram/utility/NodeMapper.h"
21 #include <cassert>
22 #include <iosfwd>
23 #include <memory>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace souffle::ram {
29 
30 /**
31  * @class NestedOperation
32  * @brief Abstract class for a nesting operations in a loop-nest
33  *
34  * In the following example, the nested operation
35  * of "IF C1" is "IF C2":
36  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
37  * QUERY
38  * ...
39  * IF C1
40  * IF C2
41  * ...
42  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
43  *
44  * TODO (b-scholz): profile text is awkward; perhaps there is a better way of
45  * storing profile information for RAM operations since
46  * it is not always used for all RAM operations.
47  */
48 class NestedOperation : public Operation {
49 public:
50  NestedOperation(Own<Operation> nested, std::string profileText = "")
51  : nestedOperation(std::move(nested)), profileText(std::move(profileText)) {
52  assert(nestedOperation != nullptr);
53  }
54 
55  NestedOperation* clone() const override = 0;
56 
57  /** @brief Get nested operation */
58  Operation& getOperation() const {
59  return *nestedOperation;
60  }
61 
62  /** @brief Get profile text */
63  const std::string& getProfileText() const {
64  return profileText;
65  }
66 
67  std::vector<const Node*> getChildNodes() const override {
68  return {nestedOperation.get()};
69  }
70 
71  void apply(const NodeMapper& map) override {
72  nestedOperation = map(std::move(nestedOperation));
73  }
74 
75 protected:
76  void print(std::ostream& os, int tabpos) const override {
77  Operation::print(nestedOperation.get(), os, tabpos);
78  }
79 
80  bool equal(const Node& node) const override {
81  const auto& other = static_cast<const NestedOperation&>(node);
82  return equal_ptr(nestedOperation, other.nestedOperation) && profileText == other.profileText;
83  }
84 
85  /** Nested operation */
87 
88  /** Text used by the profiler */
89  const std::string profileText;
90 };
91 
92 } // namespace souffle::ram
souffle::ram::NestedOperation::profileText
const std::string profileText
Text used by the profiler.
Definition: NestedOperation.h:93
souffle::ram::NestedOperation::NestedOperation
NestedOperation(Own< Operation > nested, std::string profileText="")
Definition: NestedOperation.h:54
souffle::ram::NestedOperation::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: NestedOperation.h:75
souffle::ram::NestedOperation::getOperation
Operation & getOperation() const
Get nested operation.
Definition: NestedOperation.h:62
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
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
souffle::ram::NestedOperation::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: NestedOperation.h:84
souffle::ram::NestedOperation::getProfileText
const std::string & getProfileText() const
Get profile text.
Definition: NestedOperation.h:67
souffle::ram::NestedOperation::clone
NestedOperation * clone() const override=0
Create a clone (i.e.
souffle::ram::NestedOperation
Abstract class for a nesting operations in a loop-nest.
Definition: NestedOperation.h:52
souffle::ram::Operation
Abstract class for a relational algebra operation.
Definition: Operation.h:34
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
Operation.h
souffle::ram::NestedOperation::nestedOperation
Own< Operation > nestedOperation
Nested operation.
Definition: NestedOperation.h:90
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80
souffle::ram::NestedOperation::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: NestedOperation.h:71
souffle::ram::Operation::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Operation.h:39