visitor.rs
1 // Copyright (C) 2019-2025 ADnet Contributors 2 // This file is part of the ADL library. 3 4 // The ADL 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 ADL 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 ADL library. If not, see <https://www.gnu.org/licenses/>. 16 17 use crate::CompilerState; 18 19 use adl_ast::{Function, NodeID}; 20 use adl_span::Symbol; 21 22 pub 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 37 impl 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 }