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

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

Issue 2339453002: [parser] Refactor of Parse*Statement*, part 7 (Closed)
Patch Set: Change in comment 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
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 ParseExpression(true, CHECK_OK); 291 ParseExpression(true, CHECK_OK);
292 } 292 }
293 Expect(Token::RPAREN, CHECK_OK); 293 Expect(Token::RPAREN, CHECK_OK);
294 294
295 ParseScopedStatement(nullptr, true, ok); 295 ParseScopedStatement(nullptr, true, ok);
296 } 296 }
297 return Statement::Default(); 297 return Statement::Default();
298 } 298 }
299 299
300 300
301 PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
302 // TryStatement ::
303 // 'try' Block Catch
304 // 'try' Block Finally
305 // 'try' Block Catch Finally
306 //
307 // Catch ::
308 // 'catch' '(' Identifier ')' Block
309 //
310 // Finally ::
311 // 'finally' Block
312
313 Expect(Token::TRY, CHECK_OK);
314
315 {
316 ReturnExprScope no_tail_calls(function_state_,
317 ReturnExprContext::kInsideTryBlock);
318 ParseBlock(nullptr, CHECK_OK);
319 }
320
321 Token::Value tok = peek();
322 if (tok != Token::CATCH && tok != Token::FINALLY) {
323 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally);
324 *ok = false;
325 return Statement::Default();
326 }
327 TailCallExpressionList tail_call_expressions_in_catch_block(zone());
328 bool catch_block_exists = false;
329 if (tok == Token::CATCH) {
330 Consume(Token::CATCH);
331 Expect(Token::LPAREN, CHECK_OK);
332 Scope* catch_scope = NewScope(CATCH_SCOPE);
333 ExpressionClassifier pattern_classifier(this);
334 ParsePrimaryExpression(CHECK_OK);
335 ValidateBindingPattern(CHECK_OK);
336 Expect(Token::RPAREN, CHECK_OK);
337 {
338 CollectExpressionsInTailPositionToListScope
339 collect_tail_call_expressions_scope(
340 function_state_, &tail_call_expressions_in_catch_block);
341 BlockState block_state(&scope_state_, catch_scope);
342 {
343 BlockState block_state(&scope_state_);
344 ParseBlock(nullptr, CHECK_OK);
345 }
346 }
347 catch_block_exists = true;
348 tok = peek();
349 }
350 if (tok == Token::FINALLY) {
351 Consume(Token::FINALLY);
352 ParseBlock(nullptr, CHECK_OK);
353 if (FLAG_harmony_explicit_tailcalls && catch_block_exists &&
354 tail_call_expressions_in_catch_block.has_explicit_tail_calls()) {
355 // TODO(ishell): update chapter number.
356 // ES8 XX.YY.ZZ
357 ReportMessageAt(tail_call_expressions_in_catch_block.location(),
358 MessageTemplate::kUnexpectedTailCallInCatchBlock);
359 *ok = false;
360 return Statement::Default();
361 }
362 }
363 return Statement::Default();
364 }
365
366
367 // Redefinition of CHECK_OK for parsing expressions. 301 // Redefinition of CHECK_OK for parsing expressions.
368 #undef CHECK_OK 302 #undef CHECK_OK
369 #define CHECK_OK CHECK_OK_VALUE(Expression::Default()) 303 #define CHECK_OK CHECK_OK_VALUE(Expression::Default())
370 304
371 PreParser::Expression PreParser::ParseFunctionLiteral( 305 PreParser::Expression PreParser::ParseFunctionLiteral(
372 Identifier function_name, Scanner::Location function_name_location, 306 Identifier function_name, Scanner::Location function_name_location,
373 FunctionNameValidity function_name_validity, FunctionKind kind, 307 FunctionNameValidity function_name_validity, FunctionKind kind,
374 int function_token_pos, FunctionLiteral::FunctionType function_type, 308 int function_token_pos, FunctionLiteral::FunctionType function_type,
375 LanguageMode language_mode, bool* ok) { 309 LanguageMode language_mode, bool* ok) {
376 // Function :: 310 // Function ::
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 473
540 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 474 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
541 } 475 }
542 476
543 #undef CHECK_OK 477 #undef CHECK_OK
544 #undef CHECK_OK_CUSTOM 478 #undef CHECK_OK_CUSTOM
545 479
546 480
547 } // namespace internal 481 } // namespace internal
548 } // namespace v8 482 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698