pub struct NameTable<'str, Id = ValueId> { /* private fields */ }Expand description
A name → value reverse map with amortized unique-name minting.
The context keeps one global table for module-scoped values (functions,
varnodes, spaces, p-code ops, byte blobs); each FunctionBody
keeps its own table for its block/instruction/param/Temp names. Keeping those
namespaces independent is a prerequisite for running function passes in
parallel: a worker mints names against its function’s table with no global
lock and no cross-function collisions. Two functions may each name a block
loop — they render correctly because a value’s own name field is the
source of truth; this table only enforces uniqueness and resolves by name.
Implementations§
Source§impl<'str, Id: Copy + Eq> NameTable<'str, Id>
impl<'str, Id: Copy + Eq> NameTable<'str, Id>
Sourcepub fn register(
&mut self,
name: Cow<'str, str>,
id: Id,
old_name: Option<&str>,
) -> Result<()>
pub fn register( &mut self, name: Cow<'str, str>, id: Id, old_name: Option<&str>, ) -> Result<()>
Register name for id, forgetting old_name first. Errors if name
is already taken (callers pre-check via get, so this only
fires defensively).
Sourcepub fn forget(&mut self, name: &str)
pub fn forget(&mut self, name: &str)
Remove name, keeping the unique suffix hint exact: if
name is a generated base_<n> suffix, lower base’s hint so the freed
suffix is reconsidered next time.
Sourcepub fn unique(&mut self, name: Cow<'str, str>) -> Cow<'str, str>
pub fn unique(&mut self, name: Cow<'str, str>) -> Cow<'str, str>
A free name derived from name: the bare name if untaken, else the first
free name_<n>. Resumes suffix probing from a cached lower bound so
minting many like-named values stays ~O(1) amortized; the chosen suffix is
identical to a naive first-free scan from 1.