Skip to content

Commit

Permalink
Add lookup with index
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasKl committed Oct 29, 2024
1 parent c5d1f15 commit 3238a39
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions wellen/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,26 @@ impl Hierarchy {
}

pub fn lookup_var<N: AsRef<str>>(&self, path: &[N], name: &N) -> Option<VarRef> {
self.lookup_var_with_index(path, name, &None)
}

pub fn lookup_var_with_index<N: AsRef<str>>(
&self,
path: &[N],
name: &N,
index: &Option<VarIndex>,
) -> Option<VarRef> {
match path {
[] => self
.vars()
.find(|v| self.get(*v).name(self) == name.as_ref()),
[] => self.vars().find(|v| {
let v = self.get(*v);
v.name(self) == name.as_ref() && (index.is_none() || (v.index == *index))
}),
scopes => {
let scope = self.get(self.lookup_scope(scopes)?);
scope
.vars(self)
.find(|v| self.get(*v).name(self) == name.as_ref())
scope.vars(self).find(|v| {
let v = self.get(*v);
v.name(self) == name.as_ref() && (index.is_none() || (v.index == *index))
})
}
}
}
Expand Down

0 comments on commit 3238a39

Please sign in to comment.