pub struct TypeFlowTracker { /* private fields */ }Expand description
Tracks types flowing through Python code
The tracker maintains three primary mappings:
- Variable -> Types: tracks type flow through variable assignments
- Collection -> Types: tracks types added to collections (lists, sets, etc.)
- Parameter -> Types: tracks types passed as function parameters
All mappings use conservative over-approximation: if a type might flow, it’s recorded.
Implementations§
Source§impl TypeFlowTracker
impl TypeFlowTracker
Sourcepub fn record_assignment(&mut self, target: &str, type_id: TypeId)
pub fn record_assignment(&mut self, target: &str, type_id: TypeId)
Record that a type flows into a variable
§Example
let mut tracker = TypeFlowTracker::new();
let type_id = TypeId::from_name("Observer");
tracker.record_assignment("x", type_id);Sourcepub fn record_assignment_expr(&mut self, target: &Expr, type_id: TypeId)
pub fn record_assignment_expr(&mut self, target: &Expr, type_id: TypeId)
Record that a type flows into a variable via AST expression
This is a convenience method for integration with AST analysis
Sourcepub fn record_collection_add(&mut self, collection: &str, type_id: TypeId)
pub fn record_collection_add(&mut self, collection: &str, type_id: TypeId)
Record that a type is added to a collection
§Example
let mut tracker = TypeFlowTracker::new();
let type_id = TypeId::from_name("ConcreteObserver");
tracker.record_collection_add("self.observers", type_id);Sourcepub fn record_collection_extend(
&mut self,
collection: &str,
type_ids: Vec<TypeId>,
)
pub fn record_collection_extend( &mut self, collection: &str, type_ids: Vec<TypeId>, )
Record that types are added to a collection via extend operation
Sourcepub fn track_collection_operation(
&mut self,
collection: &str,
operation: CollectionOp,
)
pub fn track_collection_operation( &mut self, collection: &str, operation: CollectionOp, )
Track collection operation (append, extend, etc.)
Sourcepub fn record_parameter_flow(
&mut self,
func: &str,
param_idx: usize,
type_id: TypeId,
)
pub fn record_parameter_flow( &mut self, func: &str, param_idx: usize, type_id: TypeId, )
Record that a type flows into a parameter
§Example
let mut tracker = TypeFlowTracker::new();
let type_id = TypeId::from_name("Observer");
tracker.record_parameter_flow("Subject.attach", 0, type_id);Sourcepub fn register_type(&mut self, type_info: TypeInfo)
pub fn register_type(&mut self, type_info: TypeInfo)
Register type information in the type registry
Sourcepub fn get_variable_types(&self, variable: &str) -> Vec<&TypeInfo>
pub fn get_variable_types(&self, variable: &str) -> Vec<&TypeInfo>
Get all types that have flowed into a variable
Sourcepub fn get_collection_types(&self, collection: &str) -> Vec<&TypeInfo>
pub fn get_collection_types(&self, collection: &str) -> Vec<&TypeInfo>
Get all types that have flowed into a collection
Sourcepub fn get_collection_type_ids(&self, collection: &str) -> Vec<TypeId>
pub fn get_collection_type_ids(&self, collection: &str) -> Vec<TypeId>
Get all type IDs (without full info) that have flowed into a collection
Sourcepub fn get_parameter_types(
&self,
func: &str,
param_idx: usize,
) -> Vec<&TypeInfo>
pub fn get_parameter_types( &self, func: &str, param_idx: usize, ) -> Vec<&TypeInfo>
Get all types that have flowed into a parameter
Sourcepub fn get_variable_type(&self, variable: &str) -> Option<TypeId>
pub fn get_variable_type(&self, variable: &str) -> Option<TypeId>
Get a single variable type (returns first if multiple)
This is useful when you expect a variable to have a single type
Trait Implementations§
Source§impl Debug for TypeFlowTracker
impl Debug for TypeFlowTracker
Auto Trait Implementations§
impl Freeze for TypeFlowTracker
impl RefUnwindSafe for TypeFlowTracker
impl Send for TypeFlowTracker
impl Sync for TypeFlowTracker
impl Unpin for TypeFlowTracker
impl UnwindSafe for TypeFlowTracker
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
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 more