mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2025-03-04 12:47:22 +00:00
Cleanup some warnings from Clippy
This commit is contained in:
parent
4caeda456e
commit
05922aa4ef
47
src/clang.rs
47
src/clang.rs
@ -120,7 +120,7 @@ impl Cursor {
|
||||
for i in 0..num {
|
||||
args.push(Cursor { x: clang_Cursor_getArgument(self.x, i as c_uint) });
|
||||
}
|
||||
return args;
|
||||
args
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ impl Cursor {
|
||||
extern fn visit_children(cur: CXCursor, parent: CXCursor,
|
||||
data: CXClientData) -> Enum_CXChildVisitResult {
|
||||
let func: &mut Box<CursorVisitor> = unsafe { mem::transmute(data) };
|
||||
return (*func)(&Cursor { x : cur }, &Cursor { x: parent });
|
||||
(*func)(&Cursor { x : cur }, &Cursor { x: parent })
|
||||
}
|
||||
|
||||
impl PartialEq for Cursor {
|
||||
@ -151,7 +151,7 @@ impl PartialEq for Cursor {
|
||||
}
|
||||
|
||||
fn ne(&self, other: &Cursor) -> bool {
|
||||
return !self.eq(other);
|
||||
!self.eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ pub struct Type {
|
||||
impl Type {
|
||||
// common
|
||||
pub fn kind(&self) -> Enum_CXTypeKind {
|
||||
return self.x.kind;
|
||||
self.x.kind
|
||||
}
|
||||
|
||||
pub fn declaration(&self) -> Cursor {
|
||||
@ -245,7 +245,7 @@ impl Type {
|
||||
for i in 0..num {
|
||||
args.push(Type { x: clang_getArgType(self.x, i as c_uint) });
|
||||
}
|
||||
return args;
|
||||
args
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ impl SourceLocation {
|
||||
let mut col = 0;
|
||||
let mut off = 0;
|
||||
clang_getSpellingLocation(self.x, &mut file, &mut line, &mut col, &mut off);
|
||||
return (File { x: file }, line as usize, col as usize, off as usize);
|
||||
(File { x: file }, line as usize, col as usize, off as usize)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -283,15 +283,14 @@ impl SourceLocation {
|
||||
impl fmt::Display for SourceLocation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let (file, line, col, _) = self.location();
|
||||
match file.is_null() {
|
||||
false => {
|
||||
try!(file.name().fmt(f));
|
||||
try!(":".fmt(f));
|
||||
try!(line.fmt(f));
|
||||
try!(":".fmt(f));
|
||||
col.fmt(f)
|
||||
},
|
||||
true => "builtin definitions".fmt(f)
|
||||
if !file.is_null() {
|
||||
try!(file.name().fmt(f));
|
||||
try!(":".fmt(f));
|
||||
try!(line.fmt(f));
|
||||
try!(":".fmt(f));
|
||||
col.fmt(f)
|
||||
} else {
|
||||
"builtin definitions".fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -304,7 +303,7 @@ pub struct File {
|
||||
impl File {
|
||||
pub fn name(&self) -> String {
|
||||
if self.is_null() {
|
||||
return "".to_string();
|
||||
return "".to_owned();
|
||||
}
|
||||
unsafe {
|
||||
String_ { x: clang_getFileName(self.x) }.to_string()
|
||||
@ -329,7 +328,7 @@ impl fmt::Display for String_ {
|
||||
unsafe {
|
||||
let c_str = clang_getCString(self.x) as *const c_char;
|
||||
let p = c_str as *const _;
|
||||
str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_string().fmt(f)
|
||||
str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned().fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -371,10 +370,10 @@ pub struct TranslationUnit {
|
||||
impl TranslationUnit {
|
||||
pub fn parse(ix: &Index, file: &str, cmd_args: &[String],
|
||||
unsaved: &[UnsavedFile], opts: ::libc::c_uint) -> TranslationUnit {
|
||||
let _fname = CString::new(file.as_bytes()).unwrap();
|
||||
let fname = _fname.as_ptr();
|
||||
let _c_args: Vec<CString> = cmd_args.iter().map(|s| CString::new(s.as_bytes()).unwrap()).collect();
|
||||
let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect();
|
||||
let fname = CString::new(file.as_bytes()).unwrap();
|
||||
let fname = fname.as_ptr();
|
||||
let c_args: Vec<CString> = cmd_args.iter().map(|s| CString::new(s.as_bytes()).unwrap()).collect();
|
||||
let c_args: Vec<*const c_char> = c_args.iter().map(|s| s.as_ptr()).collect();
|
||||
let mut c_unsaved: Vec<Struct_CXUnsavedFile> = unsaved.iter().map(|f| f.x).collect();
|
||||
let tu = unsafe {
|
||||
clang_parseTranslationUnit(ix.x, fname,
|
||||
@ -405,7 +404,7 @@ impl TranslationUnit {
|
||||
for i in 0..num {
|
||||
diags.push(Diagnostic { x: clang_getDiagnostic(self.x, i as c_uint) });
|
||||
}
|
||||
return diags;
|
||||
diags
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,7 +442,7 @@ impl TranslationUnit {
|
||||
}
|
||||
clang_disposeTokens(self.x, token_ptr, num_tokens);
|
||||
}
|
||||
return Some(tokens);
|
||||
Some(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
@ -744,5 +743,5 @@ pub fn ast_dump(c: &Cursor, depth: isize)-> Enum_CXVisitorResult {
|
||||
ast_dump(s, depth + 1)
|
||||
});
|
||||
print_indent(depth, ")");
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#![allow(unused_attributes)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(raw_pointer_derive)]
|
||||
|
||||
pub type ptrdiff_t = ::libc::c_long;
|
||||
pub type size_t = ::libc::c_ulong;
|
||||
|
224
src/gen.rs
224
src/gen.rs
@ -29,10 +29,10 @@ struct GenCtx<'r> {
|
||||
}
|
||||
|
||||
fn first<A, B>((val, _): (A, B)) -> A {
|
||||
return val;
|
||||
val
|
||||
}
|
||||
|
||||
fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
|
||||
fn ref_eq<T>(thing: &T, other: &T) -> bool {
|
||||
(thing as *const T) == (other as *const T)
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ fn empty_generics() -> ast::Generics {
|
||||
fn rust_id(ctx: &mut GenCtx, name: String) -> (String, bool) {
|
||||
let token = parse::token::Ident(ctx.ext_cx.ident_of(&name[..]), parse::token::Plain);
|
||||
if token.is_any_keyword() || "bool" == &name[..] {
|
||||
let mut s = "_".to_string();
|
||||
let mut s = "_".to_owned();
|
||||
s.push_str(&name[..]);
|
||||
(s, true)
|
||||
} else {
|
||||
@ -77,7 +77,7 @@ fn rust_type_id(ctx: &mut GenCtx, name: String) -> String {
|
||||
"i64" == &name[..] ||
|
||||
"Self" == &name[..] ||
|
||||
"str" == &name[..] {
|
||||
let mut s = "_".to_string();
|
||||
let mut s = "_".to_owned();
|
||||
s.push_str(&name[..]);
|
||||
s
|
||||
} else {
|
||||
@ -87,30 +87,30 @@ fn rust_type_id(ctx: &mut GenCtx, name: String) -> String {
|
||||
}
|
||||
|
||||
fn unnamed_name(ctx: &mut GenCtx, name: String) -> String {
|
||||
return if name.is_empty() {
|
||||
if name.is_empty() {
|
||||
ctx.unnamed_ty += 1;
|
||||
format!("Unnamed{}", ctx.unnamed_ty)
|
||||
} else {
|
||||
name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn comp_name(kind: CompKind, name: &String) -> String {
|
||||
fn comp_name(kind: CompKind, name: &str) -> String {
|
||||
match kind {
|
||||
CompKind::Struct => struct_name(name),
|
||||
CompKind::Union => union_name(name),
|
||||
}
|
||||
}
|
||||
|
||||
fn struct_name(name: &String) -> String {
|
||||
fn struct_name(name: &str) -> String {
|
||||
format!("Struct_{}", name)
|
||||
}
|
||||
|
||||
fn union_name(name: &String) -> String {
|
||||
fn union_name(name: &str) -> String {
|
||||
format!("Union_{}", name)
|
||||
}
|
||||
|
||||
fn enum_name(name: &String) -> String {
|
||||
fn enum_name(name: &str) -> String {
|
||||
format!("Enum_{}", name)
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ pub fn gen_mod(links: &[(String, LinkType)], globs: Vec<Global>, span: Span) ->
|
||||
let mut features = Features::new();
|
||||
features.allow_quote = true;
|
||||
let cfg = ExpansionConfig {
|
||||
crate_name: "xxx".to_string(),
|
||||
crate_name: "xxx".to_owned(),
|
||||
features: Some(&features),
|
||||
recursion_limit: 64,
|
||||
trace_mac: false,
|
||||
@ -287,24 +287,24 @@ fn mk_extern(ctx: &mut GenCtx, links: &[(String, LinkType)],
|
||||
Vec::new()
|
||||
} else {
|
||||
links.iter().map(|&(ref l, ref k)| {
|
||||
let k = match k {
|
||||
&LinkType::Default => None,
|
||||
&LinkType::Static => Some("static"),
|
||||
&LinkType::Framework => Some("framework")
|
||||
let k = match *k {
|
||||
LinkType::Default => None,
|
||||
LinkType::Static => Some("static"),
|
||||
LinkType::Framework => Some("framework")
|
||||
};
|
||||
let link_name = P(respan(ctx.span, ast::MetaNameValue(
|
||||
to_intern_str(ctx, "name".to_string()),
|
||||
to_intern_str(ctx, "name".to_owned()),
|
||||
respan(ctx.span, ast::LitStr(
|
||||
to_intern_str(ctx, l.to_string()),
|
||||
to_intern_str(ctx, l.to_owned()),
|
||||
ast::CookedStr
|
||||
))
|
||||
)));
|
||||
let link_args = match k {
|
||||
None => vec!(link_name),
|
||||
Some(ref k) => vec!(link_name, P(respan(ctx.span, ast::MetaNameValue(
|
||||
to_intern_str(ctx, "kind".to_string()),
|
||||
to_intern_str(ctx, "kind".to_owned()),
|
||||
respan(ctx.span, ast::LitStr(
|
||||
to_intern_str(ctx, k.to_string()),
|
||||
to_intern_str(ctx, (*k).to_owned()),
|
||||
ast::CookedStr
|
||||
))
|
||||
))))
|
||||
@ -313,7 +313,7 @@ fn mk_extern(ctx: &mut GenCtx, links: &[(String, LinkType)],
|
||||
id: mk_attr_id(),
|
||||
style: ast::AttrStyle::Outer,
|
||||
value: P(respan(ctx.span, ast::MetaList(
|
||||
to_intern_str(ctx, "link".to_string()),
|
||||
to_intern_str(ctx, "link".to_owned()),
|
||||
link_args)
|
||||
)),
|
||||
is_sugared_doc: false
|
||||
@ -328,14 +328,14 @@ fn mk_extern(ctx: &mut GenCtx, links: &[(String, LinkType)],
|
||||
items: items
|
||||
});
|
||||
|
||||
return P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(""),
|
||||
attrs: attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ext,
|
||||
vis: ast::Inherited,
|
||||
span: ctx.span
|
||||
});
|
||||
P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(""),
|
||||
attrs: attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ext,
|
||||
vis: ast::Inherited,
|
||||
span: ctx.span
|
||||
})
|
||||
}
|
||||
|
||||
fn remove_redundant_decl(gs: Vec<Global>) -> Vec<Global> {
|
||||
@ -364,9 +364,9 @@ fn remove_redundant_decl(gs: Vec<Global>) -> Vec<Global> {
|
||||
}
|
||||
).collect();
|
||||
|
||||
return gs.into_iter().filter(|g|
|
||||
gs.into_iter().filter(|g|
|
||||
!typedefs.iter().any(|t| check_decl(g, t))
|
||||
).collect();
|
||||
).collect()
|
||||
}
|
||||
|
||||
fn tag_dup_decl(gs: Vec<Global>) -> Vec<Global> {
|
||||
@ -419,24 +419,23 @@ fn tag_dup_decl(gs: Vec<Global>) -> Vec<Global> {
|
||||
return gs;
|
||||
}
|
||||
|
||||
let len = gs.len();
|
||||
let mut res: Vec<Global> = vec!();
|
||||
res.push(gs[0].clone());
|
||||
|
||||
for i in 1..len {
|
||||
for (i, gsi) in gs.iter().enumerate().skip(1) {
|
||||
let mut dup = false;
|
||||
for j in 0..i-1 {
|
||||
if check_dup(&gs[i], &gs[j]) {
|
||||
for gsj in gs.iter().take(i) {
|
||||
if check_dup(&gsi, &gsj) {
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !dup {
|
||||
res.push(gs[i].clone());
|
||||
res.push(gsi.clone());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
res
|
||||
}
|
||||
|
||||
fn ctypedef_to_rs(ctx: &mut GenCtx, name: String, ty: &Type) -> Vec<P<ast::Item>> {
|
||||
@ -452,17 +451,17 @@ fn ctypedef_to_rs(ctx: &mut GenCtx, name: String, ty: &Type) -> Vec<P<ast::Item>
|
||||
empty_generics()
|
||||
);
|
||||
|
||||
return P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(&rust_name[..]),
|
||||
attrs: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: base,
|
||||
vis: ast::Public,
|
||||
span: ctx.span
|
||||
});
|
||||
P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(&rust_name[..]),
|
||||
attrs: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: base,
|
||||
vis: ast::Public,
|
||||
span: ctx.span
|
||||
})
|
||||
}
|
||||
|
||||
return match *ty {
|
||||
match *ty {
|
||||
TComp(ref ci) => {
|
||||
let is_empty = ci.borrow().name.is_empty();
|
||||
if is_empty {
|
||||
@ -506,11 +505,11 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: String,
|
||||
let mut unnamed: u32 = 0;
|
||||
let mut bitfields: u32 = 0;
|
||||
|
||||
for m in members.iter() {
|
||||
let (opt_rc_c, opt_f) = match m {
|
||||
&CompMember::Field(ref f) => { (None, Some(f)) }
|
||||
&CompMember::Comp(ref rc_c) => { (Some(rc_c), None) }
|
||||
&CompMember::CompField(ref rc_c, ref f) => { (Some(rc_c), Some(f)) }
|
||||
for m in &members {
|
||||
let (opt_rc_c, opt_f) = match *m {
|
||||
CompMember::Field(ref f) => { (None, Some(f)) }
|
||||
CompMember::Comp(ref rc_c) => { (Some(rc_c), None) }
|
||||
CompMember::CompField(ref rc_c, ref f) => { (Some(rc_c), Some(f)) }
|
||||
};
|
||||
|
||||
if let Some(f) = opt_f {
|
||||
@ -598,26 +597,27 @@ fn opaque_to_rs(ctx: &mut GenCtx, name: String) -> P<ast::Item> {
|
||||
);
|
||||
|
||||
let id = rust_type_id(ctx, name);
|
||||
return P(ast::Item { ident: ctx.ext_cx.ident_of(&id[..]),
|
||||
attrs: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: def,
|
||||
vis: ast::Public,
|
||||
span: ctx.span
|
||||
});
|
||||
P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(&id[..]),
|
||||
attrs: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: def,
|
||||
vis: ast::Public,
|
||||
span: ctx.span
|
||||
})
|
||||
}
|
||||
|
||||
fn cunion_to_rs(ctx: &mut GenCtx, name: String, layout: Layout, members: Vec<CompMember>) -> Vec<P<ast::Item>> {
|
||||
fn mk_item(ctx: &mut GenCtx, name: String, item: ast::Item_, vis:
|
||||
ast::Visibility, attrs: Vec<ast::Attribute>) -> P<ast::Item> {
|
||||
return P(ast::Item {
|
||||
P(ast::Item {
|
||||
ident: ctx.ext_cx.ident_of(&name[..]),
|
||||
attrs: attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: item,
|
||||
vis: vis,
|
||||
span: ctx.span
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
let ci = Rc::new(RefCell::new(CompInfo::new(name.clone(), CompKind::Union, members.clone(), layout)));
|
||||
@ -652,7 +652,7 @@ fn cunion_to_rs(ctx: &mut GenCtx, name: String, layout: Layout, members: Vec<Com
|
||||
|
||||
let mut items = vec!(
|
||||
union_def,
|
||||
mk_item(ctx, "".to_string(), union_impl, ast::Inherited, Vec::new())
|
||||
mk_item(ctx, "".to_owned(), union_impl, ast::Inherited, Vec::new())
|
||||
);
|
||||
|
||||
items.push(mk_clone_impl(ctx, &name[..]));
|
||||
@ -764,7 +764,7 @@ fn cenum_to_rs(ctx: &mut GenCtx, name: String, kind: IKind, enum_items: &[EnumIt
|
||||
/// declarations and implementations that must be placed at the root level.
|
||||
/// These are emitted into `extra`.
|
||||
fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: usize,
|
||||
kind: CompKind, members: &Vec<CompMember>,
|
||||
kind: CompKind, members: &[CompMember],
|
||||
extra: &mut Vec<P<ast::Item>>) -> Vec<P<ast::ImplItem>> {
|
||||
|
||||
let mk_field_method = |ctx: &mut GenCtx, f: &FieldInfo, offset: usize| {
|
||||
@ -786,7 +786,7 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: usize,
|
||||
", f_name, tts_to_string(&ret_ty.to_tokens(&ctx.ext_cx)[..]), data_field, offset);
|
||||
|
||||
parse::new_parser_from_source_str(ctx.ext_cx.parse_sess(),
|
||||
ctx.ext_cx.cfg(), "".to_string(), impl_str).parse_item().unwrap().unwrap()
|
||||
ctx.ext_cx.cfg(), "".to_owned(), impl_str).parse_item().unwrap().unwrap()
|
||||
};
|
||||
|
||||
method.and_then(|i| {
|
||||
@ -801,19 +801,19 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: usize,
|
||||
|
||||
let mut offset = data_offset;
|
||||
let mut methods = vec!();
|
||||
for m in members.iter() {
|
||||
let advance_by = match m {
|
||||
&CompMember::Field(ref f) => {
|
||||
for m in members.into_iter() {
|
||||
let advance_by = match *m {
|
||||
CompMember::Field(ref f) => {
|
||||
methods.extend(mk_field_method(ctx, f, offset).into_iter());
|
||||
f.ty.size()
|
||||
}
|
||||
&CompMember::Comp(ref rc_c) => {
|
||||
let ref c = rc_c.borrow();
|
||||
CompMember::Comp(ref rc_c) => {
|
||||
let c = &rc_c.borrow();
|
||||
methods.extend(gen_comp_methods(ctx, data_field, offset, c.kind,
|
||||
&c.members, extra).into_iter());
|
||||
c.layout.size
|
||||
}
|
||||
&CompMember::CompField(ref rc_c, ref f) => {
|
||||
CompMember::CompField(ref rc_c, ref f) => {
|
||||
methods.extend(mk_field_method(ctx, f, offset).into_iter());
|
||||
|
||||
let c = rc_c.borrow();
|
||||
@ -839,7 +839,7 @@ fn mk_default_impl(ctx: &GenCtx, ty_name: &str) -> P<ast::Item> {
|
||||
", ty_name);
|
||||
|
||||
parse::new_parser_from_source_str(ctx.ext_cx.parse_sess(),
|
||||
ctx.ext_cx.cfg(), "".to_string(), impl_str).parse_item().unwrap().unwrap()
|
||||
ctx.ext_cx.cfg(), "".to_owned(), impl_str).parse_item().unwrap().unwrap()
|
||||
}
|
||||
|
||||
// Implements std::clone::Clone using dereferencing
|
||||
@ -851,7 +851,7 @@ fn mk_clone_impl(ctx: &GenCtx, ty_name: &str) -> P<ast::Item> {
|
||||
", ty_name);
|
||||
|
||||
parse::new_parser_from_source_str(ctx.ext_cx.parse_sess(),
|
||||
ctx.ext_cx.cfg(), "".to_string(), impl_str).parse_item().unwrap().unwrap()
|
||||
ctx.ext_cx.cfg(), "".to_owned(), impl_str).parse_item().unwrap().unwrap()
|
||||
}
|
||||
|
||||
fn mk_blob_field(ctx: &GenCtx, name: &str, layout: Layout) -> Spanned<ast::StructField_> {
|
||||
@ -863,7 +863,7 @@ fn mk_blob_field(ctx: &GenCtx, name: &str, layout: Layout) -> Spanned<ast::Struc
|
||||
_ => "u8",
|
||||
};
|
||||
let data_len = if ty_name == "u8" { layout.size } else { layout.size / layout.align };
|
||||
let base_ty = mk_ty(ctx, false, vec!(ty_name.to_string()));
|
||||
let base_ty = mk_ty(ctx, false, vec!(ty_name.to_owned()));
|
||||
let data_ty = P(mk_arrty(ctx, &base_ty, data_len));
|
||||
respan(ctx.span, ast::StructField_ {
|
||||
kind: ast::NamedField(
|
||||
@ -882,7 +882,7 @@ fn mk_link_name_attr(ctx: &mut GenCtx, name: String) -> ast::Attribute {
|
||||
ast::CookedStr
|
||||
));
|
||||
let attr_val = P(respan(ctx.span, ast::MetaNameValue(
|
||||
to_intern_str(ctx, "link_name".to_string()), lit
|
||||
to_intern_str(ctx, "link_name".to_owned()), lit
|
||||
)));
|
||||
let attr = ast::Attribute_ {
|
||||
id: mk_attr_id(),
|
||||
@ -894,12 +894,12 @@ fn mk_link_name_attr(ctx: &mut GenCtx, name: String) -> ast::Attribute {
|
||||
}
|
||||
|
||||
fn mk_repr_attr(ctx: &mut GenCtx, layout: Layout) -> ast::Attribute {
|
||||
let mut values = vec!(P(respan(ctx.span, ast::MetaWord(to_intern_str(ctx, "C".to_string())))));
|
||||
let mut values = vec!(P(respan(ctx.span, ast::MetaWord(to_intern_str(ctx, "C".to_owned())))));
|
||||
if layout.packed {
|
||||
values.push(P(respan(ctx.span, ast::MetaWord(to_intern_str(ctx, "packed".to_string())))));
|
||||
values.push(P(respan(ctx.span, ast::MetaWord(to_intern_str(ctx, "packed".to_owned())))));
|
||||
}
|
||||
let attr_val = P(respan(ctx.span, ast::MetaList(
|
||||
to_intern_str(ctx, "repr".to_string()),
|
||||
to_intern_str(ctx, "repr".to_owned()),
|
||||
values
|
||||
)));
|
||||
|
||||
@ -940,14 +940,14 @@ fn cvar_to_rs(ctx: &mut GenCtx, name: String,
|
||||
|
||||
let val_ty = P(cty_to_rs(ctx, ty));
|
||||
|
||||
return P(ast::ForeignItem {
|
||||
P(ast::ForeignItem {
|
||||
ident: ctx.ext_cx.ident_of(&rust_name[..]),
|
||||
attrs: attrs,
|
||||
node: ast::ForeignItemStatic(val_ty, !is_const),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: ctx.span,
|
||||
vis: ast::Public,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn cfuncty_to_rs(ctx: &mut GenCtx,
|
||||
@ -976,8 +976,8 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
|
||||
// adjusted to “qualified pointer to type”, where the type qualifiers
|
||||
// (if any) are those specified within the [ and ] of the array type
|
||||
// derivation.
|
||||
let arg_ty = P(match t {
|
||||
&TArray(ref typ, _, ref l) => cty_to_rs(ctx, &TPtr(typ.clone(), false, l.clone())),
|
||||
let arg_ty = P(match *t {
|
||||
TArray(ref typ, _, ref l) => cty_to_rs(ctx, &TPtr(typ.clone(), false, l.clone())),
|
||||
_ => cty_to_rs(ctx, t),
|
||||
});
|
||||
|
||||
@ -997,11 +997,11 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
|
||||
}).collect();
|
||||
|
||||
let var = !args.is_empty() && var;
|
||||
return ast::FnDecl {
|
||||
ast::FnDecl {
|
||||
inputs: args,
|
||||
output: ret,
|
||||
variadic: var
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn cfunc_to_rs(ctx: &mut GenCtx, name: String, rty: &Type,
|
||||
@ -1020,27 +1020,27 @@ fn cfunc_to_rs(ctx: &mut GenCtx, name: String, rty: &Type,
|
||||
attrs.push(mk_link_name_attr(ctx, name));
|
||||
}
|
||||
|
||||
return P(ast::ForeignItem {
|
||||
ident: ctx.ext_cx.ident_of(&rust_name[..]),
|
||||
attrs: attrs,
|
||||
node: decl,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: ctx.span,
|
||||
vis: ast::Public,
|
||||
});
|
||||
P(ast::ForeignItem {
|
||||
ident: ctx.ext_cx.ident_of(&rust_name[..]),
|
||||
attrs: attrs,
|
||||
node: decl,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: ctx.span,
|
||||
vis: ast::Public,
|
||||
})
|
||||
}
|
||||
|
||||
fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {
|
||||
let prefix = vec!["std".to_string(), "os".to_string(), "raw".to_string()];
|
||||
let prefix = vec!["std".to_owned(), "os".to_owned(), "raw".to_owned()];
|
||||
let raw = |fragment: &str| {
|
||||
let mut path = prefix.clone();
|
||||
path.push(fragment.to_string());
|
||||
path.push(fragment.to_owned());
|
||||
path
|
||||
};
|
||||
|
||||
return match ty {
|
||||
&TVoid => mk_ty(ctx, true, raw("c_void")),
|
||||
&TInt(i, ref layout) => match i {
|
||||
match *ty {
|
||||
TVoid => mk_ty(ctx, true, raw("c_void")),
|
||||
TInt(i, ref layout) => match i {
|
||||
IBool => {
|
||||
let ty_name = match layout.size {
|
||||
1 => "u8",
|
||||
@ -1049,7 +1049,7 @@ fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {
|
||||
8 => "u64",
|
||||
_ => "u8",
|
||||
};
|
||||
mk_ty(ctx, false, vec!(ty_name.to_string()))
|
||||
mk_ty(ctx, false, vec!(ty_name.to_owned()))
|
||||
},
|
||||
ISChar => mk_ty(ctx, true, raw("c_char")),
|
||||
IUChar => mk_ty(ctx, true, raw("c_uchar")),
|
||||
@ -1062,43 +1062,43 @@ fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {
|
||||
ILongLong => mk_ty(ctx, true, raw("c_longlong")),
|
||||
IULongLong => mk_ty(ctx, true, raw("c_ulonglong"))
|
||||
},
|
||||
&TFloat(f, _) => match f {
|
||||
TFloat(f, _) => match f {
|
||||
FFloat => mk_ty(ctx, true, raw("c_float")),
|
||||
FDouble => mk_ty(ctx, true, raw("c_double"))
|
||||
},
|
||||
&TPtr(ref t, is_const, _) => {
|
||||
TPtr(ref t, is_const, _) => {
|
||||
let id = cty_to_rs(ctx, &**t);
|
||||
mk_ptrty(ctx, &id, is_const)
|
||||
},
|
||||
&TArray(ref t, s, _) => {
|
||||
TArray(ref t, s, _) => {
|
||||
let ty = cty_to_rs(ctx, &**t);
|
||||
mk_arrty(ctx, &ty, s)
|
||||
},
|
||||
&TFuncPtr(ref sig) => {
|
||||
TFuncPtr(ref sig) => {
|
||||
let decl = cfuncty_to_rs(ctx, &*sig.ret_ty, &sig.args[..], sig.is_variadic);
|
||||
let unsafety = if sig.is_safe { ast::Unsafety::Normal } else { ast::Unsafety::Unsafe };
|
||||
mk_fnty(ctx, &decl, unsafety, sig.abi)
|
||||
},
|
||||
&TFuncProto(ref sig) => {
|
||||
TFuncProto(ref sig) => {
|
||||
let decl = cfuncty_to_rs(ctx, &*sig.ret_ty, &sig.args[..], sig.is_variadic);
|
||||
let unsafety = if sig.is_safe { ast::Unsafety::Normal } else { ast::Unsafety::Unsafe };
|
||||
mk_fn_proto_ty(ctx, &decl, unsafety, sig.abi)
|
||||
},
|
||||
&TNamed(ref ti) => {
|
||||
TNamed(ref ti) => {
|
||||
let id = rust_type_id(ctx, ti.borrow().name.clone());
|
||||
mk_ty(ctx, false, vec!(id))
|
||||
},
|
||||
&TComp(ref ci) => {
|
||||
TComp(ref ci) => {
|
||||
let mut c = ci.borrow_mut();
|
||||
c.name = unnamed_name(ctx, c.name.clone());
|
||||
mk_ty(ctx, false, vec!(comp_name(c.kind, &c.name)))
|
||||
},
|
||||
&TEnum(ref ei) => {
|
||||
TEnum(ref ei) => {
|
||||
let mut e = ei.borrow_mut();
|
||||
e.name = unnamed_name(ctx, e.name.clone());
|
||||
mk_ty(ctx, false, vec!(enum_name(&e.name)))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_ty(ctx: &GenCtx, global: bool, segments: Vec<String>) -> ast::Ty {
|
||||
@ -1120,11 +1120,11 @@ fn mk_ty(ctx: &GenCtx, global: bool, segments: Vec<String>) -> ast::Ty {
|
||||
},
|
||||
);
|
||||
|
||||
return ast::Ty {
|
||||
ast::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ty,
|
||||
span: ctx.span
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_ptrty(ctx: &mut GenCtx, base: &ast::Ty, is_const: bool) -> ast::Ty {
|
||||
@ -1133,11 +1133,11 @@ fn mk_ptrty(ctx: &mut GenCtx, base: &ast::Ty, is_const: bool) -> ast::Ty {
|
||||
mutbl: if is_const { ast::MutImmutable } else { ast::MutMutable }
|
||||
});
|
||||
|
||||
return ast::Ty {
|
||||
ast::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ty,
|
||||
span: ctx.span
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_arrty(ctx: &GenCtx, base: &ast::Ty, n: usize) -> ast::Ty {
|
||||
@ -1153,11 +1153,11 @@ fn mk_arrty(ctx: &GenCtx, base: &ast::Ty, n: usize) -> ast::Ty {
|
||||
})
|
||||
);
|
||||
|
||||
return ast::Ty {
|
||||
ast::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ty,
|
||||
span: ctx.span
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_fn_proto_ty(ctx: &mut GenCtx,
|
||||
@ -1222,7 +1222,7 @@ fn mk_fnty(ctx: &mut GenCtx,
|
||||
}
|
||||
];
|
||||
|
||||
return ast::Ty {
|
||||
ast::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ast::TyPath(
|
||||
None,
|
||||
@ -1233,5 +1233,5 @@ fn mk_fnty(ctx: &mut GenCtx,
|
||||
},
|
||||
),
|
||||
span: ctx.span
|
||||
};
|
||||
}
|
||||
}
|
||||
|
19
src/lib.rs
19
src/lib.rs
@ -115,7 +115,7 @@ impl Default for BindgenOptions {
|
||||
links: Vec::new(),
|
||||
emit_ast: false,
|
||||
fail_on_unknown_type: false,
|
||||
override_enum_ty: "".to_string(),
|
||||
override_enum_ty: "".to_owned(),
|
||||
clang_args: match get_include_dir() {
|
||||
Some(path) => vec!("-idirafter".to_owned(), path),
|
||||
None => Vec::new()
|
||||
@ -175,7 +175,7 @@ impl Bindings {
|
||||
let mut mod_str = Vec::new();
|
||||
{
|
||||
let ref_writer = Box::new(mod_str.by_ref()) as Box<Write>;
|
||||
self.write(ref_writer).ok().expect("Could not write bindings to string");
|
||||
self.write(ref_writer).expect("Could not write bindings to string");
|
||||
}
|
||||
String::from_utf8(mod_str).unwrap()
|
||||
}
|
||||
@ -185,7 +185,7 @@ impl Bindings {
|
||||
self.write(Box::new(file))
|
||||
}
|
||||
|
||||
pub fn write<'a, 'b>(&'a self, mut writer: Box<Write + 'b>) -> io::Result<()> {
|
||||
pub fn write<'a>(&self, mut writer: Box<Write + 'a>) -> io::Result<()> {
|
||||
try!(writer.write("/* automatically generated by rust-bindgen */\n\n".as_bytes()));
|
||||
let mut ps = pprust::rust_printer(writer);
|
||||
try!(ps.print_mod(&self.module, &[]));
|
||||
@ -241,12 +241,11 @@ fn builtin_names() -> HashSet<String> {
|
||||
"__builtin_va_list",
|
||||
];
|
||||
|
||||
keys.iter().all(|s| {
|
||||
names.insert(s.to_string());
|
||||
true
|
||||
});
|
||||
for s in &keys {
|
||||
names.insert((*s).to_owned());
|
||||
}
|
||||
|
||||
return names;
|
||||
names
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -260,8 +259,8 @@ fn builder_state()
|
||||
build.log(&logger);
|
||||
}
|
||||
assert!(build.logger.is_some());
|
||||
assert!(build.options.clang_args.binary_search(&"example.h".to_string()).is_ok());
|
||||
assert!(build.options.links.binary_search(&("m".to_string(), LinkType::Static)).is_ok());
|
||||
assert!(build.options.clang_args.binary_search(&"example.h".to_owned()).is_ok());
|
||||
assert!(build.options.links.binary_search(&("m".to_owned(), LinkType::Static)).is_ok());
|
||||
}
|
||||
|
||||
// Get the first directory in PATH that contains a file named "clang".
|
||||
|
@ -55,7 +55,7 @@ fn match_pattern(ctx: &mut ClangParserCtx, cursor: &Cursor) -> bool {
|
||||
true
|
||||
});
|
||||
|
||||
return found;
|
||||
found
|
||||
}
|
||||
|
||||
fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
|
||||
@ -119,13 +119,11 @@ fn decl_name(ctx: &mut ClangParserCtx, cursor: &Cursor) -> Global {
|
||||
},
|
||||
};
|
||||
|
||||
if new_decl {
|
||||
if ctx.options.builtin_names.contains(&cursor.spelling()) {
|
||||
ctx.builtin_defs.push(cursor);
|
||||
}
|
||||
if new_decl && ctx.options.builtin_names.contains(&cursor.spelling()) {
|
||||
ctx.builtin_defs.push(cursor);
|
||||
}
|
||||
|
||||
return decl;
|
||||
decl
|
||||
}
|
||||
|
||||
fn opaque_decl(ctx: &mut ClangParserCtx, decl: &Cursor) {
|
||||
@ -151,7 +149,7 @@ fn get_abi(cc: Enum_CXCallingConv) -> abi::Abi {
|
||||
CXCallingConv_X86FastCall => abi::Fastcall,
|
||||
CXCallingConv_AAPCS => abi::Aapcs,
|
||||
CXCallingConv_X86_64Win64 => abi::Win64,
|
||||
_other => panic!("unsupported calling convention: {}", _other),
|
||||
other => panic!("unsupported calling convention: {}", other),
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,14 +157,14 @@ fn conv_ptr_ty(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor, layout:
|
||||
let is_const = ty.is_const();
|
||||
match ty.kind() {
|
||||
CXType_Void => {
|
||||
return TPtr(Box::new(TVoid), is_const, layout)
|
||||
TPtr(Box::new(TVoid), is_const, layout)
|
||||
}
|
||||
CXType_Unexposed |
|
||||
CXType_FunctionProto |
|
||||
CXType_FunctionNoProto => {
|
||||
let ret_ty = ty.ret_type();
|
||||
let decl = ty.declaration();
|
||||
return if ret_ty.kind() != CXType_Invalid {
|
||||
if ret_ty.kind() != CXType_Invalid {
|
||||
TFuncPtr(mk_fn_sig(ctx, ty, cursor))
|
||||
} else if decl.kind() != CXCursor_NoDeclFound {
|
||||
TPtr(Box::new(conv_decl_ty(ctx, &decl)), ty.is_const(), layout)
|
||||
@ -175,19 +173,19 @@ fn conv_ptr_ty(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor, layout:
|
||||
conv_ty(ctx, &can_ty, cursor)
|
||||
} else {
|
||||
TPtr(Box::new(TVoid), ty.is_const(), layout)
|
||||
};
|
||||
}
|
||||
}
|
||||
CXType_Typedef => {
|
||||
let decl = ty.declaration();
|
||||
let def_ty = decl.typedef_type();
|
||||
if def_ty.kind() == CXType_FunctionProto ||
|
||||
def_ty.kind() == CXType_FunctionNoProto {
|
||||
return TPtr(Box::new(conv_ptr_ty(ctx, &def_ty, cursor, layout)), is_const, layout);
|
||||
TPtr(Box::new(conv_ptr_ty(ctx, &def_ty, cursor, layout)), is_const, layout)
|
||||
} else {
|
||||
return TPtr(Box::new(conv_ty(ctx, ty, cursor)), is_const, layout);
|
||||
TPtr(Box::new(conv_ty(ctx, ty, cursor)), is_const, layout)
|
||||
}
|
||||
}
|
||||
_ => return TPtr(Box::new(conv_ty(ctx, ty, cursor)), is_const, layout),
|
||||
_ => TPtr(Box::new(conv_ty(ctx, ty, cursor)), is_const, layout),
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +232,7 @@ fn mk_fn_sig(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor) -> il::Fu
|
||||
}
|
||||
|
||||
fn conv_decl_ty(ctx: &mut ClangParserCtx, cursor: &Cursor) -> il::Type {
|
||||
return match cursor.kind() {
|
||||
match cursor.kind() {
|
||||
CXCursor_StructDecl => {
|
||||
let decl = decl_name(ctx, cursor);
|
||||
let ci = decl.compinfo();
|
||||
@ -256,13 +254,13 @@ fn conv_decl_ty(ctx: &mut ClangParserCtx, cursor: &Cursor) -> il::Type {
|
||||
TNamed(ti)
|
||||
}
|
||||
_ => TVoid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn conv_ty(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor) -> il::Type {
|
||||
debug!("conv_ty: ty=`{}` sp=`{}` loc=`{}`", type_to_str(ty.kind()), cursor.spelling(), cursor.location());
|
||||
let layout = Layout::new(ty.size(), ty.align());
|
||||
return match ty.kind() {
|
||||
match ty.kind() {
|
||||
CXType_Void | CXType_Invalid => TVoid,
|
||||
CXType_Bool => TInt(IBool, layout),
|
||||
CXType_SChar |
|
||||
@ -300,7 +298,7 @@ fn conv_ty(ctx: &mut ClangParserCtx, ty: &cx::Type, cursor: &Cursor) -> il::Type
|
||||
);
|
||||
TVoid
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn opaque_ty(ctx: &mut ClangParserCtx, ty: &cx::Type) {
|
||||
@ -320,7 +318,7 @@ fn opaque_ty(ctx: &mut ClangParserCtx, ty: &cx::Type) {
|
||||
fn visit_composite(cursor: &Cursor, parent: &Cursor,
|
||||
ctx: &mut ClangParserCtx,
|
||||
compinfo: &mut CompInfo) -> Enum_CXVisitorResult {
|
||||
let ref mut members = compinfo.members;
|
||||
let members = &mut compinfo.members;
|
||||
|
||||
fn is_bitfield_continuation(field: &il::FieldInfo, ty: &il::Type, width: u32) -> bool {
|
||||
match (&field.bitfields, ty) {
|
||||
@ -349,15 +347,15 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
|
||||
(Some(width), _) => {
|
||||
// Bitfields containing enums are not supported by the c standard
|
||||
// https://stackoverflow.com/questions/11983231/is-it-safe-to-use-an-enum-in-a-bit-field
|
||||
match &ty {
|
||||
&il::TInt(_, _) => (),
|
||||
match ty {
|
||||
il::TInt(_, _) => (),
|
||||
_ => {
|
||||
let msg = format!("Enums in bitfields are not supported ({}.{}).",
|
||||
cursor.spelling(), parent.spelling());
|
||||
ctx.logger.warn(&msg[..]);
|
||||
}
|
||||
}
|
||||
("".to_string(), Some(vec!((cursor.spelling(), width))))
|
||||
("".to_owned(), Some(vec!((cursor.spelling(), width))))
|
||||
},
|
||||
// The field is not a bitfield
|
||||
(None, _) => (cursor.spelling(), None)
|
||||
@ -393,10 +391,10 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
|
||||
|
||||
fn inner_composite(mut ty: &il::Type) -> Option<&Rc<RefCell<CompInfo>>> {
|
||||
loop {
|
||||
match ty {
|
||||
&TComp(ref comp_ty) => return Some(comp_ty),
|
||||
&TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
|
||||
&TArray(ref array_ty, _, _) => ty = &**array_ty,
|
||||
match *ty {
|
||||
TComp(ref comp_ty) => return Some(comp_ty),
|
||||
TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
|
||||
TArray(ref array_ty, _, _) => ty = &**array_ty,
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
@ -459,18 +457,18 @@ fn visit_enum(cursor: &Cursor,
|
||||
let item = EnumItem::new(name, val);
|
||||
items.push(item);
|
||||
}
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
|
||||
fn visit_literal(cursor: &Cursor, unit: &TranslationUnit) -> Option<i64> {
|
||||
if cursor.kind() == CXCursor_IntegerLiteral {
|
||||
return match unit.tokens(cursor) {
|
||||
match unit.tokens(cursor) {
|
||||
None => None,
|
||||
Some(tokens) => {
|
||||
if tokens.len() == 0 || tokens[0].kind != CXToken_Literal {
|
||||
if tokens.is_empty() || tokens[0].kind != CXToken_Literal {
|
||||
None
|
||||
} else {
|
||||
let ref s = tokens[0].spelling;
|
||||
let s = &tokens[0].spelling;
|
||||
let parsed = {
|
||||
//TODO: try to preserve hex literals?
|
||||
if s.starts_with("0x") {
|
||||
@ -487,10 +485,12 @@ fn visit_literal(cursor: &Cursor, unit: &TranslationUnit) -> Option<i64> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return None;
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_top<'r>(cursor: &Cursor,
|
||||
fn visit_top(cursor: &Cursor,
|
||||
ctx: &mut ClangParserCtx,
|
||||
unit: &TranslationUnit) -> Enum_CXVisitorResult {
|
||||
if !match_pattern(ctx, cursor) {
|
||||
@ -499,7 +499,7 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
|
||||
match cursor.kind() {
|
||||
CXCursor_UnexposedDecl => {
|
||||
return CXChildVisit_Recurse;
|
||||
CXChildVisit_Recurse
|
||||
}
|
||||
CXCursor_StructDecl | CXCursor_UnionDecl => {
|
||||
fwd_decl(ctx, cursor, |ctx_| {
|
||||
@ -511,7 +511,7 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
});
|
||||
ctx_.globals.push(GComp(ci));
|
||||
});
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
CXCursor_EnumDecl => {
|
||||
fwd_decl(ctx, cursor, |ctx_| {
|
||||
@ -523,7 +523,7 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
});
|
||||
ctx_.globals.push(GEnum(ei));
|
||||
});
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
CXCursor_FunctionDecl => {
|
||||
let linkage = cursor.linkage();
|
||||
@ -538,7 +538,7 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
vi.ty = TFuncPtr(mk_fn_sig(ctx, &cursor.cur_type(), cursor));
|
||||
ctx.globals.push(func);
|
||||
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
CXCursor_VarDecl => {
|
||||
let linkage = cursor.linkage();
|
||||
@ -558,7 +558,7 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
});
|
||||
ctx.globals.push(var);
|
||||
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
CXCursor_TypedefDecl => {
|
||||
let mut under_ty = cursor.typedef_type();
|
||||
@ -575,22 +575,21 @@ fn visit_top<'r>(cursor: &Cursor,
|
||||
|
||||
opaque_ty(ctx, &under_ty);
|
||||
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
CXCursor_FieldDecl => {
|
||||
return CXChildVisit_Continue;
|
||||
CXChildVisit_Continue
|
||||
}
|
||||
_ => return CXChildVisit_Continue,
|
||||
_ => CXChildVisit_Continue,
|
||||
}
|
||||
}
|
||||
|
||||
fn log_err_warn(ctx: &mut ClangParserCtx, msg: &str, is_err: bool) {
|
||||
match is_err {
|
||||
true => {
|
||||
ctx.err_count += 1;
|
||||
ctx.logger.error(msg)
|
||||
},
|
||||
false => ctx.logger.warn(msg)
|
||||
if is_err {
|
||||
ctx.err_count += 1;
|
||||
ctx.logger.error(msg)
|
||||
} else {
|
||||
ctx.logger.warn(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@ -617,7 +616,7 @@ pub fn parse(options: ClangParserOptions, logger: &Logger) -> Result<Vec<Global>
|
||||
}
|
||||
|
||||
let diags = unit.diags();
|
||||
for d in diags.iter() {
|
||||
for d in &diags {
|
||||
let msg = d.format(Diagnostic::default_opts());
|
||||
let is_err = d.severity() >= CXDiagnostic_Error;
|
||||
log_err_warn(&mut ctx, &msg[..], is_err);
|
||||
|
62
src/types.rs
62
src/types.rs
@ -24,24 +24,24 @@ pub enum Global {
|
||||
impl Global {
|
||||
pub fn compinfo(&self) -> Rc<RefCell<CompInfo>> {
|
||||
match *self {
|
||||
GComp(ref i) => return i.clone(),
|
||||
GCompDecl(ref i) => return i.clone(),
|
||||
_ => panic!("global_compinfo".to_string())
|
||||
GComp(ref i) => i.clone(),
|
||||
GCompDecl(ref i) => i.clone(),
|
||||
_ => panic!("global_compinfo")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enuminfo(&self) -> Rc<RefCell<EnumInfo>> {
|
||||
match *self {
|
||||
GEnum(ref i) => return i.clone(),
|
||||
GEnumDecl(ref i) => return i.clone(),
|
||||
_ => panic!("global_enuminfo".to_string())
|
||||
GEnum(ref i) => i.clone(),
|
||||
GEnumDecl(ref i) => i.clone(),
|
||||
_ => panic!("global_enuminfo")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn typeinfo(&self) -> Rc<RefCell<TypeInfo>> {
|
||||
match *self {
|
||||
GType(ref i) => return i.clone(),
|
||||
_ => panic!("global_typeinfo".to_string())
|
||||
GType(ref i) => i.clone(),
|
||||
_ => panic!("global_typeinfo")
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ impl Global {
|
||||
match *self {
|
||||
GVar(ref i) => i.clone(),
|
||||
GFunc(ref i) => i.clone(),
|
||||
_ => panic!("global_varinfo".to_string())
|
||||
_ => panic!("global_varinfo")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,33 +94,33 @@ pub enum Type {
|
||||
|
||||
impl Type {
|
||||
pub fn size(&self) -> usize {
|
||||
match self {
|
||||
&TInt(_, l) => l.size,
|
||||
&TFloat(_, l) => l.size,
|
||||
&TPtr(_, _, l) => l.size,
|
||||
&TArray(_, _, l) => l.size,
|
||||
&TNamed(ref ti) => ti.borrow().ty.size(),
|
||||
&TComp(ref ci) => ci.borrow().layout.size,
|
||||
&TEnum(ref ei) => ei.borrow().layout.size,
|
||||
&TVoid => 0,
|
||||
&TFuncProto(..) => 0,
|
||||
&TFuncPtr(..) => 0,
|
||||
match *self {
|
||||
TInt(_, l) => l.size,
|
||||
TFloat(_, l) => l.size,
|
||||
TPtr(_, _, l) => l.size,
|
||||
TArray(_, _, l) => l.size,
|
||||
TNamed(ref ti) => ti.borrow().ty.size(),
|
||||
TComp(ref ci) => ci.borrow().layout.size,
|
||||
TEnum(ref ei) => ei.borrow().layout.size,
|
||||
TVoid => 0,
|
||||
TFuncProto(..) => 0,
|
||||
TFuncPtr(..) => 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn align(&self) -> usize {
|
||||
match self {
|
||||
&TInt(_, l) => l.align,
|
||||
&TFloat(_, l) => l.align,
|
||||
&TPtr(_, _, l) => l.align,
|
||||
&TArray(_, _, l) => l.align,
|
||||
&TNamed(ref ti) => ti.borrow().ty.align(),
|
||||
&TComp(ref ci) => ci.borrow().layout.align,
|
||||
&TEnum(ref ei) => ei.borrow().layout.align,
|
||||
&TVoid => 0,
|
||||
&TFuncProto(..) => 0,
|
||||
&TFuncPtr(..) => 0,
|
||||
match *self {
|
||||
TInt(_, l) => l.align,
|
||||
TFloat(_, l) => l.align,
|
||||
TPtr(_, _, l) => l.align,
|
||||
TArray(_, _, l) => l.align,
|
||||
TNamed(ref ti) => ti.borrow().ty.align(),
|
||||
TComp(ref ci) => ci.borrow().layout.align,
|
||||
TEnum(ref ei) => ei.borrow().layout.align,
|
||||
TVoid => 0,
|
||||
TFuncProto(..) => 0,
|
||||
TFuncPtr(..) => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use std::default::Default;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::codemap;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
use syntax::parse;
|
||||
use syntax::parse::token;
|
||||
use syntax::print::pprust;
|
||||
@ -50,7 +50,7 @@ pub fn assert_bind_eq(filename: &str, reference_items_str: &str)
|
||||
// rendered versions, which is not beautiful, but should work.
|
||||
let reference_rendered = render_items(&reference_items);
|
||||
let generated_rendered = render_items(&generated_items);
|
||||
|
||||
|
||||
if reference_rendered != generated_rendered {
|
||||
println!("Generated bindings for {} do not match the reference bindings.", filename);
|
||||
println!("");
|
||||
|
Loading…
x
Reference in New Issue
Block a user