/// This generates variables that store the computed sizes of the variable-length arrays in
/// the given type.
This generates variables that store the computed sizes of the variable-length arrays in
the given type.
This generates variables that store the computed sizes of the variable - length arrays in the given type .
pub fn compute_variable_array_sizes(&self, mut type_id: CTypeId) -> Result<Vec<Stmt>, String> {
        let mut stmts = vec![];
        loop {
            match self.ast_context.resolve_type(type_id).kind {
                CTypeKind::Pointer(elt) => type_id = elt.ctype,
                CTypeKind::ConstantArray(elt, _) => type_id = elt,
                CTypeKind::VariableArray(elt, Some(expr_id)) => {
                    type_id = elt;
                    // Convert this expression
                    let mut expr = self.convert_expr(ExprUse::RValue, expr_id, false, DecayRef::Default)?;
                    stmts.append(&mut expr.stmts);
                    let name = self.renamer.borrow_mut().insert(CDeclId(expr_id.0), "vla").unwrap(); // try using declref name?
                    // TODO: store the name corresponding to expr_id
                    let local = mk().local(mk().ident_pat(name), None as Option<P<Ty>>, Some(mk().cast_expr(expr.val, mk().path_ty(vec!["usize"]))));
                    stmts.push(mk().local_stmt(P(local)));
                }
                _ => break,
            }
        }
        Ok(stmts)
    }
pub fn compute_variable_array_sizes ( & self , mut type_id : CTypeId ) -> Result < Vec < Stmt > , String > { let mut stmts = vec ! [ ] ; loop { match self . ast_context . resolve_type ( type_id ) . kind { CTypeKind :: Pointer ( elt ) => type_id = elt . ctype , CTypeKind :: ConstantArray ( elt , _ ) => type_id = elt , CTypeKind :: VariableArray ( elt , Some ( expr_id ) ) => { type_id = elt ; // Convert this expression let mut expr = self . convert_expr ( ExprUse :: RValue , expr_id , false , DecayRef :: Default ) ? ; stmts . append ( & mut expr . stmts ) ; let name = self . renamer . borrow_mut ( ) . insert ( CDeclId ( expr_id . 0 ) , " " ) . unwrap ( ) ; // try using declref name? // TODO: store the name corresponding to expr_id let local = mk ( ) . local ( mk ( ) . ident_pat ( name ) , None as Option < P < Ty > > , Some ( mk ( ) . cast_expr ( expr . val , mk ( ) . path_ty ( vec ! [ " " ] ) ) ) ) ; stmts . push ( mk ( ) . local_stmt ( P ( local ) ) ) ; } _ => break , } } Ok ( stmts ) }
This generates variables that store the computed sizes of the variable-length arrays in
the given type.
This generates variables that store the computed sizes of the variable - length arrays in the given type .
&self
type_id
CTypeId