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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 ParserRecorder* log, | 90 ParserRecorder* log, |
91 typename Traits::Type::Zone* zone, | 91 typename Traits::Type::Zone* zone, |
92 typename Traits::Type::Parser this_object) | 92 typename Traits::Type::Parser this_object) |
93 : Traits(this_object), | 93 : Traits(this_object), |
94 parenthesized_function_(false), | 94 parenthesized_function_(false), |
95 scope_(NULL), | 95 scope_(NULL), |
96 function_state_(NULL), | 96 function_state_(NULL), |
97 extension_(extension), | 97 extension_(extension), |
98 fni_(NULL), | 98 fni_(NULL), |
99 log_(log), | 99 log_(log), |
| 100 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
100 scanner_(scanner), | 101 scanner_(scanner), |
101 stack_limit_(stack_limit), | 102 stack_limit_(stack_limit), |
102 stack_overflow_(false), | 103 stack_overflow_(false), |
103 allow_lazy_(false), | 104 allow_lazy_(false), |
104 allow_natives_syntax_(false), | 105 allow_natives_syntax_(false), |
105 allow_generators_(false), | 106 allow_generators_(false), |
106 allow_for_of_(false), | 107 allow_for_of_(false), |
107 zone_(zone) { } | 108 zone_(zone) { } |
108 | 109 |
109 // Getters that indicate whether certain syntactical constructs are | 110 // Getters that indicate whether certain syntactical constructs are |
(...skipping 21 matching lines...) Expand all Loading... |
131 void set_allow_harmony_numeric_literals(bool allow) { | 132 void set_allow_harmony_numeric_literals(bool allow) { |
132 scanner()->SetHarmonyNumericLiterals(allow); | 133 scanner()->SetHarmonyNumericLiterals(allow); |
133 } | 134 } |
134 | 135 |
135 protected: | 136 protected: |
136 enum AllowEvalOrArgumentsAsIdentifier { | 137 enum AllowEvalOrArgumentsAsIdentifier { |
137 kAllowEvalOrArguments, | 138 kAllowEvalOrArguments, |
138 kDontAllowEvalOrArguments | 139 kDontAllowEvalOrArguments |
139 }; | 140 }; |
140 | 141 |
| 142 enum Mode { |
| 143 PARSE_LAZILY, |
| 144 PARSE_EAGERLY |
| 145 }; |
| 146 |
141 // --------------------------------------------------------------------------- | 147 // --------------------------------------------------------------------------- |
142 // FunctionState and BlockState together implement the parser's scope stack. | 148 // FunctionState and BlockState together implement the parser's scope stack. |
143 // The parser's current scope is in scope_. BlockState and FunctionState | 149 // The parser's current scope is in scope_. BlockState and FunctionState |
144 // constructors push on the scope stack and the destructors pop. They are also | 150 // constructors push on the scope stack and the destructors pop. They are also |
145 // used to hold the parser's per-function and per-block state. | 151 // used to hold the parser's per-function and per-block state. |
146 class BlockState BASE_EMBEDDED { | 152 class BlockState BASE_EMBEDDED { |
147 public: | 153 public: |
148 BlockState(typename Traits::Type::Scope** scope_stack, | 154 BlockState(typename Traits::Type::Scope** scope_stack, |
149 typename Traits::Type::Scope* scope) | 155 typename Traits::Type::Scope* scope) |
150 : scope_stack_(scope_stack), | 156 : scope_stack_(scope_stack), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 FunctionState* outer_function_state_; | 228 FunctionState* outer_function_state_; |
223 typename Traits::Type::Scope** scope_stack_; | 229 typename Traits::Type::Scope** scope_stack_; |
224 typename Traits::Type::Scope* outer_scope_; | 230 typename Traits::Type::Scope* outer_scope_; |
225 Isolate* isolate_; // Only used by ParserTraits. | 231 Isolate* isolate_; // Only used by ParserTraits. |
226 int saved_ast_node_id_; // Only used by ParserTraits. | 232 int saved_ast_node_id_; // Only used by ParserTraits. |
227 typename Traits::Type::Factory factory_; | 233 typename Traits::Type::Factory factory_; |
228 | 234 |
229 friend class ParserTraits; | 235 friend class ParserTraits; |
230 }; | 236 }; |
231 | 237 |
| 238 class ParsingModeScope BASE_EMBEDDED { |
| 239 public: |
| 240 ParsingModeScope(ParserBase* parser, Mode mode) |
| 241 : parser_(parser), |
| 242 old_mode_(parser->mode()) { |
| 243 parser_->mode_ = mode; |
| 244 } |
| 245 ~ParsingModeScope() { |
| 246 parser_->mode_ = old_mode_; |
| 247 } |
| 248 |
| 249 private: |
| 250 ParserBase* parser_; |
| 251 Mode old_mode_; |
| 252 }; |
| 253 |
232 Scanner* scanner() const { return scanner_; } | 254 Scanner* scanner() const { return scanner_; } |
233 int position() { return scanner_->location().beg_pos; } | 255 int position() { return scanner_->location().beg_pos; } |
234 int peek_position() { return scanner_->peek_location().beg_pos; } | 256 int peek_position() { return scanner_->peek_location().beg_pos; } |
235 bool stack_overflow() const { return stack_overflow_; } | 257 bool stack_overflow() const { return stack_overflow_; } |
236 void set_stack_overflow() { stack_overflow_ = true; } | 258 void set_stack_overflow() { stack_overflow_ = true; } |
| 259 Mode mode() const { return mode_; } |
237 typename Traits::Type::Zone* zone() const { return zone_; } | 260 typename Traits::Type::Zone* zone() const { return zone_; } |
238 | 261 |
239 INLINE(Token::Value peek()) { | 262 INLINE(Token::Value peek()) { |
240 if (stack_overflow_) return Token::ILLEGAL; | 263 if (stack_overflow_) return Token::ILLEGAL; |
241 return scanner()->peek(); | 264 return scanner()->peek(); |
242 } | 265 } |
243 | 266 |
244 INLINE(Token::Value Next()) { | 267 INLINE(Token::Value Next()) { |
245 if (stack_overflow_) return Token::ILLEGAL; | 268 if (stack_overflow_) return Token::ILLEGAL; |
246 { | 269 { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 412 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
390 ExpressionT ParseArrayLiteral(bool* ok); | 413 ExpressionT ParseArrayLiteral(bool* ok); |
391 ExpressionT ParseObjectLiteral(bool* ok); | 414 ExpressionT ParseObjectLiteral(bool* ok); |
392 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 415 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
393 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 416 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
394 ExpressionT ParseYieldExpression(bool* ok); | 417 ExpressionT ParseYieldExpression(bool* ok); |
395 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 418 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
396 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 419 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
397 ExpressionT ParseUnaryExpression(bool* ok); | 420 ExpressionT ParseUnaryExpression(bool* ok); |
398 ExpressionT ParsePostfixExpression(bool* ok); | 421 ExpressionT ParsePostfixExpression(bool* ok); |
| 422 ExpressionT ParseLeftHandSideExpression(bool* ok); |
399 | 423 |
400 // Used to detect duplicates in object literals. Each of the values | 424 // Used to detect duplicates in object literals. Each of the values |
401 // kGetterProperty, kSetterProperty and kValueProperty represents | 425 // kGetterProperty, kSetterProperty and kValueProperty represents |
402 // a type of object literal property. When parsing a property, its | 426 // a type of object literal property. When parsing a property, its |
403 // type value is stored in the DuplicateFinder for the property name. | 427 // type value is stored in the DuplicateFinder for the property name. |
404 // Values are chosen so that having intersection bits means the there is | 428 // Values are chosen so that having intersection bits means the there is |
405 // an incompatibility. | 429 // an incompatibility. |
406 // I.e., you can add a getter to a property that already has a setter, since | 430 // I.e., you can add a getter to a property that already has a setter, since |
407 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 431 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
408 // already has a getter or a value. Adding the getter to an existing | 432 // already has a getter or a value. Adding the getter to an existing |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // preceded by a parenthesis. | 479 // preceded by a parenthesis. |
456 // Heuristically that means that the function will be called immediately, | 480 // Heuristically that means that the function will be called immediately, |
457 // so never lazily compile it. | 481 // so never lazily compile it. |
458 bool parenthesized_function_; | 482 bool parenthesized_function_; |
459 | 483 |
460 typename Traits::Type::Scope* scope_; // Scope stack. | 484 typename Traits::Type::Scope* scope_; // Scope stack. |
461 FunctionState* function_state_; // Function state stack. | 485 FunctionState* function_state_; // Function state stack. |
462 v8::Extension* extension_; | 486 v8::Extension* extension_; |
463 FuncNameInferrer* fni_; | 487 FuncNameInferrer* fni_; |
464 ParserRecorder* log_; | 488 ParserRecorder* log_; |
| 489 Mode mode_; |
465 | 490 |
466 private: | 491 private: |
467 Scanner* scanner_; | 492 Scanner* scanner_; |
468 uintptr_t stack_limit_; | 493 uintptr_t stack_limit_; |
469 bool stack_overflow_; | 494 bool stack_overflow_; |
470 | 495 |
471 bool allow_lazy_; | 496 bool allow_lazy_; |
472 bool allow_natives_syntax_; | 497 bool allow_natives_syntax_; |
473 bool allow_generators_; | 498 bool allow_generators_; |
474 bool allow_for_of_; | 499 bool allow_for_of_; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 bool IsThisProperty() { return code_ == kThisPropertyExpression; } | 603 bool IsThisProperty() { return code_ == kThisPropertyExpression; } |
579 | 604 |
580 bool IsProperty() { | 605 bool IsProperty() { |
581 return code_ == kPropertyExpression || code_ == kThisPropertyExpression; | 606 return code_ == kPropertyExpression || code_ == kThisPropertyExpression; |
582 } | 607 } |
583 | 608 |
584 bool IsValidLeftHandSide() { | 609 bool IsValidLeftHandSide() { |
585 return IsIdentifier() || IsProperty(); | 610 return IsIdentifier() || IsProperty(); |
586 } | 611 } |
587 | 612 |
| 613 // At the moment PreParser doesn't track these expression types. |
| 614 bool IsFunctionLiteral() const { return false; } |
| 615 bool IsCall() const { return false; } |
| 616 bool IsCallNew() const { return false; } |
| 617 |
| 618 PreParserExpression AsFunctionLiteral() { return *this; } |
| 619 |
588 // Dummy implementation for making expression->somefunc() work in both Parser | 620 // Dummy implementation for making expression->somefunc() work in both Parser |
589 // and PreParser. | 621 // and PreParser. |
590 PreParserExpression* operator->() { return this; } | 622 PreParserExpression* operator->() { return this; } |
591 | 623 |
592 // These are only used when doing function name inferring, and PreParser | |
593 // doesn't do function name inferring. | |
594 void* AsCall() const { return NULL; } | |
595 void* AsCallNew() const { return NULL; } | |
596 | |
597 // More dummy implementations of things PreParser doesn't need to track: | 624 // More dummy implementations of things PreParser doesn't need to track: |
598 void set_index(int index) {} // For YieldExpressions | 625 void set_index(int index) {} // For YieldExpressions |
| 626 void set_parenthesized() {} |
599 | 627 |
600 private: | 628 private: |
601 // Least significant 2 bits are used as flags. Bits 0 and 1 represent | 629 // Least significant 2 bits are used as flags. Bits 0 and 1 represent |
602 // identifiers or strings literals, and are mutually exclusive, but can both | 630 // identifiers or strings literals, and are mutually exclusive, but can both |
603 // be absent. If the expression is an identifier or a string literal, the | 631 // be absent. If the expression is an identifier or a string literal, the |
604 // other bits describe the type (see PreParserIdentifier::Type and string | 632 // other bits describe the type (see PreParserIdentifier::Type and string |
605 // literal constants below). | 633 // literal constants below). |
606 enum { | 634 enum { |
607 kUnknownExpression = 0, | 635 kUnknownExpression = 0, |
608 // Identifiers | 636 // Identifiers |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 private: | 694 private: |
667 ScopeType scope_type_; | 695 ScopeType scope_type_; |
668 bool scope_inside_with_; | 696 bool scope_inside_with_; |
669 StrictMode strict_mode_; | 697 StrictMode strict_mode_; |
670 }; | 698 }; |
671 | 699 |
672 | 700 |
673 class PreParserFactory { | 701 class PreParserFactory { |
674 public: | 702 public: |
675 explicit PreParserFactory(void* extra_param) {} | 703 explicit PreParserFactory(void* extra_param) {} |
676 | 704 PreParserExpression NewLiteral(PreParserIdentifier identifier, |
| 705 int pos) { |
| 706 return PreParserExpression::Default(); |
| 707 } |
| 708 PreParserExpression NewNumberLiteral(double number, |
| 709 int pos) { |
| 710 return PreParserExpression::Default(); |
| 711 } |
677 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 712 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
678 PreParserIdentifier js_flags, | 713 PreParserIdentifier js_flags, |
679 int literal_index, | 714 int literal_index, |
680 int pos) { | 715 int pos) { |
681 return PreParserExpression::Default(); | 716 return PreParserExpression::Default(); |
682 } | 717 } |
683 PreParserExpression NewUnaryOperation(Token::Value op, | |
684 PreParserExpression expression, | |
685 int pos) { | |
686 return PreParserExpression::Default(); | |
687 } | |
688 PreParserExpression NewBinaryOperation(Token::Value op, | |
689 PreParserExpression left, | |
690 PreParserExpression right, int pos) { | |
691 return PreParserExpression::Default(); | |
692 } | |
693 PreParserExpression NewCompareOperation(Token::Value op, | |
694 PreParserExpression left, | |
695 PreParserExpression right, int pos) { | |
696 return PreParserExpression::Default(); | |
697 } | |
698 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 718 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
699 int literal_index, | 719 int literal_index, |
700 int pos) { | 720 int pos) { |
701 return PreParserExpression::Default(); | 721 return PreParserExpression::Default(); |
702 } | 722 } |
703 | |
704 PreParserExpression NewObjectLiteralProperty(bool is_getter, | 723 PreParserExpression NewObjectLiteralProperty(bool is_getter, |
705 PreParserExpression value, | 724 PreParserExpression value, |
706 int pos) { | 725 int pos) { |
707 return PreParserExpression::Default(); | 726 return PreParserExpression::Default(); |
708 } | 727 } |
709 | |
710 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 728 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
711 PreParserExpression value) { | 729 PreParserExpression value) { |
712 return PreParserExpression::Default(); | 730 return PreParserExpression::Default(); |
713 } | 731 } |
714 | |
715 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 732 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
716 int literal_index, | 733 int literal_index, |
717 int boilerplate_properties, | 734 int boilerplate_properties, |
718 bool has_function, | 735 bool has_function, |
719 int pos) { | 736 int pos) { |
720 return PreParserExpression::Default(); | 737 return PreParserExpression::Default(); |
721 } | 738 } |
722 | 739 PreParserExpression NewVariableProxy(void* generator_variable) { |
723 PreParserExpression NewLiteral(PreParserIdentifier identifier, | |
724 int pos) { | |
725 return PreParserExpression::Default(); | 740 return PreParserExpression::Default(); |
726 } | 741 } |
727 | 742 PreParserExpression NewProperty(PreParserExpression obj, |
728 PreParserExpression NewNumberLiteral(double number, | 743 PreParserExpression key, |
729 int pos) { | 744 int pos) { |
| 745 if (obj.IsThis()) { |
| 746 return PreParserExpression::ThisProperty(); |
| 747 } |
| 748 return PreParserExpression::Property(); |
| 749 } |
| 750 PreParserExpression NewUnaryOperation(Token::Value op, |
| 751 PreParserExpression expression, |
| 752 int pos) { |
730 return PreParserExpression::Default(); | 753 return PreParserExpression::Default(); |
731 } | 754 } |
732 | 755 PreParserExpression NewBinaryOperation(Token::Value op, |
| 756 PreParserExpression left, |
| 757 PreParserExpression right, int pos) { |
| 758 return PreParserExpression::Default(); |
| 759 } |
| 760 PreParserExpression NewCompareOperation(Token::Value op, |
| 761 PreParserExpression left, |
| 762 PreParserExpression right, int pos) { |
| 763 return PreParserExpression::Default(); |
| 764 } |
733 PreParserExpression NewAssignment(Token::Value op, | 765 PreParserExpression NewAssignment(Token::Value op, |
734 PreParserExpression left, | 766 PreParserExpression left, |
735 PreParserExpression right, | 767 PreParserExpression right, |
736 int pos) { | 768 int pos) { |
737 return PreParserExpression::Default(); | 769 return PreParserExpression::Default(); |
738 } | 770 } |
739 | |
740 PreParserExpression NewVariableProxy(void* generator_variable) { | |
741 return PreParserExpression::Default(); | |
742 } | |
743 | |
744 PreParserExpression NewYield(PreParserExpression generator_object, | 771 PreParserExpression NewYield(PreParserExpression generator_object, |
745 PreParserExpression expression, | 772 PreParserExpression expression, |
746 Yield::Kind yield_kind, | 773 Yield::Kind yield_kind, |
747 int pos) { | 774 int pos) { |
748 return PreParserExpression::Default(); | 775 return PreParserExpression::Default(); |
749 } | 776 } |
750 | |
751 PreParserExpression NewConditional(PreParserExpression condition, | 777 PreParserExpression NewConditional(PreParserExpression condition, |
752 PreParserExpression then_expression, | 778 PreParserExpression then_expression, |
753 PreParserExpression else_expression, | 779 PreParserExpression else_expression, |
754 int pos) { | 780 int pos) { |
755 return PreParserExpression::Default(); | 781 return PreParserExpression::Default(); |
756 } | 782 } |
757 | |
758 PreParserExpression NewCountOperation(Token::Value op, | 783 PreParserExpression NewCountOperation(Token::Value op, |
759 bool is_prefix, | 784 bool is_prefix, |
760 PreParserExpression expression, | 785 PreParserExpression expression, |
761 int pos) { | 786 int pos) { |
762 return PreParserExpression::Default(); | 787 return PreParserExpression::Default(); |
763 } | 788 } |
| 789 PreParserExpression NewCall(PreParserExpression expression, |
| 790 PreParserExpressionList arguments, |
| 791 int pos) { |
| 792 return PreParserExpression::Default(); |
| 793 } |
764 }; | 794 }; |
765 | 795 |
766 | 796 |
767 class PreParser; | 797 class PreParser; |
768 | 798 |
769 class PreParserTraits { | 799 class PreParserTraits { |
770 public: | 800 public: |
771 struct Type { | 801 struct Type { |
772 // TODO(marja): To be removed. The Traits object should contain all the data | 802 // TODO(marja): To be removed. The Traits object should contain all the data |
773 // it needs. | 803 // it needs. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 // PreParser should not use FuncNameInferrer. | 862 // PreParser should not use FuncNameInferrer. |
833 ASSERT(false); | 863 ASSERT(false); |
834 } | 864 } |
835 | 865 |
836 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 866 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
837 PreParserScope* scope, PreParserExpression value, bool* has_function) {} | 867 PreParserScope* scope, PreParserExpression value, bool* has_function) {} |
838 | 868 |
839 static void CheckAssigningFunctionLiteralToProperty( | 869 static void CheckAssigningFunctionLiteralToProperty( |
840 PreParserExpression left, PreParserExpression right) {} | 870 PreParserExpression left, PreParserExpression right) {} |
841 | 871 |
| 872 static void CheckPossibleEvalCall(PreParserExpression expression, |
| 873 PreParserScope* scope) {} |
| 874 |
842 static PreParserExpression MarkExpressionAsLValue( | 875 static PreParserExpression MarkExpressionAsLValue( |
843 PreParserExpression expression) { | 876 PreParserExpression expression) { |
844 // TODO(marja): To be able to produce the same errors, the preparser needs | 877 // TODO(marja): To be able to produce the same errors, the preparser needs |
845 // to start tracking which expressions are variables and which are lvalues. | 878 // to start tracking which expressions are variables and which are lvalues. |
846 return expression; | 879 return expression; |
847 } | 880 } |
848 | 881 |
849 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 882 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
850 // in strict mode. | 883 // in strict mode. |
851 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); | 884 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 // Temporary glue; these functions will move to ParserBase. | 971 // Temporary glue; these functions will move to ParserBase. |
939 PreParserExpression ParseV8Intrinsic(bool* ok); | 972 PreParserExpression ParseV8Intrinsic(bool* ok); |
940 PreParserExpression ParseFunctionLiteral( | 973 PreParserExpression ParseFunctionLiteral( |
941 PreParserIdentifier name, | 974 PreParserIdentifier name, |
942 Scanner::Location function_name_location, | 975 Scanner::Location function_name_location, |
943 bool name_is_strict_reserved, | 976 bool name_is_strict_reserved, |
944 bool is_generator, | 977 bool is_generator, |
945 int function_token_position, | 978 int function_token_position, |
946 FunctionLiteral::FunctionType type, | 979 FunctionLiteral::FunctionType type, |
947 bool* ok); | 980 bool* ok); |
948 PreParserExpression ParseLeftHandSideExpression(bool* ok); | 981 PreParserExpression ParseMemberWithNewPrefixesExpression(bool* ok); |
949 | 982 |
950 private: | 983 private: |
951 PreParser* pre_parser_; | 984 PreParser* pre_parser_; |
952 }; | 985 }; |
953 | 986 |
954 | 987 |
955 // Preparsing checks a JavaScript program and emits preparse-data that helps | 988 // Preparsing checks a JavaScript program and emits preparse-data that helps |
956 // a later parsing to be faster. | 989 // a later parsing to be faster. |
957 // See preparse-data-format.h for the data format. | 990 // See preparse-data-format.h for the data format. |
958 | 991 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 Statement ParseReturnStatement(bool* ok); | 1135 Statement ParseReturnStatement(bool* ok); |
1103 Statement ParseWithStatement(bool* ok); | 1136 Statement ParseWithStatement(bool* ok); |
1104 Statement ParseSwitchStatement(bool* ok); | 1137 Statement ParseSwitchStatement(bool* ok); |
1105 Statement ParseDoWhileStatement(bool* ok); | 1138 Statement ParseDoWhileStatement(bool* ok); |
1106 Statement ParseWhileStatement(bool* ok); | 1139 Statement ParseWhileStatement(bool* ok); |
1107 Statement ParseForStatement(bool* ok); | 1140 Statement ParseForStatement(bool* ok); |
1108 Statement ParseThrowStatement(bool* ok); | 1141 Statement ParseThrowStatement(bool* ok); |
1109 Statement ParseTryStatement(bool* ok); | 1142 Statement ParseTryStatement(bool* ok); |
1110 Statement ParseDebuggerStatement(bool* ok); | 1143 Statement ParseDebuggerStatement(bool* ok); |
1111 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1144 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
1112 Expression ParseLeftHandSideExpression(bool* ok); | |
1113 Expression ParseMemberExpression(bool* ok); | 1145 Expression ParseMemberExpression(bool* ok); |
1114 Expression ParseMemberExpressionContinuation(PreParserExpression expression, | 1146 Expression ParseMemberExpressionContinuation(PreParserExpression expression, |
1115 bool* ok); | 1147 bool* ok); |
1116 Expression ParseMemberWithNewPrefixesExpression(bool* ok); | 1148 Expression ParseMemberWithNewPrefixesExpression(bool* ok); |
1117 Expression ParseObjectLiteral(bool* ok); | 1149 Expression ParseObjectLiteral(bool* ok); |
1118 Expression ParseV8Intrinsic(bool* ok); | 1150 Expression ParseV8Intrinsic(bool* ok); |
1119 | 1151 |
1120 Expression ParseFunctionLiteral( | 1152 Expression ParseFunctionLiteral( |
1121 Identifier name, | 1153 Identifier name, |
1122 Scanner::Location function_name_location, | 1154 Scanner::Location function_name_location, |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 | 1723 |
1692 this->CheckAssigningFunctionLiteralToProperty(expression, right); | 1724 this->CheckAssigningFunctionLiteralToProperty(expression, right); |
1693 | 1725 |
1694 if (fni_ != NULL) { | 1726 if (fni_ != NULL) { |
1695 // Check if the right hand side is a call to avoid inferring a | 1727 // Check if the right hand side is a call to avoid inferring a |
1696 // name if we're dealing with "a = function(){...}();"-like | 1728 // name if we're dealing with "a = function(){...}();"-like |
1697 // expression. | 1729 // expression. |
1698 if ((op == Token::INIT_VAR | 1730 if ((op == Token::INIT_VAR |
1699 || op == Token::INIT_CONST_LEGACY | 1731 || op == Token::INIT_CONST_LEGACY |
1700 || op == Token::ASSIGN) | 1732 || op == Token::ASSIGN) |
1701 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { | 1733 && (!right->IsCall() && !right->IsCallNew())) { |
1702 fni_->Infer(); | 1734 fni_->Infer(); |
1703 } else { | 1735 } else { |
1704 fni_->RemoveLastFunction(); | 1736 fni_->RemoveLastFunction(); |
1705 } | 1737 } |
1706 fni_->Leave(); | 1738 fni_->Leave(); |
1707 } | 1739 } |
1708 | 1740 |
1709 return factory()->NewAssignment(op, expression, right, pos); | 1741 return factory()->NewAssignment(op, expression, right, pos); |
1710 } | 1742 } |
1711 | 1743 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 expression = | 1915 expression = |
1884 factory()->NewCountOperation(next, | 1916 factory()->NewCountOperation(next, |
1885 false /* postfix */, | 1917 false /* postfix */, |
1886 expression, | 1918 expression, |
1887 position()); | 1919 position()); |
1888 } | 1920 } |
1889 return expression; | 1921 return expression; |
1890 } | 1922 } |
1891 | 1923 |
1892 | 1924 |
| 1925 template <class Traits> |
| 1926 typename ParserBase<Traits>::ExpressionT |
| 1927 ParserBase<Traits>::ParseLeftHandSideExpression(bool* ok) { |
| 1928 // LeftHandSideExpression :: |
| 1929 // (NewExpression | MemberExpression) ... |
| 1930 |
| 1931 ExpressionT result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); |
| 1932 |
| 1933 while (true) { |
| 1934 switch (peek()) { |
| 1935 case Token::LBRACK: { |
| 1936 Consume(Token::LBRACK); |
| 1937 int pos = position(); |
| 1938 ExpressionT index = ParseExpression(true, CHECK_OK); |
| 1939 result = factory()->NewProperty(result, index, pos); |
| 1940 Expect(Token::RBRACK, CHECK_OK); |
| 1941 break; |
| 1942 } |
| 1943 |
| 1944 case Token::LPAREN: { |
| 1945 int pos; |
| 1946 if (scanner()->current_token() == Token::IDENTIFIER) { |
| 1947 // For call of an identifier we want to report position of |
| 1948 // the identifier as position of the call in the stack trace. |
| 1949 pos = position(); |
| 1950 } else { |
| 1951 // For other kinds of calls we record position of the parenthesis as |
| 1952 // position of the call. Note that this is extremely important for |
| 1953 // expressions of the form function(){...}() for which call position |
| 1954 // should not point to the closing brace otherwise it will intersect |
| 1955 // with positions recorded for function literal and confuse debugger. |
| 1956 pos = peek_position(); |
| 1957 // Also the trailing parenthesis are a hint that the function will |
| 1958 // be called immediately. If we happen to have parsed a preceding |
| 1959 // function literal eagerly, we can also compile it eagerly. |
| 1960 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
| 1961 result->AsFunctionLiteral()->set_parenthesized(); |
| 1962 } |
| 1963 } |
| 1964 typename Traits::Type::ExpressionList args = ParseArguments(CHECK_OK); |
| 1965 |
| 1966 // Keep track of eval() calls since they disable all local variable |
| 1967 // optimizations. |
| 1968 // The calls that need special treatment are the |
| 1969 // direct eval calls. These calls are all of the form eval(...), with |
| 1970 // no explicit receiver. |
| 1971 // These calls are marked as potentially direct eval calls. Whether |
| 1972 // they are actually direct calls to eval is determined at run time. |
| 1973 this->CheckPossibleEvalCall(result, scope_); |
| 1974 result = factory()->NewCall(result, args, pos); |
| 1975 if (fni_ != NULL) fni_->RemoveLastFunction(); |
| 1976 break; |
| 1977 } |
| 1978 |
| 1979 case Token::PERIOD: { |
| 1980 Consume(Token::PERIOD); |
| 1981 int pos = position(); |
| 1982 IdentifierT name = ParseIdentifierName(CHECK_OK); |
| 1983 result = factory()->NewProperty( |
| 1984 result, factory()->NewLiteral(name, pos), pos); |
| 1985 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
| 1986 break; |
| 1987 } |
| 1988 |
| 1989 default: |
| 1990 return result; |
| 1991 } |
| 1992 } |
| 1993 } |
| 1994 |
| 1995 |
1893 #undef CHECK_OK | 1996 #undef CHECK_OK |
1894 #undef CHECK_OK_CUSTOM | 1997 #undef CHECK_OK_CUSTOM |
1895 | 1998 |
1896 | 1999 |
1897 template <typename Traits> | 2000 template <typename Traits> |
1898 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 2001 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
1899 Token::Value property, | 2002 Token::Value property, |
1900 PropertyKind type, | 2003 PropertyKind type, |
1901 bool* ok) { | 2004 bool* ok) { |
1902 int old; | 2005 int old; |
(...skipping 20 matching lines...) Expand all Loading... |
1923 "accessor_get_set"); | 2026 "accessor_get_set"); |
1924 } | 2027 } |
1925 *ok = false; | 2028 *ok = false; |
1926 } | 2029 } |
1927 } | 2030 } |
1928 | 2031 |
1929 | 2032 |
1930 } } // v8::internal | 2033 } } // v8::internal |
1931 | 2034 |
1932 #endif // V8_PREPARSER_H | 2035 #endif // V8_PREPARSER_H |
OLD | NEW |