Enum SsaType
pub enum SsaType {
Show 30 variants
Void,
Bool,
I8,
U8,
I16,
U16,
I32,
U32,
I64,
U64,
NativeInt,
NativeUInt,
F32,
F64,
Char,
Object,
String,
Class(TypeRef),
ValueType(TypeRef),
GenericInst(Box<SsaType>, Vec<SsaType>),
Array(Box<SsaType>, u32),
Pointer(Box<SsaType>),
ByRef(Box<SsaType>),
TypedReference,
GenericParam(u32),
MethodGenericParam(u32),
FnPtr(Box<FnPtrSig>),
Null,
Unknown,
Varying,
}Expand description
SSA type representation for CIL types.
This enum provides a simplified view of .NET types suitable for SSA analysis. It captures the essential type information without requiring full metadata resolution for common operations.
§Examples
use dotscope::analysis::SsaType;
let int_type = SsaType::I32;
let string_type = SsaType::String;
let array_type = SsaType::Array(Box::new(SsaType::I32), 1);
assert!(int_type.is_primitive());
assert!(string_type.is_reference());
assert!(array_type.is_array());Variants§
Void
No return value (void).
Bool
Boolean type (System.Boolean).
I8
Signed 8-bit integer (System.SByte).
U8
Unsigned 8-bit integer (System.Byte).
I16
Signed 16-bit integer (System.Int16).
U16
Unsigned 16-bit integer (System.UInt16).
I32
Signed 32-bit integer (System.Int32).
U32
Unsigned 32-bit integer (System.UInt32).
I64
Signed 64-bit integer (System.Int64).
U64
Unsigned 64-bit integer (System.UInt64).
NativeInt
Native-sized signed integer (System.IntPtr).
NativeUInt
Native-sized unsigned integer (System.UIntPtr).
F32
32-bit floating point (System.Single).
F64
64-bit floating point (System.Double).
Char
Unicode character (System.Char).
Object
System.Object reference.
String
System.String reference.
Class(TypeRef)
Reference to a specific class type.
ValueType(TypeRef)
Value type (struct) - stored inline, not by reference.
GenericInst(Box<SsaType>, Vec<SsaType>)
Generic instantiation of a type with concrete type arguments.
For example, List<int> is GenericInst(Class(List), [I32]).
Array(Box<SsaType>, u32)
Single-dimensional or multi-dimensional array.
The u32 is the rank (number of dimensions). Rank 1 is a vector (SZ array).
Pointer(Box<SsaType>)
Unmanaged pointer to a type.
ByRef(Box<SsaType>)
Managed reference (byref) to a type.
TypedReference
Typed reference (System.TypedReference).
GenericParam(u32)
Generic type parameter (e.g., !0, !1).
The u32 is the parameter index.
MethodGenericParam(u32)
Generic method parameter (e.g., !!0, !!1).
The u32 is the parameter index.
FnPtr(Box<FnPtrSig>)
Function pointer type.
Null
Known null constant (more precise than Object).
Unknown
Type not yet inferred or unknown.
This is used during type inference before a type is determined.
Varying
Type that varies depending on control flow (for incomplete inference).
Implementations§
§impl SsaType
impl SsaType
pub const fn is_primitive(&self) -> bool
pub const fn is_primitive(&self) -> bool
Returns true if this is a primitive numeric or boolean type.
pub const fn is_integer(&self) -> bool
pub const fn is_integer(&self) -> bool
Returns true if this is an integer type (signed or unsigned).
pub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Returns true if this is a reference type (can be null).
pub const fn is_value_type(&self) -> bool
pub const fn is_value_type(&self) -> bool
Returns true if this is a value type (struct).
pub const fn is_pointer(&self) -> bool
pub const fn is_pointer(&self) -> bool
Returns true if this is a pointer type (managed or unmanaged).
pub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Returns true if this type is unknown or not yet inferred.
pub const fn is_generic_param(&self) -> bool
pub const fn is_generic_param(&self) -> bool
Returns true if this is a generic parameter.
pub fn array_element_type(&self) -> Option<&SsaType>
pub fn array_element_type(&self) -> Option<&SsaType>
Returns the element type if this is an array.
pub const fn array_rank(&self) -> Option<u32>
pub const fn array_rank(&self) -> Option<u32>
Returns the array rank (number of dimensions) if this is an array.
pub fn pointee_type(&self) -> Option<&SsaType>
pub fn pointee_type(&self) -> Option<&SsaType>
Returns the pointed-to type if this is a pointer or byref.
pub const fn size_bytes(&self) -> Option<u32>
pub const fn size_bytes(&self) -> Option<u32>
Returns the size in bytes for primitive types, if known.
Returns None for reference types and types with platform-dependent sizes.
pub fn stack_type(&self) -> SsaType
pub fn stack_type(&self) -> SsaType
Returns the stack slot type for this SSA type.
CIL uses a normalized set of types on the evaluation stack:
- All integer types smaller than 32 bits become I32
- Float types stay as-is (F32 becomes F64 in some contexts)
- References stay as references
pub fn storage_class(&self) -> TypeClass
pub fn storage_class(&self) -> TypeClass
Returns the storage class of this type.
Used for local variable coalescing to determine which types can share the same storage slot without requiring conversion.
pub fn is_compatible_for_storage(&self, other: &SsaType) -> bool
pub fn is_compatible_for_storage(&self, other: &SsaType) -> bool
Checks if this type can share a local slot with another type.
Two types are compatible for storage if they have the same size and alignment requirements, meaning they can be stored in the same local variable slot without data corruption.
§Examples
use dotscope::analysis::SsaType;
// Same types are compatible
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::I32));
// 32-bit integers can share slots
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::U32));
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::Bool));
// Reference types can share slots
assert!(SsaType::Object.is_compatible_for_storage(&SsaType::String));
// Different sizes are incompatible
assert!(!SsaType::I32.is_compatible_for_storage(&SsaType::I64));pub fn merge(&self, other: &SsaType) -> SsaType
pub fn merge(&self, other: &SsaType) -> SsaType
Merges two types at a control flow join point.
Returns the common type if compatible, or Varying if incompatible.
pub fn to_type_signature(&self) -> TypeSignature
pub fn to_type_signature(&self) -> TypeSignature
Converts this SSA type to a TypeSignature for signature encoding.
This enables generating local variable signatures from SSA type information.
Analysis-only types (Unknown, Null, Varying) are converted to Object
as a safe fallback.
§Returns
The corresponding TypeSignature that can be used for signature encoding.
pub fn from_cil_flavor(flavor: &CilFlavor, token: Token) -> Self
pub fn from_cil_flavor(flavor: &CilFlavor, token: Token) -> Self
Creates an SsaType from a CilFlavor.
This converts the metadata type flavor to the SSA type representation. For complex types (arrays, pointers, generic instances), a token is needed to create a proper type reference.
§Arguments
flavor- The CIL type flavor to converttoken- The metadata token for creating type references
pub fn from_type_signature(
signature: &TypeSignature,
assembly: &CilObject,
) -> Self
pub fn from_type_signature( signature: &TypeSignature, assembly: &CilObject, ) -> Self
Creates an SsaType from a TypeSignature.
This converts a metadata type signature to the SSA type representation. For class and value types, the assembly context is used to resolve type tokens to determine if they are primitives.
§Arguments
signature- The type signature to convertassembly- Assembly context for resolving type tokens
pub fn from_type_token(token: Token, assembly: &CilObject) -> Self
pub fn from_type_token(token: Token, assembly: &CilObject) -> Self
Creates an SsaType from a type token by resolving it in the assembly.
Handles TypeDef (0x02), TypeRef (0x01), and TypeSpec (0x1B) tokens.
Trait Implementations§
impl Eq for SsaType
impl StructuralPartialEq for SsaType
Auto Trait Implementations§
impl Freeze for SsaType
impl RefUnwindSafe for SsaType
impl Send for SsaType
impl Sync for SsaType
impl Unpin for SsaType
impl UnsafeUnpin for SsaType
impl UnwindSafe for SsaType
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more