Skip to content

Commit dbc15e8

Browse files
committed
statement-list: use new 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.
1 parent 59693f6 commit dbc15e8

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

src/statement-list/statement_list_entry_point.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ static void add_main_function_block_call(
103103
PRECONDITION(1u == function_type.parameters().size());
104104
const code_typet::parametert &data_block_interface =
105105
function_type.parameters().front();
106-
symbolt instance_data_block;
107-
instance_data_block.name =
108-
id2string(data_block_interface.get_base_name()) + DB_ENTRY_POINT_POSTFIX;
109-
instance_data_block.type =
110-
to_type_with_subtype(data_block_interface.type()).subtype();
106+
symbolt instance_data_block{
107+
id2string(data_block_interface.get_base_name()) + DB_ENTRY_POINT_POSTFIX,
108+
to_type_with_subtype(data_block_interface.type()).subtype(),
109+
ID_statement_list};
111110
instance_data_block.is_static_lifetime = true;
112-
instance_data_block.mode = ID_statement_list;
113111
symbol_table.add(instance_data_block);
114112
const address_of_exprt data_block_ref{instance_data_block.symbol_expr()};
115113

@@ -124,10 +122,8 @@ static void add_main_function_block_call(
124122
static void
125123
generate_statement_list_init_function(symbol_table_baset &symbol_table)
126124
{
127-
symbolt init;
128-
init.name = INITIALIZE_FUNCTION;
129-
init.mode = ID_statement_list;
130-
init.type = code_typet({}, empty_typet{});
125+
symbolt init{
126+
INITIALIZE_FUNCTION, code_typet({}, empty_typet{}), ID_statement_list};
131127

132128
code_blockt dest;
133129
dest.add(code_labelt(CPROVER_HIDE, code_skipt()));
@@ -146,9 +142,7 @@ generate_statement_list_init_function(symbol_table_baset &symbol_table)
146142
/// \param [out] symbol_table: Symbol table that should contain the symbol.
147143
static void generate_rounding_mode(symbol_table_baset &symbol_table)
148144
{
149-
symbolt rounding_mode;
150-
rounding_mode.name = rounding_mode_identifier();
151-
rounding_mode.type = signed_int_type();
145+
symbolt rounding_mode{rounding_mode_identifier(), signed_int_type(), ID_C};
152146
rounding_mode.is_thread_local = true;
153147
rounding_mode.is_static_lifetime = true;
154148
const constant_exprt rounding_val{
@@ -179,12 +173,10 @@ bool generate_statement_list_start_function(
179173
add_main_function_block_call(start_function_body, symbol_table, main);
180174

181175
// Add the start symbol.
182-
symbolt start_symbol;
183-
start_symbol.name = goto_functionst::entry_point();
176+
symbolt start_symbol{
177+
goto_functionst::entry_point(), code_typet{{}, empty_typet{}}, main.mode};
184178
start_symbol.base_name = goto_functionst::entry_point();
185-
start_symbol.type = code_typet({}, empty_typet{});
186179
start_symbol.value.swap(start_function_body);
187-
start_symbol.mode = main.mode;
188180

189181
if(!symbol_table.insert(std::move(start_symbol)).second)
190182
{

src/statement-list/statement_list_typecheck.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,10 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
158158
const statement_list_parse_treet::function_blockt &function_block)
159159
{
160160
// Create FB symbol.
161-
symbolt function_block_sym;
161+
symbolt function_block_sym{function_block.name, typet{}, ID_statement_list};
162162
function_block_sym.module = module;
163-
function_block_sym.name = function_block.name;
164163
function_block_sym.base_name = function_block_sym.name;
165164
function_block_sym.pretty_name = function_block_sym.name;
166-
function_block_sym.mode = ID_statement_list;
167165

168166
// When calling function blocks, the passed parameters are value-copied to a
169167
// corresponding instance data block. This block contains all input, inout,
@@ -175,11 +173,11 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
175173
// Create and add DB type symbol.
176174
const struct_typet data_block_type{
177175
create_instance_data_block_type(function_block)};
178-
type_symbolt data_block{data_block_type};
179-
data_block.name =
180-
id2string(function_block_sym.name) + DATA_BLOCK_TYPE_POSTFIX;
176+
type_symbolt data_block{
177+
id2string(function_block_sym.name) + DATA_BLOCK_TYPE_POSTFIX,
178+
data_block_type,
179+
ID_statement_list};
181180
data_block.base_name = data_block.name;
182-
data_block.mode = ID_statement_list;
183181
symbol_table.add(data_block);
184182

185183
// Create and add parameter symbol.
@@ -206,12 +204,10 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
206204
void statement_list_typecheckt::typecheck_function_declaration(
207205
const statement_list_parse_treet::functiont &function)
208206
{
209-
symbolt function_sym;
207+
symbolt function_sym{function.name, typet{}, ID_statement_list};
210208
function_sym.module = module;
211-
function_sym.name = function.name;
212209
function_sym.base_name = function_sym.name;
213210
function_sym.pretty_name = function_sym.name;
214-
function_sym.mode = ID_statement_list;
215211
code_typet::parameterst params;
216212
typecheck_function_var_decls(
217213
function.var_input, params, function.name, ID_statement_list_var_input);
@@ -230,28 +226,22 @@ void statement_list_typecheckt::typecheck_tag_list()
230226
{
231227
for(const symbol_exprt &tag : parse_tree.tags)
232228
{
233-
symbolt tag_sym;
229+
symbolt tag_sym{tag.get_identifier(), tag.type(), ID_statement_list};
234230
tag_sym.is_static_lifetime = true;
235231
tag_sym.module = module;
236-
tag_sym.name = tag.get_identifier();
237232
tag_sym.base_name = tag_sym.name;
238233
tag_sym.pretty_name = tag_sym.name;
239-
tag_sym.type = tag.type();
240-
tag_sym.mode = ID_statement_list;
241234
symbol_table.add(tag_sym);
242235
}
243236
}
244237

245238
void statement_list_typecheckt::add_temp_rlo()
246239
{
247-
symbolt temp_rlo;
240+
symbolt temp_rlo{CPROVER_TEMP_RLO, get_bool_type(), ID_statement_list};
248241
temp_rlo.is_static_lifetime = true;
249242
temp_rlo.module = module;
250-
temp_rlo.name = CPROVER_TEMP_RLO;
251243
temp_rlo.base_name = temp_rlo.name;
252244
temp_rlo.pretty_name = temp_rlo.name;
253-
temp_rlo.type = get_bool_type();
254-
temp_rlo.mode = ID_statement_list;
255245
symbol_table.add(temp_rlo);
256246
}
257247

@@ -321,13 +311,13 @@ void statement_list_typecheckt::typecheck_temp_var_decls(
321311
for(const statement_list_parse_treet::var_declarationt &declaration :
322312
tia_module.var_temp)
323313
{
324-
symbolt temp_sym;
325-
temp_sym.name = id2string(tia_symbol.name) +
326-
"::" + id2string(declaration.variable.get_identifier());
314+
symbolt temp_sym{
315+
id2string(tia_symbol.name) +
316+
"::" + id2string(declaration.variable.get_identifier()),
317+
declaration.variable.type(),
318+
ID_statement_list};
327319
temp_sym.base_name = declaration.variable.get_identifier();
328320
temp_sym.pretty_name = temp_sym.base_name;
329-
temp_sym.type = declaration.variable.type();
330-
temp_sym.mode = ID_statement_list;
331321
temp_sym.module = module;
332322
symbol_table.add(temp_sym);
333323

0 commit comments

Comments
 (0)