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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-10-04 23:21:11 +02:00
parent 2d6243ea6c
commit 54956f0f29
2 changed files with 19 additions and 14 deletions

View File

@ -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;

View File

@ -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;
}