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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 114 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
115 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 115 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
116 IdentifierTypeField::encode(id.type_)); | 116 IdentifierTypeField::encode(id.type_)); |
117 } | 117 } |
118 | 118 |
119 static PreParserExpression BinaryOperation(PreParserExpression left, | 119 static PreParserExpression BinaryOperation(PreParserExpression left, |
120 Token::Value op, | 120 Token::Value op, |
121 PreParserExpression right) { | 121 PreParserExpression right) { |
122 return PreParserExpression( | 122 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); |
123 TypeField::encode(kBinaryOperationExpression) | | |
124 HasRestField::encode(op == Token::COMMA && | |
125 right->IsSpreadExpression())); | |
126 } | 123 } |
127 | 124 |
128 static PreParserExpression Assignment() { | 125 static PreParserExpression Assignment() { |
129 return PreParserExpression(TypeField::encode(kExpression) | | 126 return PreParserExpression(TypeField::encode(kExpression) | |
130 ExpressionTypeField::encode(kAssignment)); | 127 ExpressionTypeField::encode(kAssignment)); |
131 } | 128 } |
132 | 129 |
133 static PreParserExpression ObjectLiteral() { | 130 static PreParserExpression ObjectLiteral() { |
134 return PreParserExpression(TypeField::encode(kObjectLiteralExpression)); | 131 return PreParserExpression(TypeField::encode(kObjectLiteralExpression)); |
135 } | 132 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 255 |
259 bool IsNoTemplateTag() const { | 256 bool IsNoTemplateTag() const { |
260 return TypeField::decode(code_) == kExpression && | 257 return TypeField::decode(code_) == kExpression && |
261 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; | 258 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; |
262 } | 259 } |
263 | 260 |
264 bool IsSpreadExpression() const { | 261 bool IsSpreadExpression() const { |
265 return TypeField::decode(code_) == kSpreadExpression; | 262 return TypeField::decode(code_) == kSpreadExpression; |
266 } | 263 } |
267 | 264 |
268 bool IsArrowFunctionFormalParametersWithRestParameter() const { | |
269 // Iff the expression classifier has determined that this expression is a | |
270 // valid arrow fformal parameter list, return true if the formal parameter | |
271 // list ends with a rest parameter. | |
272 return IsSpreadExpression() || | |
273 (IsBinaryOperation() && HasRestField::decode(code_)); | |
274 } | |
275 | |
276 PreParserExpression AsFunctionLiteral() { return *this; } | 265 PreParserExpression AsFunctionLiteral() { return *this; } |
277 | 266 |
278 bool IsBinaryOperation() const { | 267 bool IsBinaryOperation() const { |
279 return TypeField::decode(code_) == kBinaryOperationExpression; | 268 return TypeField::decode(code_) == kBinaryOperationExpression; |
280 } | 269 } |
281 | 270 |
282 // Dummy implementation for making expression->somefunc() work in both Parser | 271 // Dummy implementation for making expression->somefunc() work in both Parser |
283 // and PreParser. | 272 // and PreParser. |
284 PreParserExpression* operator->() { return this; } | 273 PreParserExpression* operator->() { return this; } |
285 | 274 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // The first three bits are for the Type. | 306 // The first three bits are for the Type. |
318 typedef BitField<Type, 0, 3> TypeField; | 307 typedef BitField<Type, 0, 3> TypeField; |
319 | 308 |
320 // The rest of the bits are interpreted depending on the value | 309 // The rest of the bits are interpreted depending on the value |
321 // of the Type field, so they can share the storage. | 310 // of the Type field, so they can share the storage. |
322 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 311 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
323 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 312 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
324 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 313 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
325 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 314 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
326 IdentifierTypeField; | 315 IdentifierTypeField; |
327 typedef BitField<bool, TypeField::kNext, 1> HasRestField; | |
328 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; | 316 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
329 | 317 |
330 uint32_t code_; | 318 uint32_t code_; |
331 }; | 319 }; |
332 | 320 |
333 | 321 |
334 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 322 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
335 // the like. | 323 // the like. |
336 template <typename T> | 324 template <typename T> |
337 class PreParserList { | 325 class PreParserList { |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1089 return pre_parser_->factory()->NewCallNew(function, args, pos); |
1102 } | 1090 } |
1103 | 1091 |
1104 | 1092 |
1105 void PreParserTraits::ParseArrowFunctionFormalParameterList( | 1093 void PreParserTraits::ParseArrowFunctionFormalParameterList( |
1106 PreParserFormalParameters* parameters, | 1094 PreParserFormalParameters* parameters, |
1107 PreParserExpression params, const Scanner::Location& params_loc, | 1095 PreParserExpression params, const Scanner::Location& params_loc, |
1108 Scanner::Location* duplicate_loc, bool* ok) { | 1096 Scanner::Location* duplicate_loc, bool* ok) { |
1109 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1097 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1110 // lists that are too long. | 1098 // lists that are too long. |
1111 | |
1112 // Accomodate array literal for rest parameter. | |
1113 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { | |
1114 ++parameters->materialized_literals_count; | |
1115 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | |
1116 } | |
1117 } | 1099 } |
1118 | 1100 |
1119 | 1101 |
1120 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { | 1102 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { |
1121 return pre_parser_->ParseDoExpression(ok); | 1103 return pre_parser_->ParseDoExpression(ok); |
1122 } | 1104 } |
1123 | 1105 |
1124 | 1106 |
1125 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1107 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1126 PreParserIdentifier function_name, int pos, | 1108 PreParserIdentifier function_name, int pos, |
(...skipping 14 matching lines...) Expand all Loading... |
1141 const PreParserFormalParameters& parameters, FunctionKind kind, | 1123 const PreParserFormalParameters& parameters, FunctionKind kind, |
1142 FunctionLiteral::FunctionType function_type, bool* ok) { | 1124 FunctionLiteral::FunctionType function_type, bool* ok) { |
1143 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1125 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
1144 kind, function_type, ok); | 1126 kind, function_type, ok); |
1145 } | 1127 } |
1146 | 1128 |
1147 } // namespace internal | 1129 } // namespace internal |
1148 } // namespace v8 | 1130 } // namespace v8 |
1149 | 1131 |
1150 #endif // V8_PARSING_PREPARSER_H | 1132 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |