Skip to content

Commit 56f0577

Browse files
author
Daniel Kroening
committed
use a struct_tag to identify base classes
1 parent 356ab40 commit 56f0577

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

src/util/std_types.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ struct_union_typet::component_type(const irep_idt &component_name) const
7070
return c.type();
7171
}
7272

73+
struct_tag_typet &struct_typet::baset::type()
74+
{
75+
return to_struct_tag_type(exprt::type());
76+
}
77+
78+
const struct_tag_typet &struct_typet::baset::type() const
79+
{
80+
return to_struct_tag_type(exprt::type());
81+
}
82+
83+
struct_typet::baset::baset(const struct_tag_typet &base) : exprt(ID_base, base)
84+
{
85+
}
86+
87+
void struct_typet::add_base(const struct_tag_typet &base)
88+
{
89+
bases().push_back(baset(base));
90+
}
91+
92+
optionalt<struct_typet::baset> struct_typet::get_base(const irep_idt &id) const
93+
{
94+
for(const auto &b : bases())
95+
{
96+
if(to_struct_tag_type(b.type()).get_identifier() == id)
97+
return b;
98+
}
99+
return {};
100+
}
101+
73102
/// Returns true if the struct is a prefix of \a other, i.e., if this struct
74103
/// has n components then the component types and names of this struct must
75104
/// match the first n components of \a other struct.

src/util/std_types.h

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ inline struct_union_typet &to_struct_union_type(typet &type)
271271
return static_cast<struct_union_typet &>(type);
272272
}
273273

274+
class struct_tag_typet;
275+
274276
/// Structure type, corresponds to C style structs
275277
class struct_typet:public struct_union_typet
276278
{
@@ -291,19 +293,9 @@ class struct_typet:public struct_union_typet
291293
class baset : public exprt
292294
{
293295
public:
294-
symbol_typet &type()
295-
{
296-
return to_symbol_type(exprt::type());
297-
}
298-
299-
const symbol_typet &type() const
300-
{
301-
return to_symbol_type(exprt::type());
302-
}
303-
304-
explicit baset(const symbol_typet &base) : exprt(ID_base, base)
305-
{
306-
}
296+
struct_tag_typet &type();
297+
const struct_tag_typet &type() const;
298+
explicit baset(const struct_tag_typet &base);
307299
};
308300

309301
typedef std::vector<baset> basest;
@@ -322,23 +314,12 @@ class struct_typet:public struct_union_typet
322314

323315
/// Add a base class/struct
324316
/// \param base: Type of case/class struct to be added.
325-
void add_base(const symbol_typet &base)
326-
{
327-
bases().push_back(baset(base));
328-
}
317+
void add_base(const struct_tag_typet &base);
329318

330319
/// Return the base with the given name, if exists.
331320
/// \param id The name of the base we are looking for.
332321
/// \return The base if exists.
333-
optionalt<baset> get_base(const irep_idt &id) const
334-
{
335-
for(const auto &b : bases())
336-
{
337-
if(to_symbol_type(b.type()).get_identifier() == id)
338-
return b;
339-
}
340-
return {};
341-
}
322+
optionalt<baset> get_base(const irep_idt &id) const;
342323

343324
/// Test whether `id` is a base class/struct.
344325
/// \param id: symbol type name

0 commit comments

Comments
 (0)