| 1 |
use std::cell::RefCell; |
| 2 |
|
| 3 |
use crate::{ |
| 4 |
analysis::{self, namespaces::NsId}, |
| 5 |
config::{Config, gobjects::GStatus}, |
| 6 |
library::*, |
| 7 |
nameutil::use_glib_type, |
| 8 |
version::Version, |
| 9 |
}; |
| 10 |
|
| 11 |
#[derive(Debug)] |
| 12 |
pub struct Env { |
| 13 |
pub library: Library, |
| 14 |
pub config: Config, |
| 15 |
pub namespaces: analysis::namespaces::Info, |
| 16 |
pub symbols: RefCell<analysis::symbols::Info>, |
| 17 |
pub class_hierarchy: analysis::class_hierarchy::Info, |
| 18 |
pub analysis: analysis::Analysis, |
| 19 |
} |
| 20 |
|
| 21 |
impl Env { |
| 22 |
#[inline] |
| 23 |
pub fn type_(&self, tid: TypeId) -> &Type { |
| 24 |
self.library.type_(tid) |
| 25 |
} |
| 26 |
pub fn type_status(&self, name: &str) -> GStatus { |
| 27 |
self.config |
| 28 |
.objects |
| 29 |
.get(name) |
| 30 |
.map(|o| o.status) |
| 31 |
.unwrap_or_default() |
| 32 |
} |
| 33 |
pub fn type_status_sys(&self, name: &str) -> GStatus { |
| 34 |
self.config |
| 35 |
.objects |
| 36 |
.get(name) |
| 37 |
.map_or(GStatus::Generate, |o| o.status) |
| 38 |
} |
| 39 |
|
| 40 |
pub fn is_totally_deprecated( |
| 41 |
&self, |
| 42 |
ns_id: Option<NsId>, |
| 43 |
deprecated_version: Option<Version>, |
| 44 |
) -> bool { |
| 45 |
let to_compare_with = self.config.min_required_version(self, ns_id); |
| 46 |
match (deprecated_version, to_compare_with) { |
| 47 |
(Some(v), Some(to_compare_v)) if v <= to_compare_v => { |
| 48 |
self.config.deprecate_by_min_version |
| 49 |
} |
| 50 |
(Some(v), _) if v <= self.config.min_cfg_version => { |
| 51 |
self.config.deprecate_by_min_version |
| 52 |
} |
| 53 |
_ => false, |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
pub fn is_too_low_version(&self, ns_id: Option<NsId>, version: Option<Version>) -> bool { |
| 58 |
let to_compare_with = self.config.min_required_version(self, ns_id); |
| 59 |
if let (Some(v), Some(to_compare_v)) = (version, to_compare_with) { |
| 60 |
return v <= to_compare_v; |
| 61 |
} |
| 62 |
false |
| 63 |
} |
| 64 |
|
| 65 |
pub fn main_sys_crate_name(&self) -> &str { |
| 66 |
&self.namespaces[MAIN_NAMESPACE].sys_crate_name |
| 67 |
} |
| 68 |
|
| 69 |
/// Helper to get the ffi crate import |
| 70 |
pub fn sys_crate_import(&self, type_id: TypeId) -> String { |
| 71 |
let crate_name = &self.namespaces[type_id.ns_id].sys_crate_name; |
| 72 |
if crate_name == "gobject_ffi" { |
| 73 |
use_glib_type(self, crate_name) |
| 74 |
} else { |
| 75 |
crate_name.clone() |
| 76 |
} |
| 77 |
} |
| 78 |
} |