| OLD | NEW |
| 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 8292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8303 // function body, so the await or yield inside the async closure should always | 8303 // function body, so the await or yield inside the async closure should always |
| 8304 // be created with a try scope. | 8304 // be created with a try scope. |
| 8305 ASSERT((*try_scope != NULL) || | 8305 ASSERT((*try_scope != NULL) || |
| 8306 innermost_function().IsAsyncFunction() || | 8306 innermost_function().IsAsyncFunction() || |
| 8307 innermost_function().IsAsyncGenerator() || | 8307 innermost_function().IsAsyncGenerator() || |
| 8308 innermost_function().IsSyncGenClosure() || | 8308 innermost_function().IsSyncGenClosure() || |
| 8309 innermost_function().IsSyncGenerator()); | 8309 innermost_function().IsSyncGenerator()); |
| 8310 } | 8310 } |
| 8311 | 8311 |
| 8312 | 8312 |
| 8313 // Build an AST node for static call to Dart function print(str). |
| 8314 // Used during debugging to insert print in generated dart code. |
| 8315 AstNode* Parser::DartPrint(const char* str) { |
| 8316 const Library& lib = Library::Handle(Library::CoreLibrary()); |
| 8317 const Function& print_fn = Function::ZoneHandle( |
| 8318 Z, lib.LookupFunctionAllowPrivate(Symbols::print())); |
| 8319 ASSERT(!print_fn.IsNull()); |
| 8320 ArgumentListNode* one_arg = new(Z) ArgumentListNode(Scanner::kNoSourcePos); |
| 8321 String& msg = String::Handle(String::NewFormatted("%s", str)); |
| 8322 one_arg->Add(new(Z) LiteralNode(Scanner::kNoSourcePos, |
| 8323 String::ZoneHandle(Symbols::New(msg)))); |
| 8324 AstNode* print_call = |
| 8325 new(Z) StaticCallNode(Scanner::kNoSourcePos, print_fn, one_arg); |
| 8326 return print_call; |
| 8327 } |
| 8328 |
| 8329 |
| 8313 AstNode* Parser::ParseAwaitForStatement(String* label_name) { | 8330 AstNode* Parser::ParseAwaitForStatement(String* label_name) { |
| 8314 TRACE_PARSER("ParseAwaitForStatement"); | 8331 TRACE_PARSER("ParseAwaitForStatement"); |
| 8315 ASSERT(IsAwaitKeyword()); | 8332 ASSERT(IsAwaitKeyword()); |
| 8316 const intptr_t await_for_pos = TokenPos(); | 8333 const intptr_t await_for_pos = TokenPos(); |
| 8317 ConsumeToken(); // await. | 8334 ConsumeToken(); // await. |
| 8318 ASSERT(CurrentToken() == Token::kFOR); | 8335 ASSERT(CurrentToken() == Token::kFOR); |
| 8319 ConsumeToken(); // for. | 8336 ConsumeToken(); // for. |
| 8320 ExpectToken(Token::kLPAREN); | 8337 ExpectToken(Token::kLPAREN); |
| 8321 | 8338 |
| 8322 if (!innermost_function().IsAsyncFunction() && | 8339 if (!innermost_function().IsAsyncFunction() && |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8470 } else { | 8487 } else { |
| 8471 AstNode* loop_var_primary = | 8488 AstNode* loop_var_primary = |
| 8472 ResolveIdent(loop_var_pos, *loop_var_name, false); | 8489 ResolveIdent(loop_var_pos, *loop_var_name, false); |
| 8473 ASSERT(!loop_var_primary->IsPrimaryNode()); | 8490 ASSERT(!loop_var_primary->IsPrimaryNode()); |
| 8474 loop_var_assignment = CreateAssignmentNode(loop_var_primary, | 8491 loop_var_assignment = CreateAssignmentNode(loop_var_primary, |
| 8475 iterator_current, | 8492 iterator_current, |
| 8476 loop_var_name, | 8493 loop_var_name, |
| 8477 loop_var_assignment_pos); | 8494 loop_var_assignment_pos); |
| 8478 ASSERT(loop_var_assignment != NULL); | 8495 ASSERT(loop_var_assignment != NULL); |
| 8479 } | 8496 } |
| 8480 | |
| 8481 current_block_->statements->Add(loop_var_assignment); | 8497 current_block_->statements->Add(loop_var_assignment); |
| 8482 | 8498 |
| 8483 // Now parse the for-in loop statement or block. | 8499 // Now parse the for-in loop statement or block. |
| 8484 if (CurrentToken() == Token::kLBRACE) { | 8500 if (CurrentToken() == Token::kLBRACE) { |
| 8485 ConsumeToken(); | 8501 ConsumeToken(); |
| 8486 ParseStatementSequence(); | 8502 ParseStatementSequence(); |
| 8487 ExpectToken(Token::kRBRACE); | 8503 ExpectToken(Token::kRBRACE); |
| 8488 } else { | 8504 } else { |
| 8489 AstNode* statement = ParseStatement(); | 8505 AstNode* statement = ParseStatement(); |
| 8490 if (statement != NULL) { | 8506 if (statement != NULL) { |
| (...skipping 4933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13424 void Parser::SkipQualIdent() { | 13440 void Parser::SkipQualIdent() { |
| 13425 ASSERT(IsIdentifier()); | 13441 ASSERT(IsIdentifier()); |
| 13426 ConsumeToken(); | 13442 ConsumeToken(); |
| 13427 if (CurrentToken() == Token::kPERIOD) { | 13443 if (CurrentToken() == Token::kPERIOD) { |
| 13428 ConsumeToken(); // Consume the kPERIOD token. | 13444 ConsumeToken(); // Consume the kPERIOD token. |
| 13429 ExpectIdentifier("identifier expected after '.'"); | 13445 ExpectIdentifier("identifier expected after '.'"); |
| 13430 } | 13446 } |
| 13431 } | 13447 } |
| 13432 | 13448 |
| 13433 } // namespace dart | 13449 } // namespace dart |
| OLD | NEW |