Skip to content

Commit cf16b67

Browse files
author
Daniel Kroening
committed
add to_type_with_subtype, to_type_with_subtypes
1 parent f9a09d8 commit cf16b67

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/util/type.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ class type_with_subtypet:public typet
110110
#endif
111111
};
112112

113+
inline const type_with_subtypet &to_type_with_subtype(const typet &type)
114+
{
115+
PRECONDITION(type.has_subtype());
116+
return static_cast<const type_with_subtypet &>(type);
117+
}
118+
119+
inline type_with_subtypet &to_type_with_subtype(typet &type)
120+
{
121+
PRECONDITION(type.has_subtype());
122+
return static_cast<type_with_subtypet &>(type);
123+
}
124+
113125
/// Type with multiple subtypes.
114126
class type_with_subtypest:public typet
115127
{
@@ -133,15 +145,25 @@ class type_with_subtypest:public typet
133145
#endif
134146
};
135147

148+
inline const type_with_subtypest &to_type_with_subtypes(const typet &type)
149+
{
150+
return static_cast<const type_with_subtypest &>(type);
151+
}
152+
153+
inline type_with_subtypest &to_type_with_subtypes(typet &type)
154+
{
155+
return static_cast<type_with_subtypest &>(type);
156+
}
157+
136158
#define forall_subtypes(it, type) \
137159
if((type).has_subtypes()) /* NOLINT(readability/braces) */ \
138-
for(typet::subtypest::const_iterator it=(type).subtypes().begin(), \
139-
it##_end=(type).subtypes().end(); \
160+
for(type_with_subtypest::subtypest::const_iterator it=to_type_with_subtypes(type).subtypes().begin(), \
161+
it##_end=to_type_with_subtypes(type).subtypes().end(); \
140162
it!=it##_end; ++it)
141163

142164
#define Forall_subtypes(it, type) \
143165
if((type).has_subtypes()) /* NOLINT(readability/braces) */ \
144-
for(typet::subtypest::iterator it=(type).subtypes().begin(); \
145-
it!=(type).subtypes().end(); ++it)
166+
for(type_with_subtypest::subtypest::iterator it=to_type_with_subtypes(type).subtypes().begin(); \
167+
it!=to_type_with_subtypes(type).subtypes().end(); ++it)
146168

147169
#endif // CPROVER_UTIL_TYPE_H

0 commit comments

Comments
 (0)