Skip to content

Commit 152e39a

Browse files
committed
Add support for getting components by name to struct_exprt
1 parent e448db6 commit 152e39a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/util/std_expr.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,24 @@ class struct_exprt:public exprt
18231823
exprt(ID_struct, _type)
18241824
{
18251825
}
1826+
1827+
/// \return The expression for a named component of this struct.
1828+
exprt &component(const irep_idt &name)
1829+
{
1830+
const auto index = to_struct_type(type()).component_number(name);
1831+
DATA_INVARIANT(
1832+
index < operands().size(), "component matching index should exist");
1833+
return operands()[index];
1834+
}
1835+
1836+
/// \return The expression for a named component of this struct.
1837+
const exprt &component(const irep_idt &name) const
1838+
{
1839+
const auto index = to_struct_type(type()).component_number(name);
1840+
DATA_INVARIANT(
1841+
index < operands().size(), "component matching index should exist");
1842+
return operands()[index];
1843+
}
18261844
};
18271845

18281846
/*! \brief Cast a generic exprt to a \ref struct_exprt

0 commit comments

Comments
 (0)