|
17 | 17 |
|
18 | 18 | #include <util/as_const.h> |
19 | 19 | #include <util/base_exceptions.h> |
| 20 | +#include <util/byte_operators.h> |
20 | 21 | #include <util/exception_utils.h> |
21 | 22 | #include <util/expr_util.h> |
22 | 23 | #include <util/format.h> |
@@ -340,6 +341,73 @@ goto_symex_statet::rename(exprt expr, const namespacet &ns) |
340 | 341 | } |
341 | 342 | } |
342 | 343 |
|
| 344 | +exprt goto_symex_statet::l2_rename_rvalues(exprt lvalue, const namespacet &ns) |
| 345 | +{ |
| 346 | + rename(lvalue.type(), irep_idt(), ns); |
| 347 | + |
| 348 | + if(lvalue.id() == ID_symbol) |
| 349 | + { |
| 350 | + // Nothing to do |
| 351 | + } |
| 352 | + else if(is_read_only_object(lvalue)) |
| 353 | + { |
| 354 | + // Ignore apparent writes to 'NULL-object' and similar read-only objects |
| 355 | + } |
| 356 | + else if(lvalue.id() == ID_typecast) |
| 357 | + { |
| 358 | + auto &typecast_lvalue = to_typecast_expr(lvalue); |
| 359 | + typecast_lvalue.op() = l2_rename_rvalues(typecast_lvalue.op(), ns); |
| 360 | + } |
| 361 | + else if(lvalue.id() == ID_member) |
| 362 | + { |
| 363 | + auto &member_lvalue = to_member_expr(lvalue); |
| 364 | + member_lvalue.compound() = l2_rename_rvalues(member_lvalue.compound(), ns); |
| 365 | + } |
| 366 | + else if(lvalue.id() == ID_index) |
| 367 | + { |
| 368 | + // The index is an rvalue: |
| 369 | + auto &index_lvalue = to_index_expr(lvalue); |
| 370 | + index_lvalue.array() = l2_rename_rvalues(index_lvalue.array(), ns); |
| 371 | + index_lvalue.index() = rename(index_lvalue.index(), ns).get(); |
| 372 | + } |
| 373 | + else if( |
| 374 | + lvalue.id() == ID_byte_extract_little_endian || |
| 375 | + lvalue.id() == ID_byte_extract_big_endian) |
| 376 | + { |
| 377 | + // The offset is an rvalue: |
| 378 | + auto &byte_extract_lvalue = to_byte_extract_expr(lvalue); |
| 379 | + byte_extract_lvalue.op() = l2_rename_rvalues(byte_extract_lvalue.op(), ns); |
| 380 | + byte_extract_lvalue.offset() = rename(byte_extract_lvalue.offset(), ns); |
| 381 | + } |
| 382 | + else if(lvalue.id() == ID_if) |
| 383 | + { |
| 384 | + // The condition is an rvalue: |
| 385 | + auto &if_lvalue = to_if_expr(lvalue); |
| 386 | + if_lvalue.cond() = rename(if_lvalue.cond(), ns); |
| 387 | + if(!if_lvalue.cond().is_false()) |
| 388 | + if_lvalue.true_case() = l2_rename_rvalues(if_lvalue.true_case(), ns); |
| 389 | + if(!if_lvalue.cond().is_true()) |
| 390 | + if_lvalue.false_case() = l2_rename_rvalues(if_lvalue.false_case(), ns); |
| 391 | + } |
| 392 | + else if(lvalue.id() == ID_complex_real) |
| 393 | + { |
| 394 | + auto &complex_real_lvalue = to_complex_real_expr(lvalue); |
| 395 | + complex_real_lvalue.op() = l2_rename_rvalues(complex_real_lvalue.op(), ns); |
| 396 | + } |
| 397 | + else if(lvalue.id() == ID_complex_imag) |
| 398 | + { |
| 399 | + auto &complex_imag_lvalue = to_complex_imag_expr(lvalue); |
| 400 | + complex_imag_lvalue.op() = l2_rename_rvalues(complex_imag_lvalue.op(), ns); |
| 401 | + } |
| 402 | + else |
| 403 | + { |
| 404 | + throw unsupported_operation_exceptiont( |
| 405 | + "l2_rename_rvalues case `" + lvalue.id_string() + "' not handled"); |
| 406 | + } |
| 407 | + |
| 408 | + return lvalue; |
| 409 | +} |
| 410 | + |
343 | 411 | template renamedt<exprt, L1> |
344 | 412 | goto_symex_statet::rename<L1>(exprt expr, const namespacet &ns); |
345 | 413 |
|
|
0 commit comments