| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return static_cast<StrictMode>(backing_[kStrictModeIndex]); | 75 return static_cast<StrictMode>(backing_[kStrictModeIndex]); |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool is_valid() { return !backing_.is_empty(); } | 78 bool is_valid() { return !backing_.is_empty(); } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 Vector<unsigned> backing_; | 81 Vector<unsigned> backing_; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 | 84 |
| 85 class ScriptDataImpl : public ScriptData { | 85 class ScriptData { |
| 86 public: | 86 public: |
| 87 explicit ScriptDataImpl(Vector<unsigned> store) | 87 explicit ScriptData(Vector<unsigned> store) |
| 88 : store_(store), | 88 : store_(store), |
| 89 owns_store_(true) { } | 89 owns_store_(true) { } |
| 90 | 90 |
| 91 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | 91 // Create an empty ScriptData that is guaranteed to not satisfy |
| 92 // a SanityCheck. | 92 // a SanityCheck. |
| 93 ScriptDataImpl() : owns_store_(false) { } | 93 ScriptData() : owns_store_(false) { } |
| 94 | 94 |
| 95 virtual ~ScriptDataImpl(); | 95 // The created ScriptData won't take ownership of the data. If the alignment |
| 96 // is not correct, this will copy the data (and the created ScriptData will |
| 97 // take ownership of the copy). |
| 98 static ScriptData* New(const char* data, int length); |
| 99 |
| 100 virtual ~ScriptData(); |
| 96 virtual int Length(); | 101 virtual int Length(); |
| 97 virtual const char* Data(); | 102 virtual const char* Data(); |
| 98 virtual bool HasError(); | 103 virtual bool HasError(); |
| 99 | 104 |
| 100 void Initialize(); | 105 void Initialize(); |
| 101 void ReadNextSymbolPosition(); | 106 void ReadNextSymbolPosition(); |
| 102 | 107 |
| 103 FunctionEntry GetFunctionEntry(int start); | 108 FunctionEntry GetFunctionEntry(int start); |
| 104 int GetSymbolIdentifier(); | 109 int GetSymbolIdentifier(); |
| 105 bool SanityCheck(); | 110 bool SanityCheck(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 if (functions_size % FunctionEntry::kSize != 0) return 0; | 126 if (functions_size % FunctionEntry::kSize != 0) return 0; |
| 122 return functions_size / FunctionEntry::kSize; | 127 return functions_size / FunctionEntry::kSize; |
| 123 } | 128 } |
| 124 // The following functions should only be called if SanityCheck has | 129 // The following functions should only be called if SanityCheck has |
| 125 // returned true. | 130 // returned true. |
| 126 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } | 131 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } |
| 127 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } | 132 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } |
| 128 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } | 133 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } |
| 129 | 134 |
| 130 private: | 135 private: |
| 136 // Disable copying and assigning; because of owns_store they won't be correct. |
| 137 ScriptData(const ScriptData&); |
| 138 ScriptData& operator=(const ScriptData&); |
| 139 |
| 131 friend class v8::ScriptCompiler; | 140 friend class v8::ScriptCompiler; |
| 132 Vector<unsigned> store_; | 141 Vector<unsigned> store_; |
| 133 unsigned char* symbol_data_; | 142 unsigned char* symbol_data_; |
| 134 unsigned char* symbol_data_end_; | 143 unsigned char* symbol_data_end_; |
| 135 int function_index_; | 144 int function_index_; |
| 136 bool owns_store_; | 145 bool owns_store_; |
| 137 | 146 |
| 138 unsigned Read(int position) const; | 147 unsigned Read(int position) const; |
| 139 unsigned* ReadAddress(int position) const; | 148 unsigned* ReadAddress(int position) const; |
| 140 // Reads a number from the current symbols | 149 // Reads a number from the current symbols |
| 141 int ReadNumber(byte** source); | 150 int ReadNumber(byte** source); |
| 142 | 151 |
| 143 ScriptDataImpl(const char* backing_store, int length) | |
| 144 : store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)), | |
| 145 length / static_cast<int>(sizeof(unsigned))), | |
| 146 owns_store_(false) { | |
| 147 ASSERT_EQ(0, static_cast<int>( | |
| 148 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned))); | |
| 149 } | |
| 150 | |
| 151 // Read strings written by ParserRecorder::WriteString. | 152 // Read strings written by ParserRecorder::WriteString. |
| 152 static const char* ReadString(unsigned* start, int* chars); | 153 static const char* ReadString(unsigned* start, int* chars); |
| 153 | |
| 154 friend class ScriptData; | |
| 155 }; | 154 }; |
| 156 | 155 |
| 157 | 156 |
| 158 class PreParserApi { | |
| 159 public: | |
| 160 // Pre-parse a character stream and return full preparse data. | |
| 161 // | |
| 162 // This interface is here instead of in preparser.h because it instantiates a | |
| 163 // preparser recorder object that is suited to the parser's purposes. Also, | |
| 164 // the preparser doesn't know about ScriptDataImpl. | |
| 165 static ScriptDataImpl* PreParse(Isolate* isolate, | |
| 166 Utf16CharacterStream* source); | |
| 167 }; | |
| 168 | |
| 169 | |
| 170 // ---------------------------------------------------------------------------- | 157 // ---------------------------------------------------------------------------- |
| 171 // REGEXP PARSING | 158 // REGEXP PARSING |
| 172 | 159 |
| 173 // A BufferedZoneList is an automatically growing list, just like (and backed | 160 // A BufferedZoneList is an automatically growing list, just like (and backed |
| 174 // by) a ZoneList, that is optimized for the case of adding and removing | 161 // by) a ZoneList, that is optimized for the case of adding and removing |
| 175 // a single element. The last element added is stored outside the backing list, | 162 // a single element. The last element added is stored outside the backing list, |
| 176 // and if no more than one element is ever added, the ZoneList isn't even | 163 // and if no more than one element is ever added, the ZoneList isn't even |
| 177 // allocated. | 164 // allocated. |
| 178 // Elements must not be NULL pointers. | 165 // Elements must not be NULL pointers. |
| 179 template <typename T, int initial_size> | 166 template <typename T, int initial_size> |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 Isolate* isolate() { return isolate_; } | 662 Isolate* isolate() { return isolate_; } |
| 676 CompilationInfo* info() const { return info_; } | 663 CompilationInfo* info() const { return info_; } |
| 677 | 664 |
| 678 // Called by ParseProgram after setting up the scanner. | 665 // Called by ParseProgram after setting up the scanner. |
| 679 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 666 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
| 680 Handle<String> source); | 667 Handle<String> source); |
| 681 | 668 |
| 682 // Report syntax error | 669 // Report syntax error |
| 683 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 670 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 684 | 671 |
| 685 void SetCachedData(ScriptDataImpl** data, | 672 void SetCachedData(ScriptData** data, |
| 686 CachedDataMode cached_data_mode) { | 673 CachedDataMode cached_data_mode) { |
| 687 cached_data_mode_ = cached_data_mode; | 674 cached_data_mode_ = cached_data_mode; |
| 688 if (cached_data_mode == NO_CACHED_DATA) { | 675 if (cached_data_mode == NO_CACHED_DATA) { |
| 689 cached_data_ = NULL; | 676 cached_data_ = NULL; |
| 690 } else { | 677 } else { |
| 691 ASSERT(data != NULL); | 678 ASSERT(data != NULL); |
| 692 cached_data_ = data; | 679 cached_data_ = data; |
| 693 symbol_cache_.Initialize(*data ? (*data)->symbol_count() : 0, zone()); | 680 symbol_cache_.Initialize(*data ? (*data)->symbol_count() : 0, zone()); |
| 694 } | 681 } |
| 695 } | 682 } |
| 696 | 683 |
| 697 bool inside_with() const { return scope_->inside_with(); } | 684 bool inside_with() const { return scope_->inside_with(); } |
| 698 ScriptDataImpl** cached_data() const { return cached_data_; } | 685 ScriptData** cached_data() const { return cached_data_; } |
| 699 CachedDataMode cached_data_mode() const { return cached_data_mode_; } | 686 CachedDataMode cached_data_mode() const { return cached_data_mode_; } |
| 700 Scope* DeclarationScope(VariableMode mode) { | 687 Scope* DeclarationScope(VariableMode mode) { |
| 701 return IsLexicalVariableMode(mode) | 688 return IsLexicalVariableMode(mode) |
| 702 ? scope_ : scope_->DeclarationScope(); | 689 ? scope_ : scope_->DeclarationScope(); |
| 703 } | 690 } |
| 704 | 691 |
| 705 // All ParseXXX functions take as the last argument an *ok parameter | 692 // All ParseXXX functions take as the last argument an *ok parameter |
| 706 // which is set to false if parsing failed; it is unchanged otherwise. | 693 // which is set to false if parsing failed; it is unchanged otherwise. |
| 707 // By making the 'exception handling' explicit, we are forced to check | 694 // By making the 'exception handling' explicit, we are forced to check |
| 708 // for failure at the call sites. | 695 // for failure at the call sites. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 SingletonLogger* logger); | 794 SingletonLogger* logger); |
| 808 | 795 |
| 809 Isolate* isolate_; | 796 Isolate* isolate_; |
| 810 ZoneList<Handle<String> > symbol_cache_; | 797 ZoneList<Handle<String> > symbol_cache_; |
| 811 | 798 |
| 812 Handle<Script> script_; | 799 Handle<Script> script_; |
| 813 Scanner scanner_; | 800 Scanner scanner_; |
| 814 PreParser* reusable_preparser_; | 801 PreParser* reusable_preparser_; |
| 815 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 802 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 816 Target* target_stack_; // for break, continue statements | 803 Target* target_stack_; // for break, continue statements |
| 817 ScriptDataImpl** cached_data_; | 804 ScriptData** cached_data_; |
| 818 CachedDataMode cached_data_mode_; | 805 CachedDataMode cached_data_mode_; |
| 819 | 806 |
| 820 CompilationInfo* info_; | 807 CompilationInfo* info_; |
| 821 }; | 808 }; |
| 822 | 809 |
| 823 | 810 |
| 824 // Support for handling complex values (array and object literals) that | 811 // Support for handling complex values (array and object literals) that |
| 825 // can be fully handled at compile time. | 812 // can be fully handled at compile time. |
| 826 class CompileTimeValue: public AllStatic { | 813 class CompileTimeValue: public AllStatic { |
| 827 public: | 814 public: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 845 private: | 832 private: |
| 846 static const int kLiteralTypeSlot = 0; | 833 static const int kLiteralTypeSlot = 0; |
| 847 static const int kElementsSlot = 1; | 834 static const int kElementsSlot = 1; |
| 848 | 835 |
| 849 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 836 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 850 }; | 837 }; |
| 851 | 838 |
| 852 } } // namespace v8::internal | 839 } } // namespace v8::internal |
| 853 | 840 |
| 854 #endif // V8_PARSER_H_ | 841 #endif // V8_PARSER_H_ |
| OLD | NEW |