diff --git a/ivtest/ivltests/sv_typedef_scope.v b/ivtest/ivltests/sv_typedef_scope1.v similarity index 100% rename from ivtest/ivltests/sv_typedef_scope.v rename to ivtest/ivltests/sv_typedef_scope1.v diff --git a/ivtest/ivltests/sv_typedef_scope2.v b/ivtest/ivltests/sv_typedef_scope2.v new file mode 100644 index 000000000..ec26f5727 --- /dev/null +++ b/ivtest/ivltests/sv_typedef_scope2.v @@ -0,0 +1,24 @@ +// Check that it is possible to overwrite a type identifier declared in a higher +// level scope. Check that this works if the new type is an array type. + +typedef logic [3:0] T; +T x; + +module test; + + typedef logic [7:0] T[1:0]; + T y; + + initial begin + y[0] = 8'hff; + y[1] = 8'hfe; + + if ($bits(T) == 16 && $size(x) == 4 && $size(y) == 2 && + y[0] == 8'hff && y[1] == 8'hfe) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_typedef_scope3.v b/ivtest/ivltests/sv_typedef_scope3.v new file mode 100644 index 000000000..d036d4e4a --- /dev/null +++ b/ivtest/ivltests/sv_typedef_scope3.v @@ -0,0 +1,30 @@ +// Check that it is possible to overwrite a type identifier declared in a higher +// level scope. Check that this works when the new type is declared in a class. + +typedef logic [3:0] T; +T x; + +module test; + + class C; + typedef logic [7:0] T; + T y; + + task t; + y = 8'hff; + if ($bits(x) == 4 && $bits(y) == 8 && y == 8'hff) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + endtask + endclass + + C c; + + initial begin + c = new; + c.t(); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 43fb411a0..8312bd6b3 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -589,7 +589,9 @@ sv_timeunit_prec_fail2 CE,-g2009,-u,\ ./ivltests/sv_timeunit_prec_fail2a.v,\ ./ivltests/sv_timeunit_prec_fail2b.v,\ ./ivltests/sv_timeunit_prec_fail2c.v, ivltests gold=sv_timeunit_prec_fail2.gold -sv_typedef_scope normal,-g2009 ivltests +sv_typedef_scope1 normal,-g2009 ivltests +sv_typedef_scope2 normal,-g2009 ivltests +sv_typedef_scope3 normal,-g2009 ivltests sv_union1 normal,-g2009 ivltests sv_union1b normal,-g2009 ivltests sv_union2 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index d4b6a7303..f5944b788 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -392,6 +392,7 @@ sv_port_default7 CE,-g2009,-pallowsigned=1 ivltests sv_port_default8 CE,-g2009,-pallowsigned=1 ivltests sv_port_default9 CE,-g2009 ivltests sv_root_class CE,-g2009 ivltests +sv_typedef_scope3 CE,-g2009 ivltests sv_unit2b CE,-g2009 ivltests sv_unit3b CE,-g2009 ivltests sv_unit4b CE,-g2009 ivltests diff --git a/parse.y b/parse.y index 004fb8001..1e802d8a4 100644 --- a/parse.y +++ b/parse.y @@ -915,11 +915,8 @@ class_item /* IEEE1800-2005: A.1.8 */ /* IEEEE1800-2017: A.1.9 Class items: class_item ::= { property_qualifier} data_declaration */ - | property_qualifier_opt K_typedef data_type IDENTIFIER dimensions_opt ';' - { perm_string name = lex_strings.make($4); - delete[]$4; - pform_set_typedef(name, $3, $5); - } + /* TODO: Restrict the access based on the property qualifier. */ + | property_qualifier_opt type_declaration /* IEEE1800-1017: A.1.9 Class items: Class methods... */ @@ -2690,13 +2687,13 @@ type_declaration /* If the IDENTIFIER already is a typedef, it is possible for this code to override the definition, but only if the typedef is inherited from a different scope. */ - | K_typedef data_type TYPE_IDENTIFIER ';' + | K_typedef data_type TYPE_IDENTIFIER dimensions_opt ';' { perm_string name = lex_strings.make($3.text); if (pform_test_type_identifier_local(name)) { yyerror(@3, "error: Typedef identifier \"%s\" is already a type name.", $3.text); - + delete $4; } else { - pform_set_typedef(name, $2, NULL); + pform_set_typedef(name, $2, $4); } delete[]$3.text; }