souffle  2.0.2-371-g6315b36
IntrinsicOperator.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 IntrinsicOperator.h
12  *
13  * Defines a class for evaluating values in the Relational Algebra Machine
14  *
15  ************************************************************************/
16 
17 #pragma once
18 
19 #include "FunctorOps.h"
20 #include "ram/AbstractOperator.h"
21 #include "ram/Expression.h"
22 #include "ram/Node.h"
25 #include <memory>
26 #include <sstream>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class IntrinsicOperator
34  * @brief Operator that represents an intrinsic (built-in) functor
35  */
36 class IntrinsicOperator : public AbstractOperator {
37 public:
38  template <typename... Args>
39  IntrinsicOperator(FunctorOp op, Args... args) : AbstractOperator({std::move(args)...}), operation(op) {}
40 
41  IntrinsicOperator(FunctorOp op, VecOwn<Expression> args)
42  : AbstractOperator(std::move(args)), operation(op) {}
43 
44  /** @brief Get operator symbol */
46  return operation;
47  }
48 
49  IntrinsicOperator* clone() const override {
50  VecOwn<Expression> argsCopy;
51  for (auto& arg : arguments) {
52  argsCopy.emplace_back(arg->clone());
53  }
54  return new IntrinsicOperator(operation, std::move(argsCopy));
55  }
56 
57 protected:
58  void print(std::ostream& os) const override {
60  os << "(" << join(arguments, tfm::format("%s", operation)) << ")";
61  } else {
62  os << operation << "(" << join(arguments) << ")";
63  }
64  }
65 
66  bool equal(const Node& node) const override {
67  const auto& other = static_cast<const IntrinsicOperator&>(node);
68  return AbstractOperator::equal(node) && operation == other.operation;
69  }
70 
71  /** Operation symbol */
73 };
74 
75 } // 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::IntrinsicOperator::print
void print(std::ostream &os) const override
Print RAM node.
Definition: IntrinsicOperator.h:64
souffle::ram::AbstractOperator::arguments
VecOwn< Expression > arguments
Arguments of user defined operator.
Definition: AbstractOperator.h:74
tinyformat::format
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:1089
souffle::ram::IntrinsicOperator::getOperator
FunctorOp getOperator() const
Get operator symbol.
Definition: IntrinsicOperator.h:51
souffle::ram::AbstractOperator::AbstractOperator
AbstractOperator(VecOwn< Expression > args)
Definition: AbstractOperator.h:42
souffle::ram::IntrinsicOperator::operation
const FunctorOp operation
Operation symbol.
Definition: IntrinsicOperator.h:78
tinyformat.h
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::IntrinsicOperator::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: IntrinsicOperator.h:72
souffle::ram::IntrinsicOperator::clone
IntrinsicOperator * clone() const override
Create a clone (i.e.
Definition: IntrinsicOperator.h:55
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
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::FunctorOp
FunctorOp
Definition: FunctorOps.h:35
souffle::ram::IntrinsicOperator
Operator that represents an intrinsic (built-in) functor.
Definition: IntrinsicOperator.h:42
Node.h
std
Definition: Brie.h:3053
StreamUtil.h
souffle::ram::IntrinsicOperator::IntrinsicOperator
IntrinsicOperator(FunctorOp op, Args... args)
Definition: IntrinsicOperator.h:45
FunctorOps.h
Expression.h
souffle::isInfixFunctorOp
bool isInfixFunctorOp(std::string_view symbol)
Determines whether a functor should be written using infix notation (e.g.
Definition: FunctorOps.cpp:252
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45
souffle::ram::AbstractOperator
Abstract class for an operator/functor.
Definition: AbstractOperator.h:40
AbstractOperator.h