Support class method calls without parenthesis (#3902) (#4082)

This commit is contained in:
Srinivasan Venkataramanan 2023-04-11 05:07:24 +05:30 committed by GitHub
parent 2ab34b5eeb
commit 722ab9306a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -2765,11 +2765,15 @@ private:
m_ds.m_dotSymp = foundp; m_ds.m_dotSymp = foundp;
ok = m_ds.m_dotPos == DP_SCOPE; ok = m_ds.m_dotPos == DP_SCOPE;
} else if (const AstNodeFTask* const ftaskp = VN_CAST(foundp->nodep(), NodeFTask)) { } else if (const AstNodeFTask* const ftaskp = VN_CAST(foundp->nodep(), NodeFTask)) {
if (!ftaskp->isFunction()) {
if (!ftaskp->isFunction() ||
ftaskp->classMethod() ) {
ok = m_ds.m_dotPos == DP_NONE; ok = m_ds.m_dotPos == DP_NONE;
if (ok) { if (ok) {
// The condition is true for tasks, properties and void functions. // The condition is true for tasks,
// properties and void functions.
// In these cases, the parentheses may be skipped. // In these cases, the parentheses may be skipped.
// Also SV class methods can be called without parens
AstFuncRef* const funcRefp AstFuncRef* const funcRefp
= new AstFuncRef{nodep->fileline(), nodep->name(), nullptr}; = new AstFuncRef{nodep->fileline(), nodep->name(), nullptr};
nodep->replaceWith(funcRefp); nodep->replaceWith(funcRefp);

View File

@ -135,6 +135,9 @@ private:
// VISITs // VISITs
void visit(AstNodeFTask* nodep) override { void visit(AstNodeFTask* nodep) override {
if (!nodep->user1SetOnce()) { // Process only once. if (!nodep->user1SetOnce()) { // Process only once.
// Mark class methods
if (VN_IS(m_modp, Class)) nodep->classMethod(true);
V3Config::applyFTask(m_modp, nodep); V3Config::applyFTask(m_modp, nodep);
cleanFileline(nodep); cleanFileline(nodep);
VL_RESTORER(m_ftaskp); VL_RESTORER(m_ftaskp);

View File

@ -15,6 +15,7 @@ endclass : Cls
module t (/*AUTOARG*/); module t (/*AUTOARG*/);
initial begin initial begin
int tmp_i;
Cls c; Cls c;
if (c != null) $stop; if (c != null) $stop;
c = new; c = new;
@ -24,7 +25,9 @@ module t (/*AUTOARG*/);
if (c.get_methoda() != 20) $stop; if (c.get_methoda() != 20) $stop;
c.setv_methoda(30); c.setv_methoda(30);
if (c.get_methoda() != 30) $stop; if (c.get_methoda() != 30) $stop;
if (c.get_methoda != 30) $stop; c.setv_methoda(300);
tmp_i = c.get_methoda;
if (tmp_i != 300) $stop;
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end