souffle  2.0.2-371-g6315b36
BooleanConstraint.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2020 The Souffle Developers. 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 BooleanConstraint.h
12  *
13  * Defines the boolean constraint class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Constraint.h"
20 #include "ast/Node.h"
21 #include "parser/SrcLocation.h"
23 #include <cassert>
24 #include <iostream>
25 #include <string>
26 #include <utility>
27 
28 namespace souffle::ast {
29 
30 /**
31  * @class BooleanConstraint
32  * @brief Boolean constraint class
33  *
34  * Example:
35  * true
36  *
37  * Boolean constraint representing either the 'true' or the 'false' value
38  */
39 class BooleanConstraint : public Constraint {
40 public:
41  BooleanConstraint(bool truthValue, SrcLocation loc = {})
42  : Constraint(std::move(loc)), truthValue(truthValue) {}
43 
44  /** Check whether constraint holds */
45  bool isTrue() const {
46  return truthValue;
47  }
48 
49  /** Set truth value */
50  void set(bool value) {
51  truthValue = value;
52  }
53 
54  BooleanConstraint* clone() const override {
55  return new BooleanConstraint(truthValue, getSrcLoc());
56  }
57 
58 protected:
59  void print(std::ostream& os) const override {
60  os << (truthValue ? "true" : "false");
61  }
62 
63  bool equal(const Node& node) const override {
64  assert(isA<BooleanConstraint>(&node));
65  const auto& other = static_cast<const BooleanConstraint&>(node);
66  return truthValue == other.truthValue;
67  }
68 
69  /** Truth value of Boolean constraint */
70  bool truthValue;
71 };
72 
73 } // namespace souffle::ast
souffle::ast::BooleanConstraint::clone
BooleanConstraint * clone() const override
Definition: BooleanConstraint.h:60
souffle::ast::BooleanConstraint::equal
bool equal(const Node &node) const override
Definition: BooleanConstraint.h:69
souffle::ast::BooleanConstraint
Boolean constraint class.
Definition: BooleanConstraint.h:45
souffle::ast::BooleanConstraint::print
void print(std::ostream &os) const override
Adds print support for constraints (debugging)
Definition: BooleanConstraint.h:65
souffle::ast::BooleanConstraint::isTrue
bool isTrue() const
Check whether constraint holds.
Definition: BooleanConstraint.h:51
SrcLocation.h
souffle::ast::BooleanConstraint::truthValue
bool truthValue
Truth value of Boolean constraint.
Definition: BooleanConstraint.h:76
MiscUtil.h
Constraint.h
souffle::ast::BooleanConstraint::set
void set(bool value)
Set truth value.
Definition: BooleanConstraint.h:56
souffle::ast::BooleanConstraint::BooleanConstraint
BooleanConstraint(bool truthValue, SrcLocation loc={})
Definition: BooleanConstraint.h:47
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast
Definition: Aggregator.h:35