5 #ifndef V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_ 6 #define V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_ 8 #include "src/parsing/preparsed-scope-data.h" 10 #include "src/assert-scope.h" 20 static constexpr
int kMagicValue = 0xC0DE0DE;
22 static constexpr
size_t kUint32Size = 5;
23 static constexpr
size_t kUint8Size = 2;
24 static constexpr
size_t kQuarterMarker = 0;
25 static constexpr
size_t kPlaceholderSize = kUint32Size;
27 static constexpr
size_t kUint32Size = 4;
28 static constexpr
size_t kUint8Size = 1;
29 static constexpr
size_t kPlaceholderSize = 0;
32 static const size_t kSkippableFunctionDataSize =
33 4 * kUint32Size + 1 * kUint8Size;
41 : free_quarters_in_last_byte_(0), backing_store_(zone) {}
43 void WriteUint8(uint8_t data);
44 void WriteQuarter(uint8_t data);
48 void OverwriteFirstUint32(
uint32_t data);
53 size_t size()
const {
return backing_store_.size(); }
60 uint8_t free_quarters_in_last_byte_;
77 : consumed_data_(consumed_data) {
78 consumed_data->data_ = data;
80 consumed_data->has_data_ =
true;
84 :
ReadingScope(parent->scope_data_.get(), parent->GetScopeData()) {}
87 consumed_data_->has_data_ =
false;
93 DISALLOW_HEAP_ALLOCATION(no_gc);
96 void SetPosition(
int position) { index_ = position; }
98 size_t RemainingBytes()
const {
100 return data_.length() - index_;
103 int32_t ReadUint32() {
105 DCHECK_GE(RemainingBytes(), kUint32Size);
107 DCHECK_EQ(data_.get(index_++), kUint32Size);
109 byte* p =
reinterpret_cast<byte*
>(&result);
110 for (
int i = 0;
i < 4; ++
i) {
111 *p++ = data_.get(index_++);
113 stored_quarters_ = 0;
117 uint8_t ReadUint8() {
119 DCHECK_GE(RemainingBytes(), kUint8Size);
121 DCHECK_EQ(data_.get(index_++), kUint8Size);
122 stored_quarters_ = 0;
123 return data_.get(index_++);
126 uint8_t ReadQuarter() {
128 if (stored_quarters_ == 0) {
129 DCHECK_GE(RemainingBytes(), kUint8Size);
131 DCHECK_EQ(data_.get(index_++), kQuarterMarker);
132 stored_byte_ = data_.get(index_++);
133 stored_quarters_ = 4;
136 uint8_t result = (stored_byte_ >> 6) & 3;
137 DCHECK_LE(result, 3);
146 uint8_t stored_quarters_ = 0;
147 uint8_t stored_byte_ = 0;
149 bool has_data_ =
false;
153 BaseConsumedPreParsedScopeData()
154 : scope_data_(new ByteData()), child_index_(0) {}
156 virtual Data GetScopeData() = 0;
158 virtual ProducedPreParsedScopeData* GetChildData(Zone* zone,
159 int child_index) = 0;
161 ProducedPreParsedScopeData* GetDataForSkippableFunction(
162 Zone* zone,
int start_position,
int* end_position,
int* num_parameters,
163 int* num_inner_functions,
bool* uses_super_property,
164 LanguageMode* language_mode)
final;
166 void RestoreScopeAllocationData(DeclarationScope* scope)
final;
169 void VerifyDataStart();
173 void RestoreData(Scope* scope);
174 void RestoreDataForVariable(Variable* var);
175 void RestoreDataForInnerScopes(Scope* scope);
177 std::unique_ptr<ByteData> scope_data_;
182 DISALLOW_COPY_AND_ASSIGN(BaseConsumedPreParsedScopeData);
207 int length()
const {
return static_cast<int>(data_->size()); }
209 uint8_t
get(
int index)
const {
return data_->at(index); }
225 int child_length()
const {
return static_cast<int>(children_.size()); }
230 children_[index] = child;
260 #endif // V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_