Skip to content

Add irept::set_size_t to avoid unnecessary casts #6052

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

Merged
merged 1 commit into from
Apr 24, 2021
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
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, [email protected]

#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, [email protected]
#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