souffle  2.0.2-371-g6315b36
ParserUtils.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 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 ParserUtils.h
12  *
13  * Defines a rewrite class for multi-heads and disjunction
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Atom.h"
20 #include "ast/Clause.h"
21 #include "ast/Constraint.h"
22 #include "ast/Literal.h"
24 #include <iosfwd>
25 #include <utility>
26 #include <vector>
27 
28 namespace souffle {
29 
30 class RuleBody {
31 public:
32  RuleBody() = default;
33  RuleBody(RuleBody&&) = default;
34  RuleBody& operator=(RuleBody&&) = default;
35 
36  RuleBody negated() const;
37 
38  void conjunct(RuleBody other);
39 
40  void disjunct(RuleBody other);
41 
43 
44  // -- factory functions --
45 
46  static RuleBody getTrue();
47 
48  static RuleBody getFalse();
49 
51 
53 
54  friend std::ostream& operator<<(std::ostream& out, const RuleBody& body);
55 
56 private:
57  // a struct to represent literals
58  struct literal {
60 
61  // whether this literal is negated or not
62  bool negated;
63 
64  // the atom referenced by tis literal
66 
67  literal clone() const {
69  }
70  };
71 
72  using clause = std::vector<literal>;
73 
74  std::vector<clause> dnf;
75 
76  static bool equal(const literal& a, const literal& b);
77 
78  static bool equal(const clause& a, const clause& b);
79 
80  static bool isSubsetOf(const clause& a, const clause& b);
81 
82  static void insert(clause& cl, literal&& lit);
83 
84  static void insert(std::vector<clause>& cnf, clause&& cls);
85 };
86 
87 } // end of namespace souffle
souffle::RuleBody::disjunct
void disjunct(RuleBody other)
Definition: ParserUtils.cpp:89
souffle::RuleBody::toClauseBodies
VecOwn< ast::Clause > toClauseBodies() const
Definition: ParserUtils.cpp:96
souffle::RuleBody::literal::clone
literal clone() const
Definition: ParserUtils.h:79
souffle::RuleBody::conjunct
void conjunct(RuleBody other)
Definition: ParserUtils.cpp:58
souffle::RuleBody::literal::negated
bool negated
Definition: ParserUtils.h:74
souffle::RuleBody::negated
RuleBody negated() const
Definition: ParserUtils.cpp:42
souffle::RuleBody::literal
Definition: ParserUtils.h:70
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
MiscUtil.h
Constraint.h
souffle::RuleBody::getFalse
static RuleBody getFalse()
Definition: ParserUtils.cpp:135
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
souffle::RuleBody::operator<<
friend std::ostream & operator<<(std::ostream &out, const RuleBody &body)
Definition: ParserUtils.cpp:153
souffle::RuleBody::atom
static RuleBody atom(Own< ast::Atom > atom)
Definition: ParserUtils.cpp:139
Atom.h
Literal.h
souffle::RuleBody::operator=
RuleBody & operator=(RuleBody &&)=default
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
std
Definition: Brie.h:3053
souffle::RuleBody::literal::atom
Own< ast::Literal > atom
Definition: ParserUtils.h:77
souffle::RuleBody::constraint
static RuleBody constraint(Own< ast::Constraint > constraint)
Definition: ParserUtils.cpp:146
souffle::RuleBody::getTrue
static RuleBody getTrue()
Definition: ParserUtils.cpp:129
Clause.h
souffle
Definition: AggregateOp.h:25
souffle::RuleBody
Definition: ParserUtils.h:36
souffle::RuleBody::dnf
std::vector< clause > dnf
Definition: ParserUtils.h:86
souffle::RuleBody::literal::literal
literal(bool negated, Own< ast::Literal > atom)
Definition: ParserUtils.h:71
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45
souffle::RuleBody::isSubsetOf
static bool isSubsetOf(const clause &a, const clause &b)
Definition: ParserUtils.cpp:187