Skip to content

Commit 799e221

Browse files
authored
Merge pull request diffblue#6796 from tautschnig/cleanup/refactor-add-param
C front-end: factor out adding parameters to symbol table
2 parents 40d7f29 + 0016e99 commit 799e221

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

src/ansi-c/c_typecheck_base.cpp

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -521,34 +521,8 @@ void c_typecheck_baset::typecheck_function_body(symbolt &symbol)
521521
// set return type
522522
return_type=code_type.return_type();
523523

524-
unsigned anon_counter=0;
525-
526-
// Add the parameter declarations into the symbol table.
527-
for(auto &p : code_type.parameters())
528-
{
529-
// may be anonymous
530-
if(p.get_base_name().empty())
531-
{
532-
irep_idt base_name="#anon"+std::to_string(anon_counter++);
533-
p.set_base_name(base_name);
534-
}
535-
536-
// produce identifier
537-
irep_idt base_name = p.get_base_name();
538-
irep_idt identifier=id2string(symbol.name)+"::"+id2string(base_name);
539-
540-
p.set_identifier(identifier);
541-
542-
parameter_symbolt p_symbol;
543-
544-
p_symbol.type = p.type();
545-
p_symbol.name=identifier;
546-
p_symbol.base_name=base_name;
547-
p_symbol.location = p.source_location();
548-
549-
symbolt *new_p_symbol;
550-
move_symbol(p_symbol, new_p_symbol);
551-
}
524+
// Add the parameter declarations into the symbol table
525+
add_parameters_to_symbol_table(symbol);
552526

553527
// typecheck the body code
554528
typecheck_code(to_code(symbol.value));
@@ -774,3 +748,39 @@ void c_typecheck_baset::typecheck_declaration(
774748
}
775749
}
776750
}
751+
752+
void c_typecheck_baset::add_parameters_to_symbol_table(symbolt &symbol)
753+
{
754+
PRECONDITION(can_cast_type<code_typet>(symbol.type));
755+
756+
code_typet &code_type = to_code_type(symbol.type);
757+
758+
unsigned anon_counter = 0;
759+
760+
// Add the parameter declarations into the symbol table.
761+
for(auto &p : code_type.parameters())
762+
{
763+
// may be anonymous
764+
if(p.get_base_name().empty())
765+
{
766+
irep_idt base_name = "#anon" + std::to_string(anon_counter++);
767+
p.set_base_name(base_name);
768+
}
769+
770+
// produce identifier
771+
irep_idt base_name = p.get_base_name();
772+
irep_idt identifier = id2string(symbol.name) + "::" + id2string(base_name);
773+
774+
p.set_identifier(identifier);
775+
776+
parameter_symbolt p_symbol;
777+
778+
p_symbol.type = p.type();
779+
p_symbol.name = identifier;
780+
p_symbol.base_name = base_name;
781+
p_symbol.location = p.source_location();
782+
783+
symbolt *new_p_symbol;
784+
move_symbol(p_symbol, new_p_symbol);
785+
}
786+
}

src/ansi-c/c_typecheck_base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ class c_typecheck_baset:
268268
symbolt &old_symbol, symbolt &new_symbol);
269269
void typecheck_function_body(symbolt &symbol);
270270

271+
/// Create symbols for parameter of the code-typed symbol \p symbol.
272+
void add_parameters_to_symbol_table(symbolt &symbol);
273+
271274
virtual void do_initializer(symbolt &symbol);
272275

273276
static bool is_numeric_type(const typet &src)

0 commit comments

Comments
 (0)