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 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) {} |
926 | 927 |
927 void SetFunctionNameFromPropertyName(PreParserExpression, | 928 void SetFunctionNameFromPropertyName(PreParserExpression, |
928 PreParserIdentifier) {} | 929 PreParserIdentifier) {} |
929 void SetFunctionNameFromIdentifierRef(PreParserExpression, | 930 void SetFunctionNameFromIdentifierRef(PreParserExpression, |
930 PreParserExpression) {} | 931 PreParserExpression) {} |
931 | 932 |
932 inline PreParserExpression RewriteNonPattern( | 933 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, |
933 PreParserExpression expr, const ExpressionClassifier* classifier, | 934 bool* ok); |
934 bool* ok); | 935 |
935 inline PreParserExpression RewriteNonPatternObjectLiteralProperty( | 936 V8_INLINE Zone* zone() const; |
936 PreParserExpression property, const ExpressionClassifier* classifier, | 937 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; |
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 PreParserExpression PreParserTraits::RewriteNonPattern( | 1122 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
1123 PreParserExpression expr, const ExpressionClassifier* classifier, | 1123 bool* ok) { |
1124 bool* ok) { | |
1125 pre_parser_->ValidateExpression(classifier, ok); | 1124 pre_parser_->ValidateExpression(classifier, ok); |
1126 return expr; | |
1127 } | 1125 } |
1128 | 1126 |
1129 | 1127 |
1130 PreParserExpression PreParserTraits::RewriteNonPatternObjectLiteralProperty( | 1128 Zone* PreParserTraits::zone() const { |
1131 PreParserExpression property, const ExpressionClassifier* classifier, | 1129 return pre_parser_->function_state_->scope()->zone(); |
1132 bool* ok) { | |
1133 pre_parser_->ValidateExpression(classifier, ok); | |
1134 return property; | |
1135 } | 1130 } |
1136 | 1131 |
1137 | 1132 |
| 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 |