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

Side by Side Diff: src/preparser.cc

Issue 931223002: [strong] deprecate empty sub-statements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Another rebase & merge conflicts Created 5 years, 10 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 #define CHECK_OK ok); \ 222 #define CHECK_OK ok); \
223 if (!*ok) return Statement::Default(); \ 223 if (!*ok) return Statement::Default(); \
224 ((void)0 224 ((void)0
225 #define DUMMY ) // to make indentation work 225 #define DUMMY ) // to make indentation work
226 #undef DUMMY 226 #undef DUMMY
227 227
228 228
229 PreParser::Statement PreParser::ParseStatement(bool* ok) { 229 PreParser::Statement PreParser::ParseStatement(bool* ok) {
230 // Statement :: 230 // Statement ::
231 // EmptyStatement
232 // ...
233 return ParseSubStatement(ok);
234 }
235
236
237 PreParser::Statement PreParser::ParseSubStatement(bool* ok) {
238 // Statement ::
231 // Block 239 // Block
232 // VariableStatement 240 // VariableStatement
233 // EmptyStatement 241 // EmptyStatement
234 // ExpressionStatement 242 // ExpressionStatement
235 // IfStatement 243 // IfStatement
236 // IterationStatement 244 // IterationStatement
237 // ContinueStatement 245 // ContinueStatement
238 // BreakStatement 246 // BreakStatement
239 // ReturnStatement 247 // ReturnStatement
240 // WithStatement 248 // WithStatement
241 // LabelledStatement 249 // LabelledStatement
242 // SwitchStatement 250 // SwitchStatement
243 // ThrowStatement 251 // ThrowStatement
244 // TryStatement 252 // TryStatement
245 // DebuggerStatement 253 // DebuggerStatement
246 254
247 // Note: Since labels can only be used by 'break' and 'continue' 255 // Note: Since labels can only be used by 'break' and 'continue'
248 // statements, which themselves are only valid within blocks, 256 // statements, which themselves are only valid within blocks,
249 // iterations or 'switch' statements (i.e., BreakableStatements), 257 // iterations or 'switch' statements (i.e., BreakableStatements),
250 // labels can be simply ignored in all other cases; except for 258 // labels can be simply ignored in all other cases; except for
251 // trivial labeled break statements 'label: break label' which is 259 // trivial labeled break statements 'label: break label' which is
252 // parsed into an empty statement. 260 // parsed into an empty statement.
253 261
254 // Keep the source position of the statement 262 // Keep the source position of the statement
255 switch (peek()) { 263 switch (peek()) {
256 case Token::LBRACE: 264 case Token::LBRACE:
257 return ParseBlock(ok); 265 return ParseBlock(ok);
258 266
259 case Token::SEMICOLON: 267 case Token::SEMICOLON:
268 if (is_strong(language_mode())) {
269 PreParserTraits::ReportMessageAt(scanner()->peek_location(),
270 "strong_empty");
271 *ok = false;
272 return Statement::Default();
273 }
260 Next(); 274 Next();
261 return Statement::Default(); 275 return Statement::Default();
262 276
263 case Token::IF: 277 case Token::IF:
264 return ParseIfStatement(ok); 278 return ParseIfStatement(ok);
265 279
266 case Token::DO: 280 case Token::DO:
267 return ParseDoWhileStatement(ok); 281 return ParseDoWhileStatement(ok);
268 282
269 case Token::WHILE: 283 case Token::WHILE:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 557
544 558
545 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { 559 PreParser::Statement PreParser::ParseIfStatement(bool* ok) {
546 // IfStatement :: 560 // IfStatement ::
547 // 'if' '(' Expression ')' Statement ('else' Statement)? 561 // 'if' '(' Expression ')' Statement ('else' Statement)?
548 562
549 Expect(Token::IF, CHECK_OK); 563 Expect(Token::IF, CHECK_OK);
550 Expect(Token::LPAREN, CHECK_OK); 564 Expect(Token::LPAREN, CHECK_OK);
551 ParseExpression(true, CHECK_OK); 565 ParseExpression(true, CHECK_OK);
552 Expect(Token::RPAREN, CHECK_OK); 566 Expect(Token::RPAREN, CHECK_OK);
553 ParseStatement(CHECK_OK); 567 ParseSubStatement(CHECK_OK);
554 if (peek() == Token::ELSE) { 568 if (peek() == Token::ELSE) {
555 Next(); 569 Next();
556 ParseStatement(CHECK_OK); 570 ParseSubStatement(CHECK_OK);
557 } 571 }
558 return Statement::Default(); 572 return Statement::Default();
559 } 573 }
560 574
561 575
562 PreParser::Statement PreParser::ParseContinueStatement(bool* ok) { 576 PreParser::Statement PreParser::ParseContinueStatement(bool* ok) {
563 // ContinueStatement :: 577 // ContinueStatement ::
564 // 'continue' [no line terminator] Identifier? ';' 578 // 'continue' [no line terminator] Identifier? ';'
565 579
566 Expect(Token::CONTINUE, CHECK_OK); 580 Expect(Token::CONTINUE, CHECK_OK);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 ReportMessageAt(scanner()->location(), "strict_mode_with"); 643 ReportMessageAt(scanner()->location(), "strict_mode_with");
630 *ok = false; 644 *ok = false;
631 return Statement::Default(); 645 return Statement::Default();
632 } 646 }
633 Expect(Token::LPAREN, CHECK_OK); 647 Expect(Token::LPAREN, CHECK_OK);
634 ParseExpression(true, CHECK_OK); 648 ParseExpression(true, CHECK_OK);
635 Expect(Token::RPAREN, CHECK_OK); 649 Expect(Token::RPAREN, CHECK_OK);
636 650
637 Scope* with_scope = NewScope(scope_, WITH_SCOPE); 651 Scope* with_scope = NewScope(scope_, WITH_SCOPE);
638 BlockState block_state(&scope_, with_scope); 652 BlockState block_state(&scope_, with_scope);
639 ParseStatement(CHECK_OK); 653 ParseSubStatement(CHECK_OK);
640 return Statement::Default(); 654 return Statement::Default();
641 } 655 }
642 656
643 657
644 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { 658 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) {
645 // SwitchStatement :: 659 // SwitchStatement ::
646 // 'switch' '(' Expression ')' '{' CaseClause* '}' 660 // 'switch' '(' Expression ')' '{' CaseClause* '}'
647 661
648 Expect(Token::SWITCH, CHECK_OK); 662 Expect(Token::SWITCH, CHECK_OK);
649 Expect(Token::LPAREN, CHECK_OK); 663 Expect(Token::LPAREN, CHECK_OK);
(...skipping 21 matching lines...) Expand all
671 Expect(Token::RBRACE, ok); 685 Expect(Token::RBRACE, ok);
672 return Statement::Default(); 686 return Statement::Default();
673 } 687 }
674 688
675 689
676 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { 690 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) {
677 // DoStatement :: 691 // DoStatement ::
678 // 'do' Statement 'while' '(' Expression ')' ';' 692 // 'do' Statement 'while' '(' Expression ')' ';'
679 693
680 Expect(Token::DO, CHECK_OK); 694 Expect(Token::DO, CHECK_OK);
681 ParseStatement(CHECK_OK); 695 ParseSubStatement(CHECK_OK);
682 Expect(Token::WHILE, CHECK_OK); 696 Expect(Token::WHILE, CHECK_OK);
683 Expect(Token::LPAREN, CHECK_OK); 697 Expect(Token::LPAREN, CHECK_OK);
684 ParseExpression(true, CHECK_OK); 698 ParseExpression(true, CHECK_OK);
685 Expect(Token::RPAREN, ok); 699 Expect(Token::RPAREN, ok);
686 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); 700 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
687 return Statement::Default(); 701 return Statement::Default();
688 } 702 }
689 703
690 704
691 PreParser::Statement PreParser::ParseWhileStatement(bool* ok) { 705 PreParser::Statement PreParser::ParseWhileStatement(bool* ok) {
692 // WhileStatement :: 706 // WhileStatement ::
693 // 'while' '(' Expression ')' Statement 707 // 'while' '(' Expression ')' Statement
694 708
695 Expect(Token::WHILE, CHECK_OK); 709 Expect(Token::WHILE, CHECK_OK);
696 Expect(Token::LPAREN, CHECK_OK); 710 Expect(Token::LPAREN, CHECK_OK);
697 ParseExpression(true, CHECK_OK); 711 ParseExpression(true, CHECK_OK);
698 Expect(Token::RPAREN, CHECK_OK); 712 Expect(Token::RPAREN, CHECK_OK);
699 ParseStatement(ok); 713 ParseSubStatement(ok);
700 return Statement::Default(); 714 return Statement::Default();
701 } 715 }
702 716
703 717
704 bool PreParser::CheckInOrOf(bool accept_OF) { 718 bool PreParser::CheckInOrOf(bool accept_OF) {
705 if (Check(Token::IN) || 719 if (Check(Token::IN) ||
706 (accept_OF && CheckContextualKeyword(CStrVector("of")))) { 720 (accept_OF && CheckContextualKeyword(CStrVector("of")))) {
707 return true; 721 return true;
708 } 722 }
709 return false; 723 return false;
(...skipping 16 matching lines...) Expand all
726 VariableDeclarationProperties decl_props = kHasNoInitializers; 740 VariableDeclarationProperties decl_props = kHasNoInitializers;
727 ParseVariableDeclarations( 741 ParseVariableDeclarations(
728 kForStatement, &decl_props, &decl_count, CHECK_OK); 742 kForStatement, &decl_props, &decl_count, CHECK_OK);
729 bool has_initializers = decl_props == kHasInitializers; 743 bool has_initializers = decl_props == kHasInitializers;
730 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); 744 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers);
731 bool accept_OF = !has_initializers; 745 bool accept_OF = !has_initializers;
732 if (accept_IN && CheckInOrOf(accept_OF)) { 746 if (accept_IN && CheckInOrOf(accept_OF)) {
733 ParseExpression(true, CHECK_OK); 747 ParseExpression(true, CHECK_OK);
734 Expect(Token::RPAREN, CHECK_OK); 748 Expect(Token::RPAREN, CHECK_OK);
735 749
736 ParseStatement(CHECK_OK); 750 ParseSubStatement(CHECK_OK);
737 return Statement::Default(); 751 return Statement::Default();
738 } 752 }
739 } else { 753 } else {
740 Expression lhs = ParseExpression(false, CHECK_OK); 754 Expression lhs = ParseExpression(false, CHECK_OK);
741 is_let_identifier_expression = 755 is_let_identifier_expression =
742 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); 756 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
743 if (CheckInOrOf(lhs.IsIdentifier())) { 757 if (CheckInOrOf(lhs.IsIdentifier())) {
744 ParseExpression(true, CHECK_OK); 758 ParseExpression(true, CHECK_OK);
745 Expect(Token::RPAREN, CHECK_OK); 759 Expect(Token::RPAREN, CHECK_OK);
746 760
747 ParseStatement(CHECK_OK); 761 ParseSubStatement(CHECK_OK);
748 return Statement::Default(); 762 return Statement::Default();
749 } 763 }
750 } 764 }
751 } 765 }
752 766
753 // Parsed initializer at this point. 767 // Parsed initializer at this point.
754 // Detect attempts at 'let' declarations in sloppy mode. 768 // Detect attempts at 'let' declarations in sloppy mode.
755 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && 769 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) &&
756 is_let_identifier_expression) { 770 is_let_identifier_expression) {
757 ReportMessage("sloppy_lexical", NULL); 771 ReportMessage("sloppy_lexical", NULL);
758 *ok = false; 772 *ok = false;
759 return Statement::Default(); 773 return Statement::Default();
760 } 774 }
761 Expect(Token::SEMICOLON, CHECK_OK); 775 Expect(Token::SEMICOLON, CHECK_OK);
762 776
763 if (peek() != Token::SEMICOLON) { 777 if (peek() != Token::SEMICOLON) {
764 ParseExpression(true, CHECK_OK); 778 ParseExpression(true, CHECK_OK);
765 } 779 }
766 Expect(Token::SEMICOLON, CHECK_OK); 780 Expect(Token::SEMICOLON, CHECK_OK);
767 781
768 if (peek() != Token::RPAREN) { 782 if (peek() != Token::RPAREN) {
769 ParseExpression(true, CHECK_OK); 783 ParseExpression(true, CHECK_OK);
770 } 784 }
771 Expect(Token::RPAREN, CHECK_OK); 785 Expect(Token::RPAREN, CHECK_OK);
772 786
773 ParseStatement(ok); 787 ParseSubStatement(ok);
774 return Statement::Default(); 788 return Statement::Default();
775 } 789 }
776 790
777 791
778 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { 792 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) {
779 // ThrowStatement :: 793 // ThrowStatement ::
780 // 'throw' [no line terminator] Expression ';' 794 // 'throw' [no line terminator] Expression ';'
781 795
782 Expect(Token::THROW, CHECK_OK); 796 Expect(Token::THROW, CHECK_OK);
783 if (scanner()->HasAnyLineTerminatorBeforeNext()) { 797 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1039 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1026 ParseArguments(ok); 1040 ParseArguments(ok);
1027 1041
1028 return Expression::Default(); 1042 return Expression::Default();
1029 } 1043 }
1030 1044
1031 #undef CHECK_OK 1045 #undef CHECK_OK
1032 1046
1033 1047
1034 } } // v8::internal 1048 } } // v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698