diff --git a/PExpr.cc b/PExpr.cc index db9667877..35f0ed2ef 100644 --- a/PExpr.cc +++ b/PExpr.cc @@ -440,7 +440,7 @@ void PEIdent::declare_implicit_nets(LexicalScope*scope, NetNet::Type type) bool PEIdent::has_aa_term(Design*des, NetScope*scope) const { symbol_search_results sr; - if (!symbol_search(this, des, scope, path_, &sr)) + if (!symbol_search(this, des, scope, path_, lexical_pos_, &sr)) return false; // Class properties are not considered automatic since a non-blocking diff --git a/elab_expr.cc b/elab_expr.cc index 902f1605a..fd6954b37 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1731,7 +1731,7 @@ unsigned PECallFunction::test_width(Design*des, NetScope*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, scope, path_, UINT_MAX, &search_results); if (debug_elaborate) { cerr << get_fileline() << ": PECallFunction::test_width: " @@ -2843,7 +2843,7 @@ NetExpr* PECallFunction::elaborate_expr_(Design*des, NetScope*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, scope, path_, UINT_MAX, &search_results); if (debug_elaborate) { cerr << get_fileline() << ": PECallFunction::elaborate_expr: " @@ -4334,7 +4334,7 @@ ivl_type_t PEIdent::resolve_type_(Design *des, const symbol_search_results &sr, unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode) { symbol_search_results sr; - bool found_symbol = symbol_search(this, des, scope, path_, &sr); + bool found_symbol = symbol_search(this, des, scope, path_, lexical_pos_, &sr); // If there is a part/bit select expression, then process it // here. This constrains the results no matter what kind the @@ -4490,7 +4490,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope, bool need_const = NEED_CONST & flags; symbol_search_results sr; - symbol_search(this, des, scope, path_, &sr); + symbol_search(this, des, scope, path_, lexical_pos_, &sr); if (!sr.net) { cerr << get_fileline() << ": error: Unable to bind variable `" @@ -4680,7 +4680,7 @@ NetExpr* PEIdent::elaborate_expr_(Design*des, NetScope*scope, // a net called "b" in the scope "main.a" and with a member // named "c". symbol_search() handles this for us. symbol_search_results sr; - symbol_search(this, des, scope, path_, &sr); + symbol_search(this, des, scope, path_, lexical_pos_, &sr); // If the identifier name is a parameter name, then return // the parameter value. diff --git a/elab_lval.cc b/elab_lval.cc index 81c12a6c0..71054a72e 100644 --- a/elab_lval.cc +++ b/elab_lval.cc @@ -174,7 +174,7 @@ NetAssign_* PEIdent::elaborate_lval(Design*des, } symbol_search_results sr; - symbol_search(this, des, scope, path_, &sr); + symbol_search(this, des, scope, path_, lexical_pos_, &sr); NetNet *reg = sr.net; pform_name_t &member_path = sr.path_tail; diff --git a/elab_net.cc b/elab_net.cc index 388f01491..0ae06bf58 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -503,7 +503,7 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope, ivl_assert(*this, scope); symbol_search_results sr; - symbol_search(this, des, scope, path_.name, &sr); + symbol_search(this, des, scope, path_.name, lexical_pos_, &sr); if (sr.eve != 0) { cerr << get_fileline() << ": error: named events (" << path_ @@ -1113,7 +1113,7 @@ NetNet* PEIdent::elaborate_subport(Design*des, NetScope*scope) const NetNet*PEIdent::elaborate_unpacked_net(Design*des, NetScope*scope) const { symbol_search_results sr; - symbol_search(this, des, scope, path_, &sr); + symbol_search(this, des, scope, path_, lexical_pos_, &sr); if (!sr.net) { cerr << get_fileline() << ": error: Net " << path_ << " is not defined in this context." << endl; @@ -1138,7 +1138,7 @@ bool PEIdent::is_collapsible_net(Design*des, NetScope*scope, ivl_assert(*this, scope); symbol_search_results sr; - symbol_search(this, des, scope, path_.name, &sr); + symbol_search(this, des, scope, path_.name, lexical_pos_, &sr); if (sr.eve != 0) return false; diff --git a/elaborate.cc b/elaborate.cc index 928032db6..45c40bad9 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -1271,7 +1271,7 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const pform_name_t path_; path_.push_back(name_component_t(rmod->ports[j]->name)); symbol_search_results sr; - symbol_search(this, des, scope, path_, &sr); + symbol_search(this, des, scope, path_, UINT_MAX, &sr); if (sr.net != 0) { pins[j] = new PEIdent(rmod->ports[j]->name, UINT_MAX, true); pins[j]->set_lineno(get_lineno()); @@ -3825,7 +3825,7 @@ NetProc* PCallTask::elaborate_method_(Design*des, NetScope*scope, // (internally represented as "@") is handled by there being a // "this" object in the instance scope. symbol_search_results sr; - symbol_search(this, des, scope, use_path, &sr); + symbol_search(this, des, scope, use_path, UINT_MAX, &sr); NetNet*net = sr.net; if (net == 0) @@ -4908,7 +4908,7 @@ cerr << endl; if (PEIdent*id = dynamic_cast(expr_[idx]->expr())) { symbol_search_results sr; - symbol_search(this, des, scope, id->path(), &sr); + symbol_search(this, des, scope, id->path(), id->lexical_pos(), &sr); if (sr.scope && sr.eve) { wa->add_event(sr.eve); @@ -6038,7 +6038,7 @@ NetProc* PTrigger::elaborate(Design*des, NetScope*scope) const ivl_assert(*this, scope); symbol_search_results sr; - if (!symbol_search(this, des, scope, event_, &sr)) { + if (!symbol_search(this, des, scope, event_, UINT_MAX, &sr)) { cerr << get_fileline() << ": error: event <" << event_ << ">" << " not found." << endl; des->errors += 1; @@ -6062,7 +6062,7 @@ NetProc* PNBTrigger::elaborate(Design*des, NetScope*scope) const ivl_assert(*this, scope); symbol_search_results sr; - if (!symbol_search(this, des, scope, event_, &sr)) { + if (!symbol_search(this, des, scope, event_, UINT_MAX, &sr)) { cerr << get_fileline() << ": error: event <" << event_ << ">" << " not found." << endl; des->errors += 1; diff --git a/netmisc.h b/netmisc.h index d9da5af76..0f87fee88 100644 --- a/netmisc.h +++ b/netmisc.h @@ -106,11 +106,12 @@ static inline bool test_function_return_value(const symbol_search_results&search } extern bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, - pform_name_t path, struct symbol_search_results*res, + pform_name_t path, unsigned lexical_pos, + struct symbol_search_results*res, NetScope*start_scope = nullptr, bool prefix_scope = false); extern bool symbol_search(const LineInfo *li, Design *des, NetScope *scope, - const pform_scoped_name_t &path, + const pform_scoped_name_t &path, unsigned lexical_pos, struct symbol_search_results*res); /* diff --git a/symbol_search.cc b/symbol_search.cc index d96f2a5f0..704a03d8e 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) * Copyright CERN 2012 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -38,7 +38,8 @@ using namespace std; */ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, - pform_name_t path, struct symbol_search_results*res, + pform_name_t path, unsigned lexical_pos, + struct symbol_search_results*res, NetScope*start_scope, bool prefix_scope) { assert(scope); @@ -68,8 +69,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, // recursively. Ideally, the result is a scope that we search // for the tail key, but there are other special cases as well. if (! path.empty()) { - bool flag = symbol_search(li, des, scope, path, res, start_scope, - prefix_scope); + bool flag = symbol_search(li, des, scope, path, lexical_pos, + res, start_scope, prefix_scope); if (! flag) return false; @@ -162,20 +163,24 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (NetNet*net = scope->find_signal(path_tail.name)) { - path.push_back(path_tail); - res->scope = scope; - res->net = net; - res->type = net->net_type(); - res->path_head = path; - return true; + if (prefix_scope || (net->lexical_pos() <= lexical_pos)) { + path.push_back(path_tail); + res->scope = scope; + res->net = net; + res->type = net->net_type(); + res->path_head = path; + return true; + } } if (NetEvent*eve = scope->find_event(path_tail.name)) { - path.push_back(path_tail); - res->scope = scope; - res->eve = eve; - res->path_head = path; - return true; + if (prefix_scope || (eve->lexical_pos() <= lexical_pos)) { + path.push_back(path_tail); + res->scope = scope; + res->eve = eve; + res->path_head = path; + return true; + } } if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) { @@ -310,7 +315,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } bool symbol_search(const LineInfo *li, Design *des, NetScope *scope, - const pform_scoped_name_t &path, + const pform_scoped_name_t &path, unsigned lexical_pos, struct symbol_search_results *res) { NetScope *search_scope = scope; @@ -323,6 +328,6 @@ bool symbol_search(const LineInfo *li, Design *des, NetScope *scope, prefix_scope = true; } - return symbol_search(li, des, search_scope, path.name, res, search_scope, - prefix_scope); + return symbol_search(li, des, search_scope, path.name, lexical_pos, + res, search_scope, prefix_scope); }