5#include <mutable/mutable-config.hpp>
31 bool negative()
const {
return literal_ & 0x1UL; }
44 auto binary = cast<const ast::BinaryExpr>(&expr());
45 if (not binary)
return false;
46 if (not negative()
and binary->tok != TK_EQUAL)
return false;
47 if (negative()
and binary->tok != TK_BANG_EQUAL)
return false;
48 return is<const ast::Designator>(binary->lhs)
and is<const ast::Designator>(binary->rhs);
60 return this->negative() == other.
negative()
and this->expr() == other.
expr();
71 void to_sql(std::ostream &out)
const;
76 std::ostringstream oss;
81 void dump(std::ostream &out)
const;
86struct M_EXPORT
Clause :
public std::vector<Predicate>
90 bool operator<=(
const Clause &other)
const;
99 required |= P->get_required();
106 if (size() != 1)
return false;
107 auto &literal = operator[](0);
108 return literal.is_equi();
112 for (
auto &P : *
this)
113 if (P.can_be_null())
return true;
118 void to_sql(std::ostream &out)
const;
123 std::ostringstream oss;
128 void dump(std::ostream &out)
const;
133struct M_EXPORT
CNF :
public std::vector<Clause>
135 using std::vector<
Clause>::vector;
140 for (
auto &clause : *
this)
141 required |= clause.get_required();
150 for (
auto &clause : *
this)
151 if (not clause.is_equi())
return false;
156 for (
auto &clause : *
this)
157 if (clause.can_be_null())
return true;
161 bool operator<=(
const CNF &other)
const;
167 void to_sql(std::ostream &out)
const;
170 friend M_EXPORT std::ostream &
operator<<(std::ostream &out,
const CNF &cnf);
172 std::ostringstream oss;
177 void dump(std::ostream &out)
const;
183Clause M_EXPORT
operator||(
const Clause &lhs,
const Clause &rhs);
187CNF M_EXPORT
operator&&(
const Clause &lhs,
const Clause &rhs);
190CNF M_EXPORT
operator&&(
const CNF &lhs,
const CNF &rhs);
194CNF M_EXPORT
operator||(
const CNF &lhs,
const CNF &rhs);
198CNF M_EXPORT
operator!(
const Clause &clause);
216struct hash<
m::cnf::Predicate>
and(sizeof(T)==4) U64x1 reinterpret_to_U64(m
CNF M_EXPORT get_CNF(const ast::Clause &c)
Converts the Boolean Expr of c to a CNF.
CNF M_EXPORT operator&&(const Clause &lhs, const Clause &rhs)
Returns the logical and of two cnf::Clauses, i.e. a CNF with the two cnf::Clauses lhs and rhs.
CNF M_EXPORT operator!(const Clause &clause)
Returns the logical negation of a cnf::Clause.
Clause M_EXPORT operator||(const Clause &lhs, const Clause &rhs)
Returns the logical or of two cnf::Clauses, i.e. the disjunction of the Predicates of lhs and rhs.
CNF M_EXPORT to_CNF(const ast::Expr &e)
Converts the Boolean Expr e to a CNF.
A Schema represents a sequence of identifiers, optionally with a prefix, and their associated types.
virtual uint64_t hash() const =0
Computes a hash of this, considering only syntactic properties.
A CNF represents a conjunction of cnf::Clauses.
Schema get_required() const
Returns a Schema instance containing all required definitions (of Attributes and other Designators).
bool can_be_null() const
Returns true iff this CNF formula is nullable, i.e.
bool operator==(const CNF &other) const
bool is_equi() const
Returns true iff this CNF formula is an equi-predicate, i.e.
friend M_EXPORT std::string to_string(const CNF &cnf)
bool operator>=(const CNF &other) const
bool operator!=(const CNF &other) const
friend M_EXPORT std::ostream & operator<<(std::ostream &out, const CNF &cnf)
Print a textual representation of cnf to out.
A cnf::Clause represents a disjunction of Predicates.
bool operator==(const Clause &other) const
bool operator!=(const Clause &other) const
friend M_EXPORT std::string to_string(const Clause &clause)
Schema get_required() const
Returns a Schema instance containing all required definitions (of Attributes and other Designators).
bool operator>=(const Clause &other) const
bool can_be_null() const
Returns true iff this cnf::Clause formula is nullable, i.e.
friend std::ostream &M_EXPORT operator<<(std::ostream &out, const Clause &clause)
Print a textual representation of clause to out.
bool is_equi() const
Returns true iff this cnf::Clause formula is an equi-predicate, i.e.
A Predicate contains a Expr of Boolean type in either positive or negative form.
bool is_equi() const
Returns true iff this Predicate is an equi-predicate, i.e.
const ast::Expr & expr() const
Returns the Expr within this Predicate.
const ast::Expr * operator->() const
Returns the Expr within this Predicate.
Predicate operator!() const
Returns a negated version of this Predicate, i.e. if this Predicate is positive, the returned Predica...
bool operator<(Predicate other) const
Compare Predicates by the location of their referenced Expr in memory and their sign.
const ast::Expr & operator*() const
Returns the Expr within this Predicate.
bool can_be_null() const
Returns true iff this Predicate is nullable, i.e.
uintptr_t literal_
pointer to Expr; LSB is 1 iff literal is negated
bool operator!=(Predicate other) const
Returns true iff other is not equal to this.
static Predicate Create(const ast::Expr *e, bool is_negative)
Creates a Predicate from e.
static Predicate Negative(const ast::Expr *e)
Creates a negative Predicate from e.
bool operator==(Predicate other) const
Returns true iff other is equal to this.
friend std::ostream &M_EXPORT operator<<(std::ostream &out, const Predicate &pred)
Print a textual representation of pred to out.
static Predicate Positive(const ast::Expr *e)
Creates a positive Predicate from e.
ast::Expr & expr()
Returns the Expr within this Predicate.
bool negative() const
Returns true iff this Predicate is negative.
friend M_EXPORT std::string to_string(const Predicate &pred)
std::size_t operator()(m::cnf::Predicate P) const