leo_passes/name_validation/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 program;
18
19mod ast;
20
21mod visitor;
22use visitor::*;
23
24use crate::{CompilerState, Pass};
25
26use leo_ast::ProgramVisitor;
27use leo_errors::Result;
28
29/// A pass to validate names.
30///
31/// Enforces various naming rules such as preventing SnarkVM keywords or the use of "aleo" where relevant.
32pub struct NameValidation;
33
34impl Pass for NameValidation {
35 type Input = ();
36 type Output = ();
37
38 const NAME: &'static str = "NameValidation";
39
40 fn do_pass(_: Self::Input, state: &mut CompilerState) -> Result<Self::Output> {
41 let mut visitor = NameValidationVisitor { handler: &mut state.handler };
42 visitor.visit_program(state.ast.as_repr());
43 state.handler.last_err()?;
44
45 Ok(())
46 }
47}