Skip to content

Commit 1bd9efd

Browse files
Merge pull request diffblue#2097 from peterschrammel/java-cleanup-replace
Move replace_java_nondet to java_bytecode
2 parents 0090952 + a079f46 commit 1bd9efd

File tree

8 files changed

+71
-63
lines changed

8 files changed

+71
-63
lines changed

src/ansi-c/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ various threading interfaces.
2525

2626
\section preprocessing Preprocessing & Parsing
2727

28-
In the \ref ansi-c and \ref java_bytecode directories
28+
In the \ref ansi-c directory
2929

3030
**Key classes:**
3131
* \ref languaget and its subclasses
@@ -46,7 +46,7 @@ digraph G {
4646

4747
\section type-checking Type-checking
4848

49-
In the \ref ansi-c and \ref java_bytecode directories.
49+
In the \ref ansi-c directory
5050

5151
**Key classes:**
5252
* \ref languaget and its subclasses

src/cbmc/bmc.h

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Author: Daniel Kroening, [email protected]
1919
#include <util/options.h>
2020
#include <util/ui_message.h>
2121

22-
#include <java_bytecode/java_enum_static_init_unwind_handler.h>
23-
2422
#include <solvers/prop/prop.h>
2523
#include <solvers/prop/prop_conv.h>
2624
#include <solvers/sat/cnf.h>

src/goto-programs/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ SRC = basic_blocks.cpp \
5050
remove_unused_functions.cpp \
5151
remove_vector.cpp \
5252
remove_virtual_functions.cpp \
53-
replace_java_nondet.cpp \
5453
generate_function_bodies.cpp \
5554
resolve_inherited_component.cpp \
5655
safety_checker.cpp \

src/java_bytecode/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SRC = bytecode_info.cpp \
3131
java_types.cpp \
3232
java_utils.cpp \
3333
mz_zip_archive.cpp \
34+
replace_java_nondet.cpp \
3435
remove_exceptions.cpp \
3536
remove_instanceof.cpp \
3637
select_pointer_type.cpp \

src/goto-programs/replace_java_nondet.cpp renamed to src/java_bytecode/replace_java_nondet.cpp

+64-54
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ Author: Reuben Thomas, [email protected]
99
/// \file
1010
/// Replace Java Nondet expressions
1111

12-
#include "goto-programs/replace_java_nondet.h"
13-
#include "goto-programs/goto_convert.h"
14-
#include "goto-programs/goto_model.h"
15-
#include "goto-programs/remove_skip.h"
12+
#include "replace_java_nondet.h"
1613

17-
#include "util/irep_ids.h"
14+
#include <goto-programs/goto_convert.h>
15+
#include <goto-programs/goto_model.h>
16+
#include <goto-programs/remove_skip.h>
1817

1918
#include <algorithm>
2019
#include <regex>
@@ -24,23 +23,35 @@ Author: Reuben Thomas, [email protected]
2423
class nondet_instruction_infot final
2524
{
2625
public:
27-
enum class is_nondett:bool { FALSE, TRUE };
28-
enum class is_nullablet:bool { FALSE, TRUE };
26+
enum class is_nondett : bool
27+
{
28+
FALSE,
29+
TRUE
30+
};
31+
enum class is_nullablet : bool
32+
{
33+
FALSE,
34+
TRUE
35+
};
2936

30-
nondet_instruction_infot():
31-
is_nondet(is_nondett::FALSE),
32-
is_nullable(is_nullablet::FALSE)
37+
nondet_instruction_infot()
38+
: is_nondet(is_nondett::FALSE), is_nullable(is_nullablet::FALSE)
3339
{
3440
}
3541

36-
explicit nondet_instruction_infot(is_nullablet is_nullable):
37-
is_nondet(is_nondett::TRUE),
38-
is_nullable(is_nullable)
42+
explicit nondet_instruction_infot(is_nullablet is_nullable)
43+
: is_nondet(is_nondett::TRUE), is_nullable(is_nullable)
3944
{
4045
}
4146

42-
is_nondett get_instruction_type() const { return is_nondet; }
43-
is_nullablet get_nullable_type() const { return is_nullable; }
47+
is_nondett get_instruction_type() const
48+
{
49+
return is_nondet;
50+
}
51+
is_nullablet get_nullable_type() const
52+
{
53+
return is_nullable;
54+
}
4455

4556
private:
4657
is_nondett is_nondet;
@@ -52,11 +63,11 @@ class nondet_instruction_infot final
5263
/// \return A structure detailing whether the function call appears to be one of
5364
/// our nondet library methods, and if so, whether or not it allows null
5465
/// results.
55-
static nondet_instruction_infot is_nondet_returning_object(
56-
const code_function_callt &function_call)
66+
static nondet_instruction_infot
67+
is_nondet_returning_object(const code_function_callt &function_call)
5768
{
58-
const auto &function_symbol=to_symbol_expr(function_call.function());
59-
const auto function_name=id2string(function_symbol.get_identifier());
69+
const auto &function_symbol = to_symbol_expr(function_call.function());
70+
const auto function_name = id2string(function_symbol.get_identifier());
6071
const std::regex reg(
6172
R"(.*org\.cprover\.CProver\.nondet)"
6273
R"((?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))");
@@ -74,51 +85,51 @@ static nondet_instruction_infot is_nondet_returning_object(
7485
/// recognised nondet library methods, and return some information about it.
7586
/// \param instr: A goto-program instruction to check.
7687
/// \return A structure detailing the properties of the nondet method.
77-
static nondet_instruction_infot get_nondet_instruction_info(
78-
const goto_programt::const_targett &instr)
88+
static nondet_instruction_infot
89+
get_nondet_instruction_info(const goto_programt::const_targett &instr)
7990
{
80-
if(!(instr->is_function_call() && instr->code.id()==ID_code))
91+
if(!(instr->is_function_call() && instr->code.id() == ID_code))
8192
{
8293
return nondet_instruction_infot();
8394
}
84-
const auto &code=to_code(instr->code);
85-
if(code.get_statement()!=ID_function_call)
95+
const auto &code = to_code(instr->code);
96+
if(code.get_statement() != ID_function_call)
8697
{
8798
return nondet_instruction_infot();
8899
}
89-
const auto &function_call=to_code_function_call(code);
100+
const auto &function_call = to_code_function_call(code);
90101
return is_nondet_returning_object(function_call);
91102
}
92103

93104
/// Return whether the expression is a symbol with the specified identifier.
94105
/// \param expr: The expression which may be a symbol.
95106
/// \param identifier: Some identifier.
96107
/// \return True if the expression is a symbol with the specified identifier.
97-
static bool is_symbol_with_id(const exprt& expr, const irep_idt& identifier)
108+
static bool is_symbol_with_id(const exprt &expr, const irep_idt &identifier)
98109
{
99-
return expr.id()==ID_symbol &&
100-
to_symbol_expr(expr).get_identifier()==identifier;
110+
return expr.id() == ID_symbol &&
111+
to_symbol_expr(expr).get_identifier() == identifier;
101112
}
102113

103114
/// Return whether the expression is a typecast with the specified identifier.
104115
/// \param expr: The expression which may be a typecast.
105116
/// \param identifier: Some identifier.
106117
/// \return True if the expression is a typecast with one operand, and the
107118
/// typecast's identifier matches the specified identifier.
108-
static bool is_typecast_with_id(const exprt& expr, const irep_idt& identifier)
119+
static bool is_typecast_with_id(const exprt &expr, const irep_idt &identifier)
109120
{
110-
if(!(expr.id()==ID_typecast && expr.operands().size()==1))
121+
if(!(expr.id() == ID_typecast && expr.operands().size() == 1))
111122
{
112123
return false;
113124
}
114-
const auto &typecast=to_typecast_expr(expr);
115-
if(!(typecast.op().id()==ID_symbol && !typecast.op().has_operands()))
125+
const auto &typecast = to_typecast_expr(expr);
126+
if(!(typecast.op().id() == ID_symbol && !typecast.op().has_operands()))
116127
{
117128
return false;
118129
}
119-
const auto &op_symbol=to_symbol_expr(typecast.op());
130+
const auto &op_symbol = to_symbol_expr(typecast.op());
120131
// Return whether the typecast has the expected operand
121-
return op_symbol.get_identifier()==identifier;
132+
return op_symbol.get_identifier() == identifier;
122133
}
123134

124135
/// Return whether the instruction is an assignment, and the rhs is a symbol or
@@ -136,7 +147,7 @@ static bool is_assignment_from(
136147
{
137148
return false;
138149
}
139-
const auto &rhs=to_code_assign(instr.code).rhs();
150+
const auto &rhs = to_code_assign(instr.code).rhs();
140151
return is_symbol_with_id(rhs, identifier) ||
141152
is_typecast_with_id(rhs, identifier);
142153
}
@@ -165,10 +176,11 @@ static goto_programt::targett check_and_replace_target(
165176
const goto_programt::targett &target)
166177
{
167178
// Check whether this is a nondet library method, and return if not
168-
const auto instr_info=get_nondet_instruction_info(target);
169-
const auto next_instr=std::next(target);
170-
if(instr_info.get_instruction_type()==
171-
nondet_instruction_infot::is_nondett::FALSE)
179+
const auto instr_info = get_nondet_instruction_info(target);
180+
const auto next_instr = std::next(target);
181+
if(
182+
instr_info.get_instruction_type() ==
183+
nondet_instruction_infot::is_nondett::FALSE)
172184
{
173185
return next_instr;
174186
}
@@ -227,8 +239,8 @@ static goto_programt::targett check_and_replace_target(
227239

228240
// Assume that the LHS of *this* assignment is the actual nondet variable
229241
const auto &code_assign = to_code_assign(assignment_instruction->code);
230-
const auto nondet_var=code_assign.lhs();
231-
const auto source_loc=target->source_location;
242+
const auto nondet_var = code_assign.lhs();
243+
const auto source_loc = target->source_location;
232244

233245
// Erase from the nondet function call to the assignment
234246
const auto after_matching_assignment = std::next(assignment_instruction);
@@ -239,20 +251,19 @@ static goto_programt::targett check_and_replace_target(
239251
std::for_each(
240252
target,
241253
after_matching_assignment,
242-
[](goto_programt::instructiont &instr)
243-
{
254+
[](goto_programt::instructiont &instr) { // NOLINT (*)
244255
instr.make_skip();
245256
});
246257

247-
const auto inserted=goto_program.insert_before(after_matching_assignment);
258+
const auto inserted = goto_program.insert_before(after_matching_assignment);
248259
inserted->make_assignment();
249260
side_effect_expr_nondett inserted_expr(nondet_var.type());
250261
inserted_expr.set_nullable(
251-
instr_info.get_nullable_type()==
262+
instr_info.get_nullable_type() ==
252263
nondet_instruction_infot::is_nullablet::TRUE);
253-
inserted->code=code_assignt(nondet_var, inserted_expr);
254-
inserted->code.add_source_location()=source_loc;
255-
inserted->source_location=source_loc;
264+
inserted->code = code_assignt(nondet_var, inserted_expr);
265+
inserted->code.add_source_location() = source_loc;
266+
inserted->source_location = source_loc;
256267

257268
goto_program.update();
258269

@@ -265,13 +276,12 @@ static goto_programt::targett check_and_replace_target(
265276
/// \param goto_program: The goto program to modify.
266277
static void replace_java_nondet(goto_programt &goto_program)
267278
{
268-
for(auto instruction_iterator=goto_program.instructions.begin(),
269-
end=goto_program.instructions.end();
270-
instruction_iterator!=end;)
279+
for(auto instruction_iterator = goto_program.instructions.begin(),
280+
end = goto_program.instructions.end();
281+
instruction_iterator != end;)
271282
{
272-
instruction_iterator=check_and_replace_target(
273-
goto_program,
274-
instruction_iterator);
283+
instruction_iterator =
284+
check_and_replace_target(goto_program, instruction_iterator);
275285
}
276286
}
277287

src/goto-programs/replace_java_nondet.h renamed to src/java_bytecode/replace_java_nondet.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Author: Reuben Thomas, [email protected]
99
/// \file
1010
/// Replace Java Nondet expressions
1111

12-
#ifndef CPROVER_GOTO_PROGRAMS_REPLACE_JAVA_NONDET_H
13-
#define CPROVER_GOTO_PROGRAMS_REPLACE_JAVA_NONDET_H
12+
#ifndef CPROVER_JAVA_BYTECODE_REPLACE_JAVA_NONDET_H
13+
#define CPROVER_JAVA_BYTECODE_REPLACE_JAVA_NONDET_H
1414

1515
class goto_modelt;
1616
class goto_functionst;

src/jbmc/jbmc_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Author: Daniel Kroening, [email protected]
3636
#include <goto-programs/remove_asm.h>
3737
#include <goto-programs/remove_unused_functions.h>
3838
#include <goto-programs/remove_skip.h>
39-
#include <goto-programs/replace_java_nondet.h>
4039
#include <goto-programs/set_properties.h>
4140
#include <goto-programs/show_goto_functions.h>
4241
#include <goto-programs/show_symbol_table.h>
@@ -56,6 +55,7 @@ Author: Daniel Kroening, [email protected]
5655
#include <java_bytecode/java_enum_static_init_unwind_handler.h>
5756
#include <java_bytecode/remove_instanceof.h>
5857
#include <java_bytecode/remove_exceptions.h>
58+
#include <java_bytecode/replace_java_nondet.h>
5959

6060
#include <cbmc/version.h>
6161

unit/java_bytecode/java_replace_nondet/replace_nondet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <goto-programs/goto_convert_functions.h>
1414
#include <goto-programs/remove_virtual_functions.h>
1515
#include <goto-programs/remove_returns.h>
16-
#include <goto-programs/replace_java_nondet.h>
1716

1817
#include <java_bytecode/remove_instanceof.h>
18+
#include <java_bytecode/replace_java_nondet.h>
1919

2020
#include <util/config.h>
2121
#include <util/options.h>

0 commit comments

Comments
 (0)