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