Skip to content
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

format_type can now format range_typet #8473

Merged
merged 1 commit into from
Sep 26, 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
6 changes: 6 additions & 0 deletions src/util/format_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ std::ostream &format_rec(std::ostream &os, const typet &type)
return os << "\xe2\x84\xa4"; // u+2124, 'Z'
else if(id == ID_natural)
return os << "\xe2\x84\x95"; // u+2115, 'N'
else if(id == ID_range)
{
auto &range_type = to_range_type(type);
return os << "{ " << range_type.get_from() << ", ..., "
<< range_type.get_to() << " }";
}
else if(id == ID_rational)
return os << "\xe2\x84\x9a"; // u+211A, 'Q'
else if(id == ID_mathematical_function)
Expand Down
1 change: 1 addition & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ SRC += analyses/ai/ai.cpp \
util/format.cpp \
util/format_expr.cpp \
util/format_number_range.cpp \
util/format_type.cpp \
util/get_base_name.cpp \
util/graph.cpp \
util/help_formatter.cpp \
Expand Down
19 changes: 19 additions & 0 deletions unit/util/format_type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************\

Module: Unit tests for `format` function on types

Author: Daniel Kroening, [email protected]

\*******************************************************************/

#include <util/format.h>
#include <util/format_type.h>
#include <util/std_expr.h>

#include <testing-utils/use_catch.h>

TEST_CASE("Format a range type", "[core][util][format_type]")
{
auto type = range_typet(1, 10);
REQUIRE(format_to_string(type) == "{ 1, ..., 10 }");
}
Loading