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