Skip to content

Commit e0a0b1d

Browse files
committed
WIP: Parse macros with cexpr.
1 parent b2082bf commit e0a0b1d

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

src/clang.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1056,15 +1056,8 @@ impl TranslationUnit {
10561056
return None;
10571057
}
10581058

1059-
// The extent always includes an extra token for no good reason.
1060-
let real_count = if num_tokens > 0 {
1061-
num_tokens - 1
1062-
} else {
1063-
num_tokens
1064-
};
1065-
10661059
let token_array = slice::from_raw_parts(token_ptr,
1067-
real_count as usize);
1060+
num_tokens as usize);
10681061
for &token in token_array.iter() {
10691062
let kind = clang_getTokenKind(token);
10701063
let spelling = clang_getTokenSpelling(self.x, token).into();
@@ -1089,6 +1082,9 @@ impl TranslationUnit {
10891082
None => return None,
10901083
};
10911084

1085+
// FIXME(emilio): LLVM 3.9 at least always include an extra token for no
1086+
// good reason (except if we're at EOF). Let's try with 3.8 to see
1087+
// what's up with that.
10921088
Some(tokens.into_iter().filter_map(|token| {
10931089
let kind = match token.kind {
10941090
CXToken_Punctuation => token::Kind::Punctuation,

tests/expectations/tests/jsval_layout_opaque.rs

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
2424
fn clone(&self) -> Self { Self::new() }
2525
}
2626
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
27-
pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47;
28-
pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327;
29-
pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328;
3027
#[repr(u8)]
3128
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3229
pub enum JSValueType {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+

tests/expectations/tests/whitelist_vars.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
#![allow(non_snake_case)]
55

66

7-
pub const NONE: ::std::os::raw::c_uint = 0;
8-
pub const FOO: ::std::os::raw::c_uint = 5;
9-
pub const FOOB: ::std::os::raw::c_int = -2;
107
pub const FOOBAR: ::std::os::raw::c_int = -10;

tests/headers/macro-expr-basic.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define FOO 1
2+
#define BAR 4
3+
#define BAZ (FOO + BAR)
4+
5+
#define BARR (0 << 1)
6+
#define BAZZ (0 << 2)
7+
#define I_RAN_OUT_OF_DUMB_NAMES (BARR | BAZZ)

0 commit comments

Comments
 (0)