Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/preparser.h

Issue 156423005: Move ParseRegexpLiteral to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review (ulan) Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // whether it is strict mode future reserved. 218 // whether it is strict mode future reserved.
219 typename Traits::IdentifierType ParseIdentifierOrStrictReservedWord( 219 typename Traits::IdentifierType ParseIdentifierOrStrictReservedWord(
220 bool* is_strict_reserved, 220 bool* is_strict_reserved,
221 bool* ok); 221 bool* ok);
222 typename Traits::IdentifierType ParseIdentifierName(bool* ok); 222 typename Traits::IdentifierType ParseIdentifierName(bool* ok);
223 // Parses an identifier and determines whether or not it is 'get' or 'set'. 223 // Parses an identifier and determines whether or not it is 'get' or 'set'.
224 typename Traits::IdentifierType ParseIdentifierNameOrGetOrSet(bool* is_get, 224 typename Traits::IdentifierType ParseIdentifierNameOrGetOrSet(bool* is_get,
225 bool* is_set, 225 bool* is_set,
226 bool* ok); 226 bool* ok);
227 227
228 typename Traits::ExpressionType ParseRegExpLiteral(bool seen_equal, bool* ok);
229
228 // Used to detect duplicates in object literals. Each of the values 230 // Used to detect duplicates in object literals. Each of the values
229 // kGetterProperty, kSetterProperty and kValueProperty represents 231 // kGetterProperty, kSetterProperty and kValueProperty represents
230 // a type of object literal property. When parsing a property, its 232 // a type of object literal property. When parsing a property, its
231 // type value is stored in the DuplicateFinder for the property name. 233 // type value is stored in the DuplicateFinder for the property name.
232 // Values are chosen so that having intersection bits means the there is 234 // Values are chosen so that having intersection bits means the there is
233 // an incompatibility. 235 // an incompatibility.
234 // I.e., you can add a getter to a property that already has a setter, since 236 // I.e., you can add a getter to a property that already has a setter, since
235 // kGetterProperty and kSetterProperty doesn't intersect, but not if it 237 // kGetterProperty and kSetterProperty doesn't intersect, but not if it
236 // already has a getter or a value. Adding the getter to an existing 238 // already has a getter or a value. Adding the getter to an existing
237 // setter will store the value (kGetterProperty | kSetterProperty), which 239 // setter will store the value (kGetterProperty | kSetterProperty), which
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 }; 422 };
421 423
422 class PreParser; 424 class PreParser;
423 425
424 426
425 class PreParserTraits { 427 class PreParserTraits {
426 public: 428 public:
427 typedef PreParser* ParserType; 429 typedef PreParser* ParserType;
428 // Return types for traversing functions. 430 // Return types for traversing functions.
429 typedef PreParserIdentifier IdentifierType; 431 typedef PreParserIdentifier IdentifierType;
432 typedef PreParserExpression ExpressionType;
430 433
431 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 434 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
432 435
433 // Helper functions for recursive descent. 436 // Helper functions for recursive descent.
434 bool is_classic_mode() const; 437 bool is_classic_mode() const;
435 bool is_generator() const; 438 bool is_generator() const;
436 static bool IsEvalOrArguments(IdentifierType identifier) { 439 static bool IsEvalOrArguments(IdentifierType identifier) {
437 return identifier.IsEvalOrArguments(); 440 return identifier.IsEvalOrArguments();
438 } 441 }
442 int NextMaterializedLiteralIndex();
439 443
440 // Reporting errors. 444 // Reporting errors.
441 void ReportMessageAt(Scanner::Location location, 445 void ReportMessageAt(Scanner::Location location,
442 const char* message, 446 const char* message,
443 Vector<const char*> args); 447 Vector<const char*> args);
444 void ReportMessageAt(Scanner::Location location, 448 void ReportMessageAt(Scanner::Location location,
445 const char* type, 449 const char* type,
446 const char* name_opt); 450 const char* name_opt);
447 void ReportMessageAt(int start_pos, 451 void ReportMessageAt(int start_pos,
448 int end_pos, 452 int end_pos,
449 const char* type, 453 const char* type,
450 const char* name_opt); 454 const char* name_opt);
451 455
452 // Identifiers: 456 // "null" return type creators.
453 static IdentifierType EmptyIdentifier() { 457 static IdentifierType EmptyIdentifier() {
454 return PreParserIdentifier::Default(); 458 return PreParserIdentifier::Default();
455 } 459 }
460 static ExpressionType EmptyExpression() {
461 return PreParserExpression::Default();
462 }
456 463
464 // Producing data during the recursive descent.
457 IdentifierType GetSymbol(); 465 IdentifierType GetSymbol();
466 static IdentifierType NextLiteralString(PretenureFlag tenured) {
467 return PreParserIdentifier::Default();
468 }
469 ExpressionType NewRegExpLiteral(IdentifierType js_pattern,
470 IdentifierType js_flags,
471 int literal_index,
472 int pos) {
473 return PreParserExpression::Default();
474 }
458 475
459 private: 476 private:
460 PreParser* pre_parser_; 477 PreParser* pre_parser_;
461 }; 478 };
462 479
463 480
464 // Preparsing checks a JavaScript program and emits preparse-data that helps 481 // Preparsing checks a JavaScript program and emits preparse-data that helps
465 // a later parsing to be faster. 482 // a later parsing to be faster.
466 // See preparse-data-format.h for the data format. 483 // See preparse-data-format.h for the data format.
467 484
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 type_(type), 626 type_(type),
610 materialized_literal_count_(0), 627 materialized_literal_count_(0),
611 expected_properties_(0), 628 expected_properties_(0),
612 with_nesting_count_(0), 629 with_nesting_count_(0),
613 language_mode_( 630 language_mode_(
614 (prev_ != NULL) ? prev_->language_mode() : CLASSIC_MODE), 631 (prev_ != NULL) ? prev_->language_mode() : CLASSIC_MODE),
615 is_generator_(false) { 632 is_generator_(false) {
616 *variable = this; 633 *variable = this;
617 } 634 }
618 ~Scope() { *variable_ = prev_; } 635 ~Scope() { *variable_ = prev_; }
619 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } 636 int NextMaterializedLiteralIndex() { return materialized_literal_count_++; }
620 void AddProperty() { expected_properties_++; } 637 void AddProperty() { expected_properties_++; }
621 ScopeType type() { return type_; } 638 ScopeType type() { return type_; }
622 int expected_properties() { return expected_properties_; } 639 int expected_properties() { return expected_properties_; }
623 int materialized_literal_count() { return materialized_literal_count_; } 640 int materialized_literal_count() { return materialized_literal_count_; }
624 bool IsInsideWith() { return with_nesting_count_ != 0; } 641 bool IsInsideWith() { return with_nesting_count_ != 0; }
625 bool is_generator() { return is_generator_; } 642 bool is_generator() { return is_generator_; }
626 void set_is_generator(bool is_generator) { is_generator_ = is_generator; } 643 void set_is_generator(bool is_generator) { is_generator_ = is_generator; }
627 bool is_classic_mode() { 644 bool is_classic_mode() {
628 return language_mode_ == CLASSIC_MODE; 645 return language_mode_ == CLASSIC_MODE;
629 } 646 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 711 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
695 Expression ParseUnaryExpression(bool* ok); 712 Expression ParseUnaryExpression(bool* ok);
696 Expression ParsePostfixExpression(bool* ok); 713 Expression ParsePostfixExpression(bool* ok);
697 Expression ParseLeftHandSideExpression(bool* ok); 714 Expression ParseLeftHandSideExpression(bool* ok);
698 Expression ParseNewExpression(bool* ok); 715 Expression ParseNewExpression(bool* ok);
699 Expression ParseMemberExpression(bool* ok); 716 Expression ParseMemberExpression(bool* ok);
700 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); 717 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok);
701 Expression ParsePrimaryExpression(bool* ok); 718 Expression ParsePrimaryExpression(bool* ok);
702 Expression ParseArrayLiteral(bool* ok); 719 Expression ParseArrayLiteral(bool* ok);
703 Expression ParseObjectLiteral(bool* ok); 720 Expression ParseObjectLiteral(bool* ok);
704 Expression ParseRegExpLiteral(bool seen_equal, bool* ok);
705 Expression ParseV8Intrinsic(bool* ok); 721 Expression ParseV8Intrinsic(bool* ok);
706 722
707 Arguments ParseArguments(bool* ok); 723 Arguments ParseArguments(bool* ok);
708 Expression ParseFunctionLiteral( 724 Expression ParseFunctionLiteral(
709 Identifier name, 725 Identifier name,
710 Scanner::Location function_name_location, 726 Scanner::Location function_name_location,
711 bool name_is_strict_reserved, 727 bool name_is_strict_reserved,
712 bool is_generator, 728 bool is_generator,
713 bool* ok); 729 bool* ok);
714 void ParseLazyFunctionLiteralBody(bool* ok); 730 void ParseLazyFunctionLiteralBody(bool* ok);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 if (scanner()->is_literal_ascii() && 857 if (scanner()->is_literal_ascii() &&
842 scanner()->literal_length() == 3) { 858 scanner()->literal_length() == 3) {
843 const char* token = scanner()->literal_ascii_string().start(); 859 const char* token = scanner()->literal_ascii_string().start();
844 *is_get = strncmp(token, "get", 3) == 0; 860 *is_get = strncmp(token, "get", 3) == 0;
845 *is_set = !*is_get && strncmp(token, "set", 3) == 0; 861 *is_set = !*is_get && strncmp(token, "set", 3) == 0;
846 } 862 }
847 return result; 863 return result;
848 } 864 }
849 865
850 866
867 template <class Traits>
868 typename Traits::ExpressionType
869 ParserBase<Traits>::ParseRegExpLiteral(bool seen_equal, bool* ok) {
870 int pos = peek_position();
871 if (!scanner()->ScanRegExpPattern(seen_equal)) {
872 Next();
873 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
874 *ok = false;
875 return Traits::EmptyExpression();
876 }
877
878 int literal_index = this->NextMaterializedLiteralIndex();
879
880 typename Traits::IdentifierType js_pattern = this->NextLiteralString(TENURED);
881 if (!scanner()->ScanRegExpFlags()) {
882 Next();
883 ReportMessageAt(scanner()->location(), "invalid_regexp_flags");
884 *ok = false;
885 return Traits::EmptyExpression();
886 }
887 typename Traits::IdentifierType js_flags = this->NextLiteralString(TENURED);
888 Next();
889 return this->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
890 }
891
892
851 template <typename Traits> 893 template <typename Traits>
852 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( 894 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
853 Token::Value property, 895 Token::Value property,
854 PropertyKind type, 896 PropertyKind type,
855 bool* ok) { 897 bool* ok) {
856 int old; 898 int old;
857 if (property == Token::NUMBER) { 899 if (property == Token::NUMBER) {
858 old = finder_.AddNumber(scanner()->literal_ascii_string(), type); 900 old = finder_.AddNumber(scanner()->literal_ascii_string(), type);
859 } else if (scanner()->is_literal_ascii()) { 901 } else if (scanner()->is_literal_ascii()) {
860 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type); 902 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type);
(...skipping 18 matching lines...) Expand all
879 "accessor_get_set"); 921 "accessor_get_set");
880 } 922 }
881 *ok = false; 923 *ok = false;
882 } 924 }
883 } 925 }
884 926
885 927
886 } } // v8::internal 928 } } // v8::internal
887 929
888 #endif // V8_PREPARSER_H 930 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698