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

Side by Side Diff: src/parsing/preparser.h

Issue 2539123002: Preparsing inner funcs: be less pessimistic about maybe_assigned. (Closed)
Patch Set: Created 4 years 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/ast/scopes.cc ('k') | src/parsing/preparser.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_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"
Toon Verwaest 2016/12/01 13:34:08 Should we split out VariableProxy into a separate
marja 2016/12/06 14:50:05 It won't help here since we need to call AstNodeFa
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 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 14
14 // Whereas the Parser generates AST during the recursive descent, 15 // Whereas the Parser generates AST during the recursive descent,
15 // the PreParser doesn't create a tree. Instead, it passes around minimal 16 // the PreParser doesn't create a tree. Instead, it passes around minimal
16 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain 17 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain
17 // just enough data for the upper layer functions. PreParserFactory is 18 // just enough data for the upper layer functions. PreParserFactory is
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const AstRawString* string_; 119 const AstRawString* string_;
119 friend class PreParserExpression; 120 friend class PreParserExpression;
120 friend class PreParser; 121 friend class PreParser;
121 friend class PreParserFactory; 122 friend class PreParserFactory;
122 }; 123 };
123 124
124 125
125 class PreParserExpression { 126 class PreParserExpression {
126 public: 127 public:
127 PreParserExpression() 128 PreParserExpression()
128 : code_(TypeField::encode(kEmpty)), identifiers_(nullptr) {} 129 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {}
129 130
130 static PreParserExpression Empty() { return PreParserExpression(); } 131 static PreParserExpression Empty() { return PreParserExpression(); }
131 132
132 static PreParserExpression Default( 133 static PreParserExpression Default(
133 ZoneList<const AstRawString*>* identifiers = nullptr) { 134 ZoneList<VariableProxy*>* variables = nullptr) {
134 return PreParserExpression(TypeField::encode(kExpression), identifiers); 135 return PreParserExpression(TypeField::encode(kExpression), variables);
135 } 136 }
136 137
137 static PreParserExpression Spread(PreParserExpression expression) { 138 static PreParserExpression Spread(PreParserExpression expression) {
138 return PreParserExpression(TypeField::encode(kSpreadExpression), 139 return PreParserExpression(TypeField::encode(kSpreadExpression),
139 expression.identifiers_); 140 expression.variables_);
140 } 141 }
141 142
142 static PreParserExpression FromIdentifier(PreParserIdentifier id, 143 static PreParserExpression FromIdentifier(PreParserIdentifier id,
144 VariableProxy* variable,
143 Zone* zone) { 145 Zone* zone) {
144 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | 146 PreParserExpression expression(TypeField::encode(kIdentifierExpression) |
145 IdentifierTypeField::encode(id.type_)); 147 IdentifierTypeField::encode(id.type_));
146 expression.AddIdentifier(id.string_, zone); 148 expression.AddVariable(variable, zone);
147 return expression; 149 return expression;
148 } 150 }
149 151
150 static PreParserExpression BinaryOperation(PreParserExpression left, 152 static PreParserExpression BinaryOperation(PreParserExpression left,
151 Token::Value op, 153 Token::Value op,
152 PreParserExpression right) { 154 PreParserExpression right) {
153 return PreParserExpression(TypeField::encode(kExpression)); 155 return PreParserExpression(TypeField::encode(kExpression));
154 } 156 }
155 157
156 static PreParserExpression Assignment( 158 static PreParserExpression Assignment(
157 ZoneList<const AstRawString*>* identifiers = nullptr) { 159 ZoneList<VariableProxy*>* variables = nullptr) {
158 return PreParserExpression(TypeField::encode(kExpression) | 160 return PreParserExpression(TypeField::encode(kExpression) |
159 ExpressionTypeField::encode(kAssignment), 161 ExpressionTypeField::encode(kAssignment),
160 identifiers); 162 variables);
161 } 163 }
162 164
163 static PreParserExpression ObjectLiteral( 165 static PreParserExpression ObjectLiteral(
164 ZoneList<const AstRawString*>* identifiers = nullptr) { 166 ZoneList<VariableProxy*>* variables = nullptr) {
165 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), 167 return PreParserExpression(TypeField::encode(kObjectLiteralExpression),
166 identifiers); 168 variables);
167 } 169 }
168 170
169 static PreParserExpression ArrayLiteral( 171 static PreParserExpression ArrayLiteral(
170 ZoneList<const AstRawString*>* identifiers = nullptr) { 172 ZoneList<VariableProxy*>* variables = nullptr) {
171 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), 173 return PreParserExpression(TypeField::encode(kArrayLiteralExpression),
172 identifiers); 174 variables);
173 } 175 }
174 176
175 static PreParserExpression StringLiteral() { 177 static PreParserExpression StringLiteral() {
176 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); 178 return PreParserExpression(TypeField::encode(kStringLiteralExpression));
177 } 179 }
178 180
179 static PreParserExpression UseStrictStringLiteral() { 181 static PreParserExpression UseStrictStringLiteral() {
180 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | 182 return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
181 IsUseStrictField::encode(true)); 183 IsUseStrictField::encode(true));
182 } 184 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 kThisExpression, 341 kThisExpression,
340 kThisPropertyExpression, 342 kThisPropertyExpression,
341 kPropertyExpression, 343 kPropertyExpression,
342 kCallExpression, 344 kCallExpression,
343 kCallEvalExpression, 345 kCallEvalExpression,
344 kSuperCallReference, 346 kSuperCallReference,
345 kNoTemplateTagExpression, 347 kNoTemplateTagExpression,
346 kAssignment 348 kAssignment
347 }; 349 };
348 350
349 explicit PreParserExpression( 351 explicit PreParserExpression(uint32_t expression_code,
350 uint32_t expression_code, 352 ZoneList<VariableProxy*>* variables = nullptr)
351 ZoneList<const AstRawString*>* identifiers = nullptr) 353 : code_(expression_code), variables_(variables) {}
352 : code_(expression_code), identifiers_(identifiers) {}
353 354
354 void AddIdentifier(const AstRawString* identifier, Zone* zone) { 355 void AddVariable(VariableProxy* variable, Zone* zone) {
355 if (identifier == nullptr) { 356 if (variable == nullptr) {
356 return; 357 return;
357 } 358 }
358 if (identifiers_ == nullptr) { 359 if (variables_ == nullptr) {
359 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); 360 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone);
360 } 361 }
361 identifiers_->Add(identifier, zone); 362 variables_->Add(variable, zone);
362 } 363 }
363 364
364 // The first three bits are for the Type. 365 // The first three bits are for the Type.
365 typedef BitField<Type, 0, 3> TypeField; 366 typedef BitField<Type, 0, 3> TypeField;
366 367
367 // The high order bit applies only to nodes which would inherit from the 368 // The high order bit applies only to nodes which would inherit from the
368 // Expression ASTNode --- This is by necessity, due to the fact that 369 // Expression ASTNode --- This is by necessity, due to the fact that
369 // Expression nodes may be represented as multiple Types, not exclusively 370 // Expression nodes may be represented as multiple Types, not exclusively
370 // through kExpression. 371 // through kExpression.
371 // TODO(caitp, adamk): clean up PreParserExpression bitfields. 372 // TODO(caitp, adamk): clean up PreParserExpression bitfields.
372 typedef BitField<bool, 31, 1> ParenthesizedField; 373 typedef BitField<bool, 31, 1> ParenthesizedField;
373 374
374 // The rest of the bits are interpreted depending on the value 375 // The rest of the bits are interpreted depending on the value
375 // of the Type field, so they can share the storage. 376 // of the Type field, so they can share the storage.
376 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; 377 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
377 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; 378 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
378 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; 379 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField;
379 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> 380 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
380 IdentifierTypeField; 381 IdentifierTypeField;
381 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; 382 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField;
382 383
383 uint32_t code_; 384 uint32_t code_;
384 // If the PreParser is used in the identifier tracking mode, 385 // If the PreParser is used in the variable tracking mode, PreParserExpression
385 // PreParserExpression accumulates identifiers in that expression. 386 // accumulates variables in that expression.
386 ZoneList<const AstRawString*>* identifiers_; 387 ZoneList<VariableProxy*>* variables_;
387 388
388 friend class PreParser; 389 friend class PreParser;
389 friend class PreParserFactory; 390 friend class PreParserFactory;
390 template <typename T> 391 template <typename T>
391 friend class PreParserList; 392 friend class PreParserList;
392 }; 393 };
393 394
394 395
395 // The pre-parser doesn't need to build lists of expressions, identifiers, or 396 // The pre-parser doesn't need to build lists of expressions, identifiers, or
396 // the like. If the PreParser is used in identifier tracking mode, it needs to 397 // the like. If the PreParser is used in variable tracking mode, it needs to
397 // build lists of identifiers though. 398 // build lists of variables though.
398 template <typename T> 399 template <typename T>
399 class PreParserList { 400 class PreParserList {
400 public: 401 public:
401 // These functions make list->Add(some_expression) work (and do nothing). 402 // These functions make list->Add(some_expression) work (and do nothing).
402 PreParserList() : length_(0), identifiers_(nullptr) {} 403 PreParserList() : length_(0), variables_(nullptr) {}
403 PreParserList* operator->() { return this; } 404 PreParserList* operator->() { return this; }
404 void Add(T, Zone* zone); 405 void Add(T, Zone* zone);
405 int length() const { return length_; } 406 int length() const { return length_; }
406 static PreParserList Null() { return PreParserList(-1); } 407 static PreParserList Null() { return PreParserList(-1); }
407 bool IsNull() const { return length_ == -1; } 408 bool IsNull() const { return length_ == -1; }
408 409
409 private: 410 private:
410 explicit PreParserList(int n) : length_(n), identifiers_(nullptr) {} 411 explicit PreParserList(int n) : length_(n), variables_(nullptr) {}
411 int length_; 412 int length_;
412 ZoneList<const AstRawString*>* identifiers_; 413 ZoneList<VariableProxy*>* variables_;
413 414
414 friend class PreParser; 415 friend class PreParser;
415 friend class PreParserFactory; 416 friend class PreParserFactory;
416 }; 417 };
417 418
418 template <> 419 template <>
419 inline void PreParserList<PreParserExpression>::Add( 420 inline void PreParserList<PreParserExpression>::Add(
420 PreParserExpression expression, Zone* zone) { 421 PreParserExpression expression, Zone* zone) {
421 if (expression.identifiers_ != nullptr) { 422 if (expression.variables_ != nullptr) {
422 DCHECK(FLAG_lazy_inner_functions); 423 DCHECK(FLAG_lazy_inner_functions);
423 DCHECK(zone != nullptr); 424 DCHECK(zone != nullptr);
424 if (identifiers_ == nullptr) { 425 if (variables_ == nullptr) {
425 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); 426 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone);
426 } 427 }
427 for (auto identifier : (*expression.identifiers_)) { 428 for (auto identifier : (*expression.variables_)) {
428 identifiers_->Add(identifier, zone); 429 variables_->Add(identifier, zone);
429 } 430 }
430 } 431 }
431 ++length_; 432 ++length_;
432 } 433 }
433 434
434 template <typename T> 435 template <typename T>
435 void PreParserList<T>::Add(T, Zone* zone) { 436 void PreParserList<T>::Add(T, Zone* zone) {
436 ++length_; 437 ++length_;
437 } 438 }
438 439
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 }; 518 };
518 519
519 explicit PreParserStatement(Type code) : code_(code) {} 520 explicit PreParserStatement(Type code) : code_(code) {}
520 Type code_; 521 Type code_;
521 }; 522 };
522 523
523 524
524 class PreParserFactory { 525 class PreParserFactory {
525 public: 526 public:
526 explicit PreParserFactory(AstValueFactory* ast_value_factory) 527 explicit PreParserFactory(AstValueFactory* ast_value_factory)
527 : zone_(ast_value_factory->zone()) {} 528 : ast_value_factory_(ast_value_factory),
529 zone_(ast_value_factory->zone()) {}
528 530
529 void set_zone(Zone* zone) { zone_ = zone; } 531 void set_zone(Zone* zone) { zone_ = zone; }
530 532
531 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, 533 PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
532 int pos) { 534 int pos) {
533 // This is needed for object literal property names. Property names are 535 // This is needed for object literal property names. Property names are
534 // normalized to string literals during object literal parsing. 536 // normalized to string literals during object literal parsing.
535 PreParserExpression expression = PreParserExpression::Default(); 537 PreParserExpression expression = PreParserExpression::Default();
536 expression.AddIdentifier(identifier.string_, zone_); 538 if (identifier.string_ != nullptr) {
539 DCHECK(FLAG_lazy_inner_functions);
540 AstNodeFactory factory(ast_value_factory_);
541 factory.set_zone(zone_);
542 VariableProxy* variable =
543 factory.NewVariableProxy(identifier.string_, NORMAL_VARIABLE);
544 expression.AddVariable(variable, zone_);
545 }
537 return expression; 546 return expression;
538 } 547 }
539 PreParserExpression NewNumberLiteral(double number, 548 PreParserExpression NewNumberLiteral(double number,
540 int pos) { 549 int pos) {
541 return PreParserExpression::Default(); 550 return PreParserExpression::Default();
542 } 551 }
543 PreParserExpression NewUndefinedLiteral(int pos) { 552 PreParserExpression NewUndefinedLiteral(int pos) {
544 return PreParserExpression::Default(); 553 return PreParserExpression::Default();
545 } 554 }
546 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, 555 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern,
547 int js_flags, int literal_index, 556 int js_flags, int literal_index,
548 int pos) { 557 int pos) {
549 return PreParserExpression::Default(); 558 return PreParserExpression::Default();
550 } 559 }
551 PreParserExpression NewArrayLiteral(PreParserExpressionList values, 560 PreParserExpression NewArrayLiteral(PreParserExpressionList values,
552 int first_spread_index, int literal_index, 561 int first_spread_index, int literal_index,
553 int pos) { 562 int pos) {
554 return PreParserExpression::ArrayLiteral(values.identifiers_); 563 return PreParserExpression::ArrayLiteral(values.variables_);
555 } 564 }
556 PreParserExpression NewClassLiteralProperty(PreParserExpression key, 565 PreParserExpression NewClassLiteralProperty(PreParserExpression key,
557 PreParserExpression value, 566 PreParserExpression value,
558 ClassLiteralProperty::Kind kind, 567 ClassLiteralProperty::Kind kind,
559 bool is_static, 568 bool is_static,
560 bool is_computed_name) { 569 bool is_computed_name) {
561 return PreParserExpression::Default(); 570 return PreParserExpression::Default();
562 } 571 }
563 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, 572 PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
564 PreParserExpression value, 573 PreParserExpression value,
565 ObjectLiteralProperty::Kind kind, 574 ObjectLiteralProperty::Kind kind,
566 bool is_computed_name) { 575 bool is_computed_name) {
567 return PreParserExpression::Default(value.identifiers_); 576 return PreParserExpression::Default(value.variables_);
568 } 577 }
569 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, 578 PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
570 PreParserExpression value, 579 PreParserExpression value,
571 bool is_computed_name) { 580 bool is_computed_name) {
572 return PreParserExpression::Default(value.identifiers_); 581 return PreParserExpression::Default(value.variables_);
573 } 582 }
574 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, 583 PreParserExpression NewObjectLiteral(PreParserExpressionList properties,
575 int literal_index, 584 int literal_index,
576 int boilerplate_properties, 585 int boilerplate_properties,
577 int pos) { 586 int pos) {
578 return PreParserExpression::ObjectLiteral(properties.identifiers_); 587 return PreParserExpression::ObjectLiteral(properties.variables_);
579 } 588 }
580 PreParserExpression NewVariableProxy(void* variable) { 589 PreParserExpression NewVariableProxy(void* variable) {
581 return PreParserExpression::Default(); 590 return PreParserExpression::Default();
582 } 591 }
583 PreParserExpression NewProperty(PreParserExpression obj, 592 PreParserExpression NewProperty(PreParserExpression obj,
584 PreParserExpression key, 593 PreParserExpression key,
585 int pos) { 594 int pos) {
586 if (obj.IsThis()) { 595 if (obj.IsThis()) {
587 return PreParserExpression::ThisProperty(); 596 return PreParserExpression::ThisProperty();
588 } 597 }
(...skipping 14 matching lines...) Expand all
603 PreParserExpression right, int pos) { 612 PreParserExpression right, int pos) {
604 return PreParserExpression::Default(); 613 return PreParserExpression::Default();
605 } 614 }
606 PreParserExpression NewRewritableExpression(PreParserExpression expression) { 615 PreParserExpression NewRewritableExpression(PreParserExpression expression) {
607 return expression; 616 return expression;
608 } 617 }
609 PreParserExpression NewAssignment(Token::Value op, 618 PreParserExpression NewAssignment(Token::Value op,
610 PreParserExpression left, 619 PreParserExpression left,
611 PreParserExpression right, 620 PreParserExpression right,
612 int pos) { 621 int pos) {
613 // For tracking identifiers for parameters with a default value. 622 // For tracking variables for parameters with a default value.
614 return PreParserExpression::Assignment(left.identifiers_); 623 return PreParserExpression::Assignment(left.variables_);
615 } 624 }
616 PreParserExpression NewYield(PreParserExpression generator_object, 625 PreParserExpression NewYield(PreParserExpression generator_object,
617 PreParserExpression expression, int pos, 626 PreParserExpression expression, int pos,
618 Yield::OnException on_exception) { 627 Yield::OnException on_exception) {
619 return PreParserExpression::Default(); 628 return PreParserExpression::Default();
620 } 629 }
621 PreParserExpression NewConditional(PreParserExpression condition, 630 PreParserExpression NewConditional(PreParserExpression condition,
622 PreParserExpression then_expression, 631 PreParserExpression then_expression,
623 PreParserExpression else_expression, 632 PreParserExpression else_expression,
624 int pos) { 633 int pos) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 750
742 // Return the object itself as AstVisitor and implement the needed 751 // Return the object itself as AstVisitor and implement the needed
743 // dummy method right in this class. 752 // dummy method right in this class.
744 PreParserFactory* visitor() { return this; } 753 PreParserFactory* visitor() { return this; }
745 int* ast_properties() { 754 int* ast_properties() {
746 static int dummy = 42; 755 static int dummy = 42;
747 return &dummy; 756 return &dummy;
748 } 757 }
749 758
750 private: 759 private:
760 AstValueFactory* ast_value_factory_;
751 Zone* zone_; 761 Zone* zone_;
752 }; 762 };
753 763
754 764
755 struct PreParserFormalParameters : FormalParametersBase { 765 struct PreParserFormalParameters : FormalParametersBase {
756 struct Parameter : public ZoneObject { 766 struct Parameter : public ZoneObject {
757 Parameter(const AstRawString* name, bool is_optional, bool is_rest) 767 Parameter(const AstRawString* name, bool is_optional, bool is_rest)
758 : name(name), 768 : name(name),
759 pattern(PreParserExpression::Default()), 769 pattern(PreParserExpression::Default()),
760 is_optional(is_optional), 770 is_optional(is_optional),
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} 1238 V8_INLINE static void PushVariableName(PreParserIdentifier id) {}
1229 V8_INLINE void PushPropertyName(PreParserExpression expression) {} 1239 V8_INLINE void PushPropertyName(PreParserExpression expression) {}
1230 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} 1240 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {}
1231 V8_INLINE static void AddFunctionForNameInference( 1241 V8_INLINE static void AddFunctionForNameInference(
1232 PreParserExpression expression) {} 1242 PreParserExpression expression) {}
1233 V8_INLINE static void InferFunctionName() {} 1243 V8_INLINE static void InferFunctionName() {}
1234 1244
1235 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( 1245 V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
1236 PreParserExpression left, PreParserExpression right) {} 1246 PreParserExpression left, PreParserExpression right) {}
1237 1247
1238 V8_INLINE static void MarkExpressionAsAssigned( 1248 V8_INLINE void MarkExpressionAsAssigned(PreParserExpression expression) {
1239 PreParserExpression expression) {
1240 // TODO(marja): To be able to produce the same errors, the preparser needs 1249 // TODO(marja): To be able to produce the same errors, the preparser needs
1241 // to start tracking which expressions are variables and which are assigned. 1250 // to start tracking which expressions are variables and which are assigned.
1251 if (expression.variables_ != nullptr) {
Toon Verwaest 2016/12/01 13:34:08 This is still broken I think since it's broken in
marja 2016/12/06 14:50:05 Hmm, what do you mean?
1252 DCHECK(FLAG_lazy_inner_functions);
1253 DCHECK(track_unresolved_variables_);
1254 for (auto variable : *expression.variables_) {
1255 variable->set_is_assigned();
1256 }
1257 }
1242 } 1258 }
1243 1259
1244 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, 1260 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x,
1245 PreParserExpression y, 1261 PreParserExpression y,
1246 Token::Value op, 1262 Token::Value op,
1247 int pos) { 1263 int pos) {
1248 return false; 1264 return false;
1249 } 1265 }
1250 1266
1251 V8_INLINE PreParserExpression BuildUnaryExpression( 1267 V8_INLINE PreParserExpression BuildUnaryExpression(
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 1494
1479 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, 1495 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters,
1480 PreParserExpression pattern, 1496 PreParserExpression pattern,
1481 PreParserExpression initializer, 1497 PreParserExpression initializer,
1482 int initializer_end_position, 1498 int initializer_end_position,
1483 bool is_rest) { 1499 bool is_rest) {
1484 if (track_unresolved_variables_) { 1500 if (track_unresolved_variables_) {
1485 DCHECK(FLAG_lazy_inner_functions); 1501 DCHECK(FLAG_lazy_inner_functions);
1486 bool is_simple = pattern.IsIdentifier() && IsEmptyExpression(initializer); 1502 bool is_simple = pattern.IsIdentifier() && IsEmptyExpression(initializer);
1487 if (is_simple) { 1503 if (is_simple) {
1488 DCHECK_EQ(1, pattern.identifiers_->length()); 1504 DCHECK_EQ(1, pattern.variables_->length());
1489 parameters->params.Add( 1505 parameters->params.Add(
1490 new (zone()) PreParserFormalParameters::Parameter( 1506 new (zone()) PreParserFormalParameters::Parameter(
1491 (*pattern.identifiers_)[0], !IsEmptyExpression(initializer), 1507 (*pattern.variables_)[0]->raw_name(),
1492 is_rest)); 1508 !IsEmptyExpression(initializer), is_rest));
1493 } else { 1509 } else {
1494 parameters->params.Add( 1510 parameters->params.Add(
1495 new (zone()) PreParserFormalParameters::Parameter( 1511 new (zone()) PreParserFormalParameters::Parameter(
1496 pattern, !IsEmptyExpression(initializer), is_rest)); 1512 pattern, !IsEmptyExpression(initializer), is_rest));
1497 } 1513 }
1498 } 1514 }
1499 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest); 1515 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest);
1500 } 1516 }
1501 1517
1502 V8_INLINE void DeclareFormalParameters( 1518 V8_INLINE void DeclareFormalParameters(
1503 DeclarationScope* scope, 1519 DeclarationScope* scope,
1504 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { 1520 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) {
1505 if (!classifier()->is_simple_parameter_list()) { 1521 if (!classifier()->is_simple_parameter_list()) {
1506 scope->SetHasNonSimpleParameters(); 1522 scope->SetHasNonSimpleParameters();
1507 } 1523 }
1508 if (track_unresolved_variables_) { 1524 if (track_unresolved_variables_) {
1509 DCHECK(FLAG_lazy_inner_functions); 1525 DCHECK(FLAG_lazy_inner_functions);
1510 for (auto parameter : parameters) { 1526 for (auto parameter : parameters) {
1511 if (parameter->name != nullptr) { 1527 if (parameter->name != nullptr) {
1512 DCHECK(FLAG_lazy_inner_functions); 1528 DCHECK(FLAG_lazy_inner_functions);
1513 bool is_duplicate = false; 1529 bool is_duplicate = false;
1514 scope->DeclareParameterName(parameter->name, parameter->is_optional, 1530 scope->DeclareParameterName(parameter->name, parameter->is_optional,
1515 parameter->is_rest, &is_duplicate, 1531 parameter->is_rest, &is_duplicate,
1516 ast_value_factory()); 1532 ast_value_factory());
1517 } 1533 }
1518 if (parameter->pattern.identifiers_ != nullptr) { 1534 if (parameter->pattern.variables_ != nullptr) {
1519 DCHECK(FLAG_lazy_inner_functions); 1535 DCHECK(FLAG_lazy_inner_functions);
1520 for (auto i : *parameter->pattern.identifiers_) { 1536 for (auto i : *parameter->pattern.variables_) {
1521 scope->DeclareVariableName(i, VAR); 1537 scope->DeclareVariableName(i->raw_name(), VAR);
1522 } 1538 }
1523 } 1539 }
1524 } 1540 }
1525 } 1541 }
1526 } 1542 }
1527 1543
1528 V8_INLINE void DeclareArrowFunctionFormalParameters( 1544 V8_INLINE void DeclareArrowFunctionFormalParameters(
1529 PreParserFormalParameters* parameters, PreParserExpression params, 1545 PreParserFormalParameters* parameters, PreParserExpression params,
1530 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, 1546 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
1531 bool* ok) { 1547 bool* ok) {
(...skipping 15 matching lines...) Expand all
1547 } 1563 }
1548 1564
1549 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) { 1565 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {
1550 for (int i = 0; i < count; ++i) { 1566 for (int i = 0; i < count; ++i) {
1551 function_state_->NextMaterializedLiteralIndex(); 1567 function_state_->NextMaterializedLiteralIndex();
1552 } 1568 }
1553 } 1569 }
1554 1570
1555 V8_INLINE PreParserExpression 1571 V8_INLINE PreParserExpression
1556 ExpressionListToExpression(PreParserExpressionList args) { 1572 ExpressionListToExpression(PreParserExpressionList args) {
1557 return PreParserExpression::Default(args.identifiers_); 1573 return PreParserExpression::Default(args.variables_);
1558 } 1574 }
1559 1575
1560 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, 1576 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get,
1561 PreParserExpression function, 1577 PreParserExpression function,
1562 PreParserIdentifier name) {} 1578 PreParserIdentifier name) {}
1563 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, 1579 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property,
1564 PreParserIdentifier name) {} 1580 PreParserIdentifier name) {}
1565 V8_INLINE void SetFunctionNameFromIdentifierRef( 1581 V8_INLINE void SetFunctionNameFromIdentifierRef(
1566 PreParserExpression value, PreParserExpression identifier) {} 1582 PreParserExpression value, PreParserExpression identifier) {}
1567 1583
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 function_state_->NextMaterializedLiteralIndex(); 1642 function_state_->NextMaterializedLiteralIndex();
1627 function_state_->NextMaterializedLiteralIndex(); 1643 function_state_->NextMaterializedLiteralIndex();
1628 } 1644 }
1629 return EmptyExpression(); 1645 return EmptyExpression();
1630 } 1646 }
1631 1647
1632 } // namespace internal 1648 } // namespace internal
1633 } // namespace v8 1649 } // namespace v8
1634 1650
1635 #endif // V8_PARSING_PREPARSER_H 1651 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« no previous file with comments | « src/ast/scopes.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698