From ef4794e36df440be76779232bec8347ed5d4b52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Boro=C5=84ski?= <94375110+kboronski-ant@users.noreply.github.com> Date: Tue, 22 Aug 2023 07:06:34 +0200 Subject: [PATCH] Support parenthesesless calls to static methods (#4432) --- src/V3LinkDot.cpp | 11 ++++++- test_regress/t/t_package_export_bad.out | 12 +++---- ...ction_in_class_call_without_parentheses.pl | 21 +++++++++++++ ...nction_in_class_call_without_parentheses.v | 31 +++++++++++++++++++ 4 files changed, 68 insertions(+), 7 deletions(-) create mode 100755 test_regress/t/t_static_function_in_class_call_without_parentheses.pl create mode 100644 test_regress/t/t_static_function_in_class_call_without_parentheses.v diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 8b81802aa..53ab2238a 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2573,13 +2573,15 @@ private: string expectWhat; bool allowScope = false; bool allowVar = false; + bool allowFTask = false; bool staticAccess = false; if (m_ds.m_dotPos == DP_PACKAGE) { // {package}::{a} AstNodeModule* classOrPackagep = nullptr; - expectWhat = "scope/variable"; + expectWhat = "scope/variable/func"; allowScope = true; allowVar = true; + allowFTask = true; staticAccess = true; UASSERT_OBJ(VN_IS(m_ds.m_dotp->lhsp(), ClassOrPackageRef), m_ds.m_dotp->lhsp(), "Bad package link"); @@ -2660,6 +2662,13 @@ private: << cellp->modp()->prettyNameQ()); } } + } else if (allowFTask && VN_IS(foundp->nodep(), NodeFTask)) { + AstTaskRef* const taskrefp + = new AstTaskRef{nodep->fileline(), nodep->name(), nullptr}; + nodep->replaceWith(taskrefp); + VL_DO_DANGLING(nodep->deleteTree(), nodep); + if (start) m_ds = lastStates; + return; } else if (AstVar* const varp = foundToVarp(foundp, nodep, VAccess::READ)) { AstIfaceRefDType* const ifacerefp = LinkDotState::ifaceRefFromArray(varp->subDTypep()); diff --git a/test_regress/t/t_package_export_bad.out b/test_regress/t/t_package_export_bad.out index 98c2ef9a9..caa0aa233 100644 --- a/test_regress/t/t_package_export_bad.out +++ b/test_regress/t/t_package_export_bad.out @@ -1,27 +1,27 @@ %Error: t/t_package_export.v:45:17: Export object not found: 'pkg1::BAD_DOES_NOT_EXIST' 45 | export pkg1::BAD_DOES_NOT_EXIST; | ^~~~~~~~~~~~~~~~~~ -%Error: t/t_package_export.v:60:16: Can't find definition of scope/variable: 'PARAM2' +%Error: t/t_package_export.v:60:16: Can't find definition of scope/variable/func: 'PARAM2' : ... Suggested alternative: 'PARAM1' 60 | reg [pkg11::PARAM2 : 0] bus12; | ^~~~~~ -%Error: t/t_package_export.v:61:16: Can't find definition of scope/variable: 'PARAM3' +%Error: t/t_package_export.v:61:16: Can't find definition of scope/variable/func: 'PARAM3' : ... Suggested alternative: 'PARAM1' 61 | reg [pkg11::PARAM3 : 0] bus13; | ^~~~~~ -%Error: t/t_package_export.v:64:16: Can't find definition of scope/variable: 'PARAM2' +%Error: t/t_package_export.v:64:16: Can't find definition of scope/variable/func: 'PARAM2' : ... Suggested alternative: 'PARAM1' 64 | reg [pkg21::PARAM2 : 0] bus22; | ^~~~~~ -%Error: t/t_package_export.v:65:16: Can't find definition of scope/variable: 'PARAM3' +%Error: t/t_package_export.v:65:16: Can't find definition of scope/variable/func: 'PARAM3' : ... Suggested alternative: 'PARAM1' 65 | reg [pkg21::PARAM3 : 0] bus23; | ^~~~~~ -%Error: t/t_package_export.v:68:16: Can't find definition of scope/variable: 'PARAM2' +%Error: t/t_package_export.v:68:16: Can't find definition of scope/variable/func: 'PARAM2' : ... Suggested alternative: 'PARAM1' 68 | reg [pkg31::PARAM2 : 0] bus32; | ^~~~~~ -%Error: t/t_package_export.v:69:16: Can't find definition of scope/variable: 'PARAM3' +%Error: t/t_package_export.v:69:16: Can't find definition of scope/variable/func: 'PARAM3' : ... Suggested alternative: 'PARAM1' 69 | reg [pkg31::PARAM3 : 0] bus33; | ^~~~~~ diff --git a/test_regress/t/t_static_function_in_class_call_without_parentheses.pl b/test_regress/t/t_static_function_in_class_call_without_parentheses.pl new file mode 100755 index 000000000..859050d63 --- /dev/null +++ b/test_regress/t/t_static_function_in_class_call_without_parentheses.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2023 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + ); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_static_function_in_class_call_without_parentheses.v b/test_regress/t/t_static_function_in_class_call_without_parentheses.v new file mode 100644 index 000000000..4c125d7ff --- /dev/null +++ b/test_regress/t/t_static_function_in_class_call_without_parentheses.v @@ -0,0 +1,31 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Antmicro Ltd. +// SPDX-License-Identifier: CC0-1.0 + +class Foo; + static int m_v; + + static function void set_v(int v); + m_v = v; + endfunction + static function int get_v(); + // Let's see if referring to the implicit variable does not resolve into a call + get_v = m_v; + endfunction +endclass + +module t(); + initial begin + int v; + + Foo::set_v(3); + // Check if a parenthesesless call to static method works + v = Foo::get_v; + if (v != 3) $stop; + + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule