From 0076a17ac92fcfe054b24b080c2cbfbed50b99ef Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 28 Sep 2020 21:52:33 +0200 Subject: [PATCH] feat(ir) Simplify `ManuallyDrop` and `MaybeUninit` only for C. --- src/bindgen/ir/function.rs | 6 +++--- src/bindgen/ir/global.rs | 4 ++-- src/bindgen/ir/structure.rs | 4 ++-- src/bindgen/ir/ty.rs | 13 +++++++------ src/bindgen/ir/typedef.rs | 4 ++-- src/bindgen/ir/union.rs | 4 ++-- src/bindgen/library.rs | 12 +++++++----- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index b9f261091..8cc746edb 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -120,10 +120,10 @@ impl Function { &self.path } - pub fn simplify_standard_types(&mut self) { - self.ret.simplify_standard_types(); + pub fn simplify_standard_types(&mut self, config: &Config) { + self.ret.simplify_standard_types(config); for arg in &mut self.args { - arg.ty.simplify_standard_types(); + arg.ty.simplify_standard_types(config); } } diff --git a/src/bindgen/ir/global.rs b/src/bindgen/ir/global.rs index a6ba150d6..a9d989df8 100644 --- a/src/bindgen/ir/global.rs +++ b/src/bindgen/ir/global.rs @@ -61,8 +61,8 @@ impl Static { } } - pub fn simplify_standard_types(&mut self) { - self.ty.simplify_standard_types(); + pub fn simplify_standard_types(&mut self, config: &Config) { + self.ty.simplify_standard_types(config); } } diff --git a/src/bindgen/ir/structure.rs b/src/bindgen/ir/structure.rs index e80beecd9..84e808c30 100644 --- a/src/bindgen/ir/structure.rs +++ b/src/bindgen/ir/structure.rs @@ -143,9 +143,9 @@ impl Struct { } } - pub fn simplify_standard_types(&mut self) { + pub fn simplify_standard_types(&mut self, config: &Config) { for &mut (_, ref mut ty, _) in &mut self.fields { - ty.simplify_standard_types(); + ty.simplify_standard_types(config); } } diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index db456b161..63e7d71b8 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -6,7 +6,7 @@ use std::fmt; use std::io::Write; use crate::bindgen::cdecl; -use crate::bindgen::config::Config; +use crate::bindgen::config::{Config, Language}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{Documentation, GenericParams, GenericPath, Path}; @@ -411,7 +411,7 @@ impl Type { } } - fn simplified_type(&self) -> Option { + fn simplified_type(&self, config: &Config) -> Option { let path = match *self { Type::Path(ref p) => p, _ => return None, @@ -422,7 +422,7 @@ impl Type { } let mut generic = path.generics()[0].clone(); - generic.simplify_standard_types(); + generic.simplify_standard_types(config); match path.name() { // FIXME(#223): This is not quite correct. @@ -433,13 +433,14 @@ impl Type { is_nullable: false, is_ref: false, }), - "Cell" | "ManuallyDrop" | "MaybeUninit" => Some(generic), + "Cell" => Some(generic), + "ManuallyDrop" | "MaybeUninit" if config.language == Language::C => Some(generic), _ => None, } } - pub fn simplify_standard_types(&mut self) { - if let Some(ty) = self.simplified_type() { + pub fn simplify_standard_types(&mut self, config: &Config) { + if let Some(ty) = self.simplified_type(config) { *self = ty; } } diff --git a/src/bindgen/ir/typedef.rs b/src/bindgen/ir/typedef.rs index e6ae07296..18da50bbf 100644 --- a/src/bindgen/ir/typedef.rs +++ b/src/bindgen/ir/typedef.rs @@ -66,8 +66,8 @@ impl Typedef { } } - pub fn simplify_standard_types(&mut self) { - self.aliased.simplify_standard_types(); + pub fn simplify_standard_types(&mut self, config: &Config) { + self.aliased.simplify_standard_types(config); } pub fn transfer_annotations(&mut self, out: &mut HashMap) { diff --git a/src/bindgen/ir/union.rs b/src/bindgen/ir/union.rs index 6d9e2347c..089499a0a 100644 --- a/src/bindgen/ir/union.rs +++ b/src/bindgen/ir/union.rs @@ -96,9 +96,9 @@ impl Union { } } - pub fn simplify_standard_types(&mut self) { + pub fn simplify_standard_types(&mut self, config: &Config) { for &mut (_, ref mut ty, _) in &mut self.fields { - ty.simplify_standard_types(); + ty.simplify_standard_types(config); } } diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index 26c6fa3a3..fdd6e1702 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -344,20 +344,22 @@ impl Library { } fn simplify_standard_types(&mut self) { + let config = &self.config; + self.structs.for_all_items_mut(|x| { - x.simplify_standard_types(); + x.simplify_standard_types(config); }); self.unions.for_all_items_mut(|x| { - x.simplify_standard_types(); + x.simplify_standard_types(config); }); self.globals.for_all_items_mut(|x| { - x.simplify_standard_types(); + x.simplify_standard_types(config); }); self.typedefs.for_all_items_mut(|x| { - x.simplify_standard_types(); + x.simplify_standard_types(config); }); for x in &mut self.functions { - x.simplify_standard_types(); + x.simplify_standard_types(config); } }