Skip to content

Commit

Permalink
revert bitfield comment, generate argument name
Browse files Browse the repository at this point in the history
  • Loading branch information
crabtw committed Apr 23, 2012
1 parent 1507f8b commit 0abb6b0
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 210 deletions.
40 changes: 19 additions & 21 deletions bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,6 @@ fn opaque_ty(ctx: @bind_ctx, ty: CXType) {
}
}

crust fn visit_field(++cursor: CXCursor,
++_parent: CXCursor,
data: CXClientData) -> c_uint unsafe {
let ctx = *(data as *@bind_ctx);
let suffix = if cursor.kind == CXCursor_IntegerLiteral {
" /* FIXME: bit field */"
} else {
""
};
ctx.out.write_line(suffix);
ret CXChildVisit_Continue;
}

crust fn visit_struct(++cursor: CXCursor,
++_parent: CXCursor,
data: CXClientData) -> c_uint unsafe {
Expand All @@ -390,11 +377,9 @@ crust fn visit_struct(++cursor: CXCursor,
name = "field_unnamed" + uint::str(ctx.unnamed_field);
ctx.unnamed_field += 1u;
}
ctx.out.write_str(#fmt[" %s: %s,",
ctx.out.write_line(#fmt[" %s: %s,",
rust_id(ctx, name),
conv_ty(ctx, ty, cursor, true)]);
clang_visitChildren(cursor, visit_field,
ptr::addr_of(ctx) as CXClientData);
}
ret CXChildVisit_Continue;
}
Expand Down Expand Up @@ -558,19 +543,32 @@ crust fn visit_func_top(++cursor: CXCursor,
ret CXChildVisit_Continue;
}

let ty = clang_getCursorType(cursor);
ctx.out.write_str(#fmt["fn %s(", rust_id(ctx, name)]);
let arg_n = clang_getNumArgTypes(ty) as int;
let arg_n = clang_Cursor_getNumArguments(cursor) as int;
let mut i = 0;
let mut unnamed = 0;
while i < arg_n {
if i > 0 {
ctx.out.write_str(", ");
}
let arg_ty = clang_getArgType(ty, i as c_uint);
ctx.out.write_str(#fmt["++arg%d: %s",
i, conv_ty(ctx, arg_ty, cursor, false)]);

let arg = clang_Cursor_getArgument(cursor, i as c_uint);
let arg_ty = clang_getCursorType(arg);
let mut arg_name = to_str(clang_getCursorSpelling(arg));

arg_name = if str::is_empty(arg_name) {
unnamed += 1;
#fmt["arg%d", unnamed]
} else {
rust_id(ctx, arg_name)
};

ctx.out.write_str(#fmt["++%s: %s",
arg_name,
conv_ty(ctx, arg_ty, cursor, false)]);
i += 1;
}
let ty = clang_getCursorType(cursor);
if clang_isFunctionTypeVariadic(ty) as uint != 0u {
ctx.out.write_str("/* FIXME: variadic function */");
}
Expand Down
Loading

0 comments on commit 0abb6b0

Please sign in to comment.