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
//
// Wildland Project
//
// Copyright © 2022 Golem Foundation,
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as published by
// the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use std::hash::Hash;

use proc_macro2::{Ident, TokenStream};
use syn::Type;

#[derive(Hash, PartialEq, Eq, Clone, Debug)]
pub enum Exceptions {
    Primitive(Vec<Ident>),
    NonPrimitive(Vec<Ident>),
}

#[derive(Hash, PartialEq, Eq, Clone, Debug)]
pub enum RustWrapperType {
    Result(Box<WrapperType>, Box<WrapperType>),
    Option(Box<WrapperType>),
    Vector(Box<WrapperType>),
    Shared,
    Custom,
    String,
    Primitive,
    Trait,
    FieldlessEnum,
    DataEnum,
    Exceptions(Exceptions),
    ExceptionTrait,
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct ReferenceParameters {
    pub is_static: bool,
    pub is_mut: bool,
}

impl ReferenceParameters {
    pub fn shared() -> ReferenceParameters {
        ReferenceParameters {
            is_static: false,
            is_mut: false,
        }
    }
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct WrapperType {
    pub original_type_name: Type,
    pub wrapper_name: String,
    pub rust_type: RustWrapperType,
    pub reference_parameters: Option<ReferenceParameters>,
}

impl WrapperType {
    pub fn boxed(self) -> Box<WrapperType> {
        Box::new(self)
    }
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Arg {
    pub arg_name: String,
    pub typ: WrapperType,
}

#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct Function {
    pub arguments: Vec<Arg>,
    pub return_type: Option<WrapperType>,
    pub name: String,
}

#[derive(Clone)]
pub struct ExternFunction {
    pub arguments: Vec<WrapperType>,
    pub return_type: Option<WrapperType>,
    pub name: String,
    pub tokens: TokenStream,
}