OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 void AddTemplateExpression(ExpressionT); | 571 void AddTemplateExpression(ExpressionT); |
572 ExpressionT ParseSuperExpression(bool is_new, bool* ok); | 572 ExpressionT ParseSuperExpression(bool is_new, bool* ok); |
573 | 573 |
574 // Checks if the expression is a valid reference expression (e.g., on the | 574 // Checks if the expression is a valid reference expression (e.g., on the |
575 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 575 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
576 // we allow calls for web compatibility and rewrite them to a runtime throw. | 576 // we allow calls for web compatibility and rewrite them to a runtime throw. |
577 ExpressionT CheckAndRewriteReferenceExpression( | 577 ExpressionT CheckAndRewriteReferenceExpression( |
578 ExpressionT expression, | 578 ExpressionT expression, |
579 Scanner::Location location, const char* message, bool* ok); | 579 Scanner::Location location, const char* message, bool* ok); |
580 | 580 |
581 ExpressionT MaybeSpread(ExpressionT expression, bool is_spread, int pos) { | |
582 if (is_spread) { | |
583 return factory()->NewSpreadOperation(scope_, expression, pos); | |
584 } | |
585 return expression; | |
586 } | |
587 | |
581 // Used to validate property names in object literals and class literals | 588 // Used to validate property names in object literals and class literals |
582 enum PropertyKind { | 589 enum PropertyKind { |
583 kAccessorProperty, | 590 kAccessorProperty, |
584 kValueProperty, | 591 kValueProperty, |
585 kMethodProperty | 592 kMethodProperty |
586 }; | 593 }; |
587 | 594 |
588 class ObjectLiteralCheckerBase { | 595 class ObjectLiteralCheckerBase { |
589 public: | 596 public: |
590 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} | 597 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 friend class PreParserExpression; | 762 friend class PreParserExpression; |
756 }; | 763 }; |
757 | 764 |
758 | 765 |
759 class PreParserExpression { | 766 class PreParserExpression { |
760 public: | 767 public: |
761 static PreParserExpression Default() { | 768 static PreParserExpression Default() { |
762 return PreParserExpression(TypeField::encode(kExpression)); | 769 return PreParserExpression(TypeField::encode(kExpression)); |
763 } | 770 } |
764 | 771 |
772 static PreParserExpression Spread(PreParserExpression expression) { | |
773 DCHECK(!expression.IsSpreadExpression() || expression.is_parenthesized()); | |
774 return PreParserExpression(TypeField::encode(kSpreadExpression)); | |
775 } | |
776 | |
765 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 777 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
766 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 778 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
767 IdentifierTypeField::encode(id.type_)); | 779 IdentifierTypeField::encode(id.type_)); |
768 } | 780 } |
769 | 781 |
770 static PreParserExpression BinaryOperation(PreParserExpression left, | 782 static PreParserExpression BinaryOperation(PreParserExpression left, |
771 Token::Value op, | 783 Token::Value op, |
772 PreParserExpression right) { | 784 PreParserExpression right) { |
773 bool valid_arrow_param_list = | 785 bool valid_arrow_param_list = |
774 op == Token::COMMA && !left.is_parenthesized() && | 786 op == Token::COMMA && !left.is_parenthesized() && |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 | 900 |
889 // At the moment PreParser doesn't track these expression types. | 901 // At the moment PreParser doesn't track these expression types. |
890 bool IsFunctionLiteral() const { return false; } | 902 bool IsFunctionLiteral() const { return false; } |
891 bool IsCallNew() const { return false; } | 903 bool IsCallNew() const { return false; } |
892 | 904 |
893 bool IsNoTemplateTag() const { | 905 bool IsNoTemplateTag() const { |
894 return TypeField::decode(code_) == kExpression && | 906 return TypeField::decode(code_) == kExpression && |
895 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; | 907 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; |
896 } | 908 } |
897 | 909 |
910 bool IsSpreadExpression() const { | |
911 return TypeField::decode(code_) == kSpreadExpression; | |
912 } | |
913 | |
898 PreParserExpression AsFunctionLiteral() { return *this; } | 914 PreParserExpression AsFunctionLiteral() { return *this; } |
899 | 915 |
900 bool IsBinaryOperation() const { | 916 bool IsBinaryOperation() const { |
901 return TypeField::decode(code_) == kBinaryOperationExpression; | 917 return TypeField::decode(code_) == kBinaryOperationExpression; |
902 } | 918 } |
903 | 919 |
904 bool is_parenthesized() const { | 920 bool is_parenthesized() const { |
905 return ParenthesizationField::decode(code_) != kNotParenthesized; | 921 return ParenthesizationField::decode(code_) != kNotParenthesized; |
906 } | 922 } |
907 | 923 |
(...skipping 12 matching lines...) Expand all Loading... | |
920 void set_parenthesized() {} | 936 void set_parenthesized() {} |
921 | 937 |
922 int position() const { return RelocInfo::kNoPosition; } | 938 int position() const { return RelocInfo::kNoPosition; } |
923 void set_function_token_position(int position) {} | 939 void set_function_token_position(int position) {} |
924 | 940 |
925 private: | 941 private: |
926 enum Type { | 942 enum Type { |
927 kExpression, | 943 kExpression, |
928 kIdentifierExpression, | 944 kIdentifierExpression, |
929 kStringLiteralExpression, | 945 kStringLiteralExpression, |
930 kBinaryOperationExpression | 946 kBinaryOperationExpression, |
947 kSpreadExpression | |
931 }; | 948 }; |
932 | 949 |
933 enum Parenthesization { | 950 enum Parenthesization { |
934 kNotParenthesized, | 951 kNotParenthesized, |
935 kParanthesizedExpression, | 952 kParanthesizedExpression, |
936 kMultiParenthesizedExpression | 953 kMultiParenthesizedExpression |
937 }; | 954 }; |
938 | 955 |
939 enum ExpressionType { | 956 enum ExpressionType { |
940 kThisExpression, | 957 kThisExpression, |
941 kThisPropertyExpression, | 958 kThisPropertyExpression, |
942 kPropertyExpression, | 959 kPropertyExpression, |
943 kCallExpression, | 960 kCallExpression, |
944 kSuperExpression, | 961 kSuperExpression, |
945 kNoTemplateTagExpression | 962 kNoTemplateTagExpression |
946 }; | 963 }; |
947 | 964 |
948 explicit PreParserExpression(uint32_t expression_code) | 965 explicit PreParserExpression(uint32_t expression_code) |
949 : code_(expression_code) {} | 966 : code_(expression_code) {} |
950 | 967 |
951 V8_INLINE bool IsValidArrowParams() const { | 968 V8_INLINE bool IsValidArrowParams() const { |
952 return IsBinaryOperation() | 969 return IsBinaryOperation() |
953 ? IsValidArrowParamListField::decode(code_) | 970 ? IsValidArrowParamListField::decode(code_) |
954 : (IsIdentifier() && AsIdentifier().IsValidArrowParam()); | 971 : (IsIdentifier() && AsIdentifier().IsValidArrowParam()); |
955 } | 972 } |
956 | 973 |
957 // The first four bits are for the Type and Parenthesization. | 974 // The first four bits are for the Type and Parenthesization. |
958 typedef BitField<Type, 0, 2> TypeField; | 975 typedef BitField<Type, 0, 3> TypeField; |
959 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; | 976 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; |
960 | 977 |
961 // The rest of the bits are interpreted depending on the value | 978 // The rest of the bits are interpreted depending on the value |
962 // of the Type field, so they can share the storage. | 979 // of the Type field, so they can share the storage. |
963 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> | 980 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> |
964 ExpressionTypeField; | 981 ExpressionTypeField; |
965 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; | 982 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; |
966 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 983 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
967 typedef BitField<bool, ParenthesizationField::kNext, 1> | 984 typedef BitField<bool, ParenthesizationField::kNext, 1> |
968 IsValidArrowParamListField; | 985 IsValidArrowParamListField; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1165 Scope* scope, PreParserStatementList body, int materialized_literal_count, | 1182 Scope* scope, PreParserStatementList body, int materialized_literal_count, |
1166 int expected_property_count, int handler_count, int parameter_count, | 1183 int expected_property_count, int handler_count, int parameter_count, |
1167 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1184 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1168 FunctionLiteral::FunctionType function_type, | 1185 FunctionLiteral::FunctionType function_type, |
1169 FunctionLiteral::IsFunctionFlag is_function, | 1186 FunctionLiteral::IsFunctionFlag is_function, |
1170 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1187 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
1171 int position) { | 1188 int position) { |
1172 return PreParserExpression::Default(); | 1189 return PreParserExpression::Default(); |
1173 } | 1190 } |
1174 | 1191 |
1192 PreParserExpression NewSpreadOperation( | |
1193 Scope* scope, PreParserExpression expression, int pos) { | |
1194 return PreParserExpression::Spread(expression); | |
1195 } | |
1196 | |
1175 // Return the object itself as AstVisitor and implement the needed | 1197 // Return the object itself as AstVisitor and implement the needed |
1176 // dummy method right in this class. | 1198 // dummy method right in this class. |
1177 PreParserFactory* visitor() { return this; } | 1199 PreParserFactory* visitor() { return this; } |
1178 int* ast_properties() { | 1200 int* ast_properties() { |
1179 static int dummy = 42; | 1201 static int dummy = 42; |
1180 return &dummy; | 1202 return &dummy; |
1181 } | 1203 } |
1182 }; | 1204 }; |
1183 | 1205 |
1184 | 1206 |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2269 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2291 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
2270 bool* ok) { | 2292 bool* ok) { |
2271 // Arguments :: | 2293 // Arguments :: |
2272 // '(' (AssignmentExpression)*[','] ')' | 2294 // '(' (AssignmentExpression)*[','] ')' |
2273 | 2295 |
2274 typename Traits::Type::ExpressionList result = | 2296 typename Traits::Type::ExpressionList result = |
2275 this->NewExpressionList(4, zone_); | 2297 this->NewExpressionList(4, zone_); |
2276 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2298 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
2277 bool done = (peek() == Token::RPAREN); | 2299 bool done = (peek() == Token::RPAREN); |
2278 while (!done) { | 2300 while (!done) { |
2301 bool is_spread = peek() == Token::ELLIPSIS; | |
arv (Not doing code reviews)
2015/02/12 21:41:34
needs feature flag
| |
2302 int spread_pos = -1; | |
2303 if (is_spread) { | |
2304 spread_pos = peek_position(); | |
2305 Consume(Token::ELLIPSIS); | |
2306 } | |
2279 ExpressionT argument = this->ParseAssignmentExpression( | 2307 ExpressionT argument = this->ParseAssignmentExpression( |
2280 true, CHECK_OK_CUSTOM(NullExpressionList)); | 2308 true, CHECK_OK_CUSTOM(NullExpressionList)); |
2281 result->Add(argument, zone_); | 2309 result->Add(MaybeSpread(argument, is_spread, spread_pos), zone_); |
2282 if (result->length() > Code::kMaxArguments) { | 2310 if (result->length() > Code::kMaxArguments) { |
2283 ReportMessage("too_many_arguments"); | 2311 ReportMessage("too_many_arguments"); |
2284 *ok = false; | 2312 *ok = false; |
2285 return this->NullExpressionList(); | 2313 return this->NullExpressionList(); |
2286 } | 2314 } |
2287 done = (peek() == Token::RPAREN); | 2315 done = (peek() == Token::RPAREN); |
2288 if (!done) { | 2316 if (!done) { |
2289 // Need {} because of the CHECK_OK_CUSTOM macro. | 2317 // Need {} because of the CHECK_OK_CUSTOM macro. |
2290 Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList)); | 2318 Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList)); |
2291 } | 2319 } |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3082 *ok = false; | 3110 *ok = false; |
3083 return; | 3111 return; |
3084 } | 3112 } |
3085 has_seen_constructor_ = true; | 3113 has_seen_constructor_ = true; |
3086 return; | 3114 return; |
3087 } | 3115 } |
3088 } | 3116 } |
3089 } } // v8::internal | 3117 } } // v8::internal |
3090 | 3118 |
3091 #endif // V8_PREPARSER_H | 3119 #endif // V8_PREPARSER_H |
OLD | NEW |