souffle  2.0.2-371-g6315b36
Data Structures | Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | Friends
souffle::RuleBody Class Reference

#include <ParserUtils.h>

Collaboration diagram for souffle::RuleBody:
Collaboration graph

Data Structures

struct  literal
 

Public Member Functions

void conjunct (RuleBody other)
 
void disjunct (RuleBody other)
 
RuleBody negated () const
 
RuleBodyoperator= (RuleBody &&)=default
 
 RuleBody ()=default
 
 RuleBody (RuleBody &&)=default
 
VecOwn< ast::ClausetoClauseBodies () const
 

Static Public Member Functions

static RuleBody atom (Own< ast::Atom > atom)
 
static RuleBody constraint (Own< ast::Constraint > constraint)
 
static RuleBody getFalse ()
 
static RuleBody getTrue ()
 

Private Types

using clause = std::vector< literal >
 

Static Private Member Functions

static bool equal (const clause &a, const clause &b)
 
static bool equal (const literal &a, const literal &b)
 
static void insert (clause &cl, literal &&lit)
 
static void insert (std::vector< clause > &cnf, clause &&cls)
 
static bool isSubsetOf (const clause &a, const clause &b)
 

Private Attributes

std::vector< clausednf
 

Friends

std::ostream & operator<< (std::ostream &out, const RuleBody &body)
 

Detailed Description

Definition at line 36 of file ParserUtils.h.

Member Typedef Documentation

◆ clause

using souffle::RuleBody::clause = std::vector<literal>
private

Definition at line 84 of file ParserUtils.h.

Constructor & Destructor Documentation

◆ RuleBody() [1/2]

souffle::RuleBody::RuleBody ( )
default

Referenced by getTrue().

◆ RuleBody() [2/2]

souffle::RuleBody::RuleBody ( RuleBody &&  )
default

Member Function Documentation

◆ atom()

RuleBody souffle::RuleBody::atom ( Own< ast::Atom atom)
static

Definition at line 139 of file ParserUtils.cpp.

140  {
141  RuleBody body;
142  body.dnf.push_back(clause());
143  body.dnf.back().emplace_back(literal{false, std::move(constraint)});
144  return body;

References constraint(), and dnf.

Referenced by getFalse(), and toClauseBodies().

Here is the call graph for this function:

◆ conjunct()

void souffle::RuleBody::conjunct ( RuleBody  other)

Definition at line 58 of file ParserUtils.cpp.

65  : dnf) {
66  for (const auto& clauseB : other.dnf) {
67  clause cur;
68 
69  for (const auto& lit : clauseA) {
70  cur.emplace_back(lit.clone());
71  }
72  for (const auto& lit : clauseB) {
73  insert(cur, lit.clone());
74  }
75 
76  insert(res, std::move(cur));
77  }
78  }
79 
80  dnf = std::move(res);
81 }
82 
83 void RuleBody::disjunct(RuleBody other) {
84  // append the clauses of the other body to this body
85  for (auto& cur : other.dnf) {
86  insert(dnf, std::move(cur));
87  }

◆ constraint()

RuleBody souffle::RuleBody::constraint ( Own< ast::Constraint constraint)
static

Definition at line 146 of file ParserUtils.cpp.

147  {
148  return out << join(body.dnf, ";", [](std::ostream& out, const RuleBody::clause& cur) {
149  out << join(cur, ",", [](std::ostream& out, const RuleBody::literal& l) {
150  if (l.negated) {
151  out << "!";

References dnf, and souffle::join().

Referenced by atom().

Here is the call graph for this function:

◆ disjunct()

void souffle::RuleBody::disjunct ( RuleBody  other)

Definition at line 89 of file ParserUtils.cpp.

90  {
91  // collect clause results
92  VecOwn<ast::Clause> bodies;
93  for (const clause& cur : dnf) {
94  bodies.push_back(mk<ast::Clause>());

References dnf.

◆ equal() [1/2]

bool souffle::RuleBody::equal ( const clause a,
const clause b 
)
staticprivate

Definition at line 168 of file ParserUtils.cpp.

168  : b) {
169  if (equal(i, j)) {
170  found = true;
171  break;
172  }
173  }
174  if (!found) {
175  return false;
176  }
177  }
178  return true;
179 }
180 
181 bool RuleBody::isSubsetOf(const clause& a, const clause& b) {
182  if (a.size() > b.size()) {
183  return false;
184  }
185  for (const auto& i : a) {

References i, and j.

◆ equal() [2/2]

bool souffle::RuleBody::equal ( const literal a,
const literal b 
)
staticprivate

Definition at line 164 of file ParserUtils.cpp.

166  : a) {

◆ getFalse()

RuleBody souffle::RuleBody::getFalse ( )
static

Definition at line 135 of file ParserUtils.cpp.

136  {false, std::move(atom)});
137  return body;

References atom().

Here is the call graph for this function:

◆ getTrue()

RuleBody souffle::RuleBody::getTrue ( )
static

Definition at line 129 of file ParserUtils.cpp.

129  {
130  return RuleBody();
131 }
132 
133 RuleBody RuleBody::atom(Own<ast::Atom> atom) {

References RuleBody().

Here is the call graph for this function:

◆ insert() [1/2]

void souffle::RuleBody::insert ( clause cl,
literal &&  lit 
)
staticprivate

Definition at line 206 of file ParserUtils.cpp.

209  {
210  for (const auto& cur : cnf) {
211  if (isSubsetOf(cur, cls)) {
212  return;
213  }

◆ insert() [2/2]

void souffle::RuleBody::insert ( std::vector< clause > &  cnf,
clause &&  cls 
)
staticprivate

Definition at line 215 of file ParserUtils.cpp.

216  : cnf) {
217  if (!isSubsetOf(cls, cur)) {
218  res.push_back(std::move(cur));
219  }
220  }
221  res.swap(cnf);
222  cnf.push_back(std::move(cls));
223 }
224 
225 } // end of namespace souffle

◆ isSubsetOf()

bool souffle::RuleBody::isSubsetOf ( const clause a,
const clause b 
)
staticprivate

Definition at line 187 of file ParserUtils.cpp.

187  : b) {
188  if (equal(i, j)) {
189  found = true;
190  break;
191  }
192  }
193  if (!found) {
194  return false;
195  }
196  }
197  return true;
198 }
199 
200 void RuleBody::insert(clause& cl, literal&& lit) {
201  for (const auto& cur : cl) {
202  if (equal(cur, lit)) {
203  return;
204  }

References i, and j.

◆ negated()

RuleBody souffle::RuleBody::negated ( ) const

Definition at line 42 of file ParserUtils.cpp.

43  {!lit.negated, clone(lit.atom)});
44  }
45 
46  res.conjunct(std::move(step));
47  }
48 
49  return res;
50 }
51 
52 void RuleBody::conjunct(RuleBody other) {
53  // avoid making clones if possible
54  if (dnf.size() == 1 && other.dnf.size() == 1) {
55  for (auto&& rhs : other.dnf[0]) {
56  insert(dnf[0], std::move(rhs));

References souffle::clone(), and souffle::RuleBody::literal::negated.

Here is the call graph for this function:

◆ operator=()

RuleBody& souffle::RuleBody::operator= ( RuleBody &&  )
default

◆ toClauseBodies()

VecOwn< ast::Clause > souffle::RuleBody::toClauseBodies ( ) const

Definition at line 96 of file ParserUtils.cpp.

97  : cur) {
98  // extract literal
99  auto base = clone(lit.atom);
100  // negate if necessary
101  if (lit.negated) {
102  // negate
103  if (auto* atom = dynamic_cast<ast::Atom*>(&*base)) {
104  base.release();
105  base = mk<ast::Negation>(Own<ast::Atom>(atom));
106  base->setSrcLoc(atom->getSrcLoc());
107  } else if (auto* cstr = dynamic_cast<ast::Constraint*>(&*base)) {
109  }
110  }
111 
112  // add to result
113  clause.addToBody(std::move(base));
114  }
115  }
116 
117  // done
118  return bodies;
119 }
120 
121 // -- factory functions --
122 
124  RuleBody body;
125  body.dnf.push_back(clause());

References atom(), base, souffle::clone(), and souffle::ast::negateConstraintInPlace().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const RuleBody body 
)
friend

Definition at line 153 of file ParserUtils.cpp.

158  {
159  return a.negated == b.negated && *a.atom == *b.atom;
160 }
161 
162 bool RuleBody::equal(const clause& a, const clause& b) {

Field Documentation

◆ dnf

std::vector<clause> souffle::RuleBody::dnf
private

Definition at line 86 of file ParserUtils.h.

Referenced by atom(), constraint(), and disjunct().


The documentation for this class was generated from the following files:
souffle::RuleBody::disjunct
void disjunct(RuleBody other)
Definition: ParserUtils.cpp:89
souffle::RuleBody::conjunct
void conjunct(RuleBody other)
Definition: ParserUtils.cpp:58
base
T & base
Definition: Reader.h:60
rhs
Own< Argument > rhs
Definition: ResolveAliases.cpp:185
j
var j
Definition: htmlJsChartistMin.h:15
souffle::RuleBody::equal
static bool equal(const literal &a, const literal &b)
Definition: ParserUtils.cpp:164
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
i
size_t i
Definition: json11.h:663
souffle::RuleBody::atom
static RuleBody atom(Own< ast::Atom > atom)
Definition: ParserUtils.cpp:139
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::RuleBody::RuleBody
RuleBody()=default
souffle::RuleBody::insert
static void insert(clause &cl, literal &&lit)
Definition: ParserUtils.cpp:206
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
souffle::RuleBody::clause
std::vector< literal > clause
Definition: ParserUtils.h:84
souffle::RuleBody::constraint
static RuleBody constraint(Own< ast::Constraint > constraint)
Definition: ParserUtils.cpp:146
souffle::ast::negateConstraintInPlace
void negateConstraintInPlace(Constraint &constraint)
Negate an ast constraint.
Definition: Utils.cpp:297
souffle::RuleBody::getTrue
static RuleBody getTrue()
Definition: ParserUtils.cpp:129
souffle::RuleBody::dnf
std::vector< clause > dnf
Definition: ParserUtils.h:86
souffle::RuleBody::isSubsetOf
static bool isSubsetOf(const clause &a, const clause &b)
Definition: ParserUtils.cpp:187