souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Private Attributes
souffle::ast::Aggregator Class Reference

Defines the aggregator class. More...

#include <Aggregator.h>

Inheritance diagram for souffle::ast::Aggregator:
Inheritance graph
Collaboration diagram for souffle::ast::Aggregator:
Collaboration graph

Public Member Functions

 Aggregator (AggregateOp baseOperator, Own< Argument > expr=nullptr, VecOwn< Literal > body={}, SrcLocation loc={})
 
void apply (const NodeMapper &map) override
 Apply the mapper to all child nodes. More...
 
Aggregatorclone () const override
 Create clone. More...
 
AggregateOp getBaseOperator () const
 Return the (base type) operator of the aggregator. More...
 
std::vector< Literal * > getBodyLiterals () const
 Return body literals. More...
 
std::vector< const Node * > getChildNodes () const override
 Obtain a list of all embedded AST child nodes. More...
 
std::optional< AggregateOpgetFinalType () const
 
const ArgumentgetTargetExpression () const
 Return target expression. More...
 
void setBody (VecOwn< Literal > bodyLiterals)
 Set body. More...
 
void setFinalType (AggregateOp newType)
 
- Public Member Functions inherited from souffle::ast::Argument
 Node (SrcLocation loc={})
 
- Public Member Functions inherited from souffle::ast::Node
std::string extloc () const
 Return source location of the syntactic element. More...
 
const SrcLocationgetSrcLoc () const
 Return source location of the Node. More...
 
 Node (SrcLocation loc={})
 
bool operator!= (const Node &other) const
 Inequality check for two AST nodes. More...
 
bool operator== (const Node &other) const
 Equivalence check for two AST nodes. More...
 
void setSrcLoc (SrcLocation l)
 Set source location for the Node. More...
 
virtual ~Node ()=default
 

Protected Member Functions

bool equal (const Node &node) const override
 Abstract equality check for two AST nodes. More...
 
void print (std::ostream &os) const override
 Output to a given output stream. More...
 

Private Attributes

AggregateOp baseOperator
 Aggregate (base type) operator. More...
 
VecOwn< Literalbody
 Body literal of sub-query. More...
 
std::optional< AggregateOpfinalTranslatorType
 
Own< ArgumenttargetExpression
 Aggregate expression. More...
 

Detailed Description

Defines the aggregator class.

Example: sum y+x: {A(y),B(x)}

Aggregates over a sub-query using an aggregate operator and an expression.

Definition at line 53 of file Aggregator.h.

Constructor & Destructor Documentation

◆ Aggregator()

souffle::ast::Aggregator::Aggregator ( AggregateOp  baseOperator,
Own< Argument expr = nullptr,
VecOwn< Literal body = {},
SrcLocation  loc = {} 
)
inline

Definition at line 55 of file Aggregator.h.

55  {
56  return baseOperator;
57  }
58 

References baseOperator.

Member Function Documentation

◆ apply()

void souffle::ast::Aggregator::apply ( const NodeMapper )
inlineoverridevirtual

Apply the mapper to all child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 100 of file Aggregator.h.

103  {
104  finalTranslatorType = newType;
105  }
106 
107  std::optional<AggregateOp> getFinalType() const {

◆ clone()

Aggregator* souffle::ast::Aggregator::clone ( ) const
inlineoverridevirtual

Create clone.

Implements souffle::ast::Argument.

Definition at line 91 of file Aggregator.h.

94  {
95  if (targetExpression) {
97  }
98  for (auto& cur : body) {

◆ equal()

bool souffle::ast::Aggregator::equal ( const Node ) const
inlineoverrideprotectedvirtual

Abstract equality check for two AST nodes.

Reimplemented from souffle::ast::Node.

Definition at line 126 of file Aggregator.h.

126  :
127  /** Aggregate (base type) operator */
129 
130  /** Aggregate expression */

◆ getBaseOperator()

AggregateOp souffle::ast::Aggregator::getBaseOperator ( ) const
inline

Return the (base type) operator of the aggregator.

Definition at line 61 of file Aggregator.h.

◆ getBodyLiterals()

std::vector<Literal*> souffle::ast::Aggregator::getBodyLiterals ( ) const
inline

Return body literals.

Definition at line 71 of file Aggregator.h.

Referenced by souffle::ast::transform::RemoveEmptyRelationsTransformer::removeEmptyRelations().

◆ getChildNodes()

std::vector<const Node*> souffle::ast::Aggregator::getChildNodes ( ) const
inlineoverridevirtual

Obtain a list of all embedded AST child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 80 of file Aggregator.h.

85  {
86  auto* copy = new Aggregator(
88  if (finalTranslatorType.has_value()) {
89  copy->setFinalType(finalTranslatorType.value());

◆ getFinalType()

std::optional<AggregateOp> souffle::ast::Aggregator::getFinalType ( ) const
inline

Definition at line 113 of file Aggregator.h.

114  {
115  os << " " << *targetExpression;

References targetExpression.

◆ getTargetExpression()

const Argument* souffle::ast::Aggregator::getTargetExpression ( ) const
inline

Return target expression.

Definition at line 66 of file Aggregator.h.

70  {

◆ print()

void souffle::ast::Aggregator::print ( std::ostream &  os) const
inlineoverrideprotectedvirtual

Output to a given output stream.

Implements souffle::ast::Node.

Definition at line 118 of file Aggregator.h.

120  {
121  const auto& other = static_cast<const Aggregator&>(node);
122  return baseOperator == other.baseOperator && equal_ptr(targetExpression, other.targetExpression) &&
123  equal_targets(body, other.body);
124  }

◆ setBody()

void souffle::ast::Aggregator::setBody ( VecOwn< Literal bodyLiterals)
inline

Set body.

Definition at line 76 of file Aggregator.h.

76  {
77  res.push_back(targetExpression.get());
78  }

References targetExpression.

◆ setFinalType()

void souffle::ast::Aggregator::setFinalType ( AggregateOp  newType)
inline

Definition at line 109 of file Aggregator.h.

111  :
112  void print(std::ostream& os) const override {

Field Documentation

◆ baseOperator

AggregateOp souffle::ast::Aggregator::baseOperator
private

Aggregate (base type) operator.

Definition at line 134 of file Aggregator.h.

Referenced by Aggregator().

◆ body

VecOwn<Literal> souffle::ast::Aggregator::body
private

Body literal of sub-query.

Definition at line 140 of file Aggregator.h.

◆ finalTranslatorType

std::optional<AggregateOp> souffle::ast::Aggregator::finalTranslatorType
private

Definition at line 143 of file Aggregator.h.

◆ targetExpression

Own<Argument> souffle::ast::Aggregator::targetExpression
private

Aggregate expression.

Definition at line 137 of file Aggregator.h.

Referenced by getFinalType(), and setBody().


The documentation for this class was generated from the following file:
souffle::AggregateOp
AggregateOp
Types of aggregation functions.
Definition: AggregateOp.h:34
souffle::ast::Aggregator::body
VecOwn< Literal > body
Body literal of sub-query.
Definition: Aggregator.h:140
souffle::ast::Aggregator::baseOperator
AggregateOp baseOperator
Aggregate (base type) operator.
Definition: Aggregator.h:134
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::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
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::ast::Aggregator::finalTranslatorType
std::optional< AggregateOp > finalTranslatorType
Definition: Aggregator.h:143
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
souffle::detail::brie::copy
auto copy(span< A, arity > s)
Definition: Brie.h:98
souffle::ast::Aggregator::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: Aggregator.h:118
souffle::ast::Aggregator::targetExpression
Own< Argument > targetExpression
Aggregate expression.
Definition: Aggregator.h:137
souffle::ast::Node::getSrcLoc
const SrcLocation & getSrcLoc() const
Return source location of the Node.
Definition: Node.h:46
souffle::ast::Aggregator::getFinalType
std::optional< AggregateOp > getFinalType() const
Definition: Aggregator.h:113
souffle::ast::Aggregator::Aggregator
Aggregator(AggregateOp baseOperator, Own< Argument > expr=nullptr, VecOwn< Literal > body={}, SrcLocation loc={})
Definition: Aggregator.h:55