@@ -63,9 +63,9 @@ use syntax::ast::{DeclItem, DefId, Expr, ExprAgain, ExprBreak, ExprField};
63
63
use syntax:: ast:: { ExprClosure , ExprForLoop , ExprLoop , ExprWhile , ExprMethodCall } ;
64
64
use syntax:: ast:: { ExprPath , ExprStruct , FnDecl } ;
65
65
use syntax:: ast:: { ForeignItem , ForeignItemFn , ForeignItemStatic , Generics } ;
66
- use syntax:: ast:: { Ident , ImplItem , Item , ItemEnum , ItemFn , ItemForeignMod } ;
67
- use syntax:: ast:: { ItemImpl , ItemMac , ItemMod , ItemStatic , ItemStruct } ;
68
- use syntax:: ast:: { ItemTrait , ItemTy , LOCAL_CRATE , Local , ItemConst } ;
66
+ use syntax:: ast:: { Ident , ImplItem , Item , ItemConst , ItemEnum , ItemFn } ;
67
+ use syntax:: ast:: { ItemForeignMod , ItemImpl , ItemMac , ItemMod , ItemStatic } ;
68
+ use syntax:: ast:: { ItemStruct , ItemTrait , ItemTy , Local } ;
69
69
use syntax:: ast:: { MethodImplItem , Mod , Name , NamedField , NodeId } ;
70
70
use syntax:: ast:: { Pat , PatEnum , PatIdent , PatLit } ;
71
71
use syntax:: ast:: { PatRange , PatStruct , Path , PathListIdent , PathListMod } ;
@@ -97,6 +97,7 @@ use std::rc::{Rc, Weak};
97
97
use std:: uint;
98
98
99
99
mod check_unused;
100
+ mod record_exports;
100
101
101
102
#[ deriving( Copy ) ]
102
103
struct BindingInfo {
@@ -3708,124 +3709,6 @@ impl<'a> Resolver<'a> {
3708
3709
}
3709
3710
}
3710
3711
3711
- // Export recording
3712
- //
3713
- // This pass simply determines what all "export" keywords refer to and
3714
- // writes the results into the export map.
3715
- //
3716
- // FIXME #4953 This pass will be removed once exports change to per-item.
3717
- // Then this operation can simply be performed as part of item (or import)
3718
- // processing.
3719
-
3720
- fn record_exports ( & mut self ) {
3721
- let root_module = self . graph_root . get_module ( ) ;
3722
- self . record_exports_for_module_subtree ( root_module) ;
3723
- }
3724
-
3725
- fn record_exports_for_module_subtree ( & mut self ,
3726
- module_ : Rc < Module > ) {
3727
- // If this isn't a local krate, then bail out. We don't need to record
3728
- // exports for nonlocal crates.
3729
-
3730
- match module_. def_id . get ( ) {
3731
- Some ( def_id) if def_id. krate == LOCAL_CRATE => {
3732
- // OK. Continue.
3733
- debug ! ( "(recording exports for module subtree) recording \
3734
- exports for local module `{}`",
3735
- self . module_to_string( & * module_) ) ;
3736
- }
3737
- None => {
3738
- // Record exports for the root module.
3739
- debug ! ( "(recording exports for module subtree) recording \
3740
- exports for root module `{}`",
3741
- self . module_to_string( & * module_) ) ;
3742
- }
3743
- Some ( _) => {
3744
- // Bail out.
3745
- debug ! ( "(recording exports for module subtree) not recording \
3746
- exports for `{}`",
3747
- self . module_to_string( & * module_) ) ;
3748
- return ;
3749
- }
3750
- }
3751
-
3752
- self . record_exports_for_module ( & * module_) ;
3753
- self . populate_module_if_necessary ( & module_) ;
3754
-
3755
- for ( _, child_name_bindings) in module_. children . borrow ( ) . iter ( ) {
3756
- match child_name_bindings. get_module_if_available ( ) {
3757
- None => {
3758
- // Nothing to do.
3759
- }
3760
- Some ( child_module) => {
3761
- self . record_exports_for_module_subtree ( child_module) ;
3762
- }
3763
- }
3764
- }
3765
-
3766
- for ( _, child_module) in module_. anonymous_children . borrow ( ) . iter ( ) {
3767
- self . record_exports_for_module_subtree ( child_module. clone ( ) ) ;
3768
- }
3769
- }
3770
-
3771
- fn record_exports_for_module ( & mut self , module_ : & Module ) {
3772
- let mut exports = Vec :: new ( ) ;
3773
-
3774
- self . add_exports_for_module ( & mut exports, module_) ;
3775
- match module_. def_id . get ( ) {
3776
- Some ( def_id) => {
3777
- self . export_map . insert ( def_id. node , exports) ;
3778
- debug ! ( "(computing exports) writing exports for {} (some)" ,
3779
- def_id. node) ;
3780
- }
3781
- None => { }
3782
- }
3783
- }
3784
-
3785
- fn add_exports_of_namebindings ( & mut self ,
3786
- exports : & mut Vec < Export > ,
3787
- name : Name ,
3788
- namebindings : & NameBindings ,
3789
- ns : Namespace ) {
3790
- match namebindings. def_for_namespace ( ns) {
3791
- Some ( d) => {
3792
- debug ! ( "(computing exports) YES: export '{}' => {}" ,
3793
- name, d. def_id( ) ) ;
3794
- exports. push ( Export {
3795
- name : name,
3796
- def_id : d. def_id ( )
3797
- } ) ;
3798
- }
3799
- d_opt => {
3800
- debug ! ( "(computing exports) NO: {}" , d_opt) ;
3801
- }
3802
- }
3803
- }
3804
-
3805
- fn add_exports_for_module ( & mut self ,
3806
- exports : & mut Vec < Export > ,
3807
- module_ : & Module ) {
3808
- for ( name, importresolution) in module_. import_resolutions . borrow ( ) . iter ( ) {
3809
- if !importresolution. is_public {
3810
- continue
3811
- }
3812
- let xs = [ TypeNS , ValueNS ] ;
3813
- for & ns in xs. iter ( ) {
3814
- match importresolution. target_for_namespace ( ns) {
3815
- Some ( target) => {
3816
- debug ! ( "(computing exports) maybe export '{}'" ,
3817
- token:: get_name( * name) ) ;
3818
- self . add_exports_of_namebindings ( exports,
3819
- * name,
3820
- & * target. bindings ,
3821
- ns)
3822
- }
3823
- _ => ( )
3824
- }
3825
- }
3826
- }
3827
- }
3828
-
3829
3712
// AST resolution
3830
3713
//
3831
3714
// We maintain a list of value ribs and type ribs.
@@ -6137,7 +6020,7 @@ pub fn resolve_crate(session: &Session,
6137
6020
resolver. resolve_imports ( ) ;
6138
6021
session. abort_if_errors ( ) ;
6139
6022
6140
- resolver . record_exports ( ) ;
6023
+ record_exports:: record ( & mut resolver ) ;
6141
6024
session. abort_if_errors ( ) ;
6142
6025
6143
6026
resolver. resolve_crate ( krate) ;
0 commit comments