Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10123009: Fix mangling of local variables when their name conflict with Dart2JS's temporaries. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/src/TempManglingTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/codegen.dart
===================================================================
--- lib/compiler/implementation/ssa/codegen.dart (revision 6736)
+++ lib/compiler/implementation/ssa/codegen.dart (working copy)
@@ -100,6 +100,7 @@
final Map<Element, String> parameterNames;
final Map<int, String> names;
+ final Set<String> usedNames;
final Map<String, int> prefixes;
final Set<HInstruction> generateAtUseSite;
final Map<HPhi, String> logicalOperations;
@@ -142,6 +143,7 @@
this.parameterNames)
: names = new Map<int, String>(),
prefixes = new Map<String, int>(),
+ usedNames = new Set<String>(),
buffer = new StringBuffer(),
generateAtUseSite = new Set<HInstruction>(),
logicalOperations = new Map<HPhi, String>(),
@@ -272,25 +274,32 @@
String name = names[id];
if (name !== null) return name;
+ String prefix;
if (instruction.sourceElement !== null) {
Element element = instruction.sourceElement;
- String prefix;
if (element !== null && !element.name.isEmpty()) {
prefix = element.name.slowToString();
} else {
prefix = 'v';
}
- if (!prefixes.containsKey(prefix)) {
- prefixes[prefix] = 0;
- return newName(id, prefix);
- } else {
- return newName(id, '${prefix}_${prefixes[prefix]++}');
- }
} else {
- String prefix = 't';
- if (!prefixes.containsKey(prefix)) prefixes[prefix] = 0;
- return newName(id, '${prefix}${prefixes[prefix]++}');
+ prefix = 't';
}
+
+ while (usedNames.contains(prefix)) {
+ prefix = '${prefix}_';
+ }
+
+ if (!prefixes.containsKey(prefix)) {
+ prefixes[prefix] = 0;
+ return newName(id, prefix);
+ } else {
+ name = '${prefix}${prefixes[prefix]++}';
+ while (usedNames.contains(name)) {
+ name = '${prefix}${prefixes[prefix]++}';
+ }
+ return newName(id, name);
+ }
}
bool temporaryExists(HInstruction instruction) {
@@ -300,6 +309,7 @@
String newName(int id, String name) {
String result = JsNames.getValid(name);
names[id] = result;
+ usedNames.add(result);
return result;
}
« no previous file with comments | « no previous file | tests/language/src/TempManglingTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698