Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit ad79adb

Browse files
committed
Reused the import_globals function for Module<InternedStr>
1 parent 512ae12 commit ad79adb

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

renamer.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Renamer {
9494
Renamer { uniques: ScopedMap::new(), name_supply: NameSupply::new(), errors: Errors::new() }
9595
}
9696

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) {
9898
let mut names = module.dataDefinitions.iter()
9999
.flat_map(|data| data.constructors.iter().map(|ctor| ctor.name))
100100
.chain(module.newtypes.iter().map(|newtype| newtype.constructor_name))
@@ -104,34 +104,18 @@ impl Renamer {
104104
.chain(binding_groups(class.bindings).map(|binds| binds[0].name))))
105105
.chain(binding_groups(module.bindings.as_slice()).map(|binds| binds[0].name));
106106
for name in names {
107-
self.declare_global(name.name, name.uid);
107+
self.declare_global(str_fn(name), uid);
108108
}
109109
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;
111111
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);
113113
}
114114
}
115115
}
116116

117117
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);
135119
for import in module.imports.iter() {
136120
let imported_module = module_env.iter()
137121
.find(|m| m.name.name == import.module)
@@ -144,7 +128,7 @@ impl Renamer {
144128
}
145129
}
146130
None => {//Import everything
147-
self.import_globals(imported_module)
131+
self.import_globals(imported_module, |name| name.name, imported_module.name.uid)
148132
}
149133
}
150134
}

0 commit comments

Comments
 (0)