| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 current_function_state_(NULL), | 546 current_function_state_(NULL), |
| 547 target_stack_(NULL), | 547 target_stack_(NULL), |
| 548 extension_(info->extension()), | 548 extension_(info->extension()), |
| 549 pre_parse_data_(NULL), | 549 pre_parse_data_(NULL), |
| 550 fni_(NULL), | 550 fni_(NULL), |
| 551 parenthesized_function_(false), | 551 parenthesized_function_(false), |
| 552 zone_(info->zone()), | 552 zone_(info->zone()), |
| 553 info_(info) { | 553 info_(info) { |
| 554 ASSERT(!script_.is_null()); | 554 ASSERT(!script_.is_null()); |
| 555 isolate_->set_ast_node_id(0); | 555 isolate_->set_ast_node_id(0); |
| 556 // FIXME: these can be done only when the ExperimentalScanner has been | |
| 557 // created, and they need to be redone when it's recreated. | |
| 558 // set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | |
| 559 // set_allow_modules(!info->is_native() && FLAG_harmony_modules); | |
| 560 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 556 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 561 // set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | |
| 562 set_allow_lazy(false); // Must be explicitly enabled. | 557 set_allow_lazy(false); // Must be explicitly enabled. |
| 563 set_allow_generators(FLAG_harmony_generators); | 558 set_allow_generators(FLAG_harmony_generators); |
| 564 set_allow_for_of(FLAG_harmony_iteration); | 559 set_allow_for_of(FLAG_harmony_iteration); |
| 565 } | 560 } |
| 566 | 561 |
| 567 | 562 |
| 568 FunctionLiteral* Parser::ParseProgram() { | 563 FunctionLiteral* Parser::ParseProgram() { |
| 569 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 564 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| 570 // see comment for HistogramTimerScope class. | 565 // see comment for HistogramTimerScope class. |
| 571 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); | 566 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); |
| 572 Handle<String> source(String::cast(script_->source())); | 567 Handle<String> source(String::cast(script_->source())); |
| 573 isolate()->counters()->total_parse_size()->Increment(source->length()); | 568 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 574 ElapsedTimer timer; | 569 ElapsedTimer timer; |
| 575 if (FLAG_trace_parse) { | 570 if (FLAG_trace_parse) { |
| 576 timer.Start(); | 571 timer.Start(); |
| 577 } | 572 } |
| 578 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); | 573 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
| 579 | 574 |
| 580 // Initialize parser state. | 575 // Initialize parser state. |
| 581 FlattenString(source); | 576 FlattenString(source); |
| 582 FunctionLiteral* result; | 577 FunctionLiteral* result; |
| 583 if (source->IsTwoByteRepresentation()) { | 578 if (source->IsTwoByteRepresentation()) { |
| 584 // Notice that the stream is destroyed at the end of the branch block. | 579 delete reusable_preparser_; |
| 585 // The last line of the blocks can't be moved outside, even though they're | |
| 586 // identical calls. // FIXME | |
| 587 delete scanner_; | 580 delete scanner_; |
| 588 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); | 581 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); |
| 589 // FIXME: set flags | |
| 590 result = DoParseProgram(info(), source); | |
| 591 } else { | 582 } else { |
| 583 delete reusable_preparser_; |
| 592 delete scanner_; | 584 delete scanner_; |
| 593 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); | 585 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); |
| 594 // FIXME: set flags | |
| 595 result = DoParseProgram(info(), source); | |
| 596 } | 586 } |
| 587 SetScannerFlags(); |
| 588 scanner_->Init(); |
| 589 result = DoParseProgram(info(), source); |
| 597 | 590 |
| 598 if (FLAG_trace_parse && result != NULL) { | 591 if (FLAG_trace_parse && result != NULL) { |
| 599 double ms = timer.Elapsed().InMillisecondsF(); | 592 double ms = timer.Elapsed().InMillisecondsF(); |
| 600 if (info()->is_eval()) { | 593 if (info()->is_eval()) { |
| 601 PrintF("[parsing eval"); | 594 PrintF("[parsing eval"); |
| 602 } else if (info()->script()->name()->IsString()) { | 595 } else if (info()->script()->name()->IsString()) { |
| 603 String* name = String::cast(info()->script()->name()); | 596 String* name = String::cast(info()->script()->name()); |
| 604 SmartArrayPointer<char> name_chars = name->ToCString(); | 597 SmartArrayPointer<char> name_chars = name->ToCString(); |
| 605 PrintF("[parsing script: %s", *name_chars); | 598 PrintF("[parsing script: %s", *name_chars); |
| 606 } else { | 599 } else { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 if (FLAG_trace_parse && result != NULL) { | 711 if (FLAG_trace_parse && result != NULL) { |
| 719 double ms = timer.Elapsed().InMillisecondsF(); | 712 double ms = timer.Elapsed().InMillisecondsF(); |
| 720 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); | 713 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); |
| 721 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); | 714 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); |
| 722 } | 715 } |
| 723 return result; | 716 return result; |
| 724 } | 717 } |
| 725 | 718 |
| 726 | 719 |
| 727 FunctionLiteral* Parser::ParseLazy(Handle<String> source, int start, int end) { | 720 FunctionLiteral* Parser::ParseLazy(Handle<String> source, int start, int end) { |
| 721 delete reusable_preparser_; |
| 728 delete scanner_; | 722 delete scanner_; |
| 729 if (source->IsTwoByteRepresentation()) { | 723 if (source->IsTwoByteRepresentation()) { |
| 730 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); | 724 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); |
| 731 } else { | 725 } else { |
| 732 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); | 726 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); |
| 733 } | 727 } |
| 728 SetScannerFlags(); |
| 729 // We don't need to Init() if we immediately SeekForward. |
| 734 scanner_->SeekForward(start); | 730 scanner_->SeekForward(start); |
| 735 scanner_->SetEnd(end); | 731 scanner_->SetEnd(end); |
| 736 // FIXME: set flags | |
| 737 | 732 |
| 738 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | 733 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
| 739 ASSERT(top_scope_ == NULL); | 734 ASSERT(top_scope_ == NULL); |
| 740 ASSERT(target_stack_ == NULL); | 735 ASSERT(target_stack_ == NULL); |
| 741 | 736 |
| 742 Handle<String> name(String::cast(shared_info->name())); | 737 Handle<String> name(String::cast(shared_info->name())); |
| 743 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); | 738 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
| 744 fni_->PushEnclosingName(name); | 739 fni_->PushEnclosingName(name); |
| 745 | 740 |
| 746 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 741 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| (...skipping 4920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5667 DeleteArray(args.start()); | 5662 DeleteArray(args.start()); |
| 5668 ASSERT(info()->isolate()->has_pending_exception()); | 5663 ASSERT(info()->isolate()->has_pending_exception()); |
| 5669 } else { | 5664 } else { |
| 5670 result = ParseProgram(); | 5665 result = ParseProgram(); |
| 5671 } | 5666 } |
| 5672 } | 5667 } |
| 5673 info()->SetFunction(result); | 5668 info()->SetFunction(result); |
| 5674 return (result != NULL); | 5669 return (result != NULL); |
| 5675 } | 5670 } |
| 5676 | 5671 |
| 5672 |
| 5673 void Parser::SetScannerFlags() { |
| 5674 scanner_->SetHarmonyScoping(!info_->is_native() && FLAG_harmony_scoping); |
| 5675 scanner_->SetHarmonyModules(!info_->is_native() && FLAG_harmony_modules); |
| 5676 scanner_->SetHarmonyNumericLiterals(FLAG_harmony_numeric_literals); |
| 5677 } |
| 5678 |
| 5677 } } // namespace v8::internal | 5679 } } // namespace v8::internal |
| OLD | NEW |