Skip to content

Commit 1ba3a16

Browse files
author
Daniel Kroening
authored
Merge pull request #3758 from tautschnig/no-follow-ansi-c
Remove unnecessary use of ns.follow in ansi-c/
2 parents 5036706 + c017dc7 commit 1ba3a16

File tree

6 files changed

+52
-60
lines changed

6 files changed

+52
-60
lines changed

src/ansi-c/anonymous_member.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ exprt get_component_rec(
5151

5252
for(const auto &comp : components)
5353
{
54-
const typet &type=ns.follow(comp.type());
54+
const typet &type = comp.type();
5555

5656
if(comp.get_name()==component_name)
5757
{
5858
return std::move(make_member_expr(struct_union, comp, ns));
5959
}
60-
else if(comp.get_anonymous() &&
61-
(type.id()==ID_struct || type.id()==ID_union))
60+
else if(
61+
comp.get_anonymous() &&
62+
(type.id() == ID_struct_tag || type.id() == ID_union_tag))
6263
{
6364
const member_exprt tmp = make_member_expr(struct_union, comp, ns);
6465
exprt result=get_component_rec(tmp, component_name, ns);

src/ansi-c/c_typecast.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,12 @@ void c_typecastt::implicit_typecast_arithmetic(
388388
{
389389
typet new_type;
390390

391-
const typet &expr_type=ns.follow(expr.type());
392-
393391
switch(c_type)
394392
{
395393
case PTR:
396-
if(expr_type.id()==ID_array)
394+
if(expr.type().id() == ID_array)
397395
{
398-
new_type=pointer_type(expr_type.subtype());
396+
new_type = pointer_type(expr.type().subtype());
399397
break;
400398
}
401399
return;
@@ -423,7 +421,7 @@ void c_typecastt::implicit_typecast_arithmetic(
423421
default: return;
424422
}
425423

426-
if(new_type!=expr_type)
424+
if(new_type != expr.type())
427425
do_typecast(expr, new_type);
428426
}
429427

@@ -538,8 +536,8 @@ void c_typecastt::implicit_typecast_followed(
538536
{
539537
// we are quite generous about pointers
540538

541-
const typet &src_sub=ns.follow(src_type.subtype());
542-
const typet &dest_sub=ns.follow(dest_type.subtype());
539+
const typet &src_sub = src_type.subtype();
540+
const typet &dest_sub = dest_type.subtype();
543541

544542
if(is_void_pointer(src_type) ||
545543
is_void_pointer(dest_type))
@@ -603,8 +601,8 @@ void c_typecastt::implicit_typecast_arithmetic(
603601
exprt &expr1,
604602
exprt &expr2)
605603
{
606-
const typet &type1=ns.follow(expr1.type());
607-
const typet &type2=ns.follow(expr2.type());
604+
const typet &type1 = expr1.type();
605+
const typet &type2 = expr2.type();
608606

609607
c_typet c_type1=minimum_promotion(type1),
610608
c_type2=minimum_promotion(type2);
@@ -718,17 +716,15 @@ void c_typecastt::do_typecast(exprt &expr, const typet &dest_type)
718716
// special case: array -> pointer is actually
719717
// something like address_of
720718

721-
const typet &src_type=ns.follow(expr.type());
719+
const typet &src_type = expr.type();
722720

723721
if(src_type.id()==ID_array)
724722
{
725723
index_exprt index;
726724
index.array()=expr;
727725
index.index()=from_integer(0, index_type());
728726
index.type()=src_type.subtype();
729-
expr=address_of_exprt(index);
730-
if(ns.follow(expr.type())!=ns.follow(dest_type))
731-
expr.make_typecast(dest_type);
727+
expr = typecast_exprt::conditional_cast(address_of_exprt(index), dest_type);
732728
return;
733729
}
734730

src/ansi-c/c_typecheck_base.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
284284
}
285285

286286
// do initializer, this may change the type
287-
if(follow(new_symbol.type).id()!=ID_code &&
288-
!new_symbol.is_macro)
287+
if(new_symbol.type.id() != ID_code && !new_symbol.is_macro)
289288
do_initializer(new_symbol);
290289

291290
const typet &final_new=follow(new_symbol.type);
@@ -419,22 +418,20 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
419418
PRECONDITION(old_symbol.type.id() != ID_symbol_type);
420419
old_symbol.type=new_symbol.type;
421420
}
422-
else if(final_old.id()==ID_pointer &&
423-
follow(final_old).subtype().id()==ID_code &&
424-
to_code_type(follow(final_old).subtype()).has_ellipsis() &&
425-
final_new.id()==ID_pointer &&
426-
follow(final_new).subtype().id()==ID_code)
421+
else if(
422+
final_old.id() == ID_pointer && final_old.subtype().id() == ID_code &&
423+
to_code_type(final_old.subtype()).has_ellipsis() &&
424+
final_new.id() == ID_pointer && final_new.subtype().id() == ID_code)
427425
{
428426
// to allow
429427
// int (*f) ();
430428
// int (*f) (int)=0;
431429
old_symbol.type=new_symbol.type;
432430
}
433-
else if(final_old.id()==ID_pointer &&
434-
follow(final_old).subtype().id()==ID_code &&
435-
final_new.id()==ID_pointer &&
436-
follow(final_new).subtype().id()==ID_code &&
437-
to_code_type(follow(final_new).subtype()).has_ellipsis())
431+
else if(
432+
final_old.id() == ID_pointer && final_old.subtype().id() == ID_code &&
433+
final_new.id() == ID_pointer && final_new.subtype().id() == ID_code &&
434+
to_code_type(final_new.subtype()).has_ellipsis())
438435
{
439436
// to allow
440437
// int (*f) (int)=0;

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
334334
expr.operands().size() == 1,
335335
"real part retrieval operation should have one operand");
336336

337-
exprt op = expr.op0();
338-
op.type() = follow(op.type());
337+
const exprt &op = expr.op0();
339338

340339
if(op.type().id() != ID_complex)
341340
{
@@ -372,8 +371,7 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
372371
expr.operands().size() == 1,
373372
"imaginary part retrieval operation should have one operand");
374373

375-
exprt op = expr.op0();
376-
op.type() = follow(op.type());
374+
const exprt &op = expr.op0();
377375

378376
if(op.type().id() != ID_complex)
379377
{
@@ -636,8 +634,8 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
636634
for(const auto &c : struct_union_type.components())
637635
{
638636
if(
639-
c.get_anonymous() && (follow(c.type()).id() == ID_struct ||
640-
follow(c.type()).id() == ID_union))
637+
c.get_anonymous() &&
638+
(c.type().id() == ID_struct_tag || c.type().id() == ID_union_tag))
641639
{
642640
if(has_component_rec(c.type(), component_name, *this))
643641
{
@@ -1160,7 +1158,7 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
11601158
if(expr_type.id()==ID_empty)
11611159
return;
11621160

1163-
const typet op_type=follow(op.type());
1161+
const typet op_type = op.type();
11641162

11651163
// cast to same type?
11661164
if(base_type_eq(expr_type, op_type, *this))
@@ -2009,7 +2007,7 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
20092007
// typecheck it now
20102008
typecheck_expr(f_op);
20112009

2012-
const typet f_op_type=follow(f_op.type());
2010+
const typet f_op_type = f_op.type();
20132011

20142012
if(f_op_type.id()!=ID_pointer)
20152013
{
@@ -2853,8 +2851,7 @@ void c_typecheck_baset::typecheck_function_call_arguments(
28532851
{
28542852
// don't know type, just do standard conversion
28552853

2856-
const typet &type=follow(op.type());
2857-
if(type.id()==ID_array)
2854+
if(op.type().id() == ID_array)
28582855
{
28592856
typet dest_type=pointer_type(void_type());
28602857
dest_type.subtype().set(ID_C_constant, true);
@@ -2881,7 +2878,7 @@ void c_typecheck_baset::typecheck_expr_unary_arithmetic(exprt &expr)
28812878

28822879
exprt &operand=expr.op0();
28832880

2884-
const typet &o_type=follow(operand.type());
2881+
const typet &o_type = operand.type();
28852882

28862883
if(o_type.id()==ID_vector)
28872884
{
@@ -2970,15 +2967,16 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)
29702967
exprt &op0=expr.op0();
29712968
exprt &op1=expr.op1();
29722969

2973-
const typet o_type0=follow(op0.type());
2974-
const typet o_type1=follow(op1.type());
2970+
const typet o_type0 = op0.type();
2971+
const typet o_type1 = op1.type();
29752972

29762973
if(o_type0.id()==ID_vector &&
29772974
o_type1.id()==ID_vector)
29782975
{
2979-
if(gcc_vector_types_compatible(
2976+
if(
2977+
gcc_vector_types_compatible(
29802978
to_vector_type(o_type0), to_vector_type(o_type1)) &&
2981-
is_number(follow(o_type0.subtype())))
2979+
is_number(o_type0.subtype()))
29822980
{
29832981
// Vector arithmetic has fairly strict typing rules, no promotion
29842982
if(o_type0!=o_type1)
@@ -3010,8 +3008,8 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)
30103008

30113009
implicit_typecast_arithmetic(op0, op1);
30123010

3013-
const typet &type0=follow(op0.type());
3014-
const typet &type1=follow(op1.type());
3011+
const typet &type0 = op0.type();
3012+
const typet &type1 = op1.type();
30153013

30163014
if(expr.id()==ID_plus || expr.id()==ID_minus ||
30173015
expr.id()==ID_mult || expr.id()==ID_div)
@@ -3083,14 +3081,13 @@ void c_typecheck_baset::typecheck_expr_shifts(shift_exprt &expr)
30833081
exprt &op0=expr.op0();
30843082
exprt &op1=expr.op1();
30853083

3086-
const typet o_type0=follow(op0.type());
3087-
const typet o_type1=follow(op1.type());
3084+
const typet o_type0 = op0.type();
3085+
const typet o_type1 = op1.type();
30883086

30893087
if(o_type0.id()==ID_vector &&
30903088
o_type1.id()==ID_vector)
30913089
{
3092-
if(follow(o_type0.subtype())==follow(o_type1.subtype()) &&
3093-
is_number(follow(o_type0.subtype())))
3090+
if(o_type0.subtype() == o_type1.subtype() && is_number(o_type0.subtype()))
30943091
{
30953092
// {a0, a1, ..., an} >> {b0, b1, ..., bn} ==
30963093
// {a0 >> b0, a1 >> b1, ..., an >> bn}
@@ -3100,9 +3097,9 @@ void c_typecheck_baset::typecheck_expr_shifts(shift_exprt &expr)
31003097
}
31013098
}
31023099

3103-
if(o_type0.id()==ID_vector &&
3104-
is_number(follow(o_type0.subtype())) &&
3105-
is_number(o_type1))
3100+
if(
3101+
o_type0.id() == ID_vector && is_number(o_type0.subtype()) &&
3102+
is_number(o_type1))
31063103
{
31073104
// {a0, a1, ..., an} >> b == {a0 >> b, a1 >> b, ..., an >> b}
31083105
expr.type()=op0.type();
@@ -3120,7 +3117,7 @@ void c_typecheck_baset::typecheck_expr_shifts(shift_exprt &expr)
31203117

31213118
if(expr.id()==ID_shr) // shifting operation depends on types
31223119
{
3123-
const typet &op0_type=follow(op0.type());
3120+
const typet &op0_type = op0.type();
31243121

31253122
if(op0_type.id()==ID_unsignedbv)
31263123
{
@@ -3177,8 +3174,8 @@ void c_typecheck_baset::typecheck_expr_pointer_arithmetic(exprt &expr)
31773174
exprt &op0=expr.op0();
31783175
exprt &op1=expr.op1();
31793176

3180-
const typet &type0=follow(op0.type());
3181-
const typet &type1=follow(op1.type());
3177+
const typet &type0 = op0.type();
3178+
const typet &type1 = op1.type();
31823179

31833180
if(expr.id()==ID_minus ||
31843181
(expr.id()==ID_side_effect && expr.get(ID_statement)==ID_assign_minus))
@@ -3229,7 +3226,7 @@ void c_typecheck_baset::typecheck_expr_pointer_arithmetic(exprt &expr)
32293226
UNREACHABLE;
32303227
}
32313228

3232-
const typet &int_op_type=follow(int_op->type());
3229+
const typet &int_op_type = int_op->type();
32333230

32343231
if(int_op_type.id()==ID_bool ||
32353232
int_op_type.id()==ID_c_bool ||

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,9 @@ designatort c_typecheck_baset::make_designator(
794794
entry.type=tmp_type;
795795
}
796796
else if(
797-
c.get_anonymous() && (follow(c.type()).id() == ID_struct ||
798-
follow(c.type()).id() == ID_union) &&
797+
c.get_anonymous() &&
798+
(c.type().id() == ID_struct_tag ||
799+
c.type().id() == ID_union_tag) &&
799800
has_component_rec(c.type(), component_name, *this))
800801
{
801802
entry.index=number;

src/ansi-c/expr2c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ std::string expr2ct::convert_complex(
12871287
// float complex CMPLXF(float x, float y);
12881288
// long double complex CMPLXL(long double x, long double y);
12891289

1290-
const typet &subtype = ns.follow(src.type()).subtype();
1290+
const typet &subtype = src.type().subtype();
12911291

12921292
std::string name;
12931293

@@ -1749,7 +1749,7 @@ std::string expr2ct::convert_constant(
17491749
unsigned &precedence)
17501750
{
17511751
const irep_idt &base=src.get(ID_C_base);
1752-
const typet &type=ns.follow(src.type());
1752+
const typet &type = src.type();
17531753
const irep_idt value=src.get_value();
17541754
std::string dest;
17551755

0 commit comments

Comments
 (0)