Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: src/parsing/preparser.cc

Issue 2321103002: [parser] Refactor of Parse*Statement*, part 5 (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 token != Token::RBRACE) { 193 token != Token::RBRACE) {
194 statement = ParseStatementListItem(CHECK_OK); 194 statement = ParseStatementListItem(CHECK_OK);
195 token = peek(); 195 token = peek();
196 } 196 }
197 } 197 }
198 } 198 }
199 Expect(Token::RBRACE, ok); 199 Expect(Token::RBRACE, ok);
200 return Statement::Default(); 200 return Statement::Default();
201 } 201 }
202 202
203 PreParser::Statement PreParser::ParseDoWhileStatement(
204 ZoneList<const AstRawString*>* labels, bool* ok) {
205 // DoStatement ::
206 // 'do' Statement 'while' '(' Expression ')' ';'
207
208 Expect(Token::DO, CHECK_OK);
209 ParseScopedStatement(nullptr, true, CHECK_OK);
210 Expect(Token::WHILE, CHECK_OK);
211 Expect(Token::LPAREN, CHECK_OK);
212 ParseExpression(true, CHECK_OK);
213 Expect(Token::RPAREN, ok);
214 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
215 return Statement::Default();
216 }
217
218 PreParser::Statement PreParser::ParseWhileStatement(
219 ZoneList<const AstRawString*>* labels, bool* ok) {
220 // WhileStatement ::
221 // 'while' '(' Expression ')' Statement
222
223 Expect(Token::WHILE, CHECK_OK);
224 Expect(Token::LPAREN, CHECK_OK);
225 ParseExpression(true, CHECK_OK);
226 Expect(Token::RPAREN, CHECK_OK);
227 ParseScopedStatement(nullptr, true, ok);
228 return Statement::Default();
229 }
230
231 PreParser::Statement PreParser::ParseForStatement( 203 PreParser::Statement PreParser::ParseForStatement(
232 ZoneList<const AstRawString*>* labels, bool* ok) { 204 ZoneList<const AstRawString*>* labels, bool* ok) {
233 // ForStatement :: 205 // ForStatement ::
234 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 206 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
235 207
236 // Create an in-between scope for let-bound iteration variables. 208 // Create an in-between scope for let-bound iteration variables.
237 bool has_lexical = false; 209 bool has_lexical = false;
238 210
239 BlockState block_state(&scope_state_); 211 BlockState block_state(&scope_state_);
240 Expect(Token::FOR, CHECK_OK); 212 Expect(Token::FOR, CHECK_OK);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 ParseExpression(true, CHECK_OK); 327 ParseExpression(true, CHECK_OK);
356 } 328 }
357 Expect(Token::RPAREN, CHECK_OK); 329 Expect(Token::RPAREN, CHECK_OK);
358 330
359 ParseScopedStatement(nullptr, true, ok); 331 ParseScopedStatement(nullptr, true, ok);
360 } 332 }
361 return Statement::Default(); 333 return Statement::Default();
362 } 334 }
363 335
364 336
365 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) {
366 // ThrowStatement ::
367 // 'throw' [no line terminator] Expression ';'
368
369 Expect(Token::THROW, CHECK_OK);
370 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
371 ReportMessageAt(scanner()->location(), MessageTemplate::kNewlineAfterThrow);
372 *ok = false;
373 return Statement::Default();
374 }
375 ParseExpression(true, CHECK_OK);
376 ExpectSemicolon(ok);
377 return Statement::Jump();
378 }
379
380
381 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { 337 PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
382 // TryStatement :: 338 // TryStatement ::
383 // 'try' Block Catch 339 // 'try' Block Catch
384 // 'try' Block Finally 340 // 'try' Block Finally
385 // 'try' Block Catch Finally 341 // 'try' Block Catch Finally
386 // 342 //
387 // Catch :: 343 // Catch ::
388 // 'catch' '(' Identifier ')' Block 344 // 'catch' '(' Identifier ')' Block
389 // 345 //
390 // Finally :: 346 // Finally ::
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 &has_seen_constructor, CHECK_OK); 558 &has_seen_constructor, CHECK_OK);
603 ValidateExpression(CHECK_OK); 559 ValidateExpression(CHECK_OK);
604 impl()->AccumulateFormalParameterContainmentErrors(); 560 impl()->AccumulateFormalParameterContainmentErrors();
605 } 561 }
606 562
607 Expect(Token::RBRACE, CHECK_OK); 563 Expect(Token::RBRACE, CHECK_OK);
608 564
609 return Expression::Default(); 565 return Expression::Default();
610 } 566 }
611 567
612 PreParserExpression PreParser::ParseDoExpression(bool* ok) {
613 // AssignmentExpression ::
614 // do '{' StatementList '}'
615 Expect(Token::DO, CHECK_OK);
616 Expect(Token::LBRACE, CHECK_OK);
617 while (peek() != Token::RBRACE) {
618 ParseStatementListItem(CHECK_OK);
619 }
620 Expect(Token::RBRACE, CHECK_OK);
621 return PreParserExpression::Default();
622 }
623
624 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, 568 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body,
625 bool accept_IN, int pos, 569 bool accept_IN, int pos,
626 bool* ok) { 570 bool* ok) {
627 scope()->ForceContextAllocation(); 571 scope()->ForceContextAllocation();
628 572
629 PreParserExpression return_value = 573 PreParserExpression return_value =
630 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); 574 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID);
631 575
632 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 576 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
633 } 577 }
634 578
635 #undef CHECK_OK 579 #undef CHECK_OK
636 #undef CHECK_OK_CUSTOM 580 #undef CHECK_OK_CUSTOM
637 581
638 582
639 } // namespace internal 583 } // namespace internal
640 } // namespace v8 584 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/interpreter/bytecode_expectations/DoExpression.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698