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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* SPDX-FileCopyrightText: © 2023-2024 Decompollaborate */
/* SPDX-License-Identifier: MIT */

use crate::{file, symbol};

#[cfg(feature = "python_bindings")]
use pyo3::prelude::*;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "python_bindings", pyclass(module = "mapfile_parser"))]
pub struct SymbolComparisonInfo {
    pub symbol: symbol::Symbol,

    pub build_address: u64,

    pub build_file: Option<file::File>,

    pub expected_address: u64,

    pub expected_file: Option<file::File>,

    pub diff: Option<i64>,
}

impl SymbolComparisonInfo {
    pub fn new(
        symbol: symbol::Symbol,
        build_address: u64,
        build_file: Option<file::File>,
        expected_address: u64,
        expected_file: Option<file::File>,
        diff: Option<i64>,
    ) -> Self {
        Self {
            symbol,
            build_address,
            build_file,
            expected_address,
            expected_file,
            diff,
        }
    }
}

#[cfg(feature = "python_bindings")]
#[allow(non_snake_case)]
pub(crate) mod python_bindings {
    use pyo3::prelude::*;

    use crate::{file, symbol};

    #[pymethods]
    impl super::SymbolComparisonInfo {
        #[new]
        #[pyo3(signature = (symbol, build_address, build_file, expected_address, expected_file, diff))]
        pub fn py_new(
            symbol: symbol::Symbol,
            build_address: u64,
            build_file: Option<file::File>,
            expected_address: u64,
            expected_file: Option<file::File>,
            diff: Option<i64>,
        ) -> Self {
            Self::new(
                symbol,
                build_address,
                build_file,
                expected_address,
                expected_file,
                diff,
            )
        }

        /* Getters and setters */

        #[getter]
        fn get_symbol(&self) -> PyResult<symbol::Symbol> {
            Ok(self.symbol.clone())
        }
        #[setter]
        fn set_symbol(&mut self, value: symbol::Symbol) -> PyResult<()> {
            self.symbol = value;
            Ok(())
        }

        #[getter]
        fn get_buildAddress(&self) -> PyResult<u64> {
            Ok(self.build_address)
        }
        #[setter]
        fn set_buildAddress(&mut self, value: u64) -> PyResult<()> {
            self.build_address = value;
            Ok(())
        }

        #[getter]
        fn get_buildFile(&self) -> PyResult<Option<file::File>> {
            Ok(self.build_file.clone())
        }
        #[setter]
        fn set_buildFile(&mut self, value: Option<file::File>) -> PyResult<()> {
            self.build_file = value;
            Ok(())
        }

        #[getter]
        fn get_expectedAddress(&self) -> PyResult<u64> {
            Ok(self.expected_address)
        }
        #[setter]
        fn set_expectedAddress(&mut self, value: u64) -> PyResult<()> {
            self.expected_address = value;
            Ok(())
        }

        #[getter]
        fn get_expectedFile(&self) -> PyResult<Option<file::File>> {
            Ok(self.expected_file.clone())
        }

        #[setter]
        fn set_expectedFile(&mut self, value: Option<file::File>) -> PyResult<()> {
            self.expected_file = value;
            Ok(())
        }

        #[getter]
        fn get_diff(&self) -> PyResult<Option<i64>> {
            Ok(self.diff)
        }

        #[setter]
        fn set_diff(&mut self, value: Option<i64>) -> PyResult<()> {
            self.diff = value;
            Ok(())
        }
    }
}