@@ -102,12 +102,12 @@ void write_stackt::construct_stack_to_pointer(
102102 if (!top_stack)
103103 {
104104 // check the symbol at the bottom of the stack
105- std::shared_ptr< const write_stack_entryt> entry = * stack.cbegin ();
105+ const auto access = stack.front ()-> get_access_expr ();
106106 INVARIANT (
107- entry-> get_access_expr () .id () == ID_symbol,
107+ !access. second && access. first .id () == ID_symbol,
108108 " The base should be an addressable location (i.e. symbol)" );
109109
110- if (entry-> get_access_expr () .type ().id () != ID_array)
110+ if (access. first .type ().id () != ID_array)
111111 {
112112 top_stack = true ;
113113 }
@@ -176,27 +176,15 @@ exprt write_stackt::to_expression() const
176176{
177177 // A top stack is useless and its expression should not be evaluated
178178 PRECONDITION (!is_top_value ());
179- exprt access_expr = nil_exprt ();
180- for (const std::shared_ptr<write_stack_entryt> &entry : stack)
179+ PRECONDITION (!stack.empty ());
180+ exprt access_expr = stack.front ()->get_access_expr ().first ;
181+ for (auto it = std::next (stack.begin ()); it != stack.end (); ++it)
181182 {
182- exprt new_expr = entry->get_access_expr ();
183- if (access_expr.id () == ID_nil)
184- {
185- access_expr = new_expr;
186- }
183+ const auto access = (*it)->get_access_expr ();
184+ if (access.second )
185+ access_expr = index_exprt{access_expr, access.first };
187186 else
188- {
189- if (new_expr.operands ().size () == 0 )
190- {
191- new_expr.operands ().resize (1 );
192- }
193- new_expr.operands ()[0 ] = access_expr;
194-
195- // If necessary, complete the type of the new access expression
196- entry->adjust_access_type (new_expr);
197-
198- access_expr = new_expr;
199- }
187+ access_expr = access.first ;
200188 }
201189 address_of_exprt top_expr (access_expr);
202190 return std::move (top_expr);
@@ -210,19 +198,22 @@ size_t write_stackt::depth() const
210198exprt write_stackt::target_expression (size_t depth) const
211199{
212200 PRECONDITION (!is_top_value ());
213- return stack[depth]->get_access_expr ();
201+ return stack[depth]->get_access_expr (). first ;
214202}
215203
216204exprt write_stackt::offset_expression () const
217205{
218206 PRECONDITION (!is_top_value ());
219- auto const &access = stack.back ()->get_access_expr ();
207+ auto const access = stack.back ()->get_access_expr ();
208+
209+ if (access.second )
210+ return access.first ;
220211
221- if (access.id () == ID_member || access.id () == ID_symbol)
222- return access;
212+ if (access.first . id () == ID_member || access. first .id () == ID_symbol)
213+ return access. first ;
223214
224- if (access.id () == ID_index)
225- return to_index_expr (access).index ();
215+ if (access.first . id () == ID_index)
216+ return to_index_expr (access. first ).index ();
226217
227218 return from_integer (0 , unsigned_long_int_type ());
228219}
0 commit comments