Skip to content

Commit 0f95418

Browse files
committed
zero_initializer without message_handlert
Throws a string instead of 0.
1 parent a22a54a commit 0f95418

File tree

12 files changed

+57
-31
lines changed

12 files changed

+57
-31
lines changed

src/cegis/control/facade/control_runner.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Author: Daniel Kroening, [email protected]
77
88
\*******************************************************************/
99

10-
#include <linking/zero_initializer.h>
11-
1210
#include <cegis/symex/cegis_symex_learn.h>
1311
#include <cegis/symex/cegis_symex_verify.h>
1412
#include <cegis/facade/runner_helper.h>

src/cegis/control/verify/insert_solution.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Author: Daniel Kroening, [email protected]
1010
#include <algorithm>
1111

1212
#include <util/arith_tools.h>
13-
#include <util/message.h>
1413
#include <linking/zero_initializer.h>
1514

1615
#include <cegis/cegis-util/program_helper.h>
@@ -56,8 +55,7 @@ struct_exprt to_struct_expr(const symbol_tablet &st,
5655
const symbol_typet &type=control_solution_type(st);
5756
const namespacet ns(st);
5857
const struct_typet &struct_type=to_struct_type(ns.follow(type));
59-
null_message_handlert msg;
60-
const exprt zero(zero_initializer(type, loc, ns, msg));
58+
const exprt zero(zero_initializer(type, loc, ns));
6159
struct_exprt result(to_struct_expr(zero));
6260
struct_exprt::operandst &ops=result.operands();
6361
set_array(ops, st, struct_type, solution.a, CEGIS_CONTROL_A_MEMBER_NAME);

src/cegis/control/verify/zero_solutions.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ namespace
3232
struct_exprt make_zero(const namespacet &ns, const symbol_typet &type)
3333
{
3434
const source_locationt loc(default_cegis_source_location());
35-
null_message_handlert msg;
36-
return to_struct_expr(zero_initializer(type, loc, ns, msg));
35+
return to_struct_expr(zero_initializer(type, loc, ns));
3736
}
3837
}
3938

@@ -59,6 +58,5 @@ void zero_vector_solutiont::operator ()(
5958
const namespacet ns(st);
6059
const array_typet &type=control_vector_solution_type(st);
6160
const source_locationt loc(default_cegis_source_location());
62-
null_message_handlert msg;
63-
solution.K=to_array_expr(zero_initializer(type, loc, ns, msg));
61+
solution.K=to_array_expr(zero_initializer(type, loc, ns));
6462
}

src/cegis/jsa/learn/jsa_symex_learn.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void jsa_symex_learnt::process(const counterexamplest &counterexamples,
4545

4646
void jsa_symex_learnt::process(const size_t max_solution_size)
4747
{
48-
null_message_handlert msg;
4948
const namespacet ns(original_program.st);
5049
counterexamplest counterexamples(1);
5150
counterexamplet &counterexample=counterexamples.front();
@@ -55,7 +54,7 @@ void jsa_symex_learnt::process(const size_t max_solution_size)
5554
const irep_idt &key=pos->labels.front();
5655
const typet &type=get_affected_type(*pos);
5756
const source_locationt &loc=pos->source_location;
58-
const exprt value(zero_initializer(type, loc, ns, msg));
57+
const exprt value(zero_initializer(type, loc, ns));
5958
counterexample.insert(std::make_pair(key, value));
6059
}
6160
process(counterexamples, max_solution_size);

src/cegis/jsa/preprocessing/add_synthesis_library.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ void zero_new_global_vars(const symbol_tablet &st, goto_functionst &gf)
9393
assert(init.body_available());
9494
goto_programt &body=init.body;
9595
goto_programt::targett pos=std::prev(body.instructions.end(), 2);
96-
null_message_handlert msg;
9796
const source_locationt loc(jsa_builtin_source_location());
9897
const namespacet ns(st);
9998
for (const symbol_tablet::symbolst::value_type &symbol : st.symbols)
@@ -103,7 +102,7 @@ void zero_new_global_vars(const symbol_tablet &st, goto_functionst &gf)
103102
pos->type=goto_program_instruction_typet::ASSIGN;
104103
pos->source_location=loc;
105104
const symbol_exprt lhs(ns.lookup(symbol.first).symbol_expr());
106-
const exprt rhs(zero_initializer(lhs.type(), loc, ns, msg));
105+
const exprt rhs(zero_initializer(lhs.type(), loc, ns));
107106
pos->code=code_assignt(lhs, rhs);
108107
}
109108
}

src/cegis/learn/insert_counterexample.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ zero_valuest get_zero_values(const symbol_tablet &st,
3131
std::map<const irep_idt, exprt> zero_values;
3232
const source_locationt loc(default_cegis_source_location());
3333
const namespacet ns(st);
34-
null_message_handlert msg;
3534
for (const goto_programt::const_targett pos : ce_locs)
3635
{
3736
const irep_idt &marker=get_counterexample_marker(pos);
3837
const typet &type=get_affected_type(*pos);
39-
const exprt value(zero_initializer(type, loc, ns, msg));
38+
const exprt value(zero_initializer(type, loc, ns));
4039
zero_values.insert(std::make_pair(marker, value));
4140
}
4241
return zero_values;
@@ -172,8 +171,7 @@ void add_array_indexes(const std::set<irep_idt> &ce_keys, symbol_tablet &st,
172171
pos=declare_cegis_meta_variable(st, gf, std::prev(pos), CE_ARRAY_INDEX, type);
173172
const source_locationt loc(default_cegis_source_location());
174173
const namespacet ns(st);
175-
null_message_handlert msg;
176-
const exprt zero(zero_initializer(type, loc, ns, msg));
174+
const exprt zero(zero_initializer(type, loc, ns));
177175
assign_cegis_meta_variable(st, gf, pos, CE_ARRAY_INDEX, zero);
178176
pos=cprover_init;
179177
for (const irep_idt &key : ce_keys)

src/cegis/refactor/instructionset/create_cegis_processor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Author: Daniel Kroening, [email protected]
77
88
\*******************************************************************/
99

10-
#include <ansi-c/c_types.h>
1110
#include <util/arith_tools.h>
11+
12+
#include <ansi-c/c_types.h>
1213
#include <linking/zero_initializer.h>
1314

1415
#include <cegis/instrument/literals.h>
@@ -83,8 +84,7 @@ void create_variable_array(symbol_tablet &st, goto_functionst &gf,
8384
pos->source_location=new_symbol.location;
8485
const symbol_exprt lhs(st.lookup(name).symbol_expr());
8586
const namespacet ns(st);
86-
null_message_handlert msg;
87-
const exprt rhs(zero_initializer(array_type, new_symbol.location, ns, msg));
87+
const exprt rhs(zero_initializer(array_type, new_symbol.location, ns));
8888
pos->code=code_assignt(lhs, rhs);
8989
body.update();
9090
}

src/cegis/refactor/verify/refactor_symex_verify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ void refactor_symex_verifyt::process(const candidatet &candidate)
2828
symbol_tablet &st=current_program.st;
2929
goto_functionst &gf=current_program.gf;
3030
const namespacet ns(st);
31-
null_message_handlert msg;
3231
for (const irep_idt &program : current_program.programs)
3332
{
3433
symbolt &symbol=st.lookup(program);
3534
const candidatet::const_iterator it=candidate.find(program);
3635
if (candidate.end() == it)
3736
{
38-
const exprt zero(zero_initializer(symbol.type, symbol.location, ns, msg));
37+
const exprt zero(zero_initializer(symbol.type, symbol.location, ns));
3938
assign_in_cprover_init(gf, symbol, zero);
4039
} else assign_in_cprover_init(gf, symbol, it->second);
4140
}

src/goto-symex/symex_start_thread.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <util/message.h>
10-
119
#include <linking/zero_initializer.h>
1210

1311
#include "goto_symex.h"
@@ -116,10 +114,7 @@ void goto_symext::symex_start_thread(statet &state)
116114

117115
exprt rhs=symbol.value;
118116
if(rhs.is_nil())
119-
{
120-
null_message_handlert null_message;
121-
rhs=zero_initializer(symbol.type, symbol.location, ns, null_message);
122-
}
117+
rhs=zero_initializer(symbol.type, symbol.location, ns);
123118

124119
guardt guard;
125120
symex_assign_symbol(state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN);

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#include <iostream>
1111
#endif
1212

13+
#include <util/namespace.h>
1314
#include <util/std_expr.h>
1415
#include <util/expanding_vector.h>
1516
#include <util/string2int.h>

src/linking/zero_initializer.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9+
#include <sstream>
10+
11+
#include <util/namespace.h>
912
#include <util/message.h>
1013
#include <util/arith_tools.h>
11-
#include <util/expr_util.h>
1214
#include <util/std_types.h>
1315
#include <util/std_expr.h>
1416
#include <util/pointer_offset_size.h>
@@ -298,3 +300,34 @@ exprt zero_initializer(
298300
zero_initializert z_i(ns, message_handler);
299301
return z_i(type, source_location);
300302
}
303+
304+
/*******************************************************************\
305+
306+
Function: zero_initializer
307+
308+
Inputs:
309+
310+
Outputs:
311+
312+
Purpose:
313+
314+
\*******************************************************************/
315+
316+
exprt zero_initializer(
317+
const typet &type,
318+
const source_locationt &source_location,
319+
const namespacet &ns)
320+
{
321+
std::ostringstream oss;
322+
stream_message_handlert mh(oss);
323+
324+
try
325+
{
326+
zero_initializert z_i(ns, mh);
327+
return z_i(type, source_location);
328+
}
329+
catch(int)
330+
{
331+
throw oss.str();
332+
}
333+
}

src/linking/zero_initializer.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ Author: Daniel Kroening, [email protected]
1010
#define CPROVER_LINKING_ZERO_INITIALIZER_H
1111

1212
#include <util/expr.h>
13-
#include <util/namespace.h>
14-
#include <util/message.h>
13+
14+
class message_handlert;
15+
class namespacet;
16+
class source_locationt;
1517

1618
exprt zero_initializer(
1719
const typet &,
1820
const source_locationt &,
1921
const namespacet &,
2022
message_handlert &);
2123

24+
// throws a char* in case of failure
25+
exprt zero_initializer(
26+
const typet &,
27+
const source_locationt &,
28+
const namespacet &);
29+
2230
#endif // CPROVER_LINKING_ZERO_INITIALIZER_H

0 commit comments

Comments
 (0)