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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 bool* ok); | 378 bool* ok); |
379 | 379 |
380 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); | 380 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); |
381 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); | 381 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); |
382 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); | 382 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); |
383 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); | 383 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); |
384 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 384 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
385 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, | 385 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, |
386 bool* ok); | 386 bool* ok); |
387 typename Traits::Type::Expression ParseYieldExpression(bool* ok); | 387 typename Traits::Type::Expression ParseYieldExpression(bool* ok); |
| 388 typename Traits::Type::Expression ParseConditionalExpression(bool accept_IN, |
| 389 bool* ok); |
388 | 390 |
389 // Used to detect duplicates in object literals. Each of the values | 391 // Used to detect duplicates in object literals. Each of the values |
390 // kGetterProperty, kSetterProperty and kValueProperty represents | 392 // kGetterProperty, kSetterProperty and kValueProperty represents |
391 // a type of object literal property. When parsing a property, its | 393 // a type of object literal property. When parsing a property, its |
392 // type value is stored in the DuplicateFinder for the property name. | 394 // type value is stored in the DuplicateFinder for the property name. |
393 // Values are chosen so that having intersection bits means the there is | 395 // Values are chosen so that having intersection bits means the there is |
394 // an incompatibility. | 396 // an incompatibility. |
395 // I.e., you can add a getter to a property that already has a setter, since | 397 // I.e., you can add a getter to a property that already has a setter, since |
396 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 398 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
397 // already has a getter or a value. Adding the getter to an existing | 399 // already has a getter or a value. Adding the getter to an existing |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 PreParserExpression NewVariableProxy(void* generator_variable) { | 710 PreParserExpression NewVariableProxy(void* generator_variable) { |
709 return PreParserExpression::Default(); | 711 return PreParserExpression::Default(); |
710 } | 712 } |
711 | 713 |
712 PreParserExpression NewYield(PreParserExpression generator_object, | 714 PreParserExpression NewYield(PreParserExpression generator_object, |
713 PreParserExpression expression, | 715 PreParserExpression expression, |
714 Yield::Kind yield_kind, | 716 Yield::Kind yield_kind, |
715 int pos) { | 717 int pos) { |
716 return PreParserExpression::Default(); | 718 return PreParserExpression::Default(); |
717 } | 719 } |
| 720 |
| 721 PreParserExpression NewConditional(PreParserExpression condition, |
| 722 PreParserExpression then_expression, |
| 723 PreParserExpression else_expression, |
| 724 int pos) { |
| 725 return PreParserExpression::Default(); |
| 726 } |
718 }; | 727 }; |
719 | 728 |
720 | 729 |
721 class PreParser; | 730 class PreParser; |
722 | 731 |
723 class PreParserTraits { | 732 class PreParserTraits { |
724 public: | 733 public: |
725 struct Type { | 734 struct Type { |
726 // TODO(marja): To be removed. The Traits object should contain all the data | 735 // TODO(marja): To be removed. The Traits object should contain all the data |
727 // it needs. | 736 // it needs. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 // Temporary glue; these functions will move to ParserBase. | 889 // Temporary glue; these functions will move to ParserBase. |
881 PreParserExpression ParseV8Intrinsic(bool* ok); | 890 PreParserExpression ParseV8Intrinsic(bool* ok); |
882 PreParserExpression ParseFunctionLiteral( | 891 PreParserExpression ParseFunctionLiteral( |
883 PreParserIdentifier name, | 892 PreParserIdentifier name, |
884 Scanner::Location function_name_location, | 893 Scanner::Location function_name_location, |
885 bool name_is_strict_reserved, | 894 bool name_is_strict_reserved, |
886 bool is_generator, | 895 bool is_generator, |
887 int function_token_position, | 896 int function_token_position, |
888 FunctionLiteral::FunctionType type, | 897 FunctionLiteral::FunctionType type, |
889 bool* ok); | 898 bool* ok); |
890 PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok); | 899 PreParserExpression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
891 | 900 |
892 private: | 901 private: |
893 PreParser* pre_parser_; | 902 PreParser* pre_parser_; |
894 }; | 903 }; |
895 | 904 |
896 | 905 |
897 // Preparsing checks a JavaScript program and emits preparse-data that helps | 906 // Preparsing checks a JavaScript program and emits preparse-data that helps |
898 // a later parsing to be faster. | 907 // a later parsing to be faster. |
899 // See preparse-data-format.h for the data format. | 908 // See preparse-data-format.h for the data format. |
900 | 909 |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 ParseAssignmentExpression(false, CHECK_OK); | 1691 ParseAssignmentExpression(false, CHECK_OK); |
1683 typename Traits::Type::YieldExpression yield = | 1692 typename Traits::Type::YieldExpression yield = |
1684 factory()->NewYield(generator_object, expression, kind, pos); | 1693 factory()->NewYield(generator_object, expression, kind, pos); |
1685 if (kind == Yield::DELEGATING) { | 1694 if (kind == Yield::DELEGATING) { |
1686 yield->set_index(function_state_->NextHandlerIndex()); | 1695 yield->set_index(function_state_->NextHandlerIndex()); |
1687 } | 1696 } |
1688 return yield; | 1697 return yield; |
1689 } | 1698 } |
1690 | 1699 |
1691 | 1700 |
| 1701 // Precedence = 3 |
| 1702 template <class Traits> |
| 1703 typename Traits::Type::Expression |
| 1704 ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, bool* ok) { |
| 1705 // ConditionalExpression :: |
| 1706 // LogicalOrExpression |
| 1707 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
| 1708 |
| 1709 int pos = peek_position(); |
| 1710 // We start using the binary expression parser for prec >= 4 only! |
| 1711 typename Traits::Type::Expression expression = |
| 1712 this->ParseBinaryExpression(4, accept_IN, CHECK_OK); |
| 1713 if (peek() != Token::CONDITIONAL) return expression; |
| 1714 Consume(Token::CONDITIONAL); |
| 1715 // In parsing the first assignment expression in conditional |
| 1716 // expressions we always accept the 'in' keyword; see ECMA-262, |
| 1717 // section 11.12, page 58. |
| 1718 typename Traits::Type::Expression left = |
| 1719 ParseAssignmentExpression(true, CHECK_OK); |
| 1720 Expect(Token::COLON, CHECK_OK); |
| 1721 typename Traits::Type::Expression right = |
| 1722 ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 1723 return factory()->NewConditional(expression, left, right, pos); |
| 1724 } |
| 1725 |
| 1726 |
1692 #undef CHECK_OK | 1727 #undef CHECK_OK |
1693 #undef CHECK_OK_CUSTOM | 1728 #undef CHECK_OK_CUSTOM |
1694 | 1729 |
1695 | 1730 |
1696 template <typename Traits> | 1731 template <typename Traits> |
1697 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 1732 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
1698 Token::Value property, | 1733 Token::Value property, |
1699 PropertyKind type, | 1734 PropertyKind type, |
1700 bool* ok) { | 1735 bool* ok) { |
1701 int old; | 1736 int old; |
(...skipping 20 matching lines...) Expand all Loading... |
1722 "accessor_get_set"); | 1757 "accessor_get_set"); |
1723 } | 1758 } |
1724 *ok = false; | 1759 *ok = false; |
1725 } | 1760 } |
1726 } | 1761 } |
1727 | 1762 |
1728 | 1763 |
1729 } } // v8::internal | 1764 } } // v8::internal |
1730 | 1765 |
1731 #endif // V8_PREPARSER_H | 1766 #endif // V8_PREPARSER_H |
OLD | NEW |