@@ -287,32 +287,27 @@ exprt::operandst java_string_library_preprocesst::process_parameters(
287
287
return process_operands (ops, loc, symbol_table, init_code);
288
288
}
289
289
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
293
292
// / \param loc: location in the source
294
293
// / \param symbol_table: symbol table
295
294
// / \param init_code: code block, in which declaration of some arguments may be
296
295
// / 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 (
299
298
const exprt &op_to_process,
300
299
const source_locationt &loc,
301
300
symbol_tablet &symbol_table,
302
301
code_blockt &init_code)
303
302
{
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 ()));
308
304
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));
309
307
exprt string_expr_sym=fresh_string_expr_symbol (loc, symbol_table, init_code);
310
308
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));
314
309
init_code.add (code_assignt (string_expr_sym, string_expr));
315
- processed_ops. push_back ( string_expr) ;
310
+ return string_expr;
316
311
}
317
312
318
313
// / 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(
336
331
for (const auto &p : operands)
337
332
{
338
333
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));
344
336
else if (is_java_char_array_pointer_type (p.type ()))
345
- {
346
337
ops.push_back (replace_char_array (p, loc, symbol_table, init_code));
347
- }
348
338
else
349
- {
350
339
ops.push_back (p);
351
- }
352
340
}
353
341
return ops;
354
342
}
@@ -370,22 +358,19 @@ exprt::operandst
370
358
code_blockt &init_code)
371
359
{
372
360
PRECONDITION (operands.size ()==2 );
373
- exprt::operandst ops;
374
361
const exprt &op0=operands[0 ];
375
- const exprt &op1=operands[1 ];
376
362
PRECONDITION (implements_java_char_sequence (op0.type ()));
377
363
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) );
381
367
382
368
// TODO: Manage the case where we have a non-String Object (this should
383
369
// probably be handled upstream. At any rate, the following code should be
384
370
// 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));
389
374
return ops;
390
375
}
391
376
0 commit comments