pub struct Context {Show 15 fields
pub vars: IndexMap<String, Union>,
pub assigned_vars: HashSet<String>,
pub possibly_assigned_vars: HashSet<String>,
pub self_fqcn: Option<Arc<str>>,
pub parent_fqcn: Option<Arc<str>>,
pub static_fqcn: Option<Arc<str>>,
pub fn_return_type: Option<Union>,
pub inside_loop: bool,
pub inside_finally: bool,
pub inside_constructor: bool,
pub strict_types: bool,
pub tainted_vars: HashSet<String>,
pub read_vars: HashSet<String>,
pub param_names: HashSet<String>,
pub diverges: bool,
}Fields§
§vars: IndexMap<String, Union>Types of variables at this point in execution.
assigned_vars: HashSet<String>Variables that are definitely assigned at this point.
possibly_assigned_vars: HashSet<String>Variables that might be assigned (e.g. only in one if branch).
self_fqcn: Option<Arc<str>>The class in whose body we are analysing (self).
parent_fqcn: Option<Arc<str>>The parent class (parent).
static_fqcn: Option<Arc<str>>Late-static-binding class (static).
fn_return_type: Option<Union>Declared return type for the current function/method.
inside_loop: boolWhether we are currently inside a loop.
inside_finally: boolWhether we are currently inside a finally block.
inside_constructor: boolWhether we are inside a constructor.
strict_types: boolWhether strict_types=1 is declared for this file.
tainted_vars: HashSet<String>Variables that carry tainted (user-controlled) values at this point. Used by taint analysis (M19).
read_vars: HashSet<String>Variables that have been read at least once in this scope. Used by UnusedParam detection (M18).
param_names: HashSet<String>Names of function/method parameters in this scope (stripped of $).
Used to exclude parameters from UnusedVariable detection.
diverges: boolWhether every execution path through this context has diverged (returned, thrown, or exited). Used to detect “all catch branches return” so that variables assigned only in the try body are considered definitely assigned after the try/catch.
Implementations§
Source§impl Context
impl Context
pub fn new() -> Self
Sourcepub fn for_function(
params: &[FnParam],
return_type: Option<Union>,
self_fqcn: Option<Arc<str>>,
parent_fqcn: Option<Arc<str>>,
static_fqcn: Option<Arc<str>>,
strict_types: bool,
) -> Self
pub fn for_function( params: &[FnParam], return_type: Option<Union>, self_fqcn: Option<Arc<str>>, parent_fqcn: Option<Arc<str>>, static_fqcn: Option<Arc<str>>, strict_types: bool, ) -> Self
Create a context seeded with the given parameters.
Sourcepub fn for_method(
params: &[FnParam],
return_type: Option<Union>,
self_fqcn: Option<Arc<str>>,
parent_fqcn: Option<Arc<str>>,
static_fqcn: Option<Arc<str>>,
strict_types: bool,
inside_constructor: bool,
) -> Self
pub fn for_method( params: &[FnParam], return_type: Option<Union>, self_fqcn: Option<Arc<str>>, parent_fqcn: Option<Arc<str>>, static_fqcn: Option<Arc<str>>, strict_types: bool, inside_constructor: bool, ) -> Self
Like for_function but also sets inside_constructor.
Sourcepub fn get_var(&self, name: &str) -> Union
pub fn get_var(&self, name: &str) -> Union
Get the type of a variable. Returns mixed if not found.
Sourcepub fn set_var(&mut self, name: impl Into<String>, ty: Union)
pub fn set_var(&mut self, name: impl Into<String>, ty: Union)
Set the type of a variable and mark it as assigned.
Sourcepub fn var_is_defined(&self, name: &str) -> bool
pub fn var_is_defined(&self, name: &str) -> bool
Check if a variable is definitely in scope.
Sourcepub fn var_possibly_defined(&self, name: &str) -> bool
pub fn var_possibly_defined(&self, name: &str) -> bool
Check if a variable might be defined (but not certainly).
Sourcepub fn taint_var(&mut self, name: &str)
pub fn taint_var(&mut self, name: &str)
Mark a variable as carrying tainted (user-controlled) data.
Sourcepub fn is_tainted(&self, name: &str) -> bool
pub fn is_tainted(&self, name: &str) -> bool
Returns true if the variable is known to carry tainted data.
Sourcepub fn merge_branches(
pre: &Context,
if_ctx: Context,
else_ctx: Option<Context>,
) -> Context
pub fn merge_branches( pre: &Context, if_ctx: Context, else_ctx: Option<Context>, ) -> Context
Merge two branch contexts at a join point (e.g. end of if/else).
- vars present in both: merged union of types
- vars present in only one branch: marked
possibly_undefined - pre-existing vars from before the branch: preserved
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more