Skip to content

Commit a079f46

Browse files
Clang-format moved file
1 parent 2eb3714 commit a079f46

File tree

1 file changed

+60
-49
lines changed

1 file changed

+60
-49
lines changed

src/java_bytecode/replace_java_nondet.cpp

+60-49
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,35 @@ Author: Reuben Thomas, [email protected]
2323
class nondet_instruction_infot final
2424
{
2525
public:
26-
enum class is_nondett:bool { FALSE, TRUE };
27-
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+
};
2836

29-
nondet_instruction_infot():
30-
is_nondet(is_nondett::FALSE),
31-
is_nullable(is_nullablet::FALSE)
37+
nondet_instruction_infot()
38+
: is_nondet(is_nondett::FALSE), is_nullable(is_nullablet::FALSE)
3239
{
3340
}
3441

35-
explicit nondet_instruction_infot(is_nullablet is_nullable):
36-
is_nondet(is_nondett::TRUE),
37-
is_nullable(is_nullable)
42+
explicit nondet_instruction_infot(is_nullablet is_nullable)
43+
: is_nondet(is_nondett::TRUE), is_nullable(is_nullable)
3844
{
3945
}
4046

41-
is_nondett get_instruction_type() const { return is_nondet; }
42-
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+
}
4355

4456
private:
4557
is_nondett is_nondet;
@@ -51,11 +63,11 @@ class nondet_instruction_infot final
5163
/// \return A structure detailing whether the function call appears to be one of
5264
/// our nondet library methods, and if so, whether or not it allows null
5365
/// results.
54-
static nondet_instruction_infot is_nondet_returning_object(
55-
const code_function_callt &function_call)
66+
static nondet_instruction_infot
67+
is_nondet_returning_object(const code_function_callt &function_call)
5668
{
57-
const auto &function_symbol=to_symbol_expr(function_call.function());
58-
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());
5971
const std::regex reg(
6072
R"(.*org\.cprover\.CProver\.nondet)"
6173
R"((?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))");
@@ -73,51 +85,51 @@ static nondet_instruction_infot is_nondet_returning_object(
7385
/// recognised nondet library methods, and return some information about it.
7486
/// \param instr: A goto-program instruction to check.
7587
/// \return A structure detailing the properties of the nondet method.
76-
static nondet_instruction_infot get_nondet_instruction_info(
77-
const goto_programt::const_targett &instr)
88+
static nondet_instruction_infot
89+
get_nondet_instruction_info(const goto_programt::const_targett &instr)
7890
{
79-
if(!(instr->is_function_call() && instr->code.id()==ID_code))
91+
if(!(instr->is_function_call() && instr->code.id() == ID_code))
8092
{
8193
return nondet_instruction_infot();
8294
}
83-
const auto &code=to_code(instr->code);
84-
if(code.get_statement()!=ID_function_call)
95+
const auto &code = to_code(instr->code);
96+
if(code.get_statement() != ID_function_call)
8597
{
8698
return nondet_instruction_infot();
8799
}
88-
const auto &function_call=to_code_function_call(code);
100+
const auto &function_call = to_code_function_call(code);
89101
return is_nondet_returning_object(function_call);
90102
}
91103

92104
/// Return whether the expression is a symbol with the specified identifier.
93105
/// \param expr: The expression which may be a symbol.
94106
/// \param identifier: Some identifier.
95107
/// \return True if the expression is a symbol with the specified identifier.
96-
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)
97109
{
98-
return expr.id()==ID_symbol &&
99-
to_symbol_expr(expr).get_identifier()==identifier;
110+
return expr.id() == ID_symbol &&
111+
to_symbol_expr(expr).get_identifier() == identifier;
100112
}
101113

102114
/// Return whether the expression is a typecast with the specified identifier.
103115
/// \param expr: The expression which may be a typecast.
104116
/// \param identifier: Some identifier.
105117
/// \return True if the expression is a typecast with one operand, and the
106118
/// typecast's identifier matches the specified identifier.
107-
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)
108120
{
109-
if(!(expr.id()==ID_typecast && expr.operands().size()==1))
121+
if(!(expr.id() == ID_typecast && expr.operands().size() == 1))
110122
{
111123
return false;
112124
}
113-
const auto &typecast=to_typecast_expr(expr);
114-
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()))
115127
{
116128
return false;
117129
}
118-
const auto &op_symbol=to_symbol_expr(typecast.op());
130+
const auto &op_symbol = to_symbol_expr(typecast.op());
119131
// Return whether the typecast has the expected operand
120-
return op_symbol.get_identifier()==identifier;
132+
return op_symbol.get_identifier() == identifier;
121133
}
122134

123135
/// Return whether the instruction is an assignment, and the rhs is a symbol or
@@ -135,7 +147,7 @@ static bool is_assignment_from(
135147
{
136148
return false;
137149
}
138-
const auto &rhs=to_code_assign(instr.code).rhs();
150+
const auto &rhs = to_code_assign(instr.code).rhs();
139151
return is_symbol_with_id(rhs, identifier) ||
140152
is_typecast_with_id(rhs, identifier);
141153
}
@@ -164,10 +176,11 @@ static goto_programt::targett check_and_replace_target(
164176
const goto_programt::targett &target)
165177
{
166178
// Check whether this is a nondet library method, and return if not
167-
const auto instr_info=get_nondet_instruction_info(target);
168-
const auto next_instr=std::next(target);
169-
if(instr_info.get_instruction_type()==
170-
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)
171184
{
172185
return next_instr;
173186
}
@@ -226,8 +239,8 @@ static goto_programt::targett check_and_replace_target(
226239

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

232245
// Erase from the nondet function call to the assignment
233246
const auto after_matching_assignment = std::next(assignment_instruction);
@@ -238,20 +251,19 @@ static goto_programt::targett check_and_replace_target(
238251
std::for_each(
239252
target,
240253
after_matching_assignment,
241-
[](goto_programt::instructiont &instr)
242-
{
254+
[](goto_programt::instructiont &instr) { // NOLINT (*)
243255
instr.make_skip();
244256
});
245257

246-
const auto inserted=goto_program.insert_before(after_matching_assignment);
258+
const auto inserted = goto_program.insert_before(after_matching_assignment);
247259
inserted->make_assignment();
248260
side_effect_expr_nondett inserted_expr(nondet_var.type());
249261
inserted_expr.set_nullable(
250-
instr_info.get_nullable_type()==
262+
instr_info.get_nullable_type() ==
251263
nondet_instruction_infot::is_nullablet::TRUE);
252-
inserted->code=code_assignt(nondet_var, inserted_expr);
253-
inserted->code.add_source_location()=source_loc;
254-
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;
255267

256268
goto_program.update();
257269

@@ -264,13 +276,12 @@ static goto_programt::targett check_and_replace_target(
264276
/// \param goto_program: The goto program to modify.
265277
static void replace_java_nondet(goto_programt &goto_program)
266278
{
267-
for(auto instruction_iterator=goto_program.instructions.begin(),
268-
end=goto_program.instructions.end();
269-
instruction_iterator!=end;)
279+
for(auto instruction_iterator = goto_program.instructions.begin(),
280+
end = goto_program.instructions.end();
281+
instruction_iterator != end;)
270282
{
271-
instruction_iterator=check_and_replace_target(
272-
goto_program,
273-
instruction_iterator);
283+
instruction_iterator =
284+
check_and_replace_target(goto_program, instruction_iterator);
274285
}
275286
}
276287

0 commit comments

Comments
 (0)