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
//! Rewrite `if` / `else if` equality chains into `switch` statements.
//!
//! This pass is intentionally conservative: it only rewrites chains that
//! compare the same scrutinee expression against literal case values.
//!
//! Two patterns are recognized:
//! - `if/else if` chains (minimum 2 cases)
//! - Consecutive standalone `if` blocks comparing the same variable (minimum 3 cases)

use super::super::HighLevelEmitter;

mod chain;
mod guards;
mod parse;
mod scan;

#[cfg(test)]
mod tests;

impl HighLevelEmitter {
    /// Rewrite eligible `if` / `else if` chains into `switch` blocks.
    pub(crate) fn rewrite_switch_statements(statements: &mut Vec<String>) {
        let mut index = 0usize;
        while index < statements.len() {
            if let Some((replacement, end)) =
                guards::try_build_guarded_goto_switch(statements, index)
            {
                statements.splice(index..=end, replacement);
                index += 1;
                continue;
            }
            if let Some((replacement, end)) = chain::try_build_switch(statements, index) {
                statements.splice(index..=end, replacement);
                index += 1;
                continue;
            }
            index += 1;
        }
    }
}