diff options
-rw-r--r-- | src/clang.rs | 3 | ||||
-rw-r--r-- | src/clangll.rs | 35 | ||||
-rw-r--r-- | src/gen.rs | 25 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/types.rs | 46 |
5 files changed, 75 insertions, 36 deletions
diff --git a/src/clang.rs b/src/clang.rs index c3da6ec7..b728b9f9 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -11,6 +11,7 @@ pub use clangll as ll; use clangll::*; // Cursor +#[deriving(Copy)] pub struct Cursor { x: CXCursor } @@ -313,7 +314,7 @@ impl fmt::Show for String_ { } unsafe { let c_str = clang_getCString(self.x) as *const c_char; - string::raw::from_buf(c_str as *const u8).fmt(f) + String::from_raw_buf(c_str as *const u8).fmt(f) } } } diff --git a/src/clangll.rs b/src/clangll.rs index 68be6675..8a32d2e1 100644 --- a/src/clangll.rs +++ b/src/clangll.rs @@ -5,11 +5,13 @@ #![allow(unused_attributes)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] +#![allow(raw_pointer_deriving)] pub type ptrdiff_t = ::libc::c_long; pub type size_t = ::libc::c_ulong; pub type wchar_t = ::libc::c_int; #[repr(C)] +#[deriving(Copy)] pub struct CXString { pub data: *const ::libc::c_void, pub private_flags: ::libc::c_uint, @@ -19,6 +21,7 @@ pub enum Struct_CXTranslationUnitImpl { } pub type CXTranslationUnit = *mut Struct_CXTranslationUnitImpl; pub type CXClientData = *mut ::libc::c_void; #[repr(C)] +#[deriving(Copy)] pub struct Struct_CXUnsavedFile { pub Filename: *const ::libc::c_char, pub Contents: *const ::libc::c_char, @@ -30,6 +33,7 @@ pub const CXAvailability_Deprecated: ::libc::c_uint = 1; pub const CXAvailability_NotAvailable: ::libc::c_uint = 2; pub const CXAvailability_NotAccessible: ::libc::c_uint = 3; #[repr(C)] +#[deriving(Copy)] pub struct Struct_CXVersion { pub Major: ::libc::c_int, pub Minor: ::libc::c_int, @@ -44,15 +48,18 @@ pub const CXGlobalOpt_ThreadBackgroundPriorityForEditing: ::libc::c_uint = 2; pub const CXGlobalOpt_ThreadBackgroundPriorityForAll: ::libc::c_uint = 3; pub type CXFile = *mut ::libc::c_void; #[repr(C)] +#[deriving(Copy)] pub struct CXFileUniqueID { pub data: [::libc::c_ulonglong, ..3u], } #[repr(C)] +#[deriving(Copy)] pub struct CXSourceLocation { pub ptr_data: [*const ::libc::c_void, ..2u], pub int_data: ::libc::c_uint, } #[repr(C)] +#[deriving(Copy)] pub struct CXSourceRange { pub ptr_data: [*const ::libc::c_void, ..2u], pub begin_int_data: ::libc::c_uint, @@ -125,12 +132,14 @@ pub const CXTUResourceUsage_MEMORY_IN_BYTES_END: ::libc::c_uint = 14; pub const CXTUResourceUsage_First: ::libc::c_uint = 1; pub const CXTUResourceUsage_Last: ::libc::c_uint = 14; #[repr(C)] +#[deriving(Copy)] pub struct Struct_CXTUResourceUsageEntry { pub kind: Enum_CXTUResourceUsageKind, pub amount: ::libc::c_ulong, } pub type CXTUResourceUsageEntry = Struct_CXTUResourceUsageEntry; #[repr(C)] +#[deriving(Copy)] pub struct Struct_CXTUResourceUsage { pub data: *mut ::libc::c_void, pub numEntries: ::libc::c_uint, @@ -306,12 +315,14 @@ pub const CXCursor_ModuleImportDecl: ::libc::c_uint = 600; pub const CXCursor_FirstExtraDecl: ::libc::c_uint = 600; pub const CXCursor_LastExtraDecl: ::libc::c_uint = 600; #[repr(C)] +#[deriving(Copy)] pub struct CXCursor { pub kind: Enum_CXCursorKind, pub xdata: ::libc::c_int, pub data: [*const ::libc::c_void, ..3u], } #[repr(C)] +#[deriving(Copy)] pub struct CXComment { pub ASTNode: *const ::libc::c_void, pub TranslationUnit: CXTranslationUnit, @@ -323,6 +334,7 @@ pub const CXLinkage_Internal: ::libc::c_uint = 2; pub const CXLinkage_UniqueExternal: ::libc::c_uint = 3; pub const CXLinkage_External: ::libc::c_uint = 4; #[repr(C)] +#[deriving(Copy)] pub struct Struct_CXPlatformAvailability { pub Platform: CXString, pub Introduced: CXVersion, @@ -406,6 +418,7 @@ pub const CXCallingConv_X86_64SysV: ::libc::c_uint = 11; pub const CXCallingConv_Invalid: ::libc::c_uint = 100; pub const CXCallingConv_Unexposed: ::libc::c_uint = 200; #[repr(C)] +#[deriving(Copy)] pub struct CXType { pub kind: Enum_CXTypeKind, pub data: [*mut ::libc::c_void, ..2u], @@ -492,12 +505,14 @@ pub const CXToken_Literal: ::libc::c_uint = 3; pub const CXToken_Comment: ::libc::c_uint = 4; pub type CXTokenKind = Enum_CXTokenKind; #[repr(C)] +#[deriving(Copy)] pub struct CXToken { pub int_data: [::libc::c_uint, ..4u], pub ptr_data: *mut ::libc::c_void, } pub type CXCompletionString = *mut ::libc::c_void; #[repr(C)] +#[deriving(Copy)] pub struct CXCompletionResult { pub CursorKind: Enum_CXCursorKind, pub CompletionString: CXCompletionString, @@ -525,6 +540,7 @@ pub const CXCompletionChunk_Equal: ::libc::c_uint = 18; pub const CXCompletionChunk_HorizontalSpace: ::libc::c_uint = 19; pub const CXCompletionChunk_VerticalSpace: ::libc::c_uint = 20; #[repr(C)] +#[deriving(Copy)] pub struct CXCodeCompleteResults { pub Results: *mut CXCompletionResult, pub NumResults: ::libc::c_uint, @@ -567,6 +583,7 @@ pub type Enum_CXVisitorResult = ::libc::c_uint; pub const CXVisit_Break: ::libc::c_uint = 0; pub const CXVisit_Continue: ::libc::c_uint = 1; #[repr(C)] +#[deriving(Copy)] pub struct CXCursorAndRangeVisitor { pub context: *mut ::libc::c_void, pub visit: ::std::option::Option<extern "C" fn @@ -583,11 +600,13 @@ pub type CXIdxClientEntity = *mut ::libc::c_void; pub type CXIdxClientContainer = *mut ::libc::c_void; pub type CXIdxClientASTFile = *mut ::libc::c_void; #[repr(C)] +#[deriving(Copy)] pub struct CXIdxLoc { pub ptr_data: [*mut ::libc::c_void, ..2u], pub int_data: ::libc::c_uint, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxIncludedFileInfo { pub hashLoc: CXIdxLoc, pub filename: *const ::libc::c_char, @@ -597,6 +616,7 @@ pub struct CXIdxIncludedFileInfo { pub isModuleImport: ::libc::c_int, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxImportedASTFileInfo { pub file: CXFile, pub module: CXModule, @@ -647,12 +667,14 @@ pub const CXIdxAttr_IBAction: ::libc::c_uint = 1; pub const CXIdxAttr_IBOutlet: ::libc::c_uint = 2; pub const CXIdxAttr_IBOutletCollection: ::libc::c_uint = 3; #[repr(C)] +#[deriving(Copy)] pub struct CXIdxAttrInfo { pub kind: CXIdxAttrKind, pub cursor: CXCursor, pub loc: CXIdxLoc, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxEntityInfo { pub kind: CXIdxEntityKind, pub templateKind: CXIdxEntityCXXTemplateKind, @@ -664,10 +686,12 @@ pub struct CXIdxEntityInfo { pub numAttributes: ::libc::c_uint, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxContainerInfo { pub cursor: CXCursor, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxIBOutletCollectionAttrInfo { pub attrInfo: *const CXIdxAttrInfo, pub objcClass: *const CXIdxEntityInfo, @@ -677,6 +701,7 @@ pub struct CXIdxIBOutletCollectionAttrInfo { pub type CXIdxDeclInfoFlags = ::libc::c_uint; pub const CXIdxDeclFlag_Skipped: ::libc::c_uint = 1; #[repr(C)] +#[deriving(Copy)] pub struct CXIdxDeclInfo { pub entityInfo: *const CXIdxEntityInfo, pub cursor: CXCursor, @@ -697,34 +722,40 @@ pub const CXIdxObjCContainer_ForwardRef: ::libc::c_uint = 0; pub const CXIdxObjCContainer_Interface: ::libc::c_uint = 1; pub const CXIdxObjCContainer_Implementation: ::libc::c_uint = 2; #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCContainerDeclInfo { pub declInfo: *const CXIdxDeclInfo, pub kind: CXIdxObjCContainerKind, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxBaseClassInfo { pub base: *const CXIdxEntityInfo, pub cursor: CXCursor, pub loc: CXIdxLoc, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCProtocolRefInfo { pub protocol: *const CXIdxEntityInfo, pub cursor: CXCursor, pub loc: CXIdxLoc, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCProtocolRefListInfo { pub protocols: *const *const CXIdxObjCProtocolRefInfo, pub numProtocols: ::libc::c_uint, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCInterfaceDeclInfo { pub containerInfo: *const CXIdxObjCContainerDeclInfo, pub superInfo: *const CXIdxBaseClassInfo, pub protocols: *const CXIdxObjCProtocolRefListInfo, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCCategoryDeclInfo { pub containerInfo: *const CXIdxObjCContainerDeclInfo, pub objcClass: *const CXIdxEntityInfo, @@ -733,12 +764,14 @@ pub struct CXIdxObjCCategoryDeclInfo { pub protocols: *const CXIdxObjCProtocolRefListInfo, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxObjCPropertyDeclInfo { pub declInfo: *const CXIdxDeclInfo, pub getter: *const CXIdxEntityInfo, pub setter: *const CXIdxEntityInfo, } #[repr(C)] +#[deriving(Copy)] pub struct CXIdxCXXClassDeclInfo { pub declInfo: *const CXIdxDeclInfo, pub bases: *const *const CXIdxBaseClassInfo, @@ -748,6 +781,7 @@ pub type CXIdxEntityRefKind = ::libc::c_uint; pub const CXIdxEntityRef_Direct: ::libc::c_uint = 1; pub const CXIdxEntityRef_Implicit: ::libc::c_uint = 2; #[repr(C)] +#[deriving(Copy)] pub struct CXIdxEntityRefInfo { pub kind: CXIdxEntityRefKind, pub cursor: CXCursor, @@ -757,6 +791,7 @@ pub struct CXIdxEntityRefInfo { pub container: *const CXIdxContainerInfo, } #[repr(C)] +#[deriving(Copy)] pub struct IndexerCallbacks { pub abortQuery: ::std::option::Option<extern "C" fn (arg1: CXClientData, @@ -1,7 +1,6 @@ #![allow(unused_must_use)] use std::cell::RefCell; -use std::option; use std::iter; use std::vec::Vec; use std::rc::Rc; @@ -797,9 +796,9 @@ fn cfunc_to_rs(ctx: &mut GenCtx, name: String, rty: &Type, } fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty { - return match *ty { - TVoid => mk_ty(ctx, true, vec!("libc".to_string(), "c_void".to_string())), - TInt(i, ref layout) => match i { + return match ty { + &TVoid => mk_ty(ctx, true, vec!("libc".to_string(), "c_void".to_string())), + &TInt(i, ref layout) => match i { IBool => { let ty_name = match layout.size { 1 => "u8", @@ -821,27 +820,27 @@ fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty { ILongLong => mk_ty(ctx, true, vec!("libc".to_string(), "c_longlong".to_string())), IULongLong => mk_ty(ctx, true, vec!("libc".to_string(), "c_ulonglong".to_string())) }, - TFloat(f, _) => match f { + &TFloat(f, _) => match f { FFloat => mk_ty(ctx, true, vec!("libc".to_string(), "c_float".to_string())), FDouble => mk_ty(ctx, true, vec!("libc".to_string(), "c_double".to_string())) }, - 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) }, - TFunc(ref rty, ref atys, var, abi) => { + &TFunc(ref rty, ref atys, var, abi) => { let decl = cfuncty_to_rs(ctx, &**rty, atys.as_slice(), var); mk_fnty(ctx, &decl, 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()); if c.cstruct { @@ -850,7 +849,7 @@ fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty { mk_ty(ctx, false, vec!(union_name(c.name.clone()))) } }, - 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.clone()))) @@ -869,6 +868,7 @@ fn mk_ty(ctx: &mut GenCtx, global: bool, segments: Vec<String>) -> ast::Ty { parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: Vec::new(), types: OwnedSlice::empty(), + bindings: OwnedSlice::empty(), }), } }).collect() @@ -930,6 +930,7 @@ fn mk_fnty(ctx: &mut GenCtx, decl: &ast::FnDecl, abi: abi::Abi) -> ast::Ty { parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: Vec::new(), types: OwnedSlice::empty(), + bindings: OwnedSlice::empty(), }), }, ast::PathSegment { @@ -937,6 +938,7 @@ fn mk_fnty(ctx: &mut GenCtx, decl: &ast::FnDecl, abi: abi::Abi) -> ast::Ty { parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: Vec::new(), types: OwnedSlice::empty(), + bindings: OwnedSlice::empty(), }), }, ast::PathSegment { @@ -950,6 +952,7 @@ fn mk_fnty(ctx: &mut GenCtx, decl: &ast::FnDecl, abi: abi::Abi) -> ast::Ty { span: ctx.span }) )), + bindings: OwnedSlice::empty(), }), } ]); @@ -1,6 +1,6 @@ #![crate_name = "bindgen"] #![crate_type = "dylib"] -#![feature(globs, quote, phase, plugin_registrar, if_let)] +#![feature(globs, quote, phase, plugin_registrar)] extern crate syntax; extern crate rustc; diff --git a/src/types.rs b/src/types.rs index ad0c0faf..37312d7a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -84,35 +84,35 @@ pub enum Type { impl Type { pub fn size(&self) -> uint { - 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, - TFunc(..) => 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, + &TFunc(..) => 0, } } pub fn align(&self) -> uint { - 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, - TFunc(..) => 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, + &TFunc(..) => 0, } } } -#[deriving(Clone, PartialEq)] +#[deriving(Copy, Clone, PartialEq)] pub struct Layout { pub size: uint, pub align: uint, @@ -128,7 +128,7 @@ impl Layout { } } -#[deriving(Clone, PartialEq)] +#[deriving(Copy, Clone, PartialEq)] pub enum IKind { IBool, ISChar, @@ -143,7 +143,7 @@ pub enum IKind { IULongLong } -#[deriving(Clone, PartialEq)] +#[deriving(Copy, Clone, PartialEq)] pub enum FKind { FFloat, FDouble |