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

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

Issue 508643004: Fix scope/context behavior in await transformer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | « runtime/vm/ast_transformer.cc ('k') | runtime/vm/symbols.h » ('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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 6237 matching lines...) Expand 10 before | Expand all | Expand 10 after
6248 *value = Bool::True().raw(); 6248 *value = Bool::True().raw();
6249 return true; 6249 return true;
6250 } else if (CurrentToken() == Token::kFALSE) { 6250 } else if (CurrentToken() == Token::kFALSE) {
6251 *value = Bool::False().raw(); 6251 *value = Bool::False().raw();
6252 return true; 6252 return true;
6253 } 6253 }
6254 return false; 6254 return false;
6255 } 6255 }
6256 6256
6257 6257
6258 // Returns true if the current token is kIDENT or a pseudo-keyword. 6258 // Returns true if the current token is
6259 // * kIDENT,
6260 // * or a pseudo-keyword,
6261 // * or is not the literal "await" in an async function.
6259 bool Parser::IsIdentifier() { 6262 bool Parser::IsIdentifier() {
6260 return Token::IsIdentifier(CurrentToken()); 6263 bool is_async = false;
6264 if (parsed_function() != NULL) {
6265 const Function& func = parsed_function()->function();
6266 if (!func.IsNull()) {
6267 is_async = func.IsAsyncFunction() || func.is_async_closure();
hausner 2014/08/26 20:45:47 I think this is too expensive. I think it would ma
Michael Lippautz (Google) 2014/08/26 22:07:44 Agree. I added the proposed indicator to the parse
6268 }
6269 }
6270 return Token::IsIdentifier(CurrentToken()) &&
6271 (!is_async || (CurrentLiteral()->raw() != Symbols::Await().raw()));
6261 } 6272 }
6262 6273
6263 6274
6264 // Returns true if the next tokens can be parsed as a an optionally 6275 // Returns true if the next tokens can be parsed as a an optionally
6265 // qualified identifier: [ident '.'] ident. 6276 // qualified identifier: [ident '.'] ident.
6266 // Current token position is not restored. 6277 // Current token position is not restored.
6267 bool Parser::TryParseQualIdent() { 6278 bool Parser::TryParseQualIdent() {
6268 if (CurrentToken() != Token::kIDENT) { 6279 if (CurrentToken() != Token::kIDENT) {
6269 return false; 6280 return false;
6270 } 6281 }
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
8447 parsed_function()->reset_have_seen_await(); 8458 parsed_function()->reset_have_seen_await();
8448 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades); 8459 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades);
8449 if (parsed_function()->have_seen_await()) { 8460 if (parsed_function()->have_seen_await()) {
8450 if (!current_block_->scope->LookupVariable( 8461 if (!current_block_->scope->LookupVariable(
8451 Symbols::AsyncOperation(), true)) { 8462 Symbols::AsyncOperation(), true)) {
8452 // Async operations are always encapsulated into a local function. We only 8463 // Async operations are always encapsulated into a local function. We only
8453 // need to transform the expression when generating code for this inner 8464 // need to transform the expression when generating code for this inner
8454 // function. 8465 // function.
8455 return expr; 8466 return expr;
8456 } 8467 }
8457 SequenceNode* intermediates_block = new(I) SequenceNode( 8468 OpenBlock();
8458 Scanner::kNoSourcePos, current_block_->scope); 8469 AwaitTransformer at(current_block_->statements,
8459 AwaitTransformer at(intermediates_block, library_, parsed_function()); 8470 library_,
8471 parsed_function());
8460 AstNode* result = at.Transform(expr); 8472 AstNode* result = at.Transform(expr);
8461 current_block_->statements->Add(intermediates_block); 8473 current_block_->statements->Add(CloseBlock());
8462 parsed_function()->reset_have_seen_await(); 8474 parsed_function()->reset_have_seen_await();
8463 return result; 8475 return result;
8464 } 8476 }
8465 return expr; 8477 return expr;
8466 } 8478 }
8467 8479
8468 8480
8469 AstNode* Parser::ParseExpr(bool require_compiletime_const, 8481 AstNode* Parser::ParseExpr(bool require_compiletime_const,
8470 bool consume_cascades) { 8482 bool consume_cascades) {
8471 TRACE_PARSER("ParseExpr"); 8483 TRACE_PARSER("ParseExpr");
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
10836 TRACE_PARSER("ParsePrimary"); 10848 TRACE_PARSER("ParsePrimary");
10837 ASSERT(!is_top_level_); 10849 ASSERT(!is_top_level_);
10838 AstNode* primary = NULL; 10850 AstNode* primary = NULL;
10839 const Token::Kind token = CurrentToken(); 10851 const Token::Kind token = CurrentToken();
10840 if (IsFunctionLiteral()) { 10852 if (IsFunctionLiteral()) {
10841 // The name of a literal function is visible from inside the function, but 10853 // The name of a literal function is visible from inside the function, but
10842 // must not collide with names in the scope declaring the literal. 10854 // must not collide with names in the scope declaring the literal.
10843 OpenBlock(); 10855 OpenBlock();
10844 primary = ParseFunctionStatement(true); 10856 primary = ParseFunctionStatement(true);
10845 CloseBlock(); 10857 CloseBlock();
10846 } else if (IsLiteral("await") && 10858 } else if ((CurrentLiteral()->raw() == Symbols::Await().raw()) &&
10847 (parsed_function()->function().IsAsyncFunction() || 10859 (parsed_function()->function().IsAsyncFunction() ||
10848 parsed_function()->function().is_async_closure())) { 10860 parsed_function()->function().is_async_closure())) {
10849 // The body of an async function is parsed multiple times. The first time 10861 // The body of an async function is parsed multiple times. The first time
10850 // when setting up an AsyncFunction() for generating relevant scope 10862 // when setting up an AsyncFunction() for generating relevant scope
10851 // information. The second time the body is parsed for actually generating 10863 // information. The second time the body is parsed for actually generating
10852 // code. 10864 // code.
10853 TRACE_PARSER("ParseAwaitExpr"); 10865 TRACE_PARSER("ParseAwaitExpr");
10854 ConsumeToken(); 10866 ConsumeToken();
10855 parsed_function()->record_await(); 10867 parsed_function()->record_await();
10856 primary = new(I) AwaitNode( 10868 primary = new(I) AwaitNode(
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
11387 void Parser::SkipQualIdent() { 11399 void Parser::SkipQualIdent() {
11388 ASSERT(IsIdentifier()); 11400 ASSERT(IsIdentifier());
11389 ConsumeToken(); 11401 ConsumeToken();
11390 if (CurrentToken() == Token::kPERIOD) { 11402 if (CurrentToken() == Token::kPERIOD) {
11391 ConsumeToken(); // Consume the kPERIOD token. 11403 ConsumeToken(); // Consume the kPERIOD token.
11392 ExpectIdentifier("identifier expected after '.'"); 11404 ExpectIdentifier("identifier expected after '.'");
11393 } 11405 }
11394 } 11406 }
11395 11407
11396 } // namespace dart 11408 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698