| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
// This is an FFI interface to gccrs (c++). |
| 20 |
// It is a counterpart to `rust-polonius-ffi.h`. |
| 21 |
|
| 22 |
// Generated by rust-bindgen, remove unsafe phantoms and add Into impls. |
| 23 |
// ```shell |
| 24 |
// bindgen \ |
| 25 |
// --generate types \ |
| 26 |
// --allowlist-file rust-polonius-facts-ffi.h |
| 27 |
// --no-layout-tests |
| 28 |
// rust-polonius-ffi.h |
| 29 |
// -- -x c++ |
| 30 |
// ``` |
| 31 |
include!("gccrs_ffi_generated.rs"); |
| 32 |
|
| 33 |
use std::marker::{PhantomData, PhantomPinned}; |
| 34 |
|
| 35 |
use crate::GccrsAtom; |
| 36 |
|
| 37 |
// We define an opaque C type per the nomicon's recommendation: |
| 38 |
// https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs |
| 39 |
#[repr(C)] |
| 40 |
pub struct FFIVector { |
| 41 |
_empty: [u8; 0], |
| 42 |
marker: PhantomData<(*mut u8, PhantomPinned)>, |
| 43 |
} |
| 44 |
|
| 45 |
impl<T1, T2> Into<(GccrsAtom, GccrsAtom)> for Pair<T1, T2> |
| 46 |
where |
| 47 |
GccrsAtom: From<T1> + From<T2>, |
| 48 |
{ |
| 49 |
fn into(self) -> (GccrsAtom, GccrsAtom) { |
| 50 |
(self.first.into(), self.second.into()) |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
impl<T1, T2, T3> Into<(GccrsAtom, GccrsAtom, GccrsAtom)> for Triple<T1, T2, T3> |
| 55 |
where |
| 56 |
GccrsAtom: From<T1> + From<T2> + From<T3>, |
| 57 |
{ |
| 58 |
fn into(self) -> (GccrsAtom, GccrsAtom, GccrsAtom) { |
| 59 |
(self.first.into(), self.second.into(), self.third.into()) |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
impl<OUT, IN> Into<Vec<OUT>> for Slice<IN> |
| 64 |
where |
| 65 |
IN: Into<OUT> + Copy, |
| 66 |
{ |
| 67 |
fn into(self) -> Vec<OUT> { |
| 68 |
let slice = unsafe { std::slice::from_raw_parts(self.data, self.len as usize) }; |
| 69 |
slice.iter().map(|&e| e.into()).collect() |
| 70 |
} |
| 71 |
} |