13
13
#include < string>
14
14
15
15
#include < util/arith_tools.h>
16
+ #include < util/c_types.h>
16
17
#include < util/std_types.h>
17
18
#include < util/std_expr.h>
18
- #include < util/config.h>
19
19
#include < util/find_symbols.h>
20
20
#include < util/pointer_offset_size.h>
21
21
#include < util/string2int.h>
@@ -159,8 +159,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
159
159
{
160
160
out << " (# object:="
161
161
<< 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 << " #)" ;
164
165
}
165
166
else
166
167
throw " unknown pointer constant: " +id2string (value);
@@ -176,7 +177,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
176
177
}
177
178
else if (expr.type ().id ()==ID_array)
178
179
{
179
- out << " ARRAY (i: " << array_index_type () << " ):" ;
180
+ out << " ARRAY (i: " ;
181
+ convert_type (index_type ());
182
+ out << " ):" ;
180
183
181
184
assert (!expr.operands ().empty ());
182
185
@@ -188,7 +191,9 @@ void cvc_convt::convert_constant_expr(const exprt &expr)
188
191
else
189
192
out << " \n ELSIF " ;
190
193
191
- out << " i=" << array_index (i) << " THEN " ;
194
+ out << " i=" ;
195
+ convert_expr (from_integer (i, index_type ()));
196
+ out << " THEN " ;
192
197
convert_array_value (*it);
193
198
i++;
194
199
}
@@ -247,7 +252,7 @@ void cvc_convt::convert_plus_expr(const exprt &expr)
247
252
out << " (LET P: " << cvc_pointer_type () << " = " ;
248
253
convert_expr (*p);
249
254
out << " IN P WITH .offset:=BVPLUS("
250
- << config. ansi_c . pointer_width
255
+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
251
256
<< " , P.offset, " ;
252
257
convert_expr (*i);
253
258
out << " ))" ;
@@ -487,52 +492,24 @@ void cvc_convt::convert_literal(const literalt l)
487
492
out << " )" ;
488
493
}
489
494
490
- std::string cvc_convt::bin_zero ( unsigned bits)
495
+ std::string cvc_convt::cvc_pointer_type () const
491
496
{
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)))+" ) #]" ;
525
502
}
526
503
527
504
void cvc_convt::convert_array_index (const exprt &expr)
528
505
{
529
- if (expr.type ()==gen_array_index_type ())
506
+ if (expr.type ()==index_type ())
530
507
{
531
508
convert_expr (expr);
532
509
}
533
510
else
534
511
{
535
- exprt tmp (ID_typecast, gen_array_index_type ());
512
+ exprt tmp (ID_typecast, index_type ());
536
513
tmp.copy_to_operands (expr);
537
514
convert_expr (tmp);
538
515
}
@@ -547,8 +524,9 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
547
524
out
548
525
<< " (# object:="
549
526
<< 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 << " #)" ;
552
530
}
553
531
else if (expr.id ()==ID_index)
554
532
{
@@ -581,7 +559,7 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
581
559
assert (false );
582
560
583
561
out << " IN P WITH .offset:=BVPLUS("
584
- << config. ansi_c . pointer_width
562
+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
585
563
<< " , P.offset, " ;
586
564
convert_expr (index );
587
565
out << " ))" ;
@@ -609,13 +587,10 @@ void cvc_convt::convert_address_of_rec(const exprt &expr)
609
587
ns);
610
588
assert (offset>=0 );
611
589
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 ());
616
591
617
592
out << " IN P WITH .offset:=BVPLUS("
618
- << config. ansi_c . pointer_width
593
+ << pointer_offset_bits ( pointer_type ( void_type ()), ns)
619
594
<< " , P.offset, " ;
620
595
convert_expr (index );
621
596
out << " ))" ;
@@ -1035,7 +1010,9 @@ void cvc_convt::convert_expr(const exprt &expr)
1035
1010
{
1036
1011
assert (expr.type ().id ()==ID_array);
1037
1012
assert (expr.operands ().size ()==1 );
1038
- out << " (ARRAY (i: " << array_index_type () << " ): " ;
1013
+ out << " (ARRAY (i: " ;
1014
+ convert_type (index_type ());
1015
+ out << " ): " ;
1039
1016
convert_array_value (expr.op0 ());
1040
1017
out << " )" ;
1041
1018
}
@@ -1273,8 +1250,9 @@ void cvc_convt::convert_type(const typet &type)
1273
1250
{
1274
1251
const array_typet &array_type=to_array_type (type);
1275
1252
1276
- out << " ARRAY " << array_index_type ()
1277
- << " OF " ;
1253
+ out << " ARRAY " ;
1254
+ convert_type (index_type ());
1255
+ out << " OF " ;
1278
1256
1279
1257
if (array_type.subtype ().id ()==ID_bool)
1280
1258
out << " BITVECTOR(1)" ;
0 commit comments