Avoid repeated declaration of the same loop variable.

The following code:

void main() {
  int j = 0;
  for (int i = 0; i < 10; i++) {
    j++;
  }
}

would generate the following:

for (var j = 0, i = 0; i < 10; ) {
  j = j + 1;
  var i = i + 1;
}

with this change the 'var' in the body disappears.

R=ngeoffray@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//10471002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8192 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ager@google.com
2012-06-01 13:15:19 +00:00
parent af7dc40244
commit 696fb20ece
3 changed files with 8 additions and 9 deletions
+1 -3
View File
@@ -46,7 +46,5 @@ Future<String> compile(Uri script,
options);
compiler.run(script);
String code = compiler.assembledCode;
Completer<String> completer = new Completer<String>();
completer.complete(code);
return completer.future;
return new Future.immediate(code);
}
+1 -3
View File
@@ -164,9 +164,7 @@ void compile(List<String> argv) {
dartBytesRead += source.length;
sourceFiles[uri.toString()] =
new SourceFile(relativize(cwd, uri), source);
Completer<String> completer = new Completer<String>();
completer.complete(source);
return completer.future;
return new Future.immediate(source);
}
void info(var message) {
+6 -3
View File
@@ -468,9 +468,12 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
declaredVariables.add(variableName);
buffer.add("var ");
}
} else if (!isGeneratingDeclaration()
&& !isVariableDeclared(variableName)) {
delayedVariablesDeclaration.add(variableName);
} else if (!isVariableDeclared(variableName)) {
if (!isGeneratingDeclaration()) {
delayedVariablesDeclaration.add(variableName);
} else {
declaredVariables.add(variableName);
}
}
} else if (!isVariableDeclared(variableName)) {
declaredVariables.add(variableName);