Skip to content

Commit b55abc3

Browse files
Clang-format moved file
1 parent 42f8dcf commit b55abc3

File tree

1 file changed

+62
-52
lines changed

1 file changed

+62
-52
lines changed

src/java_bytecode/replace_java_nondet.cpp

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,35 @@ Author: Reuben Thomas, [email protected]
2525
class nondet_instruction_infot final
2626
{
2727
public:
28-
enum class is_nondett:bool { FALSE, TRUE };
29-
enum class is_nullablet:bool { FALSE, TRUE };
28+
enum class is_nondett : bool
29+
{
30+
FALSE,
31+
TRUE
32+
};
33+
enum class is_nullablet : bool
34+
{
35+
FALSE,
36+
TRUE
37+
};
3038

31-
nondet_instruction_infot():
32-
is_nondet(is_nondett::FALSE),
33-
is_nullable(is_nullablet::FALSE)
39+
nondet_instruction_infot()
40+
: is_nondet(is_nondett::FALSE), is_nullable(is_nullablet::FALSE)
3441
{
3542
}
3643

37-
explicit nondet_instruction_infot(is_nullablet is_nullable):
38-
is_nondet(is_nondett::TRUE),
39-
is_nullable(is_nullable)
44+
explicit nondet_instruction_infot(is_nullablet is_nullable)
45+
: is_nondet(is_nondett::TRUE), is_nullable(is_nullable)
4046
{
4147
}
4248

43-
is_nondett get_instruction_type() const { return is_nondet; }
44-
is_nullablet get_nullable_type() const { return is_nullable; }
49+
is_nondett get_instruction_type() const
50+
{
51+
return is_nondet;
52+
}
53+
is_nullablet get_nullable_type() const
54+
{
55+
return is_nullable;
56+
}
4557

4658
private:
4759
is_nondett is_nondet;
@@ -53,11 +65,11 @@ class nondet_instruction_infot final
5365
/// \return A structure detailing whether the function call appears to be one of
5466
/// our nondet library methods, and if so, whether or not it allows null
5567
/// results.
56-
static nondet_instruction_infot is_nondet_returning_object(
57-
const code_function_callt &function_call)
68+
static nondet_instruction_infot
69+
is_nondet_returning_object(const code_function_callt &function_call)
5870
{
59-
const auto &function_symbol=to_symbol_expr(function_call.function());
60-
const auto function_name=id2string(function_symbol.get_identifier());
71+
const auto &function_symbol = to_symbol_expr(function_call.function());
72+
const auto function_name = id2string(function_symbol.get_identifier());
6173
const std::regex reg(
6274
R"(.*org\.cprover\.CProver\.nondet)"
6375
R"((?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))");
@@ -75,51 +87,51 @@ static nondet_instruction_infot is_nondet_returning_object(
7587
/// recognised nondet library methods, and return some information about it.
7688
/// \param instr: A goto-program instruction to check.
7789
/// \return A structure detailing the properties of the nondet method.
78-
static nondet_instruction_infot get_nondet_instruction_info(
79-
const goto_programt::const_targett &instr)
90+
static nondet_instruction_infot
91+
get_nondet_instruction_info(const goto_programt::const_targett &instr)
8092
{
81-
if(!(instr->is_function_call() && instr->code.id()==ID_code))
93+
if(!(instr->is_function_call() && instr->code.id() == ID_code))
8294
{
8395
return nondet_instruction_infot();
8496
}
85-
const auto &code=to_code(instr->code);
86-
if(code.get_statement()!=ID_function_call)
97+
const auto &code = to_code(instr->code);
98+
if(code.get_statement() != ID_function_call)
8799
{
88100
return nondet_instruction_infot();
89101
}
90-
const auto &function_call=to_code_function_call(code);
102+
const auto &function_call = to_code_function_call(code);
91103
return is_nondet_returning_object(function_call);
92104
}
93105

94106
/// Return whether the expression is a symbol with the specified identifier.
95107
/// \param expr: The expression which may be a symbol.
96108
/// \param identifier: Some identifier.
97109
/// \return True if the expression is a symbol with the specified identifier.
98-
static bool is_symbol_with_id(const exprt& expr, const irep_idt& identifier)
110+
static bool is_symbol_with_id(const exprt &expr, const irep_idt &identifier)
99111
{
100-
return expr.id()==ID_symbol &&
101-
to_symbol_expr(expr).get_identifier()==identifier;
112+
return expr.id() == ID_symbol &&
113+
to_symbol_expr(expr).get_identifier() == identifier;
102114
}
103115

104116
/// Return whether the expression is a typecast with the specified identifier.
105117
/// \param expr: The expression which may be a typecast.
106118
/// \param identifier: Some identifier.
107119
/// \return True if the expression is a typecast with one operand, and the
108120
/// typecast's identifier matches the specified identifier.
109-
static bool is_typecast_with_id(const exprt& expr, const irep_idt& identifier)
121+
static bool is_typecast_with_id(const exprt &expr, const irep_idt &identifier)
110122
{
111-
if(!(expr.id()==ID_typecast && expr.operands().size()==1))
123+
if(!(expr.id() == ID_typecast && expr.operands().size() == 1))
112124
{
113125
return false;
114126
}
115-
const auto &typecast=to_typecast_expr(expr);
116-
if(!(typecast.op().id()==ID_symbol && !typecast.op().has_operands()))
127+
const auto &typecast = to_typecast_expr(expr);
128+
if(!(typecast.op().id() == ID_symbol && !typecast.op().has_operands()))
117129
{
118130
return false;
119131
}
120-
const auto &op_symbol=to_symbol_expr(typecast.op());
132+
const auto &op_symbol = to_symbol_expr(typecast.op());
121133
// Return whether the typecast has the expected operand
122-
return op_symbol.get_identifier()==identifier;
134+
return op_symbol.get_identifier() == identifier;
123135
}
124136

125137
/// Return whether the instruction is an assignment, and the rhs is a symbol or
@@ -137,7 +149,7 @@ static bool is_assignment_from(
137149
{
138150
return false;
139151
}
140-
const auto &rhs=to_code_assign(instr.code).rhs();
152+
const auto &rhs = to_code_assign(instr.code).rhs();
141153
return is_symbol_with_id(rhs, identifier) ||
142154
is_typecast_with_id(rhs, identifier);
143155
}
@@ -166,10 +178,11 @@ static goto_programt::targett check_and_replace_target(
166178
const goto_programt::targett &target)
167179
{
168180
// Check whether this is a nondet library method, and return if not
169-
const auto instr_info=get_nondet_instruction_info(target);
170-
const auto next_instr=std::next(target);
171-
if(instr_info.get_instruction_type()==
172-
nondet_instruction_infot::is_nondett::FALSE)
181+
const auto instr_info = get_nondet_instruction_info(target);
182+
const auto next_instr = std::next(target);
183+
if(
184+
instr_info.get_instruction_type() ==
185+
nondet_instruction_infot::is_nondett::FALSE)
173186
{
174187
return next_instr;
175188
}
@@ -199,9 +212,8 @@ static goto_programt::targett check_and_replace_target(
199212
to_code_assign(next_instr->code).lhs();
200213

201214
// If the assignment is null, return.
202-
if(
203-
!(return_value_assignment.id() == ID_symbol &&
204-
!return_value_assignment.has_operands()))
215+
if(!(return_value_assignment.id() == ID_symbol &&
216+
!return_value_assignment.has_operands()))
205217
{
206218
return next_instr;
207219
}
@@ -228,8 +240,8 @@ static goto_programt::targett check_and_replace_target(
228240

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

234246
// Erase from the nondet function call to the assignment
235247
const auto after_matching_assignment = std::next(assignment_instruction);
@@ -240,20 +252,19 @@ static goto_programt::targett check_and_replace_target(
240252
std::for_each(
241253
target,
242254
after_matching_assignment,
243-
[](goto_programt::instructiont &instr)
244-
{
255+
[](goto_programt::instructiont &instr) { // NOLINT (*)
245256
instr.make_skip();
246257
});
247258

248-
const auto inserted=goto_program.insert_before(after_matching_assignment);
259+
const auto inserted = goto_program.insert_before(after_matching_assignment);
249260
inserted->make_assignment();
250261
side_effect_expr_nondett inserted_expr(nondet_var.type());
251262
inserted_expr.set_nullable(
252-
instr_info.get_nullable_type()==
263+
instr_info.get_nullable_type() ==
253264
nondet_instruction_infot::is_nullablet::TRUE);
254-
inserted->code=code_assignt(nondet_var, inserted_expr);
255-
inserted->code.add_source_location()=source_loc;
256-
inserted->source_location=source_loc;
265+
inserted->code = code_assignt(nondet_var, inserted_expr);
266+
inserted->code.add_source_location() = source_loc;
267+
inserted->source_location = source_loc;
257268

258269
goto_program.update();
259270

@@ -266,13 +277,12 @@ static goto_programt::targett check_and_replace_target(
266277
/// \param goto_program: The goto program to modify.
267278
static void replace_java_nondet(goto_programt &goto_program)
268279
{
269-
for(auto instruction_iterator=goto_program.instructions.begin(),
270-
end=goto_program.instructions.end();
271-
instruction_iterator!=end;)
280+
for(auto instruction_iterator = goto_program.instructions.begin(),
281+
end = goto_program.instructions.end();
282+
instruction_iterator != end;)
272283
{
273-
instruction_iterator=check_and_replace_target(
274-
goto_program,
275-
instruction_iterator);
284+
instruction_iterator =
285+
check_and_replace_target(goto_program, instruction_iterator);
276286
}
277287
}
278288

0 commit comments

Comments
 (0)