Skip to content

Commit 4c671f1

Browse files
author
kroening
committed
Rename enum/struct/union tags in the same way as symbol
types git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@6387 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 8087244 commit 4c671f1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/util/rename_symbol.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ bool rename_symbolt::rename(typet &dest) const
237237
result=false;
238238
}
239239
}
240+
else if(dest.id()==ID_c_enum_tag ||
241+
dest.id()==ID_struct_tag ||
242+
dest.id()==ID_union_tag)
243+
{
244+
type_mapt::const_iterator it=
245+
type_map.find(to_tag_type(dest).get_identifier());
246+
247+
if(it!=type_map.end())
248+
{
249+
to_tag_type(dest).set_identifier(it->second);
250+
result=false;
251+
}
252+
}
240253
else if(dest.id()==ID_array)
241254
{
242255
array_typet &array_type=to_array_type(dest);
@@ -307,6 +320,10 @@ bool rename_symbolt::have_to_rename(const typet &dest) const
307320
}
308321
else if(dest.id()==ID_symbol)
309322
return type_map.find(dest.get(ID_identifier))!=type_map.end();
323+
else if(dest.id()==ID_c_enum_tag ||
324+
dest.id()==ID_struct_tag ||
325+
dest.id()==ID_union_tag)
326+
return type_map.find(to_tag_type(dest).get_identifier())!=type_map.end();
310327
else if(dest.id()==ID_array)
311328
return have_to_rename(to_array_type(dest).size());
312329

src/util/std_types.h

+29
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,35 @@ class tag_typet:public typet
481481
}
482482
};
483483

484+
/*! \brief Cast a generic typet to a \ref tag_typet
485+
*
486+
* This is an unchecked conversion. \a type must be known to be \ref
487+
* tag_typet.
488+
*
489+
* \param type Source type
490+
* \return Object of type \ref tag_typet
491+
*
492+
* \ingroup gr_std_types
493+
*/
494+
extern inline const tag_typet &to_tag_type(const typet &type)
495+
{
496+
assert(type.id()==ID_c_enum_tag ||
497+
type.id()==ID_struct_tag ||
498+
type.id()==ID_union_tag);
499+
return static_cast<const tag_typet &>(type);
500+
}
501+
502+
/*! \copydoc to_tag_type(const typet &)
503+
* \ingroup gr_std_types
504+
*/
505+
extern inline tag_typet &to_tag_type(typet &type)
506+
{
507+
assert(type.id()==ID_c_enum_tag ||
508+
type.id()==ID_struct_tag ||
509+
type.id()==ID_union_tag);
510+
return static_cast<tag_typet &>(type);
511+
}
512+
484513
/*! \brief A struct tag type
485514
*/
486515

0 commit comments

Comments
 (0)