File tree 7 files changed +56
-1
lines changed 7 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ mod testgen {
24
24
let out_dir = Path :: new ( env ! ( "OUT_DIR" ) ) ;
25
25
let mut dst = File :: create ( Path :: new ( & out_dir) . join ( "tests.rs" ) ) . unwrap ( ) ;
26
26
27
+ println ! ( "cargo:rerun-if-changed=tests/headers" ) ;
27
28
let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
28
29
let headers_dir = manifest_dir. join ( "tests" ) . join ( "headers" ) ;
29
30
Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ pub mod ast_ty {
133
133
}
134
134
}
135
135
136
+ pub fn bool_expr ( val : bool ) -> P < ast:: Expr > {
137
+ aster:: AstBuilder :: new ( ) . expr ( ) . bool ( val)
138
+ }
139
+
136
140
pub fn byte_array_expr ( bytes : & [ u8 ] ) -> P < ast:: Expr > {
137
141
let mut vec = Vec :: with_capacity ( bytes. len ( ) + 1 ) ;
138
142
for byte in bytes {
Original file line number Diff line number Diff line change @@ -323,6 +323,10 @@ impl CodeGenerator for Var {
323
323
. const_ ( canonical_name)
324
324
. expr ( ) ;
325
325
let item = match * val {
326
+ VarType :: Bool ( val) => {
327
+ const_item. build ( helpers:: ast_ty:: bool_expr ( val) )
328
+ . build ( ty)
329
+ }
326
330
VarType :: Int ( val) => {
327
331
const_item. build ( helpers:: ast_ty:: int_expr ( val) )
328
332
. build ( ty)
Original file line number Diff line number Diff line change @@ -131,6 +131,14 @@ impl Type {
131
131
}
132
132
}
133
133
134
+ /// Is this a boolean type?
135
+ pub fn is_bool ( & self ) -> bool {
136
+ match self . kind {
137
+ TypeKind :: Int ( IntKind :: Bool ) => true ,
138
+ _ => false ,
139
+ }
140
+ }
141
+
134
142
/// Is this an integer type?
135
143
pub fn is_integer ( & self ) -> bool {
136
144
match self . kind {
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ use super::ty::{FloatKind, TypeKind};
13
13
/// The type for a constant variable.
14
14
#[ derive( Debug ) ]
15
15
pub enum VarType {
16
+ /// An boolean.
17
+ Bool ( bool ) ,
16
18
/// An integer.
17
19
Int ( i64 ) ,
18
20
/// A floating point number.
@@ -194,14 +196,18 @@ impl ClangSubItemParser for Var {
194
196
let canonical_ty = ctx. safe_resolve_type ( ty)
195
197
. and_then ( |t| t. safe_canonical_type ( ctx) ) ;
196
198
199
+ let is_bool = canonical_ty. map_or ( false , |t| t. is_bool ( ) ) ;
197
200
let is_integer = canonical_ty. map_or ( false , |t| t. is_integer ( ) ) ;
198
201
let is_float = canonical_ty. map_or ( false , |t| t. is_float ( ) ) ;
199
202
200
203
// TODO: We could handle `char` more gracefully.
201
204
// TODO: Strings, though the lookup is a bit more hard (we need
202
205
// to look at the canonical type of the pointee too, and check
203
206
// is char, u8, or i8 I guess).
204
- let value = if is_integer {
207
+ let value = if is_bool {
208
+ cursor. evaluate ( ) . as_int ( )
209
+ . map ( |val| VarType :: Bool ( val != 0 ) )
210
+ } else if is_integer {
205
211
cursor. evaluate ( )
206
212
. as_int ( )
207
213
. map ( |val| val as i64 )
Original file line number Diff line number Diff line change
1
+ /* automatically generated by rust-bindgen */
2
+
3
+
4
+ #![ allow( non_snake_case) ]
5
+
6
+
7
+ pub const k: bool = true ;
8
+ #[ repr( C ) ]
9
+ #[ derive( Debug , Copy ) ]
10
+ pub struct A {
11
+ pub _address : u8 ,
12
+ }
13
+ pub const A_k : bool = false ;
14
+ #[ test]
15
+ fn bindgen_test_layout_A ( ) {
16
+ assert_eq ! ( :: std:: mem:: size_of:: <A >( ) , 1usize ) ;
17
+ assert_eq ! ( :: std:: mem:: align_of:: <A >( ) , 1usize ) ;
18
+ }
19
+ impl Clone for A {
20
+ fn clone ( & self ) -> Self { * self }
21
+ }
22
+ pub type foo = bool ;
23
+ pub const k2: foo = true ;
Original file line number Diff line number Diff line change
1
+ // bindgen-unstable
2
+
3
+ const bool k = true ;
4
+ struct A {
5
+ static const bool k = false ;
6
+ };
7
+
8
+ typedef bool foo;
9
+ const foo k2 = true ;
You can’t perform that action at this time.
0 commit comments