pub struct ScopeManager<'a> {
pub frames: Vec<ScopeFrame<'a>>,
pub codesize_hints: BTreeMap<String, usize>,
pub codesizes: BTreeMap<String, usize>,
pub codesize_hints_used: bool,
measurements: Vec<usize>,
}Expand description
Tracks the macro call stack during compilation.
Provides scope identifiers for label operations and exposes the call stack for argument resolution.
Fields§
§frames: Vec<ScopeFrame<'a>>Stack of scope frames from root to current
codesize_hints: BTreeMap<String, usize>Macro sizes from the previous compile pass, for __codesize values that cannot be measured
in the code they are part of
codesizes: BTreeMap<String, usize>Macro sizes generated in this pass, the hints of the next pass
codesize_hints_used: boolWhether a hint was used, so the sizes must be compiled again until they are stable
measurements: Vec<usize>Frame indices where a __codesize measurement of another macro starts
Implementations§
Source§impl<'a> ScopeManager<'a>
impl<'a> ScopeManager<'a>
Sourcepub fn start_measurement(&mut self)
pub fn start_measurement(&mut self)
Starts measuring a macro for __codesize, in a frame pushed after this call
Sourcepub fn end_measurement(&mut self)
pub fn end_measurement(&mut self)
Ends the innermost __codesize measurement
Sourcepub fn codesize_hint(&mut self, macro_name: &str) -> Option<usize>
pub fn codesize_hint(&mut self, macro_name: &str) -> Option<usize>
The size from the previous pass for a __codesize of the enclosing macro macro_name.
It is only needed when the reference sits in a measurement of another macro that does not
contain macro_name, which therefore cannot be measured there. Using it records that the
sizes must be compiled again until they are stable.
Sourcepub fn current_scope(&self) -> ScopeId
pub fn current_scope(&self) -> ScopeId
Returns the scope identifier for the currently executing macro.
Used when defining labels or creating jumps within the current macro body.
Sourcepub fn parent_scope(&self) -> ScopeId
pub fn parent_scope(&self) -> ScopeId
Returns the scope identifier for the calling macro.
Used when resolving label arguments that should be looked up in the caller’s scope. Returns the root scope if called from the top level.
Sourcepub fn push_macro(&mut self, macro_def: &'a MacroDefinition, offset: usize)
pub fn push_macro(&mut self, macro_def: &'a MacroDefinition, offset: usize)
Enters a new macro context.
Adds the macro to the call stack at the given bytecode offset. Use for root macros (MAIN/CONSTRUCTOR) without invocation details.
Sourcepub fn push_macro_with_invocation(
&mut self,
macro_def: &'a MacroDefinition,
offset: usize,
invocation: MacroInvocation,
)
pub fn push_macro_with_invocation( &mut self, macro_def: &'a MacroDefinition, offset: usize, invocation: MacroInvocation, )
Enters a new macro context with invocation arguments.
Like push_macro, but includes the invocation details for argument resolution.
Sourcepub fn pop_macro(&mut self) -> Option<&'a MacroDefinition>
pub fn pop_macro(&mut self) -> Option<&'a MacroDefinition>
Exits the current macro context.
Removes the top frame from the call stack and returns the macro definition.
Sourcepub fn current_macro(&self) -> Option<&'a MacroDefinition>
pub fn current_macro(&self) -> Option<&'a MacroDefinition>
Returns the macro definition at the top of the call stack, or None if empty.
Sourcepub fn macro_stack(&self) -> Vec<&'a MacroDefinition>
pub fn macro_stack(&self) -> Vec<&'a MacroDefinition>
Returns all macro definitions from root to current as a vector.
Sourcepub fn macro_at_depth(&self, depth: usize) -> Option<&'a MacroDefinition>
pub fn macro_at_depth(&self, depth: usize) -> Option<&'a MacroDefinition>
Returns the macro definition at the specified call stack depth, or None if out of bounds.
Sourcepub fn invocation_stack(
&self,
) -> impl Iterator<Item = (usize, Option<&MacroInvocation>)> + '_
pub fn invocation_stack( &self, ) -> impl Iterator<Item = (usize, Option<&MacroInvocation>)> + '_
Returns an iterator over (offset, invocation) pairs for all frames.
Invocation is None for root macros.
Sourcepub fn invocation_vec(&self) -> Vec<(usize, &MacroInvocation)>
pub fn invocation_vec(&self) -> Vec<(usize, &MacroInvocation)>
Returns (offset, invocation) pairs for all frames with invocation details.
Root macros without invocations are excluded from the result.
Sourcepub fn invocation_vec_up_to_depth(
&self,
target_depth: usize,
) -> Vec<(usize, &MacroInvocation)>
pub fn invocation_vec_up_to_depth( &self, target_depth: usize, ) -> Vec<(usize, &MacroInvocation)>
Returns (offset, invocation) pairs up to the specified depth.
Used to get the invocation context when resolving arguments for a macro at target_depth.
Sourcepub fn current_invocation(&self) -> Option<&MacroInvocation>
pub fn current_invocation(&self) -> Option<&MacroInvocation>
Returns the invocation details for the current macro, or None if unavailable.
Sourcepub fn current_invocation_with_offset(
&self,
) -> Option<(usize, Option<&MacroInvocation>)>
pub fn current_invocation_with_offset( &self, ) -> Option<(usize, Option<&MacroInvocation>)>
Returns the bytecode offset and invocation details for the current macro.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ScopeManager<'a>
impl<'a> RefUnwindSafe for ScopeManager<'a>
impl<'a> Send for ScopeManager<'a>
impl<'a> Sync for ScopeManager<'a>
impl<'a> Unpin for ScopeManager<'a>
impl<'a> UnsafeUnpin for ScopeManager<'a>
impl<'a> UnwindSafe for ScopeManager<'a>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<S, T> Upcast<T> for S
impl<S, T> Upcast<T> for S
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 104 bytes