| 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_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 stack_limit_(stack_limit), | 189 stack_limit_(stack_limit), |
| 190 zone_(zone), | 190 zone_(zone), |
| 191 scanner_(scanner), | 191 scanner_(scanner), |
| 192 stack_overflow_(false), | 192 stack_overflow_(false), |
| 193 allow_lazy_(false), | 193 allow_lazy_(false), |
| 194 allow_natives_(false), | 194 allow_natives_(false), |
| 195 allow_tailcalls_(false), | 195 allow_tailcalls_(false), |
| 196 allow_harmony_restrictive_declarations_(false), | 196 allow_harmony_restrictive_declarations_(false), |
| 197 allow_harmony_do_expressions_(false), | 197 allow_harmony_do_expressions_(false), |
| 198 allow_harmony_for_in_(false), | 198 allow_harmony_for_in_(false), |
| 199 allow_harmony_function_name_(false), | |
| 200 allow_harmony_function_sent_(false), | 199 allow_harmony_function_sent_(false), |
| 201 allow_harmony_async_await_(false), | 200 allow_harmony_async_await_(false), |
| 202 allow_harmony_restrictive_generators_(false) {} | 201 allow_harmony_restrictive_generators_(false) {} |
| 203 | 202 |
| 204 #define ALLOW_ACCESSORS(name) \ | 203 #define ALLOW_ACCESSORS(name) \ |
| 205 bool allow_##name() const { return allow_##name##_; } \ | 204 bool allow_##name() const { return allow_##name##_; } \ |
| 206 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 205 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 207 | 206 |
| 208 #define SCANNER_ACCESSORS(name) \ | 207 #define SCANNER_ACCESSORS(name) \ |
| 209 bool allow_##name() const { return scanner_->allow_##name(); } \ | 208 bool allow_##name() const { return scanner_->allow_##name(); } \ |
| 210 void set_allow_##name(bool allow) { \ | 209 void set_allow_##name(bool allow) { \ |
| 211 return scanner_->set_allow_##name(allow); \ | 210 return scanner_->set_allow_##name(allow); \ |
| 212 } | 211 } |
| 213 | 212 |
| 214 ALLOW_ACCESSORS(lazy); | 213 ALLOW_ACCESSORS(lazy); |
| 215 ALLOW_ACCESSORS(natives); | 214 ALLOW_ACCESSORS(natives); |
| 216 ALLOW_ACCESSORS(tailcalls); | 215 ALLOW_ACCESSORS(tailcalls); |
| 217 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 216 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
| 218 ALLOW_ACCESSORS(harmony_do_expressions); | 217 ALLOW_ACCESSORS(harmony_do_expressions); |
| 219 ALLOW_ACCESSORS(harmony_for_in); | 218 ALLOW_ACCESSORS(harmony_for_in); |
| 220 ALLOW_ACCESSORS(harmony_function_name); | |
| 221 ALLOW_ACCESSORS(harmony_function_sent); | 219 ALLOW_ACCESSORS(harmony_function_sent); |
| 222 ALLOW_ACCESSORS(harmony_async_await); | 220 ALLOW_ACCESSORS(harmony_async_await); |
| 223 ALLOW_ACCESSORS(harmony_restrictive_generators); | 221 ALLOW_ACCESSORS(harmony_restrictive_generators); |
| 224 SCANNER_ACCESSORS(harmony_exponentiation_operator); | 222 SCANNER_ACCESSORS(harmony_exponentiation_operator); |
| 225 | 223 |
| 226 #undef SCANNER_ACCESSORS | 224 #undef SCANNER_ACCESSORS |
| 227 #undef ALLOW_ACCESSORS | 225 #undef ALLOW_ACCESSORS |
| 228 | 226 |
| 229 uintptr_t stack_limit() const { return stack_limit_; } | 227 uintptr_t stack_limit() const { return stack_limit_; } |
| 230 | 228 |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 | 1179 |
| 1182 Scanner* scanner_; | 1180 Scanner* scanner_; |
| 1183 bool stack_overflow_; | 1181 bool stack_overflow_; |
| 1184 | 1182 |
| 1185 bool allow_lazy_; | 1183 bool allow_lazy_; |
| 1186 bool allow_natives_; | 1184 bool allow_natives_; |
| 1187 bool allow_tailcalls_; | 1185 bool allow_tailcalls_; |
| 1188 bool allow_harmony_restrictive_declarations_; | 1186 bool allow_harmony_restrictive_declarations_; |
| 1189 bool allow_harmony_do_expressions_; | 1187 bool allow_harmony_do_expressions_; |
| 1190 bool allow_harmony_for_in_; | 1188 bool allow_harmony_for_in_; |
| 1191 bool allow_harmony_function_name_; | |
| 1192 bool allow_harmony_function_sent_; | 1189 bool allow_harmony_function_sent_; |
| 1193 bool allow_harmony_async_await_; | 1190 bool allow_harmony_async_await_; |
| 1194 bool allow_harmony_restrictive_generators_; | 1191 bool allow_harmony_restrictive_generators_; |
| 1195 }; | 1192 }; |
| 1196 | 1193 |
| 1197 template <class Traits> | 1194 template <class Traits> |
| 1198 ParserBase<Traits>::FunctionState::FunctionState( | 1195 ParserBase<Traits>::FunctionState::FunctionState( |
| 1199 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1196 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
| 1200 FunctionKind kind, typename Traits::Type::Factory* factory) | 1197 FunctionKind kind, typename Traits::Type::Factory* factory) |
| 1201 : next_materialized_literal_index_(0), | 1198 : next_materialized_literal_index_(0), |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 Traits::RewriteNonPattern(&rhs_classifier, | 1963 Traits::RewriteNonPattern(&rhs_classifier, |
| 1967 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1964 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1968 classifier->Accumulate(&rhs_classifier, | 1965 classifier->Accumulate(&rhs_classifier, |
| 1969 ExpressionClassifier::ExpressionProductions); | 1966 ExpressionClassifier::ExpressionProductions); |
| 1970 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1967 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
| 1971 RelocInfo::kNoPosition); | 1968 RelocInfo::kNoPosition); |
| 1972 classifier->RecordCoverInitializedNameError( | 1969 classifier->RecordCoverInitializedNameError( |
| 1973 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1970 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 1974 MessageTemplate::kInvalidCoverInitializedName); | 1971 MessageTemplate::kInvalidCoverInitializedName); |
| 1975 | 1972 |
| 1976 if (allow_harmony_function_name()) { | 1973 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); |
| 1977 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); | |
| 1978 } | |
| 1979 } else { | 1974 } else { |
| 1980 value = lhs; | 1975 value = lhs; |
| 1981 } | 1976 } |
| 1982 | 1977 |
| 1983 return factory()->NewObjectLiteralProperty( | 1978 return factory()->NewObjectLiteralProperty( |
| 1984 name_expression, value, ObjectLiteralProperty::COMPUTED, is_static, | 1979 name_expression, value, ObjectLiteralProperty::COMPUTED, is_static, |
| 1985 false); | 1980 false); |
| 1986 } | 1981 } |
| 1987 } | 1982 } |
| 1988 | 1983 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 } | 2118 } |
| 2124 properties->Add(property, zone()); | 2119 properties->Add(property, zone()); |
| 2125 | 2120 |
| 2126 if (peek() != Token::RBRACE) { | 2121 if (peek() != Token::RBRACE) { |
| 2127 // Need {} because of the CHECK_OK macro. | 2122 // Need {} because of the CHECK_OK macro. |
| 2128 Expect(Token::COMMA, CHECK_OK); | 2123 Expect(Token::COMMA, CHECK_OK); |
| 2129 } | 2124 } |
| 2130 | 2125 |
| 2131 if (fni_ != nullptr) fni_->Infer(); | 2126 if (fni_ != nullptr) fni_->Infer(); |
| 2132 | 2127 |
| 2133 if (allow_harmony_function_name()) { | 2128 Traits::SetFunctionNameFromPropertyName(property, name); |
| 2134 Traits::SetFunctionNameFromPropertyName(property, name); | |
| 2135 } | |
| 2136 } | 2129 } |
| 2137 Expect(Token::RBRACE, CHECK_OK); | 2130 Expect(Token::RBRACE, CHECK_OK); |
| 2138 | 2131 |
| 2139 // Computation of literal_index must happen before pre parse bailout. | 2132 // Computation of literal_index must happen before pre parse bailout. |
| 2140 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2133 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
| 2141 | 2134 |
| 2142 return factory()->NewObjectLiteral(properties, | 2135 return factory()->NewObjectLiteral(properties, |
| 2143 literal_index, | 2136 literal_index, |
| 2144 number_of_boilerplate_properties, | 2137 number_of_boilerplate_properties, |
| 2145 pos); | 2138 pos); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 // name if we're dealing with "a = function(){...}();"-like | 2373 // name if we're dealing with "a = function(){...}();"-like |
| 2381 // expression. | 2374 // expression. |
| 2382 if ((op == Token::INIT || op == Token::ASSIGN) && | 2375 if ((op == Token::INIT || op == Token::ASSIGN) && |
| 2383 (!right->IsCall() && !right->IsCallNew())) { | 2376 (!right->IsCall() && !right->IsCallNew())) { |
| 2384 fni_->Infer(); | 2377 fni_->Infer(); |
| 2385 } else { | 2378 } else { |
| 2386 fni_->RemoveLastFunction(); | 2379 fni_->RemoveLastFunction(); |
| 2387 } | 2380 } |
| 2388 } | 2381 } |
| 2389 | 2382 |
| 2390 if (op == Token::ASSIGN && allow_harmony_function_name()) { | 2383 if (op == Token::ASSIGN) { |
| 2391 Traits::SetFunctionNameFromIdentifierRef(right, expression); | 2384 Traits::SetFunctionNameFromIdentifierRef(right, expression); |
| 2392 } | 2385 } |
| 2393 | 2386 |
| 2394 if (op == Token::ASSIGN_EXP) { | 2387 if (op == Token::ASSIGN_EXP) { |
| 2395 DCHECK(!is_destructuring_assignment); | 2388 DCHECK(!is_destructuring_assignment); |
| 2396 return Traits::RewriteAssignExponentiation(expression, right, pos); | 2389 return Traits::RewriteAssignExponentiation(expression, right, pos); |
| 2397 } | 2390 } |
| 2398 | 2391 |
| 2399 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2392 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
| 2400 | 2393 |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3178 ExpressionClassifier init_classifier(this); | 3171 ExpressionClassifier init_classifier(this); |
| 3179 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 3172 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
| 3180 if (!*ok) return; | 3173 if (!*ok) return; |
| 3181 Traits::RewriteNonPattern(&init_classifier, ok); | 3174 Traits::RewriteNonPattern(&init_classifier, ok); |
| 3182 ValidateFormalParameterInitializer(&init_classifier, ok); | 3175 ValidateFormalParameterInitializer(&init_classifier, ok); |
| 3183 if (!*ok) return; | 3176 if (!*ok) return; |
| 3184 parameters->is_simple = false; | 3177 parameters->is_simple = false; |
| 3185 init_classifier.Discard(); | 3178 init_classifier.Discard(); |
| 3186 classifier->RecordNonSimpleParameter(); | 3179 classifier->RecordNonSimpleParameter(); |
| 3187 | 3180 |
| 3188 if (allow_harmony_function_name()) { | 3181 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); |
| 3189 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); | |
| 3190 } | |
| 3191 } | 3182 } |
| 3192 | 3183 |
| 3193 Traits::AddFormalParameter(parameters, pattern, initializer, | 3184 Traits::AddFormalParameter(parameters, pattern, initializer, |
| 3194 scanner()->location().end_pos, is_rest); | 3185 scanner()->location().end_pos, is_rest); |
| 3195 } | 3186 } |
| 3196 | 3187 |
| 3197 | 3188 |
| 3198 template <class Traits> | 3189 template <class Traits> |
| 3199 void ParserBase<Traits>::ParseFormalParameterList( | 3190 void ParserBase<Traits>::ParseFormalParameterList( |
| 3200 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3191 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3630 has_seen_constructor_ = true; | 3621 has_seen_constructor_ = true; |
| 3631 return; | 3622 return; |
| 3632 } | 3623 } |
| 3633 } | 3624 } |
| 3634 | 3625 |
| 3635 | 3626 |
| 3636 } // namespace internal | 3627 } // namespace internal |
| 3637 } // namespace v8 | 3628 } // namespace v8 |
| 3638 | 3629 |
| 3639 #endif // V8_PARSING_PARSER_BASE_H | 3630 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |