@@ -367,12 +367,12 @@ exprt::operandst
367
367
symbol_tablet &symbol_table,
368
368
code_blockt &init_code)
369
369
{
370
- assert (operands.size ()==2 );
370
+ PRECONDITION (operands.size ()==2 );
371
371
exprt::operandst ops;
372
- exprt op0=operands[0 ];
373
- exprt op1=operands[1 ];
372
+ const exprt &op0=operands[0 ];
373
+ const exprt &op1=operands[1 ];
374
+ PRECONDITION (implements_java_char_sequence (op0.type ()));
374
375
375
- assert (implements_java_char_sequence (op0.type ()));
376
376
dereference_exprt deref0=
377
377
checked_dereference (op0, to_pointer_type (op0.type ()).subtype ());
378
378
process_single_operand (ops, deref0, loc, symbol_table, init_code);
@@ -394,21 +394,16 @@ exprt::operandst
394
394
typet java_string_library_preprocesst::get_data_type (
395
395
const typet &type, const symbol_tablet &symbol_table)
396
396
{
397
+ PRECONDITION (type.id ()==ID_struct || type.id ()==ID_symbol);
397
398
if (type.id ()==ID_symbol)
398
399
{
399
400
symbolt sym=symbol_table.lookup (to_symbol_type (type).get_identifier ());
400
- assert (sym.type .id ()!=ID_symbol);
401
+ CHECK_RETURN (sym.type .id ()!=ID_symbol);
401
402
return get_data_type (sym.type , symbol_table);
402
403
}
403
- else
404
- {
405
- assert (type.id ()==ID_struct);
406
- const struct_typet &struct_type=to_struct_type (type);
407
- for (auto component : struct_type.components ())
408
- if (component.get_name ()==" data" )
409
- return component.type ();
410
- assert (false && " type does not contain data component" );
411
- }
404
+ // else type id is ID_struct
405
+ const struct_typet &struct_type=to_struct_type (type);
406
+ return struct_type.component_type (" data" );
412
407
}
413
408
414
409
// / Finds the type of the length component
@@ -418,21 +413,16 @@ typet java_string_library_preprocesst::get_data_type(
418
413
typet java_string_library_preprocesst::get_length_type (
419
414
const typet &type, const symbol_tablet &symbol_table)
420
415
{
416
+ PRECONDITION (type.id ()==ID_struct || type.id ()==ID_symbol);
421
417
if (type.id ()==ID_symbol)
422
418
{
423
419
symbolt sym=symbol_table.lookup (to_symbol_type (type).get_identifier ());
424
- assert (sym.type .id ()!=ID_symbol);
420
+ CHECK_RETURN (sym.type .id ()!=ID_symbol);
425
421
return get_length_type (sym.type , symbol_table);
426
422
}
427
- else
428
- {
429
- assert (type.id ()==ID_struct);
430
- const struct_typet &struct_type=to_struct_type (type);
431
- for (auto component : struct_type.components ())
432
- if (component.get_name ()==" length" )
433
- return component.type ();
434
- assert (false && " type does not contain length component" );
435
- }
423
+ // else type id is ID_struct
424
+ const struct_typet &struct_type=to_struct_type (type);
425
+ return struct_type.component_type (" length" );
436
426
}
437
427
438
428
// / access length member
@@ -728,7 +718,7 @@ codet java_string_library_preprocesst::code_assign_components_to_java_string(
728
718
const exprt &rhs_length,
729
719
symbol_tablet &symbol_table)
730
720
{
731
- assert (implements_java_char_sequence (lhs.type ()));
721
+ PRECONDITION (implements_java_char_sequence (lhs.type ()));
732
722
dereference_exprt deref=checked_dereference (lhs, lhs.type ().subtype ());
733
723
734
724
code_blockt code;
@@ -786,7 +776,7 @@ codet java_string_library_preprocesst::
786
776
const source_locationt &loc,
787
777
symbol_tablet &symbol_table)
788
778
{
789
- assert (implements_java_char_sequence (lhs.type ()));
779
+ PRECONDITION (implements_java_char_sequence (lhs.type ()));
790
780
dereference_exprt deref=checked_dereference (lhs, lhs.type ().subtype ());
791
781
792
782
code_blockt code;
@@ -812,7 +802,7 @@ codet java_string_library_preprocesst::
812
802
codet java_string_library_preprocesst::code_assign_java_string_to_string_expr (
813
803
const string_exprt &lhs, const exprt &rhs, symbol_tablet &symbol_table)
814
804
{
815
- assert (implements_java_char_sequence (rhs.type ()));
805
+ PRECONDITION (implements_java_char_sequence (rhs.type ()));
816
806
817
807
typet deref_type;
818
808
if (rhs.type ().subtype ().id ()==ID_symbol)
@@ -901,7 +891,7 @@ codet java_string_library_preprocesst::make_float_to_string_code(
901
891
{
902
892
// Getting the argument
903
893
code_typet::parameterst params=type.parameters ();
904
- assert (params.size ()==1 && " wrong number of parameters in Float.toString " );
894
+ PRECONDITION (params.size ()==1 );
905
895
exprt arg=symbol_exprt (params[0 ].get_identifier (), params[0 ].type ());
906
896
907
897
// Holder for output code
@@ -1010,7 +1000,10 @@ codet java_string_library_preprocesst::make_float_to_string_code(
1010
1000
string_expr_list.push_back (neg_simple_notation);
1011
1001
1012
1002
// Combining all cases
1013
- assert (string_expr_list.size ()==condition_list.size ());
1003
+ INVARIANT (
1004
+ string_expr_list.size ()==condition_list.size (),
1005
+ " number of created strings should correspond to number of conditions" );
1006
+
1014
1007
// We do not check the condition of the first element in the list as it
1015
1008
// will be reached only if all other conditions are not satisfied.
1016
1009
codet tmp_code=code_assign_string_expr_to_java_string (
@@ -1057,7 +1050,7 @@ codet java_string_library_preprocesst::make_init_function_from_call(
1057
1050
code_typet::parameterst params=type.parameters ();
1058
1051
1059
1052
// The first parameter is the object to be initialized
1060
- assert (!params.empty ());
1053
+ PRECONDITION (!params.empty ());
1061
1054
exprt arg_this=symbol_exprt (params[0 ].get_identifier (), params[0 ].type ());
1062
1055
if (ignore_first_arg)
1063
1056
params.erase (params.begin ());
@@ -1098,11 +1091,11 @@ codet java_string_library_preprocesst::
1098
1091
symbol_tablet &symbol_table)
1099
1092
{
1100
1093
// This is similar to assign functions except we return a pointer to `this`
1094
+ code_typet::parameterst params=type.parameters ();
1095
+ PRECONDITION (!params.empty ());
1101
1096
code_blockt code;
1102
1097
code.add (make_assign_function_from_call (
1103
1098
function_name, type, loc, symbol_table));
1104
- code_typet::parameterst params=type.parameters ();
1105
- assert (!params.empty ());
1106
1099
exprt arg_this=symbol_exprt (params[0 ].get_identifier (), params[0 ].type ());
1107
1100
code.add (code_returnt (arg_this));
1108
1101
return code;
@@ -1149,10 +1142,10 @@ codet java_string_library_preprocesst::make_string_to_char_array_code(
1149
1142
symbol_tablet &symbol_table)
1150
1143
{
1151
1144
code_blockt code;
1152
- assert (!type.parameters ().empty ());
1145
+ PRECONDITION (!type.parameters ().empty ());
1153
1146
const code_typet::parametert &p=type.parameters ()[0 ];
1154
1147
symbol_exprt string_argument (p.get_identifier (), p.type ());
1155
- assert (implements_java_char_sequence (string_argument.type ()));
1148
+ PRECONDITION (implements_java_char_sequence (string_argument.type ()));
1156
1149
1157
1150
// lhs = new java::array[char]
1158
1151
exprt lhs=allocate_fresh_array (
0 commit comments