| 1 |
use std::io::{Result, Write}; |
| 2 |
|
| 3 |
use super::general::version_condition; |
| 4 |
use crate::{ |
| 5 |
Env, |
| 6 |
analysis::{self, special_functions::FunctionType}, |
| 7 |
version::Version, |
| 8 |
}; |
| 9 |
|
| 10 |
pub(super) fn generate( |
| 11 |
w: &mut dyn Write, |
| 12 |
env: &Env, |
| 13 |
function: &analysis::functions::Info, |
| 14 |
specials: &analysis::special_functions::Infos, |
| 15 |
scope_version: Option<Version>, |
| 16 |
) -> Result<bool> { |
| 17 |
if let Some(special) = specials.functions().get(&function.glib_name) { |
| 18 |
match special.type_ { |
| 19 |
FunctionType::StaticStringify => { |
| 20 |
generate_static_to_str(w, env, function, scope_version) |
| 21 |
} |
| 22 |
} |
| 23 |
.map(|()| true) |
| 24 |
} else { |
| 25 |
Ok(false) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
pub(super) fn generate_static_to_str( |
| 30 |
w: &mut dyn Write, |
| 31 |
env: &Env, |
| 32 |
function: &analysis::functions::Info, |
| 33 |
scope_version: Option<Version>, |
| 34 |
) -> Result<()> { |
| 35 |
writeln!(w)?; |
| 36 |
let version = Version::if_stricter_than(function.version, scope_version); |
| 37 |
version_condition(w, env, None, version, false, 1)?; |
| 38 |
|
| 39 |
writeln!( |
| 40 |
w, |
| 41 |
"\ |
| 42 |
\t{visibility} fn {rust_fn_name}<'a>(self) -> &'a GStr {{ |
| 43 |
\t\tunsafe {{ |
| 44 |
\t\t\tGStr::from_ptr( |
| 45 |
\t\t\t\t{ns}::{glib_fn_name}(self.into_glib()) |
| 46 |
\t\t\t\t\t.as_ref() |
| 47 |
\t\t\t\t\t.expect(\"{glib_fn_name} returned NULL\"), |
| 48 |
\t\t\t) |
| 49 |
\t\t}} |
| 50 |
\t}}", |
| 51 |
visibility = function.visibility, |
| 52 |
rust_fn_name = function.codegen_name(), |
| 53 |
ns = env.main_sys_crate_name(), |
| 54 |
glib_fn_name = function.glib_name, |
| 55 |
)?; |
| 56 |
|
| 57 |
Ok(()) |
| 58 |
} |