uniqueName method
Returns a variation on the input name
that is guaranteed to never be repeated within this scope.
The variation will the input name
, but with a numerical suffix appended.
Ex. foo1
, bar24
Implementation
String uniqueName(String name) {
var count = 0;
SymbolTable? search = this;
while (search != null) {
if (search._names.containsKey(name)) count += search._names[name]!;
search = search._parent;
}
_names.putIfAbsent(name, () => 0);
var n = _names[name];
if (n != null) {
n++;
_names[name] = n;
}
return '$name$count';
}