File tree Expand file tree Collapse file tree 6 files changed +47
-0
lines changed Expand file tree Collapse file tree 6 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ impl ParseCallbacks for MacroCallback {
2323
2424 MacroParsingBehavior :: Default
2525 }
26+
27+ fn item_name ( & self , original_item_name : & str ) -> Option < String > {
28+ if original_item_name. starts_with ( "my_prefixed_" ) {
29+ Some ( original_item_name. trim_start_matches ( "my_prefixed_" ) . to_string ( ) )
30+ } else if original_item_name. starts_with ( "MY_PREFIXED_" ) {
31+ Some ( original_item_name. trim_start_matches ( "MY_PREFIXED_" ) . to_string ( ) )
32+ } else {
33+ None
34+ }
35+ }
2636}
2737
2838fn main ( ) {
Original file line number Diff line number Diff line change @@ -131,3 +131,7 @@ Seventh::assert(bool first,
131131};
132132
133133} // namespace bitfields
134+
135+ int my_prefixed_function_name () {
136+ return 4 ;
137+ }
Original file line number Diff line number Diff line change @@ -178,3 +178,16 @@ struct AutoRestoreBool {
178178struct WithWChar {
179179 wchar_t foo[30 ];
180180};
181+
182+ // The names of the following items are unprefixed by the parse callbacks.
183+ const int MY_PREFIXED_CONST_VALUE = 3 ;
184+
185+ int my_prefixed_function_name ();
186+
187+ struct my_prefixed_bar {
188+ int foo;
189+ };
190+
191+ struct my_prefixed_foo {
192+ my_prefixed_bar member;
193+ };
Original file line number Diff line number Diff line change @@ -282,3 +282,13 @@ fn test_virtual_dtor() {
282282 assert_eq ! ( bindings:: VirtualDestructor_sDestructorCount , 1 ) ;
283283 }
284284}
285+
286+ #[ test]
287+ fn test_item_rename ( ) {
288+ assert_eq ! ( bindings:: CONST_VALUE , 3 ) ;
289+ assert_eq ! ( unsafe { bindings:: function_name( ) } , 4 ) ;
290+
291+ let _foo = bindings:: foo {
292+ member : bindings:: bar { foo : 2 }
293+ } ;
294+ }
Original file line number Diff line number Diff line change @@ -55,4 +55,9 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe {
5555 ) -> Option < String > {
5656 None
5757 }
58+
59+ /// Allows to rename an item, replacing `_original_item_name`.
60+ fn item_name ( & self , _original_item_name : & str ) -> Option < String > {
61+ None
62+ }
5863}
Original file line number Diff line number Diff line change @@ -875,6 +875,11 @@ impl Item {
875875
876876 let name = names. join ( "_" ) ;
877877
878+ let name = ctx
879+ . parse_callbacks ( )
880+ . and_then ( |callbacks| callbacks. item_name ( & name) )
881+ . unwrap_or ( name) ;
882+
878883 ctx. rust_mangle ( & name) . into_owned ( )
879884 }
880885
You can’t perform that action at this time.
0 commit comments