OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 static int Precedence(Token::Value token, bool accept_IN) { | 290 static int Precedence(Token::Value token, bool accept_IN) { |
291 if (token == Token::IN && !accept_IN) | 291 if (token == Token::IN && !accept_IN) |
292 return 0; // 0 precedence will terminate binary expression parsing | 292 return 0; // 0 precedence will terminate binary expression parsing |
293 return Token::Precedence(token); | 293 return Token::Precedence(token); |
294 } | 294 } |
295 | 295 |
296 typename Traits::Type::Factory* factory() { | 296 typename Traits::Type::Factory* factory() { |
297 return function_state_->factory(); | 297 return function_state_->factory(); |
298 } | 298 } |
299 | 299 |
300 bool is_classic_mode() const { return scope_->is_classic_mode(); } | 300 bool is_sloppy_mode() const { return scope_->is_sloppy_mode(); } |
301 | 301 |
302 bool is_generator() const { return function_state_->is_generator(); } | 302 bool is_generator() const { return function_state_->is_generator(); } |
303 | 303 |
304 // Report syntax errors. | 304 // Report syntax errors. |
305 void ReportMessage(const char* message, Vector<const char*> args) { | 305 void ReportMessage(const char* message, Vector<const char*> args) { |
306 Scanner::Location source_location = scanner()->location(); | 306 Scanner::Location source_location = scanner()->location(); |
307 Traits::ReportMessageAt(source_location, message, args); | 307 Traits::ReportMessageAt(source_location, message, args); |
308 } | 308 } |
309 | 309 |
310 void ReportMessageAt(Scanner::Location location, const char* message) { | 310 void ReportMessageAt(Scanner::Location location, const char* message) { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 class PreParserScope { | 561 class PreParserScope { |
562 public: | 562 public: |
563 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) | 563 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) |
564 : scope_type_(scope_type) { | 564 : scope_type_(scope_type) { |
565 if (outer_scope) { | 565 if (outer_scope) { |
566 scope_inside_with_ = | 566 scope_inside_with_ = |
567 outer_scope->scope_inside_with_ || is_with_scope(); | 567 outer_scope->scope_inside_with_ || is_with_scope(); |
568 language_mode_ = outer_scope->language_mode(); | 568 language_mode_ = outer_scope->language_mode(); |
569 } else { | 569 } else { |
570 scope_inside_with_ = is_with_scope(); | 570 scope_inside_with_ = is_with_scope(); |
571 language_mode_ = CLASSIC_MODE; | 571 language_mode_ = SLOPPY_MODE; |
572 } | 572 } |
573 } | 573 } |
574 | 574 |
575 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 575 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
576 bool is_classic_mode() const { | 576 bool is_sloppy_mode() const { |
577 return language_mode() == CLASSIC_MODE; | 577 return language_mode() == SLOPPY_MODE; |
578 } | 578 } |
579 bool is_extended_mode() { | 579 bool is_extended_mode() { |
580 return language_mode() == EXTENDED_MODE; | 580 return language_mode() == EXTENDED_MODE; |
581 } | 581 } |
582 bool inside_with() const { | 582 bool inside_with() const { |
583 return scope_inside_with_; | 583 return scope_inside_with_; |
584 } | 584 } |
585 | 585 |
586 ScopeType type() { return scope_type_; } | 586 ScopeType type() { return scope_type_; } |
587 LanguageMode language_mode() const { return language_mode_; } | 587 LanguageMode language_mode() const { return language_mode_; } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 // during parsing. | 756 // during parsing. |
757 PreParseResult PreParseProgram() { | 757 PreParseResult PreParseProgram() { |
758 PreParserScope scope(scope_, GLOBAL_SCOPE); | 758 PreParserScope scope(scope_, GLOBAL_SCOPE); |
759 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 759 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
760 bool ok = true; | 760 bool ok = true; |
761 int start_position = scanner()->peek_location().beg_pos; | 761 int start_position = scanner()->peek_location().beg_pos; |
762 ParseSourceElements(Token::EOS, &ok); | 762 ParseSourceElements(Token::EOS, &ok); |
763 if (stack_overflow()) return kPreParseStackOverflow; | 763 if (stack_overflow()) return kPreParseStackOverflow; |
764 if (!ok) { | 764 if (!ok) { |
765 ReportUnexpectedToken(scanner()->current_token()); | 765 ReportUnexpectedToken(scanner()->current_token()); |
766 } else if (!scope_->is_classic_mode()) { | 766 } else if (!scope_->is_sloppy_mode()) { |
767 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); | 767 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); |
768 } | 768 } |
769 return kPreParseSuccess; | 769 return kPreParseSuccess; |
770 } | 770 } |
771 | 771 |
772 // Parses a single function literal, from the opening parentheses before | 772 // Parses a single function literal, from the opening parentheses before |
773 // parameters to the closing brace after the body. | 773 // parameters to the closing brace after the body. |
774 // Returns a FunctionEntry describing the body of the function in enough | 774 // Returns a FunctionEntry describing the body of the function in enough |
775 // detail that it can be lazily compiled. | 775 // detail that it can be lazily compiled. |
776 // The scanner is expected to have matched the "function" or "function*" | 776 // The scanner is expected to have matched the "function" or "function*" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 return ReportMessageAt(source_location, "unexpected_token_number"); | 967 return ReportMessageAt(source_location, "unexpected_token_number"); |
968 case Token::STRING: | 968 case Token::STRING: |
969 return ReportMessageAt(source_location, "unexpected_token_string"); | 969 return ReportMessageAt(source_location, "unexpected_token_string"); |
970 case Token::IDENTIFIER: | 970 case Token::IDENTIFIER: |
971 return ReportMessageAt(source_location, "unexpected_token_identifier"); | 971 return ReportMessageAt(source_location, "unexpected_token_identifier"); |
972 case Token::FUTURE_RESERVED_WORD: | 972 case Token::FUTURE_RESERVED_WORD: |
973 return ReportMessageAt(source_location, "unexpected_reserved"); | 973 return ReportMessageAt(source_location, "unexpected_reserved"); |
974 case Token::YIELD: | 974 case Token::YIELD: |
975 case Token::FUTURE_STRICT_RESERVED_WORD: | 975 case Token::FUTURE_STRICT_RESERVED_WORD: |
976 return ReportMessageAt(source_location, | 976 return ReportMessageAt(source_location, |
977 is_classic_mode() ? "unexpected_token_identifier" | 977 is_sloppy_mode() ? "unexpected_token_identifier" |
978 : "unexpected_strict_reserved"); | 978 : "unexpected_strict_reserved"); |
Michael Starzinger
2014/02/24 15:09:14
nit: Indentation is off.
| |
979 default: | 979 default: |
980 const char* name = Token::String(token); | 980 const char* name = Token::String(token); |
981 ASSERT(name != NULL); | 981 ASSERT(name != NULL); |
982 Traits::ReportMessageAt( | 982 Traits::ReportMessageAt( |
983 source_location, "unexpected_token", Vector<const char*>(&name, 1)); | 983 source_location, "unexpected_token", Vector<const char*>(&name, 1)); |
984 } | 984 } |
985 } | 985 } |
986 | 986 |
987 | 987 |
988 template<class Traits> | 988 template<class Traits> |
989 typename Traits::Type::Identifier ParserBase<Traits>::ParseIdentifier( | 989 typename Traits::Type::Identifier ParserBase<Traits>::ParseIdentifier( |
990 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | 990 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, |
991 bool* ok) { | 991 bool* ok) { |
992 Token::Value next = Next(); | 992 Token::Value next = Next(); |
993 if (next == Token::IDENTIFIER) { | 993 if (next == Token::IDENTIFIER) { |
994 typename Traits::Type::Identifier name = this->GetSymbol(scanner()); | 994 typename Traits::Type::Identifier name = this->GetSymbol(scanner()); |
995 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && | 995 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && |
996 !is_classic_mode() && this->IsEvalOrArguments(name)) { | 996 !is_sloppy_mode() && this->IsEvalOrArguments(name)) { |
997 ReportMessageAt(scanner()->location(), "strict_eval_arguments"); | 997 ReportMessageAt(scanner()->location(), "strict_eval_arguments"); |
998 *ok = false; | 998 *ok = false; |
999 } | 999 } |
1000 return name; | 1000 return name; |
1001 } else if (is_classic_mode() && (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1001 } else if (is_sloppy_mode() && (next == Token::FUTURE_STRICT_RESERVED_WORD || |
1002 (next == Token::YIELD && !is_generator()))) { | 1002 (next == Token::YIELD && !is_generator()))) { |
Michael Starzinger
2014/02/24 15:09:14
nit: Indentation is off.
| |
1003 return this->GetSymbol(scanner()); | 1003 return this->GetSymbol(scanner()); |
1004 } else { | 1004 } else { |
1005 this->ReportUnexpectedToken(next); | 1005 this->ReportUnexpectedToken(next); |
1006 *ok = false; | 1006 *ok = false; |
1007 return Traits::EmptyIdentifier(); | 1007 return Traits::EmptyIdentifier(); |
1008 } | 1008 } |
1009 } | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 template <class Traits> | 1012 template <class Traits> |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1251 old = finder_.AddNumber(scanner()->literal_ascii_string(), type); | 1251 old = finder_.AddNumber(scanner()->literal_ascii_string(), type); |
1252 } else if (scanner()->is_literal_ascii()) { | 1252 } else if (scanner()->is_literal_ascii()) { |
1253 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type); | 1253 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type); |
1254 } else { | 1254 } else { |
1255 old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type); | 1255 old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type); |
1256 } | 1256 } |
1257 PropertyKind old_type = static_cast<PropertyKind>(old); | 1257 PropertyKind old_type = static_cast<PropertyKind>(old); |
1258 if (HasConflict(old_type, type)) { | 1258 if (HasConflict(old_type, type)) { |
1259 if (IsDataDataConflict(old_type, type)) { | 1259 if (IsDataDataConflict(old_type, type)) { |
1260 // Both are data properties. | 1260 // Both are data properties. |
1261 if (language_mode_ == CLASSIC_MODE) return; | 1261 if (language_mode_ == SLOPPY_MODE) return; |
1262 parser()->ReportMessageAt(scanner()->location(), | 1262 parser()->ReportMessageAt(scanner()->location(), |
1263 "strict_duplicate_property"); | 1263 "strict_duplicate_property"); |
1264 } else if (IsDataAccessorConflict(old_type, type)) { | 1264 } else if (IsDataAccessorConflict(old_type, type)) { |
1265 // Both a data and an accessor property with the same name. | 1265 // Both a data and an accessor property with the same name. |
1266 parser()->ReportMessageAt(scanner()->location(), | 1266 parser()->ReportMessageAt(scanner()->location(), |
1267 "accessor_data_property"); | 1267 "accessor_data_property"); |
1268 } else { | 1268 } else { |
1269 ASSERT(IsAccessorAccessorConflict(old_type, type)); | 1269 ASSERT(IsAccessorAccessorConflict(old_type, type)); |
1270 // Both accessors of the same type. | 1270 // Both accessors of the same type. |
1271 parser()->ReportMessageAt(scanner()->location(), | 1271 parser()->ReportMessageAt(scanner()->location(), |
1272 "accessor_get_set"); | 1272 "accessor_get_set"); |
1273 } | 1273 } |
1274 *ok = false; | 1274 *ok = false; |
1275 } | 1275 } |
1276 } | 1276 } |
1277 | 1277 |
1278 | 1278 |
1279 } } // v8::internal | 1279 } } // v8::internal |
1280 | 1280 |
1281 #endif // V8_PREPARSER_H | 1281 #endif // V8_PREPARSER_H |
OLD | NEW |