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

Side by Side Diff: runtime/vm/parser.cc

Issue 8490019: Capturing for loop variables correctly (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | « runtime/vm/code_generator_ia32.cc ('k') | tests/language/language.status » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 4345 matching lines...) Expand 10 before | Expand all | Expand 10 after
4356 ExpectSemicolon(); 4356 ExpectSemicolon();
4357 AstNode* increment = NULL; 4357 AstNode* increment = NULL;
4358 intptr_t incr_pos = token_index_; 4358 intptr_t incr_pos = token_index_;
4359 LocalScope* incr_scope = current_block_->scope; 4359 LocalScope* incr_scope = current_block_->scope;
4360 if (CurrentToken() != Token::kRPAREN) { 4360 if (CurrentToken() != Token::kRPAREN) {
4361 increment = ParseExprList(); 4361 increment = ParseExprList();
4362 } 4362 }
4363 ExpectToken(Token::kRPAREN); 4363 ExpectToken(Token::kRPAREN);
4364 const bool parsing_loop_body = true; 4364 const bool parsing_loop_body = true;
4365 SequenceNode* body = ParseNestedStatement(parsing_loop_body, NULL); 4365 SequenceNode* body = ParseNestedStatement(parsing_loop_body, NULL);
4366
4367 // Check whether any of the variables in the initializer part of
4368 // the for statement are captured by a closure. If so, we insert a
4369 // node that creates a new Context at the end of the loop body (but
4370 // before the increment expression is evaluated).
4371 for (int i = 0; i < init_scope->num_variables(); i++) {
4372 if (init_scope->VariableAt(i)->is_captured() &&
4373 (init_scope->VariableAt(i)->owner() == init_scope)) {
4374 body->Add(new CloneContextNode(for_pos));
4375 break;
4376 }
4377 }
4366 CloseBlock(); 4378 CloseBlock();
4367 return new ForNode(for_pos, 4379 return new ForNode(for_pos,
4368 label, 4380 label,
4369 NodeAsSequenceNode(init_pos, initializer, init_scope), 4381 NodeAsSequenceNode(init_pos, initializer, init_scope),
4370 condition, 4382 condition,
4371 NodeAsSequenceNode(incr_pos, increment, incr_scope), 4383 NodeAsSequenceNode(incr_pos, increment, incr_scope),
4372 body); 4384 body);
4373 } 4385 }
4374 4386
4375 4387
(...skipping 2878 matching lines...) Expand 10 before | Expand all | Expand 10 after
7254 } 7266 }
7255 7267
7256 7268
7257 void Parser::SkipNestedExpr() { 7269 void Parser::SkipNestedExpr() {
7258 const bool saved_mode = SetAllowFunctionLiterals(true); 7270 const bool saved_mode = SetAllowFunctionLiterals(true);
7259 SkipExpr(); 7271 SkipExpr();
7260 SetAllowFunctionLiterals(saved_mode); 7272 SetAllowFunctionLiterals(saved_mode);
7261 } 7273 }
7262 7274
7263 } // namespace dart 7275 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_ia32.cc ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698