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 | |
202 bool IsObjectLiteral() const { | 200 bool IsObjectLiteral() const { |
203 return TypeField::decode(code_) == kObjectLiteralExpression; | 201 return TypeField::decode(code_) == kObjectLiteralExpression; |
204 } | 202 } |
205 | 203 |
206 bool IsArrayLiteral() const { | 204 bool IsArrayLiteral() const { |
207 return TypeField::decode(code_) == kArrayLiteralExpression; | 205 return TypeField::decode(code_) == kArrayLiteralExpression; |
208 } | 206 } |
209 | 207 |
210 bool IsStringLiteral() const { | 208 bool IsStringLiteral() const { |
211 return TypeField::decode(code_) == kStringLiteralExpression; | 209 return TypeField::decode(code_) == kStringLiteralExpression; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 PreParserExpression NewBinaryOperation(Token::Value op, | 478 PreParserExpression NewBinaryOperation(Token::Value op, |
481 PreParserExpression left, | 479 PreParserExpression left, |
482 PreParserExpression right, int pos) { | 480 PreParserExpression right, int pos) { |
483 return PreParserExpression::BinaryOperation(left, op, right); | 481 return PreParserExpression::BinaryOperation(left, op, right); |
484 } | 482 } |
485 PreParserExpression NewCompareOperation(Token::Value op, | 483 PreParserExpression NewCompareOperation(Token::Value op, |
486 PreParserExpression left, | 484 PreParserExpression left, |
487 PreParserExpression right, int pos) { | 485 PreParserExpression right, int pos) { |
488 return PreParserExpression::Default(); | 486 return PreParserExpression::Default(); |
489 } | 487 } |
490 PreParserExpression NewRewritableAssignmentExpression( | 488 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
491 PreParserExpression expression) { | |
492 return expression; | 489 return expression; |
493 } | 490 } |
494 PreParserExpression NewAssignment(Token::Value op, | 491 PreParserExpression NewAssignment(Token::Value op, |
495 PreParserExpression left, | 492 PreParserExpression left, |
496 PreParserExpression right, | 493 PreParserExpression right, |
497 int pos) { | 494 int pos) { |
498 return PreParserExpression::Assignment(); | 495 return PreParserExpression::Assignment(); |
499 } | 496 } |
500 PreParserExpression NewYield(PreParserExpression generator_object, | 497 PreParserExpression NewYield(PreParserExpression generator_object, |
501 PreParserExpression expression, | 498 PreParserExpression expression, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 struct Type { | 579 struct Type { |
583 // TODO(marja): To be removed. The Traits object should contain all the data | 580 // TODO(marja): To be removed. The Traits object should contain all the data |
584 // it needs. | 581 // it needs. |
585 typedef PreParser* Parser; | 582 typedef PreParser* Parser; |
586 | 583 |
587 // PreParser doesn't need to store generator variables. | 584 // PreParser doesn't need to store generator variables. |
588 typedef void GeneratorVariable; | 585 typedef void GeneratorVariable; |
589 | 586 |
590 typedef int AstProperties; | 587 typedef int AstProperties; |
591 | 588 |
| 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 ExpressionClassifier* classifier) { | 888 Type::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 18 matching lines...) Expand all Loading... |
917 inline PreParserExpression SpreadCall(PreParserExpression function, | 917 inline PreParserExpression SpreadCall(PreParserExpression function, |
918 PreParserExpressionList args, int pos); | 918 PreParserExpressionList args, int pos); |
919 | 919 |
920 inline PreParserExpression SpreadCallNew(PreParserExpression function, | 920 inline PreParserExpression SpreadCallNew(PreParserExpression function, |
921 PreParserExpressionList args, | 921 PreParserExpressionList args, |
922 int pos); | 922 int pos); |
923 | 923 |
924 inline void RewriteDestructuringAssignments() {} | 924 inline void RewriteDestructuringAssignments() {} |
925 | 925 |
926 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} | 926 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} |
| 927 inline void QueueNonPatternForRewriting(PreParserExpression) {} |
927 | 928 |
928 void SetFunctionNameFromPropertyName(PreParserExpression, | 929 void SetFunctionNameFromPropertyName(PreParserExpression, |
929 PreParserIdentifier) {} | 930 PreParserIdentifier) {} |
930 void SetFunctionNameFromIdentifierRef(PreParserExpression, | 931 void SetFunctionNameFromIdentifierRef(PreParserExpression, |
931 PreParserExpression) {} | 932 PreParserExpression) {} |
932 | 933 |
933 inline PreParserExpression RewriteNonPattern( | 934 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, |
934 PreParserExpression expr, const ExpressionClassifier* classifier, | 935 bool* ok); |
935 bool* ok); | 936 |
936 inline PreParserExpression RewriteNonPatternObjectLiteralProperty( | 937 V8_INLINE Zone* zone() const; |
937 PreParserExpression property, const ExpressionClassifier* classifier, | 938 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; |
938 bool* ok); | |
939 | 939 |
940 inline PreParserExpression RewriteYieldStar( | 940 inline PreParserExpression RewriteYieldStar( |
941 PreParserExpression generator, PreParserExpression expr, int pos); | 941 PreParserExpression generator, PreParserExpression expr, int pos); |
942 | 942 |
943 private: | 943 private: |
944 PreParser* pre_parser_; | 944 PreParser* pre_parser_; |
945 }; | 945 }; |
946 | 946 |
947 | 947 |
948 // Preparsing checks a JavaScript program and emits preparse-data that helps | 948 // Preparsing checks a JavaScript program and emits preparse-data that helps |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1114 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1115 // lists that are too long. | 1115 // lists that are too long. |
1116 } | 1116 } |
1117 | 1117 |
1118 | 1118 |
1119 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { | 1119 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { |
1120 return pre_parser_->ParseDoExpression(ok); | 1120 return pre_parser_->ParseDoExpression(ok); |
1121 } | 1121 } |
1122 | 1122 |
1123 | 1123 |
1124 PreParserExpression PreParserTraits::RewriteNonPattern( | 1124 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
1125 PreParserExpression expr, const ExpressionClassifier* classifier, | 1125 bool* ok) { |
1126 bool* ok) { | |
1127 pre_parser_->ValidateExpression(classifier, ok); | 1126 pre_parser_->ValidateExpression(classifier, ok); |
1128 return expr; | |
1129 } | 1127 } |
1130 | 1128 |
1131 | 1129 |
1132 PreParserExpression PreParserTraits::RewriteNonPatternObjectLiteralProperty( | 1130 Zone* PreParserTraits::zone() const { |
1133 PreParserExpression property, const ExpressionClassifier* classifier, | 1131 return pre_parser_->function_state_->scope()->zone(); |
1134 bool* ok) { | |
1135 pre_parser_->ValidateExpression(classifier, ok); | |
1136 return property; | |
1137 } | 1132 } |
1138 | 1133 |
1139 | 1134 |
| 1135 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { |
| 1136 return pre_parser_->function_state_->non_patterns_to_rewrite(); |
| 1137 } |
| 1138 |
| 1139 |
1140 PreParserExpression PreParserTraits::RewriteYieldStar( | 1140 PreParserExpression PreParserTraits::RewriteYieldStar( |
1141 PreParserExpression generator, PreParserExpression expression, int pos) { | 1141 PreParserExpression generator, PreParserExpression expression, int pos) { |
1142 return pre_parser_->factory()->NewYield( | 1142 return pre_parser_->factory()->NewYield( |
1143 generator, expression, Yield::kDelegating, pos); | 1143 generator, expression, Yield::kDelegating, pos); |
1144 } | 1144 } |
1145 | 1145 |
1146 | 1146 |
1147 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1147 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1148 PreParserIdentifier function_name, int pos, | 1148 PreParserIdentifier function_name, int pos, |
1149 const PreParserFormalParameters& parameters, FunctionKind kind, | 1149 const PreParserFormalParameters& parameters, FunctionKind kind, |
(...skipping 13 matching lines...) Expand all Loading... |
1163 const PreParserFormalParameters& parameters, FunctionKind kind, | 1163 const PreParserFormalParameters& parameters, FunctionKind kind, |
1164 FunctionLiteral::FunctionType function_type, bool* ok) { | 1164 FunctionLiteral::FunctionType function_type, bool* ok) { |
1165 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1165 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
1166 kind, function_type, ok); | 1166 kind, function_type, ok); |
1167 } | 1167 } |
1168 | 1168 |
1169 } // namespace internal | 1169 } // namespace internal |
1170 } // namespace v8 | 1170 } // namespace v8 |
1171 | 1171 |
1172 #endif // V8_PARSING_PREPARSER_H | 1172 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |