diff options
author | Xidorn Quan <me@upsuper.org> | 2016-12-09 15:28:58 -1000 |
---|---|---|
committer | Xidorn Quan <me@upsuper.org> | 2016-12-09 15:42:13 -1000 |
commit | 544e913980baf582bb9d4df0ddb03140feb26159 (patch) | |
tree | f053bdaeebef7c78c0f299c6b4b52fb2e7a96400 /libbindgen/src | |
parent | 452319f22008bf822f4fe7e48c6c2bfb36e09924 (diff) |
Remove macro_rules in codegen
Diffstat (limited to 'libbindgen/src')
-rw-r--r-- | libbindgen/src/codegen/helpers.rs | 9 | ||||
-rw-r--r-- | libbindgen/src/codegen/mod.rs | 60 |
2 files changed, 27 insertions, 42 deletions
diff --git a/libbindgen/src/codegen/helpers.rs b/libbindgen/src/codegen/helpers.rs index 7284ab80..f1a0f314 100644 --- a/libbindgen/src/codegen/helpers.rs +++ b/libbindgen/src/codegen/helpers.rs @@ -93,11 +93,6 @@ pub mod ast_ty { pub fn float_kind_rust_type(ctx: &BindgenContext, fk: FloatKind) -> P<ast::Ty> { - macro_rules! raw { - ($ty: ident) => { - raw_type(ctx, stringify!($ty)) - } - } // TODO: we probably should just take the type layout into // account? // @@ -109,9 +104,9 @@ pub mod ast_ty { (FloatKind::Float, true) => aster::ty::TyBuilder::new().f32(), (FloatKind::Double, true) | (FloatKind::LongDouble, true) => aster::ty::TyBuilder::new().f64(), - (FloatKind::Float, false) => raw!(c_float), + (FloatKind::Float, false) => raw_type(ctx, "c_float"), (FloatKind::Double, false) | - (FloatKind::LongDouble, false) => raw!(c_double), + (FloatKind::LongDouble, false) => raw_type(ctx, "c_double"), (FloatKind::Float128, _) => { aster::ty::TyBuilder::new().array(16).u8() } diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index a88e7d73..31946964 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -1723,29 +1723,24 @@ impl ToRustTy for Type { fn to_rust_ty(&self, ctx: &BindgenContext, item: &Item) -> P<ast::Ty> { use self::helpers::ast_ty::*; - macro_rules! raw { - ($ty: ident) => { - raw_type(ctx, stringify!($ty)) - } - } match *self.kind() { - TypeKind::Void => raw!(c_void), + TypeKind::Void => raw_type(ctx, "c_void"), // TODO: we should do something smart with nullptr, or maybe *const // c_void is enough? - TypeKind::NullPtr => raw!(c_void).to_ptr(true, ctx.span()), + TypeKind::NullPtr => raw_type(ctx, "c_void").to_ptr(true, ctx.span()), TypeKind::Int(ik) => { match ik { IntKind::Bool => aster::ty::TyBuilder::new().bool(), - IntKind::Char => raw!(c_char), - IntKind::UChar => raw!(c_uchar), - IntKind::Short => raw!(c_short), - IntKind::UShort => raw!(c_ushort), - IntKind::Int => raw!(c_int), - IntKind::UInt => raw!(c_uint), - IntKind::Long => raw!(c_long), - IntKind::ULong => raw!(c_ulong), - IntKind::LongLong => raw!(c_longlong), - IntKind::ULongLong => raw!(c_ulonglong), + IntKind::Char => raw_type(ctx, "c_char"), + IntKind::UChar => raw_type(ctx, "c_uchar"), + IntKind::Short => raw_type(ctx, "c_short"), + IntKind::UShort => raw_type(ctx, "c_ushort"), + IntKind::Int => raw_type(ctx, "c_int"), + IntKind::UInt => raw_type(ctx, "c_uint"), + IntKind::Long => raw_type(ctx, "c_long"), + IntKind::ULong => raw_type(ctx, "c_ulong"), + IntKind::LongLong => raw_type(ctx, "c_longlong"), + IntKind::ULongLong => raw_type(ctx, "c_ulonglong"), IntKind::I8 => aster::ty::TyBuilder::new().i8(), IntKind::U8 => aster::ty::TyBuilder::new().u8(), @@ -1843,7 +1838,7 @@ impl ToRustTy for Type { utils::build_templated_path(item, ctx, false) } TypeKind::BlockPointer => { - let void = raw!(c_void); + let void = raw_type(ctx, "c_void"); void.to_ptr(/* is_const = */ false, ctx.span()) @@ -2204,24 +2199,19 @@ mod utils { -> Option<P<ast::Ty>> { // FIXME: We could use the inner item to check this is really a // primitive type but, who the heck overrides these anyway? - macro_rules! ty { - ($which:ident) => {{ - primitive_ty(ctx, stringify!($which)) - }} - } Some(match name { - "int8_t" => ty!(i8), - "uint8_t" => ty!(u8), - "int16_t" => ty!(i16), - "uint16_t" => ty!(u16), - "int32_t" => ty!(i32), - "uint32_t" => ty!(u32), - "int64_t" => ty!(i64), - "uint64_t" => ty!(u64), - - "uintptr_t" | "size_t" => ty!(usize), - - "intptr_t" | "ptrdiff_t" | "ssize_t" => ty!(isize), + "int8_t" => primitive_ty(ctx, "i8"), + "uint8_t" => primitive_ty(ctx, "u8"), + "int16_t" => primitive_ty(ctx, "i16"), + "uint16_t" => primitive_ty(ctx, "u16"), + "int32_t" => primitive_ty(ctx, "i32"), + "uint32_t" => primitive_ty(ctx, "u32"), + "int64_t" => primitive_ty(ctx, "i64"), + "uint64_t" => primitive_ty(ctx, "u64"), + + "uintptr_t" | "size_t" => primitive_ty(ctx, "usize"), + + "intptr_t" | "ptrdiff_t" | "ssize_t" => primitive_ty(ctx, "isize"), _ => return None, }) } |