leo_passes/processing_script/mod.rs
1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17mod ast;
18
19mod program;
20
21mod visitor;
22use visitor::*;
23
24use crate::{CompilerState, Pass};
25
26use leo_ast::{ProgramReconstructor as _, Variant};
27use leo_errors::Result;
28use leo_span::Symbol;
29
30/// A pass to validate (and remove) uses of `interpret`.
31pub struct ProcessingScript;
32
33impl Pass for ProcessingScript {
34 type Input = ();
35 type Output = ();
36
37 const NAME: &'static str = "ProcessingScript";
38
39 fn do_pass(_input: Self::Input, state: &mut CompilerState) -> Result<Self::Output> {
40 let mut ast = std::mem::take(&mut state.ast);
41
42 // We set the `current_variant` before traversing each function. We use `Inline` here as a placeholder.
43 let mut visitor =
44 ProcessingScriptVisitor { state, current_variant: Variant::Inline, program_name: Symbol::default() };
45 ast.ast = visitor.reconstruct_program(ast.ast);
46 visitor.state.ast = ast;
47
48 Ok(())
49 }
50}