Skip to main content

ArgumentStorage

Struct ArgumentStorage 

pub struct ArgumentStorage { /* private fields */ }
Expand description

Storage for method arguments.

Arguments are passed to a method by the caller and can be read or modified during method execution. For instance methods, argument 0 is typically this.

§Example

use dotscope::emulation::{ArgumentStorage, EmValue};
use dotscope::metadata::typesystem::CilFlavor;

// Create arguments from caller's values
let mut args = ArgumentStorage::new(
    vec![EmValue::I32(10), EmValue::I32(20)],
    vec![CilFlavor::I4, CilFlavor::I4],
);

// Access arguments
assert_eq!(args.get(0).unwrap(), &EmValue::I32(10));
assert_eq!(args.get(1).unwrap(), &EmValue::I32(20));

// Modify argument (for ref/out parameters)
args.set(0, EmValue::I32(42)).unwrap();

Implementations§

§

impl ArgumentStorage

pub fn new(values: Vec<EmValue>, types: Vec<CilFlavor>) -> Self

Creates argument storage from caller values and types.

§Arguments
  • values - Values passed by the caller
  • types - CIL type flavors for each argument
§Panics

Panics if values and types have different lengths.

pub fn with_this( this_ref: EmValue, arg_values: Vec<EmValue>, arg_types: Vec<CilFlavor>, ) -> Self

Creates argument storage for an instance method.

Argument 0 will be the this reference.

§Arguments
  • this_ref - The ‘this’ object reference
  • arg_values - Additional argument values
  • arg_types - CIL type flavors for additional arguments

pub fn empty() -> Self

Creates empty argument storage.

pub fn get(&self, index: usize) -> Result<&EmValue>

Gets the value of an argument.

§Arguments
  • index - The argument index (0-based)
§Errors

Returns EmulationError::ArgumentIndexOutOfBounds if index is out of bounds.

pub fn get_mut(&mut self, index: usize) -> Result<&mut EmValue>

Gets a mutable reference to an argument.

§Arguments
  • index - The argument index (0-based)
§Errors

Returns EmulationError::ArgumentIndexOutOfBounds if index is out of bounds.

pub fn set(&mut self, index: usize, value: EmValue) -> Result<()>

Sets the value of an argument.

This is used for ref/out parameters that can be modified.

§Arguments
  • index - The argument index (0-based)
  • value - The new value
§Errors

Returns error if index is out of bounds or type mismatches.

pub fn get_type(&self, index: usize) -> Result<&CilFlavor>

Gets the type of an argument.

§Arguments
  • index - The argument index (0-based)
§Errors

Returns error if index is out of bounds.

pub fn this(&self) -> Option<&EmValue>

Gets the this reference for instance methods.

§Returns

Some(&EmValue) if this is an instance method, None otherwise.

pub fn has_this(&self) -> bool

Returns true if this is an instance method.

pub fn count(&self) -> usize

Returns the number of arguments.

pub fn is_empty(&self) -> bool

Returns true if there are no arguments.

pub fn values(&self) -> &[EmValue]

Returns a slice of all argument values.

pub fn types(&self) -> &[CilFlavor]

Returns a slice of all argument types.

pub fn iter(&self) -> impl Iterator<Item = (usize, &EmValue)>

Returns an iterator over (index, value) pairs.

pub fn snapshot(&self) -> Vec<EmValue>

Creates a snapshot of the current argument state.

pub fn restore(&mut self, snapshot: Vec<EmValue>)

Restores arguments from a previous snapshot.

§Panics

Panics if snapshot length doesn’t match argument count.

Trait Implementations§

§

impl Clone for ArgumentStorage

§

fn clone(&self) -> ArgumentStorage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for ArgumentStorage

§

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

Formats the value using the given formatter. Read more
§

impl Default for ArgumentStorage

§

fn default() -> Self

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

impl Display for ArgumentStorage

§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.