OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/compiler.h" // For CachedDataMode | 10 #include "src/compiler.h" // For CachedDataMode |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, | 590 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
591 bool* ok); | 591 bool* ok); |
592 | 592 |
593 private: | 593 private: |
594 Parser* parser_; | 594 Parser* parser_; |
595 }; | 595 }; |
596 | 596 |
597 | 597 |
598 class Parser : public ParserBase<ParserTraits> { | 598 class Parser : public ParserBase<ParserTraits> { |
599 public: | 599 public: |
600 explicit Parser(CompilationInfo* info); | 600 Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed); |
601 ~Parser() { | 601 ~Parser() { |
602 delete reusable_preparser_; | 602 delete reusable_preparser_; |
603 reusable_preparser_ = NULL; | 603 reusable_preparser_ = NULL; |
604 delete cached_parse_data_; | 604 delete cached_parse_data_; |
605 cached_parse_data_ = NULL; | 605 cached_parse_data_ = NULL; |
606 } | 606 } |
607 | 607 |
608 // Parses the source code represented by the compilation info and sets its | 608 // Parses the source code represented by the compilation info and sets its |
609 // function literal. Returns false (and deallocates any allocated AST | 609 // function literal. Returns false (and deallocates any allocated AST |
610 // nodes) if parsing failed. | 610 // nodes) if parsing failed. |
611 static bool Parse(CompilationInfo* info, | 611 static bool Parse(CompilationInfo* info, |
612 bool allow_lazy = false) { | 612 bool allow_lazy = false) { |
613 Parser parser(info); | 613 Parser parser(info, info->isolate()->stack_guard()->real_climit(), |
| 614 info->isolate()->heap()->HashSeed()); |
614 parser.set_allow_lazy(allow_lazy); | 615 parser.set_allow_lazy(allow_lazy); |
615 return parser.Parse(); | 616 return parser.Parse(); |
616 } | 617 } |
617 bool Parse(); | 618 bool Parse(); |
| 619 void ParseOnBackground(); |
618 | 620 |
619 private: | 621 private: |
620 friend class ParserTraits; | 622 friend class ParserTraits; |
621 | 623 |
622 // Limit the allowed number of local variables in a function. The hard limit | 624 // Limit the allowed number of local variables in a function. The hard limit |
623 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 625 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
624 // functions are ints, and they should not overflow. In addition, accessing | 626 // functions are ints, and they should not overflow. In addition, accessing |
625 // local variables creates user-controlled constants in the generated code, | 627 // local variables creates user-controlled constants in the generated code, |
626 // and we don't want too much user-controlled memory inside the code (this was | 628 // and we don't want too much user-controlled memory inside the code (this was |
627 // the reason why this limit was introduced in the first place; see | 629 // the reason why this limit was introduced in the first place; see |
(...skipping 18 matching lines...) Expand all Loading... |
646 | 648 |
647 FunctionLiteral* ParseLazy(); | 649 FunctionLiteral* ParseLazy(); |
648 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 650 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
649 | 651 |
650 Isolate* isolate() { return isolate_; } | 652 Isolate* isolate() { return isolate_; } |
651 CompilationInfo* info() const { return info_; } | 653 CompilationInfo* info() const { return info_; } |
652 | 654 |
653 // Called by ParseProgram after setting up the scanner. | 655 // Called by ParseProgram after setting up the scanner. |
654 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 656 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
655 Handle<String> source); | 657 Handle<String> source); |
| 658 FunctionLiteral* DoParseProgramInner(CompilationInfo* info, Scope** scope, |
| 659 Scope** ad_hoc_eval_scope); |
656 | 660 |
657 void SetCachedData(); | 661 void SetCachedData(); |
658 | 662 |
659 bool inside_with() const { return scope_->inside_with(); } | 663 bool inside_with() const { return scope_->inside_with(); } |
660 ScriptCompiler::CompileOptions compile_options() const { | 664 ScriptCompiler::CompileOptions compile_options() const { |
661 return info_->compile_options(); | 665 return info_->compile_options(); |
662 } | 666 } |
663 Scope* DeclarationScope(VariableMode mode) { | 667 Scope* DeclarationScope(VariableMode mode) { |
664 return IsLexicalVariableMode(mode) | 668 return IsLexicalVariableMode(mode) |
665 ? scope_ : scope_->DeclarationScope(); | 669 ? scope_ : scope_->DeclarationScope(); |
666 } | 670 } |
667 | 671 |
668 // All ParseXXX functions take as the last argument an *ok parameter | 672 // All ParseXXX functions take as the last argument an *ok parameter |
669 // which is set to false if parsing failed; it is unchanged otherwise. | 673 // which is set to false if parsing failed; it is unchanged otherwise. |
670 // By making the 'exception handling' explicit, we are forced to check | 674 // By making the 'exception handling' explicit, we are forced to check |
671 // for failure at the call sites. | 675 // for failure at the call sites. |
672 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 676 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
673 bool is_eval, bool is_global, bool* ok); | 677 bool is_eval, bool is_global, |
| 678 Scope** ad_hoc_eval_scope, bool* ok); |
674 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, | 679 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, |
675 bool* ok); | 680 bool* ok); |
676 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, | 681 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, |
677 bool* ok); | 682 bool* ok); |
678 Module* ParseModule(bool* ok); | 683 Module* ParseModule(bool* ok); |
679 Module* ParseModuleLiteral(bool* ok); | 684 Module* ParseModuleLiteral(bool* ok); |
680 Module* ParseModulePath(bool* ok); | 685 Module* ParseModulePath(bool* ok); |
681 Module* ParseModuleVariable(bool* ok); | 686 Module* ParseModuleVariable(bool* ok); |
682 Module* ParseModuleUrl(bool* ok); | 687 Module* ParseModuleUrl(bool* ok); |
683 Module* ParseModuleSpecifier(bool* ok); | 688 Module* ParseModuleSpecifier(bool* ok); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 818 |
814 // Pending errors. | 819 // Pending errors. |
815 bool has_pending_error_; | 820 bool has_pending_error_; |
816 Scanner::Location pending_error_location_; | 821 Scanner::Location pending_error_location_; |
817 const char* pending_error_message_; | 822 const char* pending_error_message_; |
818 const AstRawString* pending_error_arg_; | 823 const AstRawString* pending_error_arg_; |
819 const char* pending_error_char_arg_; | 824 const char* pending_error_char_arg_; |
820 bool pending_error_is_reference_error_; | 825 bool pending_error_is_reference_error_; |
821 | 826 |
822 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 827 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 828 |
| 829 uint32_t hash_seed_; |
823 }; | 830 }; |
824 | 831 |
825 | 832 |
826 bool ParserTraits::IsFutureStrictReserved( | 833 bool ParserTraits::IsFutureStrictReserved( |
827 const AstRawString* identifier) const { | 834 const AstRawString* identifier) const { |
828 return identifier->IsOneByteEqualTo("yield") || | 835 return identifier->IsOneByteEqualTo("yield") || |
829 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); | 836 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
830 } | 837 } |
831 | 838 |
832 | 839 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 private: | 898 private: |
892 static const int kLiteralTypeSlot = 0; | 899 static const int kLiteralTypeSlot = 0; |
893 static const int kElementsSlot = 1; | 900 static const int kElementsSlot = 1; |
894 | 901 |
895 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 902 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
896 }; | 903 }; |
897 | 904 |
898 } } // namespace v8::internal | 905 } } // namespace v8::internal |
899 | 906 |
900 #endif // V8_PARSER_H_ | 907 #endif // V8_PARSER_H_ |
OLD | NEW |