souffle  2.0.2-371-g6315b36
Query.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 Query.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Node.h"
18 #include "ram/Operation.h"
19 #include "ram/Statement.h"
20 #include "ram/utility/NodeMapper.h"
24 #include <cassert>
25 #include <memory>
26 #include <ostream>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class Query
34  * @brief A relational algebra query
35  *
36  * Corresponds to the core machinery of semi-naive evaluation
37  *
38  * For example:
39  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
40  * QUERY
41  * FOR t0 in A
42  * FOR t1 in B
43  * ...
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  */
46 class Query : public Statement {
47 public:
48  Query(Own<Operation> o) : operation(std::move(o)) {
49  assert(operation && "operation is a nullptr");
50  }
51 
52  /** @brief Get RAM operation */
53  const Operation& getOperation() const {
54  return *operation;
55  }
56 
57  std::vector<const Node*> getChildNodes() const override {
58  return {operation.get()};
59  }
60 
61  Query* clone() const override {
62  return new Query(souffle::clone(operation));
63  }
64 
65  void apply(const NodeMapper& map) override {
66  operation = map(std::move(operation));
67  }
68 
69 protected:
70  void print(std::ostream& os, int tabpos) const override {
71  os << times(" ", tabpos) << "QUERY" << std::endl;
72  operation->print(os, tabpos + 1);
73  }
74 
75  bool equal(const Node& node) const override {
76  const auto& other = static_cast<const Query&>(node);
77  return equal_ptr(operation, other.operation);
78  }
79 
80  /** RAM operation */
82 };
83 
84 } // namespace souffle::ram
souffle::ram::Query
A relational algebra query.
Definition: Query.h:50
souffle::ram::Query::clone
Query * clone() const override
Create a clone (i.e.
Definition: Query.h:65
souffle::ram::Query::Query
Query(Own< Operation > o)
Definition: Query.h:52
souffle::ram::Query::getOperation
const Operation & getOperation() const
Get RAM operation.
Definition: Query.h:57
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::Query::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Query.h:69
souffle::ram
Definition: AstToRamTranslator.h:54
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
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
o
var o
Definition: htmlJsChartistMin.h:15
souffle::ram::Operation
Abstract class for a relational algebra operation.
Definition: Operation.h:34
souffle::equal_ptr
bool equal_ptr(const T *a, const T *b)
Compares two values referenced by a pointer where the case where both pointers are null is also consi...
Definition: MiscUtil.h:130
Node.h
souffle::ram::Query::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: Query.h:79
std
Definition: Brie.h:3053
Operation.h
StreamUtil.h
Statement.h
souffle::ram::Query::operation
Own< Operation > operation
RAM operation.
Definition: Query.h:85
souffle::ram::Query::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: Query.h:74
souffle::ram::Query::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: Query.h:61