pub(crate) fn resolve_switch(
    yul_switch: &pt::YulSwitch,
    context: &ExprContext,
    reachable: bool,
    function_table: &mut FunctionsTable,
    loop_scope: &mut LoopScopes,
    symtable: &mut Symtable,
    ns: &mut Namespace,
) -> Result<(YulStatement, bool), ()> {
    let resolved_condition =
        resolve_condition(&yul_switch.condition, context, symtable, function_table, ns)?;
    let mut default_block: Option<YulBlock> = None;
    let mut case_blocks: Vec<CaseBlock> = Vec::with_capacity(yul_switch.cases.len());
    let mut next_reachable = reachable;
    for item in &yul_switch.cases {
        let block_reachable = resolve_case_or_default(
            item,
            &mut default_block,
            &mut case_blocks,
            context,
            next_reachable,
            function_table,
            loop_scope,
            symtable,
            ns,
        )?;
        next_reachable |= block_reachable;
    }

    if yul_switch.default.is_some() && default_block.is_some() {
        ns.diagnostics.push(Diagnostic::error(
            yul_switch.default.as_ref().unwrap().loc(),
            "Only one default block is allowed".to_string(),
        ));
        return Err(());
    } else if let Some(default_unwrapped) = &yul_switch.default {
        let block_reachable = resolve_case_or_default(
            default_unwrapped,
            &mut default_block,
            &mut case_blocks,
            context,
            next_reachable,
            function_table,
            loop_scope,
            symtable,
            ns,
        )?;
        next_reachable |= block_reachable;
    } else if yul_switch.default.is_none() && default_block.is_none() {
        next_reachable |= true;
    }

    Ok((
        YulStatement::Switch {
            loc: yul_switch.loc,
            reachable,
            condition: resolved_condition,
            cases: case_blocks,
            default: default_block,
        },
        next_reachable,
    ))
}
/// Resolve switch statement
/// Returns the resolved block and a bool to indicate if the next statement is reachable.
Resolve switch statement
Returns the resolved block and a bool to indicate if the next statement is reachable.
Resolve switch statement Returns the resolved block and a bool to indicate if the next statement is reachable .
pub(crate) fn resolve_switch(
    yul_switch: &pt::YulSwitch,
    context: &ExprContext,
    reachable: bool,
    function_table: &mut FunctionsTable,
    loop_scope: &mut LoopScopes,
    symtable: &mut Symtable,
    ns: &mut Namespace,
) -> Result<(YulStatement, bool), ()> {
    let resolved_condition =
        resolve_condition(&yul_switch.condition, context, symtable, function_table, ns)?;
    let mut default_block: Option<YulBlock> = None;
    let mut case_blocks: Vec<CaseBlock> = Vec::with_capacity(yul_switch.cases.len());
    let mut next_reachable = reachable;
    for item in &yul_switch.cases {
        let block_reachable = resolve_case_or_default(
            item,
            &mut default_block,
            &mut case_blocks,
            context,
            next_reachable,
            function_table,
            loop_scope,
            symtable,
            ns,
        )?;
        next_reachable |= block_reachable;
    }
    if yul_switch.default.is_some() && default_block.is_some() {
        ns.diagnostics.push(Diagnostic::error(
            yul_switch.default.as_ref().unwrap().loc(),
            "Only one default block is allowed".to_string(),
        ));
        return Err(());
    } else if let Some(default_unwrapped) = &yul_switch.default {
        let block_reachable = resolve_case_or_default(
            default_unwrapped,
            &mut default_block,
            &mut case_blocks,
            context,
            next_reachable,
            function_table,
            loop_scope,
            symtable,
            ns,
        )?;
        next_reachable |= block_reachable;
    } else if yul_switch.default.is_none() && default_block.is_none() {
        next_reachable |= true;
    }
    Ok((
        YulStatement::Switch {
            loc: yul_switch.loc,
            reachable,
            condition: resolved_condition,
            cases: case_blocks,
            default: default_block,
        },
        next_reachable,
    ))
}
pub ( crate ) fn resolve_switch ( yul_switch : & pt :: YulSwitch , context : & ExprContext , reachable : bool , function_table : & mut FunctionsTable , loop_scope : & mut LoopScopes , symtable : & mut Symtable , ns : & mut Namespace , ) -> Result < ( YulStatement , bool ) , ( ) > { let resolved_condition = resolve_condition ( & yul_switch . condition , context , symtable , function_table , ns ) ? ; let mut default_block : Option < YulBlock > = None ; let mut case_blocks : Vec < CaseBlock > = Vec :: with_capacity ( yul_switch . cases . len ( ) ) ; let mut next_reachable = reachable ; for item in & yul_switch . cases { let block_reachable = resolve_case_or_default ( item , & mut default_block , & mut case_blocks , context , next_reachable , function_table , loop_scope , symtable , ns , ) ? ; next_reachable |= block_reachable ; } if yul_switch . default . is_some ( ) && default_block . is_some ( ) { ns . diagnostics . push ( Diagnostic :: error ( yul_switch . default . as_ref ( ) . unwrap ( ) . loc ( ) , " " . to_string ( ) , ) ) ; return Err ( ( ) ) ; } else if let Some ( default_unwrapped ) = & yul_switch . default { let block_reachable = resolve_case_or_default ( default_unwrapped , & mut default_block , & mut case_blocks , context , next_reachable , function_table , loop_scope , symtable , ns , ) ? ; next_reachable |= block_reachable ; } else if yul_switch . default . is_none ( ) && default_block . is_none ( ) { next_reachable |= true ; } Ok ( ( YulStatement :: Switch { loc : yul_switch . loc , reachable , condition : resolved_condition , cases : case_blocks , default : default_block , } , next_reachable , ) ) }
Resolve switch statement
Returns the resolved block and a bool to indicate if the next statement is reachable.
Resolve switch statement Returns the resolved block and a bool to indicate if the next statement is reachable .
yul_switch
&pt::YulSwitch
context
&ExprContext
reachable
bool
function_table
&mut FunctionsTable
loop_scope
&mut LoopScopes
symtable
&mut Symtable
ns
&mut Namespace
yul_switch
&pt::YulSwitch
context
&ExprContext
reachable
bool
function_table
&mut FunctionsTable
loop_scope
&mut LoopScopes
symtable
&mut Symtable
ns
&mut Namespace