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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return Statement::Default(); | 298 return Statement::Default(); |
299 } | 299 } |
300 return ParseSubStatement(allow_function, ok); | 300 return ParseSubStatement(allow_function, ok); |
301 } | 301 } |
302 | 302 |
303 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 303 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
304 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 304 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
305 (legacy && allow_harmony_restrictive_declarations())) { | 305 (legacy && allow_harmony_restrictive_declarations())) { |
306 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 306 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
307 } else { | 307 } else { |
308 Scope* body_scope = NewScope(BLOCK_SCOPE); | 308 BlockState block_state(&scope_state_); |
309 BlockState block_state(&scope_state_, body_scope); | |
310 return ParseFunctionDeclaration(ok); | 309 return ParseFunctionDeclaration(ok); |
311 } | 310 } |
312 } | 311 } |
313 | 312 |
314 PreParser::Statement PreParser::ParseSubStatement( | 313 PreParser::Statement PreParser::ParseSubStatement( |
315 AllowLabelledFunctionStatement allow_function, bool* ok) { | 314 AllowLabelledFunctionStatement allow_function, bool* ok) { |
316 // Statement :: | 315 // Statement :: |
317 // Block | 316 // Block |
318 // VariableStatement | 317 // VariableStatement |
319 // EmptyStatement | 318 // EmptyStatement |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, | 468 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, |
470 pos, CHECK_OK); | 469 pos, CHECK_OK); |
471 return Statement::Default(); | 470 return Statement::Default(); |
472 } | 471 } |
473 | 472 |
474 | 473 |
475 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 474 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
476 // Block :: | 475 // Block :: |
477 // '{' StatementList '}' | 476 // '{' StatementList '}' |
478 | 477 |
479 Scope* block_scope = NewScope(BLOCK_SCOPE); | |
480 Expect(Token::LBRACE, CHECK_OK); | 478 Expect(Token::LBRACE, CHECK_OK); |
481 Statement final = Statement::Default(); | 479 Statement final = Statement::Default(); |
482 { | 480 { |
483 BlockState block_state(&scope_state_, block_scope); | 481 BlockState block_state(&scope_state_); |
484 while (peek() != Token::RBRACE) { | 482 while (peek() != Token::RBRACE) { |
485 final = ParseStatementListItem(CHECK_OK); | 483 final = ParseStatementListItem(CHECK_OK); |
486 } | 484 } |
487 } | 485 } |
488 Expect(Token::RBRACE, ok); | 486 Expect(Token::RBRACE, ok); |
489 return final; | 487 return final; |
490 } | 488 } |
491 | 489 |
492 | 490 |
493 PreParser::Statement PreParser::ParseVariableStatement( | 491 PreParser::Statement PreParser::ParseVariableStatement( |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 | 797 |
800 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 798 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
801 // SwitchStatement :: | 799 // SwitchStatement :: |
802 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 800 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
803 | 801 |
804 Expect(Token::SWITCH, CHECK_OK); | 802 Expect(Token::SWITCH, CHECK_OK); |
805 Expect(Token::LPAREN, CHECK_OK); | 803 Expect(Token::LPAREN, CHECK_OK); |
806 ParseExpression(true, CHECK_OK); | 804 ParseExpression(true, CHECK_OK); |
807 Expect(Token::RPAREN, CHECK_OK); | 805 Expect(Token::RPAREN, CHECK_OK); |
808 | 806 |
809 Scope* cases_scope = NewScope(BLOCK_SCOPE); | |
810 { | 807 { |
811 BlockState cases_block_state(&scope_state_, cases_scope); | 808 BlockState cases_block_state(&scope_state_); |
812 Expect(Token::LBRACE, CHECK_OK); | 809 Expect(Token::LBRACE, CHECK_OK); |
813 Token::Value token = peek(); | 810 Token::Value token = peek(); |
814 while (token != Token::RBRACE) { | 811 while (token != Token::RBRACE) { |
815 if (token == Token::CASE) { | 812 if (token == Token::CASE) { |
816 Expect(Token::CASE, CHECK_OK); | 813 Expect(Token::CASE, CHECK_OK); |
817 ParseExpression(true, CHECK_OK); | 814 ParseExpression(true, CHECK_OK); |
818 } else { | 815 } else { |
819 Expect(Token::DEFAULT, CHECK_OK); | 816 Expect(Token::DEFAULT, CHECK_OK); |
820 } | 817 } |
821 Expect(Token::COLON, CHECK_OK); | 818 Expect(Token::COLON, CHECK_OK); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 ParseScopedStatement(true, ok); | 857 ParseScopedStatement(true, ok); |
861 return Statement::Default(); | 858 return Statement::Default(); |
862 } | 859 } |
863 | 860 |
864 | 861 |
865 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 862 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
866 // ForStatement :: | 863 // ForStatement :: |
867 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 864 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
868 | 865 |
869 // Create an in-between scope for let-bound iteration variables. | 866 // Create an in-between scope for let-bound iteration variables. |
870 Scope* for_scope = NewScope(BLOCK_SCOPE); | |
871 bool has_lexical = false; | 867 bool has_lexical = false; |
872 | 868 |
873 BlockState block_state(&scope_state_, for_scope); | 869 BlockState block_state(&scope_state_); |
874 Expect(Token::FOR, CHECK_OK); | 870 Expect(Token::FOR, CHECK_OK); |
875 Expect(Token::LPAREN, CHECK_OK); | 871 Expect(Token::LPAREN, CHECK_OK); |
876 if (peek() != Token::SEMICOLON) { | 872 if (peek() != Token::SEMICOLON) { |
877 ForEachStatement::VisitMode mode; | 873 ForEachStatement::VisitMode mode; |
878 if (peek() == Token::VAR || peek() == Token::CONST || | 874 if (peek() == Token::VAR || peek() == Token::CONST || |
879 (peek() == Token::LET && IsNextLetKeyword())) { | 875 (peek() == Token::LET && IsNextLetKeyword())) { |
880 int decl_count; | 876 int decl_count; |
881 bool is_lexical; | 877 bool is_lexical; |
882 bool is_binding_pattern; | 878 bool is_binding_pattern; |
883 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 879 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 | 946 |
951 if (mode == ForEachStatement::ITERATE) { | 947 if (mode == ForEachStatement::ITERATE) { |
952 ExpressionClassifier classifier(this); | 948 ExpressionClassifier classifier(this); |
953 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 949 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
954 RewriteNonPattern(&classifier, CHECK_OK); | 950 RewriteNonPattern(&classifier, CHECK_OK); |
955 } else { | 951 } else { |
956 ParseExpression(true, CHECK_OK); | 952 ParseExpression(true, CHECK_OK); |
957 } | 953 } |
958 | 954 |
959 Expect(Token::RPAREN, CHECK_OK); | 955 Expect(Token::RPAREN, CHECK_OK); |
960 Scope* body_scope = NewScope(BLOCK_SCOPE); | |
961 { | 956 { |
962 BlockState block_state(&scope_state_, body_scope); | 957 BlockState block_state(&scope_state_); |
963 ParseScopedStatement(true, CHECK_OK); | 958 ParseScopedStatement(true, CHECK_OK); |
964 } | 959 } |
965 return Statement::Default(); | 960 return Statement::Default(); |
966 } | 961 } |
967 } | 962 } |
968 } | 963 } |
969 | 964 |
970 // Parsed initializer at this point. | 965 // Parsed initializer at this point. |
971 Expect(Token::SEMICOLON, CHECK_OK); | 966 Expect(Token::SEMICOLON, CHECK_OK); |
972 | 967 |
973 // If there are let bindings, then condition and the next statement of the | 968 // If there are let bindings, then condition and the next statement of the |
974 // for loop must be parsed in a new scope. | 969 // for loop must be parsed in a new scope. |
975 Scope* inner_scope = scope(); | 970 Scope* inner_scope = scope(); |
976 if (has_lexical) inner_scope = NewScopeWithParent(for_scope, BLOCK_SCOPE); | 971 // TODO(verwaest): Allocate this through a ScopeState as well. |
| 972 if (has_lexical) inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE); |
977 | 973 |
978 { | 974 { |
979 BlockState block_state(&scope_state_, inner_scope); | 975 BlockState block_state(&scope_state_, inner_scope); |
980 | 976 |
981 if (peek() != Token::SEMICOLON) { | 977 if (peek() != Token::SEMICOLON) { |
982 ParseExpression(true, CHECK_OK); | 978 ParseExpression(true, CHECK_OK); |
983 } | 979 } |
984 Expect(Token::SEMICOLON, CHECK_OK); | 980 Expect(Token::SEMICOLON, CHECK_OK); |
985 | 981 |
986 if (peek() != Token::RPAREN) { | 982 if (peek() != Token::RPAREN) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 Scope* catch_scope = NewScope(CATCH_SCOPE); | 1040 Scope* catch_scope = NewScope(CATCH_SCOPE); |
1045 ExpressionClassifier pattern_classifier(this); | 1041 ExpressionClassifier pattern_classifier(this); |
1046 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 1042 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
1047 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 1043 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
1048 Expect(Token::RPAREN, CHECK_OK); | 1044 Expect(Token::RPAREN, CHECK_OK); |
1049 { | 1045 { |
1050 CollectExpressionsInTailPositionToListScope | 1046 CollectExpressionsInTailPositionToListScope |
1051 collect_tail_call_expressions_scope( | 1047 collect_tail_call_expressions_scope( |
1052 function_state_, &tail_call_expressions_in_catch_block); | 1048 function_state_, &tail_call_expressions_in_catch_block); |
1053 BlockState block_state(&scope_state_, catch_scope); | 1049 BlockState block_state(&scope_state_, catch_scope); |
1054 Scope* block_scope = NewScope(BLOCK_SCOPE); | |
1055 { | 1050 { |
1056 BlockState block_state(&scope_state_, block_scope); | 1051 BlockState block_state(&scope_state_); |
1057 ParseBlock(CHECK_OK); | 1052 ParseBlock(CHECK_OK); |
1058 } | 1053 } |
1059 } | 1054 } |
1060 catch_block_exists = true; | 1055 catch_block_exists = true; |
1061 tok = peek(); | 1056 tok = peek(); |
1062 } | 1057 } |
1063 if (tok == Token::FINALLY) { | 1058 if (tok == Token::FINALLY) { |
1064 Consume(Token::FINALLY); | 1059 Consume(Token::FINALLY); |
1065 ParseBlock(CHECK_OK); | 1060 ParseBlock(CHECK_OK); |
1066 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && | 1061 if (FLAG_harmony_explicit_tailcalls && catch_block_exists && |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 *ok = false; | 1216 *ok = false; |
1222 return EmptyExpression(); | 1217 return EmptyExpression(); |
1223 } | 1218 } |
1224 if (IsEvalOrArguments(name)) { | 1219 if (IsEvalOrArguments(name)) { |
1225 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 1220 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
1226 *ok = false; | 1221 *ok = false; |
1227 return EmptyExpression(); | 1222 return EmptyExpression(); |
1228 } | 1223 } |
1229 | 1224 |
1230 LanguageMode class_language_mode = language_mode(); | 1225 LanguageMode class_language_mode = language_mode(); |
1231 Scope* scope = NewScope(BLOCK_SCOPE); | 1226 BlockState block_state(&scope_state_); |
1232 BlockState block_state(&scope_state_, scope); | 1227 scope()->SetLanguageMode( |
1233 this->scope()->SetLanguageMode( | |
1234 static_cast<LanguageMode>(class_language_mode | STRICT)); | 1228 static_cast<LanguageMode>(class_language_mode | STRICT)); |
1235 // TODO(marja): Make PreParser use scope names too. | 1229 // TODO(marja): Make PreParser use scope names too. |
1236 // this->scope()->SetScopeName(name); | 1230 // this->scope()->SetScopeName(name); |
1237 | 1231 |
1238 bool has_extends = Check(Token::EXTENDS); | 1232 bool has_extends = Check(Token::EXTENDS); |
1239 if (has_extends) { | 1233 if (has_extends) { |
1240 ExpressionClassifier extends_classifier(this); | 1234 ExpressionClassifier extends_classifier(this); |
1241 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 1235 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
1242 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); | 1236 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
1243 ValidateExpression(&extends_classifier, CHECK_OK); | 1237 ValidateExpression(&extends_classifier, CHECK_OK); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 | 1312 |
1319 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1313 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
1320 } | 1314 } |
1321 | 1315 |
1322 #undef CHECK_OK | 1316 #undef CHECK_OK |
1323 #undef CHECK_OK_CUSTOM | 1317 #undef CHECK_OK_CUSTOM |
1324 | 1318 |
1325 | 1319 |
1326 } // namespace internal | 1320 } // namespace internal |
1327 } // namespace v8 | 1321 } // namespace v8 |
OLD | NEW |