Skip to content

Commit 84228a4

Browse files
kroeningJoel Allred
authored andcommitted
use a struct_tag to identify base classes
1 parent 32f9b13 commit 84228a4

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

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

308300
typedef std::vector<baset> basest;
@@ -321,23 +313,12 @@ class struct_typet:public struct_union_typet
321313

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

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

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

0 commit comments

Comments
 (0)