-
Notifications
You must be signed in to change notification settings - Fork 2
Synthesizing names
icefapper edited this page Feb 10, 2017
·
10 revisions
- Synthesizing begins when the whole source is parsed, to avoid things like below:
var l; // emitName=self:l
{
let l; // emitName=synth:l->l1
(function() {
var l1; // emitName=self:l1
l; // emitName=synth:l->l1 // conflict
})();
}
-
if a catch parameter is an identifier, it will be treated as a real, non-synthesized name.
-
a
var
name is treated as a real, non-synthesized name. -
a complex catch parameter is replace by a synthesized name; that synthesized name will not be added to the surrounding concrete scope's list of synthesized names, but the names that are contained in the original param are synthesized and added to the surrounding concrete scope's list of synthesized names.
-
name synthesis begins from the topmost scope; name synthesis is outline in the pseudo-code below:
function synthName(n: name): name {
var mustNotBe = [ownerScope.varNames, ownerScope.createMapForTheEmitNamesOfReferencedNames()];
for each (var scope that has referenced n) {
mustNotBe.push(scope.varNames);
}
var nameMap = createMapContainingExistingVarNames(mustNotBe);
var nonce = 0, candidate = n;
while (true) {
if (n not in.own nameMap) { break }
nonce++;
candidate = n + "" + nonce;
}
return candidate;
}