Rename `prefix_scope` to `scope_is_bound`

The `prefix_scope` flag indicates that symbol lookup has been bound to a
specific scope. It controls whether lookup can continue outside that scope
and whether declaration ordering must be checked.

Rename it to `scope_is_bound` to describe the lookup state instead of how the
scope was selected. This allows other scope bindings to reuse it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-08-02 10:46:24 -07:00
parent e393487126
commit 431b3ba1a2
2 changed files with 20 additions and 20 deletions

View File

@ -137,7 +137,7 @@ static inline bool test_function_return_value(const symbol_search_results&search
extern bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, extern bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
pform_name_t path, unsigned lexical_pos, pform_name_t path, unsigned lexical_pos,
struct symbol_search_results*res, struct symbol_search_results*res,
NetScope*start_scope = nullptr, bool prefix_scope = false); NetScope*start_scope = nullptr, bool scope_is_bound = false);
extern bool symbol_search(const LineInfo *li, Design *des, NetScope *scope, extern bool symbol_search(const LineInfo *li, Design *des, NetScope *scope,
const pform_scoped_name_t &path, unsigned lexical_pos, const pform_scoped_name_t &path, unsigned lexical_pos,

View File

@ -42,7 +42,7 @@ using namespace std;
bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
pform_name_t path, unsigned lexical_pos, pform_name_t path, unsigned lexical_pos,
struct symbol_search_results*res, struct symbol_search_results*res,
NetScope*start_scope, bool prefix_scope) NetScope*start_scope, bool scope_is_bound)
{ {
assert(scope); assert(scope);
@ -72,7 +72,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// for the tail key, but there are other special cases as well. // for the tail key, but there are other special cases as well.
if (! path.empty()) { if (! path.empty()) {
bool flag = symbol_search(li, des, scope, path, lexical_pos, bool flag = symbol_search(li, des, scope, path, lexical_pos,
res, start_scope, prefix_scope); res, start_scope, scope_is_bound);
if (! flag) if (! flag)
return false; return false;
@ -106,12 +106,12 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
return true; return true;
} }
// The prefix is found to be a scope, so switch to that // The prefix is found to be a scope, so switch to that scope,
// scope, set the hier_path to turn off upwards searches, // bind the search to it to turn off upwards searches, and continue
// and continue our search for the tail. // our search for the tail.
if (res->is_scope()) { if (res->is_scope()) {
scope = res->scope; scope = res->scope;
prefix_scope = true; scope_is_bound = true;
if (debug_scopes || debug_elaborate) { if (debug_scopes || debug_elaborate) {
cerr << li->get_fileline() << ": symbol_search: " cerr << li->get_fileline() << ": symbol_search: "
@ -140,7 +140,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// found the scope part of the path, or there is no scope part of the // found the scope part of the path, or there is no scope part of the
// path. For example, if the path in was s1.s2.x, we found the scope // path. For example, if the path in was s1.s2.x, we found the scope
// s1.s2, res->is_scope() is true, and path_tail is x. We look for x // s1.s2, res->is_scope() is true, and path_tail is x. We look for x
// now. The preceeding code set prefix_scope=true to ease our test below. // now. The preceding code bound the search to that scope.
// //
// If the input was x (without prefixes) then we don't know if x is a // If the input was x (without prefixes) then we don't know if x is a
// scope or item. In this case, res->is_found() is false and we may need // scope or item. In this case, res->is_found() is false and we may need
@ -150,7 +150,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
cerr << li->get_fileline() << ": symbol_search: " cerr << li->get_fileline() << ": symbol_search: "
<< "Looking for " << path_tail << "Looking for " << path_tail
<< " in scope " << scope_path(scope) << " in scope " << scope_path(scope)
<< " prefix_scope=" << prefix_scope << endl; << " scope_is_bound=" << scope_is_bound << endl;
} }
if (scope->genvar_tmp.str() && path_tail.name == scope->genvar_tmp) if (scope->genvar_tmp.str() && path_tail.name == scope->genvar_tmp)
return false; return false;
@ -193,7 +193,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
} }
if (NetNet*net = scope->find_signal(path_tail.name)) { if (NetNet*net = scope->find_signal(path_tail.name)) {
bool decl_after_use = !prefix_scope && !(net->lexical_pos() <= lexical_pos); bool decl_after_use = !scope_is_bound && !(net->lexical_pos() <= lexical_pos);
if (!gn_strict_net_var_declaration || !decl_after_use) { if (!gn_strict_net_var_declaration || !decl_after_use) {
path.push_back(path_tail); path.push_back(path_tail);
res->scope = scope; res->scope = scope;
@ -216,7 +216,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
} }
if (NetEvent*eve = scope->find_event(path_tail.name)) { if (NetEvent*eve = scope->find_event(path_tail.name)) {
bool decl_after_use = !prefix_scope && !(eve->lexical_pos() <= lexical_pos); bool decl_after_use = !scope_is_bound && !(eve->lexical_pos() <= lexical_pos);
if (!gn_strict_net_var_declaration || !decl_after_use) { if (!gn_strict_net_var_declaration || !decl_after_use) {
path.push_back(path_tail); path.push_back(path_tail);
res->scope = scope; res->scope = scope;
@ -238,7 +238,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
} }
if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) { if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) {
bool decl_after_use = !prefix_scope bool decl_after_use = !scope_is_bound
&& !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos); && !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos);
if (!gn_strict_parameter_declaration || !decl_after_use) { if (!gn_strict_parameter_declaration || !decl_after_use) {
path.push_back(path_tail); path.push_back(path_tail);
@ -284,7 +284,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// Finally check the rare case of a signal that hasn't // Finally check the rare case of a signal that hasn't
// been elaborated yet. // been elaborated yet.
if (PWire*wire = scope->find_signal_placeholder(path_tail.name)) { if (PWire*wire = scope->find_signal_placeholder(path_tail.name)) {
if (prefix_scope || (wire->lexical_pos() <= lexical_pos)) { if (scope_is_bound || (wire->lexical_pos() <= lexical_pos)) {
NetNet*net = wire->elaborate_sig(des, scope); NetNet*net = wire->elaborate_sig(des, scope);
if (!net) if (!net)
return false; return false;
@ -367,8 +367,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
} }
} }
// Don't scan up if we are searching within a prefixed scope. // Don't scan up if the search is bound to the current scope.
if (prefix_scope) if (scope_is_bound)
break; break;
// Imports are not visible through hierachical names // Imports are not visible through hierachical names
@ -431,8 +431,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// Last chance: this is a single name, so it might be the name // Last chance: this is a single name, so it might be the name
// of a root scope. Ask the design if this is a root // of a root scope. Ask the design if this is a root
// scope. This is only possible if there is no prefix. // scope. This is only possible if the search is not already bound.
if (prefix_scope==false) { if (!scope_is_bound) {
hname_t path_item (path_tail.name); hname_t path_item (path_tail.name);
scope = des->find_scope(path_item); scope = des->find_scope(path_item);
if (scope) { if (scope) {
@ -451,17 +451,17 @@ bool symbol_search(const LineInfo *li, Design *des, NetScope *scope,
struct symbol_search_results *res) struct symbol_search_results *res)
{ {
NetScope *search_scope = scope; NetScope *search_scope = scope;
bool prefix_scope = false; bool scope_is_bound = false;
if (path.package) { if (path.package) {
search_scope = des->find_package(path.package->pscope_name()); search_scope = des->find_package(path.package->pscope_name());
if (!search_scope) if (!search_scope)
return false; return false;
prefix_scope = true; scope_is_bound = true;
} }
return symbol_search(li, des, search_scope, path.name, lexical_pos, return symbol_search(li, des, search_scope, path.name, lexical_pos,
res, search_scope, prefix_scope); res, search_scope, scope_is_bound);
} }
bool check_interface_modport_access(const LineInfo *li, Design *des, bool check_interface_modport_access(const LineInfo *li, Design *des,