Skip to content

Commit 053a6cd

Browse files
committed
Use allocate_objects to manage new symbol creation
This simplifies the code in generate_nondet_init and reduces code duplication.
1 parent 38201a8 commit 053a6cd

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

src/util/nondet.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Author: Diffblue Ltd.
77
\*******************************************************************/
88

99
#include "nondet.h"
10+
#include "allocate_objects.h"
1011

1112
#include <util/arith_tools.h>
1213
#include <util/c_types.h>
@@ -16,25 +17,17 @@ Author: Diffblue Ltd.
1617
symbol_exprt generate_nondet_int(
1718
const exprt &min_value_expr,
1819
const exprt &max_value_expr,
19-
const std::string &name_prefix,
2020
const std::string &basename_prefix,
21-
const irep_idt &mode,
2221
const source_locationt &source_location,
23-
symbol_table_baset &symbol_table,
22+
allocate_objectst &allocate_objects,
2423
code_blockt &instructions)
2524
{
2625
PRECONDITION(min_value_expr.type() == max_value_expr.type());
2726
const typet &int_type = min_value_expr.type();
2827

2928
// Declare a symbol for the non deterministic integer.
30-
const symbol_exprt &nondet_symbol = get_fresh_aux_symbol(
31-
int_type,
32-
name_prefix,
33-
basename_prefix,
34-
source_location,
35-
mode,
36-
symbol_table)
37-
.symbol_expr();
29+
const symbol_exprt &nondet_symbol =
30+
allocate_objects.allocate_automatic_local_object(int_type, basename_prefix);
3831
instructions.add(code_declt(nondet_symbol));
3932

4033
// Assign the symbol any non deterministic integer value.
@@ -58,23 +51,19 @@ symbol_exprt generate_nondet_int(
5851
symbol_exprt generate_nondet_int(
5952
const mp_integer &min_value,
6053
const mp_integer &max_value,
61-
const std::string &name_prefix,
6254
const std::string &basename_prefix,
6355
const typet &int_type,
64-
const irep_idt &mode,
6556
const source_locationt &source_location,
66-
symbol_table_baset &symbol_table,
57+
allocate_objectst &allocate_objects,
6758
code_blockt &instructions)
6859
{
6960
PRECONDITION(min_value < max_value);
7061
return generate_nondet_int(
7162
from_integer(min_value, int_type),
7263
from_integer(max_value, int_type),
73-
name_prefix,
7464
basename_prefix,
75-
mode,
7665
source_location,
77-
symbol_table,
66+
allocate_objects,
7867
instructions);
7968
}
8069

@@ -93,15 +82,16 @@ code_blockt generate_nondet_switch(
9382

9483
code_blockt result_block;
9584

85+
allocate_objectst allocate_objects(
86+
mode, source_location, name_prefix, symbol_table);
87+
9688
const symbol_exprt &switch_value = generate_nondet_int(
9789
0,
9890
switch_cases.size() - 1,
99-
id2string(name_prefix),
10091
"nondet_int",
10192
int_type,
102-
mode,
10393
source_location,
104-
symbol_table,
94+
allocate_objects,
10595
result_block);
10696

10797
code_blockt switch_block;

src/util/nondet.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Diffblue Ltd.
99
#ifndef CPROVER_JAVA_BYTECODE_NONDET_H
1010
#define CPROVER_JAVA_BYTECODE_NONDET_H
1111

12+
#include <util/allocate_objects.h>
1213
#include <util/std_code.h>
1314
#include <util/std_expr.h>
1415
#include <util/symbol_table.h>
@@ -26,11 +27,9 @@ Author: Diffblue Ltd.
2627
symbol_exprt generate_nondet_int(
2728
const exprt &min_value_expr,
2829
const exprt &max_value_expr,
29-
const std::string &name_prefix,
3030
const std::string &basename_prefix,
31-
const irep_idt &mode,
3231
const source_locationt &source_location,
33-
symbol_table_baset &symbol_table,
32+
allocate_objectst &allocate_objects,
3433
code_blockt &instructions);
3534

3635
/// Gets a fresh nondet choice in range (min_value, max_value). GOTO generated
@@ -42,26 +41,22 @@ symbol_exprt generate_nondet_int(
4241
/// ```
4342
/// \param min_value: Minimum value (inclusive) of returned int.
4443
/// \param max_value: Maximum value (inclusive) of returned int.
45-
/// \param name_prefix: Prefix for the fresh symbol name generated (should be
46-
/// function id)
44+
/// \param basename_prefix: Basename prefix for the fresh symbol name generated.
4745
/// \param int_type: The type of the int used to non-deterministically choose
4846
/// one of the switch cases.
49-
/// \param mode: Mode (language) of the symbol to be generated.
47+
/// \param allocate_objects: Handles allocation of new objects.
5048
/// \param source_location: The location to mark the generated int with.
51-
/// \param symbol_table: The global symbol table.
5249
/// \param [out] instructions: Output instructions are written to
5350
/// 'instructions'. These declare, nondet-initialise and range-constrain (with
5451
/// assume statements) a fresh integer.
5552
/// \return Returns a symbol expression for the resulting integer.
5653
symbol_exprt generate_nondet_int(
5754
const mp_integer &min_value,
5855
const mp_integer &max_value,
59-
const std::string &name_prefix,
6056
const std::string &basename_prefix,
6157
const typet &int_type,
62-
const irep_idt &mode,
6358
const source_locationt &source_location,
64-
symbol_table_baset &symbol_table,
59+
allocate_objectst &allocate_objects,
6560
code_blockt &instructions);
6661

6762
typedef std::vector<codet> alternate_casest;

0 commit comments

Comments
 (0)