Skip to content

Commit fe2e118

Browse files
author
Daniel Kroening
authored
Merge pull request #2991 from diffblue/type-cleanup
cleanup accesses to subtype() and subtypes()
2 parents f9a09d8 + 02a1b95 commit fe2e118

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/util/mathematical_types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class real_typet : public typet
5555

5656
/// A type for mathematical functions (do not confuse with functions/methods
5757
/// in code)
58-
class mathematical_function_typet : public typet
58+
class mathematical_function_typet : public type_with_subtypest
5959
{
6060
public:
6161
// the domain of the function is composed of zero, one, or
@@ -88,7 +88,7 @@ class mathematical_function_typet : public typet
8888
using domaint = std::vector<variablet>;
8989

9090
mathematical_function_typet(const domaint &_domain, const typet &_codomain)
91-
: typet(ID_mathematical_function)
91+
: type_with_subtypest(ID_mathematical_function)
9292
{
9393
subtypes().resize(2);
9494
domain() = _domain;
@@ -97,12 +97,12 @@ class mathematical_function_typet : public typet
9797

9898
domaint &domain()
9999
{
100-
return (domaint &)subtypes()[0].subtypes();
100+
return (domaint &)to_type_with_subtypes(subtypes()[0]).subtypes();
101101
}
102102

103103
const domaint &domain() const
104104
{
105-
return (const domaint &)subtypes()[0].subtypes();
105+
return (const domaint &)to_type_with_subtypes(subtypes()[0]).subtypes();
106106
}
107107

108108
variablet &add_variable()

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)