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_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/compiler.h" // TODO(titzer): remove this include dependency | 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 534 |
535 // ---------------------------------------------------------------------------- | 535 // ---------------------------------------------------------------------------- |
536 // JAVASCRIPT PARSING | 536 // JAVASCRIPT PARSING |
537 | 537 |
538 class Parser; | 538 class Parser; |
539 class SingletonLogger; | 539 class SingletonLogger; |
540 | 540 |
541 | 541 |
542 struct ParserFormalParameters : FormalParametersBase { | 542 struct ParserFormalParameters : FormalParametersBase { |
543 struct Parameter { | 543 struct Parameter { |
544 Parameter(const AstRawString* name, Expression* pattern, bool is_rest) | 544 Parameter(const AstRawString* name, Expression* pattern, |
545 : name(name), pattern(pattern), is_rest(is_rest) {} | 545 Expression* initializer, bool is_rest) |
| 546 : name(name), pattern(pattern), initializer(initializer), |
| 547 is_rest(is_rest) {} |
546 const AstRawString* name; | 548 const AstRawString* name; |
547 Expression* pattern; | 549 Expression* pattern; |
| 550 Expression* initializer; |
548 bool is_rest; | 551 bool is_rest; |
549 }; | 552 }; |
550 | 553 |
551 explicit ParserFormalParameters(Scope* scope) | 554 explicit ParserFormalParameters(Scope* scope) |
552 : FormalParametersBase(scope), params(4, scope->zone()) {} | 555 : FormalParametersBase(scope), params(4, scope->zone()) {} |
553 ZoneList<Parameter> params; | 556 ZoneList<Parameter> params; |
554 | 557 |
555 int Arity() const { return params.length(); } | 558 int Arity() const { return params.length(); } |
556 const Parameter& at(int i) const { return params[i]; } | 559 const Parameter& at(int i) const { return params[i]; } |
557 }; | 560 }; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 } | 775 } |
773 | 776 |
774 V8_INLINE void AddParameterInitializationBlock( | 777 V8_INLINE void AddParameterInitializationBlock( |
775 const ParserFormalParameters& parameters, | 778 const ParserFormalParameters& parameters, |
776 ZoneList<v8::internal::Statement*>* body, bool* ok); | 779 ZoneList<v8::internal::Statement*>* body, bool* ok); |
777 | 780 |
778 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 781 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
779 FunctionKind kind = kNormalFunction); | 782 FunctionKind kind = kNormalFunction); |
780 | 783 |
781 V8_INLINE void AddFormalParameter( | 784 V8_INLINE void AddFormalParameter( |
782 ParserFormalParameters* parameters, Expression* pattern, bool is_rest); | 785 ParserFormalParameters* parameters, Expression* pattern, |
| 786 Expression* initializer, bool is_rest); |
783 V8_INLINE void DeclareFormalParameter( | 787 V8_INLINE void DeclareFormalParameter( |
784 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 788 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
785 bool is_simple, ExpressionClassifier* classifier); | 789 bool is_simple, ExpressionClassifier* classifier); |
786 void ParseArrowFunctionFormalParameters( | 790 void ParseArrowFunctionFormalParameters( |
787 ParserFormalParameters* parameters, Expression* params, | 791 ParserFormalParameters* parameters, Expression* params, |
788 const Scanner::Location& params_loc, | 792 const Scanner::Location& params_loc, |
789 Scanner::Location* duplicate_loc, bool* ok); | 793 Scanner::Location* duplicate_loc, bool* ok); |
790 void ParseArrowFunctionFormalParameterList( | 794 void ParseArrowFunctionFormalParameterList( |
791 ParserFormalParameters* parameters, Expression* params, | 795 ParserFormalParameters* parameters, Expression* params, |
792 const Scanner::Location& params_loc, | 796 const Scanner::Location& params_loc, |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 } | 1310 } |
1307 | 1311 |
1308 | 1312 |
1309 Expression* ParserTraits::SpreadCallNew( | 1313 Expression* ParserTraits::SpreadCallNew( |
1310 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | 1314 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { |
1311 return parser_->SpreadCallNew(function, args, pos); | 1315 return parser_->SpreadCallNew(function, args, pos); |
1312 } | 1316 } |
1313 | 1317 |
1314 | 1318 |
1315 void ParserTraits::AddFormalParameter( | 1319 void ParserTraits::AddFormalParameter( |
1316 ParserFormalParameters* parameters, Expression* pattern, bool is_rest) { | 1320 ParserFormalParameters* parameters, |
1317 bool is_simple = pattern->IsVariableProxy(); | 1321 Expression* pattern, Expression* initializer, bool is_rest) { |
| 1322 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; |
1318 DCHECK(parser_->allow_harmony_destructuring() || | 1323 DCHECK(parser_->allow_harmony_destructuring() || |
1319 parser_->allow_harmony_rest_parameters() || is_simple); | 1324 parser_->allow_harmony_rest_parameters() || |
| 1325 parser_->allow_harmony_default_parameters() || is_simple); |
1320 const AstRawString* name = is_simple | 1326 const AstRawString* name = is_simple |
1321 ? pattern->AsVariableProxy()->raw_name() | 1327 ? pattern->AsVariableProxy()->raw_name() |
1322 : parser_->ast_value_factory()->empty_string(); | 1328 : parser_->ast_value_factory()->empty_string(); |
1323 parameters->params.Add( | 1329 parameters->params.Add( |
1324 ParserFormalParameters::Parameter(name, pattern, is_rest), | 1330 ParserFormalParameters::Parameter(name, pattern, initializer, is_rest), |
1325 parameters->scope->zone()); | 1331 parameters->scope->zone()); |
1326 } | 1332 } |
1327 | 1333 |
1328 | 1334 |
1329 void ParserTraits::DeclareFormalParameter( | 1335 void ParserTraits::DeclareFormalParameter( |
1330 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1336 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
1331 bool is_simple, ExpressionClassifier* classifier) { | 1337 bool is_simple, ExpressionClassifier* classifier) { |
1332 bool is_duplicate = false; | 1338 bool is_duplicate = false; |
1333 // TODO(caitp): Remove special handling for rest once desugaring is in. | 1339 // TODO(caitp): Remove special handling for rest once desugaring is in. |
1334 auto name = is_simple || parameter.is_rest | 1340 auto name = is_simple || parameter.is_rest |
(...skipping 22 matching lines...) Expand all Loading... |
1357 parser_->BuildParameterInitializationBlock(parameters, ok); | 1363 parser_->BuildParameterInitializationBlock(parameters, ok); |
1358 if (!*ok) return; | 1364 if (!*ok) return; |
1359 if (init_block != nullptr) { | 1365 if (init_block != nullptr) { |
1360 body->Add(init_block, parser_->zone()); | 1366 body->Add(init_block, parser_->zone()); |
1361 } | 1367 } |
1362 } | 1368 } |
1363 } | 1369 } |
1364 } } // namespace v8::internal | 1370 } } // namespace v8::internal |
1365 | 1371 |
1366 #endif // V8_PARSER_H_ | 1372 #endif // V8_PARSER_H_ |
OLD | NEW |