Merge pull request #778 from larsclausen/ps-identifier

Improve parsing of package scoped identifiers
This commit is contained in:
Stephen Williams 2022-10-14 08:10:24 -07:00 committed by GitHub
commit 90538e4193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 20 deletions

View File

@ -0,0 +1,30 @@
// Check that it is possible to reference a package scoped function, even if
// there is a type identifier of the same name in the current scope.
bit failed = 1'b0;
`define check(expr, val) \
if (expr !== val) begin \
$display("FAILED: %s, expected %0d, got %0d", `"expr`", val, expr); \
failed = 1'b1; \
end
package P;
function integer T(integer x);
return x + 1;
endfunction
endpackage
module test;
typedef integer T;
initial begin
integer x;
x = P::T(10);
`check(x, 11)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,26 @@
// Check that it is possible to reference a package scoped type identifier, even if
// there is a identifier of the same name in the current scope.
bit failed = 1'b0;
`define check(expr, val) \
if (expr !== val) begin \
$display("FAILED: %s, expected %0d, got %0d", `"expr`", val, expr); \
failed = 1'b1; \
end
package P;
typedef logic [31:0] T;
endpackage
module test;
logic T;
initial begin
P::T x;
`check($bits(x), 32)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,27 @@
// Check that it is possible to reference a package scoped identifier, even if
// there is a type identifier of the same name in the current scope.
bit failed = 1'b0;
`define check(expr, val) \
if (expr !== val) begin \
$display("FAILED: %s, expected %0d, got %0d", `"expr`", val, expr); \
failed = 1'b1; \
end
package P;
integer T = 10;
endpackage
module test;
typedef integer T;
integer x;
initial begin
x = P::T;
`check(x, 10)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -618,6 +618,9 @@ sv_port_default14 CE,-g2009 ivltests
sv_ps_function1 normal,-g2009 ivltests
sv_ps_function2 normal,-g2009 ivltests
sv_ps_function3 normal,-g2009 ivltests
sv_ps_function4 normal,-g2009 ivltests
sv_ps_type1 normal,-g2009 ivltests
sv_ps_var1 normal,-g2009 ivltests
sv_queue1 normal,-g2009 ivltests
sv_queue2 normal,-g2009 ivltests
sv_queue3 normal,-g2009 ivltests

57
parse.y
View File

@ -700,6 +700,8 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector<Statem
%type <genvar_iter> genvar_iteration
%type <package> package_scope
%token K_TAND
%nonassoc K_PLUS_EQ K_MINUS_EQ K_MUL_EQ K_DIV_EQ K_MOD_EQ K_AND_EQ K_OR_EQ
%nonassoc K_XOR_EQ K_LS_EQ K_RS_EQ K_RSS_EQ K_NB_TRIGGER
@ -1165,19 +1167,25 @@ data_declaration /* IEEE1800-2005: A.2.1.3 */
| attribute_list_opt package_import_declaration
;
package_scope
: PACKAGE_IDENTIFIER K_SCOPE_RES
{ lex_in_package_scope($1);
$$ = $1;
}
;
ps_type_identifier /* IEEE1800-2017: A.9.3 */
: TYPE_IDENTIFIER
{ pform_set_type_referenced(@1, $1.text);
delete[]$1.text;
$$ = $1.type;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES
{ lex_in_package_scope($1); }
TYPE_IDENTIFIER
| package_scope TYPE_IDENTIFIER
{ lex_in_package_scope(0);
$$ = $4.type;
delete[]$4.text;
$$ = $2.type;
delete[]$2.text;
}
;
/* Data types that can have packed dimensions directly attached to it */
packed_array_data_type /* IEEE1800-2005: A.2.2.1 */
@ -1977,12 +1985,19 @@ package_import_declaration /* IEEE1800-2005 A.2.1.3 */
;
package_import_item
: PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER
{ pform_package_import(@2, $1, $3);
delete[]$3;
: package_scope IDENTIFIER
{ lex_in_package_scope(0);
pform_package_import(@1, $1, $2);
delete[]$2;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES '*'
{ pform_package_import(@2, $1, 0);
| package_scope TYPE_IDENTIFIER
{ lex_in_package_scope(0);
pform_package_import(@1, $1, $2.text);
delete[]$2.text;
}
| package_scope '*'
{ lex_in_package_scope(0);
pform_package_import(@1, $1, 0);
}
;
@ -3689,9 +3704,10 @@ expr_primary
delete nm;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES hierarchy_identifier
{ $$ = pform_package_ident(@2, $1, $3);
delete $3;
| package_scope hierarchy_identifier
{ lex_in_package_scope(0);
$$ = pform_package_ident(@2, $1, $2);
delete $2;
}
/* An identifier followed by an expression list in parentheses is a
@ -3723,11 +3739,11 @@ expr_primary
delete $3;
$$ = tmp;
}
| PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER '(' expression_list_with_nuls ')'
{ perm_string use_name = lex_strings.make($3);
| package_scope IDENTIFIER { lex_in_package_scope(0); } '(' expression_list_with_nuls ')'
{ perm_string use_name = lex_strings.make($2);
PECallFunction*tmp = new PECallFunction($1, use_name, *$5);
FILE_NAME(tmp, @3);
delete[]$3;
FILE_NAME(tmp, @2);
delete[]$2;
delete $5;
$$ = tmp;
}
@ -6342,9 +6358,10 @@ statement_item /* This is roughly statement_item in the LRM */
delete $2;
$$ = tmp;
}
| K_TRIGGER PACKAGE_IDENTIFIER K_SCOPE_RES hierarchy_identifier
{ PTrigger*tmp = pform_new_trigger(@4, $2, *$4);
delete $4;
| K_TRIGGER package_scope hierarchy_identifier
{ lex_in_package_scope(0);
PTrigger*tmp = pform_new_trigger(@3, $2, *$3);
delete $3;
$$ = tmp;
}
/* FIXME: Does this need support for package resolution like above? */