Skip to content

SMT2: implement cond #8467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,11 @@
out << ')';
}
}
else if(expr.id() == ID_cond)

Check warning on line 2493 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L2493

Added line #L2493 was not covered by tests
{
// use the lowering
convert_expr(to_cond_expr(expr).lower());

Check warning on line 2496 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L2496

Added line #L2496 was not covered by tests
}
else
INVARIANT_WITH_DIAGNOSTICS(
false,
Expand Down
29 changes: 29 additions & 0 deletions src/util/std_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,32 @@
values.push_back(new_variable);
return instantiate(values);
}

exprt cond_exprt::lower() const

Check warning on line 264 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L264

Added line #L264 was not covered by tests
{
INVARIANT(

Check warning on line 266 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L266

Added line #L266 was not covered by tests
operands().size() % 2 == 0, "cond must have even number of operands");

exprt result = nil_exprt();

Check warning on line 269 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L269

Added line #L269 was not covered by tests

auto &operands = this->operands();

Check warning on line 271 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L271

Added line #L271 was not covered by tests

// functional version -- go backwards
for(std::size_t i = operands.size(); i != 0; i -= 2)

Check warning on line 274 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L274

Added line #L274 was not covered by tests
{
INVARIANT(

Check warning on line 276 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L276

Added line #L276 was not covered by tests
i >= 2,
"since the number of operands is even if i is nonzero it must be "
"greater than two");

const exprt &cond = operands[i - 2];
const exprt &value = operands[i - 1];

Check warning on line 282 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L281-L282

Added lines #L281 - L282 were not covered by tests

if(result.is_nil())
result = value;

Check warning on line 285 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L284-L285

Added lines #L284 - L285 were not covered by tests
else
result = if_exprt{cond, value, std::move(result)};

Check warning on line 287 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L287

Added line #L287 was not covered by tests
}

return result;

Check warning on line 290 in src/util/std_expr.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_expr.cpp#L290

Added line #L290 was not covered by tests
}
3 changes: 3 additions & 0 deletions src/util/std_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,9 @@ class cond_exprt : public multi_ary_exprt
operands().push_back(condition);
operands().push_back(value);
}

// a lowering to nested if_exprt
exprt lower() const;
};

template <>
Expand Down
Loading