souffle  2.0.2-371-g6315b36
TupleElement.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 TupleElement.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 <cstdlib>
22 #include <ostream>
23 
24 namespace souffle::ram {
25 
26 /**
27  * @class TupleElement
28  * @brief Access element from the current tuple in a tuple environment
29  *
30  * In the following example, the tuple element t0.1 is accessed:
31  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
32  * IF t0.1 in A
33  * ...
34  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
35  */
36 class TupleElement : public Expression {
37 public:
38  TupleElement(size_t ident, size_t elem) : identifier(ident), element(elem) {}
39  /** @brief Get identifier */
40  int getTupleId() const {
41  return identifier;
42  }
43 
44  /** @brief Get element */
45  size_t getElement() const {
46  return element;
47  }
48 
49  TupleElement* clone() const override {
50  return new TupleElement(identifier, element);
51  }
52 
53 protected:
54  void print(std::ostream& os) const override {
55  os << "t" << identifier << "." << element;
56  }
57 
58  bool equal(const Node& node) const override {
59  const auto& other = static_cast<const TupleElement&>(node);
60  return identifier == other.identifier && element == other.element;
61  }
62 
63  /** Identifier for the tuple */
64  const size_t identifier;
65 
66  /** Element number */
67  const size_t element;
68 };
69 
70 } // namespace souffle::ram
souffle::ram::TupleElement::element
const size_t element
Element number.
Definition: TupleElement.h:73
souffle::ram::TupleElement::print
void print(std::ostream &os) const override
Print RAM node.
Definition: TupleElement.h:60
souffle::ram::TupleElement::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: TupleElement.h:64
souffle::ram::TupleElement
Access element from the current tuple in a tuple environment.
Definition: TupleElement.h:42
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
Node.h
souffle::ram::TupleElement::getElement
size_t getElement() const
Get element.
Definition: TupleElement.h:51
Expression.h
souffle::ram::TupleElement::clone
TupleElement * clone() const override
Create a clone (i.e.
Definition: TupleElement.h:55
souffle::ram::TupleElement::TupleElement
TupleElement(size_t ident, size_t elem)
Definition: TupleElement.h:44
souffle::ram::TupleElement::identifier
const size_t identifier
Identifier for the tuple.
Definition: TupleElement.h:70
souffle::ram::TupleElement::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleElement.h:46