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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return Statement::Default(); | 300 return Statement::Default(); |
301 } | 301 } |
302 return ParseSubStatement(allow_function, ok); | 302 return ParseSubStatement(allow_function, ok); |
303 } | 303 } |
304 | 304 |
305 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 305 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
306 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 306 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
307 (legacy && allow_harmony_restrictive_declarations())) { | 307 (legacy && allow_harmony_restrictive_declarations())) { |
308 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 308 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
309 } else { | 309 } else { |
310 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); | 310 Scope* body_scope = NewScope(BLOCK_SCOPE); |
311 BlockState block_state(&scope_state_, body_scope); | 311 BlockState block_state(&scope_state_, body_scope); |
312 return ParseFunctionDeclaration(ok); | 312 return ParseFunctionDeclaration(ok); |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 PreParser::Statement PreParser::ParseSubStatement( | 316 PreParser::Statement PreParser::ParseSubStatement( |
317 AllowLabelledFunctionStatement allow_function, bool* ok) { | 317 AllowLabelledFunctionStatement allow_function, bool* ok) { |
318 // Statement :: | 318 // Statement :: |
319 // Block | 319 // Block |
320 // VariableStatement | 320 // VariableStatement |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, | 471 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, |
472 pos, CHECK_OK); | 472 pos, CHECK_OK); |
473 return Statement::Default(); | 473 return Statement::Default(); |
474 } | 474 } |
475 | 475 |
476 | 476 |
477 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 477 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
478 // Block :: | 478 // Block :: |
479 // '{' StatementList '}' | 479 // '{' StatementList '}' |
480 | 480 |
481 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); | 481 Scope* block_scope = NewScope(BLOCK_SCOPE); |
482 Expect(Token::LBRACE, CHECK_OK); | 482 Expect(Token::LBRACE, CHECK_OK); |
483 Statement final = Statement::Default(); | 483 Statement final = Statement::Default(); |
484 { | 484 { |
485 BlockState block_state(&scope_state_, block_scope); | 485 BlockState block_state(&scope_state_, block_scope); |
486 while (peek() != Token::RBRACE) { | 486 while (peek() != Token::RBRACE) { |
487 final = ParseStatementListItem(CHECK_OK); | 487 final = ParseStatementListItem(CHECK_OK); |
488 } | 488 } |
489 } | 489 } |
490 Expect(Token::RBRACE, ok); | 490 Expect(Token::RBRACE, ok); |
491 return final; | 491 return final; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 Expect(Token::WITH, CHECK_OK); | 785 Expect(Token::WITH, CHECK_OK); |
786 if (is_strict(language_mode())) { | 786 if (is_strict(language_mode())) { |
787 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); | 787 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); |
788 *ok = false; | 788 *ok = false; |
789 return Statement::Default(); | 789 return Statement::Default(); |
790 } | 790 } |
791 Expect(Token::LPAREN, CHECK_OK); | 791 Expect(Token::LPAREN, CHECK_OK); |
792 ParseExpression(true, CHECK_OK); | 792 ParseExpression(true, CHECK_OK); |
793 Expect(Token::RPAREN, CHECK_OK); | 793 Expect(Token::RPAREN, CHECK_OK); |
794 | 794 |
795 Scope* with_scope = NewScope(scope(), WITH_SCOPE); | 795 Scope* with_scope = NewScope(WITH_SCOPE); |
796 BlockState block_state(&scope_state_, with_scope); | 796 BlockState block_state(&scope_state_, with_scope); |
797 ParseScopedStatement(true, CHECK_OK); | 797 ParseScopedStatement(true, CHECK_OK); |
798 return Statement::Default(); | 798 return Statement::Default(); |
799 } | 799 } |
800 | 800 |
801 | 801 |
802 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 802 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
803 // SwitchStatement :: | 803 // SwitchStatement :: |
804 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 804 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
805 | 805 |
806 Expect(Token::SWITCH, CHECK_OK); | 806 Expect(Token::SWITCH, CHECK_OK); |
807 Expect(Token::LPAREN, CHECK_OK); | 807 Expect(Token::LPAREN, CHECK_OK); |
808 ParseExpression(true, CHECK_OK); | 808 ParseExpression(true, CHECK_OK); |
809 Expect(Token::RPAREN, CHECK_OK); | 809 Expect(Token::RPAREN, CHECK_OK); |
810 | 810 |
811 Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE); | 811 Scope* cases_scope = NewScope(BLOCK_SCOPE); |
812 { | 812 { |
813 BlockState cases_block_state(&scope_state_, cases_scope); | 813 BlockState cases_block_state(&scope_state_, cases_scope); |
814 Expect(Token::LBRACE, CHECK_OK); | 814 Expect(Token::LBRACE, CHECK_OK); |
815 Token::Value token = peek(); | 815 Token::Value token = peek(); |
816 while (token != Token::RBRACE) { | 816 while (token != Token::RBRACE) { |
817 if (token == Token::CASE) { | 817 if (token == Token::CASE) { |
818 Expect(Token::CASE, CHECK_OK); | 818 Expect(Token::CASE, CHECK_OK); |
819 ParseExpression(true, CHECK_OK); | 819 ParseExpression(true, CHECK_OK); |
820 } else { | 820 } else { |
821 Expect(Token::DEFAULT, CHECK_OK); | 821 Expect(Token::DEFAULT, CHECK_OK); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 ParseScopedStatement(true, ok); | 862 ParseScopedStatement(true, ok); |
863 return Statement::Default(); | 863 return Statement::Default(); |
864 } | 864 } |
865 | 865 |
866 | 866 |
867 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 867 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
868 // ForStatement :: | 868 // ForStatement :: |
869 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 869 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
870 | 870 |
871 // Create an in-between scope for let-bound iteration variables. | 871 // Create an in-between scope for let-bound iteration variables. |
872 Scope* for_scope = NewScope(scope(), BLOCK_SCOPE); | 872 Scope* for_scope = NewScope(BLOCK_SCOPE); |
873 bool has_lexical = false; | 873 bool has_lexical = false; |
874 | 874 |
875 BlockState block_state(&scope_state_, for_scope); | 875 BlockState block_state(&scope_state_, for_scope); |
876 Expect(Token::FOR, CHECK_OK); | 876 Expect(Token::FOR, CHECK_OK); |
877 Expect(Token::LPAREN, CHECK_OK); | 877 Expect(Token::LPAREN, CHECK_OK); |
878 if (peek() != Token::SEMICOLON) { | 878 if (peek() != Token::SEMICOLON) { |
879 ForEachStatement::VisitMode mode; | 879 ForEachStatement::VisitMode mode; |
880 if (peek() == Token::VAR || peek() == Token::CONST || | 880 if (peek() == Token::VAR || peek() == Token::CONST || |
881 (peek() == Token::LET && IsNextLetKeyword())) { | 881 (peek() == Token::LET && IsNextLetKeyword())) { |
882 int decl_count; | 882 int decl_count; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 | 952 |
953 if (mode == ForEachStatement::ITERATE) { | 953 if (mode == ForEachStatement::ITERATE) { |
954 ExpressionClassifier classifier(this); | 954 ExpressionClassifier classifier(this); |
955 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 955 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
956 RewriteNonPattern(&classifier, CHECK_OK); | 956 RewriteNonPattern(&classifier, CHECK_OK); |
957 } else { | 957 } else { |
958 ParseExpression(true, CHECK_OK); | 958 ParseExpression(true, CHECK_OK); |
959 } | 959 } |
960 | 960 |
961 Expect(Token::RPAREN, CHECK_OK); | 961 Expect(Token::RPAREN, CHECK_OK); |
962 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); | 962 Scope* body_scope = NewScope(BLOCK_SCOPE); |
963 { | 963 { |
964 BlockState block_state(&scope_state_, body_scope); | 964 BlockState block_state(&scope_state_, body_scope); |
965 ParseScopedStatement(true, CHECK_OK); | 965 ParseScopedStatement(true, CHECK_OK); |
966 } | 966 } |
967 return Statement::Default(); | 967 return Statement::Default(); |
968 } | 968 } |
969 } | 969 } |
970 } | 970 } |
971 | 971 |
972 // Parsed initializer at this point. | 972 // Parsed initializer at this point. |
973 Expect(Token::SEMICOLON, CHECK_OK); | 973 Expect(Token::SEMICOLON, CHECK_OK); |
974 | 974 |
975 // If there are let bindings, then condition and the next statement of the | 975 // If there are let bindings, then condition and the next statement of the |
976 // for loop must be parsed in a new scope. | 976 // for loop must be parsed in a new scope. |
977 Scope* inner_scope = scope(); | 977 Scope* inner_scope = scope(); |
978 if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE); | 978 if (has_lexical) inner_scope = NewScopeWithParent(for_scope, BLOCK_SCOPE); |
979 | 979 |
980 { | 980 { |
981 BlockState block_state(&scope_state_, inner_scope); | 981 BlockState block_state(&scope_state_, inner_scope); |
982 | 982 |
983 if (peek() != Token::SEMICOLON) { | 983 if (peek() != Token::SEMICOLON) { |
984 ParseExpression(true, CHECK_OK); | 984 ParseExpression(true, CHECK_OK); |
985 } | 985 } |
986 Expect(Token::SEMICOLON, CHECK_OK); | 986 Expect(Token::SEMICOLON, CHECK_OK); |
987 | 987 |
988 if (peek() != Token::RPAREN) { | 988 if (peek() != Token::RPAREN) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 if (tok != Token::CATCH && tok != Token::FINALLY) { | 1036 if (tok != Token::CATCH && tok != Token::FINALLY) { |
1037 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); | 1037 ReportMessageAt(scanner()->location(), MessageTemplate::kNoCatchOrFinally); |
1038 *ok = false; | 1038 *ok = false; |
1039 return Statement::Default(); | 1039 return Statement::Default(); |
1040 } | 1040 } |
1041 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); | 1041 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); |
1042 bool catch_block_exists = false; | 1042 bool catch_block_exists = false; |
1043 if (tok == Token::CATCH) { | 1043 if (tok == Token::CATCH) { |
1044 Consume(Token::CATCH); | 1044 Consume(Token::CATCH); |
1045 Expect(Token::LPAREN, CHECK_OK); | 1045 Expect(Token::LPAREN, CHECK_OK); |
1046 Scope* catch_scope = NewScope(scope(), CATCH_SCOPE); | 1046 Scope* catch_scope = NewScope(CATCH_SCOPE); |
1047 ExpressionClassifier pattern_classifier(this); | 1047 ExpressionClassifier pattern_classifier(this); |
1048 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 1048 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
1049 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 1049 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
1050 Expect(Token::RPAREN, CHECK_OK); | 1050 Expect(Token::RPAREN, CHECK_OK); |
1051 { | 1051 { |
1052 CollectExpressionsInTailPositionToListScope | 1052 CollectExpressionsInTailPositionToListScope |
1053 collect_tail_call_expressions_scope( | 1053 collect_tail_call_expressions_scope( |
1054 function_state_, &tail_call_expressions_in_catch_block); | 1054 function_state_, &tail_call_expressions_in_catch_block); |
1055 BlockState block_state(&scope_state_, catch_scope); | 1055 BlockState block_state(&scope_state_, catch_scope); |
1056 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); | 1056 Scope* block_scope = NewScope(BLOCK_SCOPE); |
1057 { | 1057 { |
1058 BlockState block_state(&scope_state_, block_scope); | 1058 BlockState block_state(&scope_state_, block_scope); |
1059 ParseBlock(CHECK_OK); | 1059 ParseBlock(CHECK_OK); |
1060 } | 1060 } |
1061 } | 1061 } |
1062 catch_block_exists = true; | 1062 catch_block_exists = true; |
1063 tok = peek(); | 1063 tok = peek(); |
1064 } | 1064 } |
1065 if (tok == Token::FINALLY) { | 1065 if (tok == Token::FINALLY) { |
1066 Consume(Token::FINALLY); | 1066 Consume(Token::FINALLY); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 *ok = false; | 1224 *ok = false; |
1225 return EmptyExpression(); | 1225 return EmptyExpression(); |
1226 } | 1226 } |
1227 if (IsEvalOrArguments(name)) { | 1227 if (IsEvalOrArguments(name)) { |
1228 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 1228 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
1229 *ok = false; | 1229 *ok = false; |
1230 return EmptyExpression(); | 1230 return EmptyExpression(); |
1231 } | 1231 } |
1232 | 1232 |
1233 LanguageMode class_language_mode = language_mode(); | 1233 LanguageMode class_language_mode = language_mode(); |
1234 Scope* scope = NewScope(this->scope(), BLOCK_SCOPE); | 1234 Scope* scope = NewScope(BLOCK_SCOPE); |
1235 BlockState block_state(&scope_state_, scope); | 1235 BlockState block_state(&scope_state_, scope); |
1236 this->scope()->SetLanguageMode( | 1236 this->scope()->SetLanguageMode( |
1237 static_cast<LanguageMode>(class_language_mode | STRICT)); | 1237 static_cast<LanguageMode>(class_language_mode | STRICT)); |
1238 // TODO(marja): Make PreParser use scope names too. | 1238 // TODO(marja): Make PreParser use scope names too. |
1239 // this->scope()->SetScopeName(name); | 1239 // this->scope()->SetScopeName(name); |
1240 | 1240 |
1241 bool has_extends = Check(Token::EXTENDS); | 1241 bool has_extends = Check(Token::EXTENDS); |
1242 if (has_extends) { | 1242 if (has_extends) { |
1243 ExpressionClassifier extends_classifier(this); | 1243 ExpressionClassifier extends_classifier(this); |
1244 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 1244 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 | 1321 |
1322 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1322 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
1323 } | 1323 } |
1324 | 1324 |
1325 #undef CHECK_OK | 1325 #undef CHECK_OK |
1326 #undef CHECK_OK_CUSTOM | 1326 #undef CHECK_OK_CUSTOM |
1327 | 1327 |
1328 | 1328 |
1329 } // namespace internal | 1329 } // namespace internal |
1330 } // namespace v8 | 1330 } // namespace v8 |
OLD | NEW |