@@ -193,6 +193,8 @@ impl ClangSubItemParser for Var {
193
193
use clang_sys:: * ;
194
194
match cursor. kind ( ) {
195
195
CXCursor_MacroDefinition => {
196
+ let tokens: Vec < _ > = cursor. tokens ( ) . iter ( ) . collect ( ) ;
197
+
196
198
if let Some ( callbacks) = ctx. parse_callbacks ( ) {
197
199
match callbacks. will_parse_macro ( & cursor. spelling ( ) ) {
198
200
MacroParsingBehavior :: Ignore => {
@@ -201,13 +203,12 @@ impl ClangSubItemParser for Var {
201
203
MacroParsingBehavior :: Default => { }
202
204
}
203
205
204
- let tokens: Vec < _ > = cursor. tokens ( ) . iter ( ) . collect ( ) ;
205
206
handle_function_macro ( & tokens, |left, right| {
206
207
callbacks. func_macro ( left, right)
207
208
} ) ?;
208
209
}
209
210
210
- let value = parse_macro ( ctx, & cursor . cexpr_tokens ( ) ) ;
211
+ let value = parse_macro ( ctx, & tokens ) ;
211
212
212
213
let ( id, value) = match value {
213
214
Some ( v) => v,
@@ -374,7 +375,7 @@ impl ClangSubItemParser for Var {
374
375
/// Try and parse a macro using all the macros parsed until now.
375
376
fn parse_macro (
376
377
ctx : & BindgenContext ,
377
- cexpr_tokens : & [ cexpr :: token :: Token ] ,
378
+ tokens : & [ clang :: ClangToken ] ,
378
379
) -> Option < ( Vec < u8 > , cexpr:: expr:: EvalResult ) > {
379
380
use cexpr:: expr;
380
381
@@ -385,12 +386,15 @@ fn parse_macro(
385
386
// See:
386
387
// https://bugs.llvm.org//show_bug.cgi?id=9069
387
388
// https://reviews.llvm.org/D26446
388
- let cexpr_tokens = match ( cexpr_tokens. len ( ) , crate :: clang_version ( ) . parsed )
389
- {
390
- ( len, Some ( ( v, _) ) ) if len > 0 && v < 4 => & cexpr_tokens[ ..len - 1 ] ,
391
- _ => & cexpr_tokens[ ..] ,
389
+ let tokens = match ( tokens. len ( ) , crate :: clang_version ( ) . parsed ) {
390
+ ( len, Some ( ( v, _) ) ) if len > 0 && v < 4 => & tokens[ ..len - 1 ] ,
391
+ _ => & tokens[ ..] ,
392
392
} ;
393
393
394
+ let cexpr_tokens: Vec < _ > = tokens
395
+ . iter ( )
396
+ . filter_map ( |token| token. as_cexpr_token ( ) )
397
+ . collect ( ) ;
394
398
match parser. macro_definition ( & cexpr_tokens) {
395
399
Ok ( ( _, ( id, val) ) ) => Some ( ( id. into ( ) , val) ) ,
396
400
_ => None ,
0 commit comments