souffle  2.0.2-371-g6315b36
AbstractOperator.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 AbstractOperator.h
12  *
13  * Defines a class for evaluating values in the Relational Algebra Machine
14  *
15  ************************************************************************/
16 
17 #pragma once
18 
19 #include "ram/Expression.h"
20 #include "ram/Node.h"
21 #include "ram/utility/NodeMapper.h"
23 #include <cassert>
24 #include <memory>
25 #include <utility>
26 #include <vector>
27 
28 namespace souffle::ram {
29 
30 /**
31  * @class AbstractOperator
32  * @brief Abstract class for an operator/functor
33  */
34 class AbstractOperator : public Expression {
35 public:
36  explicit AbstractOperator(VecOwn<Expression> args) : arguments(std::move(args)) {
37  for (auto const& arg : arguments) {
38  assert(arg != nullptr && "argument is null-pointer");
39  }
40  }
41 
42  /** @brief Get argument values */
43  std::vector<Expression*> getArguments() const {
44  return toPtrVector(arguments);
45  }
46 
47  std::vector<const Node*> getChildNodes() const override {
48  std::vector<const Node*> res;
49  for (const auto& cur : arguments) {
50  res.push_back(cur.get());
51  }
52  return res;
53  }
54 
55  void apply(const NodeMapper& map) override {
56  for (auto& arg : arguments) {
57  arg = map(std::move(arg));
58  }
59  }
60 
61 protected:
62  bool equal(const Node& node) const override {
63  const auto& other = static_cast<const AbstractOperator&>(node);
64  return equal_targets(arguments, other.arguments);
65  }
66 
67  /** Arguments of user defined operator */
69 };
70 
71 } // namespace souffle::ram
souffle::ram::AbstractOperator::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: AbstractOperator.h:68
souffle::ram::AbstractOperator::getArguments
std::vector< Expression * > getArguments() const
Get argument values.
Definition: AbstractOperator.h:49
souffle::ram::AbstractOperator::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: AbstractOperator.h:53
souffle::ram::AbstractOperator::arguments
VecOwn< Expression > arguments
Arguments of user defined operator.
Definition: AbstractOperator.h:74
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::AbstractOperator::AbstractOperator
AbstractOperator(VecOwn< Expression > args)
Definition: AbstractOperator.h:42
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
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::AbstractOperator::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: AbstractOperator.h:61
Node.h
std
Definition: Brie.h:3053
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::AbstractOperator
Abstract class for an operator/functor.
Definition: AbstractOperator.h:40