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
use crate::{InputValue, MainInput, ProgramInput, ProgramState, Record, Registers, State, StateLeaf};
use leo_input::{
files::{File, TableOrSection},
InputParserError,
};
#[derive(Clone, PartialEq, Eq)]
pub struct Input {
name: String,
program_input: ProgramInput,
program_state: ProgramState,
}
impl Default for Input {
fn default() -> Self {
Self {
name: "default".to_owned(),
program_input: ProgramInput::new(),
program_state: ProgramState::new(),
}
}
}
#[allow(clippy::len_without_is_empty)]
impl Input {
pub fn new() -> Self {
Self::default()
}
pub fn empty(&self) -> Self {
let input = self.program_input.empty();
let state = self.program_state.empty();
Self {
name: self.name.clone(),
program_input: input,
program_state: state,
}
}
pub fn len(&self) -> usize {
self.program_input.len() + self.program_state.len()
}
pub fn set_main_input(&mut self, input: MainInput) {
self.program_input.main = input;
}
pub fn parse_input(&mut self, file: File) -> Result<(), InputParserError> {
for entry in file.entries.into_iter() {
match entry {
TableOrSection::Section(section) => {
self.program_input.parse(section)?;
}
TableOrSection::Table(table) => return Err(InputParserError::table(table)),
}
}
Ok(())
}
pub fn parse_state(&mut self, file: File) -> Result<(), InputParserError> {
for entry in file.entries.into_iter() {
match entry {
TableOrSection::Section(section) => return Err(InputParserError::section(section.header)),
TableOrSection::Table(table) => {
self.program_state.parse(table)?;
}
}
}
Ok(())
}
#[allow(clippy::ptr_arg)]
pub fn get(&self, name: &String) -> Option<Option<InputValue>> {
self.program_input.get(name)
}
pub fn get_registers(&self) -> &Registers {
self.program_input.get_registers()
}
pub fn get_record(&self) -> &Record {
self.program_state.get_record()
}
pub fn get_state(&self) -> &State {
self.program_state.get_state()
}
pub fn get_state_leaf(&self) -> &StateLeaf {
self.program_state.get_state_leaf()
}
}