pub fn convert_condition(&self, target: bool, cond_id: CExprId, is_static: bool) -> Result<WithStmts<P<Expr>>, String> {
        let ty_id = self.ast_context[cond_id].kind.get_type().ok_or_else(|| format!("bad condition type"))?;

        let null_pointer_case =
            |negated: bool, ptr: CExprId| -> Result<WithStmts<P<Expr>>, String> {
                    let val = self.convert_expr(ExprUse::RValue, ptr, is_static, DecayRef::Yes)?;
                    let ptr_type = self.ast_context[ptr].kind.get_type().ok_or_else(|| format!("bad pointer type for condition"))?;
                    Ok(val.map(|e| {
                        if self.ast_context.is_function_pointer(ptr_type) {
                            if negated {
                                mk().method_call_expr(e, "is_some", vec![] as Vec<P<Expr>>)
                            } else {
                                mk().method_call_expr(e, "is_none", vec![] as Vec<P<Expr>>)
                            }
                        } else {
                            let is_null = mk().method_call_expr(e, "is_null", vec![] as Vec<P<Expr>>);
                            if negated {
                                mk().unary_expr(ast::UnOp::Not, is_null)
                            } else {
                                is_null
                            }
                        }
                    }))
                };

        match self.ast_context[cond_id].kind {
            CExprKind::Binary(_, c_ast::BinOp::EqualEqual, null_expr, ptr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(!target, ptr)
            }

            CExprKind::Binary(_, c_ast::BinOp::EqualEqual, ptr, null_expr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(!target, ptr)
            }

            CExprKind::Binary(_, c_ast::BinOp::NotEqual, null_expr, ptr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(target, ptr)
            }

            CExprKind::Binary(_, c_ast::BinOp::NotEqual, ptr, null_expr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(target, ptr)
            }

            CExprKind::Unary(_, c_ast::UnOp::Not, subexpr_id) => {
                self.convert_condition(!target, subexpr_id, is_static)
            }

            _ => {
                // DecayRef could (and probably should) be Default instead of Yes here; however, as noted
                // in https://github.com/rust-lang/rust/issues/53772, you cant compare a reference (lhs) to
                // a ptr (rhs) (even though the reverse works!). We could also be smarter here and just
                // specify Yes for that particular case, given enough analysis.
                let val = self.convert_expr(ExprUse::RValue, cond_id, is_static, DecayRef::Yes)?;
                Ok(val.map(|e| self.match_bool(target, ty_id, e)))
            }
        }
    }
/// Convert a C expression to a rust boolean expression
Convert a C expression to a rust boolean expression
Convert a C expression to a rust boolean expression
pub fn convert_condition(&self, target: bool, cond_id: CExprId, is_static: bool) -> Result<WithStmts<P<Expr>>, String> {
        let ty_id = self.ast_context[cond_id].kind.get_type().ok_or_else(|| format!("bad condition type"))?;
        let null_pointer_case =
            |negated: bool, ptr: CExprId| -> Result<WithStmts<P<Expr>>, String> {
                    let val = self.convert_expr(ExprUse::RValue, ptr, is_static, DecayRef::Yes)?;
                    let ptr_type = self.ast_context[ptr].kind.get_type().ok_or_else(|| format!("bad pointer type for condition"))?;
                    Ok(val.map(|e| {
                        if self.ast_context.is_function_pointer(ptr_type) {
                            if negated {
                                mk().method_call_expr(e, "is_some", vec![] as Vec<P<Expr>>)
                            } else {
                                mk().method_call_expr(e, "is_none", vec![] as Vec<P<Expr>>)
                            }
                        } else {
                            let is_null = mk().method_call_expr(e, "is_null", vec![] as Vec<P<Expr>>);
                            if negated {
                                mk().unary_expr(ast::UnOp::Not, is_null)
                            } else {
                                is_null
                            }
                        }
                    }))
                };
        match self.ast_context[cond_id].kind {
            CExprKind::Binary(_, c_ast::BinOp::EqualEqual, null_expr, ptr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(!target, ptr)
            }
            CExprKind::Binary(_, c_ast::BinOp::EqualEqual, ptr, null_expr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(!target, ptr)
            }
            CExprKind::Binary(_, c_ast::BinOp::NotEqual, null_expr, ptr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(target, ptr)
            }
            CExprKind::Binary(_, c_ast::BinOp::NotEqual, ptr, null_expr, _, _)
            if self.ast_context.is_null_expr(null_expr) => {
                null_pointer_case(target, ptr)
            }
            CExprKind::Unary(_, c_ast::UnOp::Not, subexpr_id) => {
                self.convert_condition(!target, subexpr_id, is_static)
            }
            _ => {
                // DecayRef could (and probably should) be Default instead of Yes here; however, as noted
                // in https://github.com/rust-lang/rust/issues/53772, you cant compare a reference (lhs) to
                // a ptr (rhs) (even though the reverse works!). We could also be smarter here and just
                // specify Yes for that particular case, given enough analysis.
                let val = self.convert_expr(ExprUse::RValue, cond_id, is_static, DecayRef::Yes)?;
                Ok(val.map(|e| self.match_bool(target, ty_id, e)))
            }
        }
    }
pub fn convert_condition ( & self , target : bool , cond_id : CExprId , is_static : bool ) -> Result < WithStmts < P < Expr > > , String > { let ty_id = self . ast_context [ cond_id ] . kind . get_type ( ) . ok_or_else ( | | format ! ( " " ) ) ? ; let null_pointer_case = | negated : bool , ptr : CExprId | -> Result < WithStmts < P < Expr > > , String > { let val = self . convert_expr ( ExprUse :: RValue , ptr , is_static , DecayRef :: Yes ) ? ; let ptr_type = self . ast_context [ ptr ] . kind . get_type ( ) . ok_or_else ( | | format ! ( " " ) ) ? ; Ok ( val . map ( | e | { if self . ast_context . is_function_pointer ( ptr_type ) { if negated { mk ( ) . method_call_expr ( e , " " , vec ! [ ] as Vec < P < Expr > > ) } else { mk ( ) . method_call_expr ( e , " " , vec ! [ ] as Vec < P < Expr > > ) } } else { let is_null = mk ( ) . method_call_expr ( e , " " , vec ! [ ] as Vec < P < Expr > > ) ; if negated { mk ( ) . unary_expr ( ast :: UnOp :: Not , is_null ) } else { is_null } } } ) ) } ; match self . ast_context [ cond_id ] . kind { CExprKind :: Binary ( _ , c_ast :: BinOp :: EqualEqual , null_expr , ptr , _ , _ ) if self . ast_context . is_null_expr ( null_expr ) => { null_pointer_case ( ! target , ptr ) } CExprKind :: Binary ( _ , c_ast :: BinOp :: EqualEqual , ptr , null_expr , _ , _ ) if self . ast_context . is_null_expr ( null_expr ) => { null_pointer_case ( ! target , ptr ) } CExprKind :: Binary ( _ , c_ast :: BinOp :: NotEqual , null_expr , ptr , _ , _ ) if self . ast_context . is_null_expr ( null_expr ) => { null_pointer_case ( target , ptr ) } CExprKind :: Binary ( _ , c_ast :: BinOp :: NotEqual , ptr , null_expr , _ , _ ) if self . ast_context . is_null_expr ( null_expr ) => { null_pointer_case ( target , ptr ) } CExprKind :: Unary ( _ , c_ast :: UnOp :: Not , subexpr_id ) => { self . convert_condition ( ! target , subexpr_id , is_static ) } _ => { // DecayRef could (and probably should) be Default instead of Yes here; however, as noted // in https://github.com/rust-lang/rust/issues/53772, you cant compare a reference (lhs) to // a ptr (rhs) (even though the reverse works!). We could also be smarter here and just // specify Yes for that particular case, given enough analysis. let val = self . convert_expr ( ExprUse :: RValue , cond_id , is_static , DecayRef :: Yes ) ? ; Ok ( val . map ( | e | self . match_bool ( target , ty_id , e ) ) ) } } }
Convert a C expression to a rust boolean expression
Convert a C expression to a rust boolean expression
&self
target
bool
cond_id
CExprId
is_static
bool
&self
target
bool
cond_id
CExprId
is_static
bool