1313#include < string>
1414
1515#include < util/arith_tools.h>
16+ #include < util/c_types.h>
1617#include < util/std_types.h>
1718#include < util/std_expr.h>
18- #include < util/config.h>
1919#include < util/find_symbols.h>
2020#include < util/pointer_offset_size.h>
2121#include < util/string2int.h>
@@ -159,8 +159,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
159159 {
160160 out << " (# object:="
161161 << pointer_logic.get_null_object ()
162- << " , offset:="
163- << bin_zero (config.ansi_c .pointer_width ) << " #)" ;
162+ << " , offset:=" ;
163+ convert_expr (from_integer (0 , size_type ()));
164+ out << " #)" ;
164165 }
165166 else
166167 throw " unknown pointer constant: " +id2string (value);
@@ -176,7 +177,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
176177 }
177178 else if (expr.type ().id ()==ID_array)
178179 {
179- out << " ARRAY (i: " << array_index_type () << " ):" ;
180+ out << " ARRAY (i: " ;
181+ convert_type (index_type ());
182+ out << " ):" ;
180183
181184 assert (!expr.operands ().empty ());
182185
@@ -188,7 +191,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
188191 else
189192 out << " \n ELSIF " ;
190193
191- out << " i=" << array_index (i) << " THEN " ;
194+ out << " i=" ;
195+ convert_expr (from_integer (i, index_type ()));
196+ out << " THEN " ;
192197 convert_array_value (*it);
193198 i++;
194199 }
@@ -247,7 +252,7 @@ void cvc_convt::convert_plus_expr(const exprt &expr)
247252 out << " (LET P: " << cvc_pointer_type () << " = " ;
248253 convert_expr (*p);
249254 out << " IN P WITH .offset:=BVPLUS("
250- << config. ansi_c . pointer_width
255+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
251256 << " , P.offset, " ;
252257 convert_expr (*i);
253258 out << " ))" ;
@@ -487,52 +492,24 @@ void cvc_convt::convert_literal(const literalt l)
487492 out << " )" ;
488493}
489494
490- std::string cvc_convt::bin_zero ( unsigned bits)
495+ std::string cvc_convt::cvc_pointer_type () const
491496{
492- assert (bits!=0 );
493- std::string result=" 0bin" ;
494- while (bits!=0 )
495- {
496- result+=' 0' ;
497- bits--;
498- }
499- return result;
500- }
501-
502- std::string cvc_convt::cvc_pointer_type ()
503- {
504- assert (config.ansi_c .pointer_width !=0 );
505- return " [# object: INT, offset: BITVECTOR(" +
506- std::to_string (config.ansi_c .pointer_width )+" ) #]" ;
507- }
508-
509- std::string cvc_convt::array_index_type ()
510- {
511- return std::string (" BITVECTOR(" )+
512- std::to_string (32 )+" )" ;
513- }
514-
515- typet cvc_convt::gen_array_index_type ()
516- {
517- typet t (ID_signedbv);
518- t.set (ID_width, 32 );
519- return t;
520- }
521-
522- std::string cvc_convt::array_index (unsigned i)
523- {
524- return " 0bin" +integer2binary (i, config.ansi_c .int_width );
497+ return
498+ " [# object: INT, offset: BITVECTOR(" +
499+ std::to_string (
500+ integer2size_t (
501+ pointer_offset_bits (pointer_type (void_type ()), ns)))+" ) #]" ;
525502}
526503
527504void cvc_convt::convert_array_index (const exprt &expr)
528505{
529- if (expr.type ()==gen_array_index_type ())
506+ if (expr.type ()==index_type ())
530507 {
531508 convert_expr (expr);
532509 }
533510 else
534511 {
535- exprt tmp (ID_typecast, gen_array_index_type ());
512+ exprt tmp (ID_typecast, index_type ());
536513 tmp.copy_to_operands (expr);
537514 convert_expr (tmp);
538515 }
@@ -547,8 +524,9 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
547524 out
548525 << " (# object:="
549526 << pointer_logic.add_object (expr)
550- << " , offset:="
551- << bin_zero (config.ansi_c .pointer_width ) << " #)" ;
527+ << " , offset:=" ;
528+ convert_expr (from_integer (0 , size_type ()));
529+ out << " #)" ;
552530 }
553531 else if (expr.id ()==ID_index)
554532 {
@@ -581,7 +559,7 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
581559 assert (false );
582560
583561 out << " IN P WITH .offset:=BVPLUS("
584- << config. ansi_c . pointer_width
562+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
585563 << " , P.offset, " ;
586564 convert_expr (index);
587565 out << " ))" ;
@@ -609,13 +587,10 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
609587 ns);
610588 assert (offset>=0 );
611589
612- typet index_type (ID_unsignedbv);
613- index_type.set (ID_width, config.ansi_c .pointer_width );
614-
615- exprt index=from_integer (offset, index_type);
590+ exprt index=from_integer (offset, size_type ());
616591
617592 out << " IN P WITH .offset:=BVPLUS("
618- << config. ansi_c . pointer_width
593+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
619594 << " , P.offset, " ;
620595 convert_expr (index);
621596 out << " ))" ;
@@ -1035,7 +1010,9 @@ void cvc_convt::convert_expr(const exprt &expr)
10351010 {
10361011 assert (expr.type ().id ()==ID_array);
10371012 assert (expr.operands ().size ()==1 );
1038- out << " (ARRAY (i: " << array_index_type () << " ): " ;
1013+ out << " (ARRAY (i: " ;
1014+ convert_type (index_type ());
1015+ out << " ): " ;
10391016 convert_array_value (expr.op0 ());
10401017 out << " )" ;
10411018 }
@@ -1273,8 +1250,9 @@ void cvc_convt::convert_type(const typet &type)
12731250 {
12741251 const array_typet &array_type=to_array_type (type);
12751252
1276- out << " ARRAY " << array_index_type ()
1277- << " OF " ;
1253+ out << " ARRAY " ;
1254+ convert_type (index_type ());
1255+ out << " OF " ;
12781256
12791257 if (array_type.subtype ().id ()==ID_bool)
12801258 out << " BITVECTOR(1)" ;
0 commit comments