neo-decompiler 0.10.1

Neo N3 NEF decompiler: parse, disassemble, lift bytecode to high-level pseudocode and C# skeletons, with a CLI, JSON reports, and optional WebAssembly bindings.
Documentation
use std::fmt;

/// A versioned variable in SSA form.
///
/// Each SSA variable combines a base name (like `"local_0"` or `"arg_1"`) with
/// a version number. The SSA property guarantees that each unique `(base,
/// version)` pair is assigned exactly once.
///
/// # Display
///
/// `SsaVariable` implements `Display` to show only the base name, hiding the
/// version from end users. This keeps SSA as an internal analysis detail while
/// maintaining clean output.
///
/// # Examples
///
/// ```
/// use neo_decompiler::decompiler::cfg::ssa::SsaVariable;
///
/// let v0 = SsaVariable::initial("x".to_string());
/// let v1 = v0.next();
///
/// assert_eq!(v0.base, "x");
/// assert_eq!(v0.version, 0);
/// assert_eq!(v1.version, 1);
///
/// // Display hides the version
/// assert_eq!(v0.to_string(), "x");
/// assert_eq!(v1.to_string(), "x");
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SsaVariable {
    /// Base variable name (e.g., "local_0", "arg_1", "static_2").
    pub base: String,
    /// Version number ensuring single-assignment property.
    pub version: usize,
}

impl SsaVariable {
    /// Create a new SSA variable with a specific version.
    #[must_use]
    pub const fn new(base: String, version: usize) -> Self {
        Self { base, version }
    }

    /// Create an initial SSA variable (version 0).
    ///
    /// Use this for the first definition of a variable.
    #[must_use]
    pub fn initial(base: String) -> Self {
        Self::new(base, 0)
    }

    /// Create the next version of this variable.
    ///
    /// Used during SSA renaming when a new definition is encountered.
    #[must_use]
    pub fn next(&self) -> Self {
        Self::new(self.base.clone(), self.version + 1)
    }

    /// Check if this is the initial version (version 0).
    #[must_use]
    pub const fn is_initial(&self) -> bool {
        self.version == 0
    }
}

impl fmt::Display for SsaVariable {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        // Display only the base name, hiding version from users.
        write!(f, "{}", self.base)
    }
}