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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 static bool Parse(CompilationInfo* info, | 620 static bool Parse(CompilationInfo* info, |
621 bool allow_lazy = false) { | 621 bool allow_lazy = false) { |
622 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), | 622 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), |
623 info->isolate()->heap()->HashSeed(), | 623 info->isolate()->heap()->HashSeed(), |
624 info->isolate()->unicode_cache()}; | 624 info->isolate()->unicode_cache()}; |
625 Parser parser(info, &parse_info); | 625 Parser parser(info, &parse_info); |
626 parser.set_allow_lazy(allow_lazy); | 626 parser.set_allow_lazy(allow_lazy); |
627 return parser.Parse(); | 627 return parser.Parse(); |
628 } | 628 } |
629 bool Parse(); | 629 bool Parse(); |
| 630 void ParseOnBackground(); |
| 631 |
| 632 // Handle errors detected during parsing, move statistics to Isolate, |
| 633 // internalize strings (move them to the heap). |
| 634 void Internalize(); |
630 | 635 |
631 private: | 636 private: |
632 friend class ParserTraits; | 637 friend class ParserTraits; |
633 | 638 |
634 // Limit the allowed number of local variables in a function. The hard limit | 639 // Limit the allowed number of local variables in a function. The hard limit |
635 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 640 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
636 // functions are ints, and they should not overflow. In addition, accessing | 641 // functions are ints, and they should not overflow. In addition, accessing |
637 // local variables creates user-controlled constants in the generated code, | 642 // local variables creates user-controlled constants in the generated code, |
638 // and we don't want too much user-controlled memory inside the code (this was | 643 // and we don't want too much user-controlled memory inside the code (this was |
639 // the reason why this limit was introduced in the first place; see | 644 // the reason why this limit was introduced in the first place; see |
(...skipping 16 matching lines...) Expand all Loading... |
656 // Returns NULL if parsing failed. | 661 // Returns NULL if parsing failed. |
657 FunctionLiteral* ParseProgram(); | 662 FunctionLiteral* ParseProgram(); |
658 | 663 |
659 FunctionLiteral* ParseLazy(); | 664 FunctionLiteral* ParseLazy(); |
660 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 665 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
661 | 666 |
662 Isolate* isolate() { return isolate_; } | 667 Isolate* isolate() { return isolate_; } |
663 CompilationInfo* info() const { return info_; } | 668 CompilationInfo* info() const { return info_; } |
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 808 |
803 // Consumes the ending }. | 809 // Consumes the ending }. |
804 ZoneList<Statement*>* ParseEagerFunctionBody( | 810 ZoneList<Statement*>* ParseEagerFunctionBody( |
805 const AstRawString* function_name, int pos, Variable* fvar, | 811 const AstRawString* function_name, int pos, Variable* fvar, |
806 Token::Value fvar_init_op, bool is_generator, bool* ok); | 812 Token::Value fvar_init_op, bool is_generator, bool* ok); |
807 | 813 |
808 void HandleSourceURLComments(); | 814 void HandleSourceURLComments(); |
809 | 815 |
810 void ThrowPendingError(); | 816 void ThrowPendingError(); |
811 | 817 |
812 // Handle errors detected during parsing, move statistics to Isolate, | |
813 // internalize strings (move them to the heap). | |
814 void Internalize(); | |
815 | |
816 Isolate* isolate_; | 818 Isolate* isolate_; |
817 | 819 |
818 Handle<Script> script_; | 820 Handle<Script> script_; |
819 Scanner scanner_; | 821 Scanner scanner_; |
820 PreParser* reusable_preparser_; | 822 PreParser* reusable_preparser_; |
821 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 823 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
822 Target* target_stack_; // for break, continue statements | 824 Target* target_stack_; // for break, continue statements |
823 ParseData* cached_parse_data_; | 825 ParseData* cached_parse_data_; |
824 AstValueFactory* ast_value_factory_; | 826 AstValueFactory* ast_value_factory_; |
825 | 827 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 private: | 911 private: |
910 static const int kLiteralTypeSlot = 0; | 912 static const int kLiteralTypeSlot = 0; |
911 static const int kElementsSlot = 1; | 913 static const int kElementsSlot = 1; |
912 | 914 |
913 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 915 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
914 }; | 916 }; |
915 | 917 |
916 } } // namespace v8::internal | 918 } } // namespace v8::internal |
917 | 919 |
918 #endif // V8_PARSER_H_ | 920 #endif // V8_PARSER_H_ |
OLD | NEW |