leo_passes/path_resolution/
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_span::Symbol;
20
21pub struct PathResolutionVisitor<'a> {
22    pub state: &'a mut CompilerState,
23    /// The current module.
24    pub module: Vec<Symbol>,
25}
26
27impl PathResolutionVisitor<'_> {
28    /// Enter module scope with path `module`, execute `func`, and then return to the parent module.
29    pub fn in_module_scope<T>(&mut self, module: &[Symbol], func: impl FnOnce(&mut Self) -> T) -> T {
30        let parent_module = self.module.clone();
31        self.module = module.to_vec();
32        let result = func(self);
33        self.module = parent_module;
34        result
35    }
36}