1
#[cxx::bridge(namespace = "atermpp")]
2
#[allow(clippy::missing_safety_doc)]
3
pub mod ffi {
4

            
5
    unsafe extern "C++" {
6
        include!("mcrl2-sys/cpp/atermpp/atermpp.h");
7

            
8
        type aterm;
9
        type function_symbol;
10
        type tls_callback_container;
11
        type term_mark_stack;
12

            
13
        /// The underlying detail::_aterm
14
        #[namespace = "atermpp::detail"]
15
        type _aterm;
16
        #[namespace = "atermpp::detail"]
17
        type _function_symbol;
18

            
19
        /// Initialises the library.
20
600
        fn initialise();
21

            
22
        /// Enable automated garbage collection.
23
        ///
24
        /// # Warning
25
        /// This will deadlock when any Rust terms are created due to the
26
        /// interaction with the busy flags. Instead, call collect_garbage
27
        /// periodically to trigger garbage collection when needed.
28
616
        fn enable_automatic_garbage_collection(enabled: bool);
29

            
30
        /// Returns the number of terms in the pool.
31
3192
        fn aterm_pool_size() -> usize;
32

            
33
        /// Returns the capacity of the pool, for terms of all arities so this is slightly misleading.
34
3192
        fn aterm_pool_capacity() -> usize;
35

            
36
        /// Trigger garbage collection.
37
1616
        fn collect_garbage();
38

            
39
        /// Triggers a garbage collection when internal heuristics have determined it to be necessasry.
40
3852064
        fn test_garbage_collection();
41

            
42
        /// Provides shared access to the aterm library.
43
1296984688
        fn lock_shared();
44

            
45
        /// Returns true iff the shared section was actually left.
46
1296984688
        fn unlock_shared() -> bool;
47

            
48
        /// Provides exclusive access to the aterm library.
49
        fn lock_exclusive();
50
        fn unlock_exclusive();
51

            
52
        /// Register a function to be called during marking of the garbage collection
53
624
        fn register_mark_callback(
54
624
            callback_mark: fn(Pin<&mut term_mark_stack>) -> (),
55
624
            callback_size: fn() -> usize,
56
6368
        ) -> UniquePtr<tls_callback_container>;
57

            
58
        /// Prints various metrics that are being tracked for terms.
59
8
        fn print_metrics();
60

            
61
        /// Creates a term from the given function and arguments, must be
62
        /// protected before the busy flags are set to false.
63
        ///
64
        /// # Safety
65
        /// The function symbol and arguments will not be modified unless
66
        /// garbage collection marks the terms, which is done atomically.
67
67175232
        unsafe fn create_aterm(function: *const _function_symbol, arguments: &[*const _aterm]) -> *const _aterm;
68

            
69
        /// Parses the given string and returns an aterm
70
        fn aterm_from_string(text: String) -> Result<UniquePtr<aterm>>;
71

            
72
        /// Returns the pointer underlying the given term.
73
118288
        unsafe fn aterm_address(term: &aterm) -> *const _aterm;
74

            
75
        /// Marks the aterm to prevent garbage collection.
76
336528
        unsafe fn aterm_mark_address(term: *const _aterm, todo: Pin<&mut term_mark_stack>);
77

            
78
        /// Returns true iff the term is an aterm_list.
79
227568
        unsafe fn aterm_is_list(term: *const _aterm) -> bool;
80

            
81
        /// Returns true iff the term is the empty aterm_list.
82
227576
        unsafe fn aterm_is_empty_list(term: *const _aterm) -> bool;
83

            
84
        /// Returns true iff the term is an aterm_int.
85
177472
        unsafe fn aterm_is_int(term: *const _aterm) -> bool;
86

            
87
        /// Converts an aterm to a string.
88
        unsafe fn print_aterm(term: *const _aterm) -> String;
89

            
90
        /// Returns the function symbol of an aterm.
91
18674891368
        unsafe fn get_aterm_function_symbol(term: *const _aterm) -> *const _function_symbol;
92

            
93
        /// Returns the function symbol name
94
400448
        unsafe fn get_function_symbol_name<'a>(symbol: *const _function_symbol) -> &'a str;
95

            
96
        /// Returns the function symbol name
97
19653647256
        unsafe fn get_function_symbol_arity(symbol: *const _function_symbol) -> usize;
98

            
99
        /// Returns the ith argument of this term.
100
9884725880
        unsafe fn get_term_argument(term: *const _aterm, index: usize) -> *const _aterm;
101

            
102
        /// Creates a function symbol with the given name and arity, increases the reference counter by one.
103
102488
        fn create_function_symbol(name: String, arity: usize) -> *const _function_symbol;
104

            
105
        /// Protects the given function symbol by incrementing the reference counter.
106
891408
        unsafe fn protect_function_symbol(symbol: *const _function_symbol);
107

            
108
        /// Decreases the reference counter of the function symbol by one.
109
993896
        unsafe fn drop_function_symbol(symbol: *const _function_symbol);
110

            
111
        /// Obtain the address of the given function symbol.
112
        unsafe fn function_symbol_address(symbol: &function_symbol) -> *const _function_symbol;
113

            
114
        /// This function is to generate necessary data types
115
        fn generate_types() -> UniquePtr<CxxVector<aterm>>;
116
    }
117
}