Clean up Design::find_scope method use.

This commit is contained in:
Stephen Williams 2012-08-25 20:12:30 -07:00
parent 174177d437
commit a14b8c517c
3 changed files with 65 additions and 6 deletions

View File

@ -163,6 +163,26 @@ NetScope* Design::find_scope(const std::list<hname_t>&path) const
return 0;
}
/*
* This method locates a scope in the design, given its rooted
* hierarchical name. Each component of the key is used to scan one
* more step down the tree until the name runs out or the search
* fails.
*/
NetScope* Design::find_scope(const hname_t&path) const
{
for (list<NetScope*>::const_iterator scope = root_scopes_.begin()
; scope != root_scopes_.end(); ++ scope ) {
NetScope*cur = *scope;
if (path.peek_name() == cur->basename())
return cur;
}
return 0;
}
/*
* This is a relative lookup of a scope by name. The starting point is
* the scope parameter within which I start looking for the scope. If
@ -206,6 +226,43 @@ NetScope* Design::find_scope(NetScope*scope, const std::list<hname_t>&path,
return find_scope(path);
}
/*
* This is a relative lookup of a scope by name. The starting point is
* the scope parameter within which I start looking for the scope. If
* I do not find the scope within the passed scope, start looking in
* parent scopes until I find it, or I run out of parent scopes.
*/
NetScope* Design::find_scope(NetScope*scope, const hname_t&path,
NetScope::TYPE type) const
{
assert(scope);
for ( ; scope ; scope = scope->parent()) {
NetScope*cur = scope;
/* If we are looking for a module or we are not
* looking at the last path component check for
* a name match (second line). */
if (cur->type() == NetScope::MODULE
&& (type == NetScope::MODULE)
&& cur->module_name()==path.peek_name()) {
/* Up references may match module name */
} else {
cur = cur->child( path );
}
if (cur) return cur;
}
// Last chance. Look for the name starting at the root.
list<hname_t>path_list;
path_list.push_back(path);
return find_scope(path_list);
}
/*
* This method runs through the scope, noticing the defparam
* statements that were collected during the elaborate_scope pass and

View File

@ -4175,6 +4175,12 @@ class Design {
path is taken as an absolute scope name. Otherwise, the
scope is located starting at the passed scope and working
up if needed. */
NetScope* find_scope(const hname_t&path) const;
NetScope* find_scope(NetScope*, const hname_t&name,
NetScope::TYPE type = NetScope::MODULE) const;
// Note: Try to remove these versions of find_scope. Avoid
// using these in new code, use the above forms (or
// symbol_search) instead.
NetScope* find_scope(const std::list<hname_t>&path) const;
NetScope* find_scope(NetScope*, const std::list<hname_t>&path,
NetScope::TYPE type = NetScope::MODULE) const;

View File

@ -123,11 +123,9 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
if (recurse_flag) {
bool flag = false;
hname_t path_item = eval_path_component(des, start_scope, path_tail, flag);
list<hname_t>path_list;
path_list.push_back(path_item);
if (flag) {
cerr << li->get_fileline() << ": XXXXX: Errors evaluating scope index" << endl;
} else if (NetScope*chld = des->find_scope(scope, path_list)) {
} else if (NetScope*chld = des->find_scope(scope, path_item)) {
res->scope = chld;
return true;
}
@ -148,9 +146,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// scope. This is only possible if there is no prefix.
if (prefix_scope==false) {
hname_t path_item (path_tail.name);
list<hname_t>path_list;
path_list.push_back(path_item);
scope = des->find_scope(path_list);
scope = des->find_scope(path_item);
if (scope) {
res->scope = scope;
return true;