Skip to content

Commit e8491a6

Browse files
Factoring assign_java_string_to_string_expr with process_operands
These were doing mostly the same thing. Renamd function convert_exprt_to_string_exprt: This describes more precisely what the function does.
1 parent 51e493e commit e8491a6

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -287,32 +287,27 @@ exprt::operandst java_string_library_preprocesst::process_parameters(
287287
return process_operands(ops, loc, symbol_table, init_code);
288288
}
289289

290-
/// Creates a string_exprt from the input exprt and adds it to processed_ops
291-
/// \param processed_ops: the list of processed operands to populate
292-
/// \param op_to_process: a list of expressions
290+
/// Creates a string_exprt from the input exprt representing a char sequence
291+
/// \param op_to_process: an operand of a type which implements char sequence
293292
/// \param loc: location in the source
294293
/// \param symbol_table: symbol table
295294
/// \param init_code: code block, in which declaration of some arguments may be
296295
/// added
297-
void java_string_library_preprocesst::process_single_operand(
298-
exprt::operandst &processed_ops,
296+
/// \return the processed operand
297+
exprt java_string_library_preprocesst::convert_exprt_to_string_exprt(
299298
const exprt &op_to_process,
300299
const source_locationt &loc,
301300
symbol_tablet &symbol_table,
302301
code_blockt &init_code)
303302
{
304-
member_exprt length(
305-
op_to_process, "length", string_length_type());
306-
member_exprt data(op_to_process, "data", string_data_type(symbol_table));
307-
dereference_exprt deref_data(data, data.type().subtype());
303+
PRECONDITION(implements_java_char_sequence(op_to_process.type()));
308304
string_exprt string_expr=fresh_string_expr(loc, symbol_table, init_code);
305+
init_code.add(code_assign_java_string_to_string_expr(
306+
string_expr, op_to_process, symbol_table));
309307
exprt string_expr_sym=fresh_string_expr_symbol(loc, symbol_table, init_code);
310308
init_code.add(code_declt(string_expr_sym));
311-
init_code.add(code_assignt(string_expr.length(), length));
312-
init_code.add(
313-
code_assignt(string_expr.content(), deref_data));
314309
init_code.add(code_assignt(string_expr_sym, string_expr));
315-
processed_ops.push_back(string_expr);
310+
return string_expr;
316311
}
317312

318313
/// for each expression that is of a type implementing strings, we declare a new
@@ -336,19 +331,12 @@ exprt::operandst java_string_library_preprocesst::process_operands(
336331
for(const auto &p : operands)
337332
{
338333
if(implements_java_char_sequence(p.type()))
339-
{
340-
dereference_exprt deref=
341-
checked_dereference(p, to_pointer_type(p.type()).subtype());
342-
process_single_operand(ops, deref, loc, symbol_table, init_code);
343-
}
334+
ops.push_back(
335+
convert_exprt_to_string_exprt(p, loc, symbol_table, init_code));
344336
else if(is_java_char_array_pointer_type(p.type()))
345-
{
346337
ops.push_back(replace_char_array(p, loc, symbol_table, init_code));
347-
}
348338
else
349-
{
350339
ops.push_back(p);
351-
}
352340
}
353341
return ops;
354342
}
@@ -370,22 +358,19 @@ exprt::operandst
370358
code_blockt &init_code)
371359
{
372360
PRECONDITION(operands.size()==2);
373-
exprt::operandst ops;
374361
const exprt &op0=operands[0];
375-
const exprt &op1=operands[1];
376362
PRECONDITION(implements_java_char_sequence(op0.type()));
377363

378-
dereference_exprt deref0=
379-
checked_dereference(op0, to_pointer_type(op0.type()).subtype());
380-
process_single_operand(ops, deref0, loc, symbol_table, init_code);
364+
exprt::operandst ops;
365+
ops.push_back(
366+
convert_exprt_to_string_exprt(op0, loc, symbol_table, init_code));
381367

382368
// TODO: Manage the case where we have a non-String Object (this should
383369
// probably be handled upstream. At any rate, the following code should be
384370
// protected with assertions on the type of op1.
385-
typecast_exprt tcast(op1, to_pointer_type(op0.type()));
386-
dereference_exprt deref1=
387-
checked_dereference(tcast, to_pointer_type(op0.type()).subtype());
388-
process_single_operand(ops, deref1, loc, symbol_table, init_code);
371+
typecast_exprt tcast(operands[1], to_pointer_type(op0.type()));
372+
ops.push_back(
373+
convert_exprt_to_string_exprt(tcast, loc, symbol_table, init_code));
389374
return ops;
390375
}
391376

src/java_bytecode/java_string_library_preprocess.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ class java_string_library_preprocesst:public messaget
173173
symbol_tablet &symbol_table,
174174
code_blockt &init_code);
175175

176-
void process_single_operand(
177-
exprt::operandst &processed_ops,
176+
exprt convert_exprt_to_string_exprt(
178177
const exprt &deref,
179178
const source_locationt &loc,
180179
symbol_tablet &symbol_table,

0 commit comments

Comments
 (0)