Skip to content

Commit 3fe510e

Browse files
authored
Merge pull request #7561 from diffblue/remove_typet_subtype
remove typet::subtype()
2 parents d7099ae + 907e28f commit 3fe510e

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

src/cpp/cpp_template_type.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ class template_typet:public typet
3434
return (const template_parameterst &)find(ID_template_parameters).get_sub();
3535
}
3636

37-
using typet::subtype;
37+
const typet &subtype() const
38+
{
39+
if(get_sub().empty())
40+
return static_cast<const typet &>(get_nil_irep());
41+
return static_cast<const typet &>(get_sub().front());
42+
}
43+
44+
typet &subtype()
45+
{
46+
return add_subtype();
47+
}
3848
};
3949

4050
inline template_typet &to_template_type(typet &type)

src/util/c_types.h

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class c_bit_field_typet : public bitvector_typet
2222
explicit c_bit_field_typet(typet _subtype, std::size_t width)
2323
: bitvector_typet(ID_c_bit_field, width)
2424
{
25-
subtype().swap(_subtype);
25+
add_subtype() = std::move(_subtype);
2626
}
2727

2828
// These have a sub-type. The preferred way to access it
@@ -36,6 +36,28 @@ class c_bit_field_typet : public bitvector_typet
3636
{
3737
return subtype();
3838
}
39+
40+
// Use .underlying_type() instead -- this method will be removed
41+
const typet &subtype() const
42+
{
43+
// The existence of get_sub() front is enforced by check(...)
44+
return static_cast<const typet &>(get_sub().front());
45+
}
46+
47+
// Use .underlying_type() instead -- this method will be removed
48+
typet &subtype()
49+
{
50+
// The existence of get_sub() front is enforced by check(...)
51+
return static_cast<typet &>(get_sub().front());
52+
}
53+
54+
static void check(
55+
const typet &type,
56+
const validation_modet vm = validation_modet::INVARIANT)
57+
{
58+
bitvector_typet::check(type, vm);
59+
type_with_subtypet::check(type, vm);
60+
}
3961
};
4062

4163
/// Check whether a reference to a typet is a \ref c_bit_field_typet.
@@ -58,7 +80,7 @@ inline bool can_cast_type<c_bit_field_typet>(const typet &type)
5880
inline const c_bit_field_typet &to_c_bit_field_type(const typet &type)
5981
{
6082
PRECONDITION(can_cast_type<c_bit_field_typet>(type));
61-
type_with_subtypet::check(type);
83+
c_bit_field_typet::check(type);
6284
return static_cast<const c_bit_field_typet &>(type);
6385
}
6486

src/util/pointer_expr.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class pointer_typet : public bitvector_typet
2626
pointer_typet(typet _base_type, std::size_t width)
2727
: bitvector_typet(ID_pointer, width)
2828
{
29-
subtype().swap(_base_type);
29+
add_subtype() = std::move(_base_type);
3030
}
3131

3232
/// The type of the data what we point to.
@@ -45,6 +45,20 @@ class pointer_typet : public bitvector_typet
4545
return subtype();
4646
}
4747

48+
// Use .base_type() instead -- this method will be removed
49+
const typet &subtype() const
50+
{
51+
// The existence of get_sub() front is enforced by check(...)
52+
return static_cast<const typet &>(get_sub().front());
53+
}
54+
55+
// Use .base_type() instead -- this method will be removed
56+
typet &subtype()
57+
{
58+
// The existence of get_sub() front is enforced by check(...)
59+
return static_cast<typet &>(get_sub().front());
60+
}
61+
4862
signedbv_typet difference_type() const
4963
{
5064
return signedbv_typet(get_width());
@@ -54,8 +68,8 @@ class pointer_typet : public bitvector_typet
5468
const typet &type,
5569
const validation_modet vm = validation_modet::INVARIANT)
5670
{
71+
bitvector_typet::check(type, vm);
5772
type_with_subtypet::check(type);
58-
DATA_CHECK(vm, !type.get(ID_width).empty(), "pointer must have width");
5973
}
6074
};
6175

src/util/type.h

+1-19
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,10 @@ class typet:public irept
4141
#else
4242
typet(irep_idt _id, typet _subtype) : irept(std::move(_id))
4343
{
44-
subtype() = std::move(_subtype);
44+
add_subtype() = std::move(_subtype);
4545
}
4646
#endif
4747

48-
// Deliberately protected -- use type-specific accessor methods instead.
49-
protected:
50-
const typet &subtype() const
51-
{
52-
if(get_sub().empty())
53-
return static_cast<const typet &>(get_nil_irep());
54-
return static_cast<const typet &>(get_sub().front());
55-
}
56-
57-
typet &subtype()
58-
{
59-
subt &sub=get_sub();
60-
if(sub.empty())
61-
sub.resize(1);
62-
return static_cast<typet &>(sub.front());
63-
}
64-
65-
public:
6648
// This method allows the construction of a type with a subtype by
6749
// starting from a type without subtype. It avoids copying the contents
6850
// of the type. The primary use-case are parsers, where a copy could be

0 commit comments

Comments
 (0)