souffle  2.0.2-371-g6315b36
PackRecord.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 PackRecord.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"
24 #include <cassert>
25 #include <memory>
26 #include <sstream>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class PackRecord
34  * @brief Packs a record's arguments into a reference
35  */
36 class PackRecord : public Expression {
37 public:
38  PackRecord(VecOwn<Expression> args) : arguments(std::move(args)) {
39  for (const auto& arg : arguments) {
40  assert(arg != nullptr && "argument is a null-pointer");
41  }
42  }
43 
44  /** @brief Get record arguments */
45  std::vector<Expression*> getArguments() const {
46  return toPtrVector(arguments);
47  }
48 
49  std::vector<const Node*> getChildNodes() const override {
50  std::vector<const Node*> res;
51  for (const auto& cur : arguments) {
52  res.push_back(cur.get());
53  }
54  return res;
55  }
56 
57  PackRecord* clone() const override {
58  auto* res = new PackRecord({});
59  for (auto& cur : arguments) {
60  res->arguments.emplace_back(cur->clone());
61  }
62  return res;
63  }
64 
65  void apply(const NodeMapper& map) override {
66  for (auto& arg : arguments) {
67  arg = map(std::move(arg));
68  }
69  }
70 
71 protected:
72  void print(std::ostream& os) const override {
73  os << "[" << join(arguments, ",", [](std::ostream& out, const Own<Expression>& arg) { out << *arg; })
74  << "]";
75  }
76 
77  bool equal(const Node& node) const override {
78  const auto& other = static_cast<const PackRecord&>(node);
79  return equal_targets(arguments, other.arguments);
80  }
81 
82  /** Arguments */
84 };
85 
86 } // namespace souffle::ram
souffle::ram::PackRecord::PackRecord
PackRecord(VecOwn< Expression > args)
Definition: PackRecord.h:44
souffle::ram::PackRecord::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: PackRecord.h:83
souffle::ram::PackRecord
Packs a record's arguments into a reference.
Definition: PackRecord.h:42
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
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::PackRecord::arguments
VecOwn< Expression > arguments
Arguments.
Definition: PackRecord.h:89
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
souffle::ram::PackRecord::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: PackRecord.h:55
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
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::PackRecord::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: PackRecord.h:71
souffle::ram::PackRecord::getArguments
std::vector< Expression * > getArguments() const
Get record arguments.
Definition: PackRecord.h:51
souffle::ram::PackRecord::clone
PackRecord * clone() const override
Create a clone (i.e.
Definition: PackRecord.h:63
Node.h
souffle::ram::PackRecord::print
void print(std::ostream &os) const override
Print RAM node.
Definition: PackRecord.h:78
std
Definition: Brie.h:3053
StreamUtil.h
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