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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 *has_function = true; | 483 *has_function = true; |
484 value->AsFunctionLiteral()->set_pretenure(); | 484 value->AsFunctionLiteral()->set_pretenure(); |
485 } | 485 } |
486 } | 486 } |
487 | 487 |
488 // If we assign a function literal to a property we pretenure the | 488 // If we assign a function literal to a property we pretenure the |
489 // literal so it can be added as a constant function property. | 489 // literal so it can be added as a constant function property. |
490 static void CheckAssigningFunctionLiteralToProperty(Expression* left, | 490 static void CheckAssigningFunctionLiteralToProperty(Expression* left, |
491 Expression* right); | 491 Expression* right); |
492 | 492 |
493 void CheckPossibleEvalCall(Expression* expression, | |
Michael Starzinger
2014/03/21 09:45:44
nit: Should fit into one line. Also can we have a
marja
2014/03/21 09:50:56
Done.
The comment is:
// Keep track of eval() ca
| |
494 Scope* scope); | |
495 | |
493 // Determine if the expression is a variable proxy and mark it as being used | 496 // Determine if the expression is a variable proxy and mark it as being used |
494 // in an assignment or with a increment/decrement operator. This is currently | 497 // in an assignment or with a increment/decrement operator. This is currently |
495 // used on for the statically checking assignments to harmony const bindings. | 498 // used on for the statically checking assignments to harmony const bindings. |
496 static Expression* MarkExpressionAsLValue(Expression* expression); | 499 static Expression* MarkExpressionAsLValue(Expression* expression); |
497 | 500 |
498 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 501 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
499 // in strict mode. | 502 // in strict mode. |
500 void CheckStrictModeLValue(Expression*expression, bool* ok); | 503 void CheckStrictModeLValue(Expression*expression, bool* ok); |
501 | 504 |
502 // Returns true if we have a binary expression between two numeric | 505 // Returns true if we have a binary expression between two numeric |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 // Temporary glue; these functions will move to ParserBase. | 580 // Temporary glue; these functions will move to ParserBase. |
578 Expression* ParseV8Intrinsic(bool* ok); | 581 Expression* ParseV8Intrinsic(bool* ok); |
579 FunctionLiteral* ParseFunctionLiteral( | 582 FunctionLiteral* ParseFunctionLiteral( |
580 Handle<String> name, | 583 Handle<String> name, |
581 Scanner::Location function_name_location, | 584 Scanner::Location function_name_location, |
582 bool name_is_strict_reserved, | 585 bool name_is_strict_reserved, |
583 bool is_generator, | 586 bool is_generator, |
584 int function_token_position, | 587 int function_token_position, |
585 FunctionLiteral::FunctionType type, | 588 FunctionLiteral::FunctionType type, |
586 bool* ok); | 589 bool* ok); |
587 Expression* ParseLeftHandSideExpression(bool* ok); | 590 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); |
588 | 591 |
589 private: | 592 private: |
590 Parser* parser_; | 593 Parser* parser_; |
591 }; | 594 }; |
592 | 595 |
593 | 596 |
594 class Parser : public ParserBase<ParserTraits> { | 597 class Parser : public ParserBase<ParserTraits> { |
595 public: | 598 public: |
596 explicit Parser(CompilationInfo* info); | 599 explicit Parser(CompilationInfo* info); |
597 ~Parser() { | 600 ~Parser() { |
(...skipping 17 matching lines...) Expand all Loading... | |
615 | 618 |
616 // Limit the allowed number of local variables in a function. The hard limit | 619 // Limit the allowed number of local variables in a function. The hard limit |
617 // is that offsets computed by FullCodeGenerator::StackOperand and similar | 620 // is that offsets computed by FullCodeGenerator::StackOperand and similar |
618 // functions are ints, and they should not overflow. In addition, accessing | 621 // functions are ints, and they should not overflow. In addition, accessing |
619 // local variables creates user-controlled constants in the generated code, | 622 // local variables creates user-controlled constants in the generated code, |
620 // and we don't want too much user-controlled memory inside the code (this was | 623 // and we don't want too much user-controlled memory inside the code (this was |
621 // the reason why this limit was introduced in the first place; see | 624 // the reason why this limit was introduced in the first place; see |
622 // https://codereview.chromium.org/7003030/ ). | 625 // https://codereview.chromium.org/7003030/ ). |
623 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 | 626 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 |
624 | 627 |
625 enum Mode { | |
626 PARSE_LAZILY, | |
627 PARSE_EAGERLY | |
628 }; | |
629 | |
630 enum VariableDeclarationContext { | 628 enum VariableDeclarationContext { |
631 kModuleElement, | 629 kModuleElement, |
632 kBlockElement, | 630 kBlockElement, |
633 kStatement, | 631 kStatement, |
634 kForStatement | 632 kForStatement |
635 }; | 633 }; |
636 | 634 |
637 // If a list of variable declarations includes any initializers. | 635 // If a list of variable declarations includes any initializers. |
638 enum VariableDeclarationProperties { | 636 enum VariableDeclarationProperties { |
639 kHasInitializers, | 637 kHasInitializers, |
640 kHasNoInitializers | 638 kHasNoInitializers |
641 }; | 639 }; |
642 | 640 |
643 class ParsingModeScope BASE_EMBEDDED { | |
644 public: | |
645 ParsingModeScope(Parser* parser, Mode mode) | |
646 : parser_(parser), | |
647 old_mode_(parser->mode()) { | |
648 parser_->mode_ = mode; | |
649 } | |
650 ~ParsingModeScope() { | |
651 parser_->mode_ = old_mode_; | |
652 } | |
653 | |
654 private: | |
655 Parser* parser_; | |
656 Mode old_mode_; | |
657 }; | |
658 | |
659 // Returns NULL if parsing failed. | 641 // Returns NULL if parsing failed. |
660 FunctionLiteral* ParseProgram(); | 642 FunctionLiteral* ParseProgram(); |
661 | 643 |
662 FunctionLiteral* ParseLazy(); | 644 FunctionLiteral* ParseLazy(); |
663 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 645 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
664 | 646 |
665 Isolate* isolate() { return isolate_; } | 647 Isolate* isolate() { return isolate_; } |
666 CompilationInfo* info() const { return info_; } | 648 CompilationInfo* info() const { return info_; } |
667 | 649 |
668 // Called by ParseProgram after setting up the scanner. | 650 // Called by ParseProgram after setting up the scanner. |
669 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 651 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
670 Handle<String> source); | 652 Handle<String> source); |
671 | 653 |
672 // Report syntax error | 654 // Report syntax error |
673 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 655 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
674 | 656 |
675 void SetCachedData(ScriptDataImpl** data, | 657 void SetCachedData(ScriptDataImpl** data, |
676 CachedDataMode cached_data_mode) { | 658 CachedDataMode cached_data_mode) { |
677 cached_data_mode_ = cached_data_mode; | 659 cached_data_mode_ = cached_data_mode; |
678 if (cached_data_mode == NO_CACHED_DATA) { | 660 if (cached_data_mode == NO_CACHED_DATA) { |
679 cached_data_ = NULL; | 661 cached_data_ = NULL; |
680 } else { | 662 } else { |
681 ASSERT(data != NULL); | 663 ASSERT(data != NULL); |
682 cached_data_ = data; | 664 cached_data_ = data; |
683 symbol_cache_.Initialize(*data ? (*data)->symbol_count() : 0, zone()); | 665 symbol_cache_.Initialize(*data ? (*data)->symbol_count() : 0, zone()); |
684 } | 666 } |
685 } | 667 } |
686 | 668 |
687 bool inside_with() const { return scope_->inside_with(); } | 669 bool inside_with() const { return scope_->inside_with(); } |
688 Mode mode() const { return mode_; } | |
689 ScriptDataImpl** cached_data() const { return cached_data_; } | 670 ScriptDataImpl** cached_data() const { return cached_data_; } |
690 CachedDataMode cached_data_mode() const { return cached_data_mode_; } | 671 CachedDataMode cached_data_mode() const { return cached_data_mode_; } |
691 Scope* DeclarationScope(VariableMode mode) { | 672 Scope* DeclarationScope(VariableMode mode) { |
692 return IsLexicalVariableMode(mode) | 673 return IsLexicalVariableMode(mode) |
693 ? scope_ : scope_->DeclarationScope(); | 674 ? scope_ : scope_->DeclarationScope(); |
694 } | 675 } |
695 | 676 |
696 // All ParseXXX functions take as the last argument an *ok parameter | 677 // All ParseXXX functions take as the last argument an *ok parameter |
697 // which is set to false if parsing failed; it is unchanged otherwise. | 678 // which is set to false if parsing failed; it is unchanged otherwise. |
698 // By making the 'exception handling' explicit, we are forced to check | 679 // By making the 'exception handling' explicit, we are forced to check |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 716 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
736 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 717 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
737 Statement* ParseThrowStatement(bool* ok); | 718 Statement* ParseThrowStatement(bool* ok); |
738 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 719 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
739 TryStatement* ParseTryStatement(bool* ok); | 720 TryStatement* ParseTryStatement(bool* ok); |
740 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 721 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
741 | 722 |
742 // Support for hamony block scoped bindings. | 723 // Support for hamony block scoped bindings. |
743 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | 724 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
744 | 725 |
745 Expression* ParseUnaryExpression(bool* ok); | |
marja
2014/03/20 16:06:54
These are leftover definitions of funcs that have
| |
746 Expression* ParseLeftHandSideExpression(bool* ok); | |
747 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); | 726 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); |
748 Expression* ParseMemberExpression(bool* ok); | 727 Expression* ParseMemberExpression(bool* ok); |
749 Expression* ParseMemberExpressionContinuation(Expression* expression, | 728 Expression* ParseMemberExpressionContinuation(Expression* expression, |
750 bool* ok); | 729 bool* ok); |
751 Expression* ParseObjectLiteral(bool* ok); | |
752 | |
753 // Initialize the components of a for-in / for-of statement. | 730 // Initialize the components of a for-in / for-of statement. |
754 void InitializeForEachStatement(ForEachStatement* stmt, | 731 void InitializeForEachStatement(ForEachStatement* stmt, |
755 Expression* each, | 732 Expression* each, |
756 Expression* subject, | 733 Expression* subject, |
757 Statement* body); | 734 Statement* body); |
758 | 735 |
759 FunctionLiteral* ParseFunctionLiteral( | 736 FunctionLiteral* ParseFunctionLiteral( |
760 Handle<String> name, | 737 Handle<String> name, |
761 Scanner::Location function_name_location, | 738 Scanner::Location function_name_location, |
762 bool name_is_strict_reserved, | 739 bool name_is_strict_reserved, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 ZoneList<Handle<String> > symbol_cache_; | 805 ZoneList<Handle<String> > symbol_cache_; |
829 | 806 |
830 Handle<Script> script_; | 807 Handle<Script> script_; |
831 Scanner scanner_; | 808 Scanner scanner_; |
832 PreParser* reusable_preparser_; | 809 PreParser* reusable_preparser_; |
833 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 810 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
834 Target* target_stack_; // for break, continue statements | 811 Target* target_stack_; // for break, continue statements |
835 ScriptDataImpl** cached_data_; | 812 ScriptDataImpl** cached_data_; |
836 CachedDataMode cached_data_mode_; | 813 CachedDataMode cached_data_mode_; |
837 | 814 |
838 Mode mode_; | |
839 | |
840 CompilationInfo* info_; | 815 CompilationInfo* info_; |
841 }; | 816 }; |
842 | 817 |
843 | 818 |
844 // Support for handling complex values (array and object literals) that | 819 // Support for handling complex values (array and object literals) that |
845 // can be fully handled at compile time. | 820 // can be fully handled at compile time. |
846 class CompileTimeValue: public AllStatic { | 821 class CompileTimeValue: public AllStatic { |
847 public: | 822 public: |
848 enum LiteralType { | 823 enum LiteralType { |
849 OBJECT_LITERAL_FAST_ELEMENTS, | 824 OBJECT_LITERAL_FAST_ELEMENTS, |
(...skipping 15 matching lines...) Expand all Loading... | |
865 private: | 840 private: |
866 static const int kLiteralTypeSlot = 0; | 841 static const int kLiteralTypeSlot = 0; |
867 static const int kElementsSlot = 1; | 842 static const int kElementsSlot = 1; |
868 | 843 |
869 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 844 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
870 }; | 845 }; |
871 | 846 |
872 } } // namespace v8::internal | 847 } } // namespace v8::internal |
873 | 848 |
874 #endif // V8_PARSER_H_ | 849 #endif // V8_PARSER_H_ |
OLD | NEW |