@@ -11,14 +11,14 @@ use aster::struct_field::StructFieldBuilder;
11
11
use ir:: annotations:: FieldAccessorKind ;
12
12
use ir:: comp:: { Base , BitfieldUnit , Bitfield , CompInfo , CompKind , Field ,
13
13
FieldData , FieldMethods , Method , MethodKind } ;
14
+ use ir:: comment;
14
15
use ir:: context:: { BindgenContext , ItemId } ;
15
16
use ir:: derive:: { CanDeriveCopy , CanDeriveDebug , CanDeriveDefault } ;
16
17
use ir:: dot;
17
18
use ir:: enum_ty:: { Enum , EnumVariant , EnumVariantValue } ;
18
19
use ir:: function:: { Abi , Function , FunctionSig } ;
19
20
use ir:: int:: IntKind ;
20
- use ir:: item:: { IsOpaque , Item , ItemAncestors , ItemCanonicalName ,
21
- ItemCanonicalPath , ItemSet } ;
21
+ use ir:: item:: { IsOpaque , Item , ItemCanonicalName , ItemCanonicalPath , ItemSet } ;
22
22
use ir:: item_kind:: ItemKind ;
23
23
use ir:: layout:: Layout ;
24
24
use ir:: module:: Module ;
@@ -42,23 +42,13 @@ use syntax::ptr::P;
42
42
// Name of type defined in constified enum module
43
43
pub static CONSTIFIED_ENUM_MODULE_REPR_NAME : & ' static str = "Type" ;
44
44
45
- fn root_import_depth ( ctx : & BindgenContext , item : & Item ) -> usize {
46
- if !ctx. options ( ) . enable_cxx_namespaces {
47
- return 0 ;
48
- }
49
-
50
- item. ancestors ( ctx)
51
- . filter ( |id| ctx. resolve_item ( * id) . is_module ( ) )
52
- . fold ( 1 , |i, _| i + 1 )
53
- }
54
-
55
45
fn top_level_path ( ctx : & BindgenContext , item : & Item ) -> Vec < ast:: Ident > {
56
46
let mut path = vec ! [ ctx. rust_ident_raw( "self" ) ] ;
57
47
58
48
if ctx. options ( ) . enable_cxx_namespaces {
59
49
let super_ = ctx. rust_ident_raw ( "super" ) ;
60
50
61
- for _ in 0 ..root_import_depth ( ctx, item ) {
51
+ for _ in 0 ..item . codegen_depth ( ctx) {
62
52
path. push ( super_. clone ( ) ) ;
63
53
}
64
54
}
@@ -616,10 +606,8 @@ impl CodeGenerator for Type {
616
606
let rust_name = ctx. rust_ident ( & name) ;
617
607
let mut typedef = aster:: AstBuilder :: new ( ) . item ( ) . pub_ ( ) ;
618
608
619
- if ctx. options ( ) . generate_comments {
620
- if let Some ( comment) = item. comment ( ) {
621
- typedef = typedef. attr ( ) . doc ( comment) ;
622
- }
609
+ if let Some ( comment) = item. comment ( ctx) {
610
+ typedef = typedef. with_attr ( attributes:: doc ( comment) ) ;
623
611
}
624
612
625
613
// We prefer using `pub use` over `pub type` because of:
@@ -839,6 +827,7 @@ trait FieldCodegen<'a> {
839
827
fn codegen < F , M > ( & self ,
840
828
ctx : & BindgenContext ,
841
829
fields_should_be_private : bool ,
830
+ codegen_depth : usize ,
842
831
accessor_kind : FieldAccessorKind ,
843
832
parent : & CompInfo ,
844
833
anon_field_names : & mut AnonFieldNames ,
@@ -857,6 +846,7 @@ impl<'a> FieldCodegen<'a> for Field {
857
846
fn codegen < F , M > ( & self ,
858
847
ctx : & BindgenContext ,
859
848
fields_should_be_private : bool ,
849
+ codegen_depth : usize ,
860
850
accessor_kind : FieldAccessorKind ,
861
851
parent : & CompInfo ,
862
852
anon_field_names : & mut AnonFieldNames ,
@@ -872,6 +862,7 @@ impl<'a> FieldCodegen<'a> for Field {
872
862
Field :: DataMember ( ref data) => {
873
863
data. codegen ( ctx,
874
864
fields_should_be_private,
865
+ codegen_depth,
875
866
accessor_kind,
876
867
parent,
877
868
anon_field_names,
@@ -884,6 +875,7 @@ impl<'a> FieldCodegen<'a> for Field {
884
875
Field :: Bitfields ( ref unit) => {
885
876
unit. codegen ( ctx,
886
877
fields_should_be_private,
878
+ codegen_depth,
887
879
accessor_kind,
888
880
parent,
889
881
anon_field_names,
@@ -903,6 +895,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
903
895
fn codegen < F , M > ( & self ,
904
896
ctx : & BindgenContext ,
905
897
fields_should_be_private : bool ,
898
+ codegen_depth : usize ,
906
899
accessor_kind : FieldAccessorKind ,
907
900
parent : & CompInfo ,
908
901
anon_field_names : & mut AnonFieldNames ,
@@ -945,8 +938,9 @@ impl<'a> FieldCodegen<'a> for FieldData {
945
938
946
939
let mut attrs = vec ! [ ] ;
947
940
if ctx. options ( ) . generate_comments {
948
- if let Some ( comment) = self . comment ( ) {
949
- attrs. push ( attributes:: doc ( comment) ) ;
941
+ if let Some ( raw_comment) = self . comment ( ) {
942
+ let comment = comment:: preprocess ( raw_comment, codegen_depth + 1 ) ;
943
+ attrs. push ( attributes:: doc ( comment) )
950
944
}
951
945
}
952
946
@@ -1153,6 +1147,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1153
1147
fn codegen < F , M > ( & self ,
1154
1148
ctx : & BindgenContext ,
1155
1149
fields_should_be_private : bool ,
1150
+ codegen_depth : usize ,
1156
1151
accessor_kind : FieldAccessorKind ,
1157
1152
parent : & CompInfo ,
1158
1153
anon_field_names : & mut AnonFieldNames ,
@@ -1197,6 +1192,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1197
1192
for bf in self . bitfields ( ) {
1198
1193
bf. codegen ( ctx,
1199
1194
fields_should_be_private,
1195
+ codegen_depth,
1200
1196
accessor_kind,
1201
1197
parent,
1202
1198
anon_field_names,
@@ -1277,6 +1273,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1277
1273
fn codegen < F , M > ( & self ,
1278
1274
ctx : & BindgenContext ,
1279
1275
_fields_should_be_private : bool ,
1276
+ _codegen_depth : usize ,
1280
1277
_accessor_kind : FieldAccessorKind ,
1281
1278
parent : & CompInfo ,
1282
1279
_anon_field_names : & mut AnonFieldNames ,
@@ -1409,10 +1406,8 @@ impl CodeGenerator for CompInfo {
1409
1406
let mut attributes = vec ! [ ] ;
1410
1407
let mut needs_clone_impl = false ;
1411
1408
let mut needs_default_impl = false ;
1412
- if ctx. options ( ) . generate_comments {
1413
- if let Some ( comment) = item. comment ( ) {
1414
- attributes. push ( attributes:: doc ( comment) ) ;
1415
- }
1409
+ if let Some ( comment) = item. comment ( ctx) {
1410
+ attributes. push ( attributes:: doc ( comment) ) ;
1416
1411
}
1417
1412
if self . packed ( ) {
1418
1413
attributes. push ( attributes:: repr_list ( & [ "C" , "packed" ] ) ) ;
@@ -1545,9 +1540,11 @@ impl CodeGenerator for CompInfo {
1545
1540
1546
1541
let mut methods = vec ! [ ] ;
1547
1542
let mut anon_field_names = AnonFieldNames :: default ( ) ;
1543
+ let codegen_depth = item. codegen_depth ( ctx) ;
1548
1544
for field in self . fields ( ) {
1549
1545
field. codegen ( ctx,
1550
1546
fields_should_be_private,
1547
+ codegen_depth,
1551
1548
struct_accessor_kind,
1552
1549
self ,
1553
1550
& mut anon_field_names,
@@ -2367,10 +2364,8 @@ impl CodeGenerator for Enum {
2367
2364
builder = builder. with_attr ( attributes:: repr ( "C" ) ) ;
2368
2365
}
2369
2366
2370
- if ctx. options ( ) . generate_comments {
2371
- if let Some ( comment) = item. comment ( ) {
2372
- builder = builder. with_attr ( attributes:: doc ( comment) ) ;
2373
- }
2367
+ if let Some ( comment) = item. comment ( ctx) {
2368
+ builder = builder. with_attr ( attributes:: doc ( comment) ) ;
2374
2369
}
2375
2370
2376
2371
if !is_constified_enum {
@@ -3069,10 +3064,8 @@ impl CodeGenerator for Function {
3069
3064
3070
3065
let mut attributes = vec ! [ ] ;
3071
3066
3072
- if ctx. options ( ) . generate_comments {
3073
- if let Some ( comment) = item. comment ( ) {
3074
- attributes. push ( attributes:: doc ( comment) ) ;
3075
- }
3067
+ if let Some ( comment) = item. comment ( ctx) {
3068
+ attributes. push ( attributes:: doc ( comment) ) ;
3076
3069
}
3077
3070
3078
3071
if let Some ( mangled) = mangled_name {
0 commit comments