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_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 409 |
410 static const AstRawString* AsIdentifier(Expression* expression) { | 410 static const AstRawString* AsIdentifier(Expression* expression) { |
411 DCHECK(IsIdentifier(expression)); | 411 DCHECK(IsIdentifier(expression)); |
412 return expression->AsVariableProxy()->raw_name(); | 412 return expression->AsVariableProxy()->raw_name(); |
413 } | 413 } |
414 | 414 |
415 bool IsPrototype(const AstRawString* identifier) const; | 415 bool IsPrototype(const AstRawString* identifier) const; |
416 | 416 |
417 bool IsConstructor(const AstRawString* identifier) const; | 417 bool IsConstructor(const AstRawString* identifier) const; |
418 | 418 |
419 bool IsDirectEvalCall(Expression* expression) { | 419 bool IsDirectEvalCall(Expression* expression) const { |
420 if (!expression->IsCall()) return false; | 420 if (!expression->IsCall()) return false; |
421 expression = expression->AsCall()->expression(); | 421 expression = expression->AsCall()->expression(); |
422 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); | 422 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); |
423 } | 423 } |
424 | 424 |
425 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 425 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
426 return ObjectLiteral::IsBoilerplateProperty(property); | 426 return ObjectLiteral::IsBoilerplateProperty(property); |
427 } | 427 } |
428 | 428 |
429 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { | 429 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 static const AstRawString* EmptyIdentifier() { return nullptr; } | 508 static const AstRawString* EmptyIdentifier() { return nullptr; } |
509 static Expression* EmptyExpression() { return nullptr; } | 509 static Expression* EmptyExpression() { return nullptr; } |
510 static Literal* EmptyLiteral() { return nullptr; } | 510 static Literal* EmptyLiteral() { return nullptr; } |
511 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return nullptr; } | 511 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return nullptr; } |
512 static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } | 512 static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } |
513 | 513 |
514 // Used in error return values. | 514 // Used in error return values. |
515 static ZoneList<Expression*>* NullExpressionList() { return nullptr; } | 515 static ZoneList<Expression*>* NullExpressionList() { return nullptr; } |
516 | 516 |
517 // Non-NULL empty string. | 517 // Non-NULL empty string. |
518 V8_INLINE const AstRawString* EmptyIdentifierString(); | 518 V8_INLINE const AstRawString* EmptyIdentifierString() const; |
519 | 519 |
520 // Odd-ball literal creators. | 520 // Odd-ball literal creators. |
521 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); | 521 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory) const; |
522 | 522 |
523 // Producing data during the recursive descent. | 523 // Producing data during the recursive descent. |
524 const AstRawString* GetSymbol(Scanner* scanner); | 524 const AstRawString* GetSymbol(Scanner* scanner) const; |
525 const AstRawString* GetNextSymbol(Scanner* scanner); | 525 const AstRawString* GetNextSymbol(Scanner* scanner) const; |
526 const AstRawString* GetNumberAsSymbol(Scanner* scanner); | 526 const AstRawString* GetNumberAsSymbol(Scanner* scanner) const; |
527 | 527 |
528 Expression* ThisExpression(int pos); | 528 Expression* ThisExpression(int pos = kNoSourcePosition) const; |
529 Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos); | 529 Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos) const; |
530 Expression* NewSuperCallReference(AstNodeFactory* factory, int pos); | 530 Expression* NewSuperCallReference(AstNodeFactory* factory, int pos) const; |
531 Expression* NewTargetExpression(int pos); | 531 Expression* NewTargetExpression(int pos) const; |
532 Expression* FunctionSentExpression(AstNodeFactory* factory, int pos); | 532 Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const; |
533 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, | 533 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, |
534 AstNodeFactory* factory); | 534 AstNodeFactory* factory) const; |
535 Expression* ExpressionFromIdentifier(const AstRawString* name, | 535 Expression* ExpressionFromIdentifier(const AstRawString* name, |
536 int start_position, int end_position, | 536 int start_position, int end_position, |
537 InferName = InferName::kYes); | 537 InferName = InferName::kYes) const; |
538 Expression* ExpressionFromString(int pos, Scanner* scanner, | 538 Expression* ExpressionFromString(int pos, Scanner* scanner, |
539 AstNodeFactory* factory); | 539 AstNodeFactory* factory) const; |
540 Expression* GetIterator(Expression* iterable, AstNodeFactory* factory, | 540 Expression* GetIterator(Expression* iterable, AstNodeFactory* factory, |
541 int pos); | 541 int pos); |
542 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 542 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, |
| 543 Zone* zone) const { |
543 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 544 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
544 } | 545 } |
545 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 546 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, |
| 547 Zone* zone) const { |
546 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 548 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
547 } | 549 } |
548 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 550 ZoneList<v8::internal::Statement*>* NewStatementList(int size, |
| 551 Zone* zone) const { |
549 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 552 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
550 } | 553 } |
551 | 554 |
552 V8_INLINE void AddParameterInitializationBlock( | 555 V8_INLINE void AddParameterInitializationBlock( |
553 const ParserFormalParameters& parameters, | 556 const ParserFormalParameters& parameters, |
554 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); | 557 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const; |
555 | 558 |
556 void ParseAsyncArrowSingleExpressionBody( | 559 void ParseAsyncArrowSingleExpressionBody( |
557 ZoneList<Statement*>* body, bool accept_IN, | 560 ZoneList<Statement*>* body, bool accept_IN, |
558 Type::ExpressionClassifier* classifier, int pos, bool* ok); | 561 Type::ExpressionClassifier* classifier, int pos, bool* ok); |
559 | 562 |
560 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 563 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
561 Expression* pattern, | 564 Expression* pattern, |
562 Expression* initializer, | 565 Expression* initializer, |
563 int initializer_end_position, bool is_rest); | 566 int initializer_end_position, bool is_rest); |
564 V8_INLINE void DeclareFormalParameter( | 567 V8_INLINE void DeclareFormalParameter( |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 void Print(AstNode* node); | 1184 void Print(AstNode* node); |
1182 #endif // DEBUG | 1185 #endif // DEBUG |
1183 }; | 1186 }; |
1184 | 1187 |
1185 | 1188 |
1186 bool ParserTraits::IsFutureStrictReserved( | 1189 bool ParserTraits::IsFutureStrictReserved( |
1187 const AstRawString* identifier) const { | 1190 const AstRawString* identifier) const { |
1188 return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); | 1191 return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
1189 } | 1192 } |
1190 | 1193 |
1191 const AstRawString* ParserTraits::EmptyIdentifierString() { | 1194 const AstRawString* ParserTraits::EmptyIdentifierString() const { |
1192 return parser_->ast_value_factory()->empty_string(); | 1195 return parser_->ast_value_factory()->empty_string(); |
1193 } | 1196 } |
1194 | 1197 |
1195 | 1198 |
1196 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, | 1199 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, |
1197 int* expected_property_count, bool* ok, | 1200 int* expected_property_count, bool* ok, |
1198 Scanner::BookmarkScope* bookmark) { | 1201 Scanner::BookmarkScope* bookmark) { |
1199 return parser_->SkipLazyFunctionBody(materialized_literal_count, | 1202 return parser_->SkipLazyFunctionBody(materialized_literal_count, |
1200 expected_property_count, ok, bookmark); | 1203 expected_property_count, ok, bookmark); |
1201 } | 1204 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 if (is_sloppy(scope->language_mode())) { | 1322 if (is_sloppy(scope->language_mode())) { |
1320 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1323 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
1321 // conservative approximation necessary to account for parameters | 1324 // conservative approximation necessary to account for parameters |
1322 // that are assigned via the arguments array. | 1325 // that are assigned via the arguments array. |
1323 var->set_maybe_assigned(); | 1326 var->set_maybe_assigned(); |
1324 } | 1327 } |
1325 } | 1328 } |
1326 | 1329 |
1327 void ParserTraits::AddParameterInitializationBlock( | 1330 void ParserTraits::AddParameterInitializationBlock( |
1328 const ParserFormalParameters& parameters, | 1331 const ParserFormalParameters& parameters, |
1329 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) { | 1332 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const { |
1330 if (!parameters.is_simple) { | 1333 if (!parameters.is_simple) { |
1331 auto* init_block = | 1334 auto* init_block = |
1332 parser_->BuildParameterInitializationBlock(parameters, ok); | 1335 parser_->BuildParameterInitializationBlock(parameters, ok); |
1333 if (!*ok) return; | 1336 if (!*ok) return; |
1334 | 1337 |
1335 if (is_async) { | 1338 if (is_async) { |
1336 init_block = parser_->BuildRejectPromiseOnException(init_block); | 1339 init_block = parser_->BuildRejectPromiseOnException(init_block); |
1337 } | 1340 } |
1338 | 1341 |
1339 if (init_block != nullptr) { | 1342 if (init_block != nullptr) { |
(...skipping 12 matching lines...) Expand all Loading... |
1352 | 1355 |
1353 Expression* ParserTraits::RewriteYieldStar(Expression* generator, | 1356 Expression* ParserTraits::RewriteYieldStar(Expression* generator, |
1354 Expression* iterable, int pos) { | 1357 Expression* iterable, int pos) { |
1355 return parser_->RewriteYieldStar(generator, iterable, pos); | 1358 return parser_->RewriteYieldStar(generator, iterable, pos); |
1356 } | 1359 } |
1357 | 1360 |
1358 } // namespace internal | 1361 } // namespace internal |
1359 } // namespace v8 | 1362 } // namespace v8 |
1360 | 1363 |
1361 #endif // V8_PARSING_PARSER_H_ | 1364 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |