@@ -31,26 +31,19 @@ constexpr bool use_update()
3131#endif
3232}
3333
34- // / Store the \p what expression by recursively descending into the operands
35- // / of \p lhs until the first operand \c op0 is _nil_: this _nil_ operand
36- // / is then replaced with \p what.
37- // / \param lhs: Non-symbol pointed-to expression
38- // / \param what: The expression to be added to the \p lhs
39- // / \return The resulting expression
40- static exprt add_to_lhs (const exprt &lhs, const exprt &what)
34+ expr_skeletont expr_skeletont::remove_op0 (exprt e)
4135{
42- PRECONDITION (lhs.id () != ID_symbol);
43- exprt tmp_what=what;
44-
45- if (tmp_what.id ()!=ID_symbol)
46- {
47- PRECONDITION (tmp_what.operands ().size () >= 1 );
48- tmp_what.op0 ().make_nil ();
49- }
50-
51- exprt new_lhs=lhs;
36+ PRECONDITION (e.id () != ID_symbol);
37+ PRECONDITION (e.operands ().size () >= 1 );
38+ e.op0 ().make_nil ();
39+ return expr_skeletont{std::move (e)};
40+ }
5241
53- exprt *p=&new_lhs;
42+ exprt expr_skeletont::apply (exprt expr) const
43+ {
44+ PRECONDITION (skeleton.id () != ID_symbol);
45+ exprt result = skeleton;
46+ exprt *p = &result;
5447
5548 while (p->is_not_nil ())
5649 {
@@ -60,18 +53,23 @@ static exprt add_to_lhs(const exprt &lhs, const exprt &what)
6053 INVARIANT (
6154 p->operands ().size () >= 1 ,
6255 " expected pointed-to expression to have at least one operand" );
63- p= &p->op0 ();
56+ p = &p->op0 ();
6457 }
6558
6659 INVARIANT (p->is_nil (), " expected pointed-to expression to be nil" );
6760
68- *p=tmp_what;
69- return new_lhs;
61+ *p = std::move (expr);
62+ return result;
63+ }
64+
65+ expr_skeletont expr_skeletont::compose (expr_skeletont other) const
66+ {
67+ return expr_skeletont (apply (other.skeleton ));
7068}
7169
7270void symex_assignt::assign_rec (
7371 const exprt &lhs,
74- const exprt &full_lhs,
72+ const expr_skeletont &full_lhs,
7573 const exprt &rhs,
7674 exprt::operandst &guard)
7775{
@@ -349,7 +347,7 @@ static assignmentt shift_indexed_access_to_lhs(
349347// / \param guard: guard conjuncts that must hold for this assignment to be made
350348void symex_assignt::assign_from_struct (
351349 const ssa_exprt &lhs, // L1
352- const exprt &full_lhs,
350+ const expr_skeletont &full_lhs,
353351 const struct_exprt &rhs,
354352 const exprt::operandst &guard)
355353{
@@ -371,7 +369,7 @@ void symex_assignt::assign_from_struct(
371369
372370void symex_assignt::assign_non_struct_symbol (
373371 const ssa_exprt &lhs, // L1
374- const exprt &full_lhs,
372+ const expr_skeletont &full_lhs,
375373 const exprt &rhs,
376374 const exprt::operandst &guard)
377375{
@@ -409,8 +407,7 @@ void symex_assignt::assign_non_struct_symbol(
409407 .get ();
410408
411409 state.record_events .push (false );
412- const exprt l2_full_lhs =
413- state.rename (add_to_lhs (full_lhs, l2_lhs), ns).get ();
410+ const exprt l2_full_lhs = state.rename (full_lhs.apply (l2_lhs), ns).get ();
414411 state.record_events .pop ();
415412
416413 auto current_assignment_type =
@@ -443,7 +440,7 @@ void symex_assignt::assign_non_struct_symbol(
443440
444441void symex_assignt::assign_symbol (
445442 const ssa_exprt &lhs, // L1
446- const exprt &full_lhs,
443+ const expr_skeletont &full_lhs,
447444 const exprt &rhs,
448445 const exprt::operandst &guard)
449446{
@@ -456,21 +453,21 @@ void symex_assignt::assign_symbol(
456453
457454void symex_assignt::assign_typecast (
458455 const typecast_exprt &lhs,
459- const exprt &full_lhs,
456+ const expr_skeletont &full_lhs,
460457 const exprt &rhs,
461458 exprt::operandst &guard)
462459{
463460 // these may come from dereferencing on the lhs
464461 exprt rhs_typecasted = typecast_exprt::conditional_cast (rhs, lhs.op ().type ());
465-
466- exprt new_full_lhs= add_to_lhs (full_lhs, lhs);
467- assign_rec (lhs.op (), new_full_lhs , rhs_typecasted, guard);
462+ expr_skeletont new_skeleton =
463+ full_lhs. compose ( expr_skeletont::remove_op0 ( lhs) );
464+ assign_rec (lhs.op (), new_skeleton , rhs_typecasted, guard);
468465}
469466
470467template <bool use_update>
471468void symex_assignt::assign_array (
472469 const index_exprt &lhs,
473- const exprt &full_lhs,
470+ const expr_skeletont &full_lhs,
474471 const exprt &rhs,
475472 exprt::operandst &guard)
476473{
@@ -487,8 +484,9 @@ void symex_assignt::assign_array(
487484 // into
488485 // a'==UPDATE(a, [i], e)
489486 const update_exprt new_rhs{lhs_array, index_designatort (lhs_index), rhs};
490- const exprt new_full_lhs = add_to_lhs (full_lhs, lhs);
491- assign_rec (lhs_array, new_full_lhs, new_rhs, guard);
487+ const expr_skeletont new_skeleton =
488+ full_lhs.compose (expr_skeletont::remove_op0 (lhs));
489+ assign_rec (lhs, new_skeleton, new_rhs, guard);
492490 }
493491 else
494492 {
@@ -497,15 +495,16 @@ void symex_assignt::assign_array(
497495 // into
498496 // a'==a WITH [i:=e]
499497 const with_exprt new_rhs{lhs_array, lhs_index, rhs};
500- const exprt new_full_lhs = add_to_lhs (full_lhs, lhs);
501- assign_rec (lhs_array, new_full_lhs, new_rhs, guard);
498+ const expr_skeletont new_skeleton =
499+ full_lhs.compose (expr_skeletont::remove_op0 (lhs));
500+ assign_rec (lhs_array, new_skeleton, new_rhs, guard);
502501 }
503502}
504503
505504template <bool use_update>
506505void symex_assignt::assign_struct_member (
507506 const member_exprt &lhs,
508- const exprt &full_lhs,
507+ const expr_skeletont &full_lhs,
509508 const exprt &rhs,
510509 exprt::operandst &guard)
511510{
@@ -546,8 +545,9 @@ void symex_assignt::assign_struct_member(
546545 // a'==UPDATE(a, .c, e)
547546 const update_exprt new_rhs{
548547 lhs_struct, member_designatort (component_name), rhs};
549- const exprt new_full_lhs = add_to_lhs (full_lhs, lhs);
550- assign_rec (lhs_struct, new_full_lhs, new_rhs, guard);
548+ const expr_skeletont new_skeleton =
549+ full_lhs.compose (expr_skeletont::remove_op0 (lhs));
550+ assign_rec (lhs_struct, new_skeleton, new_rhs, guard);
551551 }
552552 else
553553 {
@@ -558,15 +558,15 @@ void symex_assignt::assign_struct_member(
558558
559559 with_exprt new_rhs (lhs_struct, exprt (ID_member_name), rhs);
560560 new_rhs.where ().set (ID_component_name, component_name);
561-
562- exprt new_full_lhs = add_to_lhs ( full_lhs, lhs);
563- assign_rec (lhs_struct, new_full_lhs , new_rhs, guard);
561+ const expr_skeletont new_skeleton =
562+ full_lhs. compose ( expr_skeletont::remove_op0 ( lhs) );
563+ assign_rec (lhs_struct, new_skeleton , new_rhs, guard);
564564 }
565565}
566566
567567void symex_assignt::assign_if (
568568 const if_exprt &lhs,
569- const exprt &full_lhs,
569+ const expr_skeletont &full_lhs,
570570 const exprt &rhs,
571571 exprt::operandst &guard)
572572{
@@ -592,7 +592,7 @@ void symex_assignt::assign_if(
592592
593593void symex_assignt::assign_byte_extract (
594594 const byte_extract_exprt &lhs,
595- const exprt &full_lhs,
595+ const expr_skeletont &full_lhs,
596596 const exprt &rhs,
597597 exprt::operandst &guard)
598598{
@@ -608,6 +608,7 @@ void symex_assignt::assign_byte_extract(
608608 UNREACHABLE;
609609
610610 const byte_update_exprt new_rhs{byte_update_id, lhs.op (), lhs.offset (), rhs};
611- exprt new_full_lhs=add_to_lhs (full_lhs, lhs);
612- assign_rec (lhs.op (), new_full_lhs, new_rhs, guard);
611+ const expr_skeletont new_skeleton =
612+ full_lhs.compose (expr_skeletont::remove_op0 (lhs));
613+ assign_rec (lhs.op (), new_skeleton, new_rhs, guard);
613614}
0 commit comments