From 43443dd7d1349f55331e5f111011bc2293fb6c85 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 25 Dec 2022 15:23:26 -0800 Subject: [PATCH] Improve error handling for package scoped function calls Currently a package scoped function call will result in an assert if the function does not exist in the package scope. For non-package scoped function calls instead a proper error is reported. Refactor the code to share the same code paths between package scoped and non-package scoped function calls. This makes sure that errors are reported in both cases. It also makes the code slightly smaller. Signed-off-by: Lars-Peter Clausen --- PExpr.h | 3 --- elab_expr.cc | 39 +++++++-------------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/PExpr.h b/PExpr.h index 8114eff2b..d8c7a030f 100644 --- a/PExpr.h +++ b/PExpr.h @@ -928,9 +928,6 @@ class PECallFunction : public PExpr { NetExpr* elaborate_expr_(Design *des, NetScope *scope, unsigned flags) const; - NetExpr*elaborate_expr_pkg_(Design*des, NetScope*scope, - unsigned flags)const; - NetExpr* elaborate_expr_method_(Design*des, NetScope*scope, symbol_search_results&search_results) const; diff --git a/elab_expr.cc b/elab_expr.cc index 11ceaafe4..0dc874ac0 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -2606,34 +2606,6 @@ NetExpr* PEIdent::elaborate_expr_class_field_(Design*des, NetScope*scope, return tmp; } -NetExpr* PECallFunction::elaborate_expr_pkg_(Design*des, NetScope*scope, - unsigned flags) const -{ - if (debug_elaborate) { - cerr << get_fileline() << ": PECallFunction::elaborate_expr_pkg_: " - << "Elaborate " << path_ - << " as function in package " << package_->pscope_name() - << "." << endl; - } - - // Find the package that contains this definition, and use the - // package scope as the search starting point for the function - // definition. - NetScope*pscope = des->find_package(package_->pscope_name()); - ivl_assert(*this, pscope); - - NetFuncDef*def = des->find_function(pscope, path_); - ivl_assert(*this, def); - - NetScope*dscope = def->scope(); - ivl_assert(*this, dscope); - - if (! check_call_matches_definition_(des, dscope)) - return 0; - - return elaborate_base_(des, scope, dscope, flags); -} - NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, unsigned expr_wid, unsigned flags) const { @@ -2661,14 +2633,17 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, NetExpr* PECallFunction::elaborate_expr_(Design*des, NetScope*scope, unsigned flags) const { - if (package_) - return elaborate_expr_pkg_(des, scope, flags); - flags &= ~SYS_TASK_ARG; // don't propagate the SYS_TASK_ARG flag + NetScope *use_scope = scope; + if (package_) { + use_scope = des->find_package(package_->pscope_name()); + ivl_assert(*this, use_scope); + } + // Search for the symbol. This should turn up a scope. symbol_search_results search_results; - bool search_flag = symbol_search(this, des, scope, path_, &search_results); + bool search_flag = symbol_search(this, des, use_scope, path_, &search_results); if (debug_elaborate) { cerr << get_fileline() << ": PECallFunction::elaborate_expr: "