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

Side by Side Diff: src/parsing/preparser.h

Issue 2264483003: [parser] Reorder traits methods (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Changes after reviewers' comments Created 4 years, 4 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/parsing/parser.h ('k') | no next file » | 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_PARSING_PREPARSER_H 5 #ifndef V8_PARSING_PREPARSER_H
6 #define V8_PARSING_PREPARSER_H 6 #define V8_PARSING_PREPARSER_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 599
600 typedef v8::internal::ExpressionClassifier<PreParserTraits> 600 typedef v8::internal::ExpressionClassifier<PreParserTraits>
601 ExpressionClassifier; 601 ExpressionClassifier;
602 602
603 // Return types for traversing functions. 603 // Return types for traversing functions.
604 typedef PreParserIdentifier Identifier; 604 typedef PreParserIdentifier Identifier;
605 typedef PreParserExpression Expression; 605 typedef PreParserExpression Expression;
606 typedef PreParserExpression YieldExpression; 606 typedef PreParserExpression YieldExpression;
607 typedef PreParserExpression FunctionLiteral; 607 typedef PreParserExpression FunctionLiteral;
608 typedef PreParserExpression ClassLiteral; 608 typedef PreParserExpression ClassLiteral;
609 typedef PreParserExpression Literal;
609 typedef PreParserExpression ObjectLiteralProperty; 610 typedef PreParserExpression ObjectLiteralProperty;
610 typedef PreParserExpression Literal;
611 typedef PreParserExpressionList ExpressionList; 611 typedef PreParserExpressionList ExpressionList;
612 typedef PreParserExpressionList PropertyList; 612 typedef PreParserExpressionList PropertyList;
613 typedef PreParserIdentifier FormalParameter; 613 typedef PreParserIdentifier FormalParameter;
614 typedef PreParserFormalParameters FormalParameters; 614 typedef PreParserFormalParameters FormalParameters;
615 typedef PreParserStatementList StatementList; 615 typedef PreParserStatementList StatementList;
616 616
617 // For constructing objects returned by the traversing functions. 617 // For constructing objects returned by the traversing functions.
618 typedef PreParserFactory Factory; 618 typedef PreParserFactory Factory;
619 }; 619 };
620 620
621 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 621 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
622 622
623 // Helper functions for recursive descent. 623 // Helper functions for recursive descent.
624 bool IsEval(PreParserIdentifier identifier) const { 624 bool IsEval(PreParserIdentifier identifier) const {
625 return identifier.IsEval(); 625 return identifier.IsEval();
626 } 626 }
627 627
628 bool IsArguments(PreParserIdentifier identifier) const { 628 bool IsArguments(PreParserIdentifier identifier) const {
629 return identifier.IsArguments(); 629 return identifier.IsArguments();
630 } 630 }
631 631
632 bool IsAwait(PreParserIdentifier identifier) const {
633 return identifier.IsAwait();
634 }
635
636 bool IsEvalOrArguments(PreParserIdentifier identifier) const { 632 bool IsEvalOrArguments(PreParserIdentifier identifier) const {
637 return identifier.IsEvalOrArguments(); 633 return identifier.IsEvalOrArguments();
638 } 634 }
639 635
640 bool IsUndefined(PreParserIdentifier identifier) const { 636 bool IsUndefined(PreParserIdentifier identifier) const {
641 return identifier.IsUndefined(); 637 return identifier.IsUndefined();
642 } 638 }
643 639
644 bool IsPrototype(PreParserIdentifier identifier) const { 640 bool IsAwait(PreParserIdentifier identifier) const {
645 return identifier.IsPrototype(); 641 return identifier.IsAwait();
646 } 642 }
647 643
648 bool IsConstructor(PreParserIdentifier identifier) const { 644 bool IsFutureStrictReserved(PreParserIdentifier identifier) const {
649 return identifier.IsConstructor(); 645 return identifier.IsFutureStrictReserved();
650 } 646 }
651 647
652 // Returns true if the expression is of type "this.foo". 648 // Returns true if the expression is of type "this.foo".
653 static bool IsThisProperty(PreParserExpression expression) { 649 static bool IsThisProperty(PreParserExpression expression) {
654 return expression.IsThisProperty(); 650 return expression.IsThisProperty();
655 } 651 }
656 652
657 static bool IsIdentifier(PreParserExpression expression) { 653 static bool IsIdentifier(PreParserExpression expression) {
658 return expression.IsIdentifier(); 654 return expression.IsIdentifier();
659 } 655 }
660 656
661 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { 657 static PreParserIdentifier AsIdentifier(PreParserExpression expression) {
662 return expression.AsIdentifier(); 658 return expression.AsIdentifier();
663 } 659 }
664 660
661 bool IsPrototype(PreParserIdentifier identifier) const {
662 return identifier.IsPrototype();
663 }
664
665 bool IsConstructor(PreParserIdentifier identifier) const {
666 return identifier.IsConstructor();
667 }
668
665 bool IsDirectEvalCall(PreParserExpression expression) const { 669 bool IsDirectEvalCall(PreParserExpression expression) const {
666 return expression.IsDirectEvalCall(); 670 return expression.IsDirectEvalCall();
667 } 671 }
668 672
669 bool IsFutureStrictReserved(PreParserIdentifier identifier) const {
670 return identifier.IsFutureStrictReserved();
671 }
672
673 static bool IsBoilerplateProperty(PreParserExpression property) { 673 static bool IsBoilerplateProperty(PreParserExpression property) {
674 // PreParser doesn't count boilerplate properties. 674 // PreParser doesn't count boilerplate properties.
675 return false; 675 return false;
676 } 676 }
677 677
678 static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) { 678 static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) {
679 return false; 679 return false;
680 } 680 }
681 681
682 static PreParserExpression GetPropertyValue(PreParserExpression property) { 682 static PreParserExpression GetPropertyValue(PreParserExpression property) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 const AstRawString* arg, 754 const AstRawString* arg,
755 ParseErrorType error_type = kSyntaxError); 755 ParseErrorType error_type = kSyntaxError);
756 756
757 // A dummy function, just useful as an argument to CHECK_OK_CUSTOM. 757 // A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
758 static void Void() {} 758 static void Void() {}
759 759
760 // "null" return type creators. 760 // "null" return type creators.
761 static PreParserIdentifier EmptyIdentifier() { 761 static PreParserIdentifier EmptyIdentifier() {
762 return PreParserIdentifier::Default(); 762 return PreParserIdentifier::Default();
763 } 763 }
764 static PreParserIdentifier EmptyIdentifierString() {
765 return PreParserIdentifier::Default();
766 }
767 static PreParserExpression EmptyExpression() { 764 static PreParserExpression EmptyExpression() {
768 return PreParserExpression::Default(); 765 return PreParserExpression::Default();
769 } 766 }
770 static PreParserExpression EmptyLiteral() { 767 static PreParserExpression EmptyLiteral() {
771 return PreParserExpression::Default(); 768 return PreParserExpression::Default();
772 } 769 }
773 static PreParserExpression EmptyObjectLiteralProperty() { 770 static PreParserExpression EmptyObjectLiteralProperty() {
774 return PreParserExpression::Default(); 771 return PreParserExpression::Default();
775 } 772 }
776 static PreParserExpression EmptyFunctionLiteral() { 773 static PreParserExpression EmptyFunctionLiteral() {
777 return PreParserExpression::Default(); 774 return PreParserExpression::Default();
778 } 775 }
776
779 static PreParserExpressionList NullExpressionList() { 777 static PreParserExpressionList NullExpressionList() {
780 return PreParserExpressionList(); 778 return PreParserExpressionList();
781 } 779 }
780 static PreParserIdentifier EmptyIdentifierString() {
781 return PreParserIdentifier::Default();
782 }
782 783
783 // Odd-ball literal creators. 784 // Odd-ball literal creators.
784 PreParserExpression GetLiteralTheHole(int position, 785 PreParserExpression GetLiteralTheHole(int position,
785 PreParserFactory* factory) const { 786 PreParserFactory* factory) const {
786 return PreParserExpression::Default(); 787 return PreParserExpression::Default();
787 } 788 }
788 789
789 // Producing data during the recursive descent. 790 // Producing data during the recursive descent.
790 PreParserIdentifier GetSymbol(Scanner* scanner); 791 PreParserIdentifier GetSymbol(Scanner* scanner);
791 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) {
792 return PreParserIdentifier::Default();
793 }
794 792
795 PreParserIdentifier GetNextSymbol(Scanner* scanner) const { 793 PreParserIdentifier GetNextSymbol(Scanner* scanner) const {
796 return PreParserIdentifier::Default(); 794 return PreParserIdentifier::Default();
797 } 795 }
798 796
797 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) {
798 return PreParserIdentifier::Default();
799 }
800
799 PreParserExpression ThisExpression(int pos = kNoSourcePosition) const { 801 PreParserExpression ThisExpression(int pos = kNoSourcePosition) const {
800 return PreParserExpression::This(); 802 return PreParserExpression::This();
801 } 803 }
802 804
803 PreParserExpression NewSuperPropertyReference(PreParserFactory* factory, 805 PreParserExpression NewSuperPropertyReference(PreParserFactory* factory,
804 int pos) const { 806 int pos) const {
805 return PreParserExpression::Default(); 807 return PreParserExpression::Default();
806 } 808 }
807 809
808 PreParserExpression NewSuperCallReference(PreParserFactory* factory, 810 PreParserExpression NewSuperCallReference(PreParserFactory* factory,
(...skipping 27 matching lines...) Expand all
836 838
837 PreParserExpression GetIterator(PreParserExpression iterable, 839 PreParserExpression GetIterator(PreParserExpression iterable,
838 PreParserFactory* factory, int pos) { 840 PreParserFactory* factory, int pos) {
839 return PreParserExpression::Default(); 841 return PreParserExpression::Default();
840 } 842 }
841 843
842 PreParserExpressionList NewExpressionList(int size, Zone* zone) const { 844 PreParserExpressionList NewExpressionList(int size, Zone* zone) const {
843 return PreParserExpressionList(); 845 return PreParserExpressionList();
844 } 846 }
845 847
848 PreParserExpressionList NewPropertyList(int size, Zone* zone) const {
849 return PreParserExpressionList();
850 }
851
846 PreParserStatementList NewStatementList(int size, Zone* zone) const { 852 PreParserStatementList NewStatementList(int size, Zone* zone) const {
847 return PreParserStatementList(); 853 return PreParserStatementList();
848 } 854 }
849 855
850 PreParserExpressionList NewPropertyList(int size, Zone* zone) const {
851 return PreParserExpressionList();
852 }
853
854 void AddParameterInitializationBlock( 856 void AddParameterInitializationBlock(
855 const PreParserFormalParameters& parameters, PreParserStatementList list, 857 const PreParserFormalParameters& parameters, PreParserStatementList list,
856 bool is_async, bool* ok) const {} 858 bool is_async, bool* ok) const {}
857 859
858 V8_INLINE void SkipLazyFunctionBody(
859 int* materialized_literal_count, int* expected_property_count, bool* ok,
860 Scanner::BookmarkScope* bookmark = nullptr) {
861 UNREACHABLE();
862 }
863
864 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
865 PreParserIdentifier name, int pos,
866 const PreParserFormalParameters& parameters, FunctionKind kind,
867 FunctionLiteral::FunctionType function_type, bool* ok);
868
869 V8_INLINE void ParseArrowFunctionFormalParameterList(
870 PreParserFormalParameters* parameters, PreParserExpression expression,
871 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
872 const Scope::Snapshot& scope_snapshot, bool* ok);
873
874 void ParseAsyncArrowSingleExpressionBody( 860 void ParseAsyncArrowSingleExpressionBody(
875 PreParserStatementList body, bool accept_IN, 861 PreParserStatementList body, bool accept_IN,
876 Type::ExpressionClassifier* classifier, int pos, bool* ok); 862 Type::ExpressionClassifier* classifier, int pos, bool* ok);
877 863
878 V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok);
879
880 void ReindexLiterals(const PreParserFormalParameters& parameters) {}
881
882 struct TemplateLiteralState {};
883
884 TemplateLiteralState OpenTemplateLiteral(int pos) {
885 return TemplateLiteralState();
886 }
887 void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
888 void AddTemplateExpression(TemplateLiteralState* state,
889 PreParserExpression expression) {}
890 V8_INLINE PreParserExpression CloseTemplateLiteral(
891 TemplateLiteralState* state, int start, PreParserExpression tag);
892 PreParserExpression NoTemplateTag() {
893 return PreParserExpression::NoTemplateTag();
894 }
895 static bool IsTaggedTemplate(const PreParserExpression tag) {
896 return !tag.IsNoTemplateTag();
897 }
898 864
899 void AddFormalParameter(PreParserFormalParameters* parameters, 865 void AddFormalParameter(PreParserFormalParameters* parameters,
900 PreParserExpression pattern, 866 PreParserExpression pattern,
901 PreParserExpression initializer, 867 PreParserExpression initializer,
902 int initializer_end_position, bool is_rest) { 868 int initializer_end_position, bool is_rest) {
903 ++parameters->arity; 869 ++parameters->arity;
904 } 870 }
871
905 void DeclareFormalParameter(DeclarationScope* scope, 872 void DeclareFormalParameter(DeclarationScope* scope,
906 PreParserIdentifier parameter, 873 PreParserIdentifier parameter,
907 Type::ExpressionClassifier* classifier) { 874 Type::ExpressionClassifier* classifier) {
908 if (!classifier->is_simple_parameter_list()) { 875 if (!classifier->is_simple_parameter_list()) {
909 scope->SetHasNonSimpleParameters(); 876 scope->SetHasNonSimpleParameters();
910 } 877 }
911 } 878 }
912 879
913 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 880 V8_INLINE void ParseArrowFunctionFormalParameterList(
881 PreParserFormalParameters* parameters, PreParserExpression expression,
882 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
883 const Scope::Snapshot& scope_snapshot, bool* ok);
884
885 V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok);
886
887 V8_INLINE PreParserExpression ParseDoExpression(bool* ok);
888
889 void ReindexLiterals(const PreParserFormalParameters& parameters) {}
914 890
915 // Temporary glue; these functions will move to ParserBase. 891 // Temporary glue; these functions will move to ParserBase.
916 PreParserExpression ParseV8Intrinsic(bool* ok); 892 PreParserExpression ParseV8Intrinsic(bool* ok);
917 V8_INLINE PreParserExpression ParseDoExpression(bool* ok);
918 PreParserExpression ParseFunctionLiteral( 893 PreParserExpression ParseFunctionLiteral(
919 PreParserIdentifier name, Scanner::Location function_name_location, 894 PreParserIdentifier name, Scanner::Location function_name_location,
920 FunctionNameValidity function_name_validity, FunctionKind kind, 895 FunctionNameValidity function_name_validity, FunctionKind kind,
921 int function_token_position, FunctionLiteral::FunctionType type, 896 int function_token_position, FunctionLiteral::FunctionType type,
922 LanguageMode language_mode, bool* ok); 897 LanguageMode language_mode, bool* ok);
923 898
899 V8_INLINE void SkipLazyFunctionBody(
900 int* materialized_literal_count, int* expected_property_count, bool* ok,
901 Scanner::BookmarkScope* bookmark = nullptr) {
902 UNREACHABLE();
903 }
904
905 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
906 PreParserIdentifier name, int pos,
907 const PreParserFormalParameters& parameters, FunctionKind kind,
908 FunctionLiteral::FunctionType function_type, bool* ok);
909
924 PreParserExpression ParseClassLiteral(Type::ExpressionClassifier* classifier, 910 PreParserExpression ParseClassLiteral(Type::ExpressionClassifier* classifier,
925 PreParserIdentifier name, 911 PreParserIdentifier name,
926 Scanner::Location class_name_location, 912 Scanner::Location class_name_location,
927 bool name_is_strict_reserved, int pos, 913 bool name_is_strict_reserved, int pos,
928 bool* ok); 914 bool* ok);
929 915
930 V8_INLINE void MarkCollectedTailCallExpressions() {} 916 V8_INLINE void MarkCollectedTailCallExpressions() {}
931 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} 917 V8_INLINE void MarkTailPosition(PreParserExpression expression) {}
932 918
933 PreParserExpressionList PrepareSpreadArguments(PreParserExpressionList list) { 919 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
920
921 struct TemplateLiteralState {};
922
923 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
924 return TemplateLiteralState();
925 }
926 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
927 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
928 PreParserExpression expression) {}
929 V8_INLINE PreParserExpression CloseTemplateLiteral(
930 TemplateLiteralState* state, int start, PreParserExpression tag);
931 V8_INLINE PreParserExpression NoTemplateTag() {
932 return PreParserExpression::NoTemplateTag();
933 }
934 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) {
935 return !tag.IsNoTemplateTag();
936 }
937
938 V8_INLINE PreParserExpressionList
939 PrepareSpreadArguments(PreParserExpressionList list) {
934 return list; 940 return list;
935 } 941 }
936 942
937 inline void MaterializeUnspreadArgumentsLiterals(int count); 943 inline void MaterializeUnspreadArgumentsLiterals(int count);
938 944
939 inline PreParserExpression SpreadCall(PreParserExpression function, 945 inline PreParserExpression SpreadCall(PreParserExpression function,
940 PreParserExpressionList args, int pos); 946 PreParserExpressionList args, int pos);
941 947
942 inline PreParserExpression SpreadCallNew(PreParserExpression function, 948 inline PreParserExpression SpreadCallNew(PreParserExpression function,
943 PreParserExpressionList args, 949 PreParserExpressionList args,
944 int pos); 950 int pos);
945 951
946 inline PreParserExpression ExpressionListToExpression( 952 inline PreParserExpression ExpressionListToExpression(
947 PreParserExpressionList args) { 953 PreParserExpressionList args) {
948 return PreParserExpression::Default(); 954 return PreParserExpression::Default();
949 } 955 }
950 956
951 inline void RewriteDestructuringAssignments() {} 957 inline void RewriteDestructuringAssignments() {}
952 958
953 inline PreParserExpression RewriteExponentiation(PreParserExpression left, 959 inline PreParserExpression RewriteExponentiation(PreParserExpression left,
954 PreParserExpression right, 960 PreParserExpression right,
955 int pos) { 961 int pos) {
956 return left; 962 return left;
957 } 963 }
958 inline PreParserExpression RewriteAssignExponentiation( 964 inline PreParserExpression RewriteAssignExponentiation(
959 PreParserExpression left, PreParserExpression right, int pos) { 965 PreParserExpression left, PreParserExpression right, int pos) {
960 return left; 966 return left;
961 } 967 }
968 inline PreParserExpression RewriteAwaitExpression(PreParserExpression value,
969 int pos);
962 970
963 inline void QueueDestructuringAssignmentForRewriting( 971 inline void QueueDestructuringAssignmentForRewriting(
964 PreParserExpression assignment) {} 972 PreParserExpression assignment) {}
965 inline void QueueNonPatternForRewriting(PreParserExpression expr, bool* ok) {} 973 inline void QueueNonPatternForRewriting(PreParserExpression expr, bool* ok) {}
966 974
967 void SetFunctionNameFromPropertyName(PreParserExpression property, 975 void SetFunctionNameFromPropertyName(PreParserExpression property,
968 PreParserIdentifier name) {} 976 PreParserIdentifier name) {}
969 void SetFunctionNameFromIdentifierRef(PreParserExpression value, 977 void SetFunctionNameFromIdentifierRef(PreParserExpression value,
970 PreParserExpression identifier) {} 978 PreParserExpression identifier) {}
971 979
972 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, 980 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier,
973 bool* ok); 981 bool* ok);
974 982
975 inline PreParserExpression RewriteAwaitExpression(PreParserExpression value,
976 int pos);
977
978 V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>* 983 V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
979 GetReportedErrorList() const; 984 GetReportedErrorList() const;
980 V8_INLINE Zone* zone() const; 985 V8_INLINE Zone* zone() const;
981 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; 986 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
982 987
983 inline PreParserExpression RewriteYieldStar(PreParserExpression generator, 988 inline PreParserExpression RewriteYieldStar(PreParserExpression generator,
984 PreParserExpression expression, 989 PreParserExpression expression,
985 int pos); 990 int pos);
986 991
987 private: 992 private:
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 pre_parser_->function_state_->NextMaterializedLiteralIndex(); 1256 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1252 pre_parser_->function_state_->NextMaterializedLiteralIndex(); 1257 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1253 } 1258 }
1254 return EmptyExpression(); 1259 return EmptyExpression();
1255 } 1260 }
1256 1261
1257 } // namespace internal 1262 } // namespace internal
1258 } // namespace v8 1263 } // namespace v8
1259 1264
1260 #endif // V8_PARSING_PREPARSER_H 1265 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698