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 ScriptDataImpl { |
Sven Panne
2014/04/07 12:44:44
Rename this to simply ScriptData, or perhaps even
marja
2014/04/09 12:53:55
Done.
| |
86 public: | 86 public: |
87 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | |
88 // a SanityCheck. | |
89 ScriptDataImpl() : owns_store_(false) { } | |
90 | |
91 // Won't take ownership of the data. | |
92 ScriptDataImpl(const char* data, int length); | |
93 | |
87 explicit ScriptDataImpl(Vector<unsigned> store) | 94 explicit ScriptDataImpl(Vector<unsigned> store) |
88 : store_(store), | 95 : store_(store), |
89 owns_store_(true) { } | 96 owns_store_(true) { } |
90 | 97 |
91 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | 98 // ScriptDataImpl won't take ownership of data. If the alignment is not |
92 // a SanityCheck. | 99 // correct, this will copy the data (and take ownership of the copy). |
93 ScriptDataImpl() : owns_store_(false) { } | 100 static ScriptDataImpl* New(const char* data, int length); |
Sven Panne
2014/04/07 12:44:44
I can't see the implementation of this function.
marja
2014/04/09 12:53:55
Oops. This doesn't exist, ScriptDataImpl(const cha
| |
94 | 101 |
95 virtual ~ScriptDataImpl(); | 102 virtual ~ScriptDataImpl(); |
96 virtual int Length(); | 103 virtual int Length(); |
97 virtual const char* Data(); | 104 virtual const char* Data(); |
98 virtual bool HasError(); | 105 virtual bool HasError(); |
99 | 106 |
100 void Initialize(); | 107 void Initialize(); |
101 void ReadNextSymbolPosition(); | 108 void ReadNextSymbolPosition(); |
102 | 109 |
103 FunctionEntry GetFunctionEntry(int start); | 110 FunctionEntry GetFunctionEntry(int start); |
(...skipping 17 matching lines...) Expand all Loading... | |
121 if (functions_size % FunctionEntry::kSize != 0) return 0; | 128 if (functions_size % FunctionEntry::kSize != 0) return 0; |
122 return functions_size / FunctionEntry::kSize; | 129 return functions_size / FunctionEntry::kSize; |
123 } | 130 } |
124 // The following functions should only be called if SanityCheck has | 131 // The following functions should only be called if SanityCheck has |
125 // returned true. | 132 // returned true. |
126 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } | 133 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } |
127 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } | 134 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } |
128 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } | 135 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } |
129 | 136 |
130 private: | 137 private: |
138 // Disable copying and assigning; because of owns_store they won't be correct. | |
139 ScriptDataImpl(const ScriptDataImpl&); | |
140 ScriptDataImpl& operator=(const ScriptDataImpl&); | |
141 | |
131 friend class v8::ScriptCompiler; | 142 friend class v8::ScriptCompiler; |
132 Vector<unsigned> store_; | 143 Vector<unsigned> store_; |
133 unsigned char* symbol_data_; | 144 unsigned char* symbol_data_; |
134 unsigned char* symbol_data_end_; | 145 unsigned char* symbol_data_end_; |
135 int function_index_; | 146 int function_index_; |
136 bool owns_store_; | 147 bool owns_store_; |
137 | 148 |
138 unsigned Read(int position) const; | 149 unsigned Read(int position) const; |
139 unsigned* ReadAddress(int position) const; | 150 unsigned* ReadAddress(int position) const; |
140 // Reads a number from the current symbols | 151 // Reads a number from the current symbols |
141 int ReadNumber(byte** source); | 152 int ReadNumber(byte** source); |
142 | 153 |
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. | 154 // Read strings written by ParserRecorder::WriteString. |
152 static const char* ReadString(unsigned* start, int* chars); | 155 static const char* ReadString(unsigned* start, int* chars); |
153 | |
154 friend class ScriptData; | |
155 }; | 156 }; |
156 | 157 |
157 | 158 |
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 // ---------------------------------------------------------------------------- | 159 // ---------------------------------------------------------------------------- |
171 // REGEXP PARSING | 160 // REGEXP PARSING |
172 | 161 |
173 // A BufferedZoneList is an automatically growing list, just like (and backed | 162 // 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 | 163 // 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, | 164 // 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 | 165 // and if no more than one element is ever added, the ZoneList isn't even |
177 // allocated. | 166 // allocated. |
178 // Elements must not be NULL pointers. | 167 // Elements must not be NULL pointers. |
179 template <typename T, int initial_size> | 168 template <typename T, int initial_size> |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 private: | 834 private: |
846 static const int kLiteralTypeSlot = 0; | 835 static const int kLiteralTypeSlot = 0; |
847 static const int kElementsSlot = 1; | 836 static const int kElementsSlot = 1; |
848 | 837 |
849 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 838 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
850 }; | 839 }; |
851 | 840 |
852 } } // namespace v8::internal | 841 } } // namespace v8::internal |
853 | 842 |
854 #endif // V8_PARSER_H_ | 843 #endif // V8_PARSER_H_ |
OLD | NEW |