Skip to content

Commit

Permalink
feat(ir) Simplify ManuallyDrop and MaybeUninit only for C.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan authored and emilio committed Sep 29, 2020
1 parent af6d2e3 commit 0076a17
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -411,7 +411,7 @@ impl Type {
}
}

fn simplified_type(&self) -> Option<Self> {
fn simplified_type(&self, config: &Config) -> Option<Self> {
let path = match *self {
Type::Path(ref p) => p,
_ => return None,
Expand All @@ -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.
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path, AnnotationSet>) {
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/bindgen/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 0076a17

Please sign in to comment.