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" // For CachedDataMode | 10 #include "src/compiler.h" // For CachedDataMode |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 class ParserTraits { | 379 class ParserTraits { |
380 public: | 380 public: |
381 struct Type { | 381 struct Type { |
382 // TODO(marja): To be removed. The Traits object should contain all the data | 382 // TODO(marja): To be removed. The Traits object should contain all the data |
383 // it needs. | 383 // it needs. |
384 typedef v8::internal::Parser* Parser; | 384 typedef v8::internal::Parser* Parser; |
385 | 385 |
386 // Used by FunctionState and BlockState. | 386 // Used by FunctionState and BlockState. |
387 typedef v8::internal::Scope Scope; | 387 typedef v8::internal::Scope Scope; |
| 388 typedef v8::internal::Scope* ScopePtr; |
388 typedef Variable GeneratorVariable; | 389 typedef Variable GeneratorVariable; |
389 typedef v8::internal::Zone Zone; | 390 typedef v8::internal::Zone Zone; |
390 | 391 |
| 392 typedef v8::internal::AstProperties AstProperties; |
| 393 typedef Vector<VariableProxy*> ParameterIdentifierVector; |
| 394 |
391 // Return types for traversing functions. | 395 // Return types for traversing functions. |
392 typedef const AstRawString* Identifier; | 396 typedef const AstRawString* Identifier; |
393 typedef v8::internal::Expression* Expression; | 397 typedef v8::internal::Expression* Expression; |
394 typedef Yield* YieldExpression; | 398 typedef Yield* YieldExpression; |
395 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 399 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
396 typedef v8::internal::Literal* Literal; | 400 typedef v8::internal::Literal* Literal; |
397 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 401 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
398 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 402 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
399 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 403 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
400 typedef ZoneList<v8::internal::Statement*>* StatementList; | 404 typedef ZoneList<v8::internal::Statement*>* StatementList; |
(...skipping 14 matching lines...) Expand all Loading... |
415 | 419 |
416 template<typename FunctionState> | 420 template<typename FunctionState> |
417 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { | 421 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { |
418 if (function_state->outer_function_state_ != NULL) { | 422 if (function_state->outer_function_state_ != NULL) { |
419 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); | 423 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); |
420 } | 424 } |
421 } | 425 } |
422 | 426 |
423 // Helper functions for recursive descent. | 427 // Helper functions for recursive descent. |
424 bool IsEvalOrArguments(const AstRawString* identifier) const; | 428 bool IsEvalOrArguments(const AstRawString* identifier) const; |
| 429 V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; |
425 | 430 |
426 // Returns true if the expression is of type "this.foo". | 431 // Returns true if the expression is of type "this.foo". |
427 static bool IsThisProperty(Expression* expression); | 432 static bool IsThisProperty(Expression* expression); |
428 | 433 |
429 static bool IsIdentifier(Expression* expression); | 434 static bool IsIdentifier(Expression* expression); |
430 | 435 |
431 static const AstRawString* AsIdentifier(Expression* expression) { | 436 static const AstRawString* AsIdentifier(Expression* expression) { |
432 ASSERT(IsIdentifier(expression)); | 437 ASSERT(IsIdentifier(expression)); |
433 return expression->AsVariableProxy()->raw_name(); | 438 return expression->AsVariableProxy()->raw_name(); |
434 } | 439 } |
435 | 440 |
436 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 441 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
437 return ObjectLiteral::IsBoilerplateProperty(property); | 442 return ObjectLiteral::IsBoilerplateProperty(property); |
438 } | 443 } |
439 | 444 |
440 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { | 445 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { |
441 return string->AsArrayIndex(index); | 446 return string->AsArrayIndex(index); |
442 } | 447 } |
443 | 448 |
| 449 bool IsValidArrowFunctionParameterList(Expression* expression); |
| 450 |
444 // Functions for encapsulating the differences between parsing and preparsing; | 451 // Functions for encapsulating the differences between parsing and preparsing; |
445 // operations interleaved with the recursive descent. | 452 // operations interleaved with the recursive descent. |
446 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) { | 453 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) { |
447 fni->PushLiteralName(id); | 454 fni->PushLiteralName(id); |
448 } | 455 } |
449 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); | 456 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); |
450 | 457 |
451 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 458 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
452 Scope* scope, Expression* value, bool* has_function) { | 459 Scope* scope, Expression* value, bool* has_function) { |
453 if (scope->DeclarationScope()->is_global_scope() && | 460 if (scope->DeclarationScope()->is_global_scope() && |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 const AstRawString* arg, | 535 const AstRawString* arg, |
529 bool is_reference_error = false); | 536 bool is_reference_error = false); |
530 | 537 |
531 // "null" return type creators. | 538 // "null" return type creators. |
532 static const AstRawString* EmptyIdentifier() { | 539 static const AstRawString* EmptyIdentifier() { |
533 return NULL; | 540 return NULL; |
534 } | 541 } |
535 static Expression* EmptyExpression() { | 542 static Expression* EmptyExpression() { |
536 return NULL; | 543 return NULL; |
537 } | 544 } |
| 545 static Expression* EmptyArrowParamList() { |
| 546 return NULL; |
| 547 } |
538 static Literal* EmptyLiteral() { | 548 static Literal* EmptyLiteral() { |
539 return NULL; | 549 return NULL; |
540 } | 550 } |
| 551 |
541 // Used in error return values. | 552 // Used in error return values. |
542 static ZoneList<Expression*>* NullExpressionList() { | 553 static ZoneList<Expression*>* NullExpressionList() { |
543 return NULL; | 554 return NULL; |
544 } | 555 } |
545 | 556 |
546 // Odd-ball literal creators. | 557 // Odd-ball literal creators. |
547 Literal* GetLiteralTheHole(int position, | 558 Literal* GetLiteralTheHole(int position, |
548 AstNodeFactory<AstConstructionVisitor>* factory); | 559 AstNodeFactory<AstConstructionVisitor>* factory); |
549 | 560 |
550 // Producing data during the recursive descent. | 561 // Producing data during the recursive descent. |
(...skipping 13 matching lines...) Expand all Loading... |
564 AstNodeFactory<AstConstructionVisitor>* factory); | 575 AstNodeFactory<AstConstructionVisitor>* factory); |
565 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 576 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
566 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 577 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
567 } | 578 } |
568 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 579 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
569 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 580 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
570 } | 581 } |
571 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 582 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
572 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 583 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
573 } | 584 } |
| 585 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type); |
| 586 |
| 587 // Utility functions |
| 588 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression); |
| 589 V8_INLINE AstValueFactory* ast_value_factory(); |
574 | 590 |
575 // Temporary glue; these functions will move to ParserBase. | 591 // Temporary glue; these functions will move to ParserBase. |
576 Expression* ParseV8Intrinsic(bool* ok); | 592 Expression* ParseV8Intrinsic(bool* ok); |
577 FunctionLiteral* ParseFunctionLiteral( | 593 FunctionLiteral* ParseFunctionLiteral( |
578 const AstRawString* name, | 594 const AstRawString* name, |
579 Scanner::Location function_name_location, | 595 Scanner::Location function_name_location, |
580 bool name_is_strict_reserved, | 596 bool name_is_strict_reserved, |
581 bool is_generator, | 597 bool is_generator, |
582 int function_token_position, | 598 int function_token_position, |
583 FunctionLiteral::FunctionType type, | 599 FunctionLiteral::FunctionType type, |
584 FunctionLiteral::ArityRestriction arity_restriction, | 600 FunctionLiteral::ArityRestriction arity_restriction, |
585 bool* ok); | 601 bool* ok); |
| 602 V8_INLINE void SkipLazyFunctionBody( |
| 603 const AstRawString* name, |
| 604 int* materialized_literal_count, |
| 605 int* expected_property_count, |
| 606 bool* ok); |
| 607 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 608 const AstRawString* name, |
| 609 int pos, |
| 610 Variable* fvar, |
| 611 Token::Value fvar_init_op, |
| 612 bool is_generator, |
| 613 bool* ok); |
| 614 V8_INLINE void CheckConflictingVarDeclarations( |
| 615 v8::internal::Scope* scope, |
| 616 bool* ok); |
586 | 617 |
587 private: | 618 private: |
588 Parser* parser_; | 619 Parser* parser_; |
589 }; | 620 }; |
590 | 621 |
591 | 622 |
592 class Parser : public ParserBase<ParserTraits> { | 623 class Parser : public ParserBase<ParserTraits> { |
593 public: | 624 public: |
594 explicit Parser(CompilationInfo* info); | 625 explicit Parser(CompilationInfo* info); |
595 ~Parser() { | 626 ~Parser() { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 Scanner::Location pending_error_location_; | 849 Scanner::Location pending_error_location_; |
819 const char* pending_error_message_; | 850 const char* pending_error_message_; |
820 const AstRawString* pending_error_arg_; | 851 const AstRawString* pending_error_arg_; |
821 const char* pending_error_char_arg_; | 852 const char* pending_error_char_arg_; |
822 bool pending_error_is_reference_error_; | 853 bool pending_error_is_reference_error_; |
823 | 854 |
824 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 855 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
825 }; | 856 }; |
826 | 857 |
827 | 858 |
| 859 bool ParserTraits::IsFutureStrictReserved( |
| 860 const AstRawString* identifier) const { |
| 861 return identifier->IsOneByteEqualTo("yield") || |
| 862 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
| 863 } |
| 864 |
| 865 |
| 866 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { |
| 867 return parser_->NewScope(parent_scope, scope_type); |
| 868 } |
| 869 |
| 870 |
| 871 void ParserTraits::SkipLazyFunctionBody( |
| 872 const AstRawString* function_name, |
| 873 int* materialized_literal_count, |
| 874 int* expected_property_count, |
| 875 bool* ok) { |
| 876 return parser_->SkipLazyFunctionBody(function_name, |
| 877 materialized_literal_count, expected_property_count, ok); |
| 878 } |
| 879 |
| 880 |
| 881 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| 882 const AstRawString* name, |
| 883 int pos, |
| 884 Variable* fvar, |
| 885 Token::Value fvar_init_op, |
| 886 bool is_generator, |
| 887 bool* ok) { |
| 888 return parser_->ParseEagerFunctionBody(name, pos, |
| 889 fvar, fvar_init_op, is_generator, ok); |
| 890 } |
| 891 |
| 892 void ParserTraits::CheckConflictingVarDeclarations( |
| 893 v8::internal::Scope* scope, bool* ok) { |
| 894 parser_->CheckConflictingVarDeclarations(scope, ok); |
| 895 } |
| 896 |
| 897 |
| 898 AstValueFactory* ParserTraits::ast_value_factory() { |
| 899 return parser_->ast_value_factory_; |
| 900 } |
| 901 |
| 902 |
828 // Support for handling complex values (array and object literals) that | 903 // Support for handling complex values (array and object literals) that |
829 // can be fully handled at compile time. | 904 // can be fully handled at compile time. |
830 class CompileTimeValue: public AllStatic { | 905 class CompileTimeValue: public AllStatic { |
831 public: | 906 public: |
832 enum LiteralType { | 907 enum LiteralType { |
833 OBJECT_LITERAL_FAST_ELEMENTS, | 908 OBJECT_LITERAL_FAST_ELEMENTS, |
834 OBJECT_LITERAL_SLOW_ELEMENTS, | 909 OBJECT_LITERAL_SLOW_ELEMENTS, |
835 ARRAY_LITERAL | 910 ARRAY_LITERAL |
836 }; | 911 }; |
837 | 912 |
(...skipping 11 matching lines...) Expand all Loading... |
849 private: | 924 private: |
850 static const int kLiteralTypeSlot = 0; | 925 static const int kLiteralTypeSlot = 0; |
851 static const int kElementsSlot = 1; | 926 static const int kElementsSlot = 1; |
852 | 927 |
853 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 928 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
854 }; | 929 }; |
855 | 930 |
856 } } // namespace v8::internal | 931 } } // namespace v8::internal |
857 | 932 |
858 #endif // V8_PARSER_H_ | 933 #endif // V8_PARSER_H_ |
OLD | NEW |