| 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 : public PreParserFormalParameters { | 542 struct ParserFormalParameters : public PreParserFormalParameters { |
| 543 struct Parameter { | 543 struct Parameter { |
| 544 Parameter(Variable* var, Expression* pattern) | 544 Parameter(const AstRawString* name, Expression* pattern, bool is_rest) |
| 545 : var(var), pattern(pattern) {} | 545 : name(name), pattern(pattern), is_rest(is_rest) {} |
| 546 Variable* var; | 546 const AstRawString* name; |
| 547 Expression* pattern; | 547 Expression* pattern; |
| 548 bool is_rest; |
| 548 }; | 549 }; |
| 549 | 550 |
| 550 explicit ParserFormalParameters(Scope* scope) | 551 explicit ParserFormalParameters(Scope* scope) |
| 551 : PreParserFormalParameters(scope), params(4, scope->zone()) {} | 552 : PreParserFormalParameters(scope), params(4, scope->zone()) {} |
| 552 | 553 |
| 553 ZoneList<Parameter> params; | 554 ZoneList<Parameter> params; |
| 554 | 555 |
| 555 void AddParameter(Variable* var, Expression* pattern) { | 556 void AddParameter( |
| 556 params.Add(Parameter(var, pattern), scope->zone()); | 557 const AstRawString* name, Expression* pattern, bool is_rest) { |
| 558 params.Add(Parameter(name, pattern, is_rest), scope->zone()); |
| 559 DCHECK_EQ(arity, params.length()); |
| 557 } | 560 } |
| 558 }; | 561 }; |
| 559 | 562 |
| 560 | 563 |
| 561 class ParserTraits { | 564 class ParserTraits { |
| 562 public: | 565 public: |
| 563 struct Type { | 566 struct Type { |
| 564 // TODO(marja): To be removed. The Traits object should contain all the data | 567 // TODO(marja): To be removed. The Traits object should contain all the data |
| 565 // it needs. | 568 // it needs. |
| 566 typedef v8::internal::Parser* Parser; | 569 typedef v8::internal::Parser* Parser; |
| 567 | 570 |
| 568 typedef Variable GeneratorVariable; | 571 typedef Variable GeneratorVariable; |
| 569 | 572 |
| 570 typedef v8::internal::AstProperties AstProperties; | 573 typedef v8::internal::AstProperties AstProperties; |
| 571 | 574 |
| 572 // Return types for traversing functions. | 575 // Return types for traversing functions. |
| 573 typedef const AstRawString* Identifier; | 576 typedef const AstRawString* Identifier; |
| 574 typedef v8::internal::Expression* Expression; | 577 typedef v8::internal::Expression* Expression; |
| 575 typedef Yield* YieldExpression; | 578 typedef Yield* YieldExpression; |
| 576 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 579 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 577 typedef v8::internal::ClassLiteral* ClassLiteral; | 580 typedef v8::internal::ClassLiteral* ClassLiteral; |
| 578 typedef v8::internal::Literal* Literal; | 581 typedef v8::internal::Literal* Literal; |
| 579 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 582 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 580 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 583 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 581 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 584 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 582 typedef const v8::internal::AstRawString* FormalParameter; | 585 typedef ParserFormalParameters::Parameter FormalParameter; |
| 583 typedef ParserFormalParameters FormalParameters; | 586 typedef ParserFormalParameters FormalParameters; |
| 584 typedef ZoneList<v8::internal::Statement*>* StatementList; | 587 typedef ZoneList<v8::internal::Statement*>* StatementList; |
| 585 | 588 |
| 586 // For constructing objects returned by the traversing functions. | 589 // For constructing objects returned by the traversing functions. |
| 587 typedef AstNodeFactory Factory; | 590 typedef AstNodeFactory Factory; |
| 588 }; | 591 }; |
| 589 | 592 |
| 590 explicit ParserTraits(Parser* parser) : parser_(parser) {} | 593 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
| 591 | 594 |
| 592 // Helper functions for recursive descent. | 595 // Helper functions for recursive descent. |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 bool is_duplicate = false; | 1316 bool is_duplicate = false; |
| 1314 bool is_simple = pattern->IsVariableProxy(); | 1317 bool is_simple = pattern->IsVariableProxy(); |
| 1315 DCHECK(parser_->allow_harmony_destructuring() || is_simple); | 1318 DCHECK(parser_->allow_harmony_destructuring() || is_simple); |
| 1316 | 1319 |
| 1317 const AstRawString* name = is_simple | 1320 const AstRawString* name = is_simple |
| 1318 ? pattern->AsVariableProxy()->raw_name() | 1321 ? pattern->AsVariableProxy()->raw_name() |
| 1319 : parser_->ast_value_factory()->empty_string(); | 1322 : parser_->ast_value_factory()->empty_string(); |
| 1320 VariableMode mode = is_simple ? VAR : TEMPORARY; | 1323 VariableMode mode = is_simple ? VAR : TEMPORARY; |
| 1321 Variable* var = | 1324 Variable* var = |
| 1322 parameters->scope->DeclareParameter(name, mode, is_rest, &is_duplicate); | 1325 parameters->scope->DeclareParameter(name, mode, is_rest, &is_duplicate); |
| 1323 parameters->AddParameter(var, is_simple ? nullptr : pattern); | 1326 parameters->AddParameter(name, is_simple ? nullptr : pattern, is_rest); |
| 1324 if (is_duplicate) { | 1327 if (is_duplicate) { |
| 1325 classifier->RecordDuplicateFormalParameterError( | 1328 classifier->RecordDuplicateFormalParameterError( |
| 1326 parser_->scanner()->location()); | 1329 parser_->scanner()->location()); |
| 1327 } | 1330 } |
| 1328 if (is_sloppy(parameters->scope->language_mode())) { | 1331 if (is_sloppy(parameters->scope->language_mode())) { |
| 1329 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1332 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 1330 // conservative approximation necessary to account for parameters | 1333 // conservative approximation necessary to account for parameters |
| 1331 // that are assigned via the arguments array. | 1334 // that are assigned via the arguments array. |
| 1332 var->set_maybe_assigned(); | 1335 var->set_maybe_assigned(); |
| 1333 } | 1336 } |
| 1334 } | 1337 } |
| 1335 | 1338 |
| 1336 | 1339 |
| 1337 void ParserTraits::AddParameterInitializationBlock( | 1340 void ParserTraits::AddParameterInitializationBlock( |
| 1338 const ParserFormalParameters& parameters, | 1341 const ParserFormalParameters& parameters, |
| 1339 ZoneList<v8::internal::Statement*>* body, bool* ok) { | 1342 ZoneList<v8::internal::Statement*>* body, bool* ok) { |
| 1340 if (!parameters.is_simple) { | 1343 if (!parameters.is_simple) { |
| 1341 auto* init_block = | 1344 auto* init_block = |
| 1342 parser_->BuildParameterInitializationBlock(parameters, ok); | 1345 parser_->BuildParameterInitializationBlock(parameters, ok); |
| 1343 if (!*ok) return; | 1346 if (!*ok) return; |
| 1344 if (init_block != nullptr) { | 1347 if (init_block != nullptr) { |
| 1345 body->Add(init_block, parser_->zone()); | 1348 body->Add(init_block, parser_->zone()); |
| 1346 } | 1349 } |
| 1347 } | 1350 } |
| 1348 } | 1351 } |
| 1349 } } // namespace v8::internal | 1352 } } // namespace v8::internal |
| 1350 | 1353 |
| 1351 #endif // V8_PARSER_H_ | 1354 #endif // V8_PARSER_H_ |
| OLD | NEW |