Skip to content

Commit 0a6cf08

Browse files
igeladoemilio
authored andcommitted
Add callback to modify contents of macro
1 parent 8282a90 commit 0a6cf08

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

bindgen/callbacks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub use crate::ir::analysis::DeriveTrait;
44
pub use crate::ir::derive::CanDerive as ImplementsTrait;
55
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
66
pub use crate::ir::int::IntKind;
7+
pub use cexpr::token::Kind as TokenKind;
8+
pub use cexpr::token::Token;
79
use std::fmt;
810

911
/// An enum to allow ignoring parsing of macros.
@@ -49,6 +51,10 @@ pub trait ParseCallbacks: fmt::Debug {
4951
None
5052
}
5153

54+
/// Modify the contents of a macro
55+
fn modify_macro(&self, _name: &str, _tokens: &mut Vec<Token>) {
56+
}
57+
5258
/// The integer kind an integer macro should have, given a name and the
5359
/// value of that macro, or `None` if you want the default to be chosen.
5460
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> {

bindgen/ir/var.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ fn parse_macro(
429429

430430
let cexpr_tokens = cursor.cexpr_tokens();
431431

432+
if let Some(callbacks) = ctx.parse_callbacks() {
433+
callbacks.modify_macro(cursor.spelling(), &mut cexpr_tokens);
434+
}
435+
432436
let parser = expr::IdentifierParser::new(ctx.parsed_macros());
433437

434438
match parser.macro_definition(&cexpr_tokens) {

0 commit comments

Comments
 (0)