libgir/analysis/
constants.rs
1use std::borrow::Borrow;
2
3use crate::{config, env::Env, library, nameutil, traits::*, version::Version};
4
5#[derive(Debug)]
6pub struct Info {
7 pub name: String,
8 pub glib_name: String,
9 pub typ: library::TypeId,
10 pub version: Option<Version>,
11 pub deprecated_version: Option<Version>,
12 pub cfg_condition: Option<String>,
13}
14
15pub fn analyze<F: Borrow<library::Constant>>(
16 env: &Env,
17 constants: &[F],
18 obj: &config::gobjects::GObject,
19) -> Vec<Info> {
20 let mut consts = Vec::new();
21
22 for constant in constants {
23 let constant = constant.borrow();
24 let configured_constants = obj.constants.matched(&constant.name);
25
26 if !configured_constants
27 .iter()
28 .all(|c| c.status.need_generate())
29 {
30 continue;
31 }
32
33 if env.is_totally_deprecated(None, constant.deprecated_version) {
34 continue;
35 }
36
37 match env.type_(constant.typ) {
38 library::Type::Basic(library::Basic::Utf8) => (),
39 _ => continue,
40 }
41
42 let version = configured_constants
43 .iter()
44 .filter_map(|c| c.version)
45 .min()
46 .or(constant.version);
47 let version = env.config.filter_version(version);
48 let deprecated_version = constant.deprecated_version;
49 let cfg_condition = configured_constants
50 .iter()
51 .find_map(|c| c.cfg_condition.clone());
52
53 let name = nameutil::mangle_keywords(&*constant.name).into_owned();
54
55 consts.push(Info {
56 name,
57 glib_name: constant.c_identifier.clone(),
58 typ: constant.typ,
59 version,
60 deprecated_version,
61 cfg_condition,
62 });
63 }
64
65 consts
66}