| 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(); |
| 630 | 631 |
| 631 private: | 632 private: |
| 632 friend class ParserTraits; | 633 friend class ParserTraits; |
| 634 friend class v8::ScriptCompiler; |
| 633 | 635 |
| 634 // Limit the allowed number of local variables in a function. The hard limit | 636 // Limit the allowed number of local variables in a function. The hard limit |
| 635 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 637 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
| 636 // functions are ints, and they should not overflow. In addition, accessing | 638 // functions are ints, and they should not overflow. In addition, accessing |
| 637 // local variables creates user-controlled constants in the generated code, | 639 // 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 | 640 // 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 | 641 // the reason why this limit was introduced in the first place; see |
| 640 // https://codereview.chromium.org/7003030/ ). | 642 // https://codereview.chromium.org/7003030/ ). |
| 641 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 | 643 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 |
| 642 | 644 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 656 // Returns NULL if parsing failed. | 658 // Returns NULL if parsing failed. |
| 657 FunctionLiteral* ParseProgram(); | 659 FunctionLiteral* ParseProgram(); |
| 658 | 660 |
| 659 FunctionLiteral* ParseLazy(); | 661 FunctionLiteral* ParseLazy(); |
| 660 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 662 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
| 661 | 663 |
| 662 Isolate* isolate() { return isolate_; } | 664 Isolate* isolate() { return isolate_; } |
| 663 CompilationInfo* info() const { return info_; } | 665 CompilationInfo* info() const { return info_; } |
| 664 | 666 |
| 665 // Called by ParseProgram after setting up the scanner. | 667 // Called by ParseProgram after setting up the scanner. |
| 666 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 668 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, |
| 667 Handle<String> source); | 669 Scope** ad_hoc_eval_scope); |
| 668 | 670 |
| 669 void SetCachedData(); | 671 void SetCachedData(); |
| 670 | 672 |
| 671 bool inside_with() const { return scope_->inside_with(); } | 673 bool inside_with() const { return scope_->inside_with(); } |
| 672 ScriptCompiler::CompileOptions compile_options() const { | 674 ScriptCompiler::CompileOptions compile_options() const { |
| 673 return info_->compile_options(); | 675 return info_->compile_options(); |
| 674 } | 676 } |
| 675 Scope* DeclarationScope(VariableMode mode) { | 677 Scope* DeclarationScope(VariableMode mode) { |
| 676 return IsLexicalVariableMode(mode) | 678 return IsLexicalVariableMode(mode) |
| 677 ? scope_ : scope_->DeclarationScope(); | 679 ? scope_ : scope_->DeclarationScope(); |
| 678 } | 680 } |
| 679 | 681 |
| 680 // All ParseXXX functions take as the last argument an *ok parameter | 682 // All ParseXXX functions take as the last argument an *ok parameter |
| 681 // which is set to false if parsing failed; it is unchanged otherwise. | 683 // which is set to false if parsing failed; it is unchanged otherwise. |
| 682 // By making the 'exception handling' explicit, we are forced to check | 684 // By making the 'exception handling' explicit, we are forced to check |
| 683 // for failure at the call sites. | 685 // for failure at the call sites. |
| 684 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 686 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
| 685 bool is_eval, bool is_global, bool* ok); | 687 bool is_eval, bool is_global, |
| 688 Scope** ad_hoc_eval_scope, bool* ok); |
| 686 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, | 689 Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels, |
| 687 bool* ok); | 690 bool* ok); |
| 688 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, | 691 Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names, |
| 689 bool* ok); | 692 bool* ok); |
| 690 Module* ParseModule(bool* ok); | 693 Module* ParseModule(bool* ok); |
| 691 Module* ParseModuleLiteral(bool* ok); | 694 Module* ParseModuleLiteral(bool* ok); |
| 692 Module* ParseModulePath(bool* ok); | 695 Module* ParseModulePath(bool* ok); |
| 693 Module* ParseModuleVariable(bool* ok); | 696 Module* ParseModuleVariable(bool* ok); |
| 694 Module* ParseModuleUrl(bool* ok); | 697 Module* ParseModuleUrl(bool* ok); |
| 695 Module* ParseModuleSpecifier(bool* ok); | 698 Module* ParseModuleSpecifier(bool* ok); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 private: | 912 private: |
| 910 static const int kLiteralTypeSlot = 0; | 913 static const int kLiteralTypeSlot = 0; |
| 911 static const int kElementsSlot = 1; | 914 static const int kElementsSlot = 1; |
| 912 | 915 |
| 913 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 916 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 914 }; | 917 }; |
| 915 | 918 |
| 916 } } // namespace v8::internal | 919 } } // namespace v8::internal |
| 917 | 920 |
| 918 #endif // V8_PARSER_H_ | 921 #endif // V8_PARSER_H_ |
| OLD | NEW |