Skip to main content

wesl/pass/
mangle.rs

1use wgsl_parse::{
2    SyntaxNode,
3    syntax::{ModulePath, TranslationUnit},
4};
5
6use crate::mangler::Mangler;
7
8/// Mangle all declarations in all modules. Should be called after `retarget_idents`.
9///
10/// Panics if a module is already borrowed.
11pub fn mangle(module: &mut TranslationUnit, path: &ModulePath, mangler: &impl Mangler) {
12    module
13        .global_declarations
14        .iter_mut()
15        .filter_map(|decl| decl.ident())
16        .for_each(|mut ident| {
17            let new_name = mangler.mangle(path, &ident.name());
18            ident.rename(new_name.clone());
19        })
20}