Skip to content

Commit 61b2d40

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 dc9407a commit 61b2d40

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
@@ -690,18 +690,15 @@ void goto_symex_statet::rename(
690690
}
691691
}
692692

693-
if(type.id()==ID_array)
693+
if(const auto &array_type = type_try_dynamic_cast<array_typet>(type))
694694
{
695-
auto &array_type = to_array_type(type);
696-
rename(array_type.subtype(), irep_idt(), ns, level);
697-
rename(array_type.size(), ns, level);
695+
rename(array_type->subtype(), irep_idt(), ns, level);
696+
rename(array_type->size(), ns, level);
698697
}
699-
else if(type.id() == ID_struct || type.id() == ID_union)
698+
else if(
699+
const auto &s_u_type = type_try_dynamic_cast<struct_union_typet>(type))
700700
{
701-
struct_union_typet &s_u_type=to_struct_union_type(type);
702-
struct_union_typet::componentst &components=s_u_type.components();
703-
704-
for(auto &component : components)
701+
for(auto &component : s_u_type->components())
705702
{
706703
// be careful, or it might get cyclic
707704
if(component.type().id() == ID_array)

0 commit comments

Comments
 (0)