@@ -629,7 +629,9 @@ module_identifier_with_scope:
629629 {
630630 $$ = $1 ;
631631 auto base_name = stack_expr($1 ).get(ID_base_name);
632- push_scope (base_name, " ." , verilog_scopet::MODULE);
632+ // modules go into the top scope, not into $unit
633+ auto &module_scope = PARSER.scopes.top_scope.add_scope(base_name, " ." , verilog_scopet::MODULE);
634+ PARSER.scopes.enter_scope(module_scope);
633635 }
634636 ;
635637
@@ -742,9 +744,9 @@ checker_declaration:
742744 TOK_CHECKER { init ($$); }
743745 checker_identifier
744746 {
745- // these create a scope
747+ // these create a scope, which goes into the current scope
746748 auto base_name = stack_expr ($3 ).get (ID_base_name);
747- push_scope (base_name, " ." , verilog_scopet::MODULE );
749+ push_scope (base_name, " ." , verilog_scopet::CHECKER );
748750 }
749751 checker_port_list_paren_opt ' ;'
750752 checker_or_generate_item_brace
@@ -815,7 +817,9 @@ class_declaration:
815817 init ($$, ID_verilog_class);
816818 auto base_name = stack_expr ($2 ).get (ID_base_name);
817819 stack_expr ($$).set (ID_base_name, base_name);
818- push_scope (base_name, " ::" , verilog_scopet::CLASS);
820+ // classes go into the top scope, not $unit
821+ auto &class_scope = PARSER.scopes .top_scope .add_scope (base_name, " ::" , verilog_scopet::CLASS);
822+ PARSER.scopes .enter_scope (class_scope);
819823 }
820824 class_item_brace
821825 TOK_ENDCLASS
@@ -831,7 +835,10 @@ package_declaration:
831835 lifetime_opt
832836 any_identifier ' ;'
833837 {
834- push_scope (stack_expr ($5 ).get (ID_base_name), " ::" , verilog_scopet::PACKAGE);
838+ // packages go into the top scope, not $unit
839+ auto base_name = stack_expr ($5 ).get (ID_base_name);
840+ auto &package_scope = PARSER.scopes .top_scope .add_scope (base_name, " ::" , verilog_scopet::PACKAGE);
841+ PARSER.scopes .enter_scope (package_scope);
835842 }
836843 package_item_brace
837844 TOK_ENDPACKAGE endpackage_identifier_opt
@@ -2352,7 +2359,8 @@ function_declaration: TOK_FUNCTION lifetime_opt function_body_declaration
23522359function_body_declaration:
23532360 function_data_type_or_implicit
23542361 function_identifier
2355- { push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::FUNCTION); }
2362+ { // functions go into the current scope, say module or $unit
2363+ push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::FUNCTION); }
23562364 ' ;'
23572365 tf_item_declaration_brace
23582366 function_statement_or_null_brace
@@ -2368,7 +2376,8 @@ function_body_declaration:
23682376 }
23692377 | function_data_type_or_implicit
23702378 function_identifier
2371- { push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::FUNCTION); }
2379+ { // functions go into the current scope, say module or $unit
2380+ push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::FUNCTION); }
23722381 ' (' tf_port_list_opt ' )' ' ;'
23732382 block_item_declaration_brace
23742383 function_statement_or_null_brace
@@ -2410,7 +2419,8 @@ function_prototype: TOK_FUNCTION data_type_or_void function_identifier
24102419
24112420task_declaration:
24122421 TOK_TASK task_identifier
2413- { push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::TASK); }
2422+ { // tasks go into the current scope, module or $unit
2423+ push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::TASK); }
24142424 ' ;'
24152425 tf_item_declaration_brace
24162426 task_statement_or_null_brace
@@ -2423,7 +2433,8 @@ task_declaration:
24232433 pop_scope ();
24242434 }
24252435 | TOK_TASK task_identifier
2426- { push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::TASK); }
2436+ { // tasks go into the current scope, module or $unit
2437+ push_scope (stack_expr ($2 ).get (ID_base_name), " ." , verilog_scopet::TASK); }
24272438 ' (' tf_port_list_opt ' )' ' ;'
24282439 tf_item_declaration_brace
24292440 task_statement_or_null_brace
@@ -2614,7 +2625,8 @@ assertion_item_declaration:
26142625
26152626property_declaration:
26162627 TOK_PROPERTY any_identifier
2617- { auto base_name = stack_expr ($2 ).get (ID_base_name);
2628+ { // properties go into the current scope, say module or $unit
2629+ auto base_name = stack_expr ($2 ).get (ID_base_name);
26182630 push_scope (base_name, " ." , verilog_scopet::PROPERTY); }
26192631 property_port_list_paren_opt ' ;'
26202632 property_spec semicolon_opt
@@ -2812,7 +2824,8 @@ property_case_item:
28122824sequence_declaration:
28132825 " sequence" { init ($$, ID_verilog_sequence_declaration); }
28142826 any_identifier
2815- { auto base_name = stack_expr ($3 ).get (ID_base_name);
2827+ { // sequences go into the current scope, module or $unit
2828+ auto base_name = stack_expr ($3 ).get (ID_base_name);
28162829 push_scope (base_name, " ." , verilog_scopet::SEQUENCE);
28172830 }
28182831 sequence_port_list_opt ' ;'
0 commit comments