Skip to content

Commit

Permalink
remove dead code in FunctionExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Dec 23, 2023
1 parent c23cb5c commit fc92f47
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
24 changes: 1 addition & 23 deletions smt/exprs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,8 @@ void FunctionExpr::add(const FunctionExpr &other) {
fn.insert(other.fn.begin(), other.fn.end());
}

void FunctionExpr::del(const expr &key) {
fn.erase(key);
}

optional<expr> FunctionExpr::operator()(const expr &key) const {
DisjointExpr disj(default_val);
DisjointExpr<expr> disj;
for (auto &[k, v] : fn) {
disj.add(v, k == key);
}
Expand All @@ -208,35 +204,17 @@ const expr* FunctionExpr::lookup(const expr &key) const {

FunctionExpr FunctionExpr::simplify() const {
FunctionExpr newfn;
if (default_val)
newfn.default_val = default_val->simplify();

for (auto &[k, v] : fn) {
newfn.add(k.simplify(), v.simplify());
}
return newfn;
}

weak_ordering FunctionExpr::operator<=>(const FunctionExpr &rhs) const {
if (auto cmp = fn <=> rhs.fn;
is_neq(cmp))
return cmp;

// libstdc++'s optional::operator<=> is buggy
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98842
if (default_val && rhs.default_val)
return *default_val <=> *rhs.default_val;

return (bool)default_val <=> (bool)rhs.default_val;
}

ostream& operator<<(ostream &os, const FunctionExpr &f) {
os << "{\n";
for (auto &[k, v] : f) {
os << k << ": " << v << '\n';
}
if (f.default_val)
os << "default: " << *f.default_val << '\n';
return os << '}';
}

Expand Down
7 changes: 2 additions & 5 deletions smt/exprs.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,11 @@ class ChoiceExpr {

class FunctionExpr {
std::map<expr, expr> fn; // key -> val
std::optional<expr> default_val;

public:
FunctionExpr() = default;
FunctionExpr(expr &&default_val) : default_val(std::move(default_val)) {}
void add(const expr &key, expr &&val);
void add(const FunctionExpr &other);
void del(const expr &key);

std::optional<expr> operator()(const expr &key) const;
const expr* lookup(const expr &key) const;
Expand All @@ -205,9 +202,9 @@ class FunctionExpr {

auto begin() const { return fn.begin(); }
auto end() const { return fn.end(); }
bool empty() const { return fn.empty() && !default_val; }
bool empty() const { return fn.empty(); }

std::weak_ordering operator<=>(const FunctionExpr &rhs) const;
auto operator<=>(const FunctionExpr &rhs) const = default;

friend std::ostream& operator<<(std::ostream &os, const FunctionExpr &e);
};
Expand Down

0 comments on commit fc92f47

Please sign in to comment.