@@ -94,7 +94,7 @@ impl Renamer {
94
94
Renamer { uniques : ScopedMap :: new ( ) , name_supply : NameSupply :: new ( ) , errors : Errors :: new ( ) }
95
95
}
96
96
97
- fn import_globals ( & mut self , module : & Module < Name > ) {
97
+ fn import_globals < T : Eq + Copy > ( & mut self , module : & Module < T > , str_fn : | T | -> InternedStr , uid : uint ) {
98
98
let mut names = module. dataDefinitions . iter ( )
99
99
. flat_map ( |data| data. constructors . iter ( ) . map ( |ctor| ctor. name ) )
100
100
. chain ( module. newtypes . iter ( ) . map ( |newtype| newtype. constructor_name ) )
@@ -104,34 +104,18 @@ impl Renamer {
104
104
. chain ( binding_groups ( class. bindings ) . map ( |binds| binds[ 0 ] . name ) ) ) )
105
105
. chain ( binding_groups ( module. bindings . as_slice ( ) ) . map ( |binds| binds[ 0 ] . name ) ) ;
106
106
for name in names {
107
- self . declare_global ( name. name , name . uid ) ;
107
+ self . declare_global ( str_fn ( name) , uid) ;
108
108
}
109
109
for instance in module. instances . iter ( ) {
110
- let class_uid = self . get_name ( instance. classname . name ) . uid ;
110
+ let class_uid = self . get_name ( str_fn ( instance. classname ) ) . uid ;
111
111
for binds in binding_groups ( instance. bindings . as_slice ( ) ) {
112
- self . declare_global ( binds[ 0 ] . name . name , class_uid) ;
112
+ self . declare_global ( str_fn ( binds[ 0 ] . name ) , class_uid) ;
113
113
}
114
114
}
115
115
}
116
116
117
117
fn insert_globals ( & mut self , module_env : & [ Module < Name > ] , module : & Module < InternedStr > , uid : uint ) {
118
- let mut names = module. dataDefinitions . iter ( )
119
- . flat_map ( |data| data. constructors . iter ( ) . map ( |ctor| ctor. name ) )
120
- . chain ( module. newtypes . iter ( ) . map ( |newtype| newtype. constructor_name ) )
121
- . chain ( module. classes . iter ( ) . flat_map ( |class|
122
- Some ( class. name ) . move_iter ( )
123
- . chain ( class. declarations . iter ( ) . map ( |decl| decl. name ) )
124
- . chain ( binding_groups ( class. bindings ) . map ( |binds| binds[ 0 ] . name ) ) ) )
125
- . chain ( binding_groups ( module. bindings . as_slice ( ) ) . map ( |binds| binds[ 0 ] . name ) ) ;
126
- for name in names {
127
- self . declare_global ( name, uid) ;
128
- }
129
- for instance in module. instances . iter ( ) {
130
- let class_uid = self . get_name ( instance. classname ) . uid ;
131
- for binds in binding_groups ( instance. bindings . as_slice ( ) ) {
132
- self . declare_global ( binds[ 0 ] . name , class_uid) ;
133
- }
134
- }
118
+ self . import_globals ( module, |name| name, uid) ;
135
119
for import in module. imports . iter ( ) {
136
120
let imported_module = module_env. iter ( )
137
121
. find ( |m| m. name . name == import. module )
@@ -144,7 +128,7 @@ impl Renamer {
144
128
}
145
129
}
146
130
None => { //Import everything
147
- self . import_globals ( imported_module)
131
+ self . import_globals ( imported_module, |name| name . name , imported_module . name . uid )
148
132
}
149
133
}
150
134
}
0 commit comments