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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/src/TempManglingTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 9
10 String generateMethod(WorkItem work, HGraph graph) { 10 String generateMethod(WorkItem work, HGraph graph) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static final int STATE_EXPRESSION = 3; 93 static final int STATE_EXPRESSION = 3;
94 static final int STATE_DECLARATION = 4; 94 static final int STATE_DECLARATION = 4;
95 95
96 final Compiler compiler; 96 final Compiler compiler;
97 final WorkItem work; 97 final WorkItem work;
98 final StringBuffer buffer; 98 final StringBuffer buffer;
99 final String parameters; 99 final String parameters;
100 100
101 final Map<Element, String> parameterNames; 101 final Map<Element, String> parameterNames;
102 final Map<int, String> names; 102 final Map<int, String> names;
103 final Set<String> usedNames;
103 final Map<String, int> prefixes; 104 final Map<String, int> prefixes;
104 final Set<HInstruction> generateAtUseSite; 105 final Set<HInstruction> generateAtUseSite;
105 final Map<HPhi, String> logicalOperations; 106 final Map<HPhi, String> logicalOperations;
106 final Map<Element, ElementAction> breakAction; 107 final Map<Element, ElementAction> breakAction;
107 final Map<Element, ElementAction> continueAction; 108 final Map<Element, ElementAction> continueAction;
108 final Equivalence<HPhi> phiEquivalence; 109 final Equivalence<HPhi> phiEquivalence;
109 110
110 Element equalsNullElement; 111 Element equalsNullElement;
111 int indent = 0; 112 int indent = 0;
112 int expectedPrecedence = JSPrecedence.STATEMENT_PRECEDENCE; 113 int expectedPrecedence = JSPrecedence.STATEMENT_PRECEDENCE;
(...skipping 22 matching lines...) Expand all
135 bool isGenerateAtUseSite(HInstruction instruction) { 136 bool isGenerateAtUseSite(HInstruction instruction) {
136 return generateAtUseSite.contains(instruction); 137 return generateAtUseSite.contains(instruction);
137 } 138 }
138 139
139 SsaCodeGenerator(this.compiler, 140 SsaCodeGenerator(this.compiler,
140 this.work, 141 this.work,
141 this.parameters, 142 this.parameters,
142 this.parameterNames) 143 this.parameterNames)
143 : names = new Map<int, String>(), 144 : names = new Map<int, String>(),
144 prefixes = new Map<String, int>(), 145 prefixes = new Map<String, int>(),
146 usedNames = new Set<String>(),
145 buffer = new StringBuffer(), 147 buffer = new StringBuffer(),
146 generateAtUseSite = new Set<HInstruction>(), 148 generateAtUseSite = new Set<HInstruction>(),
147 logicalOperations = new Map<HPhi, String>(), 149 logicalOperations = new Map<HPhi, String>(),
148 breakAction = new Map<Element, ElementAction>(), 150 breakAction = new Map<Element, ElementAction>(),
149 continueAction = new Map<Element, ElementAction>(), 151 continueAction = new Map<Element, ElementAction>(),
150 phiEquivalence = new Equivalence<HPhi>() { 152 phiEquivalence = new Equivalence<HPhi>() {
151 153
152 for (final name in parameterNames.getValues()) { 154 for (final name in parameterNames.getValues()) {
153 prefixes[name] = 0; 155 prefixes[name] = 0;
154 } 156 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 267
266 void visitConditionGraph(SubGraph conditionSubGraph) { 268 void visitConditionGraph(SubGraph conditionSubGraph) {
267 visitExpressionGraph(conditionSubGraph); 269 visitExpressionGraph(conditionSubGraph);
268 } 270 }
269 271
270 String temporary(HInstruction instruction) { 272 String temporary(HInstruction instruction) {
271 int id = instruction.id; 273 int id = instruction.id;
272 String name = names[id]; 274 String name = names[id];
273 if (name !== null) return name; 275 if (name !== null) return name;
274 276
277 String prefix;
275 if (instruction.sourceElement !== null) { 278 if (instruction.sourceElement !== null) {
276 Element element = instruction.sourceElement; 279 Element element = instruction.sourceElement;
277 String prefix;
278 if (element !== null && !element.name.isEmpty()) { 280 if (element !== null && !element.name.isEmpty()) {
279 prefix = element.name.slowToString(); 281 prefix = element.name.slowToString();
280 } else { 282 } else {
281 prefix = 'v'; 283 prefix = 'v';
282 } 284 }
283 if (!prefixes.containsKey(prefix)) { 285 } else {
284 prefixes[prefix] = 0; 286 prefix = 't';
285 return newName(id, prefix); 287 }
286 } else { 288
287 return newName(id, '${prefix}_${prefixes[prefix]++}'); 289 while (usedNames.contains(prefix)) {
290 prefix = '${prefix}_';
291 }
292
293 if (!prefixes.containsKey(prefix)) {
294 prefixes[prefix] = 0;
295 return newName(id, prefix);
296 } else {
297 name = '${prefix}${prefixes[prefix]++}';
298 while (usedNames.contains(name)) {
299 name = '${prefix}${prefixes[prefix]++}';
288 } 300 }
289 } else { 301 return newName(id, name);
290 String prefix = 't';
291 if (!prefixes.containsKey(prefix)) prefixes[prefix] = 0;
292 return newName(id, '${prefix}${prefixes[prefix]++}');
293 } 302 }
294 } 303 }
295 304
296 bool temporaryExists(HInstruction instruction) { 305 bool temporaryExists(HInstruction instruction) {
297 return names.containsKey(instruction.id); 306 return names.containsKey(instruction.id);
298 } 307 }
299 308
300 String newName(int id, String name) { 309 String newName(int id, String name) {
301 String result = JsNames.getValid(name); 310 String result = JsNames.getValid(name);
302 names[id] = result; 311 names[id] = result;
312 usedNames.add(result);
303 return result; 313 return result;
304 } 314 }
305 315
306 /** 316 /**
307 * Only visits the arguments starting at inputs[HInvoke.ARGUMENTS_OFFSET]. 317 * Only visits the arguments starting at inputs[HInvoke.ARGUMENTS_OFFSET].
308 */ 318 */
309 void visitArguments(List<HInstruction> inputs) { 319 void visitArguments(List<HInstruction> inputs) {
310 assert(inputs.length >= HInvoke.ARGUMENTS_OFFSET); 320 assert(inputs.length >= HInvoke.ARGUMENTS_OFFSET);
311 buffer.add('('); 321 buffer.add('(');
312 for (int i = HInvoke.ARGUMENTS_OFFSET; i < inputs.length; i++) { 322 for (int i = HInvoke.ARGUMENTS_OFFSET; i < inputs.length; i++) {
(...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 startBailoutSwitch(); 1928 startBailoutSwitch();
1919 } 1929 }
1920 } 1930 }
1921 1931
1922 void endElse(HIf node) { 1932 void endElse(HIf node) {
1923 if (node.elseBlock.hasGuards()) { 1933 if (node.elseBlock.hasGuards()) {
1924 endBailoutSwitch(); 1934 endBailoutSwitch();
1925 } 1935 }
1926 } 1936 }
1927 } 1937 }
OLDNEW
« 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