-
Notifications
You must be signed in to change notification settings - Fork 744
Use __BindegenComplex for C Complex #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ use cexpr; | |
use clang::{self, Cursor}; | ||
use parse::ClangItemParser; | ||
use std::borrow::Cow; | ||
use std::cell::Cell; | ||
use std::collections::{HashMap, hash_map}; | ||
use std::collections::btree_map::{self, BTreeMap}; | ||
use std::fmt; | ||
|
@@ -99,6 +100,9 @@ pub struct BindgenContext<'ctx> { | |
|
||
/// The options given by the user via cli or other medium. | ||
options: BindgenOptions, | ||
|
||
/// Whether a bindgen complex was generated | ||
generated_bindegen_complex: Cell<bool>, | ||
} | ||
|
||
impl<'ctx> BindgenContext<'ctx> { | ||
|
@@ -134,6 +138,7 @@ impl<'ctx> BindgenContext<'ctx> { | |
index: index, | ||
translation_unit: translation_unit, | ||
options: options, | ||
generated_bindegen_complex: Cell::new(false), | ||
}; | ||
|
||
me.add_item(root_module, None, None); | ||
|
@@ -698,6 +703,17 @@ impl<'ctx> BindgenContext<'ctx> { | |
CXType_Double => TypeKind::Float(FloatKind::Double), | ||
CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), | ||
CXType_Float128 => TypeKind::Float(FloatKind::Float128), | ||
CXType_Complex => { | ||
let float_type = ty.elem_type() | ||
.expect("Not able to resolve complex type?"); | ||
let float_kind = match float_type.kind() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably: let float_kind = match float_type.kind() {
CXType_Float => FloatKind::Float,
CXType_Double => FloatKind::Double,
CXType_LongDouble => FloatKind::LongDouble,
_ => panic!("Non floating-type complex?"),
}; Or, you could also add a |
||
CXType_Float => FloatKind::Float, | ||
CXType_Double => FloatKind::Double, | ||
CXType_LongDouble => FloatKind::LongDouble, | ||
_ => panic!("Non floating-type complex?"), | ||
}; | ||
TypeKind::Complex(float_kind) | ||
} | ||
_ => return None, | ||
}; | ||
|
||
|
@@ -930,6 +946,16 @@ impl<'ctx> BindgenContext<'ctx> { | |
self.rust_ident_raw("std") | ||
} | ||
} | ||
|
||
/// Call if a binden complex is generated | ||
pub fn generated_bindegen_complex(&self) { | ||
self.generated_bindegen_complex.set(true) | ||
} | ||
|
||
/// Whether we need to generate the binden complex type | ||
pub fn need_bindegen_complex_type(&self) -> bool { | ||
self.generated_bindegen_complex.get() | ||
} | ||
} | ||
|
||
/// An iterator over whitelisted items. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(non_snake_case)] | ||
|
||
|
||
#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] | ||
#[repr(C)] | ||
pub struct __BindgenComplex<T> { | ||
pub re: T, | ||
pub im: T, | ||
} | ||
extern "C" { | ||
#[link_name = "globalValueFloat"] | ||
pub static mut globalValueFloat: __BindgenComplex<f32>; | ||
} | ||
extern "C" { | ||
#[link_name = "globalValueDouble"] | ||
pub static mut globalValueDouble: __BindgenComplex<f64>; | ||
} | ||
extern "C" { | ||
#[link_name = "globalValueLongDouble"] | ||
pub static mut globalValueLongDouble: __BindgenComplex<f64>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to call
saw_complex
just here, and remove the rest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nevermind, you don't have access to the
result
. Maybe worth moving that to the context inside aCell<bool>
, and checking that instead? Even better would be something likeCell<SeenFlags>
, whereSeenFlags
is abitflags!
, but for now movingsaw_union
andsaw_complex
toBindgenContext
is fine, the other can be a followup if you want.Otherwise you'll need to check for virtually every possible type, function arguments, etc...