libgir/codegen/
functions.rs
1use std::path::Path;
2
3use log::info;
4
5use crate::{
6 codegen::{function, general},
7 env::Env,
8 file_saver,
9};
10
11pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
12 info!("Generate global functions");
13
14 let Some(ref functions) = env.analysis.global_functions else {
15 return;
16 };
17 if functions.functions.is_empty() {
19 return;
20 }
21
22 let path = root_path.join("functions.rs");
23 file_saver::save_to_file(path, env.config.make_backup, |w| {
24 general::start_comments(w, &env.config)?;
25 general::uses(w, env, &functions.imports, None)?;
26
27 writeln!(w)?;
28
29 mod_rs.push("\npub(crate) mod functions;".into());
30
31 for func_analysis in &functions.functions {
32 function::generate(w, env, None, func_analysis, None, None, false, false, 0)?;
33 }
34
35 Ok(())
36 });
37}