OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 #include "src/parsing/preparsed-scope-data.h" | 5 #include "src/parsing/preparsed-scope-data.h" |
6 | 6 |
| 7 #include "src/ast/variables.h" |
| 8 #include "src/objects-inl.h" |
| 9 |
7 namespace v8 { | 10 namespace v8 { |
8 namespace internal { | 11 namespace internal { |
9 | 12 |
10 PreParsedScopeData::ScopeScope::ScopeScope(PreParsedScopeData* data, | 13 PreParsedScopeData::ScopeScope::ScopeScope(PreParsedScopeData* data, |
11 ScopeType scope_type, | 14 ScopeType scope_type, |
12 int start_position, int end_position) | 15 int start_position, int end_position) |
13 : data_(data), | 16 : data_(data), |
14 previous_scope_(data->current_scope_), | 17 previous_scope_(data->current_scope_), |
15 inner_scope_count_(0), | 18 inner_scope_count_(0), |
16 variable_count_(0) { | 19 variable_count_(0) { |
(...skipping 11 matching lines...) Expand all Loading... |
28 data->backing_store_.push_back(-1); | 31 data->backing_store_.push_back(-1); |
29 data->backing_store_.push_back(-1); | 32 data->backing_store_.push_back(-1); |
30 } | 33 } |
31 | 34 |
32 PreParsedScopeData::ScopeScope::~ScopeScope() { | 35 PreParsedScopeData::ScopeScope::~ScopeScope() { |
33 data_->current_scope_ = previous_scope_; | 36 data_->current_scope_ = previous_scope_; |
34 data_->backing_store_[index_in_data_] = inner_scope_count_; | 37 data_->backing_store_[index_in_data_] = inner_scope_count_; |
35 data_->backing_store_[index_in_data_ + 1] = variable_count_; | 38 data_->backing_store_[index_in_data_ + 1] = variable_count_; |
36 } | 39 } |
37 | 40 |
38 void PreParsedScopeData::ScopeScope::AddVariable(VariableLocation location, | 41 void PreParsedScopeData::ScopeScope::MaybeAddVariable(Variable* var) { |
39 bool maybe_assigned) { | 42 if (var->mode() == VAR || var->mode() == LET || var->mode() == CONST) { |
40 data_->backing_store_.push_back(location); | 43 #ifdef DEBUG |
41 data_->backing_store_.push_back(maybe_assigned); | 44 // For tests (which check that the data is about the same variables). |
42 ++variable_count_; | 45 const AstRawString* name = var->raw_name(); |
| 46 data_->backing_store_.push_back(name->length()); |
| 47 for (int i = 0; i < name->length(); ++i) { |
| 48 data_->backing_store_.push_back(name->raw_data()[i]); |
| 49 } |
| 50 #endif |
| 51 data_->backing_store_.push_back(var->location()); |
| 52 data_->backing_store_.push_back(var->maybe_assigned()); |
| 53 ++variable_count_; |
| 54 } |
43 } | 55 } |
44 | 56 |
45 } // namespace internal | 57 } // namespace internal |
46 } // namespace v8 | 58 } // namespace v8 |
OLD | NEW |