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

bitvector_typet: set width from mp_integer #8477

Merged
merged 1 commit into from
Sep 29, 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
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ void c_typecheck_baset::typecheck_c_bit_field_type(c_bit_field_typet &type)
<< "bit field width is negative";
}

type.set_width(numeric_cast_v<std::size_t>(i));
type.width(i);
type.remove(ID_size);
}

Expand Down
11 changes: 11 additions & 0 deletions src/util/std_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "std_types.h"

#include "arith_tools.h"
#include "c_types.h"
#include "namespace.h"
#include "std_expr.h"
Expand Down Expand Up @@ -154,6 +155,16 @@
type.get_bool(ID_C_rvalue_reference);
}

std::size_t bitvector_typet::width() const

Check warning on line 158 in src/util/std_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_types.cpp#L158

Added line #L158 was not covered by tests
{
return get_size_t(ID_width);

Check warning on line 160 in src/util/std_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/std_types.cpp#L160

Added line #L160 was not covered by tests
}

void bitvector_typet::width(const mp_integer &width)
{
set_width(numeric_cast_v<std::size_t>(width));
}

void range_typet::set_from(const mp_integer &from)
{
set(ID_from, integer2string(from));
Expand Down
9 changes: 9 additions & 0 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,16 +917,25 @@ class bitvector_typet : public typet
set_width(width);
}

bitvector_typet(const irep_idt &_id, mp_integer _width) : typet(_id)
{
width(_width);
}

std::size_t get_width() const
{
return get_size_t(ID_width);
}

std::size_t width() const;

void set_width(std::size_t width)
{
set_size_t(ID_width, width);
}

void width(const mp_integer &);

static void check(
const typet &type,
const validation_modet vm = validation_modet::INVARIANT)
Expand Down
Loading