| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 88 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
| 89 return pre_parser_->ParseV8Intrinsic(ok); | 89 return pre_parser_->ParseV8Intrinsic(ok); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 93 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
| 94 PreParserIdentifier name, Scanner::Location function_name_location, | 94 PreParserIdentifier name, Scanner::Location function_name_location, |
| 95 FunctionNameValidity function_name_validity, FunctionKind kind, | 95 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 96 int function_token_position, FunctionLiteral::FunctionType type, | 96 int function_token_position, FunctionLiteral::FunctionType type, |
| 97 LanguageMode language_mode, bool* ok) { | 97 LanguageMode language_mode, typesystem::TypeFlags type_flags, bool* ok) { |
| 98 return pre_parser_->ParseFunctionLiteral( | 98 return pre_parser_->ParseFunctionLiteral( |
| 99 name, function_name_location, function_name_validity, kind, | 99 name, function_name_location, function_name_validity, kind, |
| 100 function_token_position, type, language_mode, ok); | 100 function_token_position, type, language_mode, type_flags, ok); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 104 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 105 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 105 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
| 106 ParserRecorder* log, Scanner::BookmarkScope* bookmark) { | 106 ParserRecorder* log, Scanner::BookmarkScope* bookmark) { |
| 107 log_ = log; | 107 log_ = log; |
| 108 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 108 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 109 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 109 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); |
| 110 PreParserFactory top_factory(NULL); | 110 PreParserFactory top_factory(NULL); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 bool is_generator = Check(Token::MUL); | 412 bool is_generator = Check(Token::MUL); |
| 413 bool is_strict_reserved = false; | 413 bool is_strict_reserved = false; |
| 414 Identifier name = ParseIdentifierOrStrictReservedWord( | 414 Identifier name = ParseIdentifierOrStrictReservedWord( |
| 415 &is_strict_reserved, CHECK_OK); | 415 &is_strict_reserved, CHECK_OK); |
| 416 ParseFunctionLiteral(name, scanner()->location(), | 416 ParseFunctionLiteral(name, scanner()->location(), |
| 417 is_strict_reserved ? kFunctionNameIsStrictReserved | 417 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 418 : kFunctionNameValidityUnknown, | 418 : kFunctionNameValidityUnknown, |
| 419 is_generator ? FunctionKind::kGeneratorFunction | 419 is_generator ? FunctionKind::kGeneratorFunction |
| 420 : FunctionKind::kNormalFunction, | 420 : FunctionKind::kNormalFunction, |
| 421 pos, FunctionLiteral::kDeclaration, language_mode(), | 421 pos, FunctionLiteral::kDeclaration, language_mode(), |
| 422 CHECK_OK); | 422 typesystem::kAllowSignature, CHECK_OK); |
| 423 return Statement::FunctionDeclaration(); | 423 return Statement::FunctionDeclaration(); |
| 424 } | 424 } |
| 425 | 425 |
| 426 | 426 |
| 427 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { | 427 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
| 428 Expect(Token::CLASS, CHECK_OK); | 428 Expect(Token::CLASS, CHECK_OK); |
| 429 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 429 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 430 ReportMessage(MessageTemplate::kSloppyLexical); | 430 ReportMessage(MessageTemplate::kSloppyLexical); |
| 431 *ok = false; | 431 *ok = false; |
| 432 return Statement::Default(); | 432 return Statement::Default(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 539 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 540 | 540 |
| 541 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 541 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| 542 if (lexical) { | 542 if (lexical) { |
| 543 ValidateLetPattern(&pattern_classifier, CHECK_OK); | 543 ValidateLetPattern(&pattern_classifier, CHECK_OK); |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 | 546 |
| 547 is_pattern = pattern.IsObjectLiteral() || pattern.IsArrayLiteral(); | 547 is_pattern = pattern.IsObjectLiteral() || pattern.IsArrayLiteral(); |
| 548 | 548 |
| 549 // Optional type annotation. | 549 // Parse optional type annotation. |
| 550 if (scope_->typed() && Check(Token::COLON)) { | 550 if (scope_->typed() && Check(Token::COLON)) { // Braces required here. |
| 551 ParseValidType(CHECK_OK); | 551 ParseValidType(CHECK_OK); |
| 552 } | 552 } |
| 553 | 553 |
| 554 Scanner::Location variable_loc = scanner()->location(); | 554 Scanner::Location variable_loc = scanner()->location(); |
| 555 nvars++; | 555 nvars++; |
| 556 if (Check(Token::ASSIGN)) { | 556 if (Check(Token::ASSIGN)) { |
| 557 ExpressionClassifier classifier(this); | 557 ExpressionClassifier classifier(this); |
| 558 ParseAssignmentExpression(var_context != kForStatement, &classifier, | 558 ParseAssignmentExpression(var_context != kForStatement, &classifier, |
| 559 CHECK_OK); | 559 CHECK_OK); |
| 560 ValidateExpression(&classifier, CHECK_OK); | 560 ValidateExpression(&classifier, CHECK_OK); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 if (!*ok) return Expression::Default(); \ | 1002 if (!*ok) return Expression::Default(); \ |
| 1003 ((void)0 | 1003 ((void)0 |
| 1004 #define DUMMY ) // to make indentation work | 1004 #define DUMMY ) // to make indentation work |
| 1005 #undef DUMMY | 1005 #undef DUMMY |
| 1006 | 1006 |
| 1007 | 1007 |
| 1008 PreParser::Expression PreParser::ParseFunctionLiteral( | 1008 PreParser::Expression PreParser::ParseFunctionLiteral( |
| 1009 Identifier function_name, Scanner::Location function_name_location, | 1009 Identifier function_name, Scanner::Location function_name_location, |
| 1010 FunctionNameValidity function_name_validity, FunctionKind kind, | 1010 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 1011 int function_token_pos, FunctionLiteral::FunctionType function_type, | 1011 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 1012 LanguageMode language_mode, bool* ok) { | 1012 LanguageMode language_mode, typesystem::TypeFlags type_flags, bool* ok) { |
| 1013 // Function :: | 1013 // Function :: |
| 1014 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1014 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 1015 | 1015 |
| 1016 // Parse function body. | 1016 // Parse function body. |
| 1017 bool outer_is_script_scope = scope_->is_script_scope(); | 1017 bool outer_is_script_scope = scope_->is_script_scope(); |
| 1018 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 1018 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); |
| 1019 function_scope->SetLanguageMode(language_mode); | 1019 function_scope->SetLanguageMode(language_mode); |
| 1020 PreParserFactory factory(NULL); | 1020 PreParserFactory factory(NULL); |
| 1021 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1021 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 1022 &factory); | 1022 &factory); |
| 1023 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1023 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 1024 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 1024 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 1025 | 1025 |
| 1026 // Parse optional type parameters. |
| 1027 if (scope_->typed() && !(type_flags & typesystem::kDisallowTypeParameters) && |
| 1028 peek() == Token::LT) { // Braces required here. |
| 1029 ParseTypeParameters(CHECK_OK); |
| 1030 } |
| 1031 |
| 1026 Expect(Token::LPAREN, CHECK_OK); | 1032 Expect(Token::LPAREN, CHECK_OK); |
| 1027 int start_position = scanner()->location().beg_pos; | 1033 int start_position = scanner()->location().beg_pos; |
| 1028 function_scope->set_start_position(start_position); | 1034 function_scope->set_start_position(start_position); |
| 1029 PreParserFormalParameters formals(function_scope); | 1035 PreParserFormalParameters formals(function_scope); |
| 1030 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 1036 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
| 1031 Expect(Token::RPAREN, CHECK_OK); | 1037 Expect(Token::RPAREN, CHECK_OK); |
| 1032 int formals_end_position = scanner()->location().end_pos; | 1038 int formals_end_position = scanner()->location().end_pos; |
| 1033 | 1039 |
| 1034 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, | 1040 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, |
| 1035 formals_end_position, CHECK_OK); | 1041 formals_end_position, CHECK_OK); |
| 1036 | 1042 |
| 1037 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 1043 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
| 1038 // and lazy compilation. | 1044 // and lazy compilation. |
| 1039 bool is_lazily_parsed = | 1045 bool is_lazily_parsed = |
| 1040 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); | 1046 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); |
| 1041 parenthesized_function_ = false; | 1047 parenthesized_function_ = false; |
| 1042 | 1048 |
| 1049 // Parse optional type annotation. |
| 1050 if (scope_->typed() && Check(Token::COLON)) { // Braces required here. |
| 1051 ParseValidType(CHECK_OK); |
| 1052 } |
| 1053 |
| 1054 // Allow for a function signature (i.e., a literal without body). |
| 1055 if (peek() != Token::LBRACE && scope_->typed() && |
| 1056 (type_flags & typesystem::kAllowSignature)) { |
| 1057 ExpectSemicolon(CHECK_OK); |
| 1058 return this->EmptyExpression(); |
| 1059 } |
| 1060 |
| 1043 Expect(Token::LBRACE, CHECK_OK); | 1061 Expect(Token::LBRACE, CHECK_OK); |
| 1044 if (is_lazily_parsed) { | 1062 if (is_lazily_parsed) { |
| 1045 ParseLazyFunctionLiteralBody(CHECK_OK); | 1063 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1046 } else { | 1064 } else { |
| 1047 ParseStatementList(Token::RBRACE, CHECK_OK); | 1065 ParseStatementList(Token::RBRACE, CHECK_OK); |
| 1048 } | 1066 } |
| 1049 Expect(Token::RBRACE, CHECK_OK); | 1067 Expect(Token::RBRACE, CHECK_OK); |
| 1050 | 1068 |
| 1051 // Parsing the body may change the language mode in our scope. | 1069 // Parsing the body may change the language mode in our scope. |
| 1052 language_mode = function_scope->language_mode(); | 1070 language_mode = function_scope->language_mode(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 Expect(Token::RBRACE, CHECK_OK); | 1194 Expect(Token::RBRACE, CHECK_OK); |
| 1177 return PreParserExpression::Default(); | 1195 return PreParserExpression::Default(); |
| 1178 } | 1196 } |
| 1179 } | 1197 } |
| 1180 | 1198 |
| 1181 #undef CHECK_OK | 1199 #undef CHECK_OK |
| 1182 | 1200 |
| 1183 | 1201 |
| 1184 } // namespace internal | 1202 } // namespace internal |
| 1185 } // namespace v8 | 1203 } // namespace v8 |
| OLD | NEW |