leo_passes/processing_async/
visitor.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
17use crate::CompilerState;
18
19use leo_ast::{Function, NodeID};
20use leo_span::Symbol;
21
22pub struct ProcessingAsyncVisitor<'a> {
23    pub state: &'a mut CompilerState,
24    /// The maximum number of inputs allowed for a function. This is the same limit we will enforce
25    /// on the number of variables captured by an `async` block.
26    pub max_inputs: usize,
27    /// The name of the current program being processed
28    pub current_program: Symbol,
29    /// The name of the current function being processed
30    pub current_function: Symbol,
31    /// A map of reconstructed functions in the current program scope.
32    pub new_async_functions: Vec<(Symbol, Function)>,
33    /// Indicates whether this pass actually processed any async blocks.
34    pub modified: bool,
35}
36
37impl ProcessingAsyncVisitor<'_> {
38    pub fn in_scope<T>(&mut self, id: NodeID, func: impl FnOnce(&mut Self) -> T) -> T {
39        self.state.symbol_table.enter_scope(Some(id));
40        let result = func(self);
41        self.state.symbol_table.enter_parent();
42        result
43    }
44}