Skip to content

Commit

Permalink
Merge pull request #6052 from tautschnig/set_size_t
Browse files Browse the repository at this point in the history
Add irept::set_size_t to avoid unnecessary casts
  • Loading branch information
tautschnig authored Apr 24, 2021
2 parents 4a7b064 + ae1aac1 commit afd8a60
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/util/bitvector_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class bswap_exprt : public unary_exprt

void set_bits_per_byte(std::size_t bits_per_byte)
{
set(ID_bits_per_byte, narrow_cast<long long>(bits_per_byte));
set_size_t(ID_bits_per_byte, bits_per_byte);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/util/bitvector_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class fixedbv_typet : public bitvector_typet

void set_integer_bits(std::size_t b)
{
set(ID_integer_bits, narrow_cast<long long>(b));
set_size_t(ID_integer_bits, b);
}

static void check(
Expand Down Expand Up @@ -335,7 +335,7 @@ class floatbv_typet : public bitvector_typet

void set_f(std::size_t b)
{
set(ID_f, narrow_cast<long long>(b));
set_size_t(ID_f, b);
}

static void check(
Expand Down
9 changes: 9 additions & 0 deletions src/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ void irept::set(const irep_namet &name, const long long value)
#endif
}

void irept::set_size_t(const irep_namet &name, const std::size_t value)
{
#ifdef USE_DSTRING
add(name).id(to_dstring(value));
#else
add(name).id(std::to_string(value));
#endif
}

void irept::remove(const irep_namet &name)
{
#if NAMED_SUB_IS_FORWARD_LIST
Expand Down
1 change: 1 addition & 0 deletions src/util/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ class irept
add(name, std::move(irep));
}
void set(const irep_namet &name, const long long value);
void set_size_t(const irep_namet &name, const std::size_t value);

void remove(const irep_namet &name);
void move_to_sub(irept &irep);
Expand Down
3 changes: 1 addition & 2 deletions src/util/std_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Author: Daniel Kroening, kroening@kroening.com

#include "expr_cast.h"
#include "invariant.h"
#include "narrow.h"
#include "std_types.h"

/// An expression without operands
Expand Down Expand Up @@ -1539,7 +1538,7 @@ class union_exprt:public unary_exprt

void set_component_number(std::size_t component_number)
{
set(ID_component_number, narrow_cast<long long>(component_number));
set_size_t(ID_component_number, component_number);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Author: Daniel Kroening, kroening@kroening.com
#include "invariant.h"
#include "mp_arith.h"
#include "validate.h"
#include <util/narrow.h>

#include <unordered_map>

Expand Down Expand Up @@ -842,7 +841,7 @@ class bitvector_typet : public typet

void set_width(std::size_t width)
{
set(ID_width, narrow_cast<long long>(width));
set_size_t(ID_width, width);
}

static void check(
Expand Down

0 comments on commit afd8a60

Please sign in to comment.