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

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: CR feedback 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
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 typename Traits::Type::Factory* factory); 172 typename Traits::Type::Factory* factory);
173 ~FunctionState(); 173 ~FunctionState();
174 174
175 int NextMaterializedLiteralIndex() { 175 int NextMaterializedLiteralIndex() {
176 return next_materialized_literal_index_++; 176 return next_materialized_literal_index_++;
177 } 177 }
178 int materialized_literal_count() { 178 int materialized_literal_count() {
179 return next_materialized_literal_index_; 179 return next_materialized_literal_index_;
180 } 180 }
181 181
182 void SkipMaterializedLiterals(int count) {
183 next_materialized_literal_index_ += count;
184 }
185
182 void AddProperty() { expected_property_count_++; } 186 void AddProperty() { expected_property_count_++; }
183 int expected_property_count() { return expected_property_count_; } 187 int expected_property_count() { return expected_property_count_; }
184 188
185 Scanner::Location this_location() const { return this_location_; } 189 Scanner::Location this_location() const { return this_location_; }
186 Scanner::Location super_location() const { return super_location_; } 190 Scanner::Location super_location() const { return super_location_; }
187 Scanner::Location return_location() const { return return_location_; } 191 Scanner::Location return_location() const { return return_location_; }
188 void set_this_location(Scanner::Location location) { 192 void set_this_location(Scanner::Location location) {
189 this_location_ = location; 193 this_location_ = location;
190 } 194 }
191 void set_super_location(Scanner::Location location) { 195 void set_super_location(Scanner::Location location) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // what it was before the arguments were first seen. 257 // what it was before the arguments were first seen.
254 class Checkpoint BASE_EMBEDDED { 258 class Checkpoint BASE_EMBEDDED {
255 public: 259 public:
256 explicit Checkpoint(ParserBase* parser) { 260 explicit Checkpoint(ParserBase* parser) {
257 function_state_ = parser->function_state_; 261 function_state_ = parser->function_state_;
258 next_materialized_literal_index_ = 262 next_materialized_literal_index_ =
259 function_state_->next_materialized_literal_index_; 263 function_state_->next_materialized_literal_index_;
260 expected_property_count_ = function_state_->expected_property_count_; 264 expected_property_count_ = function_state_->expected_property_count_;
261 } 265 }
262 266
263 void Restore() { 267 void Restore(int* materialized_literal_index_delta) {
268 *materialized_literal_index_delta =
269 function_state_->next_materialized_literal_index_ -
270 next_materialized_literal_index_;
264 function_state_->next_materialized_literal_index_ = 271 function_state_->next_materialized_literal_index_ =
265 next_materialized_literal_index_; 272 next_materialized_literal_index_;
266 function_state_->expected_property_count_ = expected_property_count_; 273 function_state_->expected_property_count_ = expected_property_count_;
267 } 274 }
268 275
269 private: 276 private:
270 FunctionState* function_state_; 277 FunctionState* function_state_;
271 int next_materialized_literal_index_; 278 int next_materialized_literal_index_;
272 int expected_property_count_; 279 int expected_property_count_;
273 }; 280 };
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 PreParserFactory* visitor() { return this; } 1273 PreParserFactory* visitor() { return this; }
1267 int* ast_properties() { 1274 int* ast_properties() {
1268 static int dummy = 42; 1275 static int dummy = 42;
1269 return &dummy; 1276 return &dummy;
1270 } 1277 }
1271 }; 1278 };
1272 1279
1273 1280
1274 struct PreParserFormalParameterParsingState { 1281 struct PreParserFormalParameterParsingState {
1275 explicit PreParserFormalParameterParsingState(Scope* scope) 1282 explicit PreParserFormalParameterParsingState(Scope* scope)
1276 : scope(scope), has_rest(false), is_simple_parameter_list(true) {} 1283 : scope(scope),
1284 has_rest(false),
1285 is_simple_parameter_list(true),
1286 materialized_literals_count(0) {}
1277 Scope* scope; 1287 Scope* scope;
1278 bool has_rest; 1288 bool has_rest;
1279 bool is_simple_parameter_list; 1289 bool is_simple_parameter_list;
1290 int materialized_literals_count;
1280 }; 1291 };
1281 1292
1282 1293
1283 class PreParser; 1294 class PreParser;
1284 1295
1285 class PreParserTraits { 1296 class PreParserTraits {
1286 public: 1297 public:
1287 struct Type { 1298 struct Type {
1288 // TODO(marja): To be removed. The Traits object should contain all the data 1299 // TODO(marja): To be removed. The Traits object should contain all the data
1289 // it needs. 1300 // it needs.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 1568 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
1558 PreParserIdentifier function_name, int pos, 1569 PreParserIdentifier function_name, int pos,
1559 const PreParserFormalParameterParsingState& formal_parameters, 1570 const PreParserFormalParameterParsingState& formal_parameters,
1560 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); 1571 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok);
1561 1572
1562 V8_INLINE void ParseArrowFunctionFormalParameters( 1573 V8_INLINE void ParseArrowFunctionFormalParameters(
1563 PreParserFormalParameterParsingState* parsing_state, 1574 PreParserFormalParameterParsingState* parsing_state,
1564 PreParserExpression expression, const Scanner::Location& params_loc, 1575 PreParserExpression expression, const Scanner::Location& params_loc,
1565 Scanner::Location* duplicate_loc, bool* ok); 1576 Scanner::Location* duplicate_loc, bool* ok);
1566 1577
1578 void ReindexLiterals(
1579 const PreParserFormalParameterParsingState& parsing_state) {}
1580
1567 struct TemplateLiteralState {}; 1581 struct TemplateLiteralState {};
1568 1582
1569 TemplateLiteralState OpenTemplateLiteral(int pos) { 1583 TemplateLiteralState OpenTemplateLiteral(int pos) {
1570 return TemplateLiteralState(); 1584 return TemplateLiteralState();
1571 } 1585 }
1572 void AddTemplateSpan(TemplateLiteralState*, bool) {} 1586 void AddTemplateSpan(TemplateLiteralState*, bool) {}
1573 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 1587 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
1574 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 1588 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
1575 PreParserExpression tag) { 1589 PreParserExpression tag) {
1576 if (IsTaggedTemplate(tag)) { 1590 if (IsTaggedTemplate(tag)) {
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 ParserBase<Traits>::Checkpoint checkpoint(this); 2781 ParserBase<Traits>::Checkpoint checkpoint(this);
2768 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); 2782 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder());
2769 bool parenthesized_formals = peek() == Token::LPAREN; 2783 bool parenthesized_formals = peek() == Token::LPAREN;
2770 if (!parenthesized_formals) { 2784 if (!parenthesized_formals) {
2771 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 2785 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2772 } 2786 }
2773 ExpressionT expression = this->ParseConditionalExpression( 2787 ExpressionT expression = this->ParseConditionalExpression(
2774 accept_IN, &arrow_formals_classifier, CHECK_OK); 2788 accept_IN, &arrow_formals_classifier, CHECK_OK);
2775 2789
2776 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2790 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2777 checkpoint.Restore();
2778 BindingPatternUnexpectedToken(classifier); 2791 BindingPatternUnexpectedToken(classifier);
2779 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2792 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2780 parenthesized_formals, CHECK_OK); 2793 parenthesized_formals, CHECK_OK);
2781 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); 2794 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
2782 Scope* scope = 2795 Scope* scope =
2783 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2796 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2797 FormalParameterParsingStateT parsing_state(scope);
2798 checkpoint.Restore(&parsing_state.materialized_literals_count);
2799
2784 scope->set_start_position(lhs_location.beg_pos); 2800 scope->set_start_position(lhs_location.beg_pos);
2785 Scanner::Location duplicate_loc = Scanner::Location::invalid(); 2801 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2786 FormalParameterParsingStateT parsing_state(scope);
2787 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc, 2802 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc,
2788 &duplicate_loc, CHECK_OK); 2803 &duplicate_loc, CHECK_OK);
2789 if (duplicate_loc.IsValid()) { 2804 if (duplicate_loc.IsValid()) {
2790 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2805 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2791 duplicate_loc); 2806 duplicate_loc);
2792 } 2807 }
2793 expression = this->ParseArrowFunctionLiteral( 2808 expression = this->ParseArrowFunctionLiteral(
2794 parsing_state, arrow_formals_classifier, CHECK_OK); 2809 parsing_state, arrow_formals_classifier, CHECK_OK);
2795 return expression; 2810 return expression;
2796 } 2811 }
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3680 int materialized_literal_count = -1; 3695 int materialized_literal_count = -1;
3681 int expected_property_count = -1; 3696 int expected_property_count = -1;
3682 Scanner::Location super_loc; 3697 Scanner::Location super_loc;
3683 3698
3684 { 3699 {
3685 typename Traits::Type::Factory function_factory(ast_value_factory()); 3700 typename Traits::Type::Factory function_factory(ast_value_factory());
3686 FunctionState function_state(&function_state_, &scope_, 3701 FunctionState function_state(&function_state_, &scope_,
3687 formal_parameters.scope, kArrowFunction, 3702 formal_parameters.scope, kArrowFunction,
3688 &function_factory); 3703 &function_factory);
3689 3704
3705 function_state.SkipMaterializedLiterals(
3706 formal_parameters.materialized_literals_count);
3707
3708 this->ReindexLiterals(formal_parameters);
3709
3690 Expect(Token::ARROW, CHECK_OK); 3710 Expect(Token::ARROW, CHECK_OK);
3691 3711
3692 if (peek() == Token::LBRACE) { 3712 if (peek() == Token::LBRACE) {
3693 // Multiple statement body 3713 // Multiple statement body
3694 Consume(Token::LBRACE); 3714 Consume(Token::LBRACE);
3695 bool is_lazily_parsed = 3715 bool is_lazily_parsed =
3696 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); 3716 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation());
3697 if (is_lazily_parsed) { 3717 if (is_lazily_parsed) {
3698 body = this->NewStatementList(0, zone()); 3718 body = this->NewStatementList(0, zone());
3699 this->SkipLazyFunctionBody(&materialized_literal_count, 3719 this->SkipLazyFunctionBody(&materialized_literal_count,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
3944 *ok = false; 3964 *ok = false;
3945 return; 3965 return;
3946 } 3966 }
3947 has_seen_constructor_ = true; 3967 has_seen_constructor_ = true;
3948 return; 3968 return;
3949 } 3969 }
3950 } 3970 }
3951 } } // v8::internal 3971 } } // v8::internal
3952 3972
3953 #endif // V8_PREPARSER_H 3973 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698