@@ -22,7 +22,7 @@ use super::ty::{FloatKind, Type, TypeKind};
22
22
use crate :: callbacks:: ParseCallbacks ;
23
23
use crate :: clang:: { self , Cursor } ;
24
24
use crate :: parse:: ClangItemParser ;
25
- use crate :: BindgenState ;
25
+ use crate :: { BindgenOptions , BindgenState } ;
26
26
use crate :: { Entry , HashMap , HashSet } ;
27
27
use cexpr;
28
28
use clang_sys;
@@ -371,7 +371,9 @@ pub struct BindgenContext {
371
371
target_info : clang:: TargetInfo ,
372
372
373
373
/// The options given by the user via cli or other medium.
374
- options : BindgenState ,
374
+ options : BindgenOptions ,
375
+
376
+ state : BindgenState ,
375
377
376
378
/// Whether a bindgen complex was generated
377
379
generated_bindgen_complex : Cell < bool > ,
@@ -505,7 +507,7 @@ impl<'ctx> AllowlistedItemsTraversal<'ctx> {
505
507
506
508
impl BindgenContext {
507
509
/// Construct the context for the given `options`.
508
- pub ( crate ) fn new ( options : BindgenState ) -> Self {
510
+ pub ( crate ) fn new ( state : BindgenState , options : BindgenOptions ) -> Self {
509
511
// TODO(emilio): Use the CXTargetInfo here when available.
510
512
//
511
513
// see: https://reviews.llvm.org/D32389
@@ -522,7 +524,7 @@ impl BindgenContext {
522
524
& index,
523
525
"" ,
524
526
& options. clang_args ,
525
- & options . input_unsaved_files ,
527
+ & state . input_unsaved_files ,
526
528
parse_options,
527
529
) . expect ( "libclang error; possible causes include:
528
530
- Invalid flag syntax
@@ -561,6 +563,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
561
563
translation_unit,
562
564
target_info,
563
565
options,
566
+ state,
564
567
generated_bindgen_complex : Cell :: new ( false ) ,
565
568
allowlisted : None ,
566
569
blocklisted_types_implement_traits : Default :: default ( ) ,
@@ -622,7 +625,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
622
625
623
626
/// Get the user-provided callbacks by reference, if any.
624
627
pub fn parse_callbacks ( & self ) -> Option < & dyn ParseCallbacks > {
625
- self . options ( ) . parse_callbacks . as_deref ( )
628
+ self . state ( ) . parse_callbacks . as_deref ( )
626
629
}
627
630
628
631
/// Add another path to the set of included files.
@@ -1136,7 +1139,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
1136
1139
pub ( crate ) fn gen < F , Out > (
1137
1140
mut self ,
1138
1141
cb : F ,
1139
- ) -> ( Out , BindgenState , Vec < String > )
1142
+ ) -> ( Out , BindgenOptions , Vec < String > )
1140
1143
where
1141
1144
F : FnOnce ( & Self ) -> Out ,
1142
1145
{
@@ -2077,14 +2080,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2077
2080
self . in_codegen_phase( ) ,
2078
2081
"You're not supposed to call this yet"
2079
2082
) ;
2080
- self . options . opaque_types . matches ( & path[ 1 ..] . join ( "::" ) )
2083
+ self . state . opaque_types . matches ( & path[ 1 ..] . join ( "::" ) )
2081
2084
}
2082
2085
2083
2086
/// Get the options used to configure this bindgen context.
2084
- pub ( crate ) fn options ( & self ) -> & BindgenState {
2087
+ pub ( crate ) fn options ( & self ) -> & BindgenOptions {
2085
2088
& self . options
2086
2089
}
2087
2090
2091
+ pub ( crate ) fn state ( & self ) -> & BindgenState {
2092
+ & self . state
2093
+ }
2094
+
2088
2095
/// Tokenizes a namespace cursor in order to get the name and kind of the
2089
2096
/// namespace.
2090
2097
fn tokenize_namespace (
@@ -2242,7 +2249,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2242
2249
. or_insert_with ( || {
2243
2250
item. expect_type ( )
2244
2251
. name ( )
2245
- . and_then ( |name| match self . options . parse_callbacks {
2252
+ . and_then ( |name| match self . state . parse_callbacks {
2246
2253
Some ( ref cb) => cb. blocklisted_type_implements_trait (
2247
2254
name,
2248
2255
derive_trait,
@@ -2311,7 +2318,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2311
2318
let ( file, _, _, _) = location. location ( ) ;
2312
2319
if let Some ( filename) = file. name ( ) {
2313
2320
if self
2314
- . options ( )
2321
+ . state ( )
2315
2322
. allowlisted_files
2316
2323
. matches ( & filename)
2317
2324
{
@@ -2326,13 +2333,13 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2326
2333
match * item. kind ( ) {
2327
2334
ItemKind :: Module ( ..) => true ,
2328
2335
ItemKind :: Function ( _) => {
2329
- self . options ( ) . allowlisted_functions . matches ( & name)
2336
+ self . state ( ) . allowlisted_functions . matches ( & name)
2330
2337
}
2331
2338
ItemKind :: Var ( _) => {
2332
- self . options ( ) . allowlisted_vars . matches ( & name)
2339
+ self . state ( ) . allowlisted_vars . matches ( & name)
2333
2340
}
2334
2341
ItemKind :: Type ( ref ty) => {
2335
- if self . options ( ) . allowlisted_types . matches ( & name) {
2342
+ if self . state ( ) . allowlisted_types . matches ( & name) {
2336
2343
return true ;
2337
2344
}
2338
2345
@@ -2385,7 +2392,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2385
2392
) ;
2386
2393
let name = prefix_path[ 1 ..] . join ( "::" ) ;
2387
2394
prefix_path. pop ( ) . unwrap ( ) ;
2388
- self . options ( ) . allowlisted_vars . matches ( & name)
2395
+ self . state ( ) . allowlisted_vars . matches ( & name)
2389
2396
} )
2390
2397
}
2391
2398
}
@@ -2434,16 +2441,28 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2434
2441
2435
2442
let mut warnings = Vec :: new ( ) ;
2436
2443
2437
- for item in self . options ( ) . allowlisted_functions . unmatched_items ( ) {
2444
+ for item in self
2445
+ . state ( )
2446
+ . allowlisted_functions
2447
+ . unmatched_items ( & self . options ( ) . allowlisted_functions )
2448
+ {
2438
2449
warnings
2439
2450
. push ( format ! ( "unused option: --allowlist-function {}" , item) ) ;
2440
2451
}
2441
2452
2442
- for item in self . options ( ) . allowlisted_vars . unmatched_items ( ) {
2453
+ for item in self
2454
+ . state ( )
2455
+ . allowlisted_vars
2456
+ . unmatched_items ( & self . options ( ) . allowlisted_vars )
2457
+ {
2443
2458
warnings. push ( format ! ( "unused option: --allowlist-var {}" , item) ) ;
2444
2459
}
2445
2460
2446
- for item in self . options ( ) . allowlisted_types . unmatched_items ( ) {
2461
+ for item in self
2462
+ . state ( )
2463
+ . allowlisted_types
2464
+ . unmatched_items ( & self . options ( ) . allowlisted_types )
2465
+ {
2447
2466
warnings. push ( format ! ( "unused option: --allowlist-type {}" , item) ) ;
2448
2467
}
2449
2468
@@ -2667,37 +2686,37 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2667
2686
/// Check if `--no-partialeq` flag is enabled for this item.
2668
2687
pub fn no_partialeq_by_name ( & self , item : & Item ) -> bool {
2669
2688
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2670
- self . options ( ) . no_partialeq_types . matches ( & name)
2689
+ self . state ( ) . no_partialeq_types . matches ( & name)
2671
2690
}
2672
2691
2673
2692
/// Check if `--no-copy` flag is enabled for this item.
2674
2693
pub fn no_copy_by_name ( & self , item : & Item ) -> bool {
2675
2694
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2676
- self . options ( ) . no_copy_types . matches ( & name)
2695
+ self . state ( ) . no_copy_types . matches ( & name)
2677
2696
}
2678
2697
2679
2698
/// Check if `--no-debug` flag is enabled for this item.
2680
2699
pub fn no_debug_by_name ( & self , item : & Item ) -> bool {
2681
2700
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2682
- self . options ( ) . no_debug_types . matches ( & name)
2701
+ self . state ( ) . no_debug_types . matches ( & name)
2683
2702
}
2684
2703
2685
2704
/// Check if `--no-default` flag is enabled for this item.
2686
2705
pub fn no_default_by_name ( & self , item : & Item ) -> bool {
2687
2706
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2688
- self . options ( ) . no_default_types . matches ( & name)
2707
+ self . state ( ) . no_default_types . matches ( & name)
2689
2708
}
2690
2709
2691
2710
/// Check if `--no-hash` flag is enabled for this item.
2692
2711
pub fn no_hash_by_name ( & self , item : & Item ) -> bool {
2693
2712
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2694
- self . options ( ) . no_hash_types . matches ( & name)
2713
+ self . state ( ) . no_hash_types . matches ( & name)
2695
2714
}
2696
2715
2697
2716
/// Check if `--must-use-type` flag is enabled for this item.
2698
2717
pub fn must_use_type_by_name ( & self , item : & Item ) -> bool {
2699
2718
let name = item. path_for_allowlisting ( self ) [ 1 ..] . join ( "::" ) ;
2700
- self . options ( ) . must_use_types . matches ( & name)
2719
+ self . state ( ) . must_use_types . matches ( & name)
2701
2720
}
2702
2721
}
2703
2722
0 commit comments