fn resolve_case_block(
    loc: &pt::Loc,
    has_default: bool,
    condition: &pt::YulExpression,
    block: &[pt::YulStatement],
    context: &ExprContext,
    reachable: bool,
    function_table: &mut FunctionsTable,
    loop_scope: &mut LoopScopes,
    symtable: &mut Symtable,
    ns: &mut Namespace,
) -> Result<(CaseBlock, bool), ()> {
    if has_default {
        ns.diagnostics.push(Diagnostic::error(
            *loc,
            "A case-block cannot come after a default block".to_string(),
        ));
        return Err(());
    }
    let resolved_condition =
        resolve_yul_expression(condition, context, symtable, function_table, ns)?;
    match resolved_condition {
        YulExpression::NumberLiteral(..)
        | YulExpression::StringLiteral(..)
        | YulExpression::BoolLiteral(..) => (),

        _ => {
            ns.diagnostics.push(Diagnostic::error(
                resolved_condition.loc(),
                "'case' can only be followed by a literal".to_string(),
            ));
            return Err(());
        }
    }

    let case_block = resolve_yul_block(
        loc,
        block,
        context,
        reachable,
        loop_scope,
        function_table,
        symtable,
        ns,
    );

    Ok((
        CaseBlock {
            loc: *loc,
            condition: resolved_condition,
            block: case_block.0,
        },
        case_block.1,
    ))
}
/// Resolve a case from a switch statement
Resolve a case from a switch statement
Resolve a case from a switch statement
fn resolve_case_block(
    loc: &pt::Loc,
    has_default: bool,
    condition: &pt::YulExpression,
    block: &[pt::YulStatement],
    context: &ExprContext,
    reachable: bool,
    function_table: &mut FunctionsTable,
    loop_scope: &mut LoopScopes,
    symtable: &mut Symtable,
    ns: &mut Namespace,
) -> Result<(CaseBlock, bool), ()> {
    if has_default {
        ns.diagnostics.push(Diagnostic::error(
            *loc,
            "A case-block cannot come after a default block".to_string(),
        ));
        return Err(());
    }
    let resolved_condition =
        resolve_yul_expression(condition, context, symtable, function_table, ns)?;
    match resolved_condition {
        YulExpression::NumberLiteral(..)
        | YulExpression::StringLiteral(..)
        | YulExpression::BoolLiteral(..) => (),
        _ => {
            ns.diagnostics.push(Diagnostic::error(
                resolved_condition.loc(),
                "'case' can only be followed by a literal".to_string(),
            ));
            return Err(());
        }
    }
    let case_block = resolve_yul_block(
        loc,
        block,
        context,
        reachable,
        loop_scope,
        function_table,
        symtable,
        ns,
    );
    Ok((
        CaseBlock {
            loc: *loc,
            condition: resolved_condition,
            block: case_block.0,
        },
        case_block.1,
    ))
}
fn resolve_case_block ( loc : & pt :: Loc , has_default : bool , condition : & pt :: YulExpression , block : & [ pt :: YulStatement ] , context : & ExprContext , reachable : bool , function_table : & mut FunctionsTable , loop_scope : & mut LoopScopes , symtable : & mut Symtable , ns : & mut Namespace , ) -> Result < ( CaseBlock , bool ) , ( ) > { if has_default { ns . diagnostics . push ( Diagnostic :: error ( * loc , " " . to_string ( ) , ) ) ; return Err ( ( ) ) ; } let resolved_condition = resolve_yul_expression ( condition , context , symtable , function_table , ns ) ? ; match resolved_condition { YulExpression :: NumberLiteral ( .. ) | YulExpression :: StringLiteral ( .. ) | YulExpression :: BoolLiteral ( .. ) => ( ) , _ => { ns . diagnostics . push ( Diagnostic :: error ( resolved_condition . loc ( ) , " " . to_string ( ) , ) ) ; return Err ( ( ) ) ; } } let case_block = resolve_yul_block ( loc , block , context , reachable , loop_scope , function_table , symtable , ns , ) ; Ok ( ( CaseBlock { loc : * loc , condition : resolved_condition , block : case_block . 0 , } , case_block . 1 , ) ) }
Resolve a case from a switch statement
Resolve a case from a switch statement
loc
&pt::Loc
has_default
bool
condition
&pt::YulExpression
block
&[pt::YulStatement]
context
&ExprContext
reachable
bool
function_table
&mut FunctionsTable
loop_scope
&mut LoopScopes
symtable
&mut Symtable
ns
&mut Namespace
loc
&pt::Loc
has_default
bool
condition
&pt::YulExpression
block
&[pt::YulStatement]
context
&ExprContext
reachable
bool
function_table
&mut FunctionsTable
loop_scope
&mut LoopScopes
symtable
&mut Symtable
ns
&mut Namespace