-
Notifications
You must be signed in to change notification settings - Fork 747
First steps to fix issue #57 #282
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,9 +655,43 @@ impl CodeGenerator for CompInfo { | |
// also don't output template specializations, neither total or partial. | ||
// | ||
// TODO: Generate layout tests for template specializations, yay! | ||
|
||
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. nit: And this newline. |
||
// TODO (imp): I will keep it like that right now and move it to function later | ||
if self.has_non_type_template_params() || | ||
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. You should still bail out if 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. Please divide this condition as discussed earlier: if self.has_non_type_template_params() {
return;
}
if self.is_template_specialization() {
// ...
return;
} |
||
self.is_template_specialization() { | ||
return; | ||
self.is_template_specialization() { | ||
let layout = item.kind().expect_type().layout(ctx); | ||
let canonical_name = item.canonical_name(ctx); | ||
|
||
if let Some(layout) = layout { | ||
|
||
let mut types = String::new(); | ||
|
||
for arg in self.template_args() { | ||
if let Some(name) = ctx.resolve_type(*arg).name() { | ||
// hope this isn't bad | ||
types.push_str(format!("_{}", name).as_str()); | ||
} | ||
} | ||
|
||
let fn_name = format!("bindgen_test_layout_template_{}{}", canonical_name, types); | ||
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. This is ok probably, but we could just have done something like:
This way is prettier, though a bit more likely to cause conflicts. |
||
let fn_name = ctx.rust_ident_raw(&fn_name); | ||
let ident = item.to_rust_ty(ctx); | ||
let prefix = ctx.trait_prefix(); | ||
let size_of_expr = quote_expr!(ctx.ext_cx(), | ||
::$prefix::mem::size_of::<$ident>()); | ||
let align_of_expr = quote_expr!(ctx.ext_cx(), | ||
::$prefix::mem::align_of::<$ident>()); | ||
let size = layout.size; | ||
let align = layout.align; | ||
let item = quote_item!(ctx.ext_cx(), | ||
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 we should try to reuse this code with the other tests, that way it's easier to change in the future if needed. |
||
#[test] | ||
fn $fn_name() { | ||
assert_eq!($size_of_expr, $size); | ||
assert_eq!($align_of_expr, $align); | ||
}).unwrap(); | ||
result.push(item); | ||
} | ||
return; | ||
} | ||
|
||
let applicable_template_args = item.applicable_template_args(ctx); | ||
|
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.
nit: Remove this
TODO
.