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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, | 597 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
598 bool* ok); | 598 bool* ok); |
599 | 599 |
600 private: | 600 private: |
601 Parser* parser_; | 601 Parser* parser_; |
602 }; | 602 }; |
603 | 603 |
604 | 604 |
605 class Parser : public ParserBase<ParserTraits> { | 605 class Parser : public ParserBase<ParserTraits> { |
606 public: | 606 public: |
607 explicit Parser(CompilationInfo* info); | 607 Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed); |
608 ~Parser() { | 608 ~Parser() { |
609 delete reusable_preparser_; | 609 delete reusable_preparser_; |
610 reusable_preparser_ = NULL; | 610 reusable_preparser_ = NULL; |
611 delete cached_parse_data_; | 611 delete cached_parse_data_; |
612 cached_parse_data_ = NULL; | 612 cached_parse_data_ = NULL; |
613 } | 613 } |
614 | 614 |
615 // Parses the source code represented by the compilation info and sets its | 615 // Parses the source code represented by the compilation info and sets its |
616 // function literal. Returns false (and deallocates any allocated AST | 616 // function literal. Returns false (and deallocates any allocated AST |
617 // nodes) if parsing failed. | 617 // nodes) if parsing failed. |
618 static bool Parse(CompilationInfo* info, | 618 static bool Parse(CompilationInfo* info, |
619 bool allow_lazy = false) { | 619 bool allow_lazy = false) { |
620 Parser parser(info); | 620 Parser parser(info, info->isolate()->stack_guard()->real_climit(), |
| 621 info->isolate()->heap()->HashSeed()); |
621 parser.set_allow_lazy(allow_lazy); | 622 parser.set_allow_lazy(allow_lazy); |
622 return parser.Parse(); | 623 return parser.Parse(); |
623 } | 624 } |
624 bool Parse(); | 625 bool Parse(); |
| 626 void ParseOnBackground(); |
625 | 627 |
626 private: | 628 private: |
627 friend class ParserTraits; | 629 friend class ParserTraits; |
628 | 630 |
629 // Limit the allowed number of local variables in a function. The hard limit | 631 // Limit the allowed number of local variables in a function. The hard limit |
630 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 632 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
631 // functions are ints, and they should not overflow. In addition, accessing | 633 // functions are ints, and they should not overflow. In addition, accessing |
632 // local variables creates user-controlled constants in the generated code, | 634 // local variables creates user-controlled constants in the generated code, |
633 // and we don't want too much user-controlled memory inside the code (this was | 635 // and we don't want too much user-controlled memory inside the code (this was |
634 // the reason why this limit was introduced in the first place; see | 636 // the reason why this limit was introduced in the first place; see |
(...skipping 18 matching lines...) Expand all Loading... |
653 | 655 |
654 FunctionLiteral* ParseLazy(); | 656 FunctionLiteral* ParseLazy(); |
655 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 657 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
656 | 658 |
657 Isolate* isolate() { return isolate_; } | 659 Isolate* isolate() { return isolate_; } |
658 CompilationInfo* info() const { return info_; } | 660 CompilationInfo* info() const { return info_; } |
659 | 661 |
660 // Called by ParseProgram after setting up the scanner. | 662 // Called by ParseProgram after setting up the scanner. |
661 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 663 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
662 Handle<String> source); | 664 Handle<String> source); |
| 665 FunctionLiteral* DoParseProgramInner(CompilationInfo* info, Scope** scope, |
| 666 Scope** ad_hoc_eval_scope); |
663 | 667 |
664 void SetCachedData(); | 668 void SetCachedData(); |
665 | 669 |
666 bool inside_with() const { return scope_->inside_with(); } | 670 bool inside_with() const { return scope_->inside_with(); } |
667 ScriptCompiler::CompileOptions compile_options() const { | 671 ScriptCompiler::CompileOptions compile_options() const { |
668 return info_->compile_options(); | 672 return info_->compile_options(); |
669 } | 673 } |
670 Scope* DeclarationScope(VariableMode mode) { | 674 Scope* DeclarationScope(VariableMode mode) { |
671 return IsLexicalVariableMode(mode) | 675 return IsLexicalVariableMode(mode) |
672 ? scope_ : scope_->DeclarationScope(); | 676 ? scope_ : scope_->DeclarationScope(); |
673 } | 677 } |
674 | 678 |
675 // All ParseXXX functions take as the last argument an *ok parameter | 679 // All ParseXXX functions take as the last argument an *ok parameter |
676 // which is set to false if parsing failed; it is unchanged otherwise. | 680 // which is set to false if parsing failed; it is unchanged otherwise. |
677 // By making the 'exception handling' explicit, we are forced to check | 681 // By making the 'exception handling' explicit, we are forced to check |
678 // for failure at the call sites. | 682 // for failure at the call sites. |
679 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 683 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
680 bool is_eval, bool is_global, bool* ok); | 684 bool is_eval, bool is_global, |
| 685 Scope** ad_hoc_eval_scope, bool* ok); |
681 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, | 686 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, |
682 bool* ok); | 687 bool* ok); |
683 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, | 688 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, |
684 bool* ok); | 689 bool* ok); |
685 Module* ParseModule(bool* ok); | 690 Module* ParseModule(bool* ok); |
686 Module* ParseModuleLiteral(bool* ok); | 691 Module* ParseModuleLiteral(bool* ok); |
687 Module* ParseModulePath(bool* ok); | 692 Module* ParseModulePath(bool* ok); |
688 Module* ParseModuleVariable(bool* ok); | 693 Module* ParseModuleVariable(bool* ok); |
689 Module* ParseModuleUrl(bool* ok); | 694 Module* ParseModuleUrl(bool* ok); |
690 Module* ParseModuleSpecifier(bool* ok); | 695 Module* ParseModuleSpecifier(bool* ok); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 825 |
821 // Pending errors. | 826 // Pending errors. |
822 bool has_pending_error_; | 827 bool has_pending_error_; |
823 Scanner::Location pending_error_location_; | 828 Scanner::Location pending_error_location_; |
824 const char* pending_error_message_; | 829 const char* pending_error_message_; |
825 const AstRawString* pending_error_arg_; | 830 const AstRawString* pending_error_arg_; |
826 const char* pending_error_char_arg_; | 831 const char* pending_error_char_arg_; |
827 bool pending_error_is_reference_error_; | 832 bool pending_error_is_reference_error_; |
828 | 833 |
829 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 834 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 835 |
| 836 uint32_t hash_seed_; |
830 }; | 837 }; |
831 | 838 |
832 | 839 |
833 bool ParserTraits::IsFutureStrictReserved( | 840 bool ParserTraits::IsFutureStrictReserved( |
834 const AstRawString* identifier) const { | 841 const AstRawString* identifier) const { |
835 return identifier->IsOneByteEqualTo("yield") || | 842 return identifier->IsOneByteEqualTo("yield") || |
836 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); | 843 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
837 } | 844 } |
838 | 845 |
839 | 846 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 private: | 905 private: |
899 static const int kLiteralTypeSlot = 0; | 906 static const int kLiteralTypeSlot = 0; |
900 static const int kElementsSlot = 1; | 907 static const int kElementsSlot = 1; |
901 | 908 |
902 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 909 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
903 }; | 910 }; |
904 | 911 |
905 } } // namespace v8::internal | 912 } } // namespace v8::internal |
906 | 913 |
907 #endif // V8_PARSER_H_ | 914 #endif // V8_PARSER_H_ |
OLD | NEW |