| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_PARSER_H_ | 28 #ifndef V8_PARSER_H_ |
| 29 #define V8_PARSER_H_ | 29 #define V8_PARSER_H_ |
| 30 | 30 |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "ast.h" | 32 #include "ast.h" |
| 33 #include "compiler.h" // For CachedDataMode |
| 33 #include "preparse-data-format.h" | 34 #include "preparse-data-format.h" |
| 34 #include "preparse-data.h" | 35 #include "preparse-data.h" |
| 35 #include "scopes.h" | 36 #include "scopes.h" |
| 36 #include "preparser.h" | 37 #include "preparser.h" |
| 37 | 38 |
| 38 namespace v8 { | 39 namespace v8 { |
| 40 class ScriptCompiler; |
| 41 |
| 39 namespace internal { | 42 namespace internal { |
| 40 | 43 |
| 41 class CompilationInfo; | 44 class CompilationInfo; |
| 42 class ParserLog; | 45 class ParserLog; |
| 43 class PositionStack; | 46 class PositionStack; |
| 44 class Target; | 47 class Target; |
| 45 | 48 |
| 46 template <typename T> class ZoneListWrapper; | 49 template <typename T> class ZoneListWrapper; |
| 47 | 50 |
| 48 | 51 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 ? store_[PreparseDataConstants::kSymbolCountOffset] | 113 ? store_[PreparseDataConstants::kSymbolCountOffset] |
| 111 : 0; | 114 : 0; |
| 112 } | 115 } |
| 113 // The following functions should only be called if SanityCheck has | 116 // The following functions should only be called if SanityCheck has |
| 114 // returned true. | 117 // returned true. |
| 115 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } | 118 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } |
| 116 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } | 119 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } |
| 117 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } | 120 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } |
| 118 | 121 |
| 119 private: | 122 private: |
| 123 friend class v8::ScriptCompiler; |
| 120 Vector<unsigned> store_; | 124 Vector<unsigned> store_; |
| 121 unsigned char* symbol_data_; | 125 unsigned char* symbol_data_; |
| 122 unsigned char* symbol_data_end_; | 126 unsigned char* symbol_data_end_; |
| 123 int function_index_; | 127 int function_index_; |
| 124 bool owns_store_; | 128 bool owns_store_; |
| 125 | 129 |
| 126 unsigned Read(int position); | 130 unsigned Read(int position); |
| 127 unsigned* ReadAddress(int position); | 131 unsigned* ReadAddress(int position); |
| 128 // Reads a number from the current symbols | 132 // Reads a number from the current symbols |
| 129 int ReadNumber(byte** source); | 133 int ReadNumber(byte** source); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 Isolate* isolate() { return isolate_; } | 646 Isolate* isolate() { return isolate_; } |
| 643 CompilationInfo* info() const { return info_; } | 647 CompilationInfo* info() const { return info_; } |
| 644 | 648 |
| 645 // Called by ParseProgram after setting up the scanner. | 649 // Called by ParseProgram after setting up the scanner. |
| 646 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 650 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
| 647 Handle<String> source); | 651 Handle<String> source); |
| 648 | 652 |
| 649 // Report syntax error | 653 // Report syntax error |
| 650 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 654 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 651 | 655 |
| 652 void set_pre_parse_data(ScriptDataImpl *data) { | 656 void SetCachedData(ScriptDataImpl** data, |
| 653 pre_parse_data_ = data; | 657 CachedDataMode cached_data_mode) { |
| 654 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); | 658 cached_data_mode_ = cached_data_mode; |
| 659 if (cached_data_mode == NO_CACHED_DATA) { |
| 660 cached_data_ = NULL; |
| 661 } else { |
| 662 ASSERT(data != NULL); |
| 663 cached_data_ = data; |
| 664 symbol_cache_.Initialize(*data ? (*data)->symbol_count() : 0, zone()); |
| 665 } |
| 655 } | 666 } |
| 656 | 667 |
| 657 bool inside_with() const { return scope_->inside_with(); } | 668 bool inside_with() const { return scope_->inside_with(); } |
| 658 Mode mode() const { return mode_; } | 669 Mode mode() const { return mode_; } |
| 659 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 670 ScriptDataImpl** cached_data() const { return cached_data_; } |
| 671 CachedDataMode cached_data_mode() const { return cached_data_mode_; } |
| 660 Scope* DeclarationScope(VariableMode mode) { | 672 Scope* DeclarationScope(VariableMode mode) { |
| 661 return IsLexicalVariableMode(mode) | 673 return IsLexicalVariableMode(mode) |
| 662 ? scope_ : scope_->DeclarationScope(); | 674 ? scope_ : scope_->DeclarationScope(); |
| 663 } | 675 } |
| 664 | 676 |
| 665 // All ParseXXX functions take as the last argument an *ok parameter | 677 // All ParseXXX functions take as the last argument an *ok parameter |
| 666 // which is set to false if parsing failed; it is unchanged otherwise. | 678 // which is set to false if parsing failed; it is unchanged otherwise. |
| 667 // By making the 'exception handling' explicit, we are forced to check | 679 // By making the 'exception handling' explicit, we are forced to check |
| 668 // for failure at the call sites. | 680 // for failure at the call sites. |
| 669 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 681 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 bool TargetStackContainsLabel(Handle<String> label); | 775 bool TargetStackContainsLabel(Handle<String> label); |
| 764 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); | 776 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); |
| 765 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 777 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
| 766 | 778 |
| 767 void RegisterTargetUse(Label* target, Target* stop); | 779 void RegisterTargetUse(Label* target, Target* stop); |
| 768 | 780 |
| 769 // Factory methods. | 781 // Factory methods. |
| 770 | 782 |
| 771 Scope* NewScope(Scope* parent, ScopeType type); | 783 Scope* NewScope(Scope* parent, ScopeType type); |
| 772 | 784 |
| 773 Handle<String> LookupSymbol(int symbol_id); | |
| 774 | |
| 775 Handle<String> LookupCachedSymbol(int symbol_id); | 785 Handle<String> LookupCachedSymbol(int symbol_id); |
| 776 | 786 |
| 777 // Generate AST node that throw a ReferenceError with the given type. | 787 // Generate AST node that throw a ReferenceError with the given type. |
| 778 Expression* NewThrowReferenceError(Handle<String> type); | 788 Expression* NewThrowReferenceError(Handle<String> type); |
| 779 | 789 |
| 780 // Generate AST node that throw a SyntaxError with the given | 790 // Generate AST node that throw a SyntaxError with the given |
| 781 // type. The first argument may be null (in the handle sense) in | 791 // type. The first argument may be null (in the handle sense) in |
| 782 // which case no arguments are passed to the constructor. | 792 // which case no arguments are passed to the constructor. |
| 783 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); | 793 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); |
| 784 | 794 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 797 SingletonLogger* logger); | 807 SingletonLogger* logger); |
| 798 | 808 |
| 799 Isolate* isolate_; | 809 Isolate* isolate_; |
| 800 ZoneList<Handle<String> > symbol_cache_; | 810 ZoneList<Handle<String> > symbol_cache_; |
| 801 | 811 |
| 802 Handle<Script> script_; | 812 Handle<Script> script_; |
| 803 Scanner scanner_; | 813 Scanner scanner_; |
| 804 PreParser* reusable_preparser_; | 814 PreParser* reusable_preparser_; |
| 805 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 815 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 806 Target* target_stack_; // for break, continue statements | 816 Target* target_stack_; // for break, continue statements |
| 807 ScriptDataImpl* pre_parse_data_; | 817 ScriptDataImpl** cached_data_; |
| 818 CachedDataMode cached_data_mode_; |
| 808 | 819 |
| 809 Mode mode_; | 820 Mode mode_; |
| 810 | 821 |
| 811 CompilationInfo* info_; | 822 CompilationInfo* info_; |
| 812 }; | 823 }; |
| 813 | 824 |
| 814 | 825 |
| 815 // Support for handling complex values (array and object literals) that | 826 // Support for handling complex values (array and object literals) that |
| 816 // can be fully handled at compile time. | 827 // can be fully handled at compile time. |
| 817 class CompileTimeValue: public AllStatic { | 828 class CompileTimeValue: public AllStatic { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 836 private: | 847 private: |
| 837 static const int kLiteralTypeSlot = 0; | 848 static const int kLiteralTypeSlot = 0; |
| 838 static const int kElementsSlot = 1; | 849 static const int kElementsSlot = 1; |
| 839 | 850 |
| 840 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 851 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 841 }; | 852 }; |
| 842 | 853 |
| 843 } } // namespace v8::internal | 854 } } // namespace v8::internal |
| 844 | 855 |
| 845 #endif // V8_PARSER_H_ | 856 #endif // V8_PARSER_H_ |
| OLD | NEW |