summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-03-21 17:16:07 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-03-21 17:16:07 +0100
commit2ff70a13abf8d7d66e411775c65056cfb0e9f457 (patch)
tree590aeeb2868bf6133898d2439e55cc9882928412
parent66c8a9e12d0e3012d157a68b8e12887f8e616a39 (diff)
gen: Generate raw fields for non-translatable types
-rw-r--r--src/gen.rs35
-rw-r--r--src/parser.rs3
-rw-r--r--tests/headers/size_t_template.hpp8
3 files changed, 37 insertions, 9 deletions
diff --git a/src/gen.rs b/src/gen.rs
index 6132c346..63ba866f 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -803,6 +803,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo) -> Vec<P<ast::Item>
let mut bitfields: u32 = 0;
if ci.hide ||
+ ci.has_non_type_template_params ||
template_args.iter().any(|f| f == &TVoid) {
return vec!();
}
@@ -943,10 +944,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo) -> Vec<P<ast::Item>
if cty_has_destructor(&f.ty) {
has_destructor = true;
}
- if !cty_is_translatable(&f.ty) {
- println!("{}::{} not translatable, void: {}", ci.name, f.name, f.ty == TVoid);
- continue;
- }
+
let f_name = match f.bitfields {
Some(_) => {
bitfields += 1;
@@ -955,6 +953,24 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo) -> Vec<P<ast::Item>
None => rust_type_id(ctx, &f.name)
};
+ if !cty_is_translatable(&f.ty) {
+ println!("{}::{} not translatable, void: {}", ci.name, f.name, f.ty == TVoid);
+ let size = f.ty.size();
+
+ if size != 0 {
+ fields.push(respan(ctx.span, ast::StructField_ {
+ kind: ast::NamedField(
+ ctx.ext_cx.ident_of(&f_name),
+ ast::Visibility::Public,
+ ),
+ id: ast::DUMMY_NODE_ID,
+ ty: quote_ty!(&ctx.ext_cx, [u8; $size]),
+ attrs: mk_doc_attr(ctx, &f.comment)
+ }));
+ }
+ continue;
+ }
+
let mut offset: u32 = 0;
if let Some(ref bitfields) = f.bitfields {
for &(ref bf_name, bf_size) in bitfields.iter() {
@@ -1886,14 +1902,15 @@ fn cty_to_rs(ctx: &mut GenCtx, ty: &Type, allow_bool: bool, use_full_path: bool)
}
fn cty_is_translatable(ty: &Type) -> bool {
- match ty {
- &TVoid => false,
- &TArray(ref t, _, _) => {
+ match *ty {
+ TVoid => false,
+ TArray(ref t, _, _) => {
cty_is_translatable(&**t)
},
- &TComp(ref ci) => {
+ TComp(ref ci) => {
let c = ci.borrow();
- !c.args.iter().any(|gt| gt == &TVoid)
+ println!("translatable? nttp: {}", c.has_non_type_template_params);
+ !c.args.iter().any(|gt| gt == &TVoid) && !c.has_non_type_template_params
},
_ => true,
}
diff --git a/src/parser.rs b/src/parser.rs
index c9243d0e..e5975d83 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -123,6 +123,7 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
GCompDecl(ci)
}
CXCursor_ClassDecl => {
+ let mut has_non_type_template_params = false;
let args = match ty.num_template_args() {
-1 => vec!(),
len => {
@@ -132,6 +133,7 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
if arg_type.kind() != CXType_Invalid {
list.push(conv_ty(ctx, &arg_type, &cursor));
} else {
+ has_non_type_template_params = true;
ctx.logger.warn("warning: Template parameter is not a type");
}
}
@@ -159,6 +161,7 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
let ci = Rc::new(RefCell::new(CompInfo::new(spelling, module_id, filename, comment, CompKind::Struct, vec!(), layout)));
ci.borrow_mut().args = args;
+ ci.borrow_mut().has_non_type_template_params = has_non_type_template_params;
GCompDecl(ci)
}
CXCursor_TypedefDecl => {
diff --git a/tests/headers/size_t_template.hpp b/tests/headers/size_t_template.hpp
new file mode 100644
index 00000000..6045c698
--- /dev/null
+++ b/tests/headers/size_t_template.hpp
@@ -0,0 +1,8 @@
+template<typename T, unsigned long N>
+class Array {
+ T inner[N];
+};
+
+class C {
+ Array<int, 3> arr;
+};