Skip to content

Commit 162e0f7

Browse files
authored
Merge pull request #8514 from diffblue/format-expr-bv
Format bit-vectors with `[` ... `]` vector notation
2 parents 01357a0 + 3b9e94e commit 162e0f7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/util/format_expr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,16 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
190190
{
191191
// These do not have a numerical interpretation.
192192
// We'll print the 0/1 bit pattern, starting with the bit
193-
// that has the highest index.
193+
// that has the highest index. We use vector notation
194+
// [...] to avoid confusion with decimal numbers.
194195
auto width = to_bv_type(src.type()).get_width();
195196
std::string result;
196-
result.reserve(width);
197+
result.reserve(width + 2);
197198
auto &value = src.get_value();
199+
result += '[';
198200
for(std::size_t i = 0; i < width; i++)
199201
result += get_bvrep_bit(value, width, width - i - 1) ? '1' : '0';
202+
result += ']';
200203
return os << result;
201204
}
202205
else if(type == ID_integer || type == ID_natural || type == ID_range)

unit/util/format_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ TEST_CASE("Format a bv-typed constant", "[core][util][format_expr]")
3030
{
3131
auto value = make_bvrep(4, [](std::size_t index) { return index != 2; });
3232
auto expr = constant_exprt{value, bv_typet{4}};
33-
REQUIRE(format_to_string(expr) == "1011");
33+
REQUIRE(format_to_string(expr) == "[1011]");
3434
}

0 commit comments

Comments
 (0)