-
Notifications
You must be signed in to change notification settings - Fork 195
/
ParserUtils.h
88 lines (60 loc) · 2.08 KB
/
ParserUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Souffle - A Datalog Compiler
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved
* Licensed under the Universal Permissive License v 1.0 as shown at:
* - https://opensource.org/licenses/UPL
* - <souffle root>/licenses/SOUFFLE-UPL.txt
*/
/************************************************************************
*
* @file ParserUtils.h
*
* Defines class RuleBody to represents rule bodies.
*
***********************************************************************/
#pragma once
#include "ast/Abstract.h"
#include "utility/MiscUtil.h"
#include <iosfwd>
#include <memory>
#include <utility>
#include <vector>
namespace souffle {
class AstClause;
class AstAtom;
class RuleBody {
public:
RuleBody() = default;
RuleBody(RuleBody&&) = default;
RuleBody& operator=(RuleBody&&) = default;
RuleBody negated() const;
void conjunct(RuleBody other);
void disjunct(RuleBody other);
VecOwn<AstClause> toClauseBodies() const;
// -- factory functions --
static RuleBody getTrue();
static RuleBody getFalse();
static RuleBody atom(Own<AstAtom> atom);
static RuleBody constraint(Own<AstConstraint> constraint);
friend std::ostream& operator<<(std::ostream& out, const RuleBody& body);
private:
// a struct to represent literals
struct literal {
literal(bool negated, std::unique_ptr<AstLiteral> atom) : negated(negated), atom(std::move(atom)) {}
// whether this literal is negated or not
bool negated;
// the atom referenced by tis literal
std::unique_ptr<AstLiteral> atom;
literal clone() const {
return literal(negated, souffle::clone(atom));
}
};
using clause = std::vector<literal>;
std::vector<clause> dnf;
static bool equal(const literal& a, const literal& b);
static bool equal(const clause& a, const clause& b);
static bool isSubsetOf(const clause& a, const clause& b);
static void insert(clause& cl, literal&& lit);
static void insert(std::vector<clause>& cnf, clause&& cls);
};
} // end of namespace souffle