From 54956f0f29888177705b584f496bcbface15d141 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 4 Oct 2022 23:21:11 +0200 Subject: [PATCH] Be consistent on allowing calling non-void function as task When calling non-void functions or non-void methods of built-in types as a task a warning is issued. But when calling a non-void method of a user defined class as a task an error is generated. Be consistent here and generate a warning in both cases. Signed-off-by: Lars-Peter Clausen --- Statement.h | 1 + elaborate.cc | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Statement.h b/Statement.h index 72ab46a3d..50ee2f2fd 100644 --- a/Statement.h +++ b/Statement.h @@ -235,6 +235,7 @@ class PCallTask : public Statement { NetProc*elaborate_function_(Design*des, NetScope*scope) const; NetProc*elaborate_void_function_(Design*des, NetScope*scope, NetFuncDef*def) const; + NetProc *elaborate_non_void_function_(Design *des, NetScope *scope) const; NetProc*elaborate_build_call_(Design*des, NetScope*scope, NetScope*task, NetExpr*use_this) const; diff --git a/elaborate.cc b/elaborate.cc index dfd1fb7d2..9d5ef8877 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -3896,16 +3896,8 @@ bool PCallTask::test_task_calls_ok_(Design*des, NetScope*scope) const return true; } -NetProc* PCallTask::elaborate_function_(Design*des, NetScope*scope) const +NetProc *PCallTask::elaborate_non_void_function_(Design *des, NetScope *scope) const { - NetFuncDef*func = des->find_function(scope, path_); - // This is not a function, so this task call cannot be a function - // call with a missing return assignment. - if (! func) return 0; - - if (gn_system_verilog() && func->is_void()) - return elaborate_void_function_(des, scope, func); - // Generate a function call version of this task call. PExpr*rval = new PECallFunction(package_, path_, parms_); rval->set_file(get_file()); @@ -3920,6 +3912,21 @@ NetProc* PCallTask::elaborate_function_(Design*des, NetScope*scope) const return tmp->elaborate(des, scope); } +NetProc* PCallTask::elaborate_function_(Design*des, NetScope*scope) const +{ + NetFuncDef*func = des->find_function(scope, path_); + + // This is not a function, so this task call cannot be a function + // call with a missing return assignment. + if (!func) + return nullptr; + + if (gn_system_verilog() && func->is_void()) + return elaborate_void_function_(des, scope, func); + + return elaborate_non_void_function_(des, scope); +} + NetProc* PCallTask::elaborate_void_function_(Design*des, NetScope*scope, NetFuncDef*def) const { @@ -3957,11 +3964,8 @@ NetProc* PCallTask::elaborate_build_call_(Design*des, NetScope*scope, } else if (task->type() == NetScope::FUNC) { NetFuncDef*tmp = task->func_def(); - if (!tmp->is_void()) { - cerr << get_fileline() << ": error: " - << "Calling a non-void function as a task." << endl; - des->errors += 1; - } + if (!tmp->is_void()) + return elaborate_non_void_function_(des, scope); def = tmp; }