Skip to content

Commit dc9407a

Browse files
Extract a type_of_symbol_or_tag function
It makes the rename function simpler, as well as allowing to document and make more reusable the piece of code that is concerned.
1 parent 5ea209d commit dc9407a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,20 @@ void goto_symex_statet::rename_address(
644644
}
645645
}
646646

647+
/// Return the type corresponding to a symbol or tag. Empty optional if \p type
648+
/// is neither a symbol or a tag.
649+
static optionalt<typet>
650+
type_of_symbol_or_tag(const typet &type, const namespacet &ns)
651+
{
652+
if(type.id() == ID_symbol_type)
653+
return ns.lookup(to_symbol_type(type)).type;
654+
if(type.id() == ID_union_tag)
655+
return ns.lookup(to_union_tag_type(type)).type;
656+
if(type.id() == ID_struct_tag)
657+
return ns.lookup(to_struct_tag_type(type)).type;
658+
return {};
659+
}
660+
647661
void goto_symex_statet::rename(
648662
typet &type,
649663
const irep_idt &l1_identifier,
@@ -700,22 +714,9 @@ void goto_symex_statet::rename(
700714
{
701715
rename(to_pointer_type(type).subtype(), irep_idt(), ns, level);
702716
}
703-
else if(type.id() == ID_symbol_type)
704-
{
705-
const symbolt &symbol = ns.lookup(to_symbol_type(type));
706-
type = symbol.type;
707-
rename(type, l1_identifier, ns, level);
708-
}
709-
else if(type.id() == ID_union_tag)
710-
{
711-
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
712-
type = symbol.type;
713-
rename(type, l1_identifier, ns, level);
714-
}
715-
else if(type.id() == ID_struct_tag)
717+
else if(const auto &followed_type = type_of_symbol_or_tag(type, ns))
716718
{
717-
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
718-
type=symbol.type;
719+
type = *followed_type;
719720
rename(type, l1_identifier, ns, level);
720721
}
721722

0 commit comments

Comments
 (0)