Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Enum() { | 58 static PreParserIdentifier Enum() { |
| 59 return PreParserIdentifier(kEnumIdentifier); | 59 return PreParserIdentifier(kEnumIdentifier); |
| 60 } | 60 } |
| 61 static PreParserIdentifier Async() { | |
| 62 return PreParserIdentifier(kAsyncIdentifier); | |
| 63 } | |
| 61 static PreParserIdentifier Await() { | 64 static PreParserIdentifier Await() { |
| 62 return PreParserIdentifier(kAwaitIdentifier); | 65 return PreParserIdentifier(kAwaitIdentifier); |
| 63 } | 66 } |
| 64 bool IsEval() const { return type_ == kEvalIdentifier; } | 67 bool IsEval() const { return type_ == kEvalIdentifier; } |
| 65 bool IsArguments() const { return type_ == kArgumentsIdentifier; } | 68 bool IsArguments() const { return type_ == kArgumentsIdentifier; } |
| 66 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } | 69 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } |
| 67 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } | 70 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } |
| 68 bool IsLet() const { return type_ == kLetIdentifier; } | 71 bool IsLet() const { return type_ == kLetIdentifier; } |
| 69 bool IsStatic() const { return type_ == kStaticIdentifier; } | 72 bool IsStatic() const { return type_ == kStaticIdentifier; } |
| 70 bool IsYield() const { return type_ == kYieldIdentifier; } | 73 bool IsYield() const { return type_ == kYieldIdentifier; } |
| 71 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } | 74 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } |
| 72 bool IsConstructor() const { return type_ == kConstructorIdentifier; } | 75 bool IsConstructor() const { return type_ == kConstructorIdentifier; } |
| 73 bool IsEnum() const { return type_ == kEnumIdentifier; } | 76 bool IsEnum() const { return type_ == kEnumIdentifier; } |
| 77 bool IsFutureReserved() const { | |
|
Dan Ehrenberg
2016/05/06 00:08:56
Why do you add this? I don't see it used anywhere.
caitp (gmail)
2016/05/06 00:31:03
was originally useful, became redundant but wasnt
| |
| 78 // TODO(caitp): include `kAwaitIdentifier` when parsing a Module | |
| 79 return type_ == kFutureReservedIdentifier; | |
| 80 } | |
| 81 bool IsAsync() const { return type_ == kAsyncIdentifier; } | |
| 74 bool IsAwait() const { return type_ == kAwaitIdentifier; } | 82 bool IsAwait() const { return type_ == kAwaitIdentifier; } |
| 75 bool IsFutureStrictReserved() const { | 83 bool IsFutureStrictReserved() const { |
| 76 return type_ == kFutureStrictReservedIdentifier || | 84 return type_ == kFutureStrictReservedIdentifier || |
| 77 type_ == kLetIdentifier || type_ == kStaticIdentifier || | 85 type_ == kLetIdentifier || type_ == kStaticIdentifier || |
| 78 type_ == kYieldIdentifier; | 86 type_ == kYieldIdentifier; |
| 79 } | 87 } |
| 80 | 88 |
| 81 // Allow identifier->name()[->length()] to work. The preparser | 89 // Allow identifier->name()[->length()] to work. The preparser |
| 82 // does not need the actual positions/lengths of the identifiers. | 90 // does not need the actual positions/lengths of the identifiers. |
| 83 const PreParserIdentifier* operator->() const { return this; } | 91 const PreParserIdentifier* operator->() const { return this; } |
| 84 const PreParserIdentifier raw_name() const { return *this; } | 92 const PreParserIdentifier raw_name() const { return *this; } |
| 85 | 93 |
| 86 int position() const { return 0; } | 94 int position() const { return 0; } |
| 87 int length() const { return 0; } | 95 int length() const { return 0; } |
| 88 | 96 |
| 89 private: | 97 private: |
| 90 enum Type { | 98 enum Type { |
| 91 kUnknownIdentifier, | 99 kUnknownIdentifier, |
| 92 kFutureReservedIdentifier, | 100 kFutureReservedIdentifier, |
| 93 kFutureStrictReservedIdentifier, | 101 kFutureStrictReservedIdentifier, |
| 94 kLetIdentifier, | 102 kLetIdentifier, |
| 95 kStaticIdentifier, | 103 kStaticIdentifier, |
| 96 kYieldIdentifier, | 104 kYieldIdentifier, |
| 97 kEvalIdentifier, | 105 kEvalIdentifier, |
| 98 kArgumentsIdentifier, | 106 kArgumentsIdentifier, |
| 99 kUndefinedIdentifier, | 107 kUndefinedIdentifier, |
| 100 kPrototypeIdentifier, | 108 kPrototypeIdentifier, |
| 101 kConstructorIdentifier, | 109 kConstructorIdentifier, |
| 102 kEnumIdentifier, | 110 kEnumIdentifier, |
| 111 kAsyncIdentifier, | |
| 103 kAwaitIdentifier | 112 kAwaitIdentifier |
| 104 }; | 113 }; |
| 105 | 114 |
| 106 explicit PreParserIdentifier(Type type) : type_(type) {} | 115 explicit PreParserIdentifier(Type type) : type_(type) {} |
| 107 Type type_; | 116 Type type_; |
| 108 | 117 |
| 109 friend class PreParserExpression; | 118 friend class PreParserExpression; |
| 110 }; | 119 }; |
| 111 | 120 |
| 112 | 121 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 | 608 |
| 600 // Helper functions for recursive descent. | 609 // Helper functions for recursive descent. |
| 601 static bool IsEval(PreParserIdentifier identifier) { | 610 static bool IsEval(PreParserIdentifier identifier) { |
| 602 return identifier.IsEval(); | 611 return identifier.IsEval(); |
| 603 } | 612 } |
| 604 | 613 |
| 605 static bool IsArguments(PreParserIdentifier identifier) { | 614 static bool IsArguments(PreParserIdentifier identifier) { |
| 606 return identifier.IsArguments(); | 615 return identifier.IsArguments(); |
| 607 } | 616 } |
| 608 | 617 |
| 618 static bool IsAsync(PreParserIdentifier identifier) { | |
| 619 return identifier.IsAsync(); | |
| 620 } | |
| 621 | |
| 622 static bool IsAwait(PreParserIdentifier identifier) { | |
| 623 return identifier.IsAwait(); | |
| 624 } | |
| 625 | |
| 609 static bool IsEvalOrArguments(PreParserIdentifier identifier) { | 626 static bool IsEvalOrArguments(PreParserIdentifier identifier) { |
| 610 return identifier.IsEvalOrArguments(); | 627 return identifier.IsEvalOrArguments(); |
| 611 } | 628 } |
| 612 | 629 |
| 613 static bool IsUndefined(PreParserIdentifier identifier) { | 630 static bool IsUndefined(PreParserIdentifier identifier) { |
| 614 return identifier.IsUndefined(); | 631 return identifier.IsUndefined(); |
| 615 } | 632 } |
| 616 | 633 |
| 617 static bool IsPrototype(PreParserIdentifier identifier) { | 634 static bool IsPrototype(PreParserIdentifier identifier) { |
| 618 return identifier.IsPrototype(); | 635 return identifier.IsPrototype(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 851 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 835 PreParserIdentifier function_name, int pos, | 852 PreParserIdentifier function_name, int pos, |
| 836 const PreParserFormalParameters& parameters, FunctionKind kind, | 853 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 837 FunctionLiteral::FunctionType function_type, bool* ok); | 854 FunctionLiteral::FunctionType function_type, bool* ok); |
| 838 | 855 |
| 839 V8_INLINE void ParseArrowFunctionFormalParameterList( | 856 V8_INLINE void ParseArrowFunctionFormalParameterList( |
| 840 PreParserFormalParameters* parameters, | 857 PreParserFormalParameters* parameters, |
| 841 PreParserExpression expression, const Scanner::Location& params_loc, | 858 PreParserExpression expression, const Scanner::Location& params_loc, |
| 842 Scanner::Location* duplicate_loc, bool* ok); | 859 Scanner::Location* duplicate_loc, bool* ok); |
| 843 | 860 |
| 861 V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok); | |
| 862 | |
| 844 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} | 863 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} |
| 845 | 864 |
| 846 struct TemplateLiteralState {}; | 865 struct TemplateLiteralState {}; |
| 847 | 866 |
| 848 TemplateLiteralState OpenTemplateLiteral(int pos) { | 867 TemplateLiteralState OpenTemplateLiteral(int pos) { |
| 849 return TemplateLiteralState(); | 868 return TemplateLiteralState(); |
| 850 } | 869 } |
| 851 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 870 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
| 852 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 871 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
| 853 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 872 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 | 925 |
| 907 inline void MaterializeUnspreadArgumentsLiterals(int count); | 926 inline void MaterializeUnspreadArgumentsLiterals(int count); |
| 908 | 927 |
| 909 inline PreParserExpression SpreadCall(PreParserExpression function, | 928 inline PreParserExpression SpreadCall(PreParserExpression function, |
| 910 PreParserExpressionList args, int pos); | 929 PreParserExpressionList args, int pos); |
| 911 | 930 |
| 912 inline PreParserExpression SpreadCallNew(PreParserExpression function, | 931 inline PreParserExpression SpreadCallNew(PreParserExpression function, |
| 913 PreParserExpressionList args, | 932 PreParserExpressionList args, |
| 914 int pos); | 933 int pos); |
| 915 | 934 |
| 935 inline PreParserExpression ExpressionListToExpression( | |
| 936 PreParserExpressionList args) { | |
| 937 return PreParserExpression::Default(); | |
| 938 } | |
| 939 | |
| 916 inline void RewriteDestructuringAssignments() {} | 940 inline void RewriteDestructuringAssignments() {} |
| 917 | 941 |
| 918 inline PreParserExpression RewriteExponentiation(PreParserExpression left, | 942 inline PreParserExpression RewriteExponentiation(PreParserExpression left, |
| 919 PreParserExpression right, | 943 PreParserExpression right, |
| 920 int pos) { | 944 int pos) { |
| 921 return left; | 945 return left; |
| 922 } | 946 } |
| 923 inline PreParserExpression RewriteAssignExponentiation( | 947 inline PreParserExpression RewriteAssignExponentiation( |
| 924 PreParserExpression left, PreParserExpression right, int pos) { | 948 PreParserExpression left, PreParserExpression right, int pos) { |
| 925 return left; | 949 return left; |
| 926 } | 950 } |
| 927 | 951 |
| 928 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} | 952 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} |
| 929 inline void QueueNonPatternForRewriting(PreParserExpression) {} | 953 inline void QueueNonPatternForRewriting(PreParserExpression) {} |
| 930 | 954 |
| 931 void SetFunctionNameFromPropertyName(PreParserExpression, | 955 void SetFunctionNameFromPropertyName(PreParserExpression, |
| 932 PreParserIdentifier) {} | 956 PreParserIdentifier) {} |
| 933 void SetFunctionNameFromIdentifierRef(PreParserExpression, | 957 void SetFunctionNameFromIdentifierRef(PreParserExpression, |
| 934 PreParserExpression) {} | 958 PreParserExpression) {} |
| 935 | 959 |
| 936 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, | 960 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, |
| 937 bool* ok); | 961 bool* ok); |
| 938 | 962 |
| 963 inline PreParserExpression RewriteAwaitExpression(PreParserExpression value, | |
| 964 int pos); | |
| 965 | |
| 939 V8_INLINE Zone* zone() const; | 966 V8_INLINE Zone* zone() const; |
| 940 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; | 967 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; |
| 941 | 968 |
| 942 inline PreParserExpression RewriteYieldStar( | 969 inline PreParserExpression RewriteYieldStar( |
| 943 PreParserExpression generator, PreParserExpression expr, int pos); | 970 PreParserExpression generator, PreParserExpression expr, int pos); |
| 944 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs, | 971 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs, |
| 945 PreParserExpression rhs, | 972 PreParserExpression rhs, |
| 946 int pos); | 973 int pos); |
| 947 | 974 |
| 948 private: | 975 private: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 void ParseStatementList(int end_token, bool* ok, | 1074 void ParseStatementList(int end_token, bool* ok, |
| 1048 Scanner::BookmarkScope* bookmark = nullptr); | 1075 Scanner::BookmarkScope* bookmark = nullptr); |
| 1049 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, | 1076 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, |
| 1050 bool* ok); | 1077 bool* ok); |
| 1051 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, | 1078 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, |
| 1052 bool* ok); | 1079 bool* ok); |
| 1053 Statement ParseScopedStatement(bool legacy, bool* ok); | 1080 Statement ParseScopedStatement(bool legacy, bool* ok); |
| 1054 Statement ParseHoistableDeclaration(bool* ok); | 1081 Statement ParseHoistableDeclaration(bool* ok); |
| 1055 Statement ParseHoistableDeclaration(int pos, bool is_generator, bool* ok); | 1082 Statement ParseHoistableDeclaration(int pos, bool is_generator, bool* ok); |
| 1056 Statement ParseFunctionDeclaration(bool* ok); | 1083 Statement ParseFunctionDeclaration(bool* ok); |
| 1084 Statement ParseAsyncFunctionDeclaration(bool* ok); | |
| 1085 Expression ParseAsyncFunctionExpression(bool* ok); | |
| 1057 Statement ParseClassDeclaration(bool* ok); | 1086 Statement ParseClassDeclaration(bool* ok); |
| 1058 Statement ParseBlock(bool* ok); | 1087 Statement ParseBlock(bool* ok); |
| 1059 Statement ParseVariableStatement(VariableDeclarationContext var_context, | 1088 Statement ParseVariableStatement(VariableDeclarationContext var_context, |
| 1060 bool* ok); | 1089 bool* ok); |
| 1061 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, | 1090 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 1062 int* num_decl, bool* is_lexical, | 1091 int* num_decl, bool* is_lexical, |
| 1063 bool* is_binding_pattern, | 1092 bool* is_binding_pattern, |
| 1064 Scanner::Location* first_initializer_loc, | 1093 Scanner::Location* first_initializer_loc, |
| 1065 Scanner::Location* bindings_loc, | 1094 Scanner::Location* bindings_loc, |
| 1066 bool* ok); | 1095 bool* ok); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 | 1164 |
| 1136 | 1165 |
| 1137 void PreParserTraits::ParseArrowFunctionFormalParameterList( | 1166 void PreParserTraits::ParseArrowFunctionFormalParameterList( |
| 1138 PreParserFormalParameters* parameters, | 1167 PreParserFormalParameters* parameters, |
| 1139 PreParserExpression params, const Scanner::Location& params_loc, | 1168 PreParserExpression params, const Scanner::Location& params_loc, |
| 1140 Scanner::Location* duplicate_loc, bool* ok) { | 1169 Scanner::Location* duplicate_loc, bool* ok) { |
| 1141 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1170 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
| 1142 // lists that are too long. | 1171 // lists that are too long. |
| 1143 } | 1172 } |
| 1144 | 1173 |
| 1174 PreParserExpression PreParserTraits::ParseAsyncFunctionExpression(bool* ok) { | |
| 1175 return pre_parser_->ParseAsyncFunctionExpression(ok); | |
| 1176 } | |
| 1145 | 1177 |
| 1146 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { | 1178 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { |
| 1147 return pre_parser_->ParseDoExpression(ok); | 1179 return pre_parser_->ParseDoExpression(ok); |
| 1148 } | 1180 } |
| 1149 | 1181 |
| 1150 | 1182 |
| 1151 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 1183 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
| 1152 bool* ok) { | 1184 bool* ok) { |
| 1153 pre_parser_->ValidateExpression(classifier, ok); | 1185 pre_parser_->ValidateExpression(classifier, ok); |
| 1154 } | 1186 } |
| 1155 | 1187 |
| 1188 PreParserExpression PreParserTraits::RewriteAwaitExpression( | |
| 1189 PreParserExpression value, int pos) { | |
| 1190 return value; | |
| 1191 } | |
| 1156 | 1192 |
| 1157 Zone* PreParserTraits::zone() const { | 1193 Zone* PreParserTraits::zone() const { |
| 1158 return pre_parser_->function_state_->scope()->zone(); | 1194 return pre_parser_->function_state_->scope()->zone(); |
| 1159 } | 1195 } |
| 1160 | 1196 |
| 1161 | 1197 |
| 1162 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { | 1198 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { |
| 1163 return pre_parser_->function_state_->non_patterns_to_rewrite(); | 1199 return pre_parser_->function_state_->non_patterns_to_rewrite(); |
| 1164 } | 1200 } |
| 1165 | 1201 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1200 const PreParserFormalParameters& parameters, FunctionKind kind, | 1236 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1201 FunctionLiteral::FunctionType function_type, bool* ok) { | 1237 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1202 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1238 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
| 1203 kind, function_type, ok); | 1239 kind, function_type, ok); |
| 1204 } | 1240 } |
| 1205 | 1241 |
| 1206 } // namespace internal | 1242 } // namespace internal |
| 1207 } // namespace v8 | 1243 } // namespace v8 |
| 1208 | 1244 |
| 1209 #endif // V8_PARSING_PREPARSER_H | 1245 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |