pub fn used_variable(ns: &mut Namespace, exp: &Expression, symtable: &mut Symtable) {
    match &exp {
        Expression::StorageVariable(_, _, contract_no, offset) => {
            ns.contracts[*contract_no].variables[*offset].read = true;
        }

        Expression::Variable(_, _, offset) => {
            let var = symtable.vars.get_mut(offset).unwrap();
            (*var).read = true;
        }

        Expression::ConstantVariable(_, _, Some(contract_no), offset) => {
            ns.contracts[*contract_no].variables[*offset].read = true;
        }

        Expression::ConstantVariable(_, _, None, offset) => {
            ns.constants[*offset].read = true;
        }

        Expression::StructMember(_, _, str, _) => {
            used_variable(ns, str, symtable);
        }

        Expression::Subscript(_, _, _, array, index) => {
            used_variable(ns, array, symtable);
            used_variable(ns, index, symtable);
        }

        Expression::Builtin(_, _, Builtin::ArrayLength, args) => {
            //We should not eliminate an array from the code when 'length' is called
            //So the variable is also assigned
            assigned_variable(ns, &args[0], symtable);
            used_variable(ns, &args[0], symtable);
        }
        Expression::StorageArrayLength {
            loc: _,
            ty: _,
            array,
            ..
        } => {
            //We should not eliminate an array from the code when 'length' is called
            //So the variable is also assigned
            assigned_variable(ns, array, symtable);
            used_variable(ns, array, symtable);
        }

        Expression::StorageLoad(_, _, expr)
        | Expression::Load(_, _, expr)
        | Expression::SignExt(_, _, expr)
        | Expression::ZeroExt(_, _, expr)
        | Expression::Trunc(_, _, expr)
        | Expression::Cast(_, _, expr)
        | Expression::BytesCast(_, _, _, expr) => {
            used_variable(ns, expr, symtable);
        }

        Expression::InternalFunctionCall { .. } | Expression::ExternalFunctionCall { .. } => {
            check_function_call(ns, exp, symtable);
        }

        _ => {}
    }
}
/// Mark variables as used, either in the symbol table (for local variables) or in the
/// Namespace (for global constants and storage variables)
/// The functions handles complex expressions in a recursive fashion, such as array length call,
/// assign expressions and array subscripts.
Mark variables as used, either in the symbol table (for local variables) or in the
Namespace (for global constants and storage variables)
The functions handles complex expressions in a recursive fashion, such as array length call,
assign expressions and array subscripts.
Mark variables as used either in the symbol table ( for local variables ) or in the Namespace ( for global constants and storage variables ) The functions handles complex expressions in a recursive fashion such as array length call assign expressions and array subscripts .
pub fn used_variable(ns: &mut Namespace, exp: &Expression, symtable: &mut Symtable) {
    match &exp {
        Expression::StorageVariable(_, _, contract_no, offset) => {
            ns.contracts[*contract_no].variables[*offset].read = true;
        }
        Expression::Variable(_, _, offset) => {
            let var = symtable.vars.get_mut(offset).unwrap();
            (*var).read = true;
        }
        Expression::ConstantVariable(_, _, Some(contract_no), offset) => {
            ns.contracts[*contract_no].variables[*offset].read = true;
        }
        Expression::ConstantVariable(_, _, None, offset) => {
            ns.constants[*offset].read = true;
        }
        Expression::StructMember(_, _, str, _) => {
            used_variable(ns, str, symtable);
        }
        Expression::Subscript(_, _, _, array, index) => {
            used_variable(ns, array, symtable);
            used_variable(ns, index, symtable);
        }
        Expression::Builtin(_, _, Builtin::ArrayLength, args) => {
            //We should not eliminate an array from the code when 'length' is called
            //So the variable is also assigned
            assigned_variable(ns, &args[0], symtable);
            used_variable(ns, &args[0], symtable);
        }
        Expression::StorageArrayLength {
            loc: _,
            ty: _,
            array,
            ..
        } => {
            //We should not eliminate an array from the code when 'length' is called
            //So the variable is also assigned
            assigned_variable(ns, array, symtable);
            used_variable(ns, array, symtable);
        }
        Expression::StorageLoad(_, _, expr)
        | Expression::Load(_, _, expr)
        | Expression::SignExt(_, _, expr)
        | Expression::ZeroExt(_, _, expr)
        | Expression::Trunc(_, _, expr)
        | Expression::Cast(_, _, expr)
        | Expression::BytesCast(_, _, _, expr) => {
            used_variable(ns, expr, symtable);
        }
        Expression::InternalFunctionCall { .. } | Expression::ExternalFunctionCall { .. } => {
            check_function_call(ns, exp, symtable);
        }
        _ => {}
    }
}
pub fn used_variable ( ns : & mut Namespace , exp : & Expression , symtable : & mut Symtable ) { match & exp { Expression :: StorageVariable ( _ , _ , contract_no , offset ) => { ns . contracts [ * contract_no ] . variables [ * offset ] . read = true ; } Expression :: Variable ( _ , _ , offset ) => { let var = symtable . vars . get_mut ( offset ) . unwrap ( ) ; ( * var ) . read = true ; } Expression :: ConstantVariable ( _ , _ , Some ( contract_no ) , offset ) => { ns . contracts [ * contract_no ] . variables [ * offset ] . read = true ; } Expression :: ConstantVariable ( _ , _ , None , offset ) => { ns . constants [ * offset ] . read = true ; } Expression :: StructMember ( _ , _ , str , _ ) => { used_variable ( ns , str , symtable ) ; } Expression :: Subscript ( _ , _ , _ , array , index ) => { used_variable ( ns , array , symtable ) ; used_variable ( ns , index , symtable ) ; } Expression :: Builtin ( _ , _ , Builtin :: ArrayLength , args ) => { //We should not eliminate an array from the code when 'length' is called //So the variable is also assigned assigned_variable ( ns , & args [ 0 ] , symtable ) ; used_variable ( ns , & args [ 0 ] , symtable ) ; } Expression :: StorageArrayLength { loc : _ , ty : _ , array , .. } => { //We should not eliminate an array from the code when 'length' is called //So the variable is also assigned assigned_variable ( ns , array , symtable ) ; used_variable ( ns , array , symtable ) ; } Expression :: StorageLoad ( _ , _ , expr ) | Expression :: Load ( _ , _ , expr ) | Expression :: SignExt ( _ , _ , expr ) | Expression :: ZeroExt ( _ , _ , expr ) | Expression :: Trunc ( _ , _ , expr ) | Expression :: Cast ( _ , _ , expr ) | Expression :: BytesCast ( _ , _ , _ , expr ) => { used_variable ( ns , expr , symtable ) ; } Expression :: InternalFunctionCall { .. } | Expression :: ExternalFunctionCall { .. } => { check_function_call ( ns , exp , symtable ) ; } _ => { } } }
Mark variables as used, either in the symbol table (for local variables) or in the
Namespace (for global constants and storage variables)
The functions handles complex expressions in a recursive fashion, such as array length call,
assign expressions and array subscripts.
Mark variables as used either in the symbol table ( for local variables ) or in the Namespace ( for global constants and storage variables ) The functions handles complex expressions in a recursive fashion such as array length call assign expressions and array subscripts .
ns
&mut Namespace
exp
&Expression
symtable
&mut Symtable
ns
&mut Namespace
exp
&Expression
symtable
&mut Symtable