Skip to content

Commit 49e9b69

Browse files
committed
Separate the parsing of object-bits
So that the parsing can be kept with the data structure. So the length of `configt::set` can be marginally reduced. So that this functionality can be documented.
1 parent a5d9a5f commit 49e9b69

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SRC = allocate_objects.cpp \
44
array_name.cpp \
55
base_type.cpp \
66
bv_arithmetic.cpp \
7+
bv_encoding.cpp \
78
byte_operators.cpp \
89
c_types.cpp \
910
cmdline.cpp \

src/util/bv_encoding.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************\
2+
3+
Module: bv_encoding configuration
4+
5+
Author: Diffblue Ltd
6+
7+
\*******************************************************************/
8+
9+
#include "bv_encoding.h"
10+
11+
#include "exception_utils.h"
12+
#include "string2int.h"
13+
14+
bv_encodingt parse_object_bits_encoding(
15+
const std::string &argument,
16+
const std::size_t pointer_width)
17+
{
18+
const unsigned int object_bits = unsafe_string2unsigned(argument);
19+
if(object_bits <= 0 || object_bits >= pointer_width)
20+
{
21+
throw invalid_command_line_argument_exceptiont(
22+
"object-bits must be positive and less than the pointer width (" +
23+
std::to_string(pointer_width) + ") ",
24+
"--object_bits");
25+
}
26+
27+
bv_encodingt bv_encoding;
28+
bv_encoding.object_bits = object_bits;
29+
bv_encoding.is_object_bits_default = false;
30+
return bv_encoding;
31+
}

src/util/bv_encoding.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Diffblue Ltd
1010
#define CPROVER_UTIL_BV_ENCODING_H
1111

1212
#include <cstddef>
13+
#include <string>
1314

1415
struct bv_encodingt final
1516
{
@@ -18,4 +19,15 @@ struct bv_encodingt final
1819
bool is_object_bits_default = true;
1920
};
2021

22+
/// \brief Parses the `object_bits` argument from the command line arguments.
23+
/// \param argument The command line argument to parse the `object_bits` from.
24+
/// \param pointer_width The width of a pointer in bits. This is used to check
25+
/// the value of object_bits is within the valid range.
26+
/// \return A `bv_encodingt` on successful parsing. In the case where an invalid
27+
/// argument is specified, an `invalid_command_line_argument_exceptiont` will
28+
/// be thrown.
29+
bv_encodingt parse_object_bits_encoding(
30+
const std::string &argument,
31+
const std::size_t pointer_width);
32+
2133
#endif // CPROVER_UTIL_BV_ENCODING_H

src/util/config.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,19 +1074,8 @@ bool configt::set(const cmdlinet &cmdline)
10741074

10751075
if(cmdline.isset("object-bits"))
10761076
{
1077-
bv_encoding.object_bits=
1078-
unsafe_string2unsigned(cmdline.get_value("object-bits"));
1079-
1080-
if(!(0<bv_encoding.object_bits &&
1081-
bv_encoding.object_bits<ansi_c.pointer_width))
1082-
{
1083-
throw invalid_command_line_argument_exceptiont(
1084-
"object-bits must be positive and less than the pointer width (" +
1085-
std::to_string(ansi_c.pointer_width) + ") ",
1086-
"--object_bits");
1087-
}
1088-
1089-
bv_encoding.is_object_bits_default = false;
1077+
bv_encoding = parse_object_bits_encoding(
1078+
cmdline.get_value("object-bits"), ansi_c.pointer_width);
10901079
}
10911080

10921081
if(cmdline.isset("malloc-fail-assert") && cmdline.isset("malloc-fail-null"))

0 commit comments

Comments
 (0)