leo_passes/static_analysis/
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 await_checker;
18use self::await_checker::AwaitChecker;
19
20mod future_checker;
21
22mod program;
23
24mod visitor;
25use visitor::*;
26
27use crate::Pass;
28
29use leo_ast::ProgramVisitor;
30use leo_errors::Result;
31use leo_span::Symbol;
32
33pub struct StaticAnalyzing;
34
35impl Pass for StaticAnalyzing {
36    type Input = ();
37    type Output = ();
38
39    const NAME: &str = "StaticAnalyzing";
40
41    fn do_pass(_input: Self::Input, state: &mut crate::CompilerState) -> Result<Self::Output> {
42        let ast = std::mem::take(&mut state.ast);
43        let mut visitor = StaticAnalyzingVisitor {
44            state,
45            await_checker: AwaitChecker::new(),
46            current_program: Symbol::intern(""),
47            variant: None,
48            non_async_external_call_seen: false,
49        };
50        visitor.visit_program(ast.as_repr());
51        visitor.state.handler.last_err()?;
52        visitor.state.ast = ast;
53        Ok(())
54    }
55}