Skip to content

Commit 0d5bd73

Browse files
committed
Add typecheck support for empty STL modules
Changes the way STL module symbols are generated so that they only have a value if temp variables and/or networks are present.
1 parent 153618e commit 0d5bd73

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/statement-list/statement_list_typecheck.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -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

287281
void 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

src/statement-list/statement_list_typecheck.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ class statement_list_typecheckt : public typecheckt
174174

175175
/// Performs a typecheck on the networks of a TIA module and saves the
176176
/// result to the given symbol.
177-
/// \param networks: Network list that should be checked.
178-
/// \param [out] tia_element: Symbol representation of the TIA module.
177+
/// \param tia_module: Module containing the networks that shall be checked.
178+
/// \param [out] tia_symbol: Symbol representation of the given TIA module.
179179
void typecheck_statement_list_networks(
180-
const statement_list_parse_treet::networkst &networks,
181-
symbolt &tia_element);
180+
const statement_list_parse_treet::tia_modulet &tia_module,
181+
symbolt &tia_symbol);
182182

183183
/// Performs a typecheck on a single instruction and saves the result to the
184184
/// given symbol body if necessary.

0 commit comments

Comments
 (0)