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