Skip to content

Commit 0e61c89

Browse files
committed
Add and cleanup symbolt constructors
To the extent possible, apply resource-acquisition-is-initialisation. The constructors ensure that at least the most essential fields (name, type, mode) are set. Constructors are now consistent in what they do, and do not set the base_name in addition to the name.
1 parent eb0472e commit 0e61c89

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

src/goto-instrument/dump_c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ void dump_ct::operator()(std::ostream &os)
9191
(symbol.type.id() == ID_union || symbol.type.id() == ID_struct) &&
9292
!symbol.is_type)
9393
{
94-
type_symbolt ts{symbol.type};
95-
ts.mode = symbol.mode;
94+
std::string tag_name;
9695
if(mode == ID_C)
97-
ts.name = "tag-" + type2name(symbol.type, ns);
96+
tag_name = "tag-" + type2name(symbol.type, ns);
9897
else if(mode == ID_cpp)
99-
ts.name = "tag-" + cpp_type2name(symbol.type);
98+
tag_name = "tag-" + cpp_type2name(symbol.type);
10099
else
101100
UNREACHABLE;
101+
type_symbolt ts{tag_name, symbol.type, symbol.mode};
102102
typet &type =
103103
copied_symbol_table.get_writeable_ref(named_symbol.first).type;
104104
if(ts.type.id() == ID_union)

src/util/fresh_symbol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ symbolt &get_fresh_aux_symbol(
4848
identifier = get_new_name(identifier, ns, '$');
4949
std::string basename = id2string(identifier).substr(prefix_size);
5050

51-
auxiliary_symbolt new_symbol(basename, type);
52-
new_symbol.name = identifier;
51+
auxiliary_symbolt new_symbol(identifier, type, symbol_mode);
52+
new_symbol.base_name = basename;
5353
new_symbol.location = source_location;
54-
new_symbol.mode = symbol_mode;
5554
std::pair<symbolt &, bool> res = symbol_table.insert(std::move(new_symbol));
5655
CHECK_RETURN(res.second);
5756

src/util/symbol.h

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,39 @@ class symbolt
5858
}
5959

6060
// global use
61-
bool is_type, is_macro, is_exported,
62-
is_input, is_output, is_state_var, is_property;
61+
bool is_type = false;
62+
bool is_macro = false;
63+
bool is_exported = false;
64+
bool is_input = false;
65+
bool is_output = false;
66+
bool is_state_var = false;
67+
bool is_property = false;
6368

6469
// ANSI-C
65-
bool is_static_lifetime, is_thread_local;
66-
bool is_lvalue, is_file_local, is_extern, is_volatile,
67-
is_parameter, is_auxiliary, is_weak;
70+
bool is_static_lifetime = false;
71+
bool is_thread_local = false;
72+
bool is_lvalue = false;
73+
bool is_file_local = false;
74+
bool is_extern = false;
75+
bool is_volatile = false;
76+
bool is_parameter = false;
77+
bool is_auxiliary = false;
78+
bool is_weak = false;
6879

6980
symbolt()
81+
: type(static_cast<const typet &>(get_nil_irep())),
82+
value(static_cast<const exprt &>(get_nil_irep())),
83+
location(source_locationt::nil())
84+
{
85+
}
86+
87+
symbolt(const irep_idt &_name, typet _type, const irep_idt &_mode)
88+
: type(std::move(_type)),
89+
value(static_cast<const exprt &>(get_nil_irep())),
90+
location(source_locationt::nil()),
91+
name(_name),
92+
mode(_mode)
7093
{
71-
clear();
7294
}
7395

7496
/// Zero initialise a symbol object.
@@ -132,10 +154,10 @@ std::ostream &operator<<(std::ostream &out, const symbolt &symbol);
132154
class type_symbolt:public symbolt
133155
{
134156
public:
135-
explicit type_symbolt(const typet &_type)
157+
type_symbolt(const irep_idt &_name, typet _type, const irep_idt &_mode)
158+
: symbolt(_name, _type, _mode)
136159
{
137-
type=_type;
138-
is_type=true;
160+
is_type = true;
139161
}
140162
};
141163

@@ -155,12 +177,14 @@ class auxiliary_symbolt:public symbolt
155177
is_auxiliary=true;
156178
}
157179

158-
auxiliary_symbolt(const irep_idt &name, const typet &type):
159-
auxiliary_symbolt()
180+
auxiliary_symbolt(const irep_idt &name, typet type, const irep_idt &mode)
181+
: symbolt(name, type, mode)
160182
{
161-
this->name=name;
162-
this->base_name=name;
163-
this->type=type;
183+
is_lvalue = true;
184+
is_state_var = true;
185+
is_thread_local = true;
186+
is_file_local = true;
187+
is_auxiliary = true;
164188
}
165189
};
166190

0 commit comments

Comments
 (0)