Skip to content

Commit 79607dc

Browse files
Refactor rename using expr_try_dynamic_cast
Use expr_try_dynamic_cast to check the type and convert in one instruction, which makes the code clearer.
1 parent 542efa8 commit 79607dc

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -668,18 +668,15 @@ void goto_symex_statet::rename(
668668
}
669669
}
670670

671-
if(type.id()==ID_array)
671+
if(const auto &array_type = type_try_dynamic_cast<array_typet>(type))
672672
{
673-
auto &array_type = to_array_type(type);
674-
rename(array_type.subtype(), irep_idt(), ns, level);
675-
rename(array_type.size(), ns, level);
673+
rename(array_type->subtype(), irep_idt(), ns, level);
674+
rename(array_type->size(), ns, level);
676675
}
677-
else if(type.id() == ID_struct || type.id() == ID_union)
676+
else if(
677+
const auto &s_u_type = type_try_dynamic_cast<struct_union_typet>(type))
678678
{
679-
struct_union_typet &s_u_type=to_struct_union_type(type);
680-
struct_union_typet::componentst &components=s_u_type.components();
681-
682-
for(auto &component : components)
679+
for(auto &component : s_u_type->components())
683680
{
684681
// be careful, or it might get cyclic
685682
if(component.type().id() == ID_array)

0 commit comments

Comments
 (0)