| OLD | NEW |
| 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 539 |
| 540 | 540 |
| 541 struct TopLevel { | 541 struct TopLevel { |
| 542 TopLevel() : fields(4), functions(4) { } | 542 TopLevel() : fields(4), functions(4) { } |
| 543 | 543 |
| 544 GrowableArray<Field*> fields; | 544 GrowableArray<Field*> fields; |
| 545 GrowableArray<Function*> functions; | 545 GrowableArray<Function*> functions; |
| 546 }; | 546 }; |
| 547 | 547 |
| 548 | 548 |
| 549 static bool HasReturnNode(SequenceNode* seq) { |
| 550 if (seq->length() == 0) { |
| 551 return false; |
| 552 } else if ((seq->length()) == 1 && |
| 553 (seq->NodeAt(seq->length() - 1)->IsSequenceNode())) { |
| 554 return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode()); |
| 555 } else { |
| 556 return seq->NodeAt(seq->length() - 1)->IsReturnNode(); |
| 557 } |
| 558 } |
| 559 |
| 560 |
| 549 void Parser::ParseFunction(ParsedFunction* parsed_function) { | 561 void Parser::ParseFunction(ParsedFunction* parsed_function) { |
| 550 Isolate* isolate = Isolate::Current(); | 562 Isolate* isolate = Isolate::Current(); |
| 551 // Compilation can be nested, preserve the ast node id. | 563 // Compilation can be nested, preserve the ast node id. |
| 552 const int prev_ast_node_id = isolate->ast_node_id(); | 564 const int prev_ast_node_id = isolate->ast_node_id(); |
| 553 isolate->set_ast_node_id(0); | 565 isolate->set_ast_node_id(0); |
| 554 ASSERT(parsed_function != NULL); | 566 ASSERT(parsed_function != NULL); |
| 555 const Function& func = parsed_function->function(); | 567 const Function& func = parsed_function->function(); |
| 556 const Class& cls = Class::Handle(func.owner()); | 568 const Class& cls = Class::Handle(func.owner()); |
| 557 const Script& script = Script::Handle(cls.script()); | 569 const Script& script = Script::Handle(cls.script()); |
| 558 Parser parser(script, func, func.token_index()); | 570 Parser parser(script, func, func.token_index()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 577 ASSERT(!func.is_static()); | 589 ASSERT(!func.is_static()); |
| 578 node_sequence = parser.ParseInstanceSetter(func); | 590 node_sequence = parser.ParseInstanceSetter(func); |
| 579 break; | 591 break; |
| 580 case RawFunction::kConstImplicitGetter: | 592 case RawFunction::kConstImplicitGetter: |
| 581 node_sequence = parser.ParseStaticConstGetter(func); | 593 node_sequence = parser.ParseStaticConstGetter(func); |
| 582 break; | 594 break; |
| 583 default: | 595 default: |
| 584 UNREACHABLE(); | 596 UNREACHABLE(); |
| 585 } | 597 } |
| 586 | 598 |
| 587 if ((node_sequence->length() == 0) || | 599 if (!HasReturnNode(node_sequence)) { |
| 588 !node_sequence->NodeAt(node_sequence->length() - 1)->IsReturnNode()) { | |
| 589 // Add implicit return node. | 600 // Add implicit return node. |
| 590 node_sequence->Add(new ReturnNode(parser.token_index_)); | 601 node_sequence->Add(new ReturnNode(parser.token_index_)); |
| 591 } | 602 } |
| 592 parsed_function->set_node_sequence(node_sequence); | 603 parsed_function->set_node_sequence(node_sequence); |
| 593 | 604 |
| 594 // The instantiator may be required at run time for generic type checks or | 605 // The instantiator may be required at run time for generic type checks or |
| 595 // allocation of generic types. | 606 // allocation of generic types. |
| 596 if (parser.IsInstantiatorRequired()) { | 607 if (parser.IsInstantiatorRequired()) { |
| 597 // In the case of a local function, only set the instantiator if the | 608 // In the case of a local function, only set the instantiator if the |
| 598 // receiver was captured. | 609 // receiver was captured. |
| (...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 // The instantiator may be required at run time for generic type checks. | 1838 // The instantiator may be required at run time for generic type checks. |
| 1828 if (IsInstantiatorRequired()) { | 1839 if (IsInstantiatorRequired()) { |
| 1829 // Make sure that the receiver of the enclosing instance function | 1840 // Make sure that the receiver of the enclosing instance function |
| 1830 // (or implicit first parameter of an enclosing factory) is marked as | 1841 // (or implicit first parameter of an enclosing factory) is marked as |
| 1831 // captured if type checks are enabled, because they may access the | 1842 // captured if type checks are enabled, because they may access the |
| 1832 // receiver to instantiate types. | 1843 // receiver to instantiate types. |
| 1833 CaptureReceiver(); | 1844 CaptureReceiver(); |
| 1834 } | 1845 } |
| 1835 } | 1846 } |
| 1836 | 1847 |
| 1848 OpenBlock(); // Open a nested scope for the outermost function block. |
| 1837 if (CurrentToken() == Token::kLBRACE) { | 1849 if (CurrentToken() == Token::kLBRACE) { |
| 1838 ConsumeToken(); | 1850 ConsumeToken(); |
| 1839 ParseStatementSequence(); | 1851 ParseStatementSequence(); |
| 1840 ExpectToken(Token::kRBRACE); | 1852 ExpectToken(Token::kRBRACE); |
| 1841 } else if (CurrentToken() == Token::kARROW) { | 1853 } else if (CurrentToken() == Token::kARROW) { |
| 1842 ConsumeToken(); | 1854 ConsumeToken(); |
| 1843 const intptr_t expr_pos = token_index_; | 1855 const intptr_t expr_pos = token_index_; |
| 1844 AstNode* expr = ParseExpr(kAllowConst); | 1856 AstNode* expr = ParseExpr(kAllowConst); |
| 1845 ASSERT(expr != NULL); | 1857 ASSERT(expr != NULL); |
| 1846 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); | 1858 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); |
| 1847 } else if (IsLiteral("native")) { | 1859 } else if (IsLiteral("native")) { |
| 1848 ParseNativeFunctionBlock(¶ms, func); | 1860 ParseNativeFunctionBlock(¶ms, func); |
| 1849 } else { | 1861 } else { |
| 1850 UnexpectedToken(); | 1862 UnexpectedToken(); |
| 1851 } | 1863 } |
| 1864 SequenceNode* body = CloseBlock(); |
| 1865 current_block_->statements->Add(body); |
| 1852 return CloseBlock(); | 1866 return CloseBlock(); |
| 1853 } | 1867 } |
| 1854 | 1868 |
| 1855 | 1869 |
| 1856 void Parser::SkipIf(Token::Kind token) { | 1870 void Parser::SkipIf(Token::Kind token) { |
| 1857 if (CurrentToken() == token) { | 1871 if (CurrentToken() == token) { |
| 1858 ConsumeToken(); | 1872 ConsumeToken(); |
| 1859 } | 1873 } |
| 1860 } | 1874 } |
| 1861 | 1875 |
| (...skipping 5828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7690 } | 7704 } |
| 7691 | 7705 |
| 7692 | 7706 |
| 7693 void Parser::SkipNestedExpr() { | 7707 void Parser::SkipNestedExpr() { |
| 7694 const bool saved_mode = SetAllowFunctionLiterals(true); | 7708 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7695 SkipExpr(); | 7709 SkipExpr(); |
| 7696 SetAllowFunctionLiterals(saved_mode); | 7710 SetAllowFunctionLiterals(saved_mode); |
| 7697 } | 7711 } |
| 7698 | 7712 |
| 7699 } // namespace dart | 7713 } // namespace dart |
| OLD | NEW |