@@ -537,76 +537,76 @@ void verilog_typecheckt::collect_symbols(const verilog_declt &decl)
537537 symbols_added.push_back (symbol.name );
538538 }
539539 }
540- else if (decl_class == ID_function || decl_class == ID_task)
540+ else
541541 {
542- typet return_type;
542+ DATA_INVARIANT (false , " unexpected decl class " + id2string (decl_class));
543+ }
544+ }
543545
544- if (decl_class == ID_function)
545- return_type = elaborate_type ( decl. type ());
546- else
547- return_type = empty_typet () ;
546+ void verilog_typecheckt::collect_symbols (
547+ const verilog_function_or_task_declt & decl)
548+ {
549+ typet return_type;
548550
549- auto base_name = decl.get_identifier ();
550- auto identifier = hierarchical_identifier (base_name);
551- symbolt symbol{identifier, code_typet{{}, std::move (return_type)}, mode};
551+ if (decl.id () == ID_verilog_function_decl)
552+ return_type = elaborate_type (decl.type ());
553+ else
554+ return_type = empty_typet ();
552555
553- symbol.base_name = base_name;
554- symbol.location = decl.source_location ();
555- symbol.pretty_name = strip_verilog_prefix (symbol.name );
556- symbol.module = module_identifier;
557- symbol.value = decl;
556+ auto base_name = decl.base_name ();
557+ auto identifier = hierarchical_identifier (base_name);
558+ symbolt symbol{identifier, code_typet{{}, std::move (return_type)}, mode};
558559
559- add_symbol (symbol);
560+ symbol.base_name = base_name;
561+ symbol.location = decl.source_location ();
562+ symbol.pretty_name = strip_verilog_prefix (symbol.name );
563+ symbol.module = module_identifier;
564+ symbol.value = decl;
560565
561- function_or_task_name = symbol. name ;
566+ add_symbol ( symbol) ;
562567
563- // do the ANSI-style ports, if applicable
564- for (auto &port_decl : decl.ports ())
565- {
566- // These must have one declarator exactly.
567- DATA_INVARIANT (
568- port_decl.declarators ().size () == 1 , " must have one port declarator" );
569- collect_symbols (port_decl); // rec. call
570- }
568+ function_or_task_name = symbol.name ;
571569
572- // add a symbol for the return value of functions, if applicable
570+ // do the ANSI-style ports, if applicable
571+ for (auto &port_decl : decl.ports ())
572+ {
573+ // These must have one declarator exactly.
574+ DATA_INVARIANT (
575+ port_decl.declarators ().size () == 1 , " must have one port declarator" );
576+ collect_symbols (port_decl); // rec. call
577+ }
573578
574- if (
575- decl_class == ID_function &&
576- to_code_type (symbol.type ).return_type ().id () != ID_verilog_void)
577- {
578- symbolt return_symbol;
579- return_symbol.is_state_var = true ;
580- return_symbol.is_lvalue = true ;
581- return_symbol.mode = symbol.mode ;
582- return_symbol.module = symbol.module ;
583- return_symbol.base_name = symbol.base_name ;
584- return_symbol.value = nil_exprt ();
585- return_symbol.type = to_code_type (symbol.type ).return_type ();
579+ // add a symbol for the return value of functions, if applicable
586580
587- return_symbol.name =
588- id2string (symbol.name ) + " ." + id2string (symbol.base_name );
581+ if (
582+ decl.id () == ID_verilog_function_decl &&
583+ to_code_type (symbol.type ).return_type ().id () != ID_verilog_void)
584+ {
585+ symbolt return_symbol;
586+ return_symbol.is_state_var = true ;
587+ return_symbol.is_lvalue = true ;
588+ return_symbol.mode = symbol.mode ;
589+ return_symbol.module = symbol.module ;
590+ return_symbol.base_name = symbol.base_name ;
591+ return_symbol.value = nil_exprt ();
592+ return_symbol.type = to_code_type (symbol.type ).return_type ();
589593
590- return_symbol.pretty_name = strip_verilog_prefix (return_symbol.name );
594+ return_symbol.name =
595+ id2string (symbol.name ) + " ." + id2string (symbol.base_name );
591596
592- symbol_table.add (return_symbol);
593- }
597+ return_symbol.pretty_name = strip_verilog_prefix (return_symbol.name );
594598
595- // collect symbols in the declarations within the task/function
596- for (auto &decl : decl.declarations ())
597- collect_symbols (decl);
599+ symbol_table.add (return_symbol);
600+ }
598601
599- collect_symbols (decl.body ());
602+ // collect symbols in the declarations within the task/function
603+ for (auto &sub_decl : decl.declarations ())
604+ collect_symbols (sub_decl);
600605
601- function_or_task_name = " " ;
602- }
603- else
604- {
605- DATA_INVARIANT (false , " unexpected decl class " + id2string (decl_class));
606- }
607- }
606+ collect_symbols (decl.body ());
608607
609- #include < iostream>
608+ function_or_task_name = " " ;
609+ }
610610
611611void verilog_typecheckt::collect_symbols (const verilog_lett &let)
612612{
@@ -794,6 +794,12 @@ void verilog_typecheckt::collect_symbols(
794794 {
795795 collect_symbols (to_verilog_decl (module_item));
796796 }
797+ else if (
798+ module_item.id () == ID_verilog_function_decl ||
799+ module_item.id () == ID_verilog_task_decl)
800+ {
801+ collect_symbols (to_verilog_function_or_task_decl (module_item));
802+ }
797803 else if (
798804 module_item.id () == ID_verilog_always ||
799805 module_item.id () == ID_verilog_always_comb ||
0 commit comments