@@ -42,7 +42,7 @@ use syntax::codemap::Spanned;
42
42
use syntax_pos:: * ;
43
43
44
44
use { escape, generated_code, lower_attributes, PathCollector , SaveContext } ;
45
- use json_dumper:: { DumpOutput , JsonDumper } ;
45
+ use json_dumper:: { Access , DumpOutput , JsonDumper } ;
46
46
use span_utils:: SpanUtils ;
47
47
use sig;
48
48
@@ -59,6 +59,15 @@ macro_rules! down_cast_data {
59
59
} ;
60
60
}
61
61
62
+ macro_rules! access_from {
63
+ ( $save_ctxt: expr, $item: expr) => {
64
+ Access {
65
+ public: $item. vis == ast:: Visibility :: Public ,
66
+ reachable: $save_ctxt. analysis. access_levels. is_reachable( $item. id) ,
67
+ }
68
+ }
69
+ }
70
+
62
71
pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput + ' ll > {
63
72
save_ctxt : SaveContext < ' l , ' tcx > ,
64
73
tcx : TyCtxt < ' l , ' tcx , ' tcx > ,
@@ -341,7 +350,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
341
350
let span = self . span_from_span ( sub_span. expect ( "No span found for variable" ) ) ;
342
351
343
352
self . dumper . dump_def (
344
- false ,
353
+ & Access {
354
+ public : false ,
355
+ reachable : false ,
356
+ } ,
345
357
Def {
346
358
kind : DefKind :: Local ,
347
359
id,
@@ -387,8 +399,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
387
399
388
400
method_data. value = sig_str;
389
401
method_data. sig = sig:: method_signature ( id, name, generics, sig, & self . save_ctxt ) ;
390
- self . dumper
391
- . dump_def ( vis == ast:: Visibility :: Public , method_data) ;
402
+ self . dumper . dump_def (
403
+ & Access {
404
+ public : vis == ast:: Visibility :: Public ,
405
+ reachable : self . save_ctxt . analysis . access_levels . is_reachable ( id) ,
406
+ } ,
407
+ method_data) ;
392
408
}
393
409
394
410
// walk arg and return types
@@ -409,8 +425,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
409
425
fn process_struct_field_def ( & mut self , field : & ast:: StructField , parent_id : NodeId ) {
410
426
let field_data = self . save_ctxt . get_field_data ( field, parent_id) ;
411
427
if let Some ( field_data) = field_data {
412
- self . dumper
413
- . dump_def ( field. vis == ast:: Visibility :: Public , field_data) ;
428
+ self . dumper . dump_def ( & access_from ! ( self . save_ctxt, field) , field_data) ;
414
429
}
415
430
}
416
431
@@ -432,7 +447,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
432
447
let span = self . span_from_span ( param_ss) ;
433
448
434
449
self . dumper . dump_def (
435
- false ,
450
+ & Access {
451
+ public : false ,
452
+ reachable : false ,
453
+ } ,
436
454
Def {
437
455
kind : DefKind :: Type ,
438
456
id,
@@ -467,8 +485,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
467
485
|v| v. process_formals ( & decl. inputs , & fn_data. qualname ) ,
468
486
) ;
469
487
self . process_generic_params ( ty_params, item. span , & fn_data. qualname , item. id ) ;
470
- self . dumper
471
- . dump_def ( item. vis == ast:: Visibility :: Public , fn_data) ;
488
+ self . dumper . dump_def ( & access_from ! ( self . save_ctxt, item) , fn_data) ;
472
489
}
473
490
474
491
for arg in & decl. inputs {
@@ -491,8 +508,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
491
508
self . nest_tables ( item. id , |v| {
492
509
if let Some ( var_data) = v. save_ctxt . get_item_data ( item) {
493
510
down_cast_data ! ( var_data, DefData , item. span) ;
494
- v. dumper
495
- . dump_def ( item. vis == ast:: Visibility :: Public , var_data) ;
511
+ v. dumper . dump_def ( & access_from ! ( v. save_ctxt, item) , var_data) ;
496
512
}
497
513
v. visit_ty ( & typ) ;
498
514
v. visit_expr ( expr) ;
@@ -516,14 +532,16 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
516
532
517
533
if !self . span . filter_generated ( sub_span, span) {
518
534
let sig = sig:: assoc_const_signature ( id, name, typ, expr, & self . save_ctxt ) ;
519
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
520
535
let span = self . span_from_span ( sub_span. expect ( "No span found for variable" ) ) ;
521
536
522
537
self . dumper . dump_def (
523
- vis == ast:: Visibility :: Public ,
538
+ & Access {
539
+ public : vis == ast:: Visibility :: Public ,
540
+ reachable : self . save_ctxt . analysis . access_levels . is_reachable ( id) ,
541
+ } ,
524
542
Def {
525
543
kind : DefKind :: Const ,
526
- id,
544
+ id : :: id_from_node_id ( id , & self . save_ctxt ) ,
527
545
span,
528
546
name : name. to_string ( ) ,
529
547
qualname,
@@ -596,7 +614,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
596
614
if !self . span . filter_generated ( sub_span, item. span ) {
597
615
let span = self . span_from_span ( sub_span. expect ( "No span found for struct" ) ) ;
598
616
self . dumper . dump_def (
599
- item . vis == ast :: Visibility :: Public ,
617
+ & access_from ! ( self . save_ctxt , item ) ,
600
618
Def {
601
619
kind,
602
620
id : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
@@ -635,6 +653,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
635
653
} ;
636
654
down_cast_data ! ( enum_data, DefData , item. span) ;
637
655
656
+ let access = access_from ! ( self . save_ctxt, item) ;
657
+
638
658
for variant in & enum_definition. variants {
639
659
let name = variant. node . name . name . to_string ( ) ;
640
660
let mut qualname = enum_data. qualname . clone ( ) ;
@@ -660,7 +680,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
660
680
let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
661
681
662
682
self . dumper . dump_def (
663
- item . vis == ast :: Visibility :: Public ,
683
+ & access ,
664
684
Def {
665
685
kind : DefKind :: StructVariant ,
666
686
id,
@@ -700,7 +720,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
700
720
let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
701
721
702
722
self . dumper . dump_def (
703
- item . vis == ast :: Visibility :: Public ,
723
+ & access ,
704
724
Def {
705
725
kind : DefKind :: TupleVariant ,
706
726
id,
@@ -730,8 +750,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
730
750
}
731
751
}
732
752
self . process_generic_params ( ty_params, item. span , & enum_data. qualname , item. id ) ;
733
- self . dumper
734
- . dump_def ( item. vis == ast:: Visibility :: Public , enum_data) ;
753
+ self . dumper . dump_def ( & access, enum_data) ;
735
754
}
736
755
737
756
fn process_impl (
@@ -783,7 +802,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
783
802
. map ( |i| :: id_from_node_id ( i. id , & self . save_ctxt ) )
784
803
. collect ( ) ;
785
804
self . dumper . dump_def (
786
- item . vis == ast :: Visibility :: Public ,
805
+ & access_from ! ( self . save_ctxt , item ) ,
787
806
Def {
788
807
kind : DefKind :: Trait ,
789
808
id,
@@ -846,8 +865,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
846
865
fn process_mod ( & mut self , item : & ast:: Item ) {
847
866
if let Some ( mod_data) = self . save_ctxt . get_item_data ( item) {
848
867
down_cast_data ! ( mod_data, DefData , item. span) ;
849
- self . dumper
850
- . dump_def ( item. vis == ast:: Visibility :: Public , mod_data) ;
868
+ self . dumper . dump_def ( & access_from ! ( self . save_ctxt, item) , mod_data) ;
851
869
}
852
870
}
853
871
@@ -1038,7 +1056,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1038
1056
let span = self . span_from_span ( sub_span. expect ( "No span found for variable" ) ) ;
1039
1057
1040
1058
self . dumper . dump_def (
1041
- false ,
1059
+ & Access {
1060
+ public : false ,
1061
+ reachable : false ,
1062
+ } ,
1042
1063
Def {
1043
1064
kind : DefKind :: Local ,
1044
1065
id,
@@ -1138,7 +1159,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1138
1159
let id = :: id_from_node_id ( trait_item. id , & self . save_ctxt ) ;
1139
1160
1140
1161
self . dumper . dump_def (
1141
- true ,
1162
+ & Access {
1163
+ public : true ,
1164
+ reachable : true ,
1165
+ } ,
1142
1166
Def {
1143
1167
kind : DefKind :: Type ,
1144
1168
id,
@@ -1225,7 +1249,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1225
1249
let span = self . span_from_span ( span) ;
1226
1250
1227
1251
self . dumper . dump_def (
1228
- true ,
1252
+ & Access {
1253
+ public : true ,
1254
+ reachable : true ,
1255
+ } ,
1229
1256
Def {
1230
1257
kind : DefKind :: Mod ,
1231
1258
id : data_id,
@@ -1249,6 +1276,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1249
1276
self . process_macro_use ( item. span ) ;
1250
1277
match item. node {
1251
1278
Use ( ref use_item) => {
1279
+ let access = access_from ! ( self . save_ctxt, item) ;
1280
+
1252
1281
match use_item. node {
1253
1282
ast:: ViewPathSimple ( ident, ref path) => {
1254
1283
let sub_span = self . span . span_for_last_ident ( path. span ) ;
@@ -1273,7 +1302,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1273
1302
let span =
1274
1303
self . span_from_span ( sub_span. expect ( "No span found for use" ) ) ;
1275
1304
self . dumper . import (
1276
- item . vis == ast :: Visibility :: Public ,
1305
+ & access ,
1277
1306
Import {
1278
1307
kind : ImportKind :: Use ,
1279
1308
ref_id : mod_id. map ( |id| :: id_from_def_id ( id) ) ,
@@ -1302,7 +1331,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1302
1331
let span =
1303
1332
self . span_from_span ( sub_span. expect ( "No span found for use glob" ) ) ;
1304
1333
self . dumper . import (
1305
- item . vis == ast :: Visibility :: Public ,
1334
+ & access ,
1306
1335
Import {
1307
1336
kind : ImportKind :: GlobUse ,
1308
1337
ref_id : None ,
@@ -1334,7 +1363,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1334
1363
let span =
1335
1364
self . span_from_span ( alias_span. expect ( "No span found for extern crate" ) ) ;
1336
1365
self . dumper . import (
1337
- false ,
1366
+ & Access {
1367
+ public : false ,
1368
+ reachable : false ,
1369
+ } ,
1338
1370
Import {
1339
1371
kind : ImportKind :: ExternCrate ,
1340
1372
ref_id : None ,
@@ -1373,7 +1405,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1373
1405
let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
1374
1406
1375
1407
self . dumper . dump_def (
1376
- item . vis == ast :: Visibility :: Public ,
1408
+ & access_from ! ( self . save_ctxt , item ) ,
1377
1409
Def {
1378
1410
kind : DefKind :: Type ,
1379
1411
id,
@@ -1596,7 +1628,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1596
1628
let span = self . span_from_span ( sp) ;
1597
1629
1598
1630
self . dumper . dump_def (
1599
- false ,
1631
+ & Access {
1632
+ public : false ,
1633
+ reachable : false ,
1634
+ } ,
1600
1635
Def {
1601
1636
kind : DefKind :: Local ,
1602
1637
id,
@@ -1662,6 +1697,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1662
1697
}
1663
1698
1664
1699
fn visit_foreign_item ( & mut self , item : & ' l ast:: ForeignItem ) {
1700
+ let access = access_from ! ( self . save_ctxt, item) ;
1701
+
1665
1702
match item. node {
1666
1703
ast:: ForeignItemKind :: Fn ( ref decl, ref generics) => {
1667
1704
if let Some ( fn_data) = self . save_ctxt . get_extern_item_data ( item) {
@@ -1672,8 +1709,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1672
1709
|v| v. process_formals ( & decl. inputs , & fn_data. qualname ) ,
1673
1710
) ;
1674
1711
self . process_generic_params ( generics, item. span , & fn_data. qualname , item. id ) ;
1675
- self . dumper
1676
- . dump_def ( item. vis == ast:: Visibility :: Public , fn_data) ;
1712
+ self . dumper . dump_def ( & access, fn_data) ;
1677
1713
}
1678
1714
1679
1715
for arg in & decl. inputs {
@@ -1687,17 +1723,15 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1687
1723
ast:: ForeignItemKind :: Static ( ref ty, _) => {
1688
1724
if let Some ( var_data) = self . save_ctxt . get_extern_item_data ( item) {
1689
1725
down_cast_data ! ( var_data, DefData , item. span) ;
1690
- self . dumper
1691
- . dump_def ( item. vis == ast:: Visibility :: Public , var_data) ;
1726
+ self . dumper . dump_def ( & access, var_data) ;
1692
1727
}
1693
1728
1694
1729
self . visit_ty ( ty) ;
1695
1730
}
1696
1731
ast:: ForeignItemKind :: Ty => {
1697
1732
if let Some ( var_data) = self . save_ctxt . get_extern_item_data ( item) {
1698
1733
down_cast_data ! ( var_data, DefData , item. span) ;
1699
- self . dumper
1700
- . dump_def ( item. vis == ast:: Visibility :: Public , var_data) ;
1734
+ self . dumper . dump_def ( & access, var_data) ;
1701
1735
}
1702
1736
}
1703
1737
}
0 commit comments