Skip to content

Commit b6707bb

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 80012ad commit b6707bb

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
@@ -629,6 +629,20 @@ void goto_symex_statet::rename_address(
629629
}
630630
}
631631

632+
/// Return the type corresponding to a symbol or tag. Empty optional if \p type
633+
/// is neither a symbol or a tag.
634+
static optionalt<typet>
635+
type_of_symbol_or_tag(const typet &type, const namespacet &ns)
636+
{
637+
if(type.id() == ID_symbol_type)
638+
return ns.lookup(to_symbol_type(type)).type;
639+
if(type.id() == ID_union_tag)
640+
return ns.lookup(to_union_tag_type(type)).type;
641+
if(type.id() == ID_struct_tag)
642+
return ns.lookup(to_struct_tag_type(type)).type;
643+
return {};
644+
}
645+
632646
void goto_symex_statet::rename(
633647
typet &type,
634648
const irep_idt &l1_identifier,
@@ -685,22 +699,9 @@ void goto_symex_statet::rename(
685699
{
686700
rename(to_pointer_type(type).subtype(), irep_idt(), ns, level);
687701
}
688-
else if(type.id() == ID_symbol_type)
689-
{
690-
const symbolt &symbol = ns.lookup(to_symbol_type(type));
691-
type = symbol.type;
692-
rename(type, l1_identifier, ns, level);
693-
}
694-
else if(type.id() == ID_union_tag)
695-
{
696-
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
697-
type = symbol.type;
698-
rename(type, l1_identifier, ns, level);
699-
}
700-
else if(type.id() == ID_struct_tag)
702+
else if(const auto &followed_type = type_of_symbol_or_tag(type, ns))
701703
{
702-
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
703-
type=symbol.type;
704+
type = *followed_type;
704705
rename(type, l1_identifier, ns, level);
705706
}
706707

0 commit comments

Comments
 (0)