OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 token != Token::RBRACE) { | 229 token != Token::RBRACE) { |
230 statement = ParseStatementListItem(CHECK_OK); | 230 statement = ParseStatementListItem(CHECK_OK); |
231 token = peek(); | 231 token = peek(); |
232 } | 232 } |
233 } | 233 } |
234 } | 234 } |
235 Expect(Token::RBRACE, ok); | 235 Expect(Token::RBRACE, ok); |
236 return Statement::Default(); | 236 return Statement::Default(); |
237 } | 237 } |
238 | 238 |
239 PreParser::Statement PreParser::ParseDoWhileStatement( | |
240 ZoneList<const AstRawString*>* labels, bool* ok) { | |
241 // DoStatement :: | |
242 // 'do' Statement 'while' '(' Expression ')' ';' | |
243 | |
244 Expect(Token::DO, CHECK_OK); | |
245 ParseScopedStatement(nullptr, true, CHECK_OK); | |
246 Expect(Token::WHILE, CHECK_OK); | |
247 Expect(Token::LPAREN, CHECK_OK); | |
248 ParseExpression(true, CHECK_OK); | |
249 Expect(Token::RPAREN, ok); | |
250 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); | |
251 return Statement::Default(); | |
252 } | |
253 | |
254 PreParser::Statement PreParser::ParseWhileStatement( | |
255 ZoneList<const AstRawString*>* labels, bool* ok) { | |
256 // WhileStatement :: | |
257 // 'while' '(' Expression ')' Statement | |
258 | |
259 Expect(Token::WHILE, CHECK_OK); | |
260 Expect(Token::LPAREN, CHECK_OK); | |
261 ParseExpression(true, CHECK_OK); | |
262 Expect(Token::RPAREN, CHECK_OK); | |
263 ParseScopedStatement(nullptr, true, ok); | |
264 return Statement::Default(); | |
265 } | |
266 | |
267 PreParser::Statement PreParser::ParseForStatement( | 239 PreParser::Statement PreParser::ParseForStatement( |
268 ZoneList<const AstRawString*>* labels, bool* ok) { | 240 ZoneList<const AstRawString*>* labels, bool* ok) { |
269 // ForStatement :: | 241 // ForStatement :: |
270 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 242 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
271 | 243 |
272 // Create an in-between scope for let-bound iteration variables. | 244 // Create an in-between scope for let-bound iteration variables. |
273 bool has_lexical = false; | 245 bool has_lexical = false; |
274 | 246 |
275 BlockState block_state(&scope_state_); | 247 BlockState block_state(&scope_state_); |
276 Expect(Token::FOR, CHECK_OK); | 248 Expect(Token::FOR, CHECK_OK); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 ParseExpression(true, CHECK_OK); | 363 ParseExpression(true, CHECK_OK); |
392 } | 364 } |
393 Expect(Token::RPAREN, CHECK_OK); | 365 Expect(Token::RPAREN, CHECK_OK); |
394 | 366 |
395 ParseScopedStatement(nullptr, true, ok); | 367 ParseScopedStatement(nullptr, true, ok); |
396 } | 368 } |
397 return Statement::Default(); | 369 return Statement::Default(); |
398 } | 370 } |
399 | 371 |
400 | 372 |
401 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { | |
402 // ThrowStatement :: | |
403 // 'throw' [no line terminator] Expression ';' | |
404 | |
405 Expect(Token::THROW, CHECK_OK); | |
406 if (scanner()->HasAnyLineTerminatorBeforeNext()) { | |
407 ReportMessageAt(scanner()->location(), MessageTemplate::kNewlineAfterThrow); | |
408 *ok = false; | |
409 return Statement::Default(); | |
410 } | |
411 ParseExpression(true, CHECK_OK); | |
412 ExpectSemicolon(ok); | |
413 return Statement::Jump(); | |
414 } | |
415 | |
416 | |
417 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { | 373 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { |
418 // TryStatement :: | 374 // TryStatement :: |
419 // 'try' Block Catch | 375 // 'try' Block Catch |
420 // 'try' Block Finally | 376 // 'try' Block Finally |
421 // 'try' Block Catch Finally | 377 // 'try' Block Catch Finally |
422 // | 378 // |
423 // Catch :: | 379 // Catch :: |
424 // 'catch' '(' Identifier ')' Block | 380 // 'catch' '(' Identifier ')' Block |
425 // | 381 // |
426 // Finally :: | 382 // Finally :: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 &has_seen_constructor, CHECK_OK); | 594 &has_seen_constructor, CHECK_OK); |
639 ValidateExpression(CHECK_OK); | 595 ValidateExpression(CHECK_OK); |
640 impl()->AccumulateFormalParameterContainmentErrors(); | 596 impl()->AccumulateFormalParameterContainmentErrors(); |
641 } | 597 } |
642 | 598 |
643 Expect(Token::RBRACE, CHECK_OK); | 599 Expect(Token::RBRACE, CHECK_OK); |
644 | 600 |
645 return Expression::Default(); | 601 return Expression::Default(); |
646 } | 602 } |
647 | 603 |
648 PreParserExpression PreParser::ParseDoExpression(bool* ok) { | |
649 // AssignmentExpression :: | |
650 // do '{' StatementList '}' | |
651 Expect(Token::DO, CHECK_OK); | |
652 Expect(Token::LBRACE, CHECK_OK); | |
653 while (peek() != Token::RBRACE) { | |
654 ParseStatementListItem(CHECK_OK); | |
655 } | |
656 Expect(Token::RBRACE, CHECK_OK); | |
657 return PreParserExpression::Default(); | |
658 } | |
659 | |
660 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, | 604 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, |
661 bool accept_IN, int pos, | 605 bool accept_IN, int pos, |
662 bool* ok) { | 606 bool* ok) { |
663 scope()->ForceContextAllocation(); | 607 scope()->ForceContextAllocation(); |
664 | 608 |
665 PreParserExpression return_value = | 609 PreParserExpression return_value = |
666 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); | 610 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); |
667 | 611 |
668 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 612 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
669 } | 613 } |
670 | 614 |
671 #undef CHECK_OK | 615 #undef CHECK_OK |
672 #undef CHECK_OK_CUSTOM | 616 #undef CHECK_OK_CUSTOM |
673 | 617 |
674 | 618 |
675 } // namespace internal | 619 } // namespace internal |
676 } // namespace v8 | 620 } // namespace v8 |
OLD | NEW |