pub struct EnvironmentAnalyzer { /* private fields */ }Expand description
Environment analyzer to detect which variables need to be captured
Implementations§
Source§impl EnvironmentAnalyzer
impl EnvironmentAnalyzer
pub fn new() -> Self
Sourcepub fn enter_scope(&mut self)
pub fn enter_scope(&mut self)
Enter a new scope
Sourcepub fn exit_scope(&mut self)
pub fn exit_scope(&mut self)
Exit the current scope
Sourcepub fn define_variable(&mut self, name: &str)
pub fn define_variable(&mut self, name: &str)
Record that a variable is defined in the current scope
Sourcepub fn check_variable_reference(&mut self, name: &str)
pub fn check_variable_reference(&mut self, name: &str)
Check if a variable reference needs to be captured.
Only variables defined OUTSIDE the current function (below function_scope_level)
need capturing. Variables in the same function but in an outer block scope
(e.g., defined before an if/while/for block) are just local variables.
Sourcepub fn mark_capture_mutated(&mut self, name: &str)
pub fn mark_capture_mutated(&mut self, name: &str)
Mark a captured variable as mutated (assigned to inside the closure).
Sourcepub fn get_captured_vars(&self) -> Vec<String>
pub fn get_captured_vars(&self) -> Vec<String>
Get the list of variables that need to be captured
Sourcepub fn get_mutated_captures(&self) -> HashSet<String>
pub fn get_mutated_captures(&self) -> HashSet<String>
Get the set of captured variables that are mutated inside the closure
Sourcepub fn analyze_function(
function: &FunctionDef,
outer_scope_vars: &[String],
) -> Vec<String>
pub fn analyze_function( function: &FunctionDef, outer_scope_vars: &[String], ) -> Vec<String>
Analyze a function to determine which variables it captures
Sourcepub fn analyze_function_with_mutability(
function: &FunctionDef,
outer_scope_vars: &[String],
) -> (Vec<String>, HashSet<String>)
pub fn analyze_function_with_mutability( function: &FunctionDef, outer_scope_vars: &[String], ) -> (Vec<String>, HashSet<String>)
Analyze a function to determine which variables it captures and which are mutated.
Returns (captured_vars, mutated_captures).