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 expression;
18
19mod program;
20
21mod statement;
22
23mod visitor;
24use visitor::*;
25
26use crate::{CompilerState, Pass};
27
28use leo_ast::{ProgramReconstructor as _, Variant};
29use leo_errors::Result;
30use leo_span::Symbol;
31
32/// A pass to validate (and remove) uses of `interpret`.
33pub struct ProcessingScript;
34
35impl Pass for ProcessingScript {
36 type Input = ();
37 type Output = ();
38
39 const NAME: &'static str = "ProcessingScript";
40
41 fn do_pass(_input: Self::Input, state: &mut CompilerState) -> Result<Self::Output> {
42 let mut ast = std::mem::take(&mut state.ast);
43
44 // We set the `current_variant` before traversing each function. We use `Inline` here as a placeholder.
45 let mut visitor =
46 ProcessingScriptVisitor { state, current_variant: Variant::Inline, program_name: Symbol::default() };
47 ast.ast = visitor.reconstruct_program(ast.ast);
48 visitor.state.ast = ast;
49
50 Ok(())
51 }
52}