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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 scope_(NULL), | 76 scope_(NULL), |
77 function_state_(NULL), | 77 function_state_(NULL), |
78 extension_(extension), | 78 extension_(extension), |
79 fni_(NULL), | 79 fni_(NULL), |
80 log_(log), | 80 log_(log), |
81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
82 stack_limit_(stack_limit), | 82 stack_limit_(stack_limit), |
83 scanner_(scanner), | 83 scanner_(scanner), |
84 stack_overflow_(false), | 84 stack_overflow_(false), |
85 allow_lazy_(false), | 85 allow_lazy_(false), |
86 allow_natives_syntax_(false), | 86 allow_natives_(false), |
87 allow_arrow_functions_(false), | 87 allow_harmony_arrow_functions_(false), |
88 allow_harmony_object_literals_(false), | 88 allow_harmony_object_literals_(false), |
| 89 allow_harmony_sloppy_(false), |
89 zone_(zone) {} | 90 zone_(zone) {} |
90 | 91 |
91 // Getters that indicate whether certain syntactical constructs are | 92 // Getters that indicate whether certain syntactical constructs are |
92 // allowed to be parsed by this instance of the parser. | 93 // allowed to be parsed by this instance of the parser. |
93 bool allow_lazy() const { return allow_lazy_; } | 94 bool allow_lazy() const { return allow_lazy_; } |
94 bool allow_natives_syntax() const { return allow_natives_syntax_; } | 95 bool allow_natives() const { return allow_natives_; } |
95 bool allow_arrow_functions() const { return allow_arrow_functions_; } | 96 bool allow_harmony_arrow_functions() const { |
96 bool allow_modules() const { return scanner()->HarmonyModules(); } | 97 return allow_harmony_arrow_functions_; |
| 98 } |
| 99 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
97 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 100 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
98 bool allow_harmony_numeric_literals() const { | 101 bool allow_harmony_numeric_literals() const { |
99 return scanner()->HarmonyNumericLiterals(); | 102 return scanner()->HarmonyNumericLiterals(); |
100 } | 103 } |
101 bool allow_classes() const { return scanner()->HarmonyClasses(); } | 104 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } |
102 bool allow_harmony_object_literals() const { | 105 bool allow_harmony_object_literals() const { |
103 return allow_harmony_object_literals_; | 106 return allow_harmony_object_literals_; |
104 } | 107 } |
105 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } | 108 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } |
| 109 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } |
106 | 110 |
107 // Setters that determine whether certain syntactical constructs are | 111 // Setters that determine whether certain syntactical constructs are |
108 // allowed to be parsed by this instance of the parser. | 112 // allowed to be parsed by this instance of the parser. |
109 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 113 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
110 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; } | 114 void set_allow_natives(bool allow) { allow_natives_ = allow; } |
111 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } | 115 void set_allow_harmony_arrow_functions(bool allow) { |
112 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } | 116 allow_harmony_arrow_functions_ = allow; |
| 117 } |
| 118 void set_allow_harmony_modules(bool allow) { |
| 119 scanner()->SetHarmonyModules(allow); |
| 120 } |
113 void set_allow_harmony_scoping(bool allow) { | 121 void set_allow_harmony_scoping(bool allow) { |
114 scanner()->SetHarmonyScoping(allow); | 122 scanner()->SetHarmonyScoping(allow); |
115 } | 123 } |
116 void set_allow_harmony_numeric_literals(bool allow) { | 124 void set_allow_harmony_numeric_literals(bool allow) { |
117 scanner()->SetHarmonyNumericLiterals(allow); | 125 scanner()->SetHarmonyNumericLiterals(allow); |
118 } | 126 } |
119 void set_allow_classes(bool allow) { scanner()->SetHarmonyClasses(allow); } | 127 void set_allow_harmony_classes(bool allow) { |
| 128 scanner()->SetHarmonyClasses(allow); |
| 129 } |
120 void set_allow_harmony_object_literals(bool allow) { | 130 void set_allow_harmony_object_literals(bool allow) { |
121 allow_harmony_object_literals_ = allow; | 131 allow_harmony_object_literals_ = allow; |
122 } | 132 } |
123 void set_allow_harmony_templates(bool allow) { | 133 void set_allow_harmony_templates(bool allow) { |
124 scanner()->SetHarmonyTemplates(allow); | 134 scanner()->SetHarmonyTemplates(allow); |
125 } | 135 } |
| 136 void set_allow_harmony_sloppy(bool allow) { |
| 137 allow_harmony_sloppy_ = allow; |
| 138 } |
126 | 139 |
127 protected: | 140 protected: |
128 enum AllowEvalOrArgumentsAsIdentifier { | 141 enum AllowEvalOrArgumentsAsIdentifier { |
129 kAllowEvalOrArguments, | 142 kAllowEvalOrArguments, |
130 kDontAllowEvalOrArguments | 143 kDontAllowEvalOrArguments |
131 }; | 144 }; |
132 | 145 |
133 enum Mode { | 146 enum Mode { |
134 PARSE_LAZILY, | 147 PARSE_LAZILY, |
135 PARSE_EAGERLY | 148 PARSE_EAGERLY |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 FuncNameInferrer* fni_; | 583 FuncNameInferrer* fni_; |
571 ParserRecorder* log_; | 584 ParserRecorder* log_; |
572 Mode mode_; | 585 Mode mode_; |
573 uintptr_t stack_limit_; | 586 uintptr_t stack_limit_; |
574 | 587 |
575 private: | 588 private: |
576 Scanner* scanner_; | 589 Scanner* scanner_; |
577 bool stack_overflow_; | 590 bool stack_overflow_; |
578 | 591 |
579 bool allow_lazy_; | 592 bool allow_lazy_; |
580 bool allow_natives_syntax_; | 593 bool allow_natives_; |
581 bool allow_arrow_functions_; | 594 bool allow_harmony_arrow_functions_; |
582 bool allow_harmony_object_literals_; | 595 bool allow_harmony_object_literals_; |
| 596 bool allow_harmony_sloppy_; |
583 | 597 |
584 typename Traits::Type::Zone* zone_; // Only used by Parser. | 598 typename Traits::Type::Zone* zone_; // Only used by Parser. |
585 }; | 599 }; |
586 | 600 |
587 | 601 |
588 class PreParserIdentifier { | 602 class PreParserIdentifier { |
589 public: | 603 public: |
590 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 604 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
591 static PreParserIdentifier Default() { | 605 static PreParserIdentifier Default() { |
592 return PreParserIdentifier(kUnknownIdentifier); | 606 return PreParserIdentifier(kUnknownIdentifier); |
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 case Token::LBRACK: | 1830 case Token::LBRACK: |
1817 result = this->ParseArrayLiteral(CHECK_OK); | 1831 result = this->ParseArrayLiteral(CHECK_OK); |
1818 break; | 1832 break; |
1819 | 1833 |
1820 case Token::LBRACE: | 1834 case Token::LBRACE: |
1821 result = this->ParseObjectLiteral(CHECK_OK); | 1835 result = this->ParseObjectLiteral(CHECK_OK); |
1822 break; | 1836 break; |
1823 | 1837 |
1824 case Token::LPAREN: | 1838 case Token::LPAREN: |
1825 Consume(Token::LPAREN); | 1839 Consume(Token::LPAREN); |
1826 if (allow_arrow_functions() && peek() == Token::RPAREN) { | 1840 if (allow_harmony_arrow_functions() && peek() == Token::RPAREN) { |
1827 // Arrow functions are the only expression type constructions | 1841 // Arrow functions are the only expression type constructions |
1828 // for which an empty parameter list "()" is valid input. | 1842 // for which an empty parameter list "()" is valid input. |
1829 Consume(Token::RPAREN); | 1843 Consume(Token::RPAREN); |
1830 result = this->ParseArrowFunctionLiteral( | 1844 result = this->ParseArrowFunctionLiteral( |
1831 pos, this->EmptyArrowParamList(), CHECK_OK); | 1845 pos, this->EmptyArrowParamList(), CHECK_OK); |
1832 } else { | 1846 } else { |
1833 // Heuristically try to detect immediately called functions before | 1847 // Heuristically try to detect immediately called functions before |
1834 // seeing the call parentheses. | 1848 // seeing the call parentheses. |
1835 parenthesized_function_ = (peek() == Token::FUNCTION); | 1849 parenthesized_function_ = (peek() == Token::FUNCTION); |
1836 result = this->ParseExpression(true, CHECK_OK); | 1850 result = this->ParseExpression(true, CHECK_OK); |
1837 result->increase_parenthesization_level(); | 1851 result->increase_parenthesization_level(); |
1838 Expect(Token::RPAREN, CHECK_OK); | 1852 Expect(Token::RPAREN, CHECK_OK); |
1839 } | 1853 } |
1840 break; | 1854 break; |
1841 | 1855 |
1842 case Token::CLASS: { | 1856 case Token::CLASS: { |
1843 Consume(Token::CLASS); | 1857 Consume(Token::CLASS); |
| 1858 if (!allow_harmony_sloppy() && strict_mode() == SLOPPY) { |
| 1859 ReportMessage("sloppy_lexical", NULL); |
| 1860 *ok = false; |
| 1861 break; |
| 1862 } |
1844 int class_token_position = position(); | 1863 int class_token_position = position(); |
1845 IdentifierT name = this->EmptyIdentifier(); | 1864 IdentifierT name = this->EmptyIdentifier(); |
1846 bool is_strict_reserved_name = false; | 1865 bool is_strict_reserved_name = false; |
1847 Scanner::Location class_name_location = Scanner::Location::invalid(); | 1866 Scanner::Location class_name_location = Scanner::Location::invalid(); |
1848 if (peek_any_identifier()) { | 1867 if (peek_any_identifier()) { |
1849 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 1868 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
1850 CHECK_OK); | 1869 CHECK_OK); |
1851 class_name_location = scanner()->location(); | 1870 class_name_location = scanner()->location(); |
1852 } | 1871 } |
1853 result = this->ParseClassLiteral(name, class_name_location, | 1872 result = this->ParseClassLiteral(name, class_name_location, |
1854 is_strict_reserved_name, | 1873 is_strict_reserved_name, |
1855 class_token_position, CHECK_OK); | 1874 class_token_position, CHECK_OK); |
1856 break; | 1875 break; |
1857 } | 1876 } |
1858 | 1877 |
1859 case Token::TEMPLATE_SPAN: | 1878 case Token::TEMPLATE_SPAN: |
1860 case Token::TEMPLATE_TAIL: | 1879 case Token::TEMPLATE_TAIL: |
1861 result = | 1880 result = |
1862 this->ParseTemplateLiteral(Traits::NoTemplateTag(), pos, CHECK_OK); | 1881 this->ParseTemplateLiteral(Traits::NoTemplateTag(), pos, CHECK_OK); |
1863 break; | 1882 break; |
1864 | 1883 |
1865 case Token::MOD: | 1884 case Token::MOD: |
1866 if (allow_natives_syntax() || extension_ != NULL) { | 1885 if (allow_natives() || extension_ != NULL) { |
1867 result = this->ParseV8Intrinsic(CHECK_OK); | 1886 result = this->ParseV8Intrinsic(CHECK_OK); |
1868 break; | 1887 break; |
1869 } | 1888 } |
1870 // If we're not allowing special syntax we fall-through to the | 1889 // If we're not allowing special syntax we fall-through to the |
1871 // default case. | 1890 // default case. |
1872 | 1891 |
1873 default: { | 1892 default: { |
1874 Next(); | 1893 Next(); |
1875 ReportUnexpectedToken(token); | 1894 ReportUnexpectedToken(token); |
1876 *ok = false; | 1895 *ok = false; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 | 2203 |
2185 if (peek() == Token::YIELD && is_generator()) { | 2204 if (peek() == Token::YIELD && is_generator()) { |
2186 return this->ParseYieldExpression(ok); | 2205 return this->ParseYieldExpression(ok); |
2187 } | 2206 } |
2188 | 2207 |
2189 if (fni_ != NULL) fni_->Enter(); | 2208 if (fni_ != NULL) fni_->Enter(); |
2190 ParserBase<Traits>::Checkpoint checkpoint(this); | 2209 ParserBase<Traits>::Checkpoint checkpoint(this); |
2191 ExpressionT expression = | 2210 ExpressionT expression = |
2192 this->ParseConditionalExpression(accept_IN, CHECK_OK); | 2211 this->ParseConditionalExpression(accept_IN, CHECK_OK); |
2193 | 2212 |
2194 if (allow_arrow_functions() && peek() == Token::ARROW) { | 2213 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { |
2195 checkpoint.Restore(); | 2214 checkpoint.Restore(); |
2196 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos, | 2215 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos, |
2197 expression, CHECK_OK); | 2216 expression, CHECK_OK); |
2198 return expression; | 2217 return expression; |
2199 } | 2218 } |
2200 | 2219 |
2201 if (!Token::IsAssignmentOp(peek())) { | 2220 if (!Token::IsAssignmentOp(peek())) { |
2202 if (fni_ != NULL) fni_->Leave(); | 2221 if (fni_ != NULL) fni_->Leave(); |
2203 // Parsed conditional expression only (no assignment). | 2222 // Parsed conditional expression only (no assignment). |
2204 return expression; | 2223 return expression; |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2897 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2916 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2898 // Both accessors of the same type. | 2917 // Both accessors of the same type. |
2899 parser()->ReportMessage("accessor_get_set"); | 2918 parser()->ReportMessage("accessor_get_set"); |
2900 } | 2919 } |
2901 *ok = false; | 2920 *ok = false; |
2902 } | 2921 } |
2903 } | 2922 } |
2904 } } // v8::internal | 2923 } } // v8::internal |
2905 | 2924 |
2906 #endif // V8_PREPARSER_H | 2925 #endif // V8_PREPARSER_H |
OLD | NEW |