Skip to content

Commit afd8a60

Browse files
authored
Merge pull request #6052 from tautschnig/set_size_t
Add irept::set_size_t to avoid unnecessary casts
2 parents 4a7b064 + ae1aac1 commit afd8a60

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

src/util/bitvector_expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class bswap_exprt : public unary_exprt
3737

3838
void set_bits_per_byte(std::size_t bits_per_byte)
3939
{
40-
set(ID_bits_per_byte, narrow_cast<long long>(bits_per_byte));
40+
set_size_t(ID_bits_per_byte, bits_per_byte);
4141
}
4242
};
4343

src/util/bitvector_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class fixedbv_typet : public bitvector_typet
273273

274274
void set_integer_bits(std::size_t b)
275275
{
276-
set(ID_integer_bits, narrow_cast<long long>(b));
276+
set_size_t(ID_integer_bits, b);
277277
}
278278

279279
static void check(
@@ -335,7 +335,7 @@ class floatbv_typet : public bitvector_typet
335335

336336
void set_f(std::size_t b)
337337
{
338-
set(ID_f, narrow_cast<long long>(b));
338+
set_size_t(ID_f, b);
339339
}
340340

341341
static void check(

src/util/irep.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ void irept::set(const irep_namet &name, const long long value)
9090
#endif
9191
}
9292

93+
void irept::set_size_t(const irep_namet &name, const std::size_t value)
94+
{
95+
#ifdef USE_DSTRING
96+
add(name).id(to_dstring(value));
97+
#else
98+
add(name).id(std::to_string(value));
99+
#endif
100+
}
101+
93102
void irept::remove(const irep_namet &name)
94103
{
95104
#if NAMED_SUB_IS_FORWARD_LIST

src/util/irep.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class irept
437437
add(name, std::move(irep));
438438
}
439439
void set(const irep_namet &name, const long long value);
440+
void set_size_t(const irep_namet &name, const std::size_t value);
440441

441442
void remove(const irep_namet &name);
442443
void move_to_sub(irept &irep);

src/util/std_expr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
1515

1616
#include "expr_cast.h"
1717
#include "invariant.h"
18-
#include "narrow.h"
1918
#include "std_types.h"
2019

2120
/// An expression without operands
@@ -1539,7 +1538,7 @@ class union_exprt:public unary_exprt
15391538

15401539
void set_component_number(std::size_t component_number)
15411540
{
1542-
set(ID_component_number, narrow_cast<long long>(component_number));
1541+
set_size_t(ID_component_number, component_number);
15431542
}
15441543
};
15451544

src/util/std_types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Author: Daniel Kroening, [email protected]
1818
#include "invariant.h"
1919
#include "mp_arith.h"
2020
#include "validate.h"
21-
#include <util/narrow.h>
2221

2322
#include <unordered_map>
2423

@@ -842,7 +841,7 @@ class bitvector_typet : public typet
842841

843842
void set_width(std::size_t width)
844843
{
845-
set(ID_width, narrow_cast<long long>(width));
844+
set_size_t(ID_width, width);
846845
}
847846

848847
static void check(

0 commit comments

Comments
 (0)