souffle  2.0.2-371-g6315b36
NestedIntrinsicOperator.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 NestedIntrinsicOperator.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Expression.h"
18 #include "ram/NestedOperation.h"
19 #include "ram/Node.h"
20 #include "ram/Operation.h"
21 #include "ram/TupleOperation.h"
22 #include "ram/utility/NodeMapper.h"
26 #include <iosfwd>
27 #include <memory>
28 #include <ostream>
29 #include <utility>
30 #include <vector>
31 
32 namespace souffle::ram {
33 
34 enum class NestedIntrinsicOp {
35  RANGE,
36  URANGE,
37  FRANGE,
38 };
39 
40 inline std::ostream& operator<<(std::ostream& os, NestedIntrinsicOp e) {
41  switch (e) {
42  case NestedIntrinsicOp::RANGE: return os << "RANGE";
43  case NestedIntrinsicOp::URANGE: return os << "URANGE";
44  case NestedIntrinsicOp::FRANGE: return os << "FRANGE";
45  default: fatal("invalid Operation");
46  }
47 }
48 
49 /**
50  * @class NestedIntrinsicOperator
51  * @brief Effectively identical to `IntrinsicOperator`, except it can produce multiple results.
52  *
53  * For example:
54  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
55  * RANGE(t0.0, t0.1, t0.2) INTO t1
56  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
57  */
58 class NestedIntrinsicOperator : public TupleOperation {
59 public:
60  NestedIntrinsicOperator(NestedIntrinsicOp op, VecOwn<Expression> args, Own<Operation> nested, int ident)
61  : TupleOperation(ident, std::move(nested)), args(std::move(args)), op(op) {}
62 
64  return op;
65  }
66 
67  std::vector<Expression*> getArguments() const {
68  return toPtrVector(args);
69  }
70 
71  std::vector<const Node*> getChildNodes() const override {
72  auto res = TupleOperation::getChildNodes();
73  for (auto&& x : args) {
74  res.push_back(x.get());
75  }
76  return res;
77  }
78 
79  NestedIntrinsicOperator* clone() const override {
80  return new NestedIntrinsicOperator(
82  }
83 
84  void apply(const NodeMapper& map) override {
86  for (auto&& x : args) {
87  x = map(std::move(x));
88  }
89  }
90 
91 protected:
92  void print(std::ostream& os, int tabpos) const override {
93  os << times(" ", tabpos);
94  os << op << "(" << join(args, ",", print_deref<Own<Expression>>()) << ") INTO t" << getTupleId()
95  << "\n";
96  NestedOperation::print(os, tabpos + 1);
97  }
98 
99  bool equal(const Node& node) const override {
100  auto&& other = static_cast<const NestedIntrinsicOperator&>(node);
101  return TupleOperation::equal(node) && op == other.op && equal_targets(args, other.args);
102  }
103 
104  /* Arguments */
106 
107  /* Operator */
108  const NestedIntrinsicOp op;
109 };
110 
111 } // namespace souffle::ram
souffle::ram::NestedIntrinsicOperator::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedIntrinsicOperator.h:96
NestedOperation.h
souffle::ram::NestedIntrinsicOperator::NestedIntrinsicOperator
NestedIntrinsicOperator(NestedIntrinsicOp op, VecOwn< Expression > args, Own< Operation > nested, int ident)
Definition: NestedIntrinsicOperator.h:64
souffle::ram::TupleOperation::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: TupleOperation.h:52
souffle::ram::TupleOperation::TupleOperation
TupleOperation(int ident, Own< Operation > nested, std::string profileText="")
Definition: TupleOperation.h:37
souffle::ram::NestedIntrinsicOperator::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: NestedIntrinsicOperator.h:88
souffle::ram::NestedOperation::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: NestedOperation.h:75
souffle::ram::NestedIntrinsicOp::RANGE
@ RANGE
e
l j a showGridBackground &&c b raw series this eventEmitter e
Definition: htmlJsChartistMin.h:15
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::operator<<
std::ostream & operator<<(std::ostream &os, NestedIntrinsicOp e)
Definition: NestedIntrinsicOperator.h:44
souffle::ram::NestedIntrinsicOp::FRANGE
@ FRANGE
souffle::ram::TupleOperation::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: TupleOperation.h:57
souffle::print_deref
A functor printing elements after dereferencing it.
Definition: StreamUtil.h:166
TupleOperation.h
souffle::ram::NestedIntrinsicOp::URANGE
@ URANGE
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::NestedIntrinsicOperator::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: NestedIntrinsicOperator.h:75
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
souffle::ram::NestedIntrinsicOperator::getArguments
std::vector< Expression * > getArguments() const
Definition: NestedIntrinsicOperator.h:71
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::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
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::TupleOperation::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleOperation.h:43
souffle::ram::NestedIntrinsicOperator::getFunction
NestedIntrinsicOp getFunction() const
Definition: NestedIntrinsicOperator.h:67
souffle::ram::NestedIntrinsicOperator::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: NestedIntrinsicOperator.h:103
souffle::ram::NestedIntrinsicOperator::args
VecOwn< Expression > args
Definition: NestedIntrinsicOperator.h:109
souffle::ram::NestedIntrinsicOp
NestedIntrinsicOp
Definition: NestedIntrinsicOperator.h:38
souffle::ram::NestedIntrinsicOperator::op
const NestedIntrinsicOp op
Definition: NestedIntrinsicOperator.h:112
souffle::ram::NestedIntrinsicOperator::clone
NestedIntrinsicOperator * clone() const override
Create a clone (i.e.
Definition: NestedIntrinsicOperator.h:83
Node.h
std
Definition: Brie.h:3053
Operation.h
StreamUtil.h
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ram::NestedIntrinsicOperator
Effectively identical to IntrinsicOperator, except it can produce multiple results.
Definition: NestedIntrinsicOperator.h:62
Expression.h
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
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80