|
8 | 8 |
|
9 | 9 | #include "std_expr.h"
|
10 | 10 |
|
| 11 | +#include <util/namespace.h> |
| 12 | + |
11 | 13 | #include <cassert>
|
12 | 14 |
|
13 | 15 | #include "arith_tools.h"
|
@@ -167,3 +169,31 @@ address_of_exprt::address_of_exprt(const exprt &_op):
|
167 | 169 | unary_exprt(ID_address_of, _op, pointer_type(_op.type()))
|
168 | 170 | {
|
169 | 171 | }
|
| 172 | + |
| 173 | +// Implementation of struct_exprt::component for const / non const overloads. |
| 174 | +template <typename T> |
| 175 | +auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) |
| 176 | + -> decltype(struct_expr.op0()) |
| 177 | +{ |
| 178 | + static_assert( |
| 179 | + std::is_base_of<struct_exprt, T>::value, "T must be a struct_exprt."); |
| 180 | + const auto index = |
| 181 | + to_struct_type(ns.follow(struct_expr.type())).component_number(name); |
| 182 | + DATA_INVARIANT( |
| 183 | + index < struct_expr.operands().size(), |
| 184 | + "component matching index should exist"); |
| 185 | + return struct_expr.operands()[index]; |
| 186 | +} |
| 187 | + |
| 188 | +/// \return The expression for a named component of this struct. |
| 189 | +exprt &struct_exprt::component(const irep_idt &name, const namespacet &ns) |
| 190 | +{ |
| 191 | + return ::component(*this, name, ns); |
| 192 | +} |
| 193 | + |
| 194 | +/// \return The expression for a named component of this struct. |
| 195 | +const exprt & |
| 196 | +struct_exprt::component(const irep_idt &name, const namespacet &ns) const |
| 197 | +{ |
| 198 | + return ::component(*this, name, ns); |
| 199 | +} |
0 commit comments