Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: src/preparser.h

Issue 1212473002: [destructuring] Re-index materialized literals in arrow function parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 typename Traits::Type::Factory* factory); 174 typename Traits::Type::Factory* factory);
175 ~FunctionState(); 175 ~FunctionState();
176 176
177 int NextMaterializedLiteralIndex() { 177 int NextMaterializedLiteralIndex() {
178 return next_materialized_literal_index_++; 178 return next_materialized_literal_index_++;
179 } 179 }
180 int materialized_literal_count() { 180 int materialized_literal_count() {
181 return next_materialized_literal_index_; 181 return next_materialized_literal_index_;
182 } 182 }
183 183
184 void SkipMaterializedLiterals(int count) {
185 next_materialized_literal_index_ += count;
186 }
187
184 void AddProperty() { expected_property_count_++; } 188 void AddProperty() { expected_property_count_++; }
185 int expected_property_count() { return expected_property_count_; } 189 int expected_property_count() { return expected_property_count_; }
186 190
187 Scanner::Location this_location() const { return this_location_; } 191 Scanner::Location this_location() const { return this_location_; }
188 Scanner::Location super_location() const { return super_location_; } 192 Scanner::Location super_location() const { return super_location_; }
189 Scanner::Location return_location() const { return return_location_; } 193 Scanner::Location return_location() const { return return_location_; }
190 void set_this_location(Scanner::Location location) { 194 void set_this_location(Scanner::Location location) {
191 this_location_ = location; 195 this_location_ = location;
192 } 196 }
193 void set_super_location(Scanner::Location location) { 197 void set_super_location(Scanner::Location location) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // what it was before the arguments were first seen. 259 // what it was before the arguments were first seen.
256 class Checkpoint BASE_EMBEDDED { 260 class Checkpoint BASE_EMBEDDED {
257 public: 261 public:
258 explicit Checkpoint(ParserBase* parser) { 262 explicit Checkpoint(ParserBase* parser) {
259 function_state_ = parser->function_state_; 263 function_state_ = parser->function_state_;
260 next_materialized_literal_index_ = 264 next_materialized_literal_index_ =
261 function_state_->next_materialized_literal_index_; 265 function_state_->next_materialized_literal_index_;
262 expected_property_count_ = function_state_->expected_property_count_; 266 expected_property_count_ = function_state_->expected_property_count_;
263 } 267 }
264 268
265 void Restore() { 269 void Restore(int* materialized_literal_index_delta) {
270 *materialized_literal_index_delta =
271 function_state_->next_materialized_literal_index_ -
272 next_materialized_literal_index_;
266 function_state_->next_materialized_literal_index_ = 273 function_state_->next_materialized_literal_index_ =
267 next_materialized_literal_index_; 274 next_materialized_literal_index_;
268 function_state_->expected_property_count_ = expected_property_count_; 275 function_state_->expected_property_count_ = expected_property_count_;
269 } 276 }
270 277
271 private: 278 private:
272 FunctionState* function_state_; 279 FunctionState* function_state_;
273 int next_materialized_literal_index_; 280 int next_materialized_literal_index_;
274 int expected_property_count_; 281 int expected_property_count_;
275 }; 282 };
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 PreParserFactory* visitor() { return this; } 1276 PreParserFactory* visitor() { return this; }
1270 int* ast_properties() { 1277 int* ast_properties() {
1271 static int dummy = 42; 1278 static int dummy = 42;
1272 return &dummy; 1279 return &dummy;
1273 } 1280 }
1274 }; 1281 };
1275 1282
1276 1283
1277 struct PreParserFormalParameterParsingState { 1284 struct PreParserFormalParameterParsingState {
1278 explicit PreParserFormalParameterParsingState(Scope* scope) 1285 explicit PreParserFormalParameterParsingState(Scope* scope)
1279 : scope(scope), has_rest(false), is_simple_parameter_list(true) {} 1286 : scope(scope),
1287 has_rest(false),
1288 is_simple_parameter_list(true),
1289 materialized_literals_count(0) {}
1280 Scope* scope; 1290 Scope* scope;
1281 bool has_rest; 1291 bool has_rest;
1282 bool is_simple_parameter_list; 1292 bool is_simple_parameter_list;
1293 int materialized_literals_count;
1283 }; 1294 };
1284 1295
1285 1296
1286 class PreParser; 1297 class PreParser;
1287 1298
1288 class PreParserTraits { 1299 class PreParserTraits {
1289 public: 1300 public:
1290 struct Type { 1301 struct Type {
1291 // TODO(marja): To be removed. The Traits object should contain all the data 1302 // TODO(marja): To be removed. The Traits object should contain all the data
1292 // it needs. 1303 // it needs.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 1571 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
1561 PreParserIdentifier function_name, int pos, 1572 PreParserIdentifier function_name, int pos,
1562 const PreParserFormalParameterParsingState& formal_parameters, 1573 const PreParserFormalParameterParsingState& formal_parameters,
1563 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); 1574 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok);
1564 1575
1565 V8_INLINE void ParseArrowFunctionFormalParameters( 1576 V8_INLINE void ParseArrowFunctionFormalParameters(
1566 PreParserFormalParameterParsingState* parsing_state, 1577 PreParserFormalParameterParsingState* parsing_state,
1567 PreParserExpression expression, const Scanner::Location& params_loc, 1578 PreParserExpression expression, const Scanner::Location& params_loc,
1568 Scanner::Location* duplicate_loc, bool* ok); 1579 Scanner::Location* duplicate_loc, bool* ok);
1569 1580
1581 void ReindexLiterals(
1582 const PreParserFormalParameterParsingState& parsing_state) {}
1583
1570 struct TemplateLiteralState {}; 1584 struct TemplateLiteralState {};
1571 1585
1572 TemplateLiteralState OpenTemplateLiteral(int pos) { 1586 TemplateLiteralState OpenTemplateLiteral(int pos) {
1573 return TemplateLiteralState(); 1587 return TemplateLiteralState();
1574 } 1588 }
1575 void AddTemplateSpan(TemplateLiteralState*, bool) {} 1589 void AddTemplateSpan(TemplateLiteralState*, bool) {}
1576 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 1590 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
1577 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 1591 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
1578 PreParserExpression tag) { 1592 PreParserExpression tag) {
1579 if (IsTaggedTemplate(tag)) { 1593 if (IsTaggedTemplate(tag)) {
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2772 ParserBase<Traits>::Checkpoint checkpoint(this); 2786 ParserBase<Traits>::Checkpoint checkpoint(this);
2773 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); 2787 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder());
2774 bool parenthesized_formals = peek() == Token::LPAREN; 2788 bool parenthesized_formals = peek() == Token::LPAREN;
2775 if (!parenthesized_formals) { 2789 if (!parenthesized_formals) {
2776 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 2790 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2777 } 2791 }
2778 ExpressionT expression = this->ParseConditionalExpression( 2792 ExpressionT expression = this->ParseConditionalExpression(
2779 accept_IN, &arrow_formals_classifier, CHECK_OK); 2793 accept_IN, &arrow_formals_classifier, CHECK_OK);
2780 2794
2781 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2795 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2782 checkpoint.Restore();
2783 BindingPatternUnexpectedToken(classifier); 2796 BindingPatternUnexpectedToken(classifier);
2784 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2797 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2785 parenthesized_formals, CHECK_OK); 2798 parenthesized_formals, CHECK_OK);
2786 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); 2799 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
2787 Scope* scope = 2800 Scope* scope =
2788 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2801 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2802 FormalParameterParsingStateT parsing_state(scope);
2803 checkpoint.Restore(&parsing_state.materialized_literals_count);
2804
2789 scope->set_start_position(lhs_location.beg_pos); 2805 scope->set_start_position(lhs_location.beg_pos);
2790 Scanner::Location duplicate_loc = Scanner::Location::invalid(); 2806 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2791 FormalParameterParsingStateT parsing_state(scope);
2792 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc, 2807 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc,
2793 &duplicate_loc, CHECK_OK); 2808 &duplicate_loc, CHECK_OK);
2794 if (duplicate_loc.IsValid()) { 2809 if (duplicate_loc.IsValid()) {
2795 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2810 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2796 duplicate_loc); 2811 duplicate_loc);
2797 } 2812 }
2798 expression = this->ParseArrowFunctionLiteral( 2813 expression = this->ParseArrowFunctionLiteral(
2799 parsing_state, arrow_formals_classifier, CHECK_OK); 2814 parsing_state, arrow_formals_classifier, CHECK_OK);
2800 return expression; 2815 return expression;
2801 } 2816 }
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3685 int materialized_literal_count = -1; 3700 int materialized_literal_count = -1;
3686 int expected_property_count = -1; 3701 int expected_property_count = -1;
3687 Scanner::Location super_loc; 3702 Scanner::Location super_loc;
3688 3703
3689 { 3704 {
3690 typename Traits::Type::Factory function_factory(ast_value_factory()); 3705 typename Traits::Type::Factory function_factory(ast_value_factory());
3691 FunctionState function_state(&function_state_, &scope_, 3706 FunctionState function_state(&function_state_, &scope_,
3692 formal_parameters.scope, kArrowFunction, 3707 formal_parameters.scope, kArrowFunction,
3693 &function_factory); 3708 &function_factory);
3694 3709
3710 function_state.SkipMaterializedLiterals(
3711 formal_parameters.materialized_literals_count);
3712
3713 this->ReindexLiterals(formal_parameters);
3714
3695 Expect(Token::ARROW, CHECK_OK); 3715 Expect(Token::ARROW, CHECK_OK);
3696 3716
3697 if (peek() == Token::LBRACE) { 3717 if (peek() == Token::LBRACE) {
3698 // Multiple statement body 3718 // Multiple statement body
3699 Consume(Token::LBRACE); 3719 Consume(Token::LBRACE);
3700 bool is_lazily_parsed = 3720 bool is_lazily_parsed =
3701 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); 3721 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation());
3702 if (is_lazily_parsed) { 3722 if (is_lazily_parsed) {
3703 body = this->NewStatementList(0, zone()); 3723 body = this->NewStatementList(0, zone());
3704 this->SkipLazyFunctionBody(&materialized_literal_count, 3724 this->SkipLazyFunctionBody(&materialized_literal_count,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 *ok = false; 3969 *ok = false;
3950 return; 3970 return;
3951 } 3971 }
3952 has_seen_constructor_ = true; 3972 has_seen_constructor_ = true;
3953 return; 3973 return;
3954 } 3974 }
3955 } 3975 }
3956 } } // v8::internal 3976 } } // v8::internal
3957 3977
3958 #endif // V8_PREPARSER_H 3978 #endif // V8_PREPARSER_H
OLDNEW
« src/ast-literal-reindexer.h ('K') | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698