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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 #undef ALLOW_ACCESSORS | 136 #undef ALLOW_ACCESSORS |
137 | 137 |
138 uintptr_t stack_limit() const { return stack_limit_; } | 138 uintptr_t stack_limit() const { return stack_limit_; } |
139 | 139 |
140 protected: | 140 protected: |
141 enum AllowRestrictedIdentifiers { | 141 enum AllowRestrictedIdentifiers { |
142 kAllowRestrictedIdentifiers, | 142 kAllowRestrictedIdentifiers, |
143 kDontAllowRestrictedIdentifiers | 143 kDontAllowRestrictedIdentifiers |
144 }; | 144 }; |
145 | 145 |
146 enum Mode { | 146 enum Mode { PARSE_LAZILY, PARSE_EAGERLY }; |
147 PARSE_LAZILY, | |
148 PARSE_EAGERLY | |
149 }; | |
150 | 147 |
151 enum VariableDeclarationContext { | 148 enum VariableDeclarationContext { |
152 kStatementListItem, | 149 kStatementListItem, |
153 kStatement, | 150 kStatement, |
154 kForStatement | 151 kForStatement |
155 }; | 152 }; |
156 | 153 |
157 class Checkpoint; | 154 class Checkpoint; |
158 class ObjectLiteralCheckerBase; | 155 class ObjectLiteralCheckerBase; |
159 | 156 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 282 |
286 private: | 283 private: |
287 FunctionState* function_state_; | 284 FunctionState* function_state_; |
288 int next_materialized_literal_index_; | 285 int next_materialized_literal_index_; |
289 int expected_property_count_; | 286 int expected_property_count_; |
290 }; | 287 }; |
291 | 288 |
292 class ParsingModeScope BASE_EMBEDDED { | 289 class ParsingModeScope BASE_EMBEDDED { |
293 public: | 290 public: |
294 ParsingModeScope(ParserBase* parser, Mode mode) | 291 ParsingModeScope(ParserBase* parser, Mode mode) |
295 : parser_(parser), | 292 : parser_(parser), old_mode_(parser->mode()) { |
296 old_mode_(parser->mode()) { | |
297 parser_->mode_ = mode; | 293 parser_->mode_ = mode; |
298 } | 294 } |
299 ~ParsingModeScope() { | 295 ~ParsingModeScope() { parser_->mode_ = old_mode_; } |
300 parser_->mode_ = old_mode_; | |
301 } | |
302 | 296 |
303 private: | 297 private: |
304 ParserBase* parser_; | 298 ParserBase* parser_; |
305 Mode old_mode_; | 299 Mode old_mode_; |
306 }; | 300 }; |
307 | 301 |
308 Scope* NewScope(Scope* parent, ScopeType scope_type) { | 302 Scope* NewScope(Scope* parent, ScopeType scope_type) { |
309 // Must always pass the function kind for FUNCTION_SCOPE. | 303 // Must always pass the function kind for FUNCTION_SCOPE. |
310 DCHECK(scope_type != FUNCTION_SCOPE); | 304 DCHECK(scope_type != FUNCTION_SCOPE); |
311 return NewScope(parent, scope_type, kNormalFunction); | 305 return NewScope(parent, scope_type, kNormalFunction); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } | 371 } |
378 | 372 |
379 void ExpectSemicolon(bool* ok) { | 373 void ExpectSemicolon(bool* ok) { |
380 // Check for automatic semicolon insertion according to | 374 // Check for automatic semicolon insertion according to |
381 // the rules given in ECMA-262, section 7.9, page 21. | 375 // the rules given in ECMA-262, section 7.9, page 21. |
382 Token::Value tok = peek(); | 376 Token::Value tok = peek(); |
383 if (tok == Token::SEMICOLON) { | 377 if (tok == Token::SEMICOLON) { |
384 Next(); | 378 Next(); |
385 return; | 379 return; |
386 } | 380 } |
387 if (scanner()->HasAnyLineTerminatorBeforeNext() || | 381 if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::RBRACE || |
388 tok == Token::RBRACE || | |
389 tok == Token::EOS) { | 382 tok == Token::EOS) { |
390 return; | 383 return; |
391 } | 384 } |
392 Expect(Token::SEMICOLON, ok); | 385 Expect(Token::SEMICOLON, ok); |
393 } | 386 } |
394 | 387 |
395 bool peek_any_identifier() { | 388 bool peek_any_identifier() { |
396 Token::Value next = peek(); | 389 Token::Value next = peek(); |
397 return next == Token::IDENTIFIER || next == Token::FUTURE_RESERVED_WORD || | 390 return next == Token::IDENTIFIER || next == Token::FUTURE_RESERVED_WORD || |
398 next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 391 next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 746 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
754 // we allow calls for web compatibility and rewrite them to a runtime throw. | 747 // we allow calls for web compatibility and rewrite them to a runtime throw. |
755 ExpressionT CheckAndRewriteReferenceExpression( | 748 ExpressionT CheckAndRewriteReferenceExpression( |
756 ExpressionT expression, int beg_pos, int end_pos, | 749 ExpressionT expression, int beg_pos, int end_pos, |
757 MessageTemplate::Template message, bool* ok); | 750 MessageTemplate::Template message, bool* ok); |
758 ExpressionT CheckAndRewriteReferenceExpression( | 751 ExpressionT CheckAndRewriteReferenceExpression( |
759 ExpressionT expression, int beg_pos, int end_pos, | 752 ExpressionT expression, int beg_pos, int end_pos, |
760 MessageTemplate::Template message, ParseErrorType type, bool* ok); | 753 MessageTemplate::Template message, ParseErrorType type, bool* ok); |
761 | 754 |
762 // Used to validate property names in object literals and class literals | 755 // Used to validate property names in object literals and class literals |
763 enum PropertyKind { | 756 enum PropertyKind { kAccessorProperty, kValueProperty, kMethodProperty }; |
764 kAccessorProperty, | |
765 kValueProperty, | |
766 kMethodProperty | |
767 }; | |
768 | 757 |
769 class ObjectLiteralCheckerBase { | 758 class ObjectLiteralCheckerBase { |
770 public: | 759 public: |
771 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} | 760 explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} |
772 | 761 |
773 virtual void CheckProperty(Token::Value property, PropertyKind type, | 762 virtual void CheckProperty(Token::Value property, PropertyKind type, |
774 bool is_static, bool is_generator, bool* ok) = 0; | 763 bool is_static, bool is_generator, bool* ok) = 0; |
775 | 764 |
776 virtual ~ObjectLiteralCheckerBase() {} | 765 virtual ~ObjectLiteralCheckerBase() {} |
777 | 766 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 1145 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
1157 // the like. | 1146 // the like. |
1158 template <typename T> | 1147 template <typename T> |
1159 class PreParserList { | 1148 class PreParserList { |
1160 public: | 1149 public: |
1161 // These functions make list->Add(some_expression) work (and do nothing). | 1150 // These functions make list->Add(some_expression) work (and do nothing). |
1162 PreParserList() : length_(0) {} | 1151 PreParserList() : length_(0) {} |
1163 PreParserList* operator->() { return this; } | 1152 PreParserList* operator->() { return this; } |
1164 void Add(T, void*) { ++length_; } | 1153 void Add(T, void*) { ++length_; } |
1165 int length() const { return length_; } | 1154 int length() const { return length_; } |
| 1155 |
1166 private: | 1156 private: |
1167 int length_; | 1157 int length_; |
1168 }; | 1158 }; |
1169 | 1159 |
1170 | 1160 |
1171 typedef PreParserList<PreParserExpression> PreParserExpressionList; | 1161 typedef PreParserList<PreParserExpression> PreParserExpressionList; |
1172 | 1162 |
1173 | 1163 |
1174 class PreParserStatement { | 1164 class PreParserStatement { |
1175 public: | 1165 public: |
(...skipping 19 matching lines...) Expand all Loading... |
1195 } | 1185 } |
1196 if (expression.IsUseStrongLiteral()) { | 1186 if (expression.IsUseStrongLiteral()) { |
1197 return PreParserStatement(kUseStrongExpressionStatement); | 1187 return PreParserStatement(kUseStrongExpressionStatement); |
1198 } | 1188 } |
1199 if (expression.IsStringLiteral()) { | 1189 if (expression.IsStringLiteral()) { |
1200 return PreParserStatement(kStringLiteralExpressionStatement); | 1190 return PreParserStatement(kStringLiteralExpressionStatement); |
1201 } | 1191 } |
1202 return Default(); | 1192 return Default(); |
1203 } | 1193 } |
1204 | 1194 |
1205 bool IsStringLiteral() { | 1195 bool IsStringLiteral() { return code_ == kStringLiteralExpressionStatement; } |
1206 return code_ == kStringLiteralExpressionStatement; | |
1207 } | |
1208 | 1196 |
1209 bool IsUseStrictLiteral() { | 1197 bool IsUseStrictLiteral() { return code_ == kUseStrictExpressionStatement; } |
1210 return code_ == kUseStrictExpressionStatement; | |
1211 } | |
1212 | 1198 |
1213 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } | 1199 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } |
1214 | 1200 |
1215 bool IsFunctionDeclaration() { | 1201 bool IsFunctionDeclaration() { return code_ == kFunctionDeclaration; } |
1216 return code_ == kFunctionDeclaration; | |
1217 } | |
1218 | 1202 |
1219 bool IsJumpStatement() { | 1203 bool IsJumpStatement() { return code_ == kJumpStatement; } |
1220 return code_ == kJumpStatement; | |
1221 } | |
1222 | 1204 |
1223 private: | 1205 private: |
1224 enum Type { | 1206 enum Type { |
1225 kUnknownStatement, | 1207 kUnknownStatement, |
1226 kJumpStatement, | 1208 kJumpStatement, |
1227 kStringLiteralExpressionStatement, | 1209 kStringLiteralExpressionStatement, |
1228 kUseStrictExpressionStatement, | 1210 kUseStrictExpressionStatement, |
1229 kUseStrongExpressionStatement, | 1211 kUseStrongExpressionStatement, |
1230 kFunctionDeclaration | 1212 kFunctionDeclaration |
1231 }; | 1213 }; |
1232 | 1214 |
1233 explicit PreParserStatement(Type code) : code_(code) {} | 1215 explicit PreParserStatement(Type code) : code_(code) {} |
1234 Type code_; | 1216 Type code_; |
1235 }; | 1217 }; |
1236 | 1218 |
1237 | 1219 |
1238 typedef PreParserList<PreParserStatement> PreParserStatementList; | 1220 typedef PreParserList<PreParserStatement> PreParserStatementList; |
1239 | 1221 |
1240 | 1222 |
1241 class PreParserFactory { | 1223 class PreParserFactory { |
1242 public: | 1224 public: |
1243 explicit PreParserFactory(void* unused_value_factory) {} | 1225 explicit PreParserFactory(void* unused_value_factory) {} |
1244 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 1226 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
1245 int pos) { | 1227 int pos) { |
1246 return PreParserExpression::Default(); | 1228 return PreParserExpression::Default(); |
1247 } | 1229 } |
1248 PreParserExpression NewNumberLiteral(double number, | 1230 PreParserExpression NewNumberLiteral(double number, int pos) { |
1249 int pos) { | |
1250 return PreParserExpression::Default(); | 1231 return PreParserExpression::Default(); |
1251 } | 1232 } |
1252 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 1233 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
1253 int js_flags, int literal_index, | 1234 int js_flags, int literal_index, |
1254 bool is_strong, int pos) { | 1235 bool is_strong, int pos) { |
1255 return PreParserExpression::Default(); | 1236 return PreParserExpression::Default(); |
1256 } | 1237 } |
1257 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1238 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
1258 int literal_index, | 1239 int literal_index, bool is_strong, |
1259 bool is_strong, | |
1260 int pos) { | 1240 int pos) { |
1261 return PreParserExpression::ArrayLiteral(); | 1241 return PreParserExpression::ArrayLiteral(); |
1262 } | 1242 } |
1263 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1243 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
1264 int first_spread_index, int literal_index, | 1244 int first_spread_index, int literal_index, |
1265 bool is_strong, int pos) { | 1245 bool is_strong, int pos) { |
1266 return PreParserExpression::ArrayLiteral(); | 1246 return PreParserExpression::ArrayLiteral(); |
1267 } | 1247 } |
1268 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1248 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
1269 PreParserExpression value, | 1249 PreParserExpression value, |
1270 ObjectLiteralProperty::Kind kind, | 1250 ObjectLiteralProperty::Kind kind, |
1271 bool is_static, | 1251 bool is_static, |
1272 bool is_computed_name) { | 1252 bool is_computed_name) { |
1273 return PreParserExpression::Default(); | 1253 return PreParserExpression::Default(); |
1274 } | 1254 } |
1275 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1255 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
1276 PreParserExpression value, | 1256 PreParserExpression value, |
1277 bool is_static, | 1257 bool is_static, |
1278 bool is_computed_name) { | 1258 bool is_computed_name) { |
1279 return PreParserExpression::Default(); | 1259 return PreParserExpression::Default(); |
1280 } | 1260 } |
1281 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1261 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
1282 int literal_index, | 1262 int literal_index, |
1283 int boilerplate_properties, | 1263 int boilerplate_properties, |
1284 bool has_function, | 1264 bool has_function, bool is_strong, |
1285 bool is_strong, | |
1286 int pos) { | 1265 int pos) { |
1287 return PreParserExpression::ObjectLiteral(); | 1266 return PreParserExpression::ObjectLiteral(); |
1288 } | 1267 } |
1289 PreParserExpression NewVariableProxy(void* variable) { | 1268 PreParserExpression NewVariableProxy(void* variable) { |
1290 return PreParserExpression::Default(); | 1269 return PreParserExpression::Default(); |
1291 } | 1270 } |
1292 PreParserExpression NewProperty(PreParserExpression obj, | 1271 PreParserExpression NewProperty(PreParserExpression obj, |
1293 PreParserExpression key, | 1272 PreParserExpression key, int pos) { |
1294 int pos) { | |
1295 if (obj.IsThis()) { | 1273 if (obj.IsThis()) { |
1296 return PreParserExpression::ThisProperty(); | 1274 return PreParserExpression::ThisProperty(); |
1297 } | 1275 } |
1298 return PreParserExpression::Property(); | 1276 return PreParserExpression::Property(); |
1299 } | 1277 } |
1300 PreParserExpression NewUnaryOperation(Token::Value op, | 1278 PreParserExpression NewUnaryOperation(Token::Value op, |
1301 PreParserExpression expression, | 1279 PreParserExpression expression, |
1302 int pos) { | 1280 int pos) { |
1303 return PreParserExpression::Default(); | 1281 return PreParserExpression::Default(); |
1304 } | 1282 } |
1305 PreParserExpression NewBinaryOperation(Token::Value op, | 1283 PreParserExpression NewBinaryOperation(Token::Value op, |
1306 PreParserExpression left, | 1284 PreParserExpression left, |
1307 PreParserExpression right, int pos) { | 1285 PreParserExpression right, int pos) { |
1308 return PreParserExpression::BinaryOperation(left, op, right); | 1286 return PreParserExpression::BinaryOperation(left, op, right); |
1309 } | 1287 } |
1310 PreParserExpression NewCompareOperation(Token::Value op, | 1288 PreParserExpression NewCompareOperation(Token::Value op, |
1311 PreParserExpression left, | 1289 PreParserExpression left, |
1312 PreParserExpression right, int pos) { | 1290 PreParserExpression right, int pos) { |
1313 return PreParserExpression::Default(); | 1291 return PreParserExpression::Default(); |
1314 } | 1292 } |
1315 PreParserExpression NewAssignment(Token::Value op, | 1293 PreParserExpression NewAssignment(Token::Value op, PreParserExpression left, |
1316 PreParserExpression left, | 1294 PreParserExpression right, int pos) { |
1317 PreParserExpression right, | |
1318 int pos) { | |
1319 return PreParserExpression::Default(); | 1295 return PreParserExpression::Default(); |
1320 } | 1296 } |
1321 PreParserExpression NewYield(PreParserExpression generator_object, | 1297 PreParserExpression NewYield(PreParserExpression generator_object, |
1322 PreParserExpression expression, | 1298 PreParserExpression expression, |
1323 Yield::Kind yield_kind, | 1299 Yield::Kind yield_kind, int pos) { |
1324 int pos) { | |
1325 return PreParserExpression::Default(); | 1300 return PreParserExpression::Default(); |
1326 } | 1301 } |
1327 PreParserExpression NewConditional(PreParserExpression condition, | 1302 PreParserExpression NewConditional(PreParserExpression condition, |
1328 PreParserExpression then_expression, | 1303 PreParserExpression then_expression, |
1329 PreParserExpression else_expression, | 1304 PreParserExpression else_expression, |
1330 int pos) { | 1305 int pos) { |
1331 return PreParserExpression::Default(); | 1306 return PreParserExpression::Default(); |
1332 } | 1307 } |
1333 PreParserExpression NewCountOperation(Token::Value op, | 1308 PreParserExpression NewCountOperation(Token::Value op, bool is_prefix, |
1334 bool is_prefix, | |
1335 PreParserExpression expression, | 1309 PreParserExpression expression, |
1336 int pos) { | 1310 int pos) { |
1337 return PreParserExpression::Default(); | 1311 return PreParserExpression::Default(); |
1338 } | 1312 } |
1339 PreParserExpression NewCall(PreParserExpression expression, | 1313 PreParserExpression NewCall(PreParserExpression expression, |
1340 PreParserExpressionList arguments, | 1314 PreParserExpressionList arguments, int pos) { |
1341 int pos) { | |
1342 return PreParserExpression::Call(); | 1315 return PreParserExpression::Call(); |
1343 } | 1316 } |
1344 PreParserExpression NewCallNew(PreParserExpression expression, | 1317 PreParserExpression NewCallNew(PreParserExpression expression, |
1345 PreParserExpressionList arguments, | 1318 PreParserExpressionList arguments, int pos) { |
1346 int pos) { | |
1347 return PreParserExpression::Default(); | 1319 return PreParserExpression::Default(); |
1348 } | 1320 } |
1349 PreParserExpression NewCallRuntime(const AstRawString* name, | 1321 PreParserExpression NewCallRuntime(const AstRawString* name, |
1350 const Runtime::Function* function, | 1322 const Runtime::Function* function, |
1351 PreParserExpressionList arguments, | 1323 PreParserExpressionList arguments, |
1352 int pos) { | 1324 int pos) { |
1353 return PreParserExpression::Default(); | 1325 return PreParserExpression::Default(); |
1354 } | 1326 } |
1355 PreParserStatement NewReturnStatement(PreParserExpression expression, | 1327 PreParserStatement NewReturnStatement(PreParserExpression expression, |
1356 int pos) { | 1328 int pos) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 | 1492 |
1521 static PreParserExpression MarkExpressionAsAssigned( | 1493 static PreParserExpression MarkExpressionAsAssigned( |
1522 PreParserExpression expression) { | 1494 PreParserExpression expression) { |
1523 // TODO(marja): To be able to produce the same errors, the preparser needs | 1495 // TODO(marja): To be able to produce the same errors, the preparser needs |
1524 // to start tracking which expressions are variables and which are assigned. | 1496 // to start tracking which expressions are variables and which are assigned. |
1525 return expression; | 1497 return expression; |
1526 } | 1498 } |
1527 | 1499 |
1528 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | 1500 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
1529 PreParserExpression y, | 1501 PreParserExpression y, |
1530 Token::Value op, | 1502 Token::Value op, int pos, |
1531 int pos, | |
1532 PreParserFactory* factory) { | 1503 PreParserFactory* factory) { |
1533 return false; | 1504 return false; |
1534 } | 1505 } |
1535 | 1506 |
1536 PreParserExpression BuildUnaryExpression(PreParserExpression expression, | 1507 PreParserExpression BuildUnaryExpression(PreParserExpression expression, |
1537 Token::Value op, int pos, | 1508 Token::Value op, int pos, |
1538 PreParserFactory* factory) { | 1509 PreParserFactory* factory) { |
1539 return PreParserExpression::Default(); | 1510 return PreParserExpression::Default(); |
1540 } | 1511 } |
1541 | 1512 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 PreParserFactory* factory, | 1592 PreParserFactory* factory, |
1622 int pos) { | 1593 int pos) { |
1623 return PreParserExpression::Default(); | 1594 return PreParserExpression::Default(); |
1624 } | 1595 } |
1625 | 1596 |
1626 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, | 1597 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, |
1627 int pos, int end_pos) { | 1598 int pos, int end_pos) { |
1628 return PreParserExpression::Default(); | 1599 return PreParserExpression::Default(); |
1629 } | 1600 } |
1630 | 1601 |
1631 static PreParserExpression ExpressionFromLiteral( | 1602 static PreParserExpression ExpressionFromLiteral(Token::Value token, int pos, |
1632 Token::Value token, int pos, Scanner* scanner, | 1603 Scanner* scanner, |
1633 PreParserFactory* factory) { | 1604 PreParserFactory* factory) { |
1634 return PreParserExpression::Default(); | 1605 return PreParserExpression::Default(); |
1635 } | 1606 } |
1636 | 1607 |
1637 static PreParserExpression ExpressionFromIdentifier( | 1608 static PreParserExpression ExpressionFromIdentifier( |
1638 PreParserIdentifier name, int start_position, int end_position, | 1609 PreParserIdentifier name, int start_position, int end_position, |
1639 Scope* scope, PreParserFactory* factory) { | 1610 Scope* scope, PreParserFactory* factory) { |
1640 return PreParserExpression::FromIdentifier(name); | 1611 return PreParserExpression::FromIdentifier(name); |
1641 } | 1612 } |
1642 | 1613 |
1643 PreParserExpression ExpressionFromString(int pos, | 1614 PreParserExpression ExpressionFromString(int pos, Scanner* scanner, |
1644 Scanner* scanner, | |
1645 PreParserFactory* factory = NULL); | 1615 PreParserFactory* factory = NULL); |
1646 | 1616 |
1647 PreParserExpression GetIterator(PreParserExpression iterable, | 1617 PreParserExpression GetIterator(PreParserExpression iterable, |
1648 PreParserFactory* factory) { | 1618 PreParserFactory* factory) { |
1649 return PreParserExpression::Default(); | 1619 return PreParserExpression::Default(); |
1650 } | 1620 } |
1651 | 1621 |
1652 static PreParserExpressionList NewExpressionList(int size, Zone* zone) { | 1622 static PreParserExpressionList NewExpressionList(int size, Zone* zone) { |
1653 return PreParserExpressionList(); | 1623 return PreParserExpressionList(); |
1654 } | 1624 } |
1655 | 1625 |
1656 static PreParserStatementList NewStatementList(int size, Zone* zone) { | 1626 static PreParserStatementList NewStatementList(int size, Zone* zone) { |
1657 return PreParserStatementList(); | 1627 return PreParserStatementList(); |
1658 } | 1628 } |
1659 | 1629 |
1660 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { | 1630 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { |
1661 return PreParserExpressionList(); | 1631 return PreParserExpressionList(); |
1662 } | 1632 } |
1663 | 1633 |
1664 static void AddParameterInitializationBlock( | 1634 static void AddParameterInitializationBlock( |
1665 const PreParserFormalParameters& parameters, | 1635 const PreParserFormalParameters& parameters, PreParserStatementList list, |
1666 PreParserStatementList list, bool* ok) {} | 1636 bool* ok) {} |
1667 | 1637 |
1668 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1638 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1669 int* expected_property_count, bool* ok) { | 1639 int* expected_property_count, bool* ok) { |
1670 UNREACHABLE(); | 1640 UNREACHABLE(); |
1671 } | 1641 } |
1672 | 1642 |
1673 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 1643 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
1674 PreParserIdentifier function_name, int pos, | 1644 PreParserIdentifier function_name, int pos, |
1675 const PreParserFormalParameters& parameters, FunctionKind kind, | 1645 const PreParserFormalParameters& parameters, FunctionKind kind, |
1676 FunctionLiteral::FunctionType function_type, bool* ok); | 1646 FunctionLiteral::FunctionType function_type, bool* ok); |
1677 | 1647 |
1678 V8_INLINE void ParseArrowFunctionFormalParameterList( | 1648 V8_INLINE void ParseArrowFunctionFormalParameterList( |
1679 PreParserFormalParameters* parameters, | 1649 PreParserFormalParameters* parameters, PreParserExpression expression, |
1680 PreParserExpression expression, const Scanner::Location& params_loc, | 1650 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
1681 Scanner::Location* duplicate_loc, bool* ok); | 1651 bool* ok); |
1682 | 1652 |
1683 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} | 1653 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} |
1684 | 1654 |
1685 struct TemplateLiteralState {}; | 1655 struct TemplateLiteralState {}; |
1686 | 1656 |
1687 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1657 TemplateLiteralState OpenTemplateLiteral(int pos) { |
1688 return TemplateLiteralState(); | 1658 return TemplateLiteralState(); |
1689 } | 1659 } |
1690 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1660 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
1691 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1661 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 // to speed up later parsing. Finding errors is not the goal of pre-parsing, | 1735 // to speed up later parsing. Finding errors is not the goal of pre-parsing, |
1766 // rather it is to speed up properly written and correct programs. | 1736 // rather it is to speed up properly written and correct programs. |
1767 // That means that contextual checks (like a label being declared where | 1737 // That means that contextual checks (like a label being declared where |
1768 // it is used) are generally omitted. | 1738 // it is used) are generally omitted. |
1769 class PreParser : public ParserBase<PreParserTraits> { | 1739 class PreParser : public ParserBase<PreParserTraits> { |
1770 public: | 1740 public: |
1771 typedef PreParserIdentifier Identifier; | 1741 typedef PreParserIdentifier Identifier; |
1772 typedef PreParserExpression Expression; | 1742 typedef PreParserExpression Expression; |
1773 typedef PreParserStatement Statement; | 1743 typedef PreParserStatement Statement; |
1774 | 1744 |
1775 enum PreParseResult { | 1745 enum PreParseResult { kPreParseStackOverflow, kPreParseSuccess }; |
1776 kPreParseStackOverflow, | |
1777 kPreParseSuccess | |
1778 }; | |
1779 | 1746 |
1780 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 1747 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
1781 ParserRecorder* log, uintptr_t stack_limit) | 1748 ParserRecorder* log, uintptr_t stack_limit) |
1782 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, | 1749 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, |
1783 ast_value_factory, log, this) {} | 1750 ast_value_factory, log, this) {} |
1784 | 1751 |
1785 // Pre-parse the program from the character stream; returns true on | 1752 // Pre-parse the program from the character stream; returns true on |
1786 // success (even if parsing failed, the pre-parse data successfully | 1753 // success (even if parsing failed, the pre-parse data successfully |
1787 // captured the syntax error), and false if a stack-overflow happened | 1754 // captured the syntax error), and false if a stack-overflow happened |
1788 // during parsing. | 1755 // during parsing. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 } | 1877 } |
1911 | 1878 |
1912 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, | 1879 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
1913 PreParserExpressionList args, | 1880 PreParserExpressionList args, |
1914 int pos) { | 1881 int pos) { |
1915 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1882 return pre_parser_->factory()->NewCallNew(function, args, pos); |
1916 } | 1883 } |
1917 | 1884 |
1918 | 1885 |
1919 void PreParserTraits::ParseArrowFunctionFormalParameterList( | 1886 void PreParserTraits::ParseArrowFunctionFormalParameterList( |
1920 PreParserFormalParameters* parameters, | 1887 PreParserFormalParameters* parameters, PreParserExpression params, |
1921 PreParserExpression params, const Scanner::Location& params_loc, | 1888 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
1922 Scanner::Location* duplicate_loc, bool* ok) { | 1889 bool* ok) { |
1923 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1890 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1924 // lists that are too long. | 1891 // lists that are too long. |
1925 | 1892 |
1926 // Accomodate array literal for rest parameter. | 1893 // Accomodate array literal for rest parameter. |
1927 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { | 1894 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { |
1928 ++parameters->materialized_literals_count; | 1895 ++parameters->materialized_literals_count; |
1929 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1896 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
1930 } | 1897 } |
1931 } | 1898 } |
1932 | 1899 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 } | 2160 } |
2194 | 2161 |
2195 IdentifierT name = this->GetSymbol(scanner()); | 2162 IdentifierT name = this->GetSymbol(scanner()); |
2196 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); | 2163 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); |
2197 return name; | 2164 return name; |
2198 } | 2165 } |
2199 | 2166 |
2200 | 2167 |
2201 template <class Traits> | 2168 template <class Traits> |
2202 typename ParserBase<Traits>::IdentifierT | 2169 typename ParserBase<Traits>::IdentifierT |
2203 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, | 2170 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, bool* is_set, |
2204 bool* is_set, | |
2205 bool* ok) { | 2171 bool* ok) { |
2206 IdentifierT result = ParseIdentifierName(ok); | 2172 IdentifierT result = ParseIdentifierName(ok); |
2207 if (!*ok) return Traits::EmptyIdentifier(); | 2173 if (!*ok) return Traits::EmptyIdentifier(); |
2208 scanner()->IsGetOrSet(is_get, is_set); | 2174 scanner()->IsGetOrSet(is_get, is_set); |
2209 return result; | 2175 return result; |
2210 } | 2176 } |
2211 | 2177 |
2212 | 2178 |
2213 template <class Traits> | 2179 template <class Traits> |
2214 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( | 2180 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( |
(...skipping 16 matching lines...) Expand all Loading... |
2231 *ok = false; | 2197 *ok = false; |
2232 return Traits::EmptyExpression(); | 2198 return Traits::EmptyExpression(); |
2233 } | 2199 } |
2234 int js_flags = flags.FromJust(); | 2200 int js_flags = flags.FromJust(); |
2235 Next(); | 2201 Next(); |
2236 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, | 2202 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, |
2237 is_strong(language_mode()), pos); | 2203 is_strong(language_mode()), pos); |
2238 } | 2204 } |
2239 | 2205 |
2240 | 2206 |
2241 #define CHECK_OK ok); \ | 2207 #define CHECK_OK ok); \ |
2242 if (!*ok) return this->EmptyExpression(); \ | 2208 if (!*ok) return this->EmptyExpression(); \ |
2243 ((void)0 | 2209 ((void)0 |
2244 #define DUMMY ) // to make indentation work | 2210 #define DUMMY ) // to make indentation work |
2245 #undef DUMMY | 2211 #undef DUMMY |
2246 | 2212 |
2247 // Used in functions where the return type is not ExpressionT. | 2213 // Used in functions where the return type is not ExpressionT. |
2248 #define CHECK_OK_CUSTOM(x) ok); \ | 2214 #define CHECK_OK_CUSTOM(x) ok); \ |
2249 if (!*ok) return this->x(); \ | 2215 if (!*ok) return this->x(); \ |
2250 ((void)0 | 2216 ((void)0 |
2251 #define DUMMY ) // to make indentation work | 2217 #define DUMMY ) // to make indentation work |
2252 #undef DUMMY | 2218 #undef DUMMY |
2253 | 2219 |
2254 | 2220 |
2255 template <class Traits> | 2221 template <class Traits> |
2256 typename ParserBase<Traits>::ExpressionT | 2222 typename ParserBase<Traits>::ExpressionT |
2257 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, | 2223 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
2258 bool* ok) { | 2224 bool* ok) { |
2259 // PrimaryExpression :: | 2225 // PrimaryExpression :: |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2874 if (fni_ != nullptr) { | 2840 if (fni_ != nullptr) { |
2875 fni_->Infer(); | 2841 fni_->Infer(); |
2876 fni_->Leave(); | 2842 fni_->Leave(); |
2877 } | 2843 } |
2878 } | 2844 } |
2879 Expect(Token::RBRACE, CHECK_OK); | 2845 Expect(Token::RBRACE, CHECK_OK); |
2880 | 2846 |
2881 // Computation of literal_index must happen before pre parse bailout. | 2847 // Computation of literal_index must happen before pre parse bailout. |
2882 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2848 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
2883 | 2849 |
2884 return factory()->NewObjectLiteral(properties, | 2850 return factory()->NewObjectLiteral( |
2885 literal_index, | 2851 properties, literal_index, number_of_boilerplate_properties, has_function, |
2886 number_of_boilerplate_properties, | 2852 is_strong(language_mode()), pos); |
2887 has_function, | |
2888 is_strong(language_mode()), | |
2889 pos); | |
2890 } | 2853 } |
2891 | 2854 |
2892 | 2855 |
2893 template <class Traits> | 2856 template <class Traits> |
2894 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2857 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
2895 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier, | 2858 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier, |
2896 bool* ok) { | 2859 bool* ok) { |
2897 // Arguments :: | 2860 // Arguments :: |
2898 // '(' (AssignmentExpression)*[','] ')' | 2861 // '(' (AssignmentExpression)*[','] ')' |
2899 | 2862 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 case Token::SEMICOLON: | 3063 case Token::SEMICOLON: |
3101 case Token::RBRACE: | 3064 case Token::RBRACE: |
3102 case Token::RBRACK: | 3065 case Token::RBRACK: |
3103 case Token::RPAREN: | 3066 case Token::RPAREN: |
3104 case Token::COLON: | 3067 case Token::COLON: |
3105 case Token::COMMA: | 3068 case Token::COMMA: |
3106 // The above set of tokens is the complete set of tokens that can appear | 3069 // The above set of tokens is the complete set of tokens that can appear |
3107 // after an AssignmentExpression, and none of them can start an | 3070 // after an AssignmentExpression, and none of them can start an |
3108 // AssignmentExpression. This allows us to avoid looking for an RHS for | 3071 // AssignmentExpression. This allows us to avoid looking for an RHS for |
3109 // a Yield::kSuspend operation, given only one look-ahead token. | 3072 // a Yield::kSuspend operation, given only one look-ahead token. |
3110 if (kind == Yield::kSuspend) | 3073 if (kind == Yield::kSuspend) break; |
3111 break; | |
3112 DCHECK_EQ(Yield::kDelegating, kind); | 3074 DCHECK_EQ(Yield::kDelegating, kind); |
3113 // Delegating yields require an RHS; fall through. | 3075 // Delegating yields require an RHS; fall through. |
3114 default: | 3076 default: |
3115 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 3077 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); |
3116 break; | 3078 break; |
3117 } | 3079 } |
3118 } | 3080 } |
3119 if (kind == Yield::kDelegating) { | 3081 if (kind == Yield::kDelegating) { |
3120 // var iterator = subject[Symbol.iterator](); | 3082 // var iterator = subject[Symbol.iterator](); |
3121 expression = this->GetIterator(expression, factory()); | 3083 expression = this->GetIterator(expression, factory()); |
3122 } | 3084 } |
3123 typename Traits::Type::YieldExpression yield = | 3085 typename Traits::Type::YieldExpression yield = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3179 continue; | 3141 continue; |
3180 } | 3142 } |
3181 | 3143 |
3182 // For now we distinguish between comparisons and other binary | 3144 // For now we distinguish between comparisons and other binary |
3183 // operations. (We could combine the two and get rid of this | 3145 // operations. (We could combine the two and get rid of this |
3184 // code and AST node eventually.) | 3146 // code and AST node eventually.) |
3185 if (Token::IsCompareOp(op)) { | 3147 if (Token::IsCompareOp(op)) { |
3186 // We have a comparison. | 3148 // We have a comparison. |
3187 Token::Value cmp = op; | 3149 Token::Value cmp = op; |
3188 switch (op) { | 3150 switch (op) { |
3189 case Token::NE: cmp = Token::EQ; break; | 3151 case Token::NE: |
3190 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; | 3152 cmp = Token::EQ; |
3191 default: break; | 3153 break; |
| 3154 case Token::NE_STRICT: |
| 3155 cmp = Token::EQ_STRICT; |
| 3156 break; |
| 3157 default: |
| 3158 break; |
3192 } | 3159 } |
3193 if (cmp == Token::EQ && is_strong(language_mode())) { | 3160 if (cmp == Token::EQ && is_strong(language_mode())) { |
3194 ReportMessageAt(op_location, MessageTemplate::kStrongEqual); | 3161 ReportMessageAt(op_location, MessageTemplate::kStrongEqual); |
3195 *ok = false; | 3162 *ok = false; |
3196 return this->EmptyExpression(); | 3163 return this->EmptyExpression(); |
3197 } | 3164 } |
3198 x = factory()->NewCompareOperation(cmp, x, y, pos); | 3165 x = factory()->NewCompareOperation(cmp, x, y, pos); |
3199 if (cmp != op) { | 3166 if (cmp != op) { |
3200 // The comparison was negated - add a NOT. | 3167 // The comparison was negated - add a NOT. |
3201 x = factory()->NewUnaryOperation(Token::NOT, x, pos); | 3168 x = factory()->NewUnaryOperation(Token::NOT, x, pos); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3255 BindingPatternUnexpectedToken(classifier); | 3222 BindingPatternUnexpectedToken(classifier); |
3256 ArrowFormalParametersUnexpectedToken(classifier); | 3223 ArrowFormalParametersUnexpectedToken(classifier); |
3257 op = Next(); | 3224 op = Next(); |
3258 int beg_pos = peek_position(); | 3225 int beg_pos = peek_position(); |
3259 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 3226 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
3260 expression = this->CheckAndRewriteReferenceExpression( | 3227 expression = this->CheckAndRewriteReferenceExpression( |
3261 expression, beg_pos, scanner()->location().end_pos, | 3228 expression, beg_pos, scanner()->location().end_pos, |
3262 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 3229 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
3263 this->MarkExpressionAsAssigned(expression); | 3230 this->MarkExpressionAsAssigned(expression); |
3264 | 3231 |
3265 return factory()->NewCountOperation(op, | 3232 return factory()->NewCountOperation(op, true /* prefix */, expression, |
3266 true /* prefix */, | |
3267 expression, | |
3268 position()); | 3233 position()); |
3269 | 3234 |
3270 } else { | 3235 } else { |
3271 return this->ParsePostfixExpression(classifier, ok); | 3236 return this->ParsePostfixExpression(classifier, ok); |
3272 } | 3237 } |
3273 } | 3238 } |
3274 | 3239 |
3275 | 3240 |
3276 template <class Traits> | 3241 template <class Traits> |
3277 typename ParserBase<Traits>::ExpressionT | 3242 typename ParserBase<Traits>::ExpressionT |
3278 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, | 3243 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, |
3279 bool* ok) { | 3244 bool* ok) { |
3280 // PostfixExpression :: | 3245 // PostfixExpression :: |
3281 // LeftHandSideExpression ('++' | '--')? | 3246 // LeftHandSideExpression ('++' | '--')? |
3282 | 3247 |
3283 int lhs_beg_pos = peek_position(); | 3248 int lhs_beg_pos = peek_position(); |
3284 ExpressionT expression = | 3249 ExpressionT expression = |
3285 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 3250 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
3286 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 3251 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
3287 Token::IsCountOp(peek())) { | 3252 Token::IsCountOp(peek())) { |
3288 BindingPatternUnexpectedToken(classifier); | 3253 BindingPatternUnexpectedToken(classifier); |
3289 ArrowFormalParametersUnexpectedToken(classifier); | 3254 ArrowFormalParametersUnexpectedToken(classifier); |
3290 | 3255 |
3291 expression = this->CheckAndRewriteReferenceExpression( | 3256 expression = this->CheckAndRewriteReferenceExpression( |
3292 expression, lhs_beg_pos, scanner()->location().end_pos, | 3257 expression, lhs_beg_pos, scanner()->location().end_pos, |
3293 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 3258 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
3294 expression = this->MarkExpressionAsAssigned(expression); | 3259 expression = this->MarkExpressionAsAssigned(expression); |
3295 | 3260 |
3296 Token::Value next = Next(); | 3261 Token::Value next = Next(); |
3297 expression = | 3262 expression = factory()->NewCountOperation(next, false /* postfix */, |
3298 factory()->NewCountOperation(next, | 3263 expression, position()); |
3299 false /* postfix */, | |
3300 expression, | |
3301 position()); | |
3302 } | 3264 } |
3303 return expression; | 3265 return expression; |
3304 } | 3266 } |
3305 | 3267 |
3306 | 3268 |
3307 template <class Traits> | 3269 template <class Traits> |
3308 typename ParserBase<Traits>::ExpressionT | 3270 typename ParserBase<Traits>::ExpressionT |
3309 ParserBase<Traits>::ParseLeftHandSideExpression( | 3271 ParserBase<Traits>::ParseLeftHandSideExpression( |
3310 ExpressionClassifier* classifier, bool* ok) { | 3272 ExpressionClassifier* classifier, bool* ok) { |
3311 // LeftHandSideExpression :: | 3273 // LeftHandSideExpression :: |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3789 default: | 3751 default: |
3790 return expression; | 3752 return expression; |
3791 } | 3753 } |
3792 } | 3754 } |
3793 DCHECK(false); | 3755 DCHECK(false); |
3794 return this->EmptyExpression(); | 3756 return this->EmptyExpression(); |
3795 } | 3757 } |
3796 | 3758 |
3797 | 3759 |
3798 template <class Traits> | 3760 template <class Traits> |
3799 void ParserBase<Traits>::ParseFormalParameter( | 3761 void ParserBase<Traits>::ParseFormalParameter(FormalParametersT* parameters, |
3800 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3762 ExpressionClassifier* classifier, |
| 3763 bool* ok) { |
3801 // FormalParameter[Yield,GeneratorParameter] : | 3764 // FormalParameter[Yield,GeneratorParameter] : |
3802 // BindingElement[?Yield, ?GeneratorParameter] | 3765 // BindingElement[?Yield, ?GeneratorParameter] |
3803 bool is_rest = parameters->has_rest; | 3766 bool is_rest = parameters->has_rest; |
3804 | 3767 |
3805 Token::Value next = peek(); | 3768 Token::Value next = peek(); |
3806 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 3769 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); |
3807 if (!*ok) return; | 3770 if (!*ok) return; |
3808 | 3771 |
3809 ValidateBindingPattern(classifier, ok); | 3772 ValidateBindingPattern(classifier, ok); |
3810 if (!*ok) return; | 3773 if (!*ok) return; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3874 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); | 3837 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); |
3875 ParseFormalParameter(parameters, classifier, ok); | 3838 ParseFormalParameter(parameters, classifier, ok); |
3876 if (!*ok) return; | 3839 if (!*ok) return; |
3877 } while (!parameters->has_rest && Check(Token::COMMA)); | 3840 } while (!parameters->has_rest && Check(Token::COMMA)); |
3878 | 3841 |
3879 if (parameters->has_rest) { | 3842 if (parameters->has_rest) { |
3880 parameters->is_simple = false; | 3843 parameters->is_simple = false; |
3881 classifier->RecordNonSimpleParameter(); | 3844 classifier->RecordNonSimpleParameter(); |
3882 if (peek() == Token::COMMA) { | 3845 if (peek() == Token::COMMA) { |
3883 ReportMessageAt(scanner()->peek_location(), | 3846 ReportMessageAt(scanner()->peek_location(), |
3884 MessageTemplate::kParamAfterRest); | 3847 MessageTemplate::kParamAfterRest); |
3885 *ok = false; | 3848 *ok = false; |
3886 return; | 3849 return; |
3887 } | 3850 } |
3888 } | 3851 } |
3889 } | 3852 } |
3890 | 3853 |
3891 for (int i = 0; i < parameters->Arity(); ++i) { | 3854 for (int i = 0; i < parameters->Arity(); ++i) { |
3892 auto parameter = parameters->at(i); | 3855 auto parameter = parameters->at(i); |
3893 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); | 3856 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
3894 } | 3857 } |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4253 return; | 4216 return; |
4254 } | 4217 } |
4255 has_seen_constructor_ = true; | 4218 has_seen_constructor_ = true; |
4256 return; | 4219 return; |
4257 } | 4220 } |
4258 } | 4221 } |
4259 } // namespace internal | 4222 } // namespace internal |
4260 } // namespace v8 | 4223 } // namespace v8 |
4261 | 4224 |
4262 #endif // V8_PARSING_PREPARSER_H | 4225 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |