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

Side by Side Diff: src/preparser.h

Issue 1170153003: [destructuring] Refactor duplicate parameter name detection. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 6 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
« 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 // 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 #ifndef V8_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
11 #include "src/expression-classifier.h"
11 #include "src/func-name-inferrer.h" 12 #include "src/func-name-inferrer.h"
12 #include "src/hashmap.h" 13 #include "src/hashmap.h"
13 #include "src/messages.h" 14 #include "src/messages.h"
14 #include "src/scanner.h" 15 #include "src/scanner.h"
15 #include "src/scopes.h" 16 #include "src/scopes.h"
16 #include "src/token.h" 17 #include "src/token.h"
17 18
18 namespace v8 { 19 namespace v8 {
19 namespace internal { 20 namespace internal {
20 21
21
22 // Common base class shared between parser and pre-parser. Traits encapsulate 22 // Common base class shared between parser and pre-parser. Traits encapsulate
23 // the differences between Parser and PreParser: 23 // the differences between Parser and PreParser:
24 24
25 // - Return types: For example, Parser functions return Expression* and 25 // - Return types: For example, Parser functions return Expression* and
26 // PreParser functions return PreParserExpression. 26 // PreParser functions return PreParserExpression.
27 27
28 // - Creating parse tree nodes: Parser generates an AST during the recursive 28 // - Creating parse tree nodes: Parser generates an AST during the recursive
29 // descent. PreParser doesn't create a tree. Instead, it passes around minimal 29 // descent. PreParser doesn't create a tree. Instead, it passes around minimal
30 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain 30 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain
31 // just enough data for the upper layer functions. PreParserFactory is 31 // just enough data for the upper layer functions. PreParserFactory is
(...skipping 15 matching lines...) Expand all
47 // // Return types for traversing functions. 47 // // Return types for traversing functions.
48 // typedef Identifier; 48 // typedef Identifier;
49 // typedef Expression; 49 // typedef Expression;
50 // typedef FunctionLiteral; 50 // typedef FunctionLiteral;
51 // typedef ClassLiteral; 51 // typedef ClassLiteral;
52 // typedef ObjectLiteralProperty; 52 // typedef ObjectLiteralProperty;
53 // typedef Literal; 53 // typedef Literal;
54 // typedef ExpressionList; 54 // typedef ExpressionList;
55 // typedef PropertyList; 55 // typedef PropertyList;
56 // typedef FormalParameter; 56 // typedef FormalParameter;
57 // typedef FormalParameterScope;
58 // // For constructing objects returned by the traversing functions. 57 // // For constructing objects returned by the traversing functions.
59 // typedef Factory; 58 // typedef Factory;
60 // }; 59 // };
61 // // ... 60 // // ...
62 // }; 61 // };
63 62
64 template <typename Traits> 63 template <typename Traits>
65 class ParserBase : public Traits { 64 class ParserBase : public Traits {
66 public: 65 public:
67 // Shorten type names defined by Traits. 66 // Shorten type names defined by Traits.
68 typedef typename Traits::Type::Expression ExpressionT; 67 typedef typename Traits::Type::Expression ExpressionT;
69 typedef typename Traits::Type::Identifier IdentifierT; 68 typedef typename Traits::Type::Identifier IdentifierT;
70 typedef typename Traits::Type::FormalParameter FormalParameterT; 69 typedef typename Traits::Type::FormalParameter FormalParameterT;
71 typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT;
72 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; 70 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
73 typedef typename Traits::Type::Literal LiteralT; 71 typedef typename Traits::Type::Literal LiteralT;
74 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; 72 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
75 73
76 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, 74 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
77 v8::Extension* extension, AstValueFactory* ast_value_factory, 75 v8::Extension* extension, AstValueFactory* ast_value_factory,
78 ParserRecorder* log, typename Traits::Type::Parser this_object) 76 ParserRecorder* log, typename Traits::Type::Parser this_object)
79 : Traits(this_object), 77 : Traits(this_object),
80 parenthesized_function_(false), 78 parenthesized_function_(false),
81 scope_(NULL), 79 scope_(NULL),
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 void ReportMessageAt(Scanner::Location location, 497 void ReportMessageAt(Scanner::Location location,
500 MessageTemplate::Template message, 498 MessageTemplate::Template message,
501 ParseErrorType error_type = kSyntaxError) { 499 ParseErrorType error_type = kSyntaxError) {
502 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), 500 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0),
503 error_type); 501 error_type);
504 } 502 }
505 503
506 void ReportUnexpectedToken(Token::Value token); 504 void ReportUnexpectedToken(Token::Value token);
507 void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token); 505 void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token);
508 506
509 class ExpressionClassifier {
510 public:
511 struct Error {
512 Error()
513 : location(Scanner::Location::invalid()),
514 message(MessageTemplate::kNone),
515 arg(nullptr) {}
516 507
517 Scanner::Location location; 508 void ReportClassifierError(const ExpressionClassifier::Error& error) {
518 MessageTemplate::Template message;
519 const char* arg;
520 };
521
522 enum TargetProduction {
523 ExpressionProduction = 1 << 0,
524 BindingPatternProduction = 1 << 1,
525 AssignmentPatternProduction = 1 << 2,
526 DistinctFormalParametersProduction = 1 << 3,
527 StrictModeFormalParametersProduction = 1 << 4,
528 StrongModeFormalParametersProduction = 1 << 5,
529 ArrowFormalParametersProduction = 1 << 6,
530
531 PatternProductions =
532 (BindingPatternProduction | AssignmentPatternProduction),
533 FormalParametersProductions = (DistinctFormalParametersProduction |
534 StrictModeFormalParametersProduction |
535 StrongModeFormalParametersProduction),
536 StandardProductions = ExpressionProduction | PatternProductions,
537 AllProductions = (StandardProductions | FormalParametersProductions |
538 ArrowFormalParametersProduction)
539 };
540
541 ExpressionClassifier() : invalid_productions_(0) {}
542
543 bool is_valid(unsigned productions) const {
544 return (invalid_productions_ & productions) == 0;
545 }
546
547 bool is_valid_expression() const { return is_valid(ExpressionProduction); }
548
549 bool is_valid_binding_pattern() const {
550 return is_valid(BindingPatternProduction);
551 }
552
553 bool is_valid_assignment_pattern() const {
554 return is_valid(AssignmentPatternProduction);
555 }
556
557 bool is_valid_arrow_formal_parameters() const {
558 return is_valid(ArrowFormalParametersProduction);
559 }
560
561 bool is_valid_formal_parameter_list_without_duplicates() const {
562 return is_valid(DistinctFormalParametersProduction);
563 }
564
565 // Note: callers should also check
566 // is_valid_formal_parameter_list_without_duplicates().
567 bool is_valid_strict_mode_formal_parameters() const {
568 return is_valid(StrictModeFormalParametersProduction);
569 }
570
571 // Note: callers should also check is_valid_strict_mode_formal_parameters()
572 // and is_valid_formal_parameter_list_without_duplicates().
573 bool is_valid_strong_mode_formal_parameters() const {
574 return is_valid(StrongModeFormalParametersProduction);
575 }
576
577 const Error& expression_error() const { return expression_error_; }
578
579 const Error& binding_pattern_error() const {
580 return binding_pattern_error_;
581 }
582
583 const Error& assignment_pattern_error() const {
584 return assignment_pattern_error_;
585 }
586
587 const Error& arrow_formal_parameters_error() const {
588 return arrow_formal_parameters_error_;
589 }
590
591 const Error& duplicate_formal_parameter_error() const {
592 return duplicate_formal_parameter_error_;
593 }
594
595 const Error& strict_mode_formal_parameter_error() const {
596 return strict_mode_formal_parameter_error_;
597 }
598
599 const Error& strong_mode_formal_parameter_error() const {
600 return strong_mode_formal_parameter_error_;
601 }
602
603 void RecordExpressionError(const Scanner::Location& loc,
604 MessageTemplate::Template message,
605 const char* arg = nullptr) {
606 if (!is_valid_expression()) return;
607 invalid_productions_ |= ExpressionProduction;
608 expression_error_.location = loc;
609 expression_error_.message = message;
610 expression_error_.arg = arg;
611 }
612
613 void RecordBindingPatternError(const Scanner::Location& loc,
614 MessageTemplate::Template message,
615 const char* arg = nullptr) {
616 if (!is_valid_binding_pattern()) return;
617 invalid_productions_ |= BindingPatternProduction;
618 binding_pattern_error_.location = loc;
619 binding_pattern_error_.message = message;
620 binding_pattern_error_.arg = arg;
621 }
622
623 void RecordAssignmentPatternError(const Scanner::Location& loc,
624 MessageTemplate::Template message,
625 const char* arg = nullptr) {
626 if (!is_valid_assignment_pattern()) return;
627 invalid_productions_ |= AssignmentPatternProduction;
628 assignment_pattern_error_.location = loc;
629 assignment_pattern_error_.message = message;
630 assignment_pattern_error_.arg = arg;
631 }
632
633 void RecordArrowFormalParametersError(const Scanner::Location& loc,
634 MessageTemplate::Template message,
635 const char* arg = nullptr) {
636 if (!is_valid_arrow_formal_parameters()) return;
637 invalid_productions_ |= ArrowFormalParametersProduction;
638 arrow_formal_parameters_error_.location = loc;
639 arrow_formal_parameters_error_.message = message;
640 arrow_formal_parameters_error_.arg = arg;
641 }
642
643 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) {
644 if (!is_valid_formal_parameter_list_without_duplicates()) return;
645 invalid_productions_ |= DistinctFormalParametersProduction;
646 duplicate_formal_parameter_error_.location = loc;
647 duplicate_formal_parameter_error_.message =
648 MessageTemplate::kStrictParamDupe;
649 duplicate_formal_parameter_error_.arg = nullptr;
650 }
651
652 // Record a binding that would be invalid in strict mode. Confusingly this
653 // is not the same as StrictFormalParameterList, which simply forbids
654 // duplicate bindings.
655 void RecordStrictModeFormalParameterError(const Scanner::Location& loc,
656 MessageTemplate::Template message,
657 const char* arg = nullptr) {
658 if (!is_valid_strict_mode_formal_parameters()) return;
659 invalid_productions_ |= StrictModeFormalParametersProduction;
660 strict_mode_formal_parameter_error_.location = loc;
661 strict_mode_formal_parameter_error_.message = message;
662 strict_mode_formal_parameter_error_.arg = arg;
663 }
664
665 void RecordStrongModeFormalParameterError(const Scanner::Location& loc,
666 MessageTemplate::Template message,
667 const char* arg = nullptr) {
668 if (!is_valid_strong_mode_formal_parameters()) return;
669 invalid_productions_ |= StrongModeFormalParametersProduction;
670 strong_mode_formal_parameter_error_.location = loc;
671 strong_mode_formal_parameter_error_.message = message;
672 strong_mode_formal_parameter_error_.arg = arg;
673 }
674
675 void Accumulate(const ExpressionClassifier& inner,
676 unsigned productions = StandardProductions) {
677 // Propagate errors from inner, but don't overwrite already recorded
678 // errors.
679 unsigned non_arrow_inner_invalid_productions =
680 inner.invalid_productions_ & ~ArrowFormalParametersProduction;
681 if (non_arrow_inner_invalid_productions == 0) return;
682 unsigned non_arrow_productions =
683 productions & ~ArrowFormalParametersProduction;
684 unsigned errors =
685 non_arrow_productions & non_arrow_inner_invalid_productions;
686 errors &= ~invalid_productions_;
687 if (errors != 0) {
688 invalid_productions_ |= errors;
689 if (errors & ExpressionProduction)
690 expression_error_ = inner.expression_error_;
691 if (errors & BindingPatternProduction)
692 binding_pattern_error_ = inner.binding_pattern_error_;
693 if (errors & AssignmentPatternProduction)
694 assignment_pattern_error_ = inner.assignment_pattern_error_;
695 if (errors & DistinctFormalParametersProduction)
696 duplicate_formal_parameter_error_ =
697 inner.duplicate_formal_parameter_error_;
698 if (errors & StrictModeFormalParametersProduction)
699 strict_mode_formal_parameter_error_ =
700 inner.strict_mode_formal_parameter_error_;
701 if (errors & StrongModeFormalParametersProduction)
702 strong_mode_formal_parameter_error_ =
703 inner.strong_mode_formal_parameter_error_;
704 }
705
706 // As an exception to the above, the result continues to be a valid arrow
707 // formal parameters if the inner expression is a valid binding pattern.
708 if (productions & ArrowFormalParametersProduction &&
709 is_valid_arrow_formal_parameters() &&
710 !inner.is_valid_binding_pattern()) {
711 invalid_productions_ |= ArrowFormalParametersProduction;
712 arrow_formal_parameters_error_ = inner.binding_pattern_error_;
713 }
714 }
715
716 void AccumulateReclassifyingAsPattern(const ExpressionClassifier& inner) {
717 Accumulate(inner, AllProductions & ~PatternProductions);
718 if (!inner.is_valid_expression()) {
719 if (is_valid_binding_pattern()) {
720 binding_pattern_error_ = inner.expression_error();
721 }
722 if (is_valid_assignment_pattern()) {
723 assignment_pattern_error_ = inner.expression_error();
724 }
725 }
726 }
727
728 private:
729 unsigned invalid_productions_;
730 Error expression_error_;
731 Error binding_pattern_error_;
732 Error assignment_pattern_error_;
733 Error arrow_formal_parameters_error_;
734 Error duplicate_formal_parameter_error_;
735 Error strict_mode_formal_parameter_error_;
736 Error strong_mode_formal_parameter_error_;
737 };
738
739 void ReportClassifierError(
740 const typename ExpressionClassifier::Error& error) {
741 Traits::ReportMessageAt(error.location, error.message, error.arg, 509 Traits::ReportMessageAt(error.location, error.message, error.arg,
742 kSyntaxError); 510 kSyntaxError);
743 } 511 }
744 512
745 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { 513 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) {
746 if (!classifier->is_valid_expression()) { 514 if (!classifier->is_valid_expression()) {
747 ReportClassifierError(classifier->expression_error()); 515 ReportClassifierError(classifier->expression_error());
748 *ok = false; 516 *ok = false;
749 } 517 }
750 } 518 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 ExpressionClassifier* classifier, bool* ok); 651 ExpressionClassifier* classifier, bool* ok);
884 void AddTemplateExpression(ExpressionT); 652 void AddTemplateExpression(ExpressionT);
885 ExpressionT ParseSuperExpression(bool is_new, 653 ExpressionT ParseSuperExpression(bool is_new,
886 ExpressionClassifier* classifier, bool* ok); 654 ExpressionClassifier* classifier, bool* ok);
887 ExpressionT ParseNewTargetExpression(bool* ok); 655 ExpressionT ParseNewTargetExpression(bool* ok);
888 ExpressionT ParseStrongInitializationExpression( 656 ExpressionT ParseStrongInitializationExpression(
889 ExpressionClassifier* classifier, bool* ok); 657 ExpressionClassifier* classifier, bool* ok);
890 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, 658 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
891 bool* ok); 659 bool* ok);
892 660
893 void ParseFormalParameter(FormalParameterScopeT* scope, bool is_rest, 661 void ParseFormalParameter(Scope* scope, bool is_rest,
894 ExpressionClassifier* classifier, bool* ok); 662 ExpressionClassifier* classifier, bool* ok);
895 int ParseFormalParameterList(FormalParameterScopeT* scope, bool* has_rest, 663 int ParseFormalParameterList(Scope* scope, bool* has_rest,
896 ExpressionClassifier* classifier, bool* ok); 664 ExpressionClassifier* classifier, bool* ok);
897 void CheckArityRestrictions( 665 void CheckArityRestrictions(
898 int param_count, FunctionLiteral::ArityRestriction arity_restriction, 666 int param_count, FunctionLiteral::ArityRestriction arity_restriction,
899 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); 667 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok);
900 668
901 // Checks if the expression is a valid reference expression (e.g., on the 669 // Checks if the expression is a valid reference expression (e.g., on the
902 // left-hand side of assignments). Although ruled out by ECMA as early errors, 670 // left-hand side of assignments). Although ruled out by ECMA as early errors,
903 // we allow calls for web compatibility and rewrite them to a runtime throw. 671 // we allow calls for web compatibility and rewrite them to a runtime throw.
904 ExpressionT CheckAndRewriteReferenceExpression( 672 ExpressionT CheckAndRewriteReferenceExpression(
905 ExpressionT expression, Scanner::Location location, 673 ExpressionT expression, Scanner::Location location,
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 typedef PreParserIdentifier Identifier; 1270 typedef PreParserIdentifier Identifier;
1503 typedef PreParserExpression Expression; 1271 typedef PreParserExpression Expression;
1504 typedef PreParserExpression YieldExpression; 1272 typedef PreParserExpression YieldExpression;
1505 typedef PreParserExpression FunctionLiteral; 1273 typedef PreParserExpression FunctionLiteral;
1506 typedef PreParserExpression ClassLiteral; 1274 typedef PreParserExpression ClassLiteral;
1507 typedef PreParserExpression ObjectLiteralProperty; 1275 typedef PreParserExpression ObjectLiteralProperty;
1508 typedef PreParserExpression Literal; 1276 typedef PreParserExpression Literal;
1509 typedef PreParserExpressionList ExpressionList; 1277 typedef PreParserExpressionList ExpressionList;
1510 typedef PreParserExpressionList PropertyList; 1278 typedef PreParserExpressionList PropertyList;
1511 typedef PreParserIdentifier FormalParameter; 1279 typedef PreParserIdentifier FormalParameter;
1512 typedef DuplicateFinder FormalParameterScope;
1513 typedef PreParserStatementList StatementList; 1280 typedef PreParserStatementList StatementList;
1514 1281
1515 // For constructing objects returned by the traversing functions. 1282 // For constructing objects returned by the traversing functions.
1516 typedef PreParserFactory Factory; 1283 typedef PreParserFactory Factory;
1517 }; 1284 };
1518 1285
1519 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 1286 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
1520 1287
1521 // Helper functions for recursive descent. 1288 // Helper functions for recursive descent.
1522 static bool IsEval(PreParserIdentifier identifier) { 1289 static bool IsEval(PreParserIdentifier identifier) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 return EmptyExpression(); 1548 return EmptyExpression();
1782 } 1549 }
1783 inline void MaterializeTemplateCallsiteLiterals(); 1550 inline void MaterializeTemplateCallsiteLiterals();
1784 PreParserExpression NoTemplateTag() { 1551 PreParserExpression NoTemplateTag() {
1785 return PreParserExpression::NoTemplateTag(); 1552 return PreParserExpression::NoTemplateTag();
1786 } 1553 }
1787 static bool IsTaggedTemplate(const PreParserExpression tag) { 1554 static bool IsTaggedTemplate(const PreParserExpression tag) {
1788 return !tag.IsNoTemplateTag(); 1555 return !tag.IsNoTemplateTag();
1789 } 1556 }
1790 1557
1791 V8_INLINE bool DeclareFormalParameter(DuplicateFinder* scope, 1558 void DeclareFormalParameter(Scope* scope, PreParserIdentifier param,
1792 PreParserIdentifier param, 1559 ExpressionClassifier* classifier, bool is_rest) {}
1793 bool is_rest);
1794 1560
1795 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 1561 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
1796 1562
1797 // Temporary glue; these functions will move to ParserBase. 1563 // Temporary glue; these functions will move to ParserBase.
1798 PreParserExpression ParseV8Intrinsic(bool* ok); 1564 PreParserExpression ParseV8Intrinsic(bool* ok);
1799 PreParserExpression ParseFunctionLiteral( 1565 PreParserExpression ParseFunctionLiteral(
1800 PreParserIdentifier name, Scanner::Location function_name_location, 1566 PreParserIdentifier name, Scanner::Location function_name_location,
1801 bool name_is_strict_reserved, FunctionKind kind, 1567 bool name_is_strict_reserved, FunctionKind kind,
1802 int function_token_position, FunctionLiteral::FunctionType type, 1568 int function_token_position, FunctionLiteral::FunctionType type,
1803 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); 1569 FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 return pre_parser_->factory()->NewCall(function, args, pos); 1743 return pre_parser_->factory()->NewCall(function, args, pos);
1978 } 1744 }
1979 1745
1980 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, 1746 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function,
1981 PreParserExpressionList args, 1747 PreParserExpressionList args,
1982 int pos) { 1748 int pos) {
1983 return pre_parser_->factory()->NewCallNew(function, args, pos); 1749 return pre_parser_->factory()->NewCallNew(function, args, pos);
1984 } 1750 }
1985 1751
1986 1752
1987 bool PreParserTraits::DeclareFormalParameter(
1988 DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier,
1989 bool is_rest) {
1990 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0;
1991 }
1992
1993
1994 void PreParserTraits::ParseArrowFunctionFormalParameters( 1753 void PreParserTraits::ParseArrowFunctionFormalParameters(
1995 Scope* scope, PreParserExpression params, 1754 Scope* scope, PreParserExpression params,
1996 const Scanner::Location& params_loc, bool* is_rest, 1755 const Scanner::Location& params_loc, bool* is_rest,
1997 Scanner::Location* duplicate_loc, bool* ok) { 1756 Scanner::Location* duplicate_loc, bool* ok) {
1998 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1757 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1999 // lists that are too long. 1758 // lists that are too long.
2000 } 1759 }
2001 1760
2002 1761
2003 PreParserStatementList PreParser::ParseEagerFunctionBody( 1762 PreParserStatementList PreParser::ParseEagerFunctionBody(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 classifier->RecordStrongModeFormalParameterError( 1915 classifier->RecordStrongModeFormalParameterError(
2157 scanner()->location(), MessageTemplate::kStrongUndefined); 1916 scanner()->location(), MessageTemplate::kStrongUndefined);
2158 if (is_strong(language_mode())) { 1917 if (is_strong(language_mode())) {
2159 // TODO(dslomov): allow 'undefined' in nested patterns. 1918 // TODO(dslomov): allow 'undefined' in nested patterns.
2160 classifier->RecordBindingPatternError( 1919 classifier->RecordBindingPatternError(
2161 scanner()->location(), MessageTemplate::kStrongUndefined); 1920 scanner()->location(), MessageTemplate::kStrongUndefined);
2162 classifier->RecordAssignmentPatternError( 1921 classifier->RecordAssignmentPatternError(
2163 scanner()->location(), MessageTemplate::kStrongUndefined); 1922 scanner()->location(), MessageTemplate::kStrongUndefined);
2164 } 1923 }
2165 } 1924 }
1925
1926 if (classifier->duplicate_finder() != nullptr &&
1927 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
1928 classifier->RecordDuplicateFormalParameterError(scanner()->location());
1929 }
2166 return name; 1930 return name;
2167 } else if (is_sloppy(language_mode()) && 1931 } else if (is_sloppy(language_mode()) &&
2168 (next == Token::FUTURE_STRICT_RESERVED_WORD || 1932 (next == Token::FUTURE_STRICT_RESERVED_WORD ||
2169 next == Token::LET || next == Token::STATIC || 1933 next == Token::LET || next == Token::STATIC ||
2170 (next == Token::YIELD && !is_generator()))) { 1934 (next == Token::YIELD && !is_generator()))) {
2171 classifier->RecordStrictModeFormalParameterError( 1935 classifier->RecordStrictModeFormalParameterError(
2172 scanner()->location(), MessageTemplate::kUnexpectedStrictReserved); 1936 scanner()->location(), MessageTemplate::kUnexpectedStrictReserved);
2173 return this->GetSymbol(scanner()); 1937 return this->GetSymbol(scanner());
2174 } else { 1938 } else {
2175 this->ReportUnexpectedToken(next); 1939 this->ReportUnexpectedToken(next);
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 default: 3439 default:
3676 return expression; 3440 return expression;
3677 } 3441 }
3678 } 3442 }
3679 DCHECK(false); 3443 DCHECK(false);
3680 return this->EmptyExpression(); 3444 return this->EmptyExpression();
3681 } 3445 }
3682 3446
3683 3447
3684 template <class Traits> 3448 template <class Traits>
3685 void ParserBase<Traits>::ParseFormalParameter(FormalParameterScopeT* scope, 3449 void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest,
3686 bool is_rest,
3687 ExpressionClassifier* classifier, 3450 ExpressionClassifier* classifier,
3688 bool* ok) { 3451 bool* ok) {
3689 // FormalParameter[Yield,GeneratorParameter] : 3452 // FormalParameter[Yield,GeneratorParameter] :
3690 // BindingElement[?Yield, ?GeneratorParameter] 3453 // BindingElement[?Yield, ?GeneratorParameter]
3691 IdentifierT name = ParseAndClassifyIdentifier(classifier, ok); 3454 IdentifierT name = ParseAndClassifyIdentifier(classifier, ok);
3692 if (!*ok) return; 3455 if (!*ok) return;
3693 3456
3694 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); 3457 Traits::DeclareFormalParameter(scope, name, classifier, is_rest);
3695 if (was_declared) {
3696 classifier->RecordDuplicateFormalParameterError(scanner()->location());
3697 }
3698 } 3458 }
3699 3459
3700 3460
3701 template <class Traits> 3461 template <class Traits>
3702 int ParserBase<Traits>::ParseFormalParameterList( 3462 int ParserBase<Traits>::ParseFormalParameterList(
3703 FormalParameterScopeT* scope, bool* is_rest, 3463 Scope* scope, bool* is_rest, ExpressionClassifier* classifier, bool* ok) {
3704 ExpressionClassifier* classifier, bool* ok) {
3705 // FormalParameters[Yield,GeneratorParameter] : 3464 // FormalParameters[Yield,GeneratorParameter] :
3706 // [empty] 3465 // [empty]
3707 // FormalParameterList[?Yield, ?GeneratorParameter] 3466 // FormalParameterList[?Yield, ?GeneratorParameter]
3708 // 3467 //
3709 // FormalParameterList[Yield,GeneratorParameter] : 3468 // FormalParameterList[Yield,GeneratorParameter] :
3710 // FunctionRestParameter[?Yield] 3469 // FunctionRestParameter[?Yield]
3711 // FormalsList[?Yield, ?GeneratorParameter] 3470 // FormalsList[?Yield, ?GeneratorParameter]
3712 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] 3471 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield]
3713 // 3472 //
3714 // FormalsList[Yield,GeneratorParameter] : 3473 // FormalsList[Yield,GeneratorParameter] :
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
4051 *ok = false; 3810 *ok = false;
4052 return; 3811 return;
4053 } 3812 }
4054 has_seen_constructor_ = true; 3813 has_seen_constructor_ = true;
4055 return; 3814 return;
4056 } 3815 }
4057 } 3816 }
4058 } } // v8::internal 3817 } } // v8::internal
4059 3818
4060 #endif // V8_PREPARSER_H 3819 #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