From 583605b2185ef532996e34e55c2927d21c9d0225 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 22 Aug 2020 16:24:29 -0400 Subject: [PATCH] Parser: Move extern decl unsupported message --- src/V3Ast.h | 3 ++ src/V3LinkDot.cpp | 3 ++ src/V3ParseImp.h | 1 + src/verilog.y | 60 +++++++++++++++++++------------ test_regress/t/t_class_extern.out | 5 ++- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index bdb673c8b..6fc2e3c6b 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2675,6 +2675,9 @@ public: AstNode* fvarp() const { return op1p(); } void addFvarp(AstNode* nodep) { addNOp1p(nodep); } bool isFunction() const { return fvarp() != nullptr; } + // op2 = Class/package scope + AstNode* packagep() const { return op2p(); } + void packagep(AstNode* nodep) { setNOp2p(nodep); } // op3 = Statements/Ports/Vars AstNode* stmtsp() const { return op3p(); } // op3 = List of statements void addStmtsp(AstNode* nodep) { addNOp3p(nodep); } diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 2939484f4..607268136 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2637,6 +2637,9 @@ private: if (nodep->isExtern()) { nodep->v3warn(E_UNSUPPORTED, "Unsupported: extern class methods"); } + if (nodep->packagep()) { + nodep->v3warn(E_UNSUPPORTED, "Unsupported: extern function definition"); + } VSymEnt* oldCurSymp = m_curSymp; { m_ftaskp = nodep; diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 4e195bdbf..c460ee22a 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -129,6 +129,7 @@ struct V3ParseBisonYYSType { AstClass* classp; AstConst* constp; AstFork* forkp; + AstFunc* funcp; AstMemberDType* memberp; AstNodeModule* modulep; AstNodeUOrStructDType* uorstructp; diff --git a/src/verilog.y b/src/verilog.y index 1175542c7..92527d41f 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3781,33 +3781,43 @@ lifetime: // ==IEEE: lifetime ; taskId: - tfIdScoped - { $$ = new AstTask($1, *$1, nullptr); + id + { $$ = new AstTask($$, *$1, nullptr); + SYMP->pushNewUnderNodeOrCurrent($$, nullptr); } + // + | id/*interface_identifier*/ '.' id + { $$ = new AstTask($$, *$3, nullptr); + BBUNSUP($2, "Unsupported: Out of block function declaration"); + SYMP->pushNewUnderNodeOrCurrent($$, nullptr); } + // + | packageClassScope id + { $$ = new AstTask($$, *$2, nullptr); + $$->packagep($1); SYMP->pushNewUnderNodeOrCurrent($$, $1); } ; funcId: // IEEE: function_data_type_or_implicit + part of function_body_declaration // // IEEE: function_data_type_or_implicit must be expanded here to prevent conflict // // function_data_type expanded here to prevent conflicts with implicit_type:empty vs data_type:ID - /**/ tfIdScoped - { $$ = new AstFunc($1,*$1,nullptr, - new AstBasicDType($1, LOGIC_IMPLICIT)); + /**/ fIdScoped + { $$ = $1; + $$->addFvarp(new AstBasicDType($1, LOGIC_IMPLICIT)); SYMP->pushNewUnderNodeOrCurrent($$, $1); } - | signingE rangeList tfIdScoped - { $$ = new AstFunc($3,*$3,nullptr, - GRAMMARP->addRange(new AstBasicDType($3, LOGIC_IMPLICIT, $1), $2,true)); + | signingE rangeList fIdScoped + { $$ = $3; + $$->addFvarp(GRAMMARP->addRange(new AstBasicDType($3, LOGIC_IMPLICIT, $1), $2,true)); SYMP->pushNewUnderNodeOrCurrent($$, $3); } - | signing tfIdScoped - { $$ = new AstFunc($2,*$2,nullptr, - new AstBasicDType($2, LOGIC_IMPLICIT, $1)); + | signing fIdScoped + { $$ = $2; + $$->addFvarp(new AstBasicDType($2, LOGIC_IMPLICIT, $1)); SYMP->pushNewUnderNodeOrCurrent($$, $2); } - | data_type tfIdScoped - { $$ = new AstFunc($2,*$2,nullptr,$1); + | data_type fIdScoped + { $$ = $2; + $$->addFvarp($1); SYMP->pushNewUnderNodeOrCurrent($$, $2); } // // To verilator tasks are the same as void functions (we separately detect time passing) - | yVOID tfIdScoped - { $$ = new AstTask($2, *$2, nullptr); - SYMP->pushNewUnderNodeOrCurrent($$, $2); } + | yVOID taskId + { $$ = $2; } ; funcIdNew: // IEEE: from class_constructor_declaration @@ -3821,23 +3831,29 @@ funcIdNew: // IEEE: from class_constructor_declaration SYMP->pushNewUnder($$, nullptr); } | packageClassScopeNoId yNEW__PAREN { $$ = new AstFunc($2, "new", nullptr, nullptr); - BBUNSUP($2, "Unsupported: scoped new constructor"); + $$->packagep($1); $$->isConstructor(true); SYMP->pushNewUnderNodeOrCurrent($$, $1); } ; -tfIdScoped: // IEEE: part of function_body_declaration/task_body_declaration +fIdScoped: // IEEE: part of function_body_declaration/task_body_declaration // // IEEE: [ interface_identifier '.' | class_scope ] function_identifier id - { $$ = $1; $$ = nullptr; $$ = $1; } + { $$ = $1; + $$ = nullptr; + $$ = new AstFunc($$, *$1, nullptr, nullptr); } // | id/*interface_identifier*/ '.' id - { $$ = $3; $$ = nullptr; $$ = $3; + { $$ = $1; + $$ = nullptr; + $$ = new AstFunc($$, *$1, nullptr, nullptr); BBUNSUP($2, "Unsupported: Out of block function declaration"); } // | packageClassScope id - { $$ = $2; $$ = $1; $$ = $2; - BBUNSUP($1, "Unsupported: Out of class block function declaration"); } + { $$ = $1; + $$ = $1; + $$ = new AstFunc($$, *$2, nullptr, nullptr); + $$->packagep($1); } ; tfGuts: diff --git a/test_regress/t/t_class_extern.out b/test_regress/t/t_class_extern.out index 6adffc70c..3238d1424 100644 --- a/test_regress/t/t_class_extern.out +++ b/test_regress/t/t_class_extern.out @@ -1,4 +1,7 @@ -%Error-UNSUPPORTED: t/t_class_extern.v:11:15: Unsupported: Out of class block function declaration +%Error-UNSUPPORTED: t/t_class_extern.v:8:24: Unsupported: extern class methods + 8 | extern function void extfunc(); + | ^~~~~~~ +%Error-UNSUPPORTED: t/t_class_extern.v:11:15: Unsupported: extern function definition 11 | function void Cls::extfunc(); | ^~~ %Error: Exiting due to