pub struct NameResolver { /* private fields */ }Expand description
Tracks the current namespace and use imports and resolves names against them.
Feed every statement to observe_stmt in source order
(e.g. from ScopeVisitor::visit_stmt), then call resolve_name.
Imports are cleared at each namespace statement; they are not popped at the end
of a braced namespace block.
Builtin type names (int, string, …) are not special-cased.
Implementations§
Source§impl NameResolver
impl NameResolver
Sourcepub fn enter_namespace(&mut self, namespace: Option<&str>)
pub fn enter_namespace(&mut self, namespace: Option<&str>)
Enters namespace and clears all imports.
Sourcepub fn add_import(&mut self, kind: UseKind, fqn: &str, alias: Option<&str>)
pub fn add_import(&mut self, kind: UseKind, fqn: &str, alias: Option<&str>)
Registers an import. fqn may carry a leading backslash; alias defaults
to the last segment of fqn.
Sourcepub fn observe_stmt(&mut self, stmt: &Stmt<'_, '_>)
pub fn observe_stmt(&mut self, stmt: &Stmt<'_, '_>)
Updates state for namespace and use statements; ignores everything else.
Sourcepub fn observe_owned_stmt(&mut self, stmt: &Stmt)
pub fn observe_owned_stmt(&mut self, stmt: &Stmt)
Owned-AST counterpart of observe_stmt.
Sourcepub fn resolve_name(
&self,
name: &Name<'_, '_>,
ctx: NameContext,
) -> ResolvedName
pub fn resolve_name( &self, name: &Name<'_, '_>, ctx: NameContext, ) -> ResolvedName
Resolves a borrowed-AST name.
Sourcepub fn resolve_owned_name(&self, name: &Name, ctx: NameContext) -> ResolvedName
pub fn resolve_owned_name(&self, name: &Name, ctx: NameContext) -> ResolvedName
Resolves an owned-AST name.
Sourcepub fn resolve<S: AsRef<str>>(
&self,
ctx: NameContext,
kind: NameKind,
parts: &[S],
) -> ResolvedName
pub fn resolve<S: AsRef<str>>( &self, ctx: NameContext, kind: NameKind, parts: &[S], ) -> ResolvedName
Resolves a name given as its kind and \-separated segments.
Trait Implementations§
Source§impl Clone for NameResolver
impl Clone for NameResolver
Source§impl Debug for NameResolver
impl Debug for NameResolver
Auto Trait Implementations§
impl Freeze for NameResolver
impl RefUnwindSafe for NameResolver
impl Send for NameResolver
impl Sync for NameResolver
impl Unpin for NameResolver
impl UnsafeUnpin for NameResolver
impl UnwindSafe for NameResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more