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

Intermediate representation of a horn clause. More...

#include <Clause.h>

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

Public Member Functions

void addToBody (Own< Literal > literal)
 Add a literal to the body of the clause. More...
 
void apply (const NodeMapper &map) override
 Apply the mapper to all child nodes. More...
 
 Clause (Own< Atom > head={}, VecOwn< Literal > bodyLiterals={}, Own< ExecutionPlan > plan={}, SrcLocation loc={})
 
void clearExecutionPlan ()
 Resets the execution plan. More...
 
Clauseclone () const override
 Create a clone (i.e. More...
 
std::vector< Literal * > getBodyLiterals () const
 Obtains a copy of the internally maintained body literals. More...
 
std::vector< const Node * > getChildNodes () const override
 Obtain a list of all embedded AST child nodes. More...
 
const ExecutionPlangetExecutionPlan () const
 Obtains the execution plan associated to this clause or null if there is none. More...
 
AtomgetHead () const
 Return the atom that represents the head of the clause. More...
 
void setBodyLiterals (VecOwn< Literal > body)
 Set the bodyLiterals of clause to body. More...
 
void setExecutionPlan (Own< ExecutionPlan > plan)
 Updates the execution plan associated to this clause. More...
 
void setHead (Own< Atom > h)
 Set the head of clause to h. More...
 
- 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...
 

Protected Attributes

VecOwn< LiteralbodyLiterals
 Body literals of clause. More...
 
Own< Atomhead
 Head of the clause. More...
 
Own< ExecutionPlanplan
 User defined execution plan (if not defined, plan is null) More...
 

Detailed Description

Intermediate representation of a horn clause.

A clause can either be:

Definition at line 51 of file Clause.h.

Constructor & Destructor Documentation

◆ Clause()

souffle::ast::Clause::Clause ( Own< Atom head = {},
VecOwn< Literal bodyLiterals = {},
Own< ExecutionPlan plan = {},
SrcLocation  loc = {} 
)
inline

Definition at line 53 of file Clause.h.

53  {
54  bodyLiterals.push_back(std::move(literal));
55  }
56 

References bodyLiterals.

Member Function Documentation

◆ addToBody()

void souffle::ast::Clause::addToBody ( Own< Literal literal)
inline

Add a literal to the body of the clause.

Definition at line 59 of file Clause.h.

63  {

◆ apply()

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

Apply the mapper to all child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 103 of file Clause.h.

104  {
105  std::vector<const Node*> res = {head.get()};
106  for (auto& cur : bodyLiterals) {
107  res.push_back(cur.get());
108  }

References bodyLiterals, and head.

◆ clearExecutionPlan()

void souffle::ast::Clause::clearExecutionPlan ( )
inline

Resets the execution plan.

Definition at line 94 of file Clause.h.

97  {

◆ clone()

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

Create a clone (i.e.

deep copy) of this node

Implements souffle::ast::Node.

Definition at line 98 of file Clause.h.

99  : bodyLiterals) {
100  lit = map(std::move(lit));
101  }

◆ equal()

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

Abstract equality check for two AST nodes.

Reimplemented from souffle::ast::Node.

Definition at line 132 of file Clause.h.

◆ getBodyLiterals()

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

Obtains a copy of the internally maintained body literals.

Definition at line 79 of file Clause.h.

83  {

Referenced by souffle::ast::transform::RemoveRelationCopiesTransformer::removeRelationCopies(), and souffle::ast::transform::PartitionBodyLiteralsTransformer::transform().

◆ getChildNodes()

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

Obtain a list of all embedded AST child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 110 of file Clause.h.

112  :
113  void print(std::ostream& os) const override {
114  if (head != nullptr) {
115  os << *head;
116  }

◆ getExecutionPlan()

const ExecutionPlan* souffle::ast::Clause::getExecutionPlan ( ) const
inline

Obtains the execution plan associated to this clause or null if there is none.

Definition at line 84 of file Clause.h.

88  {

◆ getHead()

Atom* souffle::ast::Clause::getHead ( ) const
inline

Return the atom that represents the head of the clause.

Definition at line 74 of file Clause.h.

78  {

Referenced by souffle::ast::transform::RemoveRelationCopiesTransformer::removeRelationCopies(), and souffle::ast::transform::PartitionBodyLiteralsTransformer::transform().

◆ print()

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

Output to a given output stream.

Implements souffle::ast::Node.

Definition at line 119 of file Clause.h.

121  {
122  os << *plan;
123  }
124  }
125 
126  bool equal(const Node& node) const override {
127  const auto& other = static_cast<const Clause&>(node);
128  return equal_ptr(head, other.head) && equal_targets(bodyLiterals, other.bodyLiterals) &&
129  equal_ptr(plan, other.plan);
130  }

◆ setBodyLiterals()

void souffle::ast::Clause::setBodyLiterals ( VecOwn< Literal body)
inline

Set the bodyLiterals of clause to body.

Definition at line 69 of file Clause.h.

◆ setExecutionPlan()

void souffle::ast::Clause::setExecutionPlan ( Own< ExecutionPlan plan)
inline

Updates the execution plan associated to this clause.

Definition at line 89 of file Clause.h.

92  {

◆ setHead()

void souffle::ast::Clause::setHead ( Own< Atom h)
inline

Set the head of clause to h.

Definition at line 64 of file Clause.h.

68  {

Field Documentation

◆ bodyLiterals

VecOwn<Literal> souffle::ast::Clause::bodyLiterals
protected

Body literals of clause.

Definition at line 142 of file Clause.h.

Referenced by apply(), and Clause().

◆ head

Own<Atom> souffle::ast::Clause::head
protected

Head of the clause.

Definition at line 139 of file Clause.h.

Referenced by apply().

◆ plan

Own<ExecutionPlan> souffle::ast::Clause::plan
protected

User defined execution plan (if not defined, plan is null)

Definition at line 145 of file Clause.h.


The documentation for this class was generated from the following file:
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::ast::Clause::head
Own< Atom > head
Head of the clause.
Definition: Clause.h:139
souffle::ast::Clause::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: Clause.h:132
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::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::ast::Clause::plan
Own< ExecutionPlan > plan
User defined execution plan (if not defined, plan is null)
Definition: Clause.h:145
souffle::ast::Node::Node
Node(SrcLocation loc={})
Definition: Node.h:42
souffle::ast::Clause::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: Clause.h:119
souffle::ast::Clause::Clause
Clause(Own< Atom > head={}, VecOwn< Literal > bodyLiterals={}, Own< ExecutionPlan > plan={}, SrcLocation loc={})
Definition: Clause.h:53
souffle::ast::Clause::bodyLiterals
VecOwn< Literal > bodyLiterals
Body literals of clause.
Definition: Clause.h:142