| 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 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 return PreParserExpression::Default(); | 1407 return PreParserExpression::Default(); |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 static PreParserExpression ExpressionFromLiteral( | 1410 static PreParserExpression ExpressionFromLiteral( |
| 1411 Token::Value token, int pos, Scanner* scanner, | 1411 Token::Value token, int pos, Scanner* scanner, |
| 1412 PreParserFactory* factory) { | 1412 PreParserFactory* factory) { |
| 1413 return PreParserExpression::Default(); | 1413 return PreParserExpression::Default(); |
| 1414 } | 1414 } |
| 1415 | 1415 |
| 1416 static PreParserExpression ExpressionFromIdentifier( | 1416 static PreParserExpression ExpressionFromIdentifier( |
| 1417 PreParserIdentifier name, int pos, Scope* scope, | 1417 PreParserIdentifier name, int start_position, int end_position, |
| 1418 PreParserFactory* factory) { | 1418 Scope* scope, PreParserFactory* factory) { |
| 1419 return PreParserExpression::FromIdentifier(name); | 1419 return PreParserExpression::FromIdentifier(name); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 PreParserExpression ExpressionFromString(int pos, | 1422 PreParserExpression ExpressionFromString(int pos, |
| 1423 Scanner* scanner, | 1423 Scanner* scanner, |
| 1424 PreParserFactory* factory = NULL); | 1424 PreParserFactory* factory = NULL); |
| 1425 | 1425 |
| 1426 PreParserExpression GetIterator(PreParserExpression iterable, | 1426 PreParserExpression GetIterator(PreParserExpression iterable, |
| 1427 PreParserFactory* factory) { | 1427 PreParserFactory* factory) { |
| 1428 return PreParserExpression::Default(); | 1428 return PreParserExpression::Default(); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 // Identifier | 1858 // Identifier |
| 1859 // Number | 1859 // Number |
| 1860 // String | 1860 // String |
| 1861 // ArrayLiteral | 1861 // ArrayLiteral |
| 1862 // ObjectLiteral | 1862 // ObjectLiteral |
| 1863 // RegExpLiteral | 1863 // RegExpLiteral |
| 1864 // ClassLiteral | 1864 // ClassLiteral |
| 1865 // '(' Expression ')' | 1865 // '(' Expression ')' |
| 1866 // TemplateLiteral | 1866 // TemplateLiteral |
| 1867 | 1867 |
| 1868 int pos = peek_position(); | 1868 int beg_pos = scanner()->peek_location().beg_pos; |
| 1869 int end_pos = scanner()->peek_location().end_pos; |
| 1869 ExpressionT result = this->EmptyExpression(); | 1870 ExpressionT result = this->EmptyExpression(); |
| 1870 Token::Value token = peek(); | 1871 Token::Value token = peek(); |
| 1871 switch (token) { | 1872 switch (token) { |
| 1872 case Token::THIS: { | 1873 case Token::THIS: { |
| 1873 Consume(Token::THIS); | 1874 Consume(Token::THIS); |
| 1874 scope_->RecordThisUsage(); | 1875 scope_->RecordThisUsage(); |
| 1875 result = this->ThisExpression(scope_, factory(), pos); | 1876 result = this->ThisExpression(scope_, factory(), beg_pos); |
| 1876 break; | 1877 break; |
| 1877 } | 1878 } |
| 1878 | 1879 |
| 1879 case Token::NULL_LITERAL: | 1880 case Token::NULL_LITERAL: |
| 1880 case Token::TRUE_LITERAL: | 1881 case Token::TRUE_LITERAL: |
| 1881 case Token::FALSE_LITERAL: | 1882 case Token::FALSE_LITERAL: |
| 1882 case Token::NUMBER: | 1883 case Token::NUMBER: |
| 1883 Next(); | 1884 Next(); |
| 1884 result = this->ExpressionFromLiteral(token, pos, scanner(), factory()); | 1885 result = |
| 1886 this->ExpressionFromLiteral(token, beg_pos, scanner(), factory()); |
| 1885 break; | 1887 break; |
| 1886 | 1888 |
| 1887 case Token::IDENTIFIER: | 1889 case Token::IDENTIFIER: |
| 1888 case Token::LET: | 1890 case Token::LET: |
| 1889 case Token::STATIC: | 1891 case Token::STATIC: |
| 1890 case Token::YIELD: | 1892 case Token::YIELD: |
| 1891 case Token::FUTURE_STRICT_RESERVED_WORD: { | 1893 case Token::FUTURE_STRICT_RESERVED_WORD: { |
| 1892 // Using eval or arguments in this context is OK even in strict mode. | 1894 // Using eval or arguments in this context is OK even in strict mode. |
| 1893 IdentifierT name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1895 IdentifierT name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 1894 result = this->ExpressionFromIdentifier(name, pos, scope_, factory()); | 1896 result = this->ExpressionFromIdentifier(name, beg_pos, end_pos, scope_, |
| 1897 factory()); |
| 1895 break; | 1898 break; |
| 1896 } | 1899 } |
| 1897 | 1900 |
| 1898 case Token::STRING: { | 1901 case Token::STRING: { |
| 1899 Consume(Token::STRING); | 1902 Consume(Token::STRING); |
| 1900 result = this->ExpressionFromString(pos, scanner(), factory()); | 1903 result = this->ExpressionFromString(beg_pos, scanner(), factory()); |
| 1901 break; | 1904 break; |
| 1902 } | 1905 } |
| 1903 | 1906 |
| 1904 case Token::ASSIGN_DIV: | 1907 case Token::ASSIGN_DIV: |
| 1905 result = this->ParseRegExpLiteral(true, CHECK_OK); | 1908 result = this->ParseRegExpLiteral(true, CHECK_OK); |
| 1906 break; | 1909 break; |
| 1907 | 1910 |
| 1908 case Token::DIV: | 1911 case Token::DIV: |
| 1909 result = this->ParseRegExpLiteral(false, CHECK_OK); | 1912 result = this->ParseRegExpLiteral(false, CHECK_OK); |
| 1910 break; | 1913 break; |
| 1911 | 1914 |
| 1912 case Token::LBRACK: | 1915 case Token::LBRACK: |
| 1913 result = this->ParseArrayLiteral(CHECK_OK); | 1916 result = this->ParseArrayLiteral(CHECK_OK); |
| 1914 break; | 1917 break; |
| 1915 | 1918 |
| 1916 case Token::LBRACE: | 1919 case Token::LBRACE: |
| 1917 result = this->ParseObjectLiteral(CHECK_OK); | 1920 result = this->ParseObjectLiteral(CHECK_OK); |
| 1918 break; | 1921 break; |
| 1919 | 1922 |
| 1920 case Token::LPAREN: | 1923 case Token::LPAREN: |
| 1921 Consume(Token::LPAREN); | 1924 Consume(Token::LPAREN); |
| 1922 if (allow_harmony_arrow_functions() && peek() == Token::RPAREN) { | 1925 if (allow_harmony_arrow_functions() && peek() == Token::RPAREN) { |
| 1923 // Arrow functions are the only expression type constructions | 1926 // Arrow functions are the only expression type constructions |
| 1924 // for which an empty parameter list "()" is valid input. | 1927 // for which an empty parameter list "()" is valid input. |
| 1925 Consume(Token::RPAREN); | 1928 Consume(Token::RPAREN); |
| 1926 result = this->ParseArrowFunctionLiteral( | 1929 result = this->ParseArrowFunctionLiteral( |
| 1927 pos, this->EmptyArrowParamList(), CHECK_OK); | 1930 beg_pos, this->EmptyArrowParamList(), CHECK_OK); |
| 1928 } else { | 1931 } else { |
| 1929 // Heuristically try to detect immediately called functions before | 1932 // Heuristically try to detect immediately called functions before |
| 1930 // seeing the call parentheses. | 1933 // seeing the call parentheses. |
| 1931 parenthesized_function_ = (peek() == Token::FUNCTION); | 1934 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 1932 result = this->ParseExpression(true, CHECK_OK); | 1935 result = this->ParseExpression(true, CHECK_OK); |
| 1933 result->increase_parenthesization_level(); | 1936 result->increase_parenthesization_level(); |
| 1934 Expect(Token::RPAREN, CHECK_OK); | 1937 Expect(Token::RPAREN, CHECK_OK); |
| 1935 } | 1938 } |
| 1936 break; | 1939 break; |
| 1937 | 1940 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1952 class_name_location = scanner()->location(); | 1955 class_name_location = scanner()->location(); |
| 1953 } | 1956 } |
| 1954 result = this->ParseClassLiteral(name, class_name_location, | 1957 result = this->ParseClassLiteral(name, class_name_location, |
| 1955 is_strict_reserved_name, | 1958 is_strict_reserved_name, |
| 1956 class_token_position, CHECK_OK); | 1959 class_token_position, CHECK_OK); |
| 1957 break; | 1960 break; |
| 1958 } | 1961 } |
| 1959 | 1962 |
| 1960 case Token::TEMPLATE_SPAN: | 1963 case Token::TEMPLATE_SPAN: |
| 1961 case Token::TEMPLATE_TAIL: | 1964 case Token::TEMPLATE_TAIL: |
| 1962 result = | 1965 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, |
| 1963 this->ParseTemplateLiteral(Traits::NoTemplateTag(), pos, CHECK_OK); | 1966 CHECK_OK); |
| 1964 break; | 1967 break; |
| 1965 | 1968 |
| 1966 case Token::MOD: | 1969 case Token::MOD: |
| 1967 if (allow_natives() || extension_ != NULL) { | 1970 if (allow_natives() || extension_ != NULL) { |
| 1968 result = this->ParseV8Intrinsic(CHECK_OK); | 1971 result = this->ParseV8Intrinsic(CHECK_OK); |
| 1969 break; | 1972 break; |
| 1970 } | 1973 } |
| 1971 // If we're not allowing special syntax we fall-through to the | 1974 // If we're not allowing special syntax we fall-through to the |
| 1972 // default case. | 1975 // default case. |
| 1973 | 1976 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2099 bool* ok) { | 2102 bool* ok) { |
| 2100 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); | 2103 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); |
| 2101 ExpressionT value = this->EmptyExpression(); | 2104 ExpressionT value = this->EmptyExpression(); |
| 2102 IdentifierT name = this->EmptyIdentifier(); | 2105 IdentifierT name = this->EmptyIdentifier(); |
| 2103 bool is_get = false; | 2106 bool is_get = false; |
| 2104 bool is_set = false; | 2107 bool is_set = false; |
| 2105 bool name_is_static = false; | 2108 bool name_is_static = false; |
| 2106 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | 2109 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); |
| 2107 | 2110 |
| 2108 Token::Value name_token = peek(); | 2111 Token::Value name_token = peek(); |
| 2109 int next_pos = peek_position(); | 2112 int next_beg_pos = scanner()->peek_location().beg_pos; |
| 2113 int next_end_pos = scanner()->peek_location().end_pos; |
| 2110 ExpressionT name_expression = ParsePropertyName( | 2114 ExpressionT name_expression = ParsePropertyName( |
| 2111 &name, &is_get, &is_set, &name_is_static, is_computed_name, | 2115 &name, &is_get, &is_set, &name_is_static, is_computed_name, |
| 2112 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2116 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2113 | 2117 |
| 2114 if (fni_ != nullptr && !*is_computed_name) { | 2118 if (fni_ != nullptr && !*is_computed_name) { |
| 2115 this->PushLiteralName(fni_, name); | 2119 this->PushLiteralName(fni_, name); |
| 2116 } | 2120 } |
| 2117 | 2121 |
| 2118 if (!in_class && !is_generator && peek() == Token::COLON) { | 2122 if (!in_class && !is_generator && peek() == Token::COLON) { |
| 2119 // PropertyDefinition : PropertyName ':' AssignmentExpression | 2123 // PropertyDefinition : PropertyName ':' AssignmentExpression |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 return factory()->NewObjectLiteralProperty( | 2198 return factory()->NewObjectLiteralProperty( |
| 2195 name_expression, value, | 2199 name_expression, value, |
| 2196 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 2200 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
| 2197 is_static, *is_computed_name); | 2201 is_static, *is_computed_name); |
| 2198 | 2202 |
| 2199 } else if (!in_class && allow_harmony_object_literals_ && | 2203 } else if (!in_class && allow_harmony_object_literals_ && |
| 2200 Token::IsIdentifier(name_token, language_mode(), | 2204 Token::IsIdentifier(name_token, language_mode(), |
| 2201 this->is_generator())) { | 2205 this->is_generator())) { |
| 2202 DCHECK(!*is_computed_name); | 2206 DCHECK(!*is_computed_name); |
| 2203 DCHECK(!is_static); | 2207 DCHECK(!is_static); |
| 2204 value = this->ExpressionFromIdentifier(name, next_pos, scope_, factory()); | 2208 value = this->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos, |
| 2209 scope_, factory()); |
| 2205 return factory()->NewObjectLiteralProperty( | 2210 return factory()->NewObjectLiteralProperty( |
| 2206 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); | 2211 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); |
| 2207 | 2212 |
| 2208 } else { | 2213 } else { |
| 2209 Token::Value next = Next(); | 2214 Token::Value next = Next(); |
| 2210 ReportUnexpectedToken(next); | 2215 ReportUnexpectedToken(next); |
| 2211 *ok = false; | 2216 *ok = false; |
| 2212 return this->EmptyObjectLiteralProperty(); | 2217 return this->EmptyObjectLiteralProperty(); |
| 2213 } | 2218 } |
| 2214 | 2219 |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3109 *ok = false; | 3114 *ok = false; |
| 3110 return; | 3115 return; |
| 3111 } | 3116 } |
| 3112 has_seen_constructor_ = true; | 3117 has_seen_constructor_ = true; |
| 3113 return; | 3118 return; |
| 3114 } | 3119 } |
| 3115 } | 3120 } |
| 3116 } } // v8::internal | 3121 } } // v8::internal |
| 3117 | 3122 |
| 3118 #endif // V8_PREPARSER_H | 3123 #endif // V8_PREPARSER_H |
| OLD | NEW |