Skip to content

Commit 794f6f7

Browse files
committed
Clean up ansi_c_convert_typet's interface
The need to invoke read() was only specified in a comment. Make the constructor take care of this. Also, make the constructor initialise all members rather than leaving this to clear(), which is thus no longer necessary.
1 parent 957f87c commit 794f6f7

File tree

4 files changed

+57
-54
lines changed

4 files changed

+57
-54
lines changed

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ Author: Daniel Kroening, [email protected]
1919

2020
#include "gcc_types.h"
2121

22-
void ansi_c_convert_typet::read(const typet &type)
23-
{
24-
clear();
25-
source_location=type.source_location();
26-
read_rec(type);
27-
}
28-
2922
void ansi_c_convert_typet::read_rec(const typet &type)
3023
{
3124
if(type.id()==ID_merged_type)

src/ansi-c/ansi_c_convert_type.h

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,51 +56,68 @@ class ansi_c_convert_typet
5656
// qualifiers
5757
c_qualifierst c_qualifiers;
5858

59-
virtual void read(const typet &type);
6059
virtual void write(typet &type);
6160

6261
source_locationt source_location;
6362

6463
std::list<typet> other;
6564

66-
explicit ansi_c_convert_typet(message_handlert &_message_handler)
67-
: message_handler(_message_handler)
68-
// class members are initialized by calling read()
69-
{
70-
}
71-
72-
virtual void clear()
65+
ansi_c_convert_typet(message_handlert &_message_handler, const typet &type)
66+
: ansi_c_convert_typet(_message_handler)
7367
{
74-
unsigned_cnt=signed_cnt=char_cnt=int_cnt=short_cnt=
75-
long_cnt=double_cnt=float_cnt=c_bool_cnt=proper_bool_cnt=complex_cnt=
76-
int8_cnt=int16_cnt=int32_cnt=int64_cnt=
77-
ptr32_cnt=ptr64_cnt=
78-
gcc_float16_cnt=
79-
gcc_float32_cnt=gcc_float32x_cnt=
80-
gcc_float64_cnt=gcc_float64x_cnt=
81-
gcc_float128_cnt=gcc_float128x_cnt=
82-
gcc_int128_cnt=bv_cnt=floatbv_cnt=fixedbv_cnt=0;
83-
vector_size.make_nil();
84-
alignment.make_nil();
85-
bv_width.make_nil();
86-
fraction_width.make_nil();
87-
msc_based.make_nil();
88-
gcc_attribute_mode.make_nil();
89-
90-
assigns.clear();
91-
requires.clear();
92-
ensures.clear();
93-
94-
packed=aligned=constructor=destructor=false;
95-
96-
other.clear();
97-
c_storage_spec.clear();
98-
c_qualifiers.clear();
68+
source_location = type.source_location();
69+
read_rec(type);
9970
}
10071

10172
protected:
10273
message_handlert &message_handler;
10374

75+
// Default-initialize all members. To be used by classes deriving from this
76+
// one to make sure additional members can be initialized before invoking
77+
// read_rec.
78+
explicit ansi_c_convert_typet(message_handlert &_message_handler)
79+
: unsigned_cnt(0),
80+
signed_cnt(0),
81+
char_cnt(0),
82+
int_cnt(0),
83+
short_cnt(0),
84+
long_cnt(0),
85+
double_cnt(0),
86+
float_cnt(0),
87+
c_bool_cnt(0),
88+
proper_bool_cnt(0),
89+
complex_cnt(0),
90+
int8_cnt(0),
91+
int16_cnt(0),
92+
int32_cnt(0),
93+
int64_cnt(0),
94+
ptr32_cnt(0),
95+
ptr64_cnt(0),
96+
gcc_float16_cnt(0),
97+
gcc_float32_cnt(0),
98+
gcc_float32x_cnt(0),
99+
gcc_float64_cnt(0),
100+
gcc_float64x_cnt(0),
101+
gcc_float128_cnt(0),
102+
gcc_float128x_cnt(0),
103+
gcc_int128_cnt(0),
104+
bv_cnt(0),
105+
floatbv_cnt(0),
106+
fixedbv_cnt(0),
107+
gcc_attribute_mode(static_cast<const typet &>(get_nil_irep())),
108+
packed(false),
109+
aligned(false),
110+
vector_size(nil_exprt{}),
111+
alignment(nil_exprt{}),
112+
bv_width(nil_exprt{}),
113+
fraction_width(nil_exprt{}),
114+
msc_based(nil_exprt{}),
115+
constructor(false),
116+
destructor(false),
117+
message_handler(_message_handler)
118+
{
119+
}
120+
104121
virtual void read_rec(const typet &type);
105122
virtual void build_type_with_subtype(typet &type) const;
106123
virtual void set_attributes(typet &type) const;

src/ansi-c/c_typecheck_type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ void c_typecheck_baset::typecheck_type(typet &type)
3535
{
3636
// we first convert, and then check
3737
{
38-
ansi_c_convert_typet ansi_c_convert_type(get_message_handler());
39-
40-
ansi_c_convert_type.read(type);
38+
ansi_c_convert_typet ansi_c_convert_type{get_message_handler(), type};
4139
ansi_c_convert_type.write(type);
4240
}
4341

src/cpp/cpp_convert_type.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,16 @@ class cpp_convert_typet : public ansi_c_convert_typet
3333
void write(typet &type) override;
3434

3535
cpp_convert_typet(message_handlert &message_handler, const typet &type)
36-
: ansi_c_convert_typet(message_handler)
36+
: ansi_c_convert_typet(message_handler),
37+
wchar_t_count(0),
38+
char16_t_count(0),
39+
char32_t_count(0)
3740
{
38-
read(type);
41+
source_location = type.source_location();
42+
read_rec(type);
3943
}
4044

4145
protected:
42-
void clear() override
43-
{
44-
wchar_t_count = 0;
45-
char16_t_count = 0;
46-
char32_t_count = 0;
47-
48-
ansi_c_convert_typet::clear();
49-
}
50-
5146
void read_rec(const typet &type) override;
5247
void read_function_type(const typet &type);
5348
void read_template(const typet &type);

0 commit comments

Comments
 (0)