Skip to content

Commit 5826a8e

Browse files
committed
format_type can now format range_typet
This adds formatting for range_typet as { from, ..., to }.
1 parent 4c59d28 commit 5826a8e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/util/format_type.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ std::ostream &format_rec(std::ostream &os, const typet &type)
9898
return os << "\xe2\x84\xa4"; // u+2124, 'Z'
9999
else if(id == ID_natural)
100100
return os << "\xe2\x84\x95"; // u+2115, 'N'
101+
else if(id == ID_range)
102+
{
103+
auto &range_type = to_range_type(type);
104+
return os << "{ " << range_type.get_from() << ", ..., "
105+
<< range_type.get_to() << " }";
106+
}
101107
else if(id == ID_rational)
102108
return os << "\xe2\x84\x9a"; // u+211A, 'Q'
103109
else if(id == ID_mathematical_function)

unit/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ SRC += analyses/ai/ai.cpp \
144144
util/format.cpp \
145145
util/format_expr.cpp \
146146
util/format_number_range.cpp \
147+
util/format_type.cpp \
147148
util/get_base_name.cpp \
148149
util/graph.cpp \
149150
util/help_formatter.cpp \

unit/util/format_type.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for `format` function on types
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include <util/format.h>
10+
#include <util/format_type.h>
11+
#include <util/std_expr.h>
12+
13+
#include <testing-utils/use_catch.h>
14+
15+
TEST_CASE("Format a range type", "[core][util][format_type]")
16+
{
17+
auto type = range_typet(1, 10);
18+
REQUIRE(format_to_string(type) == "{ 1, ..., 10 }");
19+
}

0 commit comments

Comments
 (0)