Skip to content

Commit b06c0cb

Browse files
author
Daniel Kroening
committed
use a struct_tag to identify base classes
1 parent f5f870b commit b06c0cb

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
@@ -272,6 +272,8 @@ inline struct_union_typet &to_struct_union_type(typet &type)
272272
return static_cast<struct_union_typet &>(type);
273273
}
274274

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

310302
typedef std::vector<baset> basest;
@@ -323,23 +315,12 @@ class struct_typet:public struct_union_typet
323315

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

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

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

0 commit comments

Comments
 (0)