Merge pull request #605 from larsclausen/class-scoped-base

Support scoped base class type
This commit is contained in:
Stephen Williams 2022-02-10 17:12:27 -08:00 committed by GitHub
commit a7a154047a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 33 deletions

View File

@ -514,7 +514,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)
netclass_t*use_base_class = 0;
if (base_class) {
use_base_class = scope->find_class(des, base_class->name);
use_base_class = base_class->save_elaborated_type;
if (use_base_class == 0) {
cerr << pclass->get_fileline() << ": error: "
<< "Base class " << base_class->name

View File

@ -0,0 +1,29 @@
// Check that base class defined in a package is handled correctly
package P;
class B;
task check;
$display("PASSED");
endtask
endclass
endpackage
module test;
class B;
task check;
$display("FAILED");
endtask
endclass
class C extends P::B;
endclass
C c;
initial begin
c = new;
c.check();
end
endmodule

View File

@ -424,6 +424,7 @@ sv_class21 normal,-g2009 ivltests
sv_class22 normal,-g2009 ivltests
sv_class23 normal,-g2009 ivltests
sv_class24 normal,-g2009 ivltests
sv_class_extends_scoped normal,-g2009 ivltests
sv_darray1 normal,-g2009 ivltests
sv_darray2 normal,-g2009 ivltests
sv_darray3 normal,-g2009 ivltests

View File

@ -363,6 +363,7 @@ sv_class21 CE,-g2009 ivltests
sv_class22 CE,-g2009 ivltests
sv_class23 CE,-g2009 ivltests
sv_class24 CE,-g2009 ivltests
sv_class_extends_scoped CE,-g2009 ivltests
sv_end_label CE,-g2009 ivltests # Also generate
sv_foreach2 CE,-g2009,-pallowsigned=1 ivltests
sv_foreach3 CE,-g2009 ivltests

53
parse.y
View File

@ -644,6 +644,7 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector<Statem
%type <data_type> data_type data_type_or_implicit data_type_or_implicit_or_void
%type <data_type> simple_type_or_string let_formal_type
%type <data_type> packed_array_data_type
%type <data_type> ps_type_identifier
%type <class_type> class_identifier
%type <struct_member> struct_union_member
%type <struct_members> struct_union_member_list
@ -850,17 +851,13 @@ class_declaration_endlabel_opt
a data_type. */
class_declaration_extends_opt /* IEEE1800-2005: A.1.2 */
: K_extends TYPE_IDENTIFIER
{ pform_set_type_referenced(@2, $2.text);
$$.type = $2.type;
$$.exprs= 0;
delete[]$2.text;
: K_extends ps_type_identifier
{ $$.type = $2;
$$.exprs = 0;
}
| K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')'
{ pform_set_type_referenced(@2, $2.text);
$$.type = $2.type;
| K_extends ps_type_identifier '(' expression_list_with_nuls ')'
{ $$.type = $2;
$$.exprs = $4;
delete[]$2.text;
}
|
{ $$.type = 0; $$.exprs = 0; }
@ -1178,17 +1175,8 @@ data_declaration /* IEEE1800-2005: A.2.1.3 */
| attribute_list_opt package_import_declaration
;
/* Data types that can have packed dimensions directly attached to it */
packed_array_data_type /* IEEE1800-2005: A.2.2.1 */
: enum_data_type
{ $$ = $1; }
| struct_data_type
{ if (!$1->packed_flag) {
yyerror(@1, "sorry: Unpacked structs not supported.");
}
$$ = $1;
}
| TYPE_IDENTIFIER
ps_type_identifier /* IEEE1800-2017: A.9.3 */
: TYPE_IDENTIFIER
{ pform_set_type_referenced(@1, $1.text);
delete[]$1.text;
$$ = $1.type;
@ -1200,6 +1188,18 @@ packed_array_data_type /* IEEE1800-2005: A.2.2.1 */
$$ = $4.type;
delete[]$4.text;
}
/* Data types that can have packed dimensions directly attached to it */
packed_array_data_type /* IEEE1800-2005: A.2.2.1 */
: enum_data_type
{ $$ = $1; }
| struct_data_type
{ if (!$1->packed_flag) {
yyerror(@1, "sorry: Unpacked structs not supported.");
}
$$ = $1;
}
| ps_type_identifier
;
data_type /* IEEE1800-2005: A.2.2.1 */
@ -2243,23 +2243,12 @@ simple_type_or_string /* IEEE1800-2005: A.2.2.1 */
tmp->reg_flag = !gn_system_verilog();
$$ = tmp;
}
| TYPE_IDENTIFIER
{ pform_set_type_referenced(@1, $1.text);
$$ = $1.type;
delete[]$1.text;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES
{ lex_in_package_scope($1); }
TYPE_IDENTIFIER
{ lex_in_package_scope(0);
$$ = $4.type;
delete[]$4.text;
}
| K_string
{ string_type_t*tmp = new string_type_t;
FILE_NAME(tmp, @1);
$$ = tmp;
}
| ps_type_identifier
;
statement /* IEEE1800-2005: A.6.4 */