@@ -1123,57 +1123,37 @@ code_blockt java_string_library_preprocesst::make_assign_function_from_call(
1123
1123
// / primitive value contained in the given object.
1124
1124
optionalt<symbol_exprt>
1125
1125
java_string_library_preprocesst::get_primitive_value_of_object (
1126
- const exprt &object,
1127
- irep_idt type_name,
1128
- const source_locationt &loc,
1129
- const irep_idt &function_id,
1130
- symbol_table_baset &symbol_table,
1131
- code_blockt &code)
1132
- {
1126
+ const exprt &object, irep_idt type_name, const source_locationt &loc,
1127
+ const irep_idt &function_id, symbol_table_baset &symbol_table,
1128
+ code_blockt &code) {
1133
1129
optionalt<struct_tag_typet> object_type;
1134
1130
1135
1131
typet value_type;
1136
- if (type_name==ID_boolean)
1137
- {
1138
- value_type=java_boolean_type ();
1132
+ if (type_name == ID_boolean) {
1133
+ value_type = java_boolean_type ();
1139
1134
object_type = struct_tag_typet (" java::java.lang.Boolean" );
1140
- }
1141
- else if (type_name==ID_char)
1142
- {
1143
- value_type=java_char_type ();
1135
+ } else if (type_name == ID_char) {
1136
+ value_type = java_char_type ();
1144
1137
object_type = struct_tag_typet (" java::java.lang.Character" );
1145
- }
1146
- else if (type_name==ID_byte)
1147
- {
1148
- value_type=java_byte_type ();
1138
+ } else if (type_name == ID_byte) {
1139
+ value_type = java_byte_type ();
1149
1140
object_type = struct_tag_typet (" java::java.lang.Byte" );
1150
- }
1151
- else if (type_name==ID_short)
1152
- {
1153
- value_type=java_short_type ();
1141
+ } else if (type_name == ID_short) {
1142
+ value_type = java_short_type ();
1154
1143
object_type = struct_tag_typet (" java::java.lang.Short" );
1155
- }
1156
- else if (type_name==ID_int)
1157
- {
1158
- value_type=java_int_type ();
1144
+ } else if (type_name == ID_int) {
1145
+ value_type = java_int_type ();
1159
1146
object_type = struct_tag_typet (" java::java.lang.Integer" );
1160
- }
1161
- else if (type_name==ID_long)
1162
- {
1163
- value_type=java_long_type ();
1147
+ } else if (type_name == ID_long) {
1148
+ value_type = java_long_type ();
1164
1149
object_type = struct_tag_typet (" java::java.lang.Long" );
1165
- }
1166
- else if (type_name==ID_float)
1167
- {
1168
- value_type=java_float_type ();
1150
+ } else if (type_name == ID_float) {
1151
+ value_type = java_float_type ();
1169
1152
object_type = struct_tag_typet (" java::java.lang.Float" );
1170
- }
1171
- else if (type_name==ID_double)
1172
- {
1173
- value_type=java_double_type ();
1153
+ } else if (type_name == ID_double) {
1154
+ value_type = java_double_type ();
1174
1155
object_type = struct_tag_typet (" java::java.lang.Double" );
1175
- }
1176
- else if (type_name==ID_void)
1156
+ } else if (type_name == ID_void)
1177
1157
return {};
1178
1158
else
1179
1159
UNREACHABLE;
@@ -1183,26 +1163,23 @@ java_string_library_preprocesst::get_primitive_value_of_object(
1183
1163
// declare tmp_type_name to hold the value
1184
1164
const std::string aux_name = " tmp_" + id2string (type_name);
1185
1165
const symbolt &symbol =
1186
- fresh_java_symbol (value_type, aux_name, loc, function_id, symbol_table);
1166
+ fresh_java_symbol (value_type, aux_name, loc, function_id, symbol_table);
1187
1167
const auto value = symbol.symbol_expr ();
1188
1168
1189
1169
// Check that the type of the object is in the symbol table,
1190
1170
// otherwise there is no safe way of finding its value.
1191
- if (
1192
- const auto maybe_symbol =
1193
- symbol_table.lookup (object_type->get_identifier ()))
1194
- {
1171
+ if (const auto maybe_symbol =
1172
+ symbol_table.lookup (object_type->get_identifier ())) {
1195
1173
const struct_typet &struct_type = to_struct_type (maybe_symbol->type );
1196
1174
// Check that the type has a value field
1197
1175
const struct_union_typet::componentt &value_comp =
1198
- struct_type.get_component (" value" );
1199
- if (!value_comp.is_nil ())
1200
- {
1176
+ struct_type.get_component (" value" );
1177
+ if (!value_comp.is_nil ()) {
1201
1178
const pointer_typet struct_pointer_type = pointer_type (struct_type);
1202
1179
dereference_exprt deref{typecast_exprt (object, struct_pointer_type),
1203
1180
struct_pointer_type.subtype ()};
1204
- const member_exprt deref_value{
1205
- std::move (deref), value_comp. get_name (), value_comp.type ()};
1181
+ const member_exprt deref_value{std::move (deref), value_comp. get_name (),
1182
+ value_comp.type ()};
1206
1183
code.add (code_assignt (value, deref_value), loc);
1207
1184
return value;
1208
1185
}
@@ -1222,16 +1199,15 @@ java_string_library_preprocesst::get_primitive_value_of_object(
1222
1199
// / \param argv: reference to an array of references
1223
1200
// / \param index: index of the desired object
1224
1201
// / \return An expression representing the object at position `index` of `argv`.
1225
- dereference_exprt java_string_library_preprocesst::get_object_at_index (
1226
- const exprt &argv,
1227
- std::size_t index)
1228
- {
1202
+ dereference_exprt
1203
+ java_string_library_preprocesst::get_object_at_index (const exprt &argv,
1204
+ std::size_t index) {
1229
1205
const dereference_exprt deref_objs{argv, argv.type ().subtype ()};
1230
1206
const pointer_typet empty_pointer = pointer_type (java_void_type ());
1231
1207
const pointer_typet pointer_of_pointer = pointer_type (empty_pointer);
1232
1208
const member_exprt data_member{deref_objs, " data" , pointer_of_pointer};
1233
1209
const plus_exprt data_pointer_plus_index{
1234
- data_member, from_integer (index , java_int_type ()), data_member.type ()};
1210
+ data_member, from_integer (index , java_int_type ()), data_member.type ()};
1235
1211
return dereference_exprt{data_pointer_plus_index,
1236
1212
data_pointer_plus_index.type ().subtype ()};
1237
1213
}
@@ -1268,35 +1244,27 @@ dereference_exprt java_string_library_preprocesst::get_object_at_index(
1268
1244
// / \return An expression of type `structured_type` representing the possible
1269
1245
// / values of the argument at position `index` of `argv`.
1270
1246
struct_exprt java_string_library_preprocesst::make_argument_for_format (
1271
- const exprt &argv,
1272
- std::size_t index,
1273
- const struct_typet &structured_type,
1274
- const source_locationt &loc,
1275
- const irep_idt &function_id,
1276
- symbol_table_baset &symbol_table,
1277
- code_blockt &code)
1278
- {
1247
+ const exprt &argv, std::size_t index, const struct_typet &structured_type,
1248
+ const source_locationt &loc, const irep_idt &function_id,
1249
+ symbol_table_baset &symbol_table, code_blockt &code) {
1279
1250
// Declarations of the fields of arg_i_struct
1280
1251
// arg_i_struct is { arg_i_string_expr, tmp_int, tmp_char, ... }
1281
1252
struct_exprt arg_i_struct ({}, structured_type);
1282
1253
std::list<exprt> field_exprs;
1283
- for (const auto & comp : structured_type.components ())
1284
- {
1285
- const irep_idt &name=comp.get_name ();
1286
- const typet &type=comp.type ();
1254
+ for (const auto &comp : structured_type.components ()) {
1255
+ const irep_idt &name = comp.get_name ();
1256
+ const typet &type = comp.type ();
1287
1257
exprt field_expr;
1288
- if (name!=" string_expr" )
1289
- {
1290
- std::string tmp_name=" tmp_" +id2string (name);
1258
+ if (name != " string_expr" ) {
1259
+ std::string tmp_name = " tmp_" + id2string (name);
1291
1260
const symbolt &field_symbol =
1292
- fresh_java_symbol (type, tmp_name, loc, function_id, symbol_table);
1261
+ fresh_java_symbol (type, tmp_name, loc, function_id, symbol_table);
1293
1262
auto field_symbol_expr = field_symbol.symbol_expr ();
1294
1263
field_expr = field_symbol_expr;
1295
1264
code.add (code_declt (field_symbol_expr), loc);
1296
- }
1297
- else
1265
+ } else
1298
1266
field_expr =
1299
- make_nondet_string_expr (loc, function_id, symbol_table, code);
1267
+ make_nondet_string_expr (loc, function_id, symbol_table, code);
1300
1268
1301
1269
field_exprs.push_back (field_expr);
1302
1270
arg_i_struct.copy_to_operands (field_expr);
@@ -1305,7 +1273,7 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
1305
1273
// arg_i = argv[index]
1306
1274
const exprt obj = get_object_at_index (argv, index );
1307
1275
const symbolt &object_symbol = fresh_java_symbol (
1308
- obj.type (), " tmp_format_obj" , loc, function_id, symbol_table);
1276
+ obj.type (), " tmp_format_obj" , loc, function_id, symbol_table);
1309
1277
const symbol_exprt arg_i = object_symbol.symbol_expr ();
1310
1278
1311
1279
allocate_objectst allocate_objects (ID_java, loc, function_id, symbol_table);
@@ -1316,44 +1284,34 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
1316
1284
code.append (tmp);
1317
1285
1318
1286
code.add (code_assignt (arg_i, obj), loc);
1319
- code.add (
1320
- code_assumet (
1321
- not_exprt (
1322
- equal_exprt (arg_i, null_pointer_exprt (to_pointer_type (arg_i.type ()))))),
1323
- loc);
1287
+ code.add (code_assumet (not_exprt (equal_exprt (
1288
+ arg_i, null_pointer_exprt (to_pointer_type (arg_i.type ()))))),
1289
+ loc);
1324
1290
1325
1291
code_blockt code_not_null;
1326
1292
1327
1293
// Assigning all the fields of arg_i_struct
1328
- for (const auto &comp : structured_type.components ())
1329
- {
1330
- const irep_idt &name=comp.get_name ();
1331
- exprt field_expr=field_exprs.front ();
1294
+ for (const auto &comp : structured_type.components ()) {
1295
+ const irep_idt &name = comp.get_name ();
1296
+ exprt field_expr = field_exprs.front ();
1332
1297
field_exprs.pop_front ();
1333
1298
1334
- if (name==" string_expr" )
1335
- {
1299
+ if (name == " string_expr" ) {
1336
1300
const pointer_typet string_pointer =
1337
- java_reference_type (struct_tag_typet (" java::java.lang.String" ));
1301
+ java_reference_type (struct_tag_typet (" java::java.lang.String" ));
1338
1302
const typecast_exprt arg_i_as_string{arg_i, string_pointer};
1339
- code_assign_java_string_to_string_expr (
1340
- to_string_expr (field_expr),
1341
- arg_i_as_string,
1342
- loc,
1343
- symbol_table,
1344
- code_not_null);
1345
- }
1346
- else if (name==ID_int || name==ID_float || name==ID_char || name==ID_boolean)
1347
- {
1303
+ code_assign_java_string_to_string_expr (to_string_expr (field_expr),
1304
+ arg_i_as_string, loc, symbol_table,
1305
+ code_not_null);
1306
+ } else if (name == ID_int || name == ID_float || name == ID_char ||
1307
+ name == ID_boolean) {
1348
1308
const auto value = get_primitive_value_of_object (
1349
- arg_i, name, loc, function_id, symbol_table, code_not_null);
1350
- if (value.has_value ())
1309
+ arg_i, name, loc, function_id, symbol_table, code_not_null);
1310
+ if (value.has_value ())
1351
1311
code_not_null.add (code_assignt (field_expr, *value), loc);
1352
1312
else
1353
1313
code_not_null.add (code_assignt (field_expr, nil_exprt ()), loc);
1354
- }
1355
- else
1356
- {
1314
+ } else {
1357
1315
// TODO: date_time and hash_code not implemented
1358
1316
}
1359
1317
}
@@ -1374,16 +1332,13 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
1374
1332
// / class of the arguments is not known, we give as argument to the internal
1375
1333
// format function a structure containing the different possible types.
1376
1334
code_blockt java_string_library_preprocesst::make_string_format_code (
1377
- const java_method_typet &type,
1378
- const source_locationt &loc,
1379
- const irep_idt &function_id,
1380
- symbol_table_baset &symbol_table)
1381
- {
1382
- PRECONDITION (type.parameters ().size ()==2 );
1335
+ const java_method_typet &type, const source_locationt &loc,
1336
+ const irep_idt &function_id, symbol_table_baset &symbol_table) {
1337
+ PRECONDITION (type.parameters ().size () == 2 );
1383
1338
code_blockt code;
1384
- exprt::operandst args =
1385
- process_parameters (type. parameters (), loc, function_id, symbol_table, code);
1386
- INVARIANT (args.size ()== 2 , " String.format should have two arguments" );
1339
+ exprt::operandst args = process_parameters (type. parameters (), loc,
1340
+ function_id, symbol_table, code);
1341
+ INVARIANT (args.size () == 2 , " String.format should have two arguments" );
1387
1342
1388
1343
// The argument can be:
1389
1344
// a string, an integer, a floating point, a character, a boolean,
@@ -1403,19 +1358,17 @@ code_blockt java_string_library_preprocesst::make_string_format_code(
1403
1358
// containing each possible type used in format specifiers.
1404
1359
std::vector<exprt> processed_args;
1405
1360
processed_args.push_back (args[0 ]);
1406
- for (std::size_t i=0 ; i<MAX_FORMAT_ARGS; ++i)
1407
- processed_args.push_back (
1408
- make_argument_for_format (
1361
+ for (std::size_t i = 0 ; i < MAX_FORMAT_ARGS; ++i)
1362
+ processed_args.push_back (make_argument_for_format (
1409
1363
args[1 ], i, structured_type, loc, function_id, symbol_table, code));
1410
1364
1411
1365
const refined_string_exprt string_expr = string_expr_of_function (
1412
- ID_cprover_string_format_func, processed_args, loc, symbol_table, code);
1366
+ ID_cprover_string_format_func, processed_args, loc, symbol_table, code);
1413
1367
const exprt java_string = allocate_fresh_string (
1414
- type.return_type (), loc, function_id, symbol_table, code);
1415
- code.add (
1416
- code_assign_string_expr_to_java_string (
1417
- java_string, string_expr, symbol_table, true ),
1418
- loc);
1368
+ type.return_type (), loc, function_id, symbol_table, code);
1369
+ code.add (code_assign_string_expr_to_java_string (java_string, string_expr,
1370
+ symbol_table, true ),
1371
+ loc);
1419
1372
code.add (code_returnt (java_string), loc);
1420
1373
return code;
1421
1374
}
@@ -1849,15 +1802,11 @@ void java_string_library_preprocesst::initialize_conversion_table()
1849
1802
[" java::java.lang.String.equalsIgnoreCase:(Ljava/lang/String;)Z" ]=
1850
1803
ID_cprover_string_equals_ignore_case_func;
1851
1804
conversion_table
1852
- [" java::java.lang.String.format:(Ljava/lang/String;[Ljava/lang/Object;)"
1853
- " Ljava/lang/String;" ] =
1854
- std::bind (
1855
- &java_string_library_preprocesst::make_string_format_code,
1856
- this ,
1857
- std::placeholders::_1,
1858
- std::placeholders::_2,
1859
- std::placeholders::_3,
1860
- std::placeholders::_4);
1805
+ [" java::java.lang.String.format:(Ljava/lang/String;[Ljava/lang/Object;)"
1806
+ " Ljava/lang/String;" ] =
1807
+ std::bind (&java_string_library_preprocesst::make_string_format_code,
1808
+ this , std::placeholders::_1, std::placeholders::_2,
1809
+ std::placeholders::_3, std::placeholders::_4);
1861
1810
cprover_equivalent_to_java_function
1862
1811
[" java::java.lang.String.hashCode:()I" ]=
1863
1812
ID_cprover_string_hash_code_func;
0 commit comments