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_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 PreParserIdentifier AsIdentifier() const { | 190 PreParserIdentifier AsIdentifier() const { |
191 DCHECK(IsIdentifier()); | 191 DCHECK(IsIdentifier()); |
192 return PreParserIdentifier(IdentifierTypeField::decode(code_)); | 192 return PreParserIdentifier(IdentifierTypeField::decode(code_)); |
193 } | 193 } |
194 | 194 |
195 bool IsAssignment() const { | 195 bool IsAssignment() const { |
196 return TypeField::decode(code_) == kExpression && | 196 return TypeField::decode(code_) == kExpression && |
197 ExpressionTypeField::decode(code_) == kAssignment; | 197 ExpressionTypeField::decode(code_) == kAssignment; |
198 } | 198 } |
199 | 199 |
| 200 bool IsRewritableAssignmentExpression() const { return IsAssignment(); } |
| 201 |
200 bool IsObjectLiteral() const { | 202 bool IsObjectLiteral() const { |
201 return TypeField::decode(code_) == kObjectLiteralExpression; | 203 return TypeField::decode(code_) == kObjectLiteralExpression; |
202 } | 204 } |
203 | 205 |
204 bool IsArrayLiteral() const { | 206 bool IsArrayLiteral() const { |
205 return TypeField::decode(code_) == kArrayLiteralExpression; | 207 return TypeField::decode(code_) == kArrayLiteralExpression; |
206 } | 208 } |
207 | 209 |
208 bool IsStringLiteral() const { | 210 bool IsStringLiteral() const { |
209 return TypeField::decode(code_) == kStringLiteralExpression; | 211 return TypeField::decode(code_) == kStringLiteralExpression; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 PreParserExpression NewBinaryOperation(Token::Value op, | 480 PreParserExpression NewBinaryOperation(Token::Value op, |
479 PreParserExpression left, | 481 PreParserExpression left, |
480 PreParserExpression right, int pos) { | 482 PreParserExpression right, int pos) { |
481 return PreParserExpression::BinaryOperation(left, op, right); | 483 return PreParserExpression::BinaryOperation(left, op, right); |
482 } | 484 } |
483 PreParserExpression NewCompareOperation(Token::Value op, | 485 PreParserExpression NewCompareOperation(Token::Value op, |
484 PreParserExpression left, | 486 PreParserExpression left, |
485 PreParserExpression right, int pos) { | 487 PreParserExpression right, int pos) { |
486 return PreParserExpression::Default(); | 488 return PreParserExpression::Default(); |
487 } | 489 } |
488 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 490 PreParserExpression NewRewritableAssignmentExpression( |
| 491 PreParserExpression expression) { |
489 return expression; | 492 return expression; |
490 } | 493 } |
491 PreParserExpression NewAssignment(Token::Value op, | 494 PreParserExpression NewAssignment(Token::Value op, |
492 PreParserExpression left, | 495 PreParserExpression left, |
493 PreParserExpression right, | 496 PreParserExpression right, |
494 int pos) { | 497 int pos) { |
495 return PreParserExpression::Assignment(); | 498 return PreParserExpression::Assignment(); |
496 } | 499 } |
497 PreParserExpression NewYield(PreParserExpression generator_object, | 500 PreParserExpression NewYield(PreParserExpression generator_object, |
498 PreParserExpression expression, | 501 PreParserExpression expression, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 struct Type { | 582 struct Type { |
580 // TODO(marja): To be removed. The Traits object should contain all the data | 583 // TODO(marja): To be removed. The Traits object should contain all the data |
581 // it needs. | 584 // it needs. |
582 typedef PreParser* Parser; | 585 typedef PreParser* Parser; |
583 | 586 |
584 // PreParser doesn't need to store generator variables. | 587 // PreParser doesn't need to store generator variables. |
585 typedef void GeneratorVariable; | 588 typedef void GeneratorVariable; |
586 | 589 |
587 typedef int AstProperties; | 590 typedef int AstProperties; |
588 | 591 |
589 typedef v8::internal::ExpressionClassifier<PreParserTraits> | |
590 ExpressionClassifier; | |
591 | |
592 // Return types for traversing functions. | 592 // Return types for traversing functions. |
593 typedef PreParserIdentifier Identifier; | 593 typedef PreParserIdentifier Identifier; |
594 typedef PreParserExpression Expression; | 594 typedef PreParserExpression Expression; |
595 typedef PreParserExpression YieldExpression; | 595 typedef PreParserExpression YieldExpression; |
596 typedef PreParserExpression FunctionLiteral; | 596 typedef PreParserExpression FunctionLiteral; |
597 typedef PreParserExpression ClassLiteral; | 597 typedef PreParserExpression ClassLiteral; |
598 typedef PreParserExpression ObjectLiteralProperty; | 598 typedef PreParserExpression ObjectLiteralProperty; |
599 typedef PreParserExpression Literal; | 599 typedef PreParserExpression Literal; |
600 typedef PreParserExpressionList ExpressionList; | 600 typedef PreParserExpressionList ExpressionList; |
601 typedef PreParserExpressionList PropertyList; | 601 typedef PreParserExpressionList PropertyList; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 return !tag.IsNoTemplateTag(); | 878 return !tag.IsNoTemplateTag(); |
879 } | 879 } |
880 | 880 |
881 void AddFormalParameter(PreParserFormalParameters* parameters, | 881 void AddFormalParameter(PreParserFormalParameters* parameters, |
882 PreParserExpression pattern, | 882 PreParserExpression pattern, |
883 PreParserExpression initializer, | 883 PreParserExpression initializer, |
884 int initializer_end_position, bool is_rest) { | 884 int initializer_end_position, bool is_rest) { |
885 ++parameters->arity; | 885 ++parameters->arity; |
886 } | 886 } |
887 void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, | 887 void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, |
888 Type::ExpressionClassifier* classifier) { | 888 ExpressionClassifier* classifier) { |
889 if (!classifier->is_simple_parameter_list()) { | 889 if (!classifier->is_simple_parameter_list()) { |
890 scope->SetHasNonSimpleParameters(); | 890 scope->SetHasNonSimpleParameters(); |
891 } | 891 } |
892 } | 892 } |
893 | 893 |
894 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 894 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
895 | 895 |
896 // Temporary glue; these functions will move to ParserBase. | 896 // Temporary glue; these functions will move to ParserBase. |
897 PreParserExpression ParseV8Intrinsic(bool* ok); | 897 PreParserExpression ParseV8Intrinsic(bool* ok); |
898 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); | 898 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); |
(...skipping 17 matching lines...) Expand all Loading... |
916 inline PreParserExpression SpreadCall(PreParserExpression function, | 916 inline PreParserExpression SpreadCall(PreParserExpression function, |
917 PreParserExpressionList args, int pos); | 917 PreParserExpressionList args, int pos); |
918 | 918 |
919 inline PreParserExpression SpreadCallNew(PreParserExpression function, | 919 inline PreParserExpression SpreadCallNew(PreParserExpression function, |
920 PreParserExpressionList args, | 920 PreParserExpressionList args, |
921 int pos); | 921 int pos); |
922 | 922 |
923 inline void RewriteDestructuringAssignments() {} | 923 inline void RewriteDestructuringAssignments() {} |
924 | 924 |
925 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} | 925 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} |
926 inline void QueueNonPatternForRewriting(PreParserExpression) {} | |
927 | 926 |
928 void SetFunctionNameFromPropertyName(PreParserExpression, | 927 void SetFunctionNameFromPropertyName(PreParserExpression, |
929 PreParserIdentifier) {} | 928 PreParserIdentifier) {} |
930 void SetFunctionNameFromIdentifierRef(PreParserExpression, | 929 void SetFunctionNameFromIdentifierRef(PreParserExpression, |
931 PreParserExpression) {} | 930 PreParserExpression) {} |
932 | 931 |
933 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, | 932 inline PreParserExpression RewriteNonPattern( |
934 bool* ok); | 933 PreParserExpression expr, const ExpressionClassifier* classifier, |
935 | 934 bool* ok); |
936 V8_INLINE Zone* zone() const; | 935 inline PreParserExpression RewriteNonPatternObjectLiteralProperty( |
937 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; | 936 PreParserExpression property, const ExpressionClassifier* classifier, |
| 937 bool* ok); |
938 | 938 |
939 inline PreParserExpression RewriteYieldStar( | 939 inline PreParserExpression RewriteYieldStar( |
940 PreParserExpression generator, PreParserExpression expr, int pos); | 940 PreParserExpression generator, PreParserExpression expr, int pos); |
941 | 941 |
942 private: | 942 private: |
943 PreParser* pre_parser_; | 943 PreParser* pre_parser_; |
944 }; | 944 }; |
945 | 945 |
946 | 946 |
947 // Preparsing checks a JavaScript program and emits preparse-data that helps | 947 // Preparsing checks a JavaScript program and emits preparse-data that helps |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1112 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1113 // lists that are too long. | 1113 // lists that are too long. |
1114 } | 1114 } |
1115 | 1115 |
1116 | 1116 |
1117 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { | 1117 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { |
1118 return pre_parser_->ParseDoExpression(ok); | 1118 return pre_parser_->ParseDoExpression(ok); |
1119 } | 1119 } |
1120 | 1120 |
1121 | 1121 |
1122 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 1122 PreParserExpression PreParserTraits::RewriteNonPattern( |
1123 bool* ok) { | 1123 PreParserExpression expr, const ExpressionClassifier* classifier, |
| 1124 bool* ok) { |
1124 pre_parser_->ValidateExpression(classifier, ok); | 1125 pre_parser_->ValidateExpression(classifier, ok); |
| 1126 return expr; |
1125 } | 1127 } |
1126 | 1128 |
1127 | 1129 |
1128 Zone* PreParserTraits::zone() const { | 1130 PreParserExpression PreParserTraits::RewriteNonPatternObjectLiteralProperty( |
1129 return pre_parser_->function_state_->scope()->zone(); | 1131 PreParserExpression property, const ExpressionClassifier* classifier, |
| 1132 bool* ok) { |
| 1133 pre_parser_->ValidateExpression(classifier, ok); |
| 1134 return property; |
1130 } | 1135 } |
1131 | 1136 |
1132 | 1137 |
1133 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { | |
1134 return pre_parser_->function_state_->non_patterns_to_rewrite(); | |
1135 } | |
1136 | |
1137 | |
1138 PreParserExpression PreParserTraits::RewriteYieldStar( | 1138 PreParserExpression PreParserTraits::RewriteYieldStar( |
1139 PreParserExpression generator, PreParserExpression expression, int pos) { | 1139 PreParserExpression generator, PreParserExpression expression, int pos) { |
1140 return pre_parser_->factory()->NewYield( | 1140 return pre_parser_->factory()->NewYield( |
1141 generator, expression, Yield::kDelegating, pos); | 1141 generator, expression, Yield::kDelegating, pos); |
1142 } | 1142 } |
1143 | 1143 |
1144 | 1144 |
1145 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1145 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1146 PreParserIdentifier function_name, int pos, | 1146 PreParserIdentifier function_name, int pos, |
1147 const PreParserFormalParameters& parameters, FunctionKind kind, | 1147 const PreParserFormalParameters& parameters, FunctionKind kind, |
(...skipping 13 matching lines...) Expand all Loading... |
1161 const PreParserFormalParameters& parameters, FunctionKind kind, | 1161 const PreParserFormalParameters& parameters, FunctionKind kind, |
1162 FunctionLiteral::FunctionType function_type, bool* ok) { | 1162 FunctionLiteral::FunctionType function_type, bool* ok) { |
1163 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1163 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
1164 kind, function_type, ok); | 1164 kind, function_type, ok); |
1165 } | 1165 } |
1166 | 1166 |
1167 } // namespace internal | 1167 } // namespace internal |
1168 } // namespace v8 | 1168 } // namespace v8 |
1169 | 1169 |
1170 #endif // V8_PARSING_PREPARSER_H | 1170 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |