@@ -32,7 +32,6 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
3232 pointer_abstract_objectt(t)
3333{
3434 assert (t.id ()==ID_pointer);
35- value=nil_exprt ();
3635}
3736
3837/* ******************************************************************\
@@ -56,7 +55,6 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
5655 pointer_abstract_objectt(t, tp, bttm)
5756{
5857 assert (t.id ()==ID_pointer);
59- value=nil_exprt ();
6058}
6159
6260/* ******************************************************************\
@@ -74,7 +72,7 @@ Function: constant_pointer_abstract_objectt::constant_pointer_abstract_objectt
7472
7573constant_pointer_abstract_objectt::constant_pointer_abstract_objectt (
7674 const constant_pointer_abstract_objectt &old):
77- pointer_abstract_objectt(old), value (old.value )
75+ pointer_abstract_objectt(old), value_stack (old.value_stack )
7876{}
7977
8078/* ******************************************************************\
@@ -94,26 +92,11 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
9492 const exprt &e,
9593 const abstract_environmentt &environment,
9694 const namespacet &ns):
97- pointer_abstract_objectt(e, environment, ns)
95+ pointer_abstract_objectt(e, environment, ns),
96+ value_stack(e, environment, ns)
9897{
9998 assert (e.type ().id ()==ID_pointer);
100- value=nil_exprt ();
101-
102- if (e.id ()==ID_address_of)
103- {
104- value=e;
105- top=false ;
106- }
107- else if (e.id ()==ID_constant)
108- {
109- constant_exprt constant_expr (to_constant_expr (e));
110- if (constant_expr.get_value ()==ID_NULL)
111- {
112- value=e;
113- top=false ;
114- }
115- }
116- // Else unknown expression type - possibly we should handle more
99+ top=value_stack.is_top_value ();
117100}
118101
119102/* ******************************************************************\
@@ -174,8 +157,10 @@ abstract_object_pointert
174157 }
175158 else
176159 {
177- // Can we actually merge these value
178- if (value==other->value )
160+ bool matching_pointer=
161+ value_stack.to_expression ()==other->value_stack .to_expression ();
162+
163+ if (matching_pointer)
179164 {
180165 return shared_from_this ();
181166 }
@@ -213,7 +198,7 @@ exprt constant_pointer_abstract_objectt::to_constant() const
213198 {
214199 // TODO(tkiley): I think we would like to eval this before using it
215200 // in the to_constant.
216- return value ;
201+ return value_stack. to_expression () ;
217202 }
218203}
219204
@@ -236,33 +221,27 @@ Function: constant_pointer_abstract_objectt::output
236221void constant_pointer_abstract_objectt::output (
237222 std::ostream &out, const ai_baset &ai, const namespacet &ns) const
238223{
239- if (is_top () || is_bottom ())
224+ if (is_top () || is_bottom () || value_stack. is_top_value () )
240225 {
241226 pointer_abstract_objectt::output (out, ai, ns);
242227 }
243228 else
244229 {
245- if (value.id ()==ID_constant && value.get (ID_value)==ID_NULL)
246- {
247- out << " NULL" ;
248- }
249- else
230+ out << " ptr ->(" ;
231+ const exprt &value=value_stack.to_expression ();
232+ if (value.id ()==ID_address_of)
250233 {
251- out << " ptr ->( " ;
252- if (value. id ()==ID_address_of )
234+ const address_of_exprt & address_expr ( to_address_of_expr (value)) ;
235+ if (address_expr. object (). id ()==ID_symbol )
253236 {
254- const address_of_exprt &address_expr (to_address_of_expr (value));
255- if (address_expr.object ().id ()==ID_symbol)
256- {
257- const symbol_exprt &symbol_pointed_to (
258- to_symbol_expr (address_expr.object ()));
259-
260- out << symbol_pointed_to.get_identifier ();
261- }
262- }
237+ const symbol_exprt &symbol_pointed_to (
238+ to_symbol_expr (address_expr.object ()));
263239
264- out << " )" ;
240+ out << symbol_pointed_to.get_identifier ();
241+ }
265242 }
243+
244+ out << " )" ;
266245 }
267246}
268247
@@ -286,28 +265,16 @@ Function: constant_pointer_abstract_objectt::read_dereference
286265abstract_object_pointert constant_pointer_abstract_objectt::read_dereference (
287266 const abstract_environmentt &env, const namespacet &ns) const
288267{
289- if (is_top () || is_bottom () || value. id ()==ID_nil )
268+ if (is_top () || is_bottom () || value_stack. is_top_value () )
290269 {
291270 // Return top if dereferencing a null pointer or we are top
292- bool is_value_top = is_top () || value. id ()==ID_nil ;
271+ bool is_value_top = is_top () || value_stack. is_top_value () ;
293272 return env.abstract_object_factory (
294273 type ().subtype (), ns, is_value_top, !is_value_top);
295274 }
296275 else
297276 {
298- if (value.id ()==ID_address_of)
299- {
300- return env.eval (value.op0 (), ns);
301- }
302- else if (value.id ()==ID_constant)
303- {
304- // Reading a null pointer, return top
305- return env.abstract_object_factory (type ().subtype (), ns, true , false );
306- }
307- else
308- {
309- return env.abstract_object_factory (type ().subtype (), ns, true , false );
310- }
277+ return env.eval (value_stack.to_expression ().op0 (), ns);
311278 }
312279}
313280
@@ -344,22 +311,13 @@ sharing_ptrt<pointer_abstract_objectt>
344311 const abstract_object_pointert new_value,
345312 bool merging_write) const
346313{
347- if (is_top () || is_bottom ())
314+ if (is_top () || is_bottom () || value_stack. is_top_value () )
348315 {
349316 return pointer_abstract_objectt::write_dereference (
350317 environment, ns, stack, new_value, merging_write);
351318 }
352319 else
353320 {
354- // If not an address, we don't know what we are pointing to
355- if (value.id ()!=ID_address_of)
356- {
357- return pointer_abstract_objectt::write_dereference (
358- environment, ns, stack, new_value, merging_write);
359- }
360-
361- const address_of_exprt &address_expr=to_address_of_expr (value);
362-
363321 sharing_ptrt<constant_pointer_abstract_objectt> copy=
364322 sharing_ptrt<constant_pointer_abstract_objectt>(
365323 new constant_pointer_abstract_objectt (*this ));
@@ -369,26 +327,30 @@ sharing_ptrt<pointer_abstract_objectt>
369327 // We should not be changing the type of an abstract object
370328 assert (new_value->type ()==type ().subtype ());
371329
372-
330+ // Get an expression that we can assign to
331+ exprt value=value_stack.to_expression ().op0 ();
373332 if (merging_write)
374333 {
375334 abstract_object_pointert pointed_value=
376- environment.eval (address_expr. object () , ns);
335+ environment.eval (value , ns);
377336 bool modifications;
378337 abstract_object_pointert merged_value=
379338 abstract_objectt::merge (pointed_value, new_value, modifications);
380- environment.assign (address_expr. object () , merged_value, ns);
339+ environment.assign (value , merged_value, ns);
381340 }
382341 else
383342 {
384- environment.assign (address_expr. object () , new_value, ns);
343+ environment.assign (value , new_value, ns);
385344 }
386345 }
387346 else
388347 {
348+ exprt value=value_stack.to_expression ().op0 ();
389349 abstract_object_pointert pointed_value=
390- environment.eval (address_expr.object (), ns);
391- environment.write (pointed_value, new_value, stack, ns, merging_write);
350+ environment.eval (value, ns);
351+ abstract_object_pointert modified_value=
352+ environment.write (pointed_value, new_value, stack, ns, merging_write);
353+ environment.assign (value, modified_value, ns);
392354
393355 // but the pointer itself does not change!
394356 }
0 commit comments