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 "func-name-inferrer.h" | 8 #include "func-name-inferrer.h" |
9 #include "hashmap.h" | 9 #include "hashmap.h" |
10 #include "scopes.h" | 10 #include "scopes.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 | 342 |
343 typename Traits::Type::Factory* factory() { | 343 typename Traits::Type::Factory* factory() { |
344 return function_state_->factory(); | 344 return function_state_->factory(); |
345 } | 345 } |
346 | 346 |
347 StrictMode strict_mode() { return scope_->strict_mode(); } | 347 StrictMode strict_mode() { return scope_->strict_mode(); } |
348 bool is_generator() const { return function_state_->is_generator(); } | 348 bool is_generator() const { return function_state_->is_generator(); } |
349 | 349 |
350 // Report syntax errors. | 350 // Report syntax errors. |
351 void ReportMessage(const char* message, Vector<const char*> args, | 351 void ReportMessage(const char* message, const char* arg = NULL, |
352 bool is_reference_error = false) { | 352 bool is_reference_error = false) { |
353 Scanner::Location source_location = scanner()->location(); | 353 Scanner::Location source_location = scanner()->location(); |
354 Traits::ReportMessageAt(source_location, message, args, is_reference_error); | 354 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); |
355 } | 355 } |
356 | 356 |
357 void ReportMessageAt(Scanner::Location location, const char* message, | 357 void ReportMessageAt(Scanner::Location location, const char* message, |
358 bool is_reference_error = false) { | 358 bool is_reference_error = false) { |
359 Traits::ReportMessageAt(location, message, Vector<const char*>::empty(), | 359 Traits::ReportMessageAt(location, message, NULL, is_reference_error); |
360 is_reference_error); | |
361 } | 360 } |
362 | 361 |
363 void ReportUnexpectedToken(Token::Value token); | 362 void ReportUnexpectedToken(Token::Value token); |
364 | 363 |
365 // Recursive descent functions: | 364 // Recursive descent functions: |
366 | 365 |
367 // Parses an identifier that is valid for the current scope, in particular it | 366 // Parses an identifier that is valid for the current scope, in particular it |
368 // fails on strict mode future reserved keywords in a strict scope. If | 367 // fails on strict mode future reserved keywords in a strict scope. If |
369 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 368 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
370 // "arguments" as identifier even in strict mode (this is needed in cases like | 369 // "arguments" as identifier even in strict mode (this is needed in cases like |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 return PreParserExpression::Default(); | 960 return PreParserExpression::Default(); |
962 } | 961 } |
963 PreParserExpression NewThrowTypeError( | 962 PreParserExpression NewThrowTypeError( |
964 const char* type, Handle<Object> arg, int pos) { | 963 const char* type, Handle<Object> arg, int pos) { |
965 return PreParserExpression::Default(); | 964 return PreParserExpression::Default(); |
966 } | 965 } |
967 | 966 |
968 // Reporting errors. | 967 // Reporting errors. |
969 void ReportMessageAt(Scanner::Location location, | 968 void ReportMessageAt(Scanner::Location location, |
970 const char* message, | 969 const char* message, |
971 Vector<const char*> args, | 970 const char* arg = NULL, |
972 bool is_reference_error = false); | |
973 void ReportMessageAt(Scanner::Location location, | |
974 const char* type, | |
975 const char* name_opt, | |
976 bool is_reference_error = false); | 971 bool is_reference_error = false); |
977 void ReportMessageAt(int start_pos, | 972 void ReportMessageAt(int start_pos, |
978 int end_pos, | 973 int end_pos, |
979 const char* type, | 974 const char* message, |
980 const char* name_opt, | 975 const char* arg = NULL, |
981 bool is_reference_error = false); | 976 bool is_reference_error = false); |
982 | 977 |
983 // "null" return type creators. | 978 // "null" return type creators. |
984 static PreParserIdentifier EmptyIdentifier() { | 979 static PreParserIdentifier EmptyIdentifier() { |
985 return PreParserIdentifier::Default(); | 980 return PreParserIdentifier::Default(); |
986 } | 981 } |
987 static PreParserExpression EmptyExpression() { | 982 static PreParserExpression EmptyExpression() { |
988 return PreParserExpression::Default(); | 983 return PreParserExpression::Default(); |
989 } | 984 } |
990 static PreParserExpression EmptyLiteral() { | 985 static PreParserExpression EmptyLiteral() { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 case Token::FUTURE_RESERVED_WORD: | 1228 case Token::FUTURE_RESERVED_WORD: |
1234 return ReportMessageAt(source_location, "unexpected_reserved"); | 1229 return ReportMessageAt(source_location, "unexpected_reserved"); |
1235 case Token::YIELD: | 1230 case Token::YIELD: |
1236 case Token::FUTURE_STRICT_RESERVED_WORD: | 1231 case Token::FUTURE_STRICT_RESERVED_WORD: |
1237 return ReportMessageAt(source_location, strict_mode() == SLOPPY | 1232 return ReportMessageAt(source_location, strict_mode() == SLOPPY |
1238 ? "unexpected_token_identifier" : "unexpected_strict_reserved"); | 1233 ? "unexpected_token_identifier" : "unexpected_strict_reserved"); |
1239 default: | 1234 default: |
1240 const char* name = Token::String(token); | 1235 const char* name = Token::String(token); |
1241 ASSERT(name != NULL); | 1236 ASSERT(name != NULL); |
1242 Traits::ReportMessageAt( | 1237 Traits::ReportMessageAt( |
1243 source_location, "unexpected_token", Vector<const char*>(&name, 1)); | 1238 source_location, "unexpected_token", name); |
1244 } | 1239 } |
1245 } | 1240 } |
1246 | 1241 |
1247 | 1242 |
1248 template<class Traits> | 1243 template<class Traits> |
1249 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1244 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( |
1250 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | 1245 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, |
1251 bool* ok) { | 1246 bool* ok) { |
1252 Token::Value next = Next(); | 1247 Token::Value next = Next(); |
1253 if (next == Token::IDENTIFIER) { | 1248 if (next == Token::IDENTIFIER) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 return result; | 1309 return result; |
1315 } | 1310 } |
1316 | 1311 |
1317 | 1312 |
1318 template <class Traits> | 1313 template <class Traits> |
1319 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( | 1314 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( |
1320 bool seen_equal, bool* ok) { | 1315 bool seen_equal, bool* ok) { |
1321 int pos = peek_position(); | 1316 int pos = peek_position(); |
1322 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1317 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
1323 Next(); | 1318 Next(); |
1324 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 1319 ReportMessage("unterminated_regexp"); |
1325 *ok = false; | 1320 *ok = false; |
1326 return Traits::EmptyExpression(); | 1321 return Traits::EmptyExpression(); |
1327 } | 1322 } |
1328 | 1323 |
1329 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1324 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1330 | 1325 |
1331 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); | 1326 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); |
1332 if (!scanner()->ScanRegExpFlags()) { | 1327 if (!scanner()->ScanRegExpFlags()) { |
1333 Next(); | 1328 Next(); |
1334 ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); | 1329 ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 | 1852 |
1858 Token::Value op = peek(); | 1853 Token::Value op = peek(); |
1859 if (Token::IsUnaryOp(op)) { | 1854 if (Token::IsUnaryOp(op)) { |
1860 op = Next(); | 1855 op = Next(); |
1861 int pos = position(); | 1856 int pos = position(); |
1862 ExpressionT expression = ParseUnaryExpression(CHECK_OK); | 1857 ExpressionT expression = ParseUnaryExpression(CHECK_OK); |
1863 | 1858 |
1864 // "delete identifier" is a syntax error in strict mode. | 1859 // "delete identifier" is a syntax error in strict mode. |
1865 if (op == Token::DELETE && strict_mode() == STRICT && | 1860 if (op == Token::DELETE && strict_mode() == STRICT && |
1866 this->IsIdentifier(expression)) { | 1861 this->IsIdentifier(expression)) { |
1867 ReportMessage("strict_delete", Vector<const char*>::empty()); | 1862 ReportMessage("strict_delete"); |
1868 *ok = false; | 1863 *ok = false; |
1869 return this->EmptyExpression(); | 1864 return this->EmptyExpression(); |
1870 } | 1865 } |
1871 | 1866 |
1872 // Allow Traits do rewrite the expression. | 1867 // Allow Traits do rewrite the expression. |
1873 return this->BuildUnaryExpression(expression, op, pos, factory()); | 1868 return this->BuildUnaryExpression(expression, op, pos, factory()); |
1874 } else if (Token::IsCountOp(op)) { | 1869 } else if (Token::IsCountOp(op)) { |
1875 op = Next(); | 1870 op = Next(); |
1876 Scanner::Location lhs_location = scanner()->peek_location(); | 1871 Scanner::Location lhs_location = scanner()->peek_location(); |
1877 ExpressionT expression = this->ParseUnaryExpression(CHECK_OK); | 1872 ExpressionT expression = this->ParseUnaryExpression(CHECK_OK); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2170 "accessor_get_set"); | 2165 "accessor_get_set"); |
2171 } | 2166 } |
2172 *ok = false; | 2167 *ok = false; |
2173 } | 2168 } |
2174 } | 2169 } |
2175 | 2170 |
2176 | 2171 |
2177 } } // v8::internal | 2172 } } // v8::internal |
2178 | 2173 |
2179 #endif // V8_PREPARSER_H | 2174 #endif // V8_PREPARSER_H |
OLD | NEW |