Skip to content

Commit

Permalink
special_functions: Add version condition to imports as well
Browse files Browse the repository at this point in the history
Complements: 5ce31f2 ("codegen: Add version condition on special function traits")
  • Loading branch information
MarijnS95 committed Dec 4, 2020
1 parent 68bdcf8 commit cc20ba3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/analysis/special_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
imports::Imports,
},
library::{Type as LibType, TypeId},
version::Version,
};
use std::{collections::BTreeMap, str::FromStr};

Expand Down Expand Up @@ -52,6 +53,7 @@ impl Type {
pub struct Info {
pub glib_name: String,
pub returns_static_ref: bool,
pub version: Option<Version>,
}

pub type Infos = BTreeMap<Type, Info>;
Expand Down Expand Up @@ -144,6 +146,7 @@ pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType) -> Infos {
Info {
glib_name: func.glib_name.clone(),
returns_static_ref,
version: func.version,
},
);
}
Expand All @@ -152,12 +155,14 @@ pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType) -> Infos {
if has_copy && !has_free {
if let Some((glib_name, pos)) = destroy {
let ty_ = Type::from_str("destroy").unwrap();
update_func(&mut functions[pos], ty_, parent_type);
let func = &mut functions[pos];
update_func(func, ty_, parent_type);
specials.insert(
ty_,
Info {
glib_name,
returns_static_ref: false,
version: func.version,
},
);
}
Expand Down Expand Up @@ -191,16 +196,16 @@ pub fn analyze_imports(specials: &Infos, imports: &mut Imports) {
use self::Type::*;
for (type_, info) in specials {
match *type_ {
Compare => imports.add("std::cmp"),
Compare => imports.add_with_version("std::cmp", info.version),
Display => {
imports.add("std::fmt");
imports.add_with_version("std::fmt", info.version);
// TODO: This is for the function itself (not the trait)
// and should only be emitted on .generate(), not on ignored() or manual()
if info.returns_static_ref {
imports.add("std::ffi::CStr");
imports.add_with_version("std::ffi::CStr", info.version);
}
}
Hash => imports.add("std::hash"),
Hash => imports.add_with_version("std::hash", info.version),
_ => {}
}
}
Expand Down

0 comments on commit cc20ba3

Please sign in to comment.