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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 static bool Parse(CompilationInfo* info, | 616 static bool Parse(CompilationInfo* info, |
617 bool allow_lazy = false) { | 617 bool allow_lazy = false) { |
618 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), | 618 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), |
619 info->isolate()->heap()->HashSeed(), | 619 info->isolate()->heap()->HashSeed(), |
620 info->isolate()->unicode_cache()}; | 620 info->isolate()->unicode_cache()}; |
621 Parser parser(info, &parse_info); | 621 Parser parser(info, &parse_info); |
622 parser.set_allow_lazy(allow_lazy); | 622 parser.set_allow_lazy(allow_lazy); |
623 return parser.Parse(); | 623 return parser.Parse(); |
624 } | 624 } |
625 bool Parse(); | 625 bool Parse(); |
| 626 void ParseOnBackground(); |
| 627 |
| 628 // Handle errors detected during parsing, move statistics to Isolate, |
| 629 // internalize strings (move them to the heap). |
| 630 void Internalize(); |
626 | 631 |
627 private: | 632 private: |
628 friend class ParserTraits; | 633 friend class ParserTraits; |
629 | 634 |
630 // Limit the allowed number of local variables in a function. The hard limit | 635 // Limit the allowed number of local variables in a function. The hard limit |
631 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 636 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
632 // functions are ints, and they should not overflow. In addition, accessing | 637 // functions are ints, and they should not overflow. In addition, accessing |
633 // local variables creates user-controlled constants in the generated code, | 638 // local variables creates user-controlled constants in the generated code, |
634 // and we don't want too much user-controlled memory inside the code (this was | 639 // and we don't want too much user-controlled memory inside the code (this was |
635 // the reason why this limit was introduced in the first place; see | 640 // the reason why this limit was introduced in the first place; see |
(...skipping 20 matching lines...) Expand all Loading... |
656 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 661 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
657 | 662 |
658 Isolate* isolate() { return info_->isolate(); } | 663 Isolate* isolate() { return info_->isolate(); } |
659 CompilationInfo* info() const { return info_; } | 664 CompilationInfo* info() const { return info_; } |
660 Handle<Script> script() const { return info_->script(); } | 665 Handle<Script> script() const { return info_->script(); } |
661 AstValueFactory* ast_value_factory() const { | 666 AstValueFactory* ast_value_factory() const { |
662 return info_->ast_value_factory(); | 667 return info_->ast_value_factory(); |
663 } | 668 } |
664 | 669 |
665 // Called by ParseProgram after setting up the scanner. | 670 // Called by ParseProgram after setting up the scanner. |
666 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 671 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, |
667 Handle<String> source); | 672 Scope** ad_hoc_eval_scope); |
668 | 673 |
669 void SetCachedData(); | 674 void SetCachedData(); |
670 | 675 |
671 bool inside_with() const { return scope_->inside_with(); } | 676 bool inside_with() const { return scope_->inside_with(); } |
672 ScriptCompiler::CompileOptions compile_options() const { | 677 ScriptCompiler::CompileOptions compile_options() const { |
673 return info_->compile_options(); | 678 return info_->compile_options(); |
674 } | 679 } |
675 Scope* DeclarationScope(VariableMode mode) { | 680 Scope* DeclarationScope(VariableMode mode) { |
676 return IsLexicalVariableMode(mode) | 681 return IsLexicalVariableMode(mode) |
677 ? scope_ : scope_->DeclarationScope(); | 682 ? scope_ : scope_->DeclarationScope(); |
678 } | 683 } |
679 | 684 |
680 // All ParseXXX functions take as the last argument an *ok parameter | 685 // All ParseXXX functions take as the last argument an *ok parameter |
681 // which is set to false if parsing failed; it is unchanged otherwise. | 686 // which is set to false if parsing failed; it is unchanged otherwise. |
682 // By making the 'exception handling' explicit, we are forced to check | 687 // By making the 'exception handling' explicit, we are forced to check |
683 // for failure at the call sites. | 688 // for failure at the call sites. |
684 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 689 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
685 bool is_eval, bool is_global, bool* ok); | 690 bool is_eval, bool is_global, |
| 691 Scope** ad_hoc_eval_scope, bool* ok); |
686 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, | 692 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, |
687 bool* ok); | 693 bool* ok); |
688 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, | 694 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, |
689 bool* ok); | 695 bool* ok); |
690 Module* ParseModule(bool* ok); | 696 Module* ParseModule(bool* ok); |
691 Module* ParseModuleLiteral(bool* ok); | 697 Module* ParseModuleLiteral(bool* ok); |
692 Module* ParseModulePath(bool* ok); | 698 Module* ParseModulePath(bool* ok); |
693 Module* ParseModuleVariable(bool* ok); | 699 Module* ParseModuleVariable(bool* ok); |
694 Module* ParseModuleUrl(bool* ok); | 700 Module* ParseModuleUrl(bool* ok); |
695 Module* ParseModuleSpecifier(bool* ok); | 701 Module* ParseModuleSpecifier(bool* ok); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 | 804 |
799 // Consumes the ending }. | 805 // Consumes the ending }. |
800 ZoneList<Statement*>* ParseEagerFunctionBody( | 806 ZoneList<Statement*>* ParseEagerFunctionBody( |
801 const AstRawString* function_name, int pos, Variable* fvar, | 807 const AstRawString* function_name, int pos, Variable* fvar, |
802 Token::Value fvar_init_op, bool is_generator, bool* ok); | 808 Token::Value fvar_init_op, bool is_generator, bool* ok); |
803 | 809 |
804 void HandleSourceURLComments(); | 810 void HandleSourceURLComments(); |
805 | 811 |
806 void ThrowPendingError(); | 812 void ThrowPendingError(); |
807 | 813 |
808 // Handle errors detected during parsing, move statistics to Isolate, | |
809 // internalize strings (move them to the heap). | |
810 void Internalize(); | |
811 | |
812 Scanner scanner_; | 814 Scanner scanner_; |
813 PreParser* reusable_preparser_; | 815 PreParser* reusable_preparser_; |
814 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 816 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
815 Target* target_stack_; // for break, continue statements | 817 Target* target_stack_; // for break, continue statements |
816 ParseData* cached_parse_data_; | 818 ParseData* cached_parse_data_; |
817 | 819 |
818 CompilationInfo* info_; | 820 CompilationInfo* info_; |
819 | 821 |
820 // Pending errors. | 822 // Pending errors. |
821 bool has_pending_error_; | 823 bool has_pending_error_; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 private: | 903 private: |
902 static const int kLiteralTypeSlot = 0; | 904 static const int kLiteralTypeSlot = 0; |
903 static const int kElementsSlot = 1; | 905 static const int kElementsSlot = 1; |
904 | 906 |
905 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 907 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
906 }; | 908 }; |
907 | 909 |
908 } } // namespace v8::internal | 910 } } // namespace v8::internal |
909 | 911 |
910 #endif // V8_PARSER_H_ | 912 #endif // V8_PARSER_H_ |
OLD | NEW |