OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 class ParserTraits { | 407 class ParserTraits { |
408 public: | 408 public: |
409 struct Type { | 409 struct Type { |
410 // TODO(marja): To be removed. The Traits object should contain all the data | 410 // TODO(marja): To be removed. The Traits object should contain all the data |
411 // it needs. | 411 // it needs. |
412 typedef v8::internal::Parser* Parser; | 412 typedef v8::internal::Parser* Parser; |
413 | 413 |
414 // Used by FunctionState and BlockState. | 414 // Used by FunctionState and BlockState. |
415 typedef v8::internal::Scope Scope; | 415 typedef v8::internal::Scope Scope; |
| 416 typedef v8::internal::Scope* ScopePtr; |
416 typedef Variable GeneratorVariable; | 417 typedef Variable GeneratorVariable; |
417 typedef v8::internal::Zone Zone; | 418 typedef v8::internal::Zone Zone; |
418 | 419 |
| 420 typedef v8::internal::AstProperties AstProperties; |
| 421 typedef v8::internal::DeferredFeedbackSlotProcessor |
| 422 DeferredFeedbackSlotProcessor; |
| 423 typedef Vector<VariableProxy*> ParameterIdentifierVector; |
| 424 |
419 // Return types for traversing functions. | 425 // Return types for traversing functions. |
420 typedef Handle<String> Identifier; | 426 typedef Handle<String> Identifier; |
421 typedef v8::internal::Expression* Expression; | 427 typedef v8::internal::Expression* Expression; |
422 typedef Yield* YieldExpression; | 428 typedef Yield* YieldExpression; |
423 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 429 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
424 typedef v8::internal::Literal* Literal; | 430 typedef v8::internal::Literal* Literal; |
425 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 431 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
426 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 432 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
427 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 433 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 434 typedef ZoneList<v8::internal::Statement*>* StatementList; |
428 | 435 |
429 // For constructing objects returned by the traversing functions. | 436 // For constructing objects returned by the traversing functions. |
430 typedef AstNodeFactory<AstConstructionVisitor> Factory; | 437 typedef AstNodeFactory<AstConstructionVisitor> Factory; |
431 }; | 438 }; |
432 | 439 |
433 explicit ParserTraits(Parser* parser) : parser_(parser) {} | 440 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
434 | 441 |
435 // Custom operations executed when FunctionStates are created and destructed. | 442 // Custom operations executed when FunctionStates are created and destructed. |
436 template<typename FunctionState> | 443 template<typename FunctionState> |
437 static void SetUpFunctionState(FunctionState* function_state, Zone* zone) { | 444 static void SetUpFunctionState(FunctionState* function_state, Zone* zone) { |
(...skipping 29 matching lines...) Expand all Loading... |
467 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { | 474 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { |
468 return !string.is_null() && string->AsArrayIndex(index); | 475 return !string.is_null() && string->AsArrayIndex(index); |
469 } | 476 } |
470 | 477 |
471 // Functions for encapsulating the differences between parsing and preparsing; | 478 // Functions for encapsulating the differences between parsing and preparsing; |
472 // operations interleaved with the recursive descent. | 479 // operations interleaved with the recursive descent. |
473 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { | 480 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { |
474 fni->PushLiteralName(id); | 481 fni->PushLiteralName(id); |
475 } | 482 } |
476 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); | 483 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); |
| 484 static void InferFunctionName(FuncNameInferrer* fni, |
| 485 FunctionLiteral* func_to_infer) { |
| 486 fni->AddFunction(func_to_infer); |
| 487 } |
477 | 488 |
478 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 489 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
479 Scope* scope, Expression* value, bool* has_function) { | 490 Scope* scope, Expression* value, bool* has_function) { |
480 if (scope->DeclarationScope()->is_global_scope() && | 491 if (scope->DeclarationScope()->is_global_scope() && |
481 value->AsFunctionLiteral() != NULL) { | 492 value->AsFunctionLiteral() != NULL) { |
482 *has_function = true; | 493 *has_function = true; |
483 value->AsFunctionLiteral()->set_pretenure(); | 494 value->AsFunctionLiteral()->set_pretenure(); |
484 } | 495 } |
485 } | 496 } |
486 | 497 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 // "null" return type creators. | 566 // "null" return type creators. |
556 static Handle<String> EmptyIdentifier() { | 567 static Handle<String> EmptyIdentifier() { |
557 return Handle<String>(); | 568 return Handle<String>(); |
558 } | 569 } |
559 static Expression* EmptyExpression() { | 570 static Expression* EmptyExpression() { |
560 return NULL; | 571 return NULL; |
561 } | 572 } |
562 static Literal* EmptyLiteral() { | 573 static Literal* EmptyLiteral() { |
563 return NULL; | 574 return NULL; |
564 } | 575 } |
| 576 |
565 // Used in error return values. | 577 // Used in error return values. |
566 static ZoneList<Expression*>* NullExpressionList() { | 578 static ZoneList<Expression*>* NullExpressionList() { |
567 return NULL; | 579 return NULL; |
568 } | 580 } |
569 | 581 |
| 582 // Non-"null" empty string. |
| 583 V8_INLINE Handle<String> EmptyIdentifierString(); |
| 584 |
570 // Odd-ball literal creators. | 585 // Odd-ball literal creators. |
571 Literal* GetLiteralTheHole(int position, | 586 Literal* GetLiteralTheHole(int position, |
572 AstNodeFactory<AstConstructionVisitor>* factory); | 587 AstNodeFactory<AstConstructionVisitor>* factory); |
573 | 588 |
574 // Producing data during the recursive descent. | 589 // Producing data during the recursive descent. |
575 Handle<String> GetSymbol(Scanner* scanner = NULL); | 590 Handle<String> GetSymbol(Scanner* scanner = NULL); |
576 Handle<String> NextLiteralString(Scanner* scanner, | 591 Handle<String> NextLiteralString(Scanner* scanner, |
577 PretenureFlag tenured); | 592 PretenureFlag tenured); |
578 Expression* ThisExpression(Scope* scope, | 593 Expression* ThisExpression(Scope* scope, |
579 AstNodeFactory<AstConstructionVisitor>* factory); | 594 AstNodeFactory<AstConstructionVisitor>* factory, |
| 595 int pos = RelocInfo::kNoPosition); |
580 Literal* ExpressionFromLiteral( | 596 Literal* ExpressionFromLiteral( |
581 Token::Value token, int pos, Scanner* scanner, | 597 Token::Value token, int pos, Scanner* scanner, |
582 AstNodeFactory<AstConstructionVisitor>* factory); | 598 AstNodeFactory<AstConstructionVisitor>* factory); |
583 Expression* ExpressionFromIdentifier( | 599 Expression* ExpressionFromIdentifier( |
584 Handle<String> name, int pos, Scope* scope, | 600 Handle<String> name, int pos, Scope* scope, |
585 AstNodeFactory<AstConstructionVisitor>* factory); | 601 AstNodeFactory<AstConstructionVisitor>* factory); |
586 Expression* ExpressionFromString( | 602 Expression* ExpressionFromString( |
587 int pos, Scanner* scanner, | 603 int pos, Scanner* scanner, |
588 AstNodeFactory<AstConstructionVisitor>* factory); | 604 AstNodeFactory<AstConstructionVisitor>* factory); |
589 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 605 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
590 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 606 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
591 } | 607 } |
592 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 608 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
593 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 609 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
594 } | 610 } |
| 611 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| 612 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 613 } |
| 614 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type); |
| 615 |
| 616 // Utility functions |
| 617 Vector<VariableProxy*> ParameterListFromExpression( |
| 618 Expression* expression, bool* ok); |
| 619 void InferFunctionName(FunctionLiteral* func_to_infer); |
595 | 620 |
596 // Temporary glue; these functions will move to ParserBase. | 621 // Temporary glue; these functions will move to ParserBase. |
597 Expression* ParseV8Intrinsic(bool* ok); | 622 Expression* ParseV8Intrinsic(bool* ok); |
598 FunctionLiteral* ParseFunctionLiteral( | 623 FunctionLiteral* ParseFunctionLiteral( |
599 Handle<String> name, | 624 Handle<String> name, |
600 Scanner::Location function_name_location, | 625 Scanner::Location function_name_location, |
601 bool name_is_strict_reserved, | 626 bool name_is_strict_reserved, |
602 bool is_generator, | 627 bool is_generator, |
603 int function_token_position, | 628 int function_token_position, |
604 FunctionLiteral::FunctionType type, | 629 FunctionLiteral::FunctionType type, |
605 bool* ok); | 630 bool* ok); |
| 631 V8_INLINE void SkipLazyFunctionBody( |
| 632 Handle<String> function_name, |
| 633 int* materialized_literal_count, |
| 634 int* expected_property_count, |
| 635 bool* ok); |
| 636 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 637 Handle<String> function_name, |
| 638 int pos, |
| 639 Variable* fvar, |
| 640 Token::Value fvar_init_op, |
| 641 bool is_generator, |
| 642 bool* ok); |
| 643 V8_INLINE void CheckConflictingVarDeclarations( |
| 644 v8::internal::Scope* scope, |
| 645 bool* ok); |
606 | 646 |
607 private: | 647 private: |
608 Parser* parser_; | 648 Parser* parser_; |
609 }; | 649 }; |
610 | 650 |
611 | 651 |
612 class Parser : public ParserBase<ParserTraits> { | 652 class Parser : public ParserBase<ParserTraits> { |
613 public: | 653 public: |
614 explicit Parser(CompilationInfo* info); | 654 explicit Parser(CompilationInfo* info); |
615 ~Parser() { | 655 ~Parser() { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 VariableMode mode, | 817 VariableMode mode, |
778 Interface* interface); | 818 Interface* interface); |
779 void Declare(Declaration* declaration, bool resolve, bool* ok); | 819 void Declare(Declaration* declaration, bool resolve, bool* ok); |
780 | 820 |
781 bool TargetStackContainsLabel(Handle<String> label); | 821 bool TargetStackContainsLabel(Handle<String> label); |
782 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); | 822 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); |
783 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 823 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
784 | 824 |
785 void RegisterTargetUse(Label* target, Target* stop); | 825 void RegisterTargetUse(Label* target, Target* stop); |
786 | 826 |
| 827 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression, |
| 828 bool* ok); |
| 829 |
787 // Factory methods. | 830 // Factory methods. |
788 | 831 |
789 Scope* NewScope(Scope* parent, ScopeType type); | 832 Scope* NewScope(Scope* parent, ScopeType type); |
790 | 833 |
791 Handle<String> LookupCachedSymbol(int symbol_id); | 834 Handle<String> LookupCachedSymbol(int symbol_id); |
792 | 835 |
793 // Skip over a lazy function, either using cached data if we have it, or | 836 // Skip over a lazy function, either using cached data if we have it, or |
794 // by parsing the function with PreParser. Consumes the ending }. | 837 // by parsing the function with PreParser. Consumes the ending }. |
795 void SkipLazyFunctionBody(Handle<String> function_name, | 838 void SkipLazyFunctionBody(Handle<String> function_name, |
796 int* materialized_literal_count, | 839 int* materialized_literal_count, |
(...skipping 19 matching lines...) Expand all Loading... |
816 PreParser* reusable_preparser_; | 859 PreParser* reusable_preparser_; |
817 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 860 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
818 Target* target_stack_; // for break, continue statements | 861 Target* target_stack_; // for break, continue statements |
819 ScriptData** cached_data_; | 862 ScriptData** cached_data_; |
820 CachedDataMode cached_data_mode_; | 863 CachedDataMode cached_data_mode_; |
821 | 864 |
822 CompilationInfo* info_; | 865 CompilationInfo* info_; |
823 }; | 866 }; |
824 | 867 |
825 | 868 |
| 869 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { |
| 870 return parser_->NewScope(parent_scope, scope_type); |
| 871 } |
| 872 |
| 873 |
| 874 Handle<String> ParserTraits::EmptyIdentifierString() { |
| 875 return parser_->isolate()->factory()->empty_string(); |
| 876 } |
| 877 |
| 878 |
| 879 void ParserTraits::SkipLazyFunctionBody( |
| 880 Handle<String> function_name, |
| 881 int* materialized_literal_count, |
| 882 int* expected_property_count, |
| 883 bool* ok) { |
| 884 return parser_->SkipLazyFunctionBody(function_name, |
| 885 materialized_literal_count, expected_property_count, ok); |
| 886 } |
| 887 |
| 888 |
| 889 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| 890 Handle<String> function_name, |
| 891 int pos, |
| 892 Variable* fvar, |
| 893 Token::Value fvar_init_op, |
| 894 bool is_generator, |
| 895 bool* ok) { |
| 896 return parser_->ParseEagerFunctionBody(function_name, pos, |
| 897 fvar, fvar_init_op, is_generator, ok); |
| 898 } |
| 899 |
| 900 void ParserTraits::CheckConflictingVarDeclarations( |
| 901 v8::internal::Scope* scope, bool* ok) { |
| 902 parser_->CheckConflictingVarDeclarations(scope, ok); |
| 903 } |
| 904 |
826 // Support for handling complex values (array and object literals) that | 905 // Support for handling complex values (array and object literals) that |
827 // can be fully handled at compile time. | 906 // can be fully handled at compile time. |
828 class CompileTimeValue: public AllStatic { | 907 class CompileTimeValue: public AllStatic { |
829 public: | 908 public: |
830 enum LiteralType { | 909 enum LiteralType { |
831 OBJECT_LITERAL_FAST_ELEMENTS, | 910 OBJECT_LITERAL_FAST_ELEMENTS, |
832 OBJECT_LITERAL_SLOW_ELEMENTS, | 911 OBJECT_LITERAL_SLOW_ELEMENTS, |
833 ARRAY_LITERAL | 912 ARRAY_LITERAL |
834 }; | 913 }; |
835 | 914 |
(...skipping 11 matching lines...) Expand all Loading... |
847 private: | 926 private: |
848 static const int kLiteralTypeSlot = 0; | 927 static const int kLiteralTypeSlot = 0; |
849 static const int kElementsSlot = 1; | 928 static const int kElementsSlot = 1; |
850 | 929 |
851 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 930 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
852 }; | 931 }; |
853 | 932 |
854 } } // namespace v8::internal | 933 } } // namespace v8::internal |
855 | 934 |
856 #endif // V8_PARSER_H_ | 935 #endif // V8_PARSER_H_ |
OLD | NEW |