Skip to content

Commit dcb6b94

Browse files
authored
Merge pull request #3991 from tautschnig/deprecation-make_typecast
Replace make_typecast by typecast_exprt or typecast_exprt::conditional_cast [blocks: #3800]
2 parents 6f692d7 + ebaacea commit dcb6b94

30 files changed

+150
-182
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,8 +2166,7 @@ void java_bytecode_convert_methodt::convert_invoke(
21662166
type == java_byte_type() || type == java_short_type() ||
21672167
type.id() == ID_pointer)
21682168
{
2169-
if(type != arguments[i].type())
2170-
arguments[i].make_typecast(type);
2169+
arguments[i] = typecast_exprt::conditional_cast(arguments[i], type);
21712170
}
21722171
}
21732172

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ code_ifthenelset java_bytecode_instrumentt::check_class_cast(
225225
class1, ID_java_instanceof, class2);
226226

227227
pointer_typet voidptr = pointer_type(java_void_type());
228-
exprt null_check_op=class1;
229-
if(null_check_op.type()!=voidptr)
230-
null_check_op.make_typecast(voidptr);
228+
exprt null_check_op = typecast_exprt::conditional_cast(class1, voidptr);
231229

232230
optionalt<codet> check_code;
233231
if(throw_runtime_exceptions)

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ bool generate_ansi_c_start_function(
406406
zero_string.type().subtype()=char_type();
407407
zero_string.type().set(ID_size, "infinity");
408408
const index_exprt index(zero_string, from_integer(0, uint_type()));
409-
exprt address_of=address_of_exprt(index, pointer_type(char_type()));
410-
411-
if(argv_symbol.type.subtype()!=address_of.type())
412-
address_of.make_typecast(argv_symbol.type.subtype());
409+
exprt address_of =
410+
typecast_exprt::conditional_cast(
411+
address_of_exprt(index, pointer_type(char_type())),
412+
argv_symbol.type.subtype());
413413
414414
// assign argv[*] to the address of a string-object
415415
array_of_exprt array_of(address_of, argv_symbol.type);

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,10 +2596,11 @@ exprt c_typecheck_baset::do_special_functions(
25962596
throw 0;
25972597
}
25982598

2599-
expr.arguments()[0].make_typecast(bool_typet());
2600-
make_constant(expr.arguments()[0]);
2599+
exprt arg0 =
2600+
typecast_exprt::conditional_cast(expr.arguments()[0], bool_typet());
2601+
make_constant(arg0);
26012602

2602-
if(expr.arguments()[0].is_true())
2603+
if(arg0.is_true())
26032604
return expr.arguments()[1];
26042605
else
26052606
return expr.arguments()[2];
@@ -2953,7 +2954,7 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)
29532954
is_number(o_type1))
29542955
{
29552956
// convert op1 to the vector type
2956-
op1.make_typecast(o_type0);
2957+
op1 = typecast_exprt(op1, o_type0);
29572958
expr.type() = o_type0;
29582959
return;
29592960
}
@@ -2962,7 +2963,7 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)
29622963
is_number(o_type0))
29632964
{
29642965
// convert op0 to the vector type
2965-
op0.make_typecast(o_type1);
2966+
op0 = typecast_exprt(op0, o_type1);
29662967
expr.type() = o_type1;
29672968
return;
29682969
}

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ bool cpp_typecheckt::standard_conversion_integral_promotion(
210210
std::size_t width=to_signedbv_type(expr.type()).get_width();
211211
if(width >= config.ansi_c.int_width)
212212
return false;
213-
new_expr=expr;
214-
new_expr.make_typecast(int_type);
213+
new_expr = typecast_exprt(expr, int_type);
215214
return true;
216215
}
217216

@@ -220,24 +219,19 @@ bool cpp_typecheckt::standard_conversion_integral_promotion(
220219
std::size_t width=to_unsignedbv_type(expr.type()).get_width();
221220
if(width >= config.ansi_c.int_width)
222221
return false;
223-
new_expr=expr;
224-
if(width==config.ansi_c.int_width)
225-
int_type.id(ID_unsignedbv);
226-
new_expr.make_typecast(int_type);
222+
new_expr = typecast_exprt(expr, int_type);
227223
return true;
228224
}
229225

230226
if(expr.type().id() == ID_bool || expr.type().id() == ID_c_bool)
231227
{
232-
new_expr = expr;
233-
new_expr.make_typecast(int_type);
228+
new_expr = typecast_exprt(expr, int_type);
234229
return true;
235230
}
236231

237232
if(expr.type().id()==ID_c_enum_tag)
238233
{
239-
new_expr=expr;
240-
new_expr.make_typecast(int_type);
234+
new_expr = typecast_exprt(expr, int_type);
241235
return true;
242236
}
243237

@@ -271,8 +265,7 @@ bool cpp_typecheckt::standard_conversion_floating_point_promotion(
271265
c_qualifierst qual_from;
272266
qual_from.read(expr.type());
273267

274-
new_expr=expr;
275-
new_expr.make_typecast(double_type());
268+
new_expr = typecast_exprt(expr, double_type());
276269
qual_from.write(new_expr.type());
277270

278271
return true;
@@ -328,8 +321,7 @@ bool cpp_typecheckt::standard_conversion_integral_conversion(
328321

329322
c_qualifierst qual_from;
330323
qual_from.read(expr.type());
331-
new_expr=expr;
332-
new_expr.make_typecast(type);
324+
new_expr = typecast_exprt::conditional_cast(expr, type);
333325
qual_from.write(new_expr.type());
334326

335327
return true;
@@ -382,8 +374,7 @@ bool cpp_typecheckt::standard_conversion_floating_integral_conversion(
382374

383375
c_qualifierst qual_from;
384376
qual_from.read(expr.type());
385-
new_expr=expr;
386-
new_expr.make_typecast(type);
377+
new_expr = typecast_exprt::conditional_cast(expr, type);
387378
qual_from.write(new_expr.type());
388379

389380
return true;
@@ -425,8 +416,7 @@ bool cpp_typecheckt::standard_conversion_floating_point_conversion(
425416
c_qualifierst qual_from;
426417

427418
qual_from.read(expr.type());
428-
new_expr=expr;
429-
new_expr.make_typecast(type);
419+
new_expr = typecast_exprt::conditional_cast(expr, type);
430420
qual_from.write(new_expr.type());
431421

432422
return true;
@@ -508,8 +498,7 @@ bool cpp_typecheckt::standard_conversion_pointer(
508498
{
509499
c_qualifierst qual_from;
510500
qual_from.read(expr.type().subtype());
511-
new_expr=expr;
512-
new_expr.make_typecast(type);
501+
new_expr = typecast_exprt::conditional_cast(expr, type);
513502
qual_from.write(new_expr.type().subtype());
514503
return true;
515504
}
@@ -614,8 +603,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
614603
if(expr.id()==ID_constant &&
615604
expr.get(ID_value)==ID_NULL)
616605
{
617-
new_expr=expr;
618-
new_expr.make_typecast(type);
606+
new_expr = typecast_exprt::conditional_cast(expr, type);
619607
return true;
620608
}
621609

@@ -627,8 +615,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
627615

628616
if(subtype_typecast(to_struct, from_struct))
629617
{
630-
new_expr=expr;
631-
new_expr.make_typecast(type);
618+
new_expr = typecast_exprt::conditional_cast(expr, type);
632619
return true;
633620
}
634621

@@ -664,8 +651,7 @@ bool cpp_typecheckt::standard_conversion_boolean(
664651
typet Bool = c_bool_type();
665652
qual_from.write(Bool);
666653

667-
new_expr=expr;
668-
new_expr.make_typecast(Bool);
654+
new_expr = typecast_exprt::conditional_cast(expr, Bool);
669655
return true;
670656
}
671657

@@ -705,7 +691,7 @@ bool cpp_typecheckt::standard_conversion_sequence(
705691

706692
// we turn bit fields into their underlying type
707693
if(curr_expr.type().id()==ID_c_bit_field)
708-
curr_expr.make_typecast(curr_expr.type().subtype());
694+
curr_expr = typecast_exprt(curr_expr, curr_expr.type().subtype());
709695

710696
if(curr_expr.type().id()==ID_array)
711697
{
@@ -791,7 +777,7 @@ bool cpp_typecheckt::standard_conversion_sequence(
791777
if(expr.type().subtype().id()==ID_nullptr)
792778
{
793779
// std::nullptr_t to _any_ pointer type is ok
794-
new_expr.make_typecast(type);
780+
new_expr = typecast_exprt::conditional_cast(new_expr, type);
795781
}
796782
else if(!standard_conversion_pointer(curr_expr, type, new_expr))
797783
{
@@ -1278,7 +1264,7 @@ bool cpp_typecheckt::reference_binding(
12781264
{
12791265
c_qualifierst qual_from;
12801266
qual_from.read(expr.type());
1281-
new_expr.make_typecast(type);
1267+
new_expr = typecast_exprt::conditional_cast(new_expr, type);
12821268
qual_from.write(new_expr.type().subtype());
12831269
}
12841270

@@ -1805,8 +1791,7 @@ bool cpp_typecheckt::reinterpret_typecast(
18051791
(type.id()==ID_unsignedbv || type.id()==ID_signedbv))
18061792
{
18071793
// pointer to integer, always ok
1808-
new_expr=e;
1809-
new_expr.make_typecast(type);
1794+
new_expr = typecast_exprt::conditional_cast(e, type);
18101795
return true;
18111796
}
18121797

@@ -1825,8 +1810,7 @@ bool cpp_typecheckt::reinterpret_typecast(
18251810
}
18261811
else
18271812
{
1828-
new_expr=e;
1829-
new_expr.make_typecast(type);
1813+
new_expr = typecast_exprt::conditional_cast(e, type);
18301814
}
18311815
return true;
18321816
}
@@ -1837,16 +1821,13 @@ bool cpp_typecheckt::reinterpret_typecast(
18371821
{
18381822
// pointer to pointer: we ok it all.
18391823
// This is more generous than the standard.
1840-
new_expr=expr;
1841-
new_expr.make_typecast(type);
1824+
new_expr = typecast_exprt::conditional_cast(expr, type);
18421825
return true;
18431826
}
18441827

18451828
if(is_reference(type) && e.get_bool(ID_C_lvalue))
18461829
{
1847-
exprt tmp=address_of_exprt(e);
1848-
tmp.make_typecast(type);
1849-
new_expr.swap(tmp);
1830+
new_expr = typecast_exprt::conditional_cast(address_of_exprt(e), type);
18501831
return true;
18511832
}
18521833

@@ -1919,8 +1900,7 @@ bool cpp_typecheckt::static_typecast(
19191900

19201901
if(type.id()==ID_empty)
19211902
{
1922-
new_expr=e;
1923-
new_expr.make_typecast(type);
1903+
new_expr = typecast_exprt::conditional_cast(e, type);
19241904
return true;
19251905
}
19261906

@@ -1930,8 +1910,7 @@ bool cpp_typecheckt::static_typecast(
19301910
e.type().id()==ID_unsignedbv ||
19311911
e.type().id()==ID_c_enum_tag))
19321912
{
1933-
new_expr=e;
1934-
new_expr.make_typecast(type);
1913+
new_expr = typecast_exprt::conditional_cast(e, type);
19351914
new_expr.remove(ID_C_lvalue);
19361915
return true;
19371916
}
@@ -1966,9 +1945,8 @@ bool cpp_typecheckt::static_typecast(
19661945

19671946
if(from.id()==ID_empty)
19681947
{
1969-
e.make_typecast(type);
1970-
new_expr.swap(e);
1971-
return true;
1948+
new_expr = typecast_exprt::conditional_cast(e, type);
1949+
return true;
19721950
}
19731951

19741952
if(to.id()==ID_struct && from.id()==ID_struct)
@@ -2007,8 +1985,7 @@ bool cpp_typecheckt::static_typecast(
20071985

20081986
if(subtype_typecast(from_struct, to_struct))
20091987
{
2010-
new_expr=e;
2011-
new_expr.make_typecast(type);
1988+
new_expr = typecast_exprt::conditional_cast(e, type);
20121989
return true;
20131990
}
20141991
}

src/cpp/cpp_typecheck_initializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ void cpp_typecheckt::zero_initializer(
296296
const unsignedbv_typet enum_type(
297297
to_bitvector_type(final_type.subtype()).get_width());
298298

299-
exprt zero(from_integer(0, enum_type));
300-
zero.make_typecast(type);
299+
exprt zero =
300+
typecast_exprt::conditional_cast(from_integer(0, enum_type), type);
301301
already_typechecked(zero);
302302

303303
code_assignt assign;

src/cpp/cpp_typecheck_static_assert.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void cpp_typecheckt::convert(cpp_static_assertt &cpp_static_assert)
1919
typecheck_expr(cpp_static_assert.op0());
2020
typecheck_expr(cpp_static_assert.op1());
2121

22-
cpp_static_assert.op0().make_typecast(bool_typet());
22+
cpp_static_assert.op0() =
23+
typecast_exprt::conditional_cast(cpp_static_assert.op0(), bool_typet());
2324
make_constant(cpp_static_assert.op0());
2425

2526
if(cpp_static_assert.op0().is_true())

src/goto-cc/linker_script_merge.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,7 @@ int linker_script_merget::ls_data2instructions(
576576
unsigned_int_type().get_width()),
577577
unsigned_int_type());
578578

579-
exprt rhs_tc(rhs);
580-
rhs_tc.make_typecast(pointer_type(char_type()));
579+
typecast_exprt rhs_tc(rhs, pointer_type(char_type()));
581580

582581
linker_values.emplace(
583582
irep_idt(d["sym"].value), std::make_pair(lhs, rhs_tc));
@@ -640,8 +639,8 @@ int linker_script_merget::ls_data2instructions(
640639
string2integer(d["val"].value), unsigned_int_type().get_width()));
641640
rhs.type()=unsigned_int_type();
642641
643-
exprt rhs_tc(rhs);
644-
rhs_tc.make_typecast(pointer_type(char_type()));
642+
exprt rhs_tc =
643+
typecast_exprt::conditional_cast(rhs, pointer_type(char_type()));
645644
646645
linker_values.emplace(
647646
irep_idt(d["sym"].value), std::make_pair(lhs, rhs_tc));

src/goto-instrument/goto_program2code.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
18461846

18471847
const typet &t=expr.type();
18481848

1849-
expr.make_typecast(t);
1849+
expr = typecast_exprt(expr, t);
18501850
add_local_types(t);
18511851

18521852
const irep_idt &typedef_str=expr.type().get(ID_C_typedef);
@@ -1944,10 +1944,10 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
19441944
else if(expr.type().id()==ID_bool ||
19451945
expr.type().id()==ID_c_bool)
19461946
{
1947-
expr=from_integer(
1948-
expr.is_true()?1:0,
1949-
signedbv_typet(config.ansi_c.int_width));
1950-
expr.make_typecast(bool_typet());
1947+
expr = typecast_exprt(
1948+
from_integer(
1949+
expr.is_true() ? 1 : 0, signedbv_typet(config.ansi_c.int_width)),
1950+
bool_typet());
19511951
}
19521952

19531953
const irept &c_sizeof_type=expr.find(ID_C_c_sizeof_type);

0 commit comments

Comments
 (0)