OLD | NEW |
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_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
7 | 7 |
| 8 #include "src/ast/ast.h" |
8 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
9 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
10 #include "src/parsing/preparse-data.h" | 11 #include "src/parsing/preparse-data.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 // Whereas the Parser generates AST during the recursive descent, | 16 // Whereas the Parser generates AST during the recursive descent, |
16 // the PreParser doesn't create a tree. Instead, it passes around minimal | 17 // the PreParser doesn't create a tree. Instead, it passes around minimal |
17 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 18 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const AstRawString* string_; | 120 const AstRawString* string_; |
120 friend class PreParserExpression; | 121 friend class PreParserExpression; |
121 friend class PreParser; | 122 friend class PreParser; |
122 friend class PreParserFactory; | 123 friend class PreParserFactory; |
123 }; | 124 }; |
124 | 125 |
125 | 126 |
126 class PreParserExpression { | 127 class PreParserExpression { |
127 public: | 128 public: |
128 PreParserExpression() | 129 PreParserExpression() |
129 : code_(TypeField::encode(kEmpty)), identifiers_(nullptr) {} | 130 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} |
130 | 131 |
131 static PreParserExpression Empty() { return PreParserExpression(); } | 132 static PreParserExpression Empty() { return PreParserExpression(); } |
132 | 133 |
133 static PreParserExpression Default( | 134 static PreParserExpression Default( |
134 ZoneList<const AstRawString*>* identifiers = nullptr) { | 135 ZoneList<VariableProxy*>* variables = nullptr) { |
135 return PreParserExpression(TypeField::encode(kExpression), identifiers); | 136 return PreParserExpression(TypeField::encode(kExpression), variables); |
136 } | 137 } |
137 | 138 |
138 static PreParserExpression Spread(PreParserExpression expression) { | 139 static PreParserExpression Spread(PreParserExpression expression) { |
139 return PreParserExpression(TypeField::encode(kSpreadExpression), | 140 return PreParserExpression(TypeField::encode(kSpreadExpression), |
140 expression.identifiers_); | 141 expression.variables_); |
141 } | 142 } |
142 | 143 |
143 static PreParserExpression FromIdentifier(PreParserIdentifier id, | 144 static PreParserExpression FromIdentifier(PreParserIdentifier id, |
| 145 VariableProxy* variable, |
144 Zone* zone) { | 146 Zone* zone) { |
145 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | | 147 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | |
146 IdentifierTypeField::encode(id.type_)); | 148 IdentifierTypeField::encode(id.type_)); |
147 expression.AddIdentifier(id.string_, zone); | 149 expression.AddVariable(variable, zone); |
148 return expression; | 150 return expression; |
149 } | 151 } |
150 | 152 |
151 static PreParserExpression BinaryOperation(PreParserExpression left, | 153 static PreParserExpression BinaryOperation(PreParserExpression left, |
152 Token::Value op, | 154 Token::Value op, |
153 PreParserExpression right) { | 155 PreParserExpression right) { |
154 return PreParserExpression(TypeField::encode(kExpression)); | 156 return PreParserExpression(TypeField::encode(kExpression)); |
155 } | 157 } |
156 | 158 |
157 static PreParserExpression Assignment( | 159 static PreParserExpression Assignment(ZoneList<VariableProxy*>* variables) { |
158 ZoneList<const AstRawString*>* identifiers = nullptr) { | |
159 return PreParserExpression(TypeField::encode(kExpression) | | 160 return PreParserExpression(TypeField::encode(kExpression) | |
160 ExpressionTypeField::encode(kAssignment), | 161 ExpressionTypeField::encode(kAssignment), |
161 identifiers); | 162 variables); |
162 } | 163 } |
163 | 164 |
164 static PreParserExpression ObjectLiteral( | 165 static PreParserExpression ObjectLiteral( |
165 ZoneList<const AstRawString*>* identifiers = nullptr) { | 166 ZoneList<VariableProxy*>* variables) { |
166 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), | 167 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
167 identifiers); | 168 variables); |
168 } | 169 } |
169 | 170 |
170 static PreParserExpression ArrayLiteral( | 171 static PreParserExpression ArrayLiteral(ZoneList<VariableProxy*>* variables) { |
171 ZoneList<const AstRawString*>* identifiers = nullptr) { | |
172 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), | 172 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), |
173 identifiers); | 173 variables); |
174 } | 174 } |
175 | 175 |
176 static PreParserExpression StringLiteral() { | 176 static PreParserExpression StringLiteral() { |
177 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 177 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
178 } | 178 } |
179 | 179 |
180 static PreParserExpression UseStrictStringLiteral() { | 180 static PreParserExpression UseStrictStringLiteral() { |
181 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 181 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
182 IsUseStrictField::encode(true)); | 182 IsUseStrictField::encode(true)); |
183 } | 183 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 kThisExpression, | 340 kThisExpression, |
341 kThisPropertyExpression, | 341 kThisPropertyExpression, |
342 kPropertyExpression, | 342 kPropertyExpression, |
343 kCallExpression, | 343 kCallExpression, |
344 kCallEvalExpression, | 344 kCallEvalExpression, |
345 kSuperCallReference, | 345 kSuperCallReference, |
346 kNoTemplateTagExpression, | 346 kNoTemplateTagExpression, |
347 kAssignment | 347 kAssignment |
348 }; | 348 }; |
349 | 349 |
350 explicit PreParserExpression( | 350 explicit PreParserExpression(uint32_t expression_code, |
351 uint32_t expression_code, | 351 ZoneList<VariableProxy*>* variables = nullptr) |
352 ZoneList<const AstRawString*>* identifiers = nullptr) | 352 : code_(expression_code), variables_(variables) {} |
353 : code_(expression_code), identifiers_(identifiers) {} | |
354 | 353 |
355 void AddIdentifier(const AstRawString* identifier, Zone* zone) { | 354 void AddVariable(VariableProxy* variable, Zone* zone) { |
356 if (identifier == nullptr) { | 355 if (variable == nullptr) { |
357 return; | 356 return; |
358 } | 357 } |
359 if (identifiers_ == nullptr) { | 358 if (variables_ == nullptr) { |
360 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); | 359 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
361 } | 360 } |
362 identifiers_->Add(identifier, zone); | 361 variables_->Add(variable, zone); |
363 } | 362 } |
364 | 363 |
365 // The first three bits are for the Type. | 364 // The first three bits are for the Type. |
366 typedef BitField<Type, 0, 3> TypeField; | 365 typedef BitField<Type, 0, 3> TypeField; |
367 | 366 |
368 // The high order bit applies only to nodes which would inherit from the | 367 // The high order bit applies only to nodes which would inherit from the |
369 // Expression ASTNode --- This is by necessity, due to the fact that | 368 // Expression ASTNode --- This is by necessity, due to the fact that |
370 // Expression nodes may be represented as multiple Types, not exclusively | 369 // Expression nodes may be represented as multiple Types, not exclusively |
371 // through kExpression. | 370 // through kExpression. |
372 // TODO(caitp, adamk): clean up PreParserExpression bitfields. | 371 // TODO(caitp, adamk): clean up PreParserExpression bitfields. |
373 typedef BitField<bool, 31, 1> ParenthesizedField; | 372 typedef BitField<bool, 31, 1> ParenthesizedField; |
374 | 373 |
375 // The rest of the bits are interpreted depending on the value | 374 // The rest of the bits are interpreted depending on the value |
376 // of the Type field, so they can share the storage. | 375 // of the Type field, so they can share the storage. |
377 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 376 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
378 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 377 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
379 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; | 378 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; |
380 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 379 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
381 IdentifierTypeField; | 380 IdentifierTypeField; |
382 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; | 381 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
383 | 382 |
384 uint32_t code_; | 383 uint32_t code_; |
385 // If the PreParser is used in the identifier tracking mode, | 384 // If the PreParser is used in the variable tracking mode, PreParserExpression |
386 // PreParserExpression accumulates identifiers in that expression. | 385 // accumulates variables in that expression. |
387 ZoneList<const AstRawString*>* identifiers_; | 386 ZoneList<VariableProxy*>* variables_; |
388 | 387 |
389 friend class PreParser; | 388 friend class PreParser; |
390 friend class PreParserFactory; | 389 friend class PreParserFactory; |
391 template <typename T> | 390 template <typename T> |
392 friend class PreParserList; | 391 friend class PreParserList; |
393 }; | 392 }; |
394 | 393 |
395 | 394 |
396 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 395 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
397 // the like. If the PreParser is used in identifier tracking mode, it needs to | 396 // the like. If the PreParser is used in variable tracking mode, it needs to |
398 // build lists of identifiers though. | 397 // build lists of variables though. |
399 template <typename T> | 398 template <typename T> |
400 class PreParserList { | 399 class PreParserList { |
401 public: | 400 public: |
402 // These functions make list->Add(some_expression) work (and do nothing). | 401 // These functions make list->Add(some_expression) work (and do nothing). |
403 PreParserList() : length_(0), identifiers_(nullptr) {} | 402 PreParserList() : length_(0), variables_(nullptr) {} |
404 PreParserList* operator->() { return this; } | 403 PreParserList* operator->() { return this; } |
405 void Add(T, Zone* zone); | 404 void Add(T, Zone* zone); |
406 int length() const { return length_; } | 405 int length() const { return length_; } |
407 static PreParserList Null() { return PreParserList(-1); } | 406 static PreParserList Null() { return PreParserList(-1); } |
408 bool IsNull() const { return length_ == -1; } | 407 bool IsNull() const { return length_ == -1; } |
409 | 408 |
410 private: | 409 private: |
411 explicit PreParserList(int n) : length_(n), identifiers_(nullptr) {} | 410 explicit PreParserList(int n) : length_(n), variables_(nullptr) {} |
412 int length_; | 411 int length_; |
413 ZoneList<const AstRawString*>* identifiers_; | 412 ZoneList<VariableProxy*>* variables_; |
414 | 413 |
415 friend class PreParser; | 414 friend class PreParser; |
416 friend class PreParserFactory; | 415 friend class PreParserFactory; |
417 }; | 416 }; |
418 | 417 |
419 template <> | 418 template <> |
420 inline void PreParserList<PreParserExpression>::Add( | 419 inline void PreParserList<PreParserExpression>::Add( |
421 PreParserExpression expression, Zone* zone) { | 420 PreParserExpression expression, Zone* zone) { |
422 if (expression.identifiers_ != nullptr) { | 421 if (expression.variables_ != nullptr) { |
423 DCHECK(FLAG_lazy_inner_functions); | 422 DCHECK(FLAG_lazy_inner_functions); |
424 DCHECK(zone != nullptr); | 423 DCHECK(zone != nullptr); |
425 if (identifiers_ == nullptr) { | 424 if (variables_ == nullptr) { |
426 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); | 425 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
427 } | 426 } |
428 for (auto identifier : (*expression.identifiers_)) { | 427 for (auto identifier : (*expression.variables_)) { |
429 identifiers_->Add(identifier, zone); | 428 variables_->Add(identifier, zone); |
430 } | 429 } |
431 } | 430 } |
432 ++length_; | 431 ++length_; |
433 } | 432 } |
434 | 433 |
435 template <typename T> | 434 template <typename T> |
436 void PreParserList<T>::Add(T, Zone* zone) { | 435 void PreParserList<T>::Add(T, Zone* zone) { |
437 ++length_; | 436 ++length_; |
438 } | 437 } |
439 | 438 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 }; | 517 }; |
519 | 518 |
520 explicit PreParserStatement(Type code) : code_(code) {} | 519 explicit PreParserStatement(Type code) : code_(code) {} |
521 Type code_; | 520 Type code_; |
522 }; | 521 }; |
523 | 522 |
524 | 523 |
525 class PreParserFactory { | 524 class PreParserFactory { |
526 public: | 525 public: |
527 explicit PreParserFactory(AstValueFactory* ast_value_factory) | 526 explicit PreParserFactory(AstValueFactory* ast_value_factory) |
528 : zone_(ast_value_factory->zone()) {} | 527 : ast_value_factory_(ast_value_factory), |
| 528 zone_(ast_value_factory->zone()) {} |
529 | 529 |
530 void set_zone(Zone* zone) { zone_ = zone; } | 530 void set_zone(Zone* zone) { zone_ = zone; } |
531 | 531 |
532 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 532 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
533 int pos) { | 533 int pos) { |
534 // This is needed for object literal property names. Property names are | 534 // This is needed for object literal property names. Property names are |
535 // normalized to string literals during object literal parsing. | 535 // normalized to string literals during object literal parsing. |
536 PreParserExpression expression = PreParserExpression::Default(); | 536 PreParserExpression expression = PreParserExpression::Default(); |
537 expression.AddIdentifier(identifier.string_, zone_); | 537 if (identifier.string_ != nullptr) { |
| 538 DCHECK(FLAG_lazy_inner_functions); |
| 539 AstNodeFactory factory(ast_value_factory_); |
| 540 factory.set_zone(zone_); |
| 541 VariableProxy* variable = |
| 542 factory.NewVariableProxy(identifier.string_, NORMAL_VARIABLE); |
| 543 expression.AddVariable(variable, zone_); |
| 544 } |
538 return expression; | 545 return expression; |
539 } | 546 } |
540 PreParserExpression NewNumberLiteral(double number, | 547 PreParserExpression NewNumberLiteral(double number, |
541 int pos) { | 548 int pos) { |
542 return PreParserExpression::Default(); | 549 return PreParserExpression::Default(); |
543 } | 550 } |
544 PreParserExpression NewUndefinedLiteral(int pos) { | 551 PreParserExpression NewUndefinedLiteral(int pos) { |
545 return PreParserExpression::Default(); | 552 return PreParserExpression::Default(); |
546 } | 553 } |
547 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 554 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
548 int js_flags, int literal_index, | 555 int js_flags, int literal_index, |
549 int pos) { | 556 int pos) { |
550 return PreParserExpression::Default(); | 557 return PreParserExpression::Default(); |
551 } | 558 } |
552 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 559 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
553 int first_spread_index, int literal_index, | 560 int first_spread_index, int literal_index, |
554 int pos) { | 561 int pos) { |
555 return PreParserExpression::ArrayLiteral(values.identifiers_); | 562 return PreParserExpression::ArrayLiteral(values.variables_); |
556 } | 563 } |
557 PreParserExpression NewClassLiteralProperty(PreParserExpression key, | 564 PreParserExpression NewClassLiteralProperty(PreParserExpression key, |
558 PreParserExpression value, | 565 PreParserExpression value, |
559 ClassLiteralProperty::Kind kind, | 566 ClassLiteralProperty::Kind kind, |
560 bool is_static, | 567 bool is_static, |
561 bool is_computed_name) { | 568 bool is_computed_name) { |
562 return PreParserExpression::Default(); | 569 return PreParserExpression::Default(); |
563 } | 570 } |
564 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 571 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
565 PreParserExpression value, | 572 PreParserExpression value, |
566 ObjectLiteralProperty::Kind kind, | 573 ObjectLiteralProperty::Kind kind, |
567 bool is_computed_name) { | 574 bool is_computed_name) { |
568 return PreParserExpression::Default(value.identifiers_); | 575 return PreParserExpression::Default(value.variables_); |
569 } | 576 } |
570 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 577 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
571 PreParserExpression value, | 578 PreParserExpression value, |
572 bool is_computed_name) { | 579 bool is_computed_name) { |
573 return PreParserExpression::Default(value.identifiers_); | 580 return PreParserExpression::Default(value.variables_); |
574 } | 581 } |
575 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 582 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
576 int literal_index, | 583 int literal_index, |
577 int boilerplate_properties, | 584 int boilerplate_properties, |
578 int pos) { | 585 int pos) { |
579 return PreParserExpression::ObjectLiteral(properties.identifiers_); | 586 return PreParserExpression::ObjectLiteral(properties.variables_); |
580 } | 587 } |
581 PreParserExpression NewVariableProxy(void* variable) { | 588 PreParserExpression NewVariableProxy(void* variable) { |
582 return PreParserExpression::Default(); | 589 return PreParserExpression::Default(); |
583 } | 590 } |
584 PreParserExpression NewProperty(PreParserExpression obj, | 591 PreParserExpression NewProperty(PreParserExpression obj, |
585 PreParserExpression key, | 592 PreParserExpression key, |
586 int pos) { | 593 int pos) { |
587 if (obj.IsThis()) { | 594 if (obj.IsThis()) { |
588 return PreParserExpression::ThisProperty(); | 595 return PreParserExpression::ThisProperty(); |
589 } | 596 } |
(...skipping 14 matching lines...) Expand all Loading... |
604 PreParserExpression right, int pos) { | 611 PreParserExpression right, int pos) { |
605 return PreParserExpression::Default(); | 612 return PreParserExpression::Default(); |
606 } | 613 } |
607 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 614 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
608 return expression; | 615 return expression; |
609 } | 616 } |
610 PreParserExpression NewAssignment(Token::Value op, | 617 PreParserExpression NewAssignment(Token::Value op, |
611 PreParserExpression left, | 618 PreParserExpression left, |
612 PreParserExpression right, | 619 PreParserExpression right, |
613 int pos) { | 620 int pos) { |
614 // For tracking identifiers for parameters with a default value. | 621 // For tracking variables for parameters with a default value. |
615 return PreParserExpression::Assignment(left.identifiers_); | 622 return PreParserExpression::Assignment(left.variables_); |
616 } | 623 } |
617 PreParserExpression NewYield(PreParserExpression generator_object, | 624 PreParserExpression NewYield(PreParserExpression generator_object, |
618 PreParserExpression expression, int pos, | 625 PreParserExpression expression, int pos, |
619 Yield::OnException on_exception) { | 626 Yield::OnException on_exception) { |
620 return PreParserExpression::Default(); | 627 return PreParserExpression::Default(); |
621 } | 628 } |
622 PreParserExpression NewConditional(PreParserExpression condition, | 629 PreParserExpression NewConditional(PreParserExpression condition, |
623 PreParserExpression then_expression, | 630 PreParserExpression then_expression, |
624 PreParserExpression else_expression, | 631 PreParserExpression else_expression, |
625 int pos) { | 632 int pos) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 749 |
743 // Return the object itself as AstVisitor and implement the needed | 750 // Return the object itself as AstVisitor and implement the needed |
744 // dummy method right in this class. | 751 // dummy method right in this class. |
745 PreParserFactory* visitor() { return this; } | 752 PreParserFactory* visitor() { return this; } |
746 int* ast_properties() { | 753 int* ast_properties() { |
747 static int dummy = 42; | 754 static int dummy = 42; |
748 return &dummy; | 755 return &dummy; |
749 } | 756 } |
750 | 757 |
751 private: | 758 private: |
| 759 AstValueFactory* ast_value_factory_; |
752 Zone* zone_; | 760 Zone* zone_; |
753 }; | 761 }; |
754 | 762 |
755 | 763 |
756 struct PreParserFormalParameters : FormalParametersBase { | 764 struct PreParserFormalParameters : FormalParametersBase { |
757 struct Parameter : public ZoneObject { | 765 struct Parameter : public ZoneObject { |
758 explicit Parameter(PreParserExpression pattern) : pattern(pattern) {} | 766 explicit Parameter(PreParserExpression pattern) : pattern(pattern) {} |
759 Parameter** next() { return &next_parameter; } | 767 Parameter** next() { return &next_parameter; } |
760 Parameter* const* next() const { return &next_parameter; } | 768 Parameter* const* next() const { return &next_parameter; } |
761 PreParserExpression pattern; | 769 PreParserExpression pattern; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} | 1212 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} |
1205 V8_INLINE void PushPropertyName(PreParserExpression expression) {} | 1213 V8_INLINE void PushPropertyName(PreParserExpression expression) {} |
1206 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} | 1214 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} |
1207 V8_INLINE static void AddFunctionForNameInference( | 1215 V8_INLINE static void AddFunctionForNameInference( |
1208 PreParserExpression expression) {} | 1216 PreParserExpression expression) {} |
1209 V8_INLINE static void InferFunctionName() {} | 1217 V8_INLINE static void InferFunctionName() {} |
1210 | 1218 |
1211 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 1219 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
1212 PreParserExpression left, PreParserExpression right) {} | 1220 PreParserExpression left, PreParserExpression right) {} |
1213 | 1221 |
1214 V8_INLINE static void MarkExpressionAsAssigned( | 1222 V8_INLINE void MarkExpressionAsAssigned(PreParserExpression expression) { |
1215 PreParserExpression expression) { | |
1216 // TODO(marja): To be able to produce the same errors, the preparser needs | 1223 // TODO(marja): To be able to produce the same errors, the preparser needs |
1217 // to start tracking which expressions are variables and which are assigned. | 1224 // to start tracking which expressions are variables and which are assigned. |
| 1225 if (expression.variables_ != nullptr) { |
| 1226 DCHECK(FLAG_lazy_inner_functions); |
| 1227 DCHECK(track_unresolved_variables_); |
| 1228 for (auto variable : *expression.variables_) { |
| 1229 variable->set_is_assigned(); |
| 1230 } |
| 1231 } |
1218 } | 1232 } |
1219 | 1233 |
1220 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | 1234 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
1221 PreParserExpression y, | 1235 PreParserExpression y, |
1222 Token::Value op, | 1236 Token::Value op, |
1223 int pos) { | 1237 int pos) { |
1224 return false; | 1238 return false; |
1225 } | 1239 } |
1226 | 1240 |
1227 V8_INLINE PreParserExpression BuildUnaryExpression( | 1241 V8_INLINE PreParserExpression BuildUnaryExpression( |
1228 PreParserExpression expression, Token::Value op, int pos) { | 1242 PreParserExpression expression, Token::Value op, int pos) { |
1229 return PreParserExpression::Default(); | 1243 return PreParserExpression::Default(); |
1230 } | 1244 } |
1231 | 1245 |
1232 V8_INLINE PreParserExpression BuildIteratorResult(PreParserExpression value, | 1246 V8_INLINE PreParserExpression BuildIteratorResult(PreParserExpression value, |
1233 bool done) { | 1247 bool done) { |
1234 return PreParserExpression::Default(); | 1248 return PreParserExpression::Default(); |
1235 } | 1249 } |
1236 | 1250 |
1237 V8_INLINE PreParserStatement | 1251 V8_INLINE PreParserStatement |
1238 BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 1252 BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
1239 ZoneList<const AstRawString*>* names, bool* ok) { | 1253 ZoneList<const AstRawString*>* names, bool* ok) { |
1240 return PreParserStatement::Default(); | 1254 return PreParserStatement::Default(); |
1241 } | 1255 } |
1242 | 1256 |
1243 V8_INLINE PreParserStatement | 1257 V8_INLINE PreParserStatement |
1244 InitializeForEachStatement(PreParserStatement stmt, PreParserExpression each, | 1258 InitializeForEachStatement(PreParserStatement stmt, PreParserExpression each, |
1245 PreParserExpression subject, | 1259 PreParserExpression subject, |
1246 PreParserStatement body, int each_keyword_pos) { | 1260 PreParserStatement body, int each_keyword_pos) { |
| 1261 MarkExpressionAsAssigned(each); |
1247 return stmt; | 1262 return stmt; |
1248 } | 1263 } |
1249 | 1264 |
1250 V8_INLINE PreParserStatement RewriteForVarInLegacy(const ForInfo& for_info) { | 1265 V8_INLINE PreParserStatement RewriteForVarInLegacy(const ForInfo& for_info) { |
1251 return PreParserStatement::Null(); | 1266 return PreParserStatement::Null(); |
1252 } | 1267 } |
1253 V8_INLINE void DesugarBindingInForEachStatement( | 1268 V8_INLINE void DesugarBindingInForEachStatement( |
1254 ForInfo* for_info, PreParserStatement* body_block, | 1269 ForInfo* for_info, PreParserStatement* body_block, |
1255 PreParserExpression* each_variable, bool* ok) {} | 1270 PreParserExpression* each_variable, bool* ok) {} |
1256 V8_INLINE PreParserStatement CreateForEachStatementTDZ( | 1271 V8_INLINE PreParserStatement CreateForEachStatementTDZ( |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 | 1482 |
1468 V8_INLINE void DeclareFormalParameters( | 1483 V8_INLINE void DeclareFormalParameters( |
1469 DeclarationScope* scope, | 1484 DeclarationScope* scope, |
1470 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { | 1485 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { |
1471 if (!classifier()->is_simple_parameter_list()) { | 1486 if (!classifier()->is_simple_parameter_list()) { |
1472 scope->SetHasNonSimpleParameters(); | 1487 scope->SetHasNonSimpleParameters(); |
1473 } | 1488 } |
1474 if (track_unresolved_variables_) { | 1489 if (track_unresolved_variables_) { |
1475 DCHECK(FLAG_lazy_inner_functions); | 1490 DCHECK(FLAG_lazy_inner_functions); |
1476 for (auto parameter : parameters) { | 1491 for (auto parameter : parameters) { |
1477 if (parameter->pattern.identifiers_ != nullptr) { | 1492 if (parameter->pattern.variables_ != nullptr) { |
1478 for (auto i : *parameter->pattern.identifiers_) { | 1493 for (auto variable : *parameter->pattern.variables_) { |
1479 scope->DeclareVariableName(i, VAR); | 1494 scope->DeclareVariableName(variable->raw_name(), VAR); |
1480 } | 1495 } |
1481 } | 1496 } |
1482 } | 1497 } |
1483 } | 1498 } |
1484 } | 1499 } |
1485 | 1500 |
1486 V8_INLINE void DeclareArrowFunctionFormalParameters( | 1501 V8_INLINE void DeclareArrowFunctionFormalParameters( |
1487 PreParserFormalParameters* parameters, PreParserExpression params, | 1502 PreParserFormalParameters* parameters, PreParserExpression params, |
1488 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1503 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
1489 bool* ok) { | 1504 bool* ok) { |
(...skipping 14 matching lines...) Expand all Loading... |
1504 } | 1519 } |
1505 | 1520 |
1506 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) { | 1521 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) { |
1507 for (int i = 0; i < count; ++i) { | 1522 for (int i = 0; i < count; ++i) { |
1508 function_state_->NextMaterializedLiteralIndex(); | 1523 function_state_->NextMaterializedLiteralIndex(); |
1509 } | 1524 } |
1510 } | 1525 } |
1511 | 1526 |
1512 V8_INLINE PreParserExpression | 1527 V8_INLINE PreParserExpression |
1513 ExpressionListToExpression(PreParserExpressionList args) { | 1528 ExpressionListToExpression(PreParserExpressionList args) { |
1514 return PreParserExpression::Default(args.identifiers_); | 1529 return PreParserExpression::Default(args.variables_); |
1515 } | 1530 } |
1516 | 1531 |
1517 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, | 1532 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, |
1518 PreParserExpression function, | 1533 PreParserExpression function, |
1519 PreParserIdentifier name) {} | 1534 PreParserIdentifier name) {} |
1520 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, | 1535 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, |
1521 PreParserIdentifier name) {} | 1536 PreParserIdentifier name) {} |
1522 V8_INLINE void SetFunctionNameFromIdentifierRef( | 1537 V8_INLINE void SetFunctionNameFromIdentifierRef( |
1523 PreParserExpression value, PreParserExpression identifier) {} | 1538 PreParserExpression value, PreParserExpression identifier) {} |
1524 | 1539 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 function_state_->NextMaterializedLiteralIndex(); | 1598 function_state_->NextMaterializedLiteralIndex(); |
1584 function_state_->NextMaterializedLiteralIndex(); | 1599 function_state_->NextMaterializedLiteralIndex(); |
1585 } | 1600 } |
1586 return EmptyExpression(); | 1601 return EmptyExpression(); |
1587 } | 1602 } |
1588 | 1603 |
1589 } // namespace internal | 1604 } // namespace internal |
1590 } // namespace v8 | 1605 } // namespace v8 |
1591 | 1606 |
1592 #endif // V8_PARSING_PREPARSER_H | 1607 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |