mcrl2_sys/atermpp.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
#[cxx::bridge(namespace = "atermpp")]
#[allow(clippy::missing_safety_doc)]
pub mod ffi {
unsafe extern "C++" {
include!("mcrl2-sys/cpp/atermpp/atermpp.h");
type aterm;
type function_symbol;
type tls_callback_container;
type term_mark_stack;
/// The underlying detail::_aterm
#[namespace = "atermpp::detail"]
type _aterm;
#[namespace = "atermpp::detail"]
type _function_symbol;
/// Initialises the library.
fn initialise();
/// Enable automated garbage collection.
///
/// # Warning
/// This will deadlock when any Rust terms are created due to the
/// interaction with the busy flags. Instead, call collect_garbage
/// periodically to trigger garbage collection when needed.
fn enable_automatic_garbage_collection(enabled: bool);
/// Returns the number of terms in the pool.
fn aterm_pool_size() -> usize;
/// Returns the capacity of the pool, for terms of all arities so this is slightly misleading.
fn aterm_pool_capacity() -> usize;
/// Trigger garbage collection.
fn collect_garbage();
/// Triggers a garbage collection when internal heuristics have determined it to be necessasry.
fn test_garbage_collection();
/// Provides shared access to the aterm library.
fn lock_shared();
/// Returns true iff the shared section was actually left.
fn unlock_shared() -> bool;
/// Provides exclusive access to the aterm library.
fn lock_exclusive();
fn unlock_exclusive();
/// Register a function to be called during marking of the garbage collection
fn register_mark_callback(
callback_mark: fn(Pin<&mut term_mark_stack>) -> (),
callback_size: fn() -> usize,
) -> UniquePtr<tls_callback_container>;
/// Prints various metrics that are being tracked for terms.
fn print_metrics();
/// Creates a term from the given function and arguments, must be
/// protected before the busy flags are set to false.
///
/// # Safety
/// The function symbol and arguments will not be modified unless
/// garbage collection marks the terms, which is done atomically.
unsafe fn create_aterm(function: *const _function_symbol, arguments: &[*const _aterm]) -> *const _aterm;
/// Parses the given string and returns an aterm
fn aterm_from_string(text: String) -> Result<UniquePtr<aterm>>;
/// Returns the pointer underlying the given term.
unsafe fn aterm_address(term: &aterm) -> *const _aterm;
/// Marks the aterm to prevent garbage collection.
unsafe fn aterm_mark_address(term: *const _aterm, todo: Pin<&mut term_mark_stack>);
/// Returns true iff the term is an aterm_list.
unsafe fn aterm_is_list(term: *const _aterm) -> bool;
/// Returns true iff the term is the empty aterm_list.
unsafe fn aterm_is_empty_list(term: *const _aterm) -> bool;
/// Returns true iff the term is an aterm_int.
unsafe fn aterm_is_int(term: *const _aterm) -> bool;
/// Converts an aterm to a string.
unsafe fn print_aterm(term: *const _aterm) -> String;
/// Returns the function symbol of an aterm.
unsafe fn get_aterm_function_symbol(term: *const _aterm) -> *const _function_symbol;
/// Returns the function symbol name
unsafe fn get_function_symbol_name<'a>(symbol: *const _function_symbol) -> &'a str;
/// Returns the function symbol name
unsafe fn get_function_symbol_arity(symbol: *const _function_symbol) -> usize;
/// Returns the ith argument of this term.
unsafe fn get_term_argument(term: *const _aterm, index: usize) -> *const _aterm;
/// Creates a function symbol with the given name and arity, increases the reference counter by one.
fn create_function_symbol(name: String, arity: usize) -> *const _function_symbol;
/// Protects the given function symbol by incrementing the reference counter.
unsafe fn protect_function_symbol(symbol: *const _function_symbol);
/// Decreases the reference counter of the function symbol by one.
unsafe fn drop_function_symbol(symbol: *const _function_symbol);
/// Obtain the address of the given function symbol.
unsafe fn function_symbol_address(symbol: &function_symbol) -> *const _function_symbol;
/// This function is to generate necessary data types
fn generate_types() -> UniquePtr<CxxVector<aterm>>;
}
}