Skip to content

Commit db81667

Browse files
committed
Add namespacet::follow_struct_union_tag to simplify follow_tag uses
Replacing namespacet::follow by namespacet::follow_tag produced several instances that require expanding composite data types, without a need to distinguish structs vs unions.
1 parent baaccb6 commit db81667

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: src/util/namespace.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ namespace_baset::follow_tag(const c_enum_tag_typet &src) const
9292
return to_c_enum_type(symbol.type);
9393
}
9494

95+
const struct_union_typet &follow_struct_union_tag(const tag_typet &src) const
96+
{
97+
PRECONDITION(src.id() == ID_struct_tag || src.id() == ID_union_tag);
98+
const symbolt &symbol = lookup(src.get_identifier());
99+
CHECK_RETURN(symbol.is_type);
100+
CHECK_RETURN(symbol.type.id() == ID_struct || symbol.type.id() == ID_union);
101+
return to_struct_union_type(symbol.type);
102+
}
103+
95104
/// Follow macros to their values in a given expression.
96105
/// \param expr: The expression to follow macros in.
97106
void namespace_baset::follow_macros(exprt &expr) const

Diff for: src/util/namespace.h

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class namespace_baset
6868
const struct_typet &follow_tag(const struct_tag_typet &) const;
6969
const c_enum_typet &follow_tag(const c_enum_tag_typet &) const;
7070

71+
/// Resolve a `struct_tag_typet` or `union_tag_typet` to the complete version.
72+
const struct_union_typet &follow_struct_union_tag(const tag_typet &) const;
73+
7174
/// Returns the minimal integer n such that there is no symbol (in any of the
7275
/// symbol tables) whose name is of the form "An" where A is \p prefix.
7376
/// The intended use case is finding the next available symbol name for a

0 commit comments

Comments
 (0)