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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 | 378 |
379 #define CHECK_FAILED /**/); \ | 379 #define CHECK_FAILED /**/); \ |
380 if (failed_) return nullptr; \ | 380 if (failed_) return nullptr; \ |
381 ((void)0 | 381 ((void)0 |
382 #define DUMMY ) // to make indentation work | 382 #define DUMMY ) // to make indentation work |
383 #undef DUMMY | 383 #undef DUMMY |
384 | 384 |
385 // ---------------------------------------------------------------------------- | 385 // ---------------------------------------------------------------------------- |
386 // Implementation of Parser | 386 // Implementation of Parser |
387 | 387 |
388 bool ParserTraits::IsEval(const AstRawString* identifier) const { | 388 bool ParserBaseTraits<Parser>::IsEval(const AstRawString* identifier) const { |
marja
2016/08/23 09:09:39
Discussed (offline): these functions, and everythi
nickie
2016/08/23 12:10:12
Yes, indeed. 2267783002 is the first of a series
| |
389 return identifier == parser_->ast_value_factory()->eval_string(); | 389 return identifier == delegate()->ast_value_factory()->eval_string(); |
390 } | 390 } |
391 | 391 |
392 bool ParserTraits::IsArguments(const AstRawString* identifier) const { | 392 bool ParserBaseTraits<Parser>::IsArguments( |
393 return identifier == parser_->ast_value_factory()->arguments_string(); | 393 const AstRawString* identifier) const { |
394 return identifier == delegate()->ast_value_factory()->arguments_string(); | |
394 } | 395 } |
395 | 396 |
396 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { | 397 bool ParserBaseTraits<Parser>::IsEvalOrArguments( |
398 const AstRawString* identifier) const { | |
397 return IsEval(identifier) || IsArguments(identifier); | 399 return IsEval(identifier) || IsArguments(identifier); |
398 } | 400 } |
399 | 401 |
400 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { | 402 bool ParserBaseTraits<Parser>::IsUndefined( |
401 return identifier == parser_->ast_value_factory()->undefined_string(); | 403 const AstRawString* identifier) const { |
404 return identifier == delegate()->ast_value_factory()->undefined_string(); | |
402 } | 405 } |
403 | 406 |
404 bool ParserTraits::IsAwait(const AstRawString* identifier) const { | 407 bool ParserBaseTraits<Parser>::IsAwait(const AstRawString* identifier) const { |
405 return identifier == parser_->ast_value_factory()->await_string(); | 408 return identifier == delegate()->ast_value_factory()->await_string(); |
406 } | 409 } |
407 | 410 |
408 bool ParserTraits::IsPrototype(const AstRawString* identifier) const { | 411 bool ParserBaseTraits<Parser>::IsPrototype( |
409 return identifier == parser_->ast_value_factory()->prototype_string(); | 412 const AstRawString* identifier) const { |
413 return identifier == delegate()->ast_value_factory()->prototype_string(); | |
414 } | |
415 | |
416 bool ParserBaseTraits<Parser>::IsConstructor( | |
417 const AstRawString* identifier) const { | |
418 return identifier == delegate()->ast_value_factory()->constructor_string(); | |
410 } | 419 } |
411 | 420 |
412 | 421 |
413 bool ParserTraits::IsConstructor(const AstRawString* identifier) const { | 422 bool ParserBaseTraits<Parser>::IsThisProperty(Expression* expression) { |
414 return identifier == parser_->ast_value_factory()->constructor_string(); | |
415 } | |
416 | |
417 | |
418 bool ParserTraits::IsThisProperty(Expression* expression) { | |
419 DCHECK(expression != NULL); | 423 DCHECK(expression != NULL); |
420 Property* property = expression->AsProperty(); | 424 Property* property = expression->AsProperty(); |
421 return property != NULL && property->obj()->IsVariableProxy() && | 425 return property != NULL && property->obj()->IsVariableProxy() && |
422 property->obj()->AsVariableProxy()->is_this(); | 426 property->obj()->AsVariableProxy()->is_this(); |
423 } | 427 } |
424 | 428 |
425 | 429 |
426 bool ParserTraits::IsIdentifier(Expression* expression) { | 430 bool ParserBaseTraits<Parser>::IsIdentifier(Expression* expression) { |
427 VariableProxy* operand = expression->AsVariableProxy(); | 431 VariableProxy* operand = expression->AsVariableProxy(); |
428 return operand != NULL && !operand->is_this(); | 432 return operand != NULL && !operand->is_this(); |
429 } | 433 } |
430 | 434 |
431 | 435 void ParserBaseTraits<Parser>::PushPropertyName(FuncNameInferrer* fni, |
432 void ParserTraits::PushPropertyName(FuncNameInferrer* fni, | 436 Expression* expression) { |
433 Expression* expression) { | |
434 if (expression->IsPropertyName()) { | 437 if (expression->IsPropertyName()) { |
435 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); | 438 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); |
436 } else { | 439 } else { |
437 fni->PushLiteralName( | 440 fni->PushLiteralName( |
438 parser_->ast_value_factory()->anonymous_function_string()); | 441 delegate()->ast_value_factory()->anonymous_function_string()); |
439 } | 442 } |
440 } | 443 } |
441 | 444 |
442 | 445 void ParserBaseTraits<Parser>::CheckAssigningFunctionLiteralToProperty( |
443 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, | 446 Expression* left, Expression* right) { |
444 Expression* right) { | |
445 DCHECK(left != NULL); | 447 DCHECK(left != NULL); |
446 if (left->IsProperty() && right->IsFunctionLiteral()) { | 448 if (left->IsProperty() && right->IsFunctionLiteral()) { |
447 right->AsFunctionLiteral()->set_pretenure(); | 449 right->AsFunctionLiteral()->set_pretenure(); |
448 } | 450 } |
449 } | 451 } |
450 | 452 |
451 | 453 Expression* ParserBaseTraits<Parser>::MarkExpressionAsAssigned( |
452 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) { | 454 Expression* expression) { |
453 VariableProxy* proxy = | 455 VariableProxy* proxy = |
454 expression != NULL ? expression->AsVariableProxy() : NULL; | 456 expression != NULL ? expression->AsVariableProxy() : NULL; |
455 if (proxy != NULL) proxy->set_is_assigned(); | 457 if (proxy != NULL) proxy->set_is_assigned(); |
456 return expression; | 458 return expression; |
457 } | 459 } |
458 | 460 |
459 | 461 bool ParserBaseTraits<Parser>::ShortcutNumericLiteralBinaryExpression( |
460 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( | |
461 Expression** x, Expression* y, Token::Value op, int pos, | 462 Expression** x, Expression* y, Token::Value op, int pos, |
462 AstNodeFactory* factory) { | 463 AstNodeFactory* factory) { |
463 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && | 464 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && |
464 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { | 465 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { |
465 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); | 466 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); |
466 double y_val = y->AsLiteral()->raw_value()->AsNumber(); | 467 double y_val = y->AsLiteral()->raw_value()->AsNumber(); |
467 bool x_has_dot = (*x)->AsLiteral()->raw_value()->ContainsDot(); | 468 bool x_has_dot = (*x)->AsLiteral()->raw_value()->ContainsDot(); |
468 bool y_has_dot = y->AsLiteral()->raw_value()->ContainsDot(); | 469 bool y_has_dot = y->AsLiteral()->raw_value()->ContainsDot(); |
469 bool has_dot = x_has_dot || y_has_dot; | 470 bool has_dot = x_has_dot || y_has_dot; |
470 switch (op) { | 471 switch (op) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 has_dot); | 521 has_dot); |
521 return true; | 522 return true; |
522 } | 523 } |
523 default: | 524 default: |
524 break; | 525 break; |
525 } | 526 } |
526 } | 527 } |
527 return false; | 528 return false; |
528 } | 529 } |
529 | 530 |
530 | 531 Expression* ParserBaseTraits<Parser>::BuildUnaryExpression( |
531 Expression* ParserTraits::BuildUnaryExpression(Expression* expression, | 532 Expression* expression, Token::Value op, int pos, AstNodeFactory* factory) { |
532 Token::Value op, int pos, | |
533 AstNodeFactory* factory) { | |
534 DCHECK(expression != NULL); | 533 DCHECK(expression != NULL); |
535 if (expression->IsLiteral()) { | 534 if (expression->IsLiteral()) { |
536 const AstValue* literal = expression->AsLiteral()->raw_value(); | 535 const AstValue* literal = expression->AsLiteral()->raw_value(); |
537 if (op == Token::NOT) { | 536 if (op == Token::NOT) { |
538 // Convert the literal to a boolean condition and negate it. | 537 // Convert the literal to a boolean condition and negate it. |
539 bool condition = literal->BooleanValue(); | 538 bool condition = literal->BooleanValue(); |
540 return factory->NewBooleanLiteral(!condition, pos); | 539 return factory->NewBooleanLiteral(!condition, pos); |
541 } else if (literal->IsNumber()) { | 540 } else if (literal->IsNumber()) { |
542 // Compute some expressions involving only number literals. | 541 // Compute some expressions involving only number literals. |
543 double value = literal->AsNumber(); | 542 double value = literal->AsNumber(); |
(...skipping 21 matching lines...) Expand all Loading... | |
565 Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos); | 564 Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos); |
566 } | 565 } |
567 // ...and one more time for '~foo' => 'foo^(~0)'. | 566 // ...and one more time for '~foo' => 'foo^(~0)'. |
568 if (op == Token::BIT_NOT) { | 567 if (op == Token::BIT_NOT) { |
569 return factory->NewBinaryOperation( | 568 return factory->NewBinaryOperation( |
570 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); | 569 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); |
571 } | 570 } |
572 return factory->NewUnaryOperation(op, expression, pos); | 571 return factory->NewUnaryOperation(op, expression, pos); |
573 } | 572 } |
574 | 573 |
575 Expression* ParserTraits::BuildIteratorResult(Expression* value, bool done) { | 574 Expression* ParserBaseTraits<Parser>::BuildIteratorResult(Expression* value, |
575 bool done) { | |
576 int pos = kNoSourcePosition; | 576 int pos = kNoSourcePosition; |
577 AstNodeFactory* factory = parser_->factory(); | 577 AstNodeFactory* factory = delegate()->factory(); |
578 Zone* zone = parser_->zone(); | 578 Zone* zone = delegate()->zone(); |
579 | 579 |
580 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); | 580 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); |
581 | 581 |
582 auto args = new (zone) ZoneList<Expression*>(2, zone); | 582 auto args = new (zone) ZoneList<Expression*>(2, zone); |
583 args->Add(value, zone); | 583 args->Add(value, zone); |
584 args->Add(factory->NewBooleanLiteral(done, pos), zone); | 584 args->Add(factory->NewBooleanLiteral(done, pos), zone); |
585 | 585 |
586 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, | 586 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, |
587 pos); | 587 pos); |
588 } | 588 } |
589 | 589 |
590 Expression* ParserTraits::NewThrowReferenceError( | 590 Expression* ParserBaseTraits<Parser>::NewThrowReferenceError( |
591 MessageTemplate::Template message, int pos) { | 591 MessageTemplate::Template message, int pos) { |
592 return parser_->NewThrowError(Runtime::kNewReferenceError, message, | 592 return delegate()->NewThrowError( |
593 parser_->ast_value_factory()->empty_string(), | 593 Runtime::kNewReferenceError, message, |
594 pos); | 594 delegate()->ast_value_factory()->empty_string(), pos); |
595 } | 595 } |
596 | 596 |
597 | 597 Expression* ParserBaseTraits<Parser>::NewThrowSyntaxError( |
598 Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message, | 598 MessageTemplate::Template message, const AstRawString* arg, int pos) { |
599 const AstRawString* arg, | 599 return delegate()->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); |
600 int pos) { | |
601 return parser_->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); | |
602 } | 600 } |
603 | 601 |
604 | 602 Expression* ParserBaseTraits<Parser>::NewThrowTypeError( |
605 Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message, | 603 MessageTemplate::Template message, const AstRawString* arg, int pos) { |
606 const AstRawString* arg, int pos) { | 604 return delegate()->NewThrowError(Runtime::kNewTypeError, message, arg, pos); |
607 return parser_->NewThrowError(Runtime::kNewTypeError, message, arg, pos); | |
608 } | 605 } |
609 | 606 |
610 Expression* Parser::NewThrowError(Runtime::FunctionId id, | 607 Expression* Parser::NewThrowError(Runtime::FunctionId id, |
611 MessageTemplate::Template message, | 608 MessageTemplate::Template message, |
612 const AstRawString* arg, int pos) { | 609 const AstRawString* arg, int pos) { |
613 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 610 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
614 args->Add(factory()->NewSmiLiteral(message, pos), zone()); | 611 args->Add(factory()->NewSmiLiteral(message, pos), zone()); |
615 args->Add(factory()->NewStringLiteral(arg, pos), zone()); | 612 args->Add(factory()->NewStringLiteral(arg, pos), zone()); |
616 CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos); | 613 CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos); |
617 return factory()->NewThrow(call_constructor, pos); | 614 return factory()->NewThrow(call_constructor, pos); |
618 } | 615 } |
619 | 616 |
620 | 617 void ParserBaseTraits<Parser>::ReportMessageAt( |
621 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 618 Scanner::Location source_location, MessageTemplate::Template message, |
622 MessageTemplate::Template message, | 619 const char* arg, ParseErrorType error_type) { |
623 const char* arg, ParseErrorType error_type) { | 620 if (delegate()->stack_overflow()) { |
624 if (parser_->stack_overflow()) { | |
625 // Suppress the error message (syntax error or such) in the presence of a | 621 // Suppress the error message (syntax error or such) in the presence of a |
626 // stack overflow. The isolate allows only one pending exception at at time | 622 // stack overflow. The isolate allows only one pending exception at at time |
627 // and we want to report the stack overflow later. | 623 // and we want to report the stack overflow later. |
628 return; | 624 return; |
629 } | 625 } |
630 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 626 delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
631 source_location.end_pos, | 627 source_location.end_pos, |
632 message, arg, error_type); | 628 message, arg, error_type); |
633 } | 629 } |
634 | 630 |
635 | 631 void ParserBaseTraits<Parser>::ReportMessageAt( |
636 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 632 Scanner::Location source_location, MessageTemplate::Template message, |
637 MessageTemplate::Template message, | 633 const AstRawString* arg, ParseErrorType error_type) { |
638 const AstRawString* arg, | 634 if (delegate()->stack_overflow()) { |
639 ParseErrorType error_type) { | |
640 if (parser_->stack_overflow()) { | |
641 // Suppress the error message (syntax error or such) in the presence of a | 635 // Suppress the error message (syntax error or such) in the presence of a |
642 // stack overflow. The isolate allows only one pending exception at at time | 636 // stack overflow. The isolate allows only one pending exception at at time |
643 // and we want to report the stack overflow later. | 637 // and we want to report the stack overflow later. |
644 return; | 638 return; |
645 } | 639 } |
646 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 640 delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
647 source_location.end_pos, | 641 source_location.end_pos, |
648 message, arg, error_type); | 642 message, arg, error_type); |
649 } | 643 } |
650 | 644 |
651 | 645 const AstRawString* ParserBaseTraits<Parser>::GetSymbol( |
652 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) const { | 646 Scanner* scanner) const { |
653 const AstRawString* result = | 647 const AstRawString* result = |
654 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); | 648 delegate()->scanner()->CurrentSymbol(delegate()->ast_value_factory()); |
655 DCHECK(result != NULL); | 649 DCHECK(result != NULL); |
656 return result; | 650 return result; |
657 } | 651 } |
658 | 652 |
659 | 653 |
660 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) const { | 654 const AstRawString* ParserBaseTraits<Parser>::GetNumberAsSymbol( |
661 double double_value = parser_->scanner()->DoubleValue(); | 655 Scanner* scanner) const { |
656 double double_value = delegate()->scanner()->DoubleValue(); | |
662 char array[100]; | 657 char array[100]; |
663 const char* string = DoubleToCString(double_value, ArrayVector(array)); | 658 const char* string = DoubleToCString(double_value, ArrayVector(array)); |
664 return parser_->ast_value_factory()->GetOneByteString(string); | 659 return delegate()->ast_value_factory()->GetOneByteString(string); |
665 } | 660 } |
666 | 661 |
667 | 662 const AstRawString* ParserBaseTraits<Parser>::GetNextSymbol( |
668 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) const { | 663 Scanner* scanner) const { |
669 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 664 return delegate()->scanner()->NextSymbol(delegate()->ast_value_factory()); |
670 } | 665 } |
671 | 666 |
672 Expression* ParserTraits::ThisExpression(int pos) { | 667 Expression* ParserBaseTraits<Parser>::ThisExpression(int pos) { |
673 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), | 668 return delegate()->NewUnresolved( |
674 pos, pos + 4, Variable::THIS); | 669 delegate()->ast_value_factory()->this_string(), pos, pos + 4, |
670 Variable::THIS); | |
675 } | 671 } |
676 | 672 |
677 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, | 673 Expression* ParserBaseTraits<Parser>::NewSuperPropertyReference( |
678 int pos) { | 674 AstNodeFactory* factory, int pos) { |
679 // this_function[home_object_symbol] | 675 // this_function[home_object_symbol] |
680 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 676 VariableProxy* this_function_proxy = delegate()->NewUnresolved( |
681 parser_->ast_value_factory()->this_function_string(), pos); | 677 delegate()->ast_value_factory()->this_function_string(), pos); |
682 Expression* home_object_symbol_literal = | 678 Expression* home_object_symbol_literal = |
683 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); | 679 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); |
684 Expression* home_object = factory->NewProperty( | 680 Expression* home_object = factory->NewProperty( |
685 this_function_proxy, home_object_symbol_literal, pos); | 681 this_function_proxy, home_object_symbol_literal, pos); |
686 return factory->NewSuperPropertyReference( | 682 return factory->NewSuperPropertyReference( |
687 ThisExpression(pos)->AsVariableProxy(), home_object, pos); | 683 ThisExpression(pos)->AsVariableProxy(), home_object, pos); |
688 } | 684 } |
689 | 685 |
690 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, | 686 Expression* ParserBaseTraits<Parser>::NewSuperCallReference( |
691 int pos) { | 687 AstNodeFactory* factory, int pos) { |
692 VariableProxy* new_target_proxy = parser_->NewUnresolved( | 688 VariableProxy* new_target_proxy = delegate()->NewUnresolved( |
693 parser_->ast_value_factory()->new_target_string(), pos); | 689 delegate()->ast_value_factory()->new_target_string(), pos); |
694 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 690 VariableProxy* this_function_proxy = delegate()->NewUnresolved( |
695 parser_->ast_value_factory()->this_function_string(), pos); | 691 delegate()->ast_value_factory()->this_function_string(), pos); |
696 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), | 692 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), |
697 new_target_proxy, this_function_proxy, | 693 new_target_proxy, this_function_proxy, |
698 pos); | 694 pos); |
699 } | 695 } |
700 | 696 |
701 Expression* ParserTraits::NewTargetExpression(int pos) { | 697 Expression* ParserBaseTraits<Parser>::NewTargetExpression(int pos) { |
702 static const int kNewTargetStringLength = 10; | 698 static const int kNewTargetStringLength = 10; |
703 auto proxy = | 699 auto proxy = delegate()->NewUnresolved( |
704 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), | 700 delegate()->ast_value_factory()->new_target_string(), pos, |
705 pos, pos + kNewTargetStringLength); | 701 pos + kNewTargetStringLength); |
706 proxy->set_is_new_target(); | 702 proxy->set_is_new_target(); |
707 return proxy; | 703 return proxy; |
708 } | 704 } |
709 | 705 |
710 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, | 706 Expression* ParserBaseTraits<Parser>::FunctionSentExpression( |
711 int pos) const { | 707 AstNodeFactory* factory, int pos) const { |
712 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). | 708 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). |
713 Zone* zone = parser_->zone(); | 709 Zone* zone = delegate()->zone(); |
714 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); | 710 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); |
715 VariableProxy* generator = factory->NewVariableProxy( | 711 VariableProxy* generator = factory->NewVariableProxy( |
716 parser_->function_state_->generator_object_variable()); | 712 delegate()->function_state_->generator_object_variable()); |
717 args->Add(generator, zone); | 713 args->Add(generator, zone); |
718 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, | 714 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, |
719 args, pos); | 715 args, pos); |
720 } | 716 } |
721 | 717 |
722 | 718 Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral( |
723 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, | 719 Token::Value token, int pos, Scanner* scanner, |
724 Scanner* scanner, | 720 AstNodeFactory* factory) const { |
725 AstNodeFactory* factory) const { | |
726 switch (token) { | 721 switch (token) { |
727 case Token::NULL_LITERAL: | 722 case Token::NULL_LITERAL: |
728 return factory->NewNullLiteral(pos); | 723 return factory->NewNullLiteral(pos); |
729 case Token::TRUE_LITERAL: | 724 case Token::TRUE_LITERAL: |
730 return factory->NewBooleanLiteral(true, pos); | 725 return factory->NewBooleanLiteral(true, pos); |
731 case Token::FALSE_LITERAL: | 726 case Token::FALSE_LITERAL: |
732 return factory->NewBooleanLiteral(false, pos); | 727 return factory->NewBooleanLiteral(false, pos); |
733 case Token::SMI: { | 728 case Token::SMI: { |
734 int value = scanner->smi_value(); | 729 int value = scanner->smi_value(); |
735 return factory->NewSmiLiteral(value, pos); | 730 return factory->NewSmiLiteral(value, pos); |
736 } | 731 } |
737 case Token::NUMBER: { | 732 case Token::NUMBER: { |
738 bool has_dot = scanner->ContainsDot(); | 733 bool has_dot = scanner->ContainsDot(); |
739 double value = scanner->DoubleValue(); | 734 double value = scanner->DoubleValue(); |
740 return factory->NewNumberLiteral(value, pos, has_dot); | 735 return factory->NewNumberLiteral(value, pos, has_dot); |
741 } | 736 } |
742 default: | 737 default: |
743 DCHECK(false); | 738 DCHECK(false); |
744 } | 739 } |
745 return NULL; | 740 return NULL; |
746 } | 741 } |
747 | 742 |
748 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 743 Expression* ParserBaseTraits<Parser>::ExpressionFromIdentifier( |
749 int start_position, | 744 const AstRawString* name, int start_position, int end_position, |
750 int end_position, | 745 InferName infer) { |
751 InferName infer) { | 746 if (infer == InferName::kYes && delegate()->fni_ != NULL) { |
752 if (infer == InferName::kYes && parser_->fni_ != NULL) { | 747 delegate()->fni_->PushVariableName(name); |
753 parser_->fni_->PushVariableName(name); | |
754 } | 748 } |
755 return parser_->NewUnresolved(name, start_position, end_position); | 749 return delegate()->NewUnresolved(name, start_position, end_position); |
756 } | 750 } |
757 | 751 |
758 | 752 Expression* ParserBaseTraits<Parser>::ExpressionFromString( |
759 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 753 int pos, Scanner* scanner, AstNodeFactory* factory) const { |
760 AstNodeFactory* factory) const { | |
761 const AstRawString* symbol = GetSymbol(scanner); | 754 const AstRawString* symbol = GetSymbol(scanner); |
762 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 755 if (delegate()->fni_ != NULL) delegate()->fni_->PushLiteralName(symbol); |
763 return factory->NewStringLiteral(symbol, pos); | 756 return factory->NewStringLiteral(symbol, pos); |
764 } | 757 } |
765 | 758 |
766 | 759 |
767 Expression* ParserTraits::GetIterator(Expression* iterable, | 760 Expression* ParserBaseTraits<Parser>::GetIterator(Expression* iterable, |
768 AstNodeFactory* factory, int pos) { | 761 AstNodeFactory* factory, |
762 int pos) { | |
769 Expression* iterator_symbol_literal = | 763 Expression* iterator_symbol_literal = |
770 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); | 764 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); |
771 Expression* prop = | 765 Expression* prop = |
772 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 766 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
773 Zone* zone = parser_->zone(); | 767 Zone* zone = delegate()->zone(); |
774 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 768 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
775 return factory->NewCall(prop, args, pos); | 769 return factory->NewCall(prop, args, pos); |
776 } | 770 } |
777 | 771 |
778 | 772 Literal* ParserBaseTraits<Parser>::GetLiteralTheHole( |
779 Literal* ParserTraits::GetLiteralTheHole(int position, | 773 int position, AstNodeFactory* factory) const { |
780 AstNodeFactory* factory) const { | |
781 return factory->NewTheHoleLiteral(kNoSourcePosition); | 774 return factory->NewTheHoleLiteral(kNoSourcePosition); |
782 } | 775 } |
783 | 776 |
784 | 777 |
785 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 778 Expression* ParserBaseTraits<Parser>::ParseV8Intrinsic(bool* ok) { |
786 return parser_->ParseV8Intrinsic(ok); | 779 return delegate()->ParseV8Intrinsic(ok); |
787 } | 780 } |
788 | 781 |
789 | 782 |
790 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | 783 FunctionLiteral* ParserBaseTraits<Parser>::ParseFunctionLiteral( |
791 const AstRawString* name, Scanner::Location function_name_location, | 784 const AstRawString* name, Scanner::Location function_name_location, |
792 FunctionNameValidity function_name_validity, FunctionKind kind, | 785 FunctionNameValidity function_name_validity, FunctionKind kind, |
793 int function_token_position, FunctionLiteral::FunctionType type, | 786 int function_token_position, FunctionLiteral::FunctionType type, |
794 LanguageMode language_mode, bool* ok) { | 787 LanguageMode language_mode, bool* ok) { |
795 return parser_->ParseFunctionLiteral( | 788 return delegate()->ParseFunctionLiteral( |
796 name, function_name_location, function_name_validity, kind, | 789 name, function_name_location, function_name_validity, kind, |
797 function_token_position, type, language_mode, ok); | 790 function_token_position, type, language_mode, ok); |
798 } | 791 } |
799 | 792 |
800 Expression* ParserTraits::ParseClassLiteral( | 793 Expression* ParserBaseTraits<Parser>::ParseClassLiteral( |
801 Type::ExpressionClassifier* classifier, const AstRawString* name, | 794 Type::ExpressionClassifier* classifier, const AstRawString* name, |
802 Scanner::Location class_name_location, bool name_is_strict_reserved, | 795 Scanner::Location class_name_location, bool name_is_strict_reserved, |
803 int pos, bool* ok) { | 796 int pos, bool* ok) { |
804 return parser_->ParseClassLiteral(classifier, name, class_name_location, | 797 return delegate()->ParseClassLiteral(classifier, name, class_name_location, |
805 name_is_strict_reserved, pos, ok); | 798 name_is_strict_reserved, pos, ok); |
806 } | 799 } |
807 | 800 |
808 void ParserTraits::MarkTailPosition(Expression* expression) { | 801 void ParserBaseTraits<Parser>::MarkTailPosition(Expression* expression) { |
809 expression->MarkTail(); | 802 expression->MarkTail(); |
810 } | 803 } |
811 | 804 |
812 void ParserTraits::MarkCollectedTailCallExpressions() { | 805 void ParserBaseTraits<Parser>::MarkCollectedTailCallExpressions() { |
813 parser_->MarkCollectedTailCallExpressions(); | 806 delegate()->MarkCollectedTailCallExpressions(); |
814 } | 807 } |
815 | 808 |
816 Parser::Parser(ParseInfo* info) | 809 Parser::Parser(ParseInfo* info) |
817 : ParserBase<ParserTraits>(info->zone(), &scanner_, info->stack_limit(), | 810 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), |
818 info->extension(), info->ast_value_factory(), | 811 info->extension(), info->ast_value_factory(), NULL), |
819 NULL, this), | |
820 scanner_(info->unicode_cache()), | 812 scanner_(info->unicode_cache()), |
821 reusable_preparser_(NULL), | 813 reusable_preparser_(NULL), |
822 original_scope_(NULL), | 814 original_scope_(NULL), |
823 target_stack_(NULL), | 815 target_stack_(NULL), |
824 compile_options_(info->compile_options()), | 816 compile_options_(info->compile_options()), |
825 cached_parse_data_(NULL), | 817 cached_parse_data_(NULL), |
826 total_preparse_skipped_(0), | 818 total_preparse_skipped_(0), |
827 pre_parse_timer_(NULL), | 819 pre_parse_timer_(NULL), |
828 parsing_on_main_thread_(true) { | 820 parsing_on_main_thread_(true) { |
829 // Even though we were passed ParseInfo, we should not store it in | 821 // Even though we were passed ParseInfo, we should not store it in |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1038 if (body->length() != 1 || | 1030 if (body->length() != 1 || |
1039 !body->at(0)->IsExpressionStatement() || | 1031 !body->at(0)->IsExpressionStatement() || |
1040 !body->at(0)->AsExpressionStatement()-> | 1032 !body->at(0)->AsExpressionStatement()-> |
1041 expression()->IsFunctionLiteral()) { | 1033 expression()->IsFunctionLiteral()) { |
1042 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 1034 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
1043 ok = false; | 1035 ok = false; |
1044 } | 1036 } |
1045 } | 1037 } |
1046 | 1038 |
1047 if (ok) { | 1039 if (ok) { |
1048 ParserTraits::RewriteDestructuringAssignments(); | 1040 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); |
1049 result = factory()->NewScriptOrEvalFunctionLiteral( | 1041 result = factory()->NewScriptOrEvalFunctionLiteral( |
1050 scope, body, function_state.materialized_literal_count(), | 1042 scope, body, function_state.materialized_literal_count(), |
1051 function_state.expected_property_count()); | 1043 function_state.expected_property_count()); |
1052 } | 1044 } |
1053 } | 1045 } |
1054 | 1046 |
1055 // Make sure the target stack is empty. | 1047 // Make sure the target stack is empty. |
1056 DCHECK(target_stack_ == NULL); | 1048 DCHECK(target_stack_ == NULL); |
1057 | 1049 |
1058 return result; | 1050 return result; |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2429 // Don't infer if it is "a = function(){...}();"-like expression. | 2421 // Don't infer if it is "a = function(){...}();"-like expression. |
2430 if (single_name) { | 2422 if (single_name) { |
2431 if (fni_ != NULL && value->AsCall() == NULL && | 2423 if (fni_ != NULL && value->AsCall() == NULL && |
2432 value->AsCallNew() == NULL) { | 2424 value->AsCallNew() == NULL) { |
2433 fni_->Infer(); | 2425 fni_->Infer(); |
2434 } else { | 2426 } else { |
2435 fni_->RemoveLastFunction(); | 2427 fni_->RemoveLastFunction(); |
2436 } | 2428 } |
2437 } | 2429 } |
2438 | 2430 |
2439 ParserTraits::SetFunctionNameFromIdentifierRef(value, pattern); | 2431 ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef(value, |
2432 pattern); | |
2440 | 2433 |
2441 // End position of the initializer is after the assignment expression. | 2434 // End position of the initializer is after the assignment expression. |
2442 initializer_position = scanner()->location().end_pos; | 2435 initializer_position = scanner()->location().end_pos; |
2443 } else { | 2436 } else { |
2444 // Initializers may be either required or implied unless this is a | 2437 // Initializers may be either required or implied unless this is a |
2445 // for-in/of iteration variable. | 2438 // for-in/of iteration variable. |
2446 if (var_context != kForStatement || !PeekInOrOf()) { | 2439 if (var_context != kForStatement || !PeekInOrOf()) { |
2447 // ES6 'const' and binding patterns require initializers. | 2440 // ES6 'const' and binding patterns require initializers. |
2448 if (parsing_result->descriptor.mode == CONST || | 2441 if (parsing_result->descriptor.mode == CONST || |
2449 !pattern->IsVariableProxy()) { | 2442 !pattern->IsVariableProxy()) { |
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4089 if (expr->IsAssignment()) { | 4082 if (expr->IsAssignment()) { |
4090 Assignment* assignment = expr->AsAssignment(); | 4083 Assignment* assignment = expr->AsAssignment(); |
4091 DCHECK(!assignment->is_compound()); | 4084 DCHECK(!assignment->is_compound()); |
4092 initializer = assignment->value(); | 4085 initializer = assignment->value(); |
4093 expr = assignment->target(); | 4086 expr = assignment->target(); |
4094 } | 4087 } |
4095 | 4088 |
4096 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 4089 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); |
4097 } | 4090 } |
4098 | 4091 |
4099 void ParserTraits::ParseAsyncArrowSingleExpressionBody( | 4092 void ParserBaseTraits<Parser>::ParseAsyncArrowSingleExpressionBody( |
4100 ZoneList<Statement*>* body, bool accept_IN, | 4093 ZoneList<Statement*>* body, bool accept_IN, |
4101 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 4094 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
4102 parser_->DesugarAsyncFunctionBody( | 4095 delegate()->DesugarAsyncFunctionBody( |
4103 parser_->ast_value_factory()->empty_string(), parser_->scope(), body, | 4096 delegate()->ast_value_factory()->empty_string(), delegate()->scope(), |
4104 classifier, kAsyncArrowFunction, | 4097 body, classifier, kAsyncArrowFunction, |
4105 Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok); | 4098 Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok); |
4106 } | 4099 } |
4107 | 4100 |
4108 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, | 4101 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, |
4109 Scope* scope, ZoneList<Statement*>* body, | 4102 Scope* scope, ZoneList<Statement*>* body, |
4110 ExpressionClassifier* classifier, | 4103 ExpressionClassifier* classifier, |
4111 FunctionKind kind, | 4104 FunctionKind kind, |
4112 FunctionBodyType body_type, | 4105 FunctionBodyType body_type, |
4113 bool accept_IN, int pos, bool* ok) { | 4106 bool accept_IN, int pos, bool* ok) { |
4114 // function async_function() { | 4107 // function async_function() { |
(...skipping 20 matching lines...) Expand all Loading... | |
4135 | 4128 |
4136 ZoneList<Statement*>* inner_body = try_block->statements(); | 4129 ZoneList<Statement*>* inner_body = try_block->statements(); |
4137 | 4130 |
4138 Expression* return_value = nullptr; | 4131 Expression* return_value = nullptr; |
4139 if (body_type == FunctionBodyType::kNormal) { | 4132 if (body_type == FunctionBodyType::kNormal) { |
4140 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); | 4133 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); |
4141 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); | 4134 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); |
4142 } else { | 4135 } else { |
4143 return_value = | 4136 return_value = |
4144 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); | 4137 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); |
4145 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_VOID); | 4138 ParserBaseTraits<Parser>::RewriteNonPattern(classifier, CHECK_OK_VOID); |
4146 } | 4139 } |
4147 | 4140 |
4148 return_value = BuildPromiseResolve(return_value, return_value->position()); | 4141 return_value = BuildPromiseResolve(return_value, return_value->position()); |
4149 inner_body->Add( | 4142 inner_body->Add( |
4150 factory()->NewReturnStatement(return_value, return_value->position()), | 4143 factory()->NewReturnStatement(return_value, return_value->position()), |
4151 zone()); | 4144 zone()); |
4152 body->Add(BuildRejectPromiseOnException(try_block), zone()); | 4145 body->Add(BuildRejectPromiseOnException(try_block), zone()); |
4153 scope->set_end_position(scanner()->location().end_pos); | 4146 scope->set_end_position(scanner()->location().end_pos); |
4154 } | 4147 } |
4155 | 4148 |
4156 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4149 DoExpression* Parser::ParseDoExpression(bool* ok) { |
4157 // AssignmentExpression :: | 4150 // AssignmentExpression :: |
4158 // do '{' StatementList '}' | 4151 // do '{' StatementList '}' |
4159 int pos = peek_position(); | 4152 int pos = peek_position(); |
4160 | 4153 |
4161 Expect(Token::DO, CHECK_OK); | 4154 Expect(Token::DO, CHECK_OK); |
4162 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 4155 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
4163 Block* block = ParseBlock(nullptr, CHECK_OK); | 4156 Block* block = ParseBlock(nullptr, CHECK_OK); |
4164 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4157 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
4165 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 4158 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
4166 *ok = false; | 4159 *ok = false; |
4167 return nullptr; | 4160 return nullptr; |
4168 } | 4161 } |
4169 return expr; | 4162 return expr; |
4170 } | 4163 } |
4171 | 4164 |
4172 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4165 void ParserBaseTraits<Parser>::ParseArrowFunctionFormalParameterList( |
4173 ParserFormalParameters* parameters, Expression* expr, | 4166 ParserFormalParameters* parameters, Expression* expr, |
4174 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 4167 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
4175 const Scope::Snapshot& scope_snapshot, bool* ok) { | 4168 const Scope::Snapshot& scope_snapshot, bool* ok) { |
4176 if (expr->IsEmptyParentheses()) return; | 4169 if (expr->IsEmptyParentheses()) return; |
4177 | 4170 |
4178 parser_->ParseArrowFunctionFormalParameters( | 4171 delegate()->ParseArrowFunctionFormalParameters( |
4179 parameters, expr, params_loc.end_pos, CHECK_OK_VOID); | 4172 parameters, expr, params_loc.end_pos, CHECK_OK_VOID); |
4180 | 4173 |
4181 scope_snapshot.Reparent(parameters->scope); | 4174 scope_snapshot.Reparent(parameters->scope); |
4182 | 4175 |
4183 if (parameters->Arity() > Code::kMaxArguments) { | 4176 if (parameters->Arity() > Code::kMaxArguments) { |
4184 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 4177 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
4185 *ok = false; | 4178 *ok = false; |
4186 return; | 4179 return; |
4187 } | 4180 } |
4188 | 4181 |
4189 Type::ExpressionClassifier classifier(parser_); | 4182 Type::ExpressionClassifier classifier(delegate()); |
4190 if (!parameters->is_simple) { | 4183 if (!parameters->is_simple) { |
4191 classifier.RecordNonSimpleParameter(); | 4184 classifier.RecordNonSimpleParameter(); |
4192 } | 4185 } |
4193 for (int i = 0; i < parameters->Arity(); ++i) { | 4186 for (int i = 0; i < parameters->Arity(); ++i) { |
4194 auto parameter = parameters->at(i); | 4187 auto parameter = parameters->at(i); |
4195 DeclareFormalParameter(parameters->scope, parameter, &classifier); | 4188 DeclareFormalParameter(parameters->scope, parameter, &classifier); |
4196 if (!duplicate_loc->IsValid()) { | 4189 if (!duplicate_loc->IsValid()) { |
4197 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 4190 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; |
4198 } | 4191 } |
4199 } | 4192 } |
4200 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); | 4193 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); |
4201 } | 4194 } |
4202 | 4195 |
4203 | 4196 void ParserBaseTraits<Parser>::ReindexLiterals( |
4204 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { | 4197 const ParserFormalParameters& parameters) { |
4205 if (parser_->function_state_->materialized_literal_count() > 0) { | 4198 if (delegate()->function_state_->materialized_literal_count() > 0) { |
4206 AstLiteralReindexer reindexer; | 4199 AstLiteralReindexer reindexer; |
4207 | 4200 |
4208 for (const auto p : parameters.params) { | 4201 for (const auto p : parameters.params) { |
4209 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); | 4202 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); |
4210 if (p.initializer != nullptr) reindexer.Reindex(p.initializer); | 4203 if (p.initializer != nullptr) reindexer.Reindex(p.initializer); |
4211 } | 4204 } |
4212 | 4205 |
4213 DCHECK(reindexer.count() <= | 4206 DCHECK(reindexer.count() <= |
4214 parser_->function_state_->materialized_literal_count()); | 4207 delegate()->function_state_->materialized_literal_count()); |
4215 } | 4208 } |
4216 } | 4209 } |
4217 | 4210 |
4218 | 4211 |
4219 FunctionLiteral* Parser::ParseFunctionLiteral( | 4212 FunctionLiteral* Parser::ParseFunctionLiteral( |
4220 const AstRawString* function_name, Scanner::Location function_name_location, | 4213 const AstRawString* function_name, Scanner::Location function_name_location, |
4221 FunctionNameValidity function_name_validity, FunctionKind kind, | 4214 FunctionNameValidity function_name_validity, FunctionKind kind, |
4222 int function_token_pos, FunctionLiteral::FunctionType function_type, | 4215 int function_token_pos, FunctionLiteral::FunctionType function_type, |
4223 LanguageMode language_mode, bool* ok) { | 4216 LanguageMode language_mode, bool* ok) { |
4224 // Function :: | 4217 // Function :: |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4439 if (is_strict(language_mode)) { | 4432 if (is_strict(language_mode)) { |
4440 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4433 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4441 CHECK_OK); | 4434 CHECK_OK); |
4442 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(), | 4435 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(), |
4443 scope->end_position()); | 4436 scope->end_position()); |
4444 } | 4437 } |
4445 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4438 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4446 | 4439 |
4447 if (body) { | 4440 if (body) { |
4448 // If body can be inspected, rewrite queued destructuring assignments | 4441 // If body can be inspected, rewrite queued destructuring assignments |
4449 ParserTraits::RewriteDestructuringAssignments(); | 4442 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); |
4450 } | 4443 } |
4451 has_duplicate_parameters = | 4444 has_duplicate_parameters = |
4452 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4445 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4453 | 4446 |
4454 if (use_temp_zone) { | 4447 if (use_temp_zone) { |
4455 DCHECK(main_scope != scope); | 4448 DCHECK(main_scope != scope); |
4456 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory); | 4449 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory); |
4457 } | 4450 } |
4458 } // DiscardableZoneScope goes out of scope. | 4451 } // DiscardableZoneScope goes out of scope. |
4459 | 4452 |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5466 | 5459 |
5467 // We cannot internalize on a background thread; a foreground task will take | 5460 // We cannot internalize on a background thread; a foreground task will take |
5468 // care of calling Parser::Internalize just before compilation. | 5461 // care of calling Parser::Internalize just before compilation. |
5469 | 5462 |
5470 if (produce_cached_parse_data()) { | 5463 if (produce_cached_parse_data()) { |
5471 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); | 5464 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); |
5472 log_ = NULL; | 5465 log_ = NULL; |
5473 } | 5466 } |
5474 } | 5467 } |
5475 | 5468 |
5476 | 5469 ParserBaseTraits<Parser>::TemplateLiteralState Parser::OpenTemplateLiteral( |
5477 ParserTraits::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { | 5470 int pos) { |
5478 return new (zone()) ParserTraits::TemplateLiteral(zone(), pos); | 5471 return new (zone()) ParserBaseTraits<Parser>::TemplateLiteral(zone(), pos); |
5479 } | 5472 } |
5480 | 5473 |
5481 | 5474 |
5482 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | 5475 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { |
5483 int pos = scanner()->location().beg_pos; | 5476 int pos = scanner()->location().beg_pos; |
5484 int end = scanner()->location().end_pos - (tail ? 1 : 2); | 5477 int end = scanner()->location().end_pos - (tail ? 1 : 2); |
5485 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); | 5478 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); |
5486 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); | 5479 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); |
5487 Literal* cooked = factory()->NewStringLiteral(tv, pos); | 5480 Literal* cooked = factory()->NewStringLiteral(tv, pos); |
5488 Literal* raw = factory()->NewStringLiteral(trv, pos); | 5481 Literal* raw = factory()->NewStringLiteral(trv, pos); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5733 for (int i = 0; i < tail_call_expressions.length(); ++i) { | 5726 for (int i = 0; i < tail_call_expressions.length(); ++i) { |
5734 Expression* expression = tail_call_expressions[i]; | 5727 Expression* expression = tail_call_expressions[i]; |
5735 // If only FLAG_harmony_explicit_tailcalls is enabled then expression | 5728 // If only FLAG_harmony_explicit_tailcalls is enabled then expression |
5736 // must be a Call expression. | 5729 // must be a Call expression. |
5737 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || | 5730 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || |
5738 expression->IsCall()); | 5731 expression->IsCall()); |
5739 MarkTailPosition(expression); | 5732 MarkTailPosition(expression); |
5740 } | 5733 } |
5741 } | 5734 } |
5742 | 5735 |
5743 Expression* ParserTraits::ExpressionListToExpression( | 5736 Expression* ParserBaseTraits<Parser>::ExpressionListToExpression( |
5744 ZoneList<Expression*>* args) { | 5737 ZoneList<Expression*>* args) { |
5745 AstNodeFactory* factory = parser_->factory(); | 5738 AstNodeFactory* factory = delegate()->factory(); |
5746 Expression* expr = args->at(0); | 5739 Expression* expr = args->at(0); |
5747 for (int i = 1; i < args->length(); ++i) { | 5740 for (int i = 1; i < args->length(); ++i) { |
5748 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), | 5741 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), |
5749 expr->position()); | 5742 expr->position()); |
5750 } | 5743 } |
5751 return expr; | 5744 return expr; |
5752 } | 5745 } |
5753 | 5746 |
5754 void ParserTraits::RewriteDestructuringAssignments() { | 5747 void ParserBaseTraits<Parser>::RewriteDestructuringAssignments() { |
5755 parser_->RewriteDestructuringAssignments(); | 5748 delegate()->RewriteDestructuringAssignments(); |
5756 } | 5749 } |
5757 | 5750 |
5758 Expression* ParserTraits::RewriteExponentiation(Expression* left, | 5751 Expression* ParserBaseTraits<Parser>::RewriteExponentiation(Expression* left, |
5759 Expression* right, int pos) { | 5752 Expression* right, |
5760 return parser_->RewriteExponentiation(left, right, pos); | 5753 int pos) { |
5754 return delegate()->RewriteExponentiation(left, right, pos); | |
5761 } | 5755 } |
5762 | 5756 |
5763 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left, | 5757 Expression* ParserBaseTraits<Parser>::RewriteAssignExponentiation( |
5764 Expression* right, | 5758 Expression* left, Expression* right, int pos) { |
5765 int pos) { | 5759 return delegate()->RewriteAssignExponentiation(left, right, pos); |
5766 return parser_->RewriteAssignExponentiation(left, right, pos); | |
5767 } | 5760 } |
5768 | 5761 |
5769 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5762 void ParserBaseTraits<Parser>::RewriteNonPattern( |
5770 bool* ok) { | 5763 Type::ExpressionClassifier* classifier, bool* ok) { |
5771 parser_->RewriteNonPattern(classifier, ok); | 5764 delegate()->RewriteNonPattern(classifier, ok); |
5772 } | 5765 } |
5773 | 5766 |
5774 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, | 5767 Expression* ParserBaseTraits<Parser>::RewriteAwaitExpression(Expression* value, |
5775 int await_pos) { | 5768 int await_pos) { |
5776 // yield %AsyncFunctionAwait(.generator_object, <operand>) | 5769 // yield %AsyncFunctionAwait(.generator_object, <operand>) |
5777 Variable* generator_object_variable = | 5770 Variable* generator_object_variable = |
5778 parser_->function_state_->generator_object_variable(); | 5771 delegate()->function_state_->generator_object_variable(); |
5779 | 5772 |
5780 // If generator_object_variable is null, | 5773 // If generator_object_variable is null, |
5781 if (!generator_object_variable) return value; | 5774 if (!generator_object_variable) return value; |
5782 | 5775 |
5783 auto factory = parser_->factory(); | 5776 auto factory = delegate()->factory(); |
5784 const int nopos = kNoSourcePosition; | 5777 const int nopos = kNoSourcePosition; |
5785 | 5778 |
5786 Variable* temp_var = | 5779 Variable* temp_var = |
5787 parser_->NewTemporary(parser_->ast_value_factory()->empty_string()); | 5780 delegate()->NewTemporary(delegate()->ast_value_factory()->empty_string()); |
5788 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); | 5781 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); |
5789 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); | 5782 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); |
5790 | 5783 |
5791 // Wrap value evaluation to provide a break location. | 5784 // Wrap value evaluation to provide a break location. |
5792 Expression* value_assignment = | 5785 Expression* value_assignment = |
5793 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); | 5786 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); |
5794 do_block->statements()->Add( | 5787 do_block->statements()->Add( |
5795 factory->NewExpressionStatement(value_assignment, value->position()), | 5788 factory->NewExpressionStatement(value_assignment, value->position()), |
5796 zone()); | 5789 zone()); |
5797 | 5790 |
5798 ZoneList<Expression*>* async_function_await_args = | 5791 ZoneList<Expression*>* async_function_await_args = |
5799 new (zone()) ZoneList<Expression*>(2, zone()); | 5792 new (zone()) ZoneList<Expression*>(2, zone()); |
5800 Expression* generator_object = | 5793 Expression* generator_object = |
5801 factory->NewVariableProxy(generator_object_variable); | 5794 factory->NewVariableProxy(generator_object_variable); |
5802 async_function_await_args->Add(generator_object, zone()); | 5795 async_function_await_args->Add(generator_object, zone()); |
5803 async_function_await_args->Add(temp_proxy, zone()); | 5796 async_function_await_args->Add(temp_proxy, zone()); |
5804 Expression* async_function_await = parser_->factory()->NewCallRuntime( | 5797 Expression* async_function_await = delegate()->factory()->NewCallRuntime( |
5805 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); | 5798 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); |
5806 // Wrap await to provide a break location between value evaluation and yield. | 5799 // Wrap await to provide a break location between value evaluation and yield. |
5807 Expression* await_assignment = factory->NewAssignment( | 5800 Expression* await_assignment = factory->NewAssignment( |
5808 Token::ASSIGN, temp_proxy, async_function_await, nopos); | 5801 Token::ASSIGN, temp_proxy, async_function_await, nopos); |
5809 do_block->statements()->Add( | 5802 do_block->statements()->Add( |
5810 factory->NewExpressionStatement(await_assignment, await_pos), zone()); | 5803 factory->NewExpressionStatement(await_assignment, await_pos), zone()); |
5811 Expression* do_expr = factory->NewDoExpression(do_block, temp_var, nopos); | 5804 Expression* do_expr = factory->NewDoExpression(do_block, temp_var, nopos); |
5812 | 5805 |
5813 generator_object = factory->NewVariableProxy(generator_object_variable); | 5806 generator_object = factory->NewVariableProxy(generator_object_variable); |
5814 return factory->NewYield(generator_object, do_expr, nopos, | 5807 return factory->NewYield(generator_object, do_expr, nopos, |
5815 Yield::kOnExceptionRethrow); | 5808 Yield::kOnExceptionRethrow); |
5816 } | 5809 } |
5817 | 5810 |
5818 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { | 5811 ZoneList<Expression*>* ParserBaseTraits<Parser>::GetNonPatternList() const { |
5819 return parser_->function_state_->non_patterns_to_rewrite(); | 5812 return delegate()->function_state_->non_patterns_to_rewrite(); |
5820 } | 5813 } |
5821 | 5814 |
5822 | 5815 |
5823 ZoneList<typename ParserTraits::Type::ExpressionClassifier::Error>* | 5816 ZoneList<typename ParserBaseTraits<Parser>::Type::ExpressionClassifier::Error>* |
5824 ParserTraits::GetReportedErrorList() const { | 5817 ParserBaseTraits<Parser>::GetReportedErrorList() const { |
5825 return parser_->function_state_->GetReportedErrorList(); | 5818 return delegate()->function_state_->GetReportedErrorList(); |
5826 } | 5819 } |
5827 | 5820 |
5828 Zone* ParserTraits::zone() const { return parser_->zone(); } | 5821 Zone* ParserBaseTraits<Parser>::zone() const { return delegate()->zone(); } |
5829 | 5822 |
5830 class NonPatternRewriter : public AstExpressionRewriter { | 5823 class NonPatternRewriter : public AstExpressionRewriter { |
5831 public: | 5824 public: |
5832 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) | 5825 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) |
5833 : AstExpressionRewriter(stack_limit), parser_(parser) {} | 5826 : AstExpressionRewriter(stack_limit), parser_(parser) {} |
5834 ~NonPatternRewriter() override {} | 5827 ~NonPatternRewriter() override {} |
5835 | 5828 |
5836 private: | 5829 private: |
5837 bool RewriteExpression(Expression* expr) override { | 5830 bool RewriteExpression(Expression* expr) override { |
5838 if (expr->IsRewritableExpression()) return true; | 5831 if (expr->IsRewritableExpression()) return true; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6018 append_body, finalize); | 6011 append_body, finalize); |
6019 do_block->statements()->Add(loop, zone()); | 6012 do_block->statements()->Add(loop, zone()); |
6020 } | 6013 } |
6021 } | 6014 } |
6022 // Now, rewind the original array literal to truncate everything from the | 6015 // Now, rewind the original array literal to truncate everything from the |
6023 // first spread (included) until the end. This fixes $R's initialization. | 6016 // first spread (included) until the end. This fixes $R's initialization. |
6024 lit->RewindSpreads(); | 6017 lit->RewindSpreads(); |
6025 return factory()->NewDoExpression(do_block, result, lit->position()); | 6018 return factory()->NewDoExpression(do_block, result, lit->position()); |
6026 } | 6019 } |
6027 | 6020 |
6021 void ParserBaseTraits<Parser>::QueueDestructuringAssignmentForRewriting( | |
6022 Expression* expr) { | |
6023 DCHECK(expr->IsRewritableExpression()); | |
6024 delegate()->function_state_->AddDestructuringAssignment( | |
6025 Parser::DestructuringAssignment(expr, delegate()->scope())); | |
6026 } | |
6028 | 6027 |
6029 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 6028 void ParserBaseTraits<Parser>::QueueNonPatternForRewriting(Expression* expr, |
6029 bool* ok) { | |
6030 DCHECK(expr->IsRewritableExpression()); | 6030 DCHECK(expr->IsRewritableExpression()); |
6031 parser_->function_state_->AddDestructuringAssignment( | 6031 delegate()->function_state_->AddNonPatternForRewriting(expr, ok); |
6032 Parser::DestructuringAssignment(expr, parser_->scope())); | |
6033 } | 6032 } |
6034 | 6033 |
6035 | 6034 |
6036 void ParserTraits::QueueNonPatternForRewriting(Expression* expr, bool* ok) { | 6035 void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName( |
6037 DCHECK(expr->IsRewritableExpression()); | |
6038 parser_->function_state_->AddNonPatternForRewriting(expr, ok); | |
6039 } | |
6040 | |
6041 | |
6042 void ParserTraits::SetFunctionNameFromPropertyName( | |
6043 ObjectLiteralProperty* property, const AstRawString* name) { | 6036 ObjectLiteralProperty* property, const AstRawString* name) { |
6044 Expression* value = property->value(); | 6037 Expression* value = property->value(); |
6045 | 6038 |
6046 // Computed name setting must happen at runtime. | 6039 // Computed name setting must happen at runtime. |
6047 if (property->is_computed_name()) return; | 6040 if (property->is_computed_name()) return; |
6048 | 6041 |
6049 // Getter and setter names are handled here because their names | 6042 // Getter and setter names are handled here because their names |
6050 // change in ES2015, even though they are not anonymous. | 6043 // change in ES2015, even though they are not anonymous. |
6051 auto function = value->AsFunctionLiteral(); | 6044 auto function = value->AsFunctionLiteral(); |
6052 if (function != nullptr) { | 6045 if (function != nullptr) { |
6053 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER; | 6046 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER; |
6054 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER; | 6047 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER; |
6055 if (is_getter || is_setter) { | 6048 if (is_getter || is_setter) { |
6056 DCHECK_NOT_NULL(name); | 6049 DCHECK_NOT_NULL(name); |
6057 const AstRawString* prefix = | 6050 const AstRawString* prefix = |
6058 is_getter ? parser_->ast_value_factory()->get_space_string() | 6051 is_getter ? delegate()->ast_value_factory()->get_space_string() |
6059 : parser_->ast_value_factory()->set_space_string(); | 6052 : delegate()->ast_value_factory()->set_space_string(); |
6060 function->set_raw_name( | 6053 function->set_raw_name( |
6061 parser_->ast_value_factory()->NewConsString(prefix, name)); | 6054 delegate()->ast_value_factory()->NewConsString(prefix, name)); |
6062 return; | 6055 return; |
6063 } | 6056 } |
6064 } | 6057 } |
6065 | 6058 |
6066 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] | 6059 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] |
6067 // of an object literal. | 6060 // of an object literal. |
6068 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; | 6061 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; |
6069 | 6062 |
6070 DCHECK(!value->IsAnonymousFunctionDefinition() || | 6063 DCHECK(!value->IsAnonymousFunctionDefinition() || |
6071 property->kind() == ObjectLiteralProperty::COMPUTED); | 6064 property->kind() == ObjectLiteralProperty::COMPUTED); |
6072 parser_->SetFunctionName(value, name); | 6065 delegate()->SetFunctionName(value, name); |
6073 } | 6066 } |
6074 | 6067 |
6075 | 6068 void ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef( |
6076 void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value, | 6069 Expression* value, Expression* identifier) { |
6077 Expression* identifier) { | |
6078 if (!identifier->IsVariableProxy()) return; | 6070 if (!identifier->IsVariableProxy()) return; |
6079 parser_->SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); | 6071 delegate()->SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); |
6080 } | 6072 } |
6081 | 6073 |
6082 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { | 6074 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { |
6083 DCHECK_NOT_NULL(name); | 6075 DCHECK_NOT_NULL(name); |
6084 if (!value->IsAnonymousFunctionDefinition()) return; | 6076 if (!value->IsAnonymousFunctionDefinition()) return; |
6085 auto function = value->AsFunctionLiteral(); | 6077 auto function = value->AsFunctionLiteral(); |
6086 if (function != nullptr) { | 6078 if (function != nullptr) { |
6087 function->set_raw_name(name); | 6079 function->set_raw_name(name); |
6088 } else { | 6080 } else { |
6089 DCHECK(value->IsDoExpression()); | 6081 DCHECK(value->IsDoExpression()); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7022 node->Print(Isolate::Current()); | 7014 node->Print(Isolate::Current()); |
7023 } | 7015 } |
7024 #endif // DEBUG | 7016 #endif // DEBUG |
7025 | 7017 |
7026 #undef CHECK_OK | 7018 #undef CHECK_OK |
7027 #undef CHECK_OK_VOID | 7019 #undef CHECK_OK_VOID |
7028 #undef CHECK_FAILED | 7020 #undef CHECK_FAILED |
7029 | 7021 |
7030 } // namespace internal | 7022 } // namespace internal |
7031 } // namespace v8 | 7023 } // namespace v8 |
OLD | NEW |