TypeFlowTracker

Struct TypeFlowTracker 

Source
pub struct TypeFlowTracker { /* private fields */ }
Expand description

Tracks types flowing through Python code

The tracker maintains three primary mappings:

  1. Variable -> Types: tracks type flow through variable assignments
  2. Collection -> Types: tracks types added to collections (lists, sets, etc.)
  3. 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

Source

pub fn new() -> Self

Create a new type flow tracker

Source

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);
Source

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

Source

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);
Source

pub fn record_collection_extend( &mut self, collection: &str, type_ids: Vec<TypeId>, )

Record that types are added to a collection via extend operation

Source

pub fn track_collection_operation( &mut self, collection: &str, operation: CollectionOp, )

Track collection operation (append, extend, etc.)

Source

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);
Source

pub fn register_type(&mut self, type_info: TypeInfo)

Register type information in the type registry

Source

pub fn get_variable_types(&self, variable: &str) -> Vec<&TypeInfo>

Get all types that have flowed into a variable

Source

pub fn get_collection_types(&self, collection: &str) -> Vec<&TypeInfo>

Get all types that have flowed into a collection

Source

pub fn get_collection_type_ids(&self, collection: &str) -> Vec<TypeId>

Get all type IDs (without full info) that have flowed into a collection

Source

pub fn get_parameter_types( &self, func: &str, param_idx: usize, ) -> Vec<&TypeInfo>

Get all types that have flowed into a parameter

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TypeFlowTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.