fn gen_ptr(ctx: &mut ProgContext, ty: TypeRef, dir: Dir) -> Value {
    let (elem_ty, elem_dir) = ty.ptr_info().unwrap();

    // Handle recusive type or circle reference here.
    if ty.optional
        && matches!(
            elem_ty.kind,
            TypeKind::Struct { .. } | TypeKind::Union { .. } | TypeKind::Array { .. }
        )
    {
        let depth = ctx.inc_rec_depth(elem_ty);
        if depth >= 3 {
            ctx.dec_rec_depth(elem_ty);
            return Value::new(dir, ty, ValueKind::new_ptr_null());
        }
    }

    let elem_val = gen_inner(ctx, elem_ty, elem_dir);
    let addr = ctx.mem_alloc.alloc(elem_val.size(), elem_ty.align);
    // TODO use a recusive depth guard here.
    if ty.optional
        && matches!(
            elem_ty.kind,
            TypeKind::Struct { .. } | TypeKind::Union { .. } | TypeKind::Array { .. }
        )
    {
        ctx.dec_rec_depth(elem_ty);
    }
    Value::new(dir, ty, ValueKind::new_ptr(addr, elem_val))
}
/// Generate value for ptr type.
Generate value for ptr type.
Generate value for ptr type .
fn gen_ptr(ctx: &mut ProgContext, ty: TypeRef, dir: Dir) -> Value {
    let (elem_ty, elem_dir) = ty.ptr_info().unwrap();
    // Handle recusive type or circle reference here.
    if ty.optional
        && matches!(
            elem_ty.kind,
            TypeKind::Struct { .. } | TypeKind::Union { .. } | TypeKind::Array { .. }
        )
    {
        let depth = ctx.inc_rec_depth(elem_ty);
        if depth >= 3 {
            ctx.dec_rec_depth(elem_ty);
            return Value::new(dir, ty, ValueKind::new_ptr_null());
        }
    }
    let elem_val = gen_inner(ctx, elem_ty, elem_dir);
    let addr = ctx.mem_alloc.alloc(elem_val.size(), elem_ty.align);
    // TODO use a recusive depth guard here.
    if ty.optional
        && matches!(
            elem_ty.kind,
            TypeKind::Struct { .. } | TypeKind::Union { .. } | TypeKind::Array { .. }
        )
    {
        ctx.dec_rec_depth(elem_ty);
    }
    Value::new(dir, ty, ValueKind::new_ptr(addr, elem_val))
}
fn gen_ptr ( ctx : & mut ProgContext , ty : TypeRef , dir : Dir ) -> Value { let ( elem_ty , elem_dir ) = ty . ptr_info ( ) . unwrap ( ) ; // Handle recusive type or circle reference here. if ty . optional && matches ! ( elem_ty kind TypeKind Struct { } TypeKind Union { } TypeKind Array { } ) { let depth = ctx . inc_rec_depth ( elem_ty ) ; if depth >= 3 { ctx . dec_rec_depth ( elem_ty ) ; return Value :: new ( dir , ty , ValueKind :: new_ptr_null ( ) ) ; } } let elem_val = gen_inner ( ctx , elem_ty , elem_dir ) ; let addr = ctx . mem_alloc . alloc ( elem_val . size ( ) , elem_ty . align ) ; // TODO use a recusive depth guard here. if ty . optional && matches ! ( elem_ty kind TypeKind Struct { } TypeKind Union { } TypeKind Array { } ) { ctx . dec_rec_depth ( elem_ty ) ; } Value :: new ( dir , ty , ValueKind :: new_ptr ( addr , elem_val ) ) }
Generate value for ptr type.
Generate value for ptr type .
ctx
&mut ProgContext
ty
TypeRef
dir
Dir
ctx
&mut ProgContext
ty
TypeRef
dir
Dir