Skip to content

Commit 711c9f7

Browse files
committed
Use ns.follow on type of struct
Implementation moved into `.cpp` as it was getting bigger and required the full include of `namespace.h`, not just a forward declaration.
1 parent 152e39a commit 711c9f7

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/util/std_expr.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
#include "std_expr.h"
1010

11+
#include <util/namespace.h>
12+
1113
#include <cassert>
1214

1315
#include "arith_tools.h"
@@ -167,3 +169,22 @@ address_of_exprt::address_of_exprt(const exprt &_op):
167169
unary_exprt(ID_address_of, _op, pointer_type(_op.type()))
168170
{
169171
}
172+
173+
/// \return The expression for a named component of this struct.
174+
exprt &struct_exprt::component(const irep_idt &name, const namespacet &ns)
175+
{
176+
const auto index = to_struct_type(ns.follow(type())).component_number(name);
177+
DATA_INVARIANT(
178+
index < operands().size(), "component matching index should exist");
179+
return operands()[index];
180+
}
181+
182+
/// \return The expression for a named component of this struct.
183+
const exprt &
184+
struct_exprt::component(const irep_idt &name, const namespacet &ns) const
185+
{
186+
const auto index = to_struct_type(ns.follow(type())).component_number(name);
187+
DATA_INVARIANT(
188+
index < operands().size(), "component matching index should exist");
189+
return operands()[index];
190+
}

src/util/std_expr.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,23 +1824,8 @@ class struct_exprt:public exprt
18241824
{
18251825
}
18261826

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-
}
1827+
exprt &component(const irep_idt &name, const namespacet &ns);
1828+
const exprt &component(const irep_idt &name, const namespacet &ns) const;
18441829
};
18451830

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

0 commit comments

Comments
 (0)