| 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 "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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (position < token_index_ && position != 0) { | 221 if (position < token_index_ && position != 0) { |
| 222 CompilerStats::num_tokens_rewind += (token_index_ - position); | 222 CompilerStats::num_tokens_rewind += (token_index_ - position); |
| 223 } | 223 } |
| 224 token_index_ = position; | 224 token_index_ = position; |
| 225 token_kind_ = Token::kILLEGAL; | 225 token_kind_ = Token::kILLEGAL; |
| 226 } | 226 } |
| 227 | 227 |
| 228 | 228 |
| 229 void Parser::ParseCompilationUnit(const Library& library, | 229 void Parser::ParseCompilationUnit(const Library& library, |
| 230 const Script& script) { | 230 const Script& script) { |
| 231 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); |
| 231 Parser parser(script, library); | 232 Parser parser(script, library); |
| 232 if (FLAG_compiler_stats) { | |
| 233 CompilerStats::parser_timer.Start(); | |
| 234 } | |
| 235 parser.ParseTopLevel(); | 233 parser.ParseTopLevel(); |
| 236 if (FLAG_compiler_stats) { | 234 if (FLAG_compiler_stats) { |
| 237 CompilerStats::parser_timer.Stop(); | |
| 238 CompilerStats::num_tokens_total += parser.tokens_.Length(); | 235 CompilerStats::num_tokens_total += parser.tokens_.Length(); |
| 239 } | 236 } |
| 240 } | 237 } |
| 241 | 238 |
| 242 | 239 |
| 243 Token::Kind Parser::CurrentToken() { | 240 Token::Kind Parser::CurrentToken() { |
| 244 if (token_kind_ == Token::kILLEGAL) { | 241 if (token_kind_ == Token::kILLEGAL) { |
| 245 token_kind_ = tokens_.KindAt(token_index_); | 242 token_kind_ = tokens_.KindAt(token_index_); |
| 246 if (token_kind_ == Token::kERROR) { | 243 if (token_kind_ == Token::kERROR) { |
| 247 ErrorMsg(token_index_, CurrentLiteral()->ToCString()); | 244 ErrorMsg(token_index_, CurrentLiteral()->ToCString()); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } else if ((seq->length()) == 1 && | 546 } else if ((seq->length()) == 1 && |
| 550 (seq->NodeAt(seq->length() - 1)->IsSequenceNode())) { | 547 (seq->NodeAt(seq->length() - 1)->IsSequenceNode())) { |
| 551 return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode()); | 548 return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode()); |
| 552 } else { | 549 } else { |
| 553 return seq->NodeAt(seq->length() - 1)->IsReturnNode(); | 550 return seq->NodeAt(seq->length() - 1)->IsReturnNode(); |
| 554 } | 551 } |
| 555 } | 552 } |
| 556 | 553 |
| 557 | 554 |
| 558 void Parser::ParseFunction(ParsedFunction* parsed_function) { | 555 void Parser::ParseFunction(ParsedFunction* parsed_function) { |
| 556 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); |
| 559 Isolate* isolate = Isolate::Current(); | 557 Isolate* isolate = Isolate::Current(); |
| 560 // Compilation can be nested, preserve the ast node id. | 558 // Compilation can be nested, preserve the ast node id. |
| 561 const int prev_ast_node_id = isolate->ast_node_id(); | 559 const int prev_ast_node_id = isolate->ast_node_id(); |
| 562 isolate->set_ast_node_id(0); | 560 isolate->set_ast_node_id(0); |
| 563 ASSERT(parsed_function != NULL); | 561 ASSERT(parsed_function != NULL); |
| 564 const Function& func = parsed_function->function(); | 562 const Function& func = parsed_function->function(); |
| 565 const Class& cls = Class::Handle(isolate, func.owner()); | 563 const Class& cls = Class::Handle(isolate, func.owner()); |
| 566 const Script& script = Script::Handle(isolate, cls.script()); | 564 const Script& script = Script::Handle(isolate, cls.script()); |
| 567 Parser parser(script, func, func.token_index()); | 565 Parser parser(script, func, func.token_index()); |
| 568 if (FLAG_compiler_stats) { | |
| 569 CompilerStats::parser_timer.Start(); | |
| 570 } | |
| 571 SequenceNode* node_sequence = NULL; | 566 SequenceNode* node_sequence = NULL; |
| 572 Array& default_parameter_values = Array::Handle(isolate, Array::null()); | 567 Array& default_parameter_values = Array::Handle(isolate, Array::null()); |
| 573 switch (func.kind()) { | 568 switch (func.kind()) { |
| 574 case RawFunction::kFunction: | 569 case RawFunction::kFunction: |
| 575 case RawFunction::kClosureFunction: | 570 case RawFunction::kClosureFunction: |
| 576 case RawFunction::kGetterFunction: | 571 case RawFunction::kGetterFunction: |
| 577 case RawFunction::kSetterFunction: | 572 case RawFunction::kSetterFunction: |
| 578 case RawFunction::kConstructor: | 573 case RawFunction::kConstructor: |
| 579 node_sequence = parser.ParseFunc(func, default_parameter_values); | 574 node_sequence = parser.ParseFunc(func, default_parameter_values); |
| 580 break; | 575 break; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 609 parser.LookupReceiver(node_sequence->scope(), | 604 parser.LookupReceiver(node_sequence->scope(), |
| 610 kTestOnly); | 605 kTestOnly); |
| 611 if (!parser.current_function().IsLocalFunction() || | 606 if (!parser.current_function().IsLocalFunction() || |
| 612 ((receiver != NULL) && receiver->is_captured())) { | 607 ((receiver != NULL) && receiver->is_captured())) { |
| 613 parsed_function->set_instantiator( | 608 parsed_function->set_instantiator( |
| 614 new LoadLocalNode(node_sequence->token_index(), *receiver)); | 609 new LoadLocalNode(node_sequence->token_index(), *receiver)); |
| 615 } | 610 } |
| 616 } | 611 } |
| 617 | 612 |
| 618 parsed_function->set_default_parameter_values(default_parameter_values); | 613 parsed_function->set_default_parameter_values(default_parameter_values); |
| 619 if (FLAG_compiler_stats) { | |
| 620 CompilerStats::parser_timer.Stop(); | |
| 621 } | |
| 622 isolate->set_ast_node_id(prev_ast_node_id); | 614 isolate->set_ast_node_id(prev_ast_node_id); |
| 623 } | 615 } |
| 624 | 616 |
| 625 | 617 |
| 626 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { | 618 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { |
| 627 ParamList params; | 619 ParamList params; |
| 628 ASSERT(func.num_fixed_parameters() == 0); // static. | 620 ASSERT(func.num_fixed_parameters() == 0); // static. |
| 629 ASSERT(func.num_optional_parameters() == 0); | 621 ASSERT(func.num_optional_parameters() == 0); |
| 630 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 622 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 631 | 623 |
| (...skipping 7126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7758 } | 7750 } |
| 7759 | 7751 |
| 7760 | 7752 |
| 7761 void Parser::SkipNestedExpr() { | 7753 void Parser::SkipNestedExpr() { |
| 7762 const bool saved_mode = SetAllowFunctionLiterals(true); | 7754 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7763 SkipExpr(); | 7755 SkipExpr(); |
| 7764 SetAllowFunctionLiterals(saved_mode); | 7756 SetAllowFunctionLiterals(saved_mode); |
| 7765 } | 7757 } |
| 7766 | 7758 |
| 7767 } // namespace dart | 7759 } // namespace dart |
| OLD | NEW |