OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal, | 338 typename Traits::Type::Expression ParseRegExpLiteral(bool seen_equal, |
339 bool* ok); | 339 bool* ok); |
340 | 340 |
341 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); | 341 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); |
342 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); | 342 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); |
343 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); | 343 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); |
344 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); | 344 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); |
345 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 345 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
346 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, | 346 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, |
347 bool* ok); | 347 bool* ok); |
| 348 typename Traits::Type::Expression ParseYieldExpression(bool* ok); |
348 | 349 |
349 // Used to detect duplicates in object literals. Each of the values | 350 // Used to detect duplicates in object literals. Each of the values |
350 // kGetterProperty, kSetterProperty and kValueProperty represents | 351 // kGetterProperty, kSetterProperty and kValueProperty represents |
351 // a type of object literal property. When parsing a property, its | 352 // a type of object literal property. When parsing a property, its |
352 // type value is stored in the DuplicateFinder for the property name. | 353 // type value is stored in the DuplicateFinder for the property name. |
353 // Values are chosen so that having intersection bits means the there is | 354 // Values are chosen so that having intersection bits means the there is |
354 // an incompatibility. | 355 // an incompatibility. |
355 // I.e., you can add a getter to a property that already has a setter, since | 356 // I.e., you can add a getter to a property that already has a setter, since |
356 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 357 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
357 // already has a getter or a value. Adding the getter to an existing | 358 // already has a getter or a value. Adding the getter to an existing |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 bool IsStrictFunction() { return code_ == kStrictFunctionExpression; } | 529 bool IsStrictFunction() { return code_ == kStrictFunctionExpression; } |
529 | 530 |
530 // Dummy implementation for making expression->AsCall() work (see below). | 531 // Dummy implementation for making expression->AsCall() work (see below). |
531 PreParserExpression* operator->() { return this; } | 532 PreParserExpression* operator->() { return this; } |
532 | 533 |
533 // These are only used when doing function name inferring, and PreParser | 534 // These are only used when doing function name inferring, and PreParser |
534 // doesn't do function name inferring. | 535 // doesn't do function name inferring. |
535 void* AsCall() const { return NULL; } | 536 void* AsCall() const { return NULL; } |
536 void* AsCallNew() const { return NULL; } | 537 void* AsCallNew() const { return NULL; } |
537 | 538 |
| 539 // More dummy implementations of things PreParser doesn't need to track: |
| 540 void set_index(int index) {} // For YieldExpressions |
| 541 |
538 private: | 542 private: |
539 // First two/three bits are used as flags. | 543 // First two/three bits are used as flags. |
540 // Bit 0 and 1 represent identifiers or strings literals, and are | 544 // Bit 0 and 1 represent identifiers or strings literals, and are |
541 // mutually exclusive, but can both be absent. | 545 // mutually exclusive, but can both be absent. |
542 enum { | 546 enum { |
543 kUnknownExpression = 0, | 547 kUnknownExpression = 0, |
544 // Identifiers | 548 // Identifiers |
545 kIdentifierFlag = 1, // Used to detect labels. | 549 kIdentifierFlag = 1, // Used to detect labels. |
546 kIdentifierShift = 3, | 550 kIdentifierShift = 3, |
547 | 551 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 int pos) { | 658 int pos) { |
655 return PreParserExpression::Default(); | 659 return PreParserExpression::Default(); |
656 } | 660 } |
657 | 661 |
658 PreParserExpression NewAssignment(Token::Value op, | 662 PreParserExpression NewAssignment(Token::Value op, |
659 PreParserExpression left, | 663 PreParserExpression left, |
660 PreParserExpression right, | 664 PreParserExpression right, |
661 int pos) { | 665 int pos) { |
662 return PreParserExpression::Default(); | 666 return PreParserExpression::Default(); |
663 } | 667 } |
| 668 |
| 669 PreParserExpression NewVariableProxy(void* generator_variable) { |
| 670 return PreParserExpression::Default(); |
| 671 } |
| 672 |
| 673 PreParserExpression NewYield(PreParserExpression generator_object, |
| 674 PreParserExpression expression, |
| 675 Yield::Kind yield_kind, |
| 676 int pos) { |
| 677 return PreParserExpression::Default(); |
| 678 } |
664 }; | 679 }; |
665 | 680 |
666 | 681 |
667 class PreParser; | 682 class PreParser; |
668 | 683 |
669 class PreParserTraits { | 684 class PreParserTraits { |
670 public: | 685 public: |
671 struct Type { | 686 struct Type { |
672 typedef PreParser* Parser; | 687 typedef PreParser* Parser; |
673 | 688 |
674 // Types used by FunctionState and BlockState. | 689 // Types used by FunctionState and BlockState. |
675 typedef PreParserScope Scope; | 690 typedef PreParserScope Scope; |
676 typedef PreParserFactory Factory; | 691 typedef PreParserFactory Factory; |
677 // PreParser doesn't need to store generator variables. | 692 // PreParser doesn't need to store generator variables. |
678 typedef void GeneratorVariable; | 693 typedef void GeneratorVariable; |
679 // No interaction with Zones. | 694 // No interaction with Zones. |
680 typedef void Zone; | 695 typedef void Zone; |
681 | 696 |
682 // Return types for traversing functions. | 697 // Return types for traversing functions. |
683 typedef PreParserIdentifier Identifier; | 698 typedef PreParserIdentifier Identifier; |
684 typedef PreParserExpression Expression; | 699 typedef PreParserExpression Expression; |
| 700 typedef PreParserExpression YieldExpression; |
685 typedef PreParserExpression FunctionLiteral; | 701 typedef PreParserExpression FunctionLiteral; |
686 typedef PreParserExpression ObjectLiteralProperty; | 702 typedef PreParserExpression ObjectLiteralProperty; |
687 typedef PreParserExpression Literal; | 703 typedef PreParserExpression Literal; |
688 typedef PreParserExpressionList ExpressionList; | 704 typedef PreParserExpressionList ExpressionList; |
689 typedef PreParserExpressionList PropertyList; | 705 typedef PreParserExpressionList PropertyList; |
690 }; | 706 }; |
691 | 707 |
692 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 708 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
693 | 709 |
694 // Custom operations executed when FunctionStates are created and | 710 // Custom operations executed when FunctionStates are created and |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 // Temporary glue; these functions will move to ParserBase. | 837 // Temporary glue; these functions will move to ParserBase. |
822 PreParserExpression ParseV8Intrinsic(bool* ok); | 838 PreParserExpression ParseV8Intrinsic(bool* ok); |
823 PreParserExpression ParseFunctionLiteral( | 839 PreParserExpression ParseFunctionLiteral( |
824 PreParserIdentifier name, | 840 PreParserIdentifier name, |
825 Scanner::Location function_name_location, | 841 Scanner::Location function_name_location, |
826 bool name_is_strict_reserved, | 842 bool name_is_strict_reserved, |
827 bool is_generator, | 843 bool is_generator, |
828 int function_token_position, | 844 int function_token_position, |
829 FunctionLiteral::FunctionType type, | 845 FunctionLiteral::FunctionType type, |
830 bool* ok); | 846 bool* ok); |
831 PreParserExpression ParseYieldExpression(bool* ok); | |
832 PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok); | 847 PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok); |
833 | 848 |
834 private: | 849 private: |
835 PreParser* pre_parser_; | 850 PreParser* pre_parser_; |
836 }; | 851 }; |
837 | 852 |
838 | 853 |
839 // Preparsing checks a JavaScript program and emits preparse-data that helps | 854 // Preparsing checks a JavaScript program and emits preparse-data that helps |
840 // a later parsing to be faster. | 855 // a later parsing to be faster. |
841 // See preparse-data-format.h for the data format. | 856 // See preparse-data-format.h for the data format. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 Statement ParseBreakStatement(bool* ok); | 1002 Statement ParseBreakStatement(bool* ok); |
988 Statement ParseReturnStatement(bool* ok); | 1003 Statement ParseReturnStatement(bool* ok); |
989 Statement ParseWithStatement(bool* ok); | 1004 Statement ParseWithStatement(bool* ok); |
990 Statement ParseSwitchStatement(bool* ok); | 1005 Statement ParseSwitchStatement(bool* ok); |
991 Statement ParseDoWhileStatement(bool* ok); | 1006 Statement ParseDoWhileStatement(bool* ok); |
992 Statement ParseWhileStatement(bool* ok); | 1007 Statement ParseWhileStatement(bool* ok); |
993 Statement ParseForStatement(bool* ok); | 1008 Statement ParseForStatement(bool* ok); |
994 Statement ParseThrowStatement(bool* ok); | 1009 Statement ParseThrowStatement(bool* ok); |
995 Statement ParseTryStatement(bool* ok); | 1010 Statement ParseTryStatement(bool* ok); |
996 Statement ParseDebuggerStatement(bool* ok); | 1011 Statement ParseDebuggerStatement(bool* ok); |
997 Expression ParseYieldExpression(bool* ok); | |
998 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1012 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
999 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 1013 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
1000 Expression ParseUnaryExpression(bool* ok); | 1014 Expression ParseUnaryExpression(bool* ok); |
1001 Expression ParsePostfixExpression(bool* ok); | 1015 Expression ParsePostfixExpression(bool* ok); |
1002 Expression ParseLeftHandSideExpression(bool* ok); | 1016 Expression ParseLeftHandSideExpression(bool* ok); |
1003 Expression ParseMemberExpression(bool* ok); | 1017 Expression ParseMemberExpression(bool* ok); |
1004 Expression ParseMemberExpressionContinuation(PreParserExpression expression, | 1018 Expression ParseMemberExpressionContinuation(PreParserExpression expression, |
1005 bool* ok); | 1019 bool* ok); |
1006 Expression ParseMemberWithNewPrefixesExpression(bool* ok); | 1020 Expression ParseMemberWithNewPrefixesExpression(bool* ok); |
1007 Expression ParseObjectLiteral(bool* ok); | 1021 Expression ParseObjectLiteral(bool* ok); |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 fni_->Infer(); | 1623 fni_->Infer(); |
1610 } else { | 1624 } else { |
1611 fni_->RemoveLastFunction(); | 1625 fni_->RemoveLastFunction(); |
1612 } | 1626 } |
1613 fni_->Leave(); | 1627 fni_->Leave(); |
1614 } | 1628 } |
1615 | 1629 |
1616 return factory()->NewAssignment(op, expression, right, pos); | 1630 return factory()->NewAssignment(op, expression, right, pos); |
1617 } | 1631 } |
1618 | 1632 |
| 1633 template <class Traits> |
| 1634 typename Traits::Type::Expression ParserBase<Traits>::ParseYieldExpression( |
| 1635 bool* ok) { |
| 1636 // YieldExpression :: |
| 1637 // 'yield' '*'? AssignmentExpression |
| 1638 int pos = peek_position(); |
| 1639 Expect(Token::YIELD, CHECK_OK); |
| 1640 Yield::Kind kind = |
| 1641 Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND; |
| 1642 typename Traits::Type::Expression generator_object = |
| 1643 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
| 1644 typename Traits::Type::Expression expression = |
| 1645 ParseAssignmentExpression(false, CHECK_OK); |
| 1646 typename Traits::Type::YieldExpression yield = |
| 1647 factory()->NewYield(generator_object, expression, kind, pos); |
| 1648 if (kind == Yield::DELEGATING) { |
| 1649 yield->set_index(function_state_->NextHandlerIndex()); |
| 1650 } |
| 1651 return yield; |
| 1652 } |
| 1653 |
| 1654 |
1619 #undef CHECK_OK | 1655 #undef CHECK_OK |
1620 #undef CHECK_OK_CUSTOM | 1656 #undef CHECK_OK_CUSTOM |
1621 | 1657 |
1622 | 1658 |
1623 template <typename Traits> | 1659 template <typename Traits> |
1624 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 1660 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
1625 Token::Value property, | 1661 Token::Value property, |
1626 PropertyKind type, | 1662 PropertyKind type, |
1627 bool* ok) { | 1663 bool* ok) { |
1628 int old; | 1664 int old; |
(...skipping 22 matching lines...) Expand all Loading... |
1651 "accessor_get_set"); | 1687 "accessor_get_set"); |
1652 } | 1688 } |
1653 *ok = false; | 1689 *ok = false; |
1654 } | 1690 } |
1655 } | 1691 } |
1656 | 1692 |
1657 | 1693 |
1658 } } // v8::internal | 1694 } } // v8::internal |
1659 | 1695 |
1660 #endif // V8_PREPARSER_H | 1696 #endif // V8_PREPARSER_H |
OLD | NEW |