@@ -100,12 +100,12 @@ void statement_list_typecheckt::typecheck()
100100 parse_tree.function_blocks )
101101 {
102102 symbolt &fb_sym{symbol_table.get_writeable_ref (fb.name )};
103- typecheck_statement_list_networks (fb. networks , fb_sym);
103+ typecheck_statement_list_networks (fb, fb_sym);
104104 }
105105 for (const statement_list_parse_treet::functiont &fc : parse_tree.functions )
106106 {
107107 symbolt &function_sym{symbol_table.get_writeable_ref (fc.name )};
108- typecheck_statement_list_networks (fc. networks , function_sym);
108+ typecheck_statement_list_networks (fc, function_sym);
109109 }
110110}
111111
@@ -149,14 +149,12 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
149149 param_sym.mode = STATEMENT_LIST_MODE;
150150 symbol_table.add (param_sym);
151151
152- // Setup FB symbol type and value and add it to the symbol table .
152+ // Setup FB symbol type and value.
153153 code_typet::parameterst params;
154154 params.push_back (param);
155155 code_typet fb_type{params, empty_typet ()};
156156 fb_type.set (ID_statement_list_type, ID_statement_list_function_block);
157157 function_block_sym.type = fb_type;
158- function_block_sym.value = code_blockt{};
159- typecheck_temp_var_decls (function_block, function_block_sym);
160158 symbol_table.add (function_block_sym);
161159}
162160
@@ -180,10 +178,6 @@ void statement_list_typecheckt::typecheck_function_declaration(
180178 code_typet fc_type{params, function.return_type };
181179 fc_type.set (ID_statement_list_type, ID_statement_list_function);
182180 function_sym.type = fc_type;
183- function_sym.value = code_blockt{};
184-
185- typecheck_temp_var_decls (function, function_sym);
186-
187181 symbol_table.add (function_sym);
188182}
189183
@@ -285,15 +279,23 @@ void statement_list_typecheckt::typecheck_temp_var_decls(
285279}
286280
287281void statement_list_typecheckt::typecheck_statement_list_networks (
288- const statement_list_parse_treet::networkst &networks ,
289- symbolt &tia_element )
282+ const statement_list_parse_treet::tia_modulet &tia_module ,
283+ symbolt &tia_symbol )
290284{
291- for (const auto &network : networks)
285+ // Leave value empty if there are no networks to iterate through.
286+ if (tia_module.networks .empty ())
287+ return ;
288+ if (tia_symbol.value .is_nil ())
289+ tia_symbol.value = code_blockt{};
290+
291+ typecheck_temp_var_decls (tia_module, tia_symbol);
292+
293+ for (const auto &network : tia_module.networks )
292294 {
293295 // Set RLO to true each time a new network is entered (TIA behaviour).
294296 rlo_bit = true_exprt ();
295297 for (const auto &instruction : network.instructions )
296- typecheck_statement_list_instruction (instruction, tia_element );
298+ typecheck_statement_list_instruction (instruction, tia_symbol );
297299 }
298300}
299301
0 commit comments