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

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

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase over generator change cl Created 4 years, 8 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
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/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 static PreParserIdentifier Yield() { 49 static PreParserIdentifier Yield() {
50 return PreParserIdentifier(kYieldIdentifier); 50 return PreParserIdentifier(kYieldIdentifier);
51 } 51 }
52 static PreParserIdentifier Prototype() { 52 static PreParserIdentifier Prototype() {
53 return PreParserIdentifier(kPrototypeIdentifier); 53 return PreParserIdentifier(kPrototypeIdentifier);
54 } 54 }
55 static PreParserIdentifier Constructor() { 55 static PreParserIdentifier Constructor() {
56 return PreParserIdentifier(kConstructorIdentifier); 56 return PreParserIdentifier(kConstructorIdentifier);
57 } 57 }
58 static PreParserIdentifier Async() {
59 return PreParserIdentifier(kAsyncIdentifier);
60 }
61 static PreParserIdentifier Await() {
62 return PreParserIdentifier(kAwaitIdentifier);
63 }
58 bool IsEval() const { return type_ == kEvalIdentifier; } 64 bool IsEval() const { return type_ == kEvalIdentifier; }
59 bool IsArguments() const { return type_ == kArgumentsIdentifier; } 65 bool IsArguments() const { return type_ == kArgumentsIdentifier; }
60 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } 66 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
61 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } 67 bool IsUndefined() const { return type_ == kUndefinedIdentifier; }
62 bool IsLet() const { return type_ == kLetIdentifier; } 68 bool IsLet() const { return type_ == kLetIdentifier; }
63 bool IsStatic() const { return type_ == kStaticIdentifier; } 69 bool IsStatic() const { return type_ == kStaticIdentifier; }
64 bool IsYield() const { return type_ == kYieldIdentifier; } 70 bool IsYield() const { return type_ == kYieldIdentifier; }
65 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } 71 bool IsPrototype() const { return type_ == kPrototypeIdentifier; }
66 bool IsConstructor() const { return type_ == kConstructorIdentifier; } 72 bool IsConstructor() const { return type_ == kConstructorIdentifier; }
67 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } 73 bool IsFutureReserved() const {
74 // TODO(caitp): include `kAwaitIdentifier` when parsing a Module
75 return type_ == kFutureReservedIdentifier;
76 }
77 bool IsAsync() const { return type_ == kAsyncIdentifier; }
78 bool IsAwait() const { return type_ == kAwaitIdentifier; }
68 bool IsFutureStrictReserved() const { 79 bool IsFutureStrictReserved() const {
69 return type_ == kFutureStrictReservedIdentifier || 80 return type_ == kFutureStrictReservedIdentifier ||
70 type_ == kLetIdentifier || type_ == kStaticIdentifier || 81 type_ == kLetIdentifier || type_ == kStaticIdentifier ||
71 type_ == kYieldIdentifier; 82 type_ == kYieldIdentifier;
72 } 83 }
73 84
74 // Allow identifier->name()[->length()] to work. The preparser 85 // Allow identifier->name()[->length()] to work. The preparser
75 // does not need the actual positions/lengths of the identifiers. 86 // does not need the actual positions/lengths of the identifiers.
76 const PreParserIdentifier* operator->() const { return this; } 87 const PreParserIdentifier* operator->() const { return this; }
77 const PreParserIdentifier raw_name() const { return *this; } 88 const PreParserIdentifier raw_name() const { return *this; }
78 89
79 int position() const { return 0; } 90 int position() const { return 0; }
80 int length() const { return 0; } 91 int length() const { return 0; }
81 92
82 private: 93 private:
83 enum Type { 94 enum Type {
84 kUnknownIdentifier, 95 kUnknownIdentifier,
85 kFutureReservedIdentifier, 96 kFutureReservedIdentifier,
86 kFutureStrictReservedIdentifier, 97 kFutureStrictReservedIdentifier,
87 kLetIdentifier, 98 kLetIdentifier,
88 kStaticIdentifier, 99 kStaticIdentifier,
89 kYieldIdentifier, 100 kYieldIdentifier,
90 kEvalIdentifier, 101 kEvalIdentifier,
91 kArgumentsIdentifier, 102 kArgumentsIdentifier,
92 kUndefinedIdentifier, 103 kUndefinedIdentifier,
93 kPrototypeIdentifier, 104 kPrototypeIdentifier,
94 kConstructorIdentifier 105 kConstructorIdentifier,
106 kAsyncIdentifier,
107 kAwaitIdentifier
95 }; 108 };
96 109
97 explicit PreParserIdentifier(Type type) : type_(type) {} 110 explicit PreParserIdentifier(Type type) : type_(type) {}
98 Type type_; 111 Type type_;
99 112
100 friend class PreParserExpression; 113 friend class PreParserExpression;
101 }; 114 };
102 115
103 116
104 class PreParserExpression { 117 class PreParserExpression {
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 603
591 // Helper functions for recursive descent. 604 // Helper functions for recursive descent.
592 static bool IsEval(PreParserIdentifier identifier) { 605 static bool IsEval(PreParserIdentifier identifier) {
593 return identifier.IsEval(); 606 return identifier.IsEval();
594 } 607 }
595 608
596 static bool IsArguments(PreParserIdentifier identifier) { 609 static bool IsArguments(PreParserIdentifier identifier) {
597 return identifier.IsArguments(); 610 return identifier.IsArguments();
598 } 611 }
599 612
613 static bool IsAsync(PreParserIdentifier identifier) {
614 return identifier.IsAsync();
615 }
616
617 static bool IsAwait(PreParserIdentifier identifier) {
618 return identifier.IsAwait();
619 }
620
600 static bool IsEvalOrArguments(PreParserIdentifier identifier) { 621 static bool IsEvalOrArguments(PreParserIdentifier identifier) {
601 return identifier.IsEvalOrArguments(); 622 return identifier.IsEvalOrArguments();
602 } 623 }
603 624
604 static bool IsUndefined(PreParserIdentifier identifier) { 625 static bool IsUndefined(PreParserIdentifier identifier) {
605 return identifier.IsUndefined(); 626 return identifier.IsUndefined();
606 } 627 }
607 628
608 static bool IsPrototype(PreParserIdentifier identifier) { 629 static bool IsPrototype(PreParserIdentifier identifier) {
609 return identifier.IsPrototype(); 630 return identifier.IsPrototype();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 846 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
826 PreParserIdentifier function_name, int pos, 847 PreParserIdentifier function_name, int pos,
827 const PreParserFormalParameters& parameters, FunctionKind kind, 848 const PreParserFormalParameters& parameters, FunctionKind kind,
828 FunctionLiteral::FunctionType function_type, bool* ok); 849 FunctionLiteral::FunctionType function_type, bool* ok);
829 850
830 V8_INLINE void ParseArrowFunctionFormalParameterList( 851 V8_INLINE void ParseArrowFunctionFormalParameterList(
831 PreParserFormalParameters* parameters, 852 PreParserFormalParameters* parameters,
832 PreParserExpression expression, const Scanner::Location& params_loc, 853 PreParserExpression expression, const Scanner::Location& params_loc,
833 Scanner::Location* duplicate_loc, bool* ok); 854 Scanner::Location* duplicate_loc, bool* ok);
834 855
856 V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok);
857
835 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} 858 void ReindexLiterals(const PreParserFormalParameters& paramaters) {}
836 859
837 struct TemplateLiteralState {}; 860 struct TemplateLiteralState {};
838 861
839 TemplateLiteralState OpenTemplateLiteral(int pos) { 862 TemplateLiteralState OpenTemplateLiteral(int pos) {
840 return TemplateLiteralState(); 863 return TemplateLiteralState();
841 } 864 }
842 void AddTemplateSpan(TemplateLiteralState*, bool) {} 865 void AddTemplateSpan(TemplateLiteralState*, bool) {}
843 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 866 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
844 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 867 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 916
894 inline void MaterializeUnspreadArgumentsLiterals(int count); 917 inline void MaterializeUnspreadArgumentsLiterals(int count);
895 918
896 inline PreParserExpression SpreadCall(PreParserExpression function, 919 inline PreParserExpression SpreadCall(PreParserExpression function,
897 PreParserExpressionList args, int pos); 920 PreParserExpressionList args, int pos);
898 921
899 inline PreParserExpression SpreadCallNew(PreParserExpression function, 922 inline PreParserExpression SpreadCallNew(PreParserExpression function,
900 PreParserExpressionList args, 923 PreParserExpressionList args,
901 int pos); 924 int pos);
902 925
926 inline PreParserExpression ExpressionListToExpression(
927 PreParserExpressionList args) {
928 return PreParserExpression::Default();
929 }
930
903 inline void RewriteDestructuringAssignments() {} 931 inline void RewriteDestructuringAssignments() {}
904 932
905 inline PreParserExpression RewriteExponentiation(PreParserExpression left, 933 inline PreParserExpression RewriteExponentiation(PreParserExpression left,
906 PreParserExpression right, 934 PreParserExpression right,
907 int pos) { 935 int pos) {
908 return left; 936 return left;
909 } 937 }
910 inline PreParserExpression RewriteAssignExponentiation( 938 inline PreParserExpression RewriteAssignExponentiation(
911 PreParserExpression left, PreParserExpression right, int pos) { 939 PreParserExpression left, PreParserExpression right, int pos) {
912 return left; 940 return left;
913 } 941 }
914 942
915 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} 943 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {}
916 inline void QueueNonPatternForRewriting(PreParserExpression) {} 944 inline void QueueNonPatternForRewriting(PreParserExpression) {}
917 945
918 void SetFunctionNameFromPropertyName(PreParserExpression, 946 void SetFunctionNameFromPropertyName(PreParserExpression,
919 PreParserIdentifier) {} 947 PreParserIdentifier) {}
920 void SetFunctionNameFromIdentifierRef(PreParserExpression, 948 void SetFunctionNameFromIdentifierRef(PreParserExpression,
921 PreParserExpression) {} 949 PreParserExpression) {}
922 950
923 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, 951 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier,
924 bool* ok); 952 bool* ok);
925 953
954 inline PreParserExpression RewriteAwaitExpression(PreParserExpression value,
955 int pos);
956
926 V8_INLINE Zone* zone() const; 957 V8_INLINE Zone* zone() const;
927 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; 958 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
928 959
929 inline PreParserExpression RewriteYieldStar( 960 inline PreParserExpression RewriteYieldStar(
930 PreParserExpression generator, PreParserExpression expr, int pos); 961 PreParserExpression generator, PreParserExpression expr, int pos);
931 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs, 962 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs,
932 PreParserExpression rhs, 963 PreParserExpression rhs,
933 int pos); 964 int pos);
934 965
935 private: 966 private:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 // for failure at the call sites. 1049 // for failure at the call sites.
1019 Statement ParseStatementListItem(bool* ok); 1050 Statement ParseStatementListItem(bool* ok);
1020 void ParseStatementList(int end_token, bool* ok, 1051 void ParseStatementList(int end_token, bool* ok,
1021 Scanner::BookmarkScope* bookmark = nullptr); 1052 Scanner::BookmarkScope* bookmark = nullptr);
1022 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, 1053 Statement ParseStatement(AllowLabelledFunctionStatement allow_function,
1023 bool* ok); 1054 bool* ok);
1024 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, 1055 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function,
1025 bool* ok); 1056 bool* ok);
1026 Statement ParseScopedStatement(bool legacy, bool* ok); 1057 Statement ParseScopedStatement(bool legacy, bool* ok);
1027 Statement ParseFunctionDeclaration(bool* ok); 1058 Statement ParseFunctionDeclaration(bool* ok);
1059 Statement ParseAsyncFunctionDeclaration(bool* ok);
1060 Expression ParseAsyncFunctionExpression(bool* ok);
1028 Statement ParseClassDeclaration(bool* ok); 1061 Statement ParseClassDeclaration(bool* ok);
1029 Statement ParseBlock(bool* ok); 1062 Statement ParseBlock(bool* ok);
1030 Statement ParseVariableStatement(VariableDeclarationContext var_context, 1063 Statement ParseVariableStatement(VariableDeclarationContext var_context,
1031 bool* ok); 1064 bool* ok);
1032 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, 1065 Statement ParseVariableDeclarations(VariableDeclarationContext var_context,
1033 int* num_decl, bool* is_lexical, 1066 int* num_decl, bool* is_lexical,
1034 bool* is_binding_pattern, 1067 bool* is_binding_pattern,
1035 Scanner::Location* first_initializer_loc, 1068 Scanner::Location* first_initializer_loc,
1036 Scanner::Location* bindings_loc, 1069 Scanner::Location* bindings_loc,
1037 bool* ok); 1070 bool* ok);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 1136
1104 1137
1105 void PreParserTraits::ParseArrowFunctionFormalParameterList( 1138 void PreParserTraits::ParseArrowFunctionFormalParameterList(
1106 PreParserFormalParameters* parameters, 1139 PreParserFormalParameters* parameters,
1107 PreParserExpression params, const Scanner::Location& params_loc, 1140 PreParserExpression params, const Scanner::Location& params_loc,
1108 Scanner::Location* duplicate_loc, bool* ok) { 1141 Scanner::Location* duplicate_loc, bool* ok) {
1109 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1142 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1110 // lists that are too long. 1143 // lists that are too long.
1111 } 1144 }
1112 1145
1146 PreParserExpression PreParserTraits::ParseAsyncFunctionExpression(bool* ok) {
1147 return pre_parser_->ParseAsyncFunctionExpression(ok);
1148 }
1113 1149
1114 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { 1150 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) {
1115 return pre_parser_->ParseDoExpression(ok); 1151 return pre_parser_->ParseDoExpression(ok);
1116 } 1152 }
1117 1153
1118 1154
1119 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, 1155 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
1120 bool* ok) { 1156 bool* ok) {
1121 pre_parser_->ValidateExpression(classifier, ok); 1157 pre_parser_->ValidateExpression(classifier, ok);
1122 } 1158 }
1123 1159
1160 PreParserExpression PreParserTraits::RewriteAwaitExpression(
1161 PreParserExpression value, int pos) {
1162 return value;
1163 }
1124 1164
1125 Zone* PreParserTraits::zone() const { 1165 Zone* PreParserTraits::zone() const {
1126 return pre_parser_->function_state_->scope()->zone(); 1166 return pre_parser_->function_state_->scope()->zone();
1127 } 1167 }
1128 1168
1129 1169
1130 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { 1170 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const {
1131 return pre_parser_->function_state_->non_patterns_to_rewrite(); 1171 return pre_parser_->function_state_->non_patterns_to_rewrite();
1132 } 1172 }
1133 1173
(...skipping 28 matching lines...) Expand all
1162 const PreParserFormalParameters& parameters, FunctionKind kind, 1202 const PreParserFormalParameters& parameters, FunctionKind kind,
1163 FunctionLiteral::FunctionType function_type, bool* ok) { 1203 FunctionLiteral::FunctionType function_type, bool* ok) {
1164 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, 1204 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters,
1165 kind, function_type, ok); 1205 kind, function_type, ok);
1166 } 1206 }
1167 1207
1168 } // namespace internal 1208 } // namespace internal
1169 } // namespace v8 1209 } // namespace v8
1170 1210
1171 #endif // V8_PARSING_PREPARSER_H 1211 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/parser-base.h ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698