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/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 typename Traits::Type::Scope* outer_scope_; | 143 typename Traits::Type::Scope* outer_scope_; |
144 typename Traits::Type::Scope* scope_; | 144 typename Traits::Type::Scope* scope_; |
145 }; | 145 }; |
146 | 146 |
147 class FunctionState BASE_EMBEDDED { | 147 class FunctionState BASE_EMBEDDED { |
148 public: | 148 public: |
149 FunctionState( | 149 FunctionState( |
150 FunctionState** function_state_stack, | 150 FunctionState** function_state_stack, |
151 typename Traits::Type::Scope** scope_stack, | 151 typename Traits::Type::Scope** scope_stack, |
152 typename Traits::Type::Scope* scope, | 152 typename Traits::Type::Scope* scope, |
153 typename Traits::Type::Zone* zone = NULL); | 153 typename Traits::Type::Zone* zone = NULL, |
| 154 AstValueFactory* ast_value_factory = NULL); |
154 ~FunctionState(); | 155 ~FunctionState(); |
155 | 156 |
156 int NextMaterializedLiteralIndex() { | 157 int NextMaterializedLiteralIndex() { |
157 return next_materialized_literal_index_++; | 158 return next_materialized_literal_index_++; |
158 } | 159 } |
159 int materialized_literal_count() { | 160 int materialized_literal_count() { |
160 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | 161 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; |
161 } | 162 } |
162 | 163 |
163 int NextHandlerIndex() { return next_handler_index_++; } | 164 int NextHandlerIndex() { return next_handler_index_++; } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 389 |
389 // Report syntax errors. | 390 // Report syntax errors. |
390 void ReportMessage(const char* message, const char* arg = NULL, | 391 void ReportMessage(const char* message, const char* arg = NULL, |
391 bool is_reference_error = false) { | 392 bool is_reference_error = false) { |
392 Scanner::Location source_location = scanner()->location(); | 393 Scanner::Location source_location = scanner()->location(); |
393 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); | 394 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); |
394 } | 395 } |
395 | 396 |
396 void ReportMessageAt(Scanner::Location location, const char* message, | 397 void ReportMessageAt(Scanner::Location location, const char* message, |
397 bool is_reference_error = false) { | 398 bool is_reference_error = false) { |
398 Traits::ReportMessageAt(location, message, NULL, is_reference_error); | 399 Traits::ReportMessageAt(location, message, |
| 400 reinterpret_cast<const char*>(NULL), |
| 401 is_reference_error); |
399 } | 402 } |
400 | 403 |
401 void ReportUnexpectedToken(Token::Value token); | 404 void ReportUnexpectedToken(Token::Value token); |
402 | 405 |
403 // Recursive descent functions: | 406 // Recursive descent functions: |
404 | 407 |
405 // Parses an identifier that is valid for the current scope, in particular it | 408 // Parses an identifier that is valid for the current scope, in particular it |
406 // fails on strict mode future reserved keywords in a strict scope. If | 409 // fails on strict mode future reserved keywords in a strict scope. If |
407 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 410 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
408 // "arguments" as identifier even in strict mode (this is needed in cases like | 411 // "arguments" as identifier even in strict mode (this is needed in cases like |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } | 778 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } |
776 | 779 |
777 private: | 780 private: |
778 ScopeType scope_type_; | 781 ScopeType scope_type_; |
779 StrictMode strict_mode_; | 782 StrictMode strict_mode_; |
780 }; | 783 }; |
781 | 784 |
782 | 785 |
783 class PreParserFactory { | 786 class PreParserFactory { |
784 public: | 787 public: |
785 explicit PreParserFactory(void* extra_param) {} | 788 explicit PreParserFactory(void* extra_param1, void* extra_param2) {} |
786 PreParserExpression NewLiteral(PreParserIdentifier identifier, | 789 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
787 int pos) { | 790 int pos) { |
788 return PreParserExpression::Default(); | 791 return PreParserExpression::Default(); |
789 } | 792 } |
790 PreParserExpression NewNumberLiteral(double number, | 793 PreParserExpression NewNumberLiteral(double number, |
791 int pos) { | 794 int pos) { |
792 return PreParserExpression::Default(); | 795 return PreParserExpression::Default(); |
793 } | 796 } |
794 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 797 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
795 PreParserIdentifier js_flags, | 798 PreParserIdentifier js_flags, |
796 int literal_index, | 799 int literal_index, |
797 int pos) { | 800 int pos) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 } | 1032 } |
1030 | 1033 |
1031 // Odd-ball literal creators. | 1034 // Odd-ball literal creators. |
1032 static PreParserExpression GetLiteralTheHole(int position, | 1035 static PreParserExpression GetLiteralTheHole(int position, |
1033 PreParserFactory* factory) { | 1036 PreParserFactory* factory) { |
1034 return PreParserExpression::Default(); | 1037 return PreParserExpression::Default(); |
1035 } | 1038 } |
1036 | 1039 |
1037 // Producing data during the recursive descent. | 1040 // Producing data during the recursive descent. |
1038 PreParserIdentifier GetSymbol(Scanner* scanner); | 1041 PreParserIdentifier GetSymbol(Scanner* scanner); |
1039 static PreParserIdentifier NextLiteralString(Scanner* scanner, | 1042 |
1040 PretenureFlag tenured) { | 1043 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { |
1041 return PreParserIdentifier::Default(); | 1044 return PreParserIdentifier::Default(); |
1042 } | 1045 } |
1043 | 1046 |
1044 static PreParserExpression ThisExpression(PreParserScope* scope, | 1047 static PreParserExpression ThisExpression(PreParserScope* scope, |
1045 PreParserFactory* factory) { | 1048 PreParserFactory* factory) { |
1046 return PreParserExpression::This(); | 1049 return PreParserExpression::This(); |
1047 } | 1050 } |
1048 | 1051 |
1049 static PreParserExpression ExpressionFromLiteral( | 1052 static PreParserExpression ExpressionFromLiteral( |
1050 Token::Value token, int pos, Scanner* scanner, | 1053 Token::Value token, int pos, Scanner* scanner, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 void ParseLazyFunctionLiteralBody(bool* ok); | 1221 void ParseLazyFunctionLiteralBody(bool* ok); |
1219 | 1222 |
1220 bool CheckInOrOf(bool accept_OF); | 1223 bool CheckInOrOf(bool accept_OF); |
1221 }; | 1224 }; |
1222 | 1225 |
1223 template<class Traits> | 1226 template<class Traits> |
1224 ParserBase<Traits>::FunctionState::FunctionState( | 1227 ParserBase<Traits>::FunctionState::FunctionState( |
1225 FunctionState** function_state_stack, | 1228 FunctionState** function_state_stack, |
1226 typename Traits::Type::Scope** scope_stack, | 1229 typename Traits::Type::Scope** scope_stack, |
1227 typename Traits::Type::Scope* scope, | 1230 typename Traits::Type::Scope* scope, |
1228 typename Traits::Type::Zone* extra_param) | 1231 typename Traits::Type::Zone* extra_param, |
| 1232 AstValueFactory* ast_value_factory) |
1229 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 1233 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
1230 next_handler_index_(0), | 1234 next_handler_index_(0), |
1231 expected_property_count_(0), | 1235 expected_property_count_(0), |
1232 is_generator_(false), | 1236 is_generator_(false), |
1233 generator_object_variable_(NULL), | 1237 generator_object_variable_(NULL), |
1234 function_state_stack_(function_state_stack), | 1238 function_state_stack_(function_state_stack), |
1235 outer_function_state_(*function_state_stack), | 1239 outer_function_state_(*function_state_stack), |
1236 scope_stack_(scope_stack), | 1240 scope_stack_(scope_stack), |
1237 outer_scope_(*scope_stack), | 1241 outer_scope_(*scope_stack), |
1238 saved_ast_node_id_(0), | 1242 saved_ast_node_id_(0), |
1239 extra_param_(extra_param), | 1243 extra_param_(extra_param), |
1240 factory_(extra_param) { | 1244 factory_(extra_param, ast_value_factory) { |
1241 *scope_stack_ = scope; | 1245 *scope_stack_ = scope; |
1242 *function_state_stack = this; | 1246 *function_state_stack = this; |
1243 Traits::SetUpFunctionState(this, extra_param); | 1247 Traits::SetUpFunctionState(this, extra_param); |
1244 } | 1248 } |
1245 | 1249 |
1246 | 1250 |
1247 template<class Traits> | 1251 template<class Traits> |
1248 ParserBase<Traits>::FunctionState::~FunctionState() { | 1252 ParserBase<Traits>::FunctionState::~FunctionState() { |
1249 *scope_stack_ = outer_scope_; | 1253 *scope_stack_ = outer_scope_; |
1250 *function_state_stack_ = outer_function_state_; | 1254 *function_state_stack_ = outer_function_state_; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 int pos = peek_position(); | 1360 int pos = peek_position(); |
1357 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1361 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
1358 Next(); | 1362 Next(); |
1359 ReportMessage("unterminated_regexp"); | 1363 ReportMessage("unterminated_regexp"); |
1360 *ok = false; | 1364 *ok = false; |
1361 return Traits::EmptyExpression(); | 1365 return Traits::EmptyExpression(); |
1362 } | 1366 } |
1363 | 1367 |
1364 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1368 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1365 | 1369 |
1366 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); | 1370 IdentifierT js_pattern = this->GetNextSymbol(scanner()); |
1367 if (!scanner()->ScanRegExpFlags()) { | 1371 if (!scanner()->ScanRegExpFlags()) { |
1368 Next(); | 1372 Next(); |
1369 ReportMessage("invalid_regexp_flags"); | 1373 ReportMessage("invalid_regexp_flags"); |
1370 *ok = false; | 1374 *ok = false; |
1371 return Traits::EmptyExpression(); | 1375 return Traits::EmptyExpression(); |
1372 } | 1376 } |
1373 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); | 1377 IdentifierT js_flags = this->GetNextSymbol(scanner()); |
1374 Next(); | 1378 Next(); |
1375 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); | 1379 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); |
1376 } | 1380 } |
1377 | 1381 |
1378 | 1382 |
1379 #define CHECK_OK ok); \ | 1383 #define CHECK_OK ok); \ |
1380 if (!*ok) return this->EmptyExpression(); \ | 1384 if (!*ok) return this->EmptyExpression(); \ |
1381 ((void)0 | 1385 ((void)0 |
1382 #define DUMMY ) // to make indentation work | 1386 #define DUMMY ) // to make indentation work |
1383 #undef DUMMY | 1387 #undef DUMMY |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 } | 1612 } |
1609 | 1613 |
1610 if (fni_ != NULL) { | 1614 if (fni_ != NULL) { |
1611 fni_->Infer(); | 1615 fni_->Infer(); |
1612 fni_->Leave(); | 1616 fni_->Leave(); |
1613 } | 1617 } |
1614 continue; // restart the while | 1618 continue; // restart the while |
1615 } | 1619 } |
1616 // Failed to parse as get/set property, so it's just a normal property | 1620 // Failed to parse as get/set property, so it's just a normal property |
1617 // (which might be called "get" or "set" or something else). | 1621 // (which might be called "get" or "set" or something else). |
1618 key = factory()->NewLiteral(id, next_pos); | 1622 key = factory()->NewStringLiteral(id, next_pos); |
1619 break; | 1623 break; |
1620 } | 1624 } |
1621 case Token::STRING: { | 1625 case Token::STRING: { |
1622 Consume(Token::STRING); | 1626 Consume(Token::STRING); |
1623 IdentifierT string = this->GetSymbol(scanner_); | 1627 IdentifierT string = this->GetSymbol(scanner_); |
1624 if (fni_ != NULL) this->PushLiteralName(fni_, string); | 1628 if (fni_ != NULL) this->PushLiteralName(fni_, string); |
1625 uint32_t index; | 1629 uint32_t index; |
1626 if (this->IsArrayIndex(string, &index)) { | 1630 if (this->IsArrayIndex(string, &index)) { |
1627 key = factory()->NewNumberLiteral(index, next_pos); | 1631 key = factory()->NewNumberLiteral(index, next_pos); |
1628 break; | 1632 break; |
1629 } | 1633 } |
1630 key = factory()->NewLiteral(string, next_pos); | 1634 key = factory()->NewStringLiteral(string, next_pos); |
1631 break; | 1635 break; |
1632 } | 1636 } |
1633 case Token::NUMBER: { | 1637 case Token::NUMBER: { |
1634 Consume(Token::NUMBER); | 1638 Consume(Token::NUMBER); |
1635 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, | 1639 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, |
1636 factory()); | 1640 factory()); |
1637 break; | 1641 break; |
1638 } | 1642 } |
1639 default: | 1643 default: |
1640 if (Token::IsKeyword(next)) { | 1644 if (Token::IsKeyword(next)) { |
1641 Consume(next); | 1645 Consume(next); |
1642 IdentifierT string = this->GetSymbol(scanner_); | 1646 IdentifierT string = this->GetSymbol(scanner_); |
1643 key = factory()->NewLiteral(string, next_pos); | 1647 key = factory()->NewStringLiteral(string, next_pos); |
1644 } else { | 1648 } else { |
1645 Token::Value next = Next(); | 1649 Token::Value next = Next(); |
1646 ReportUnexpectedToken(next); | 1650 ReportUnexpectedToken(next); |
1647 *ok = false; | 1651 *ok = false; |
1648 return this->EmptyLiteral(); | 1652 return this->EmptyLiteral(); |
1649 } | 1653 } |
1650 } | 1654 } |
1651 | 1655 |
1652 // Validate the property | 1656 // Validate the property |
1653 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1657 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 result = factory()->NewCall(result, args, pos); | 2006 result = factory()->NewCall(result, args, pos); |
2003 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2007 if (fni_ != NULL) fni_->RemoveLastFunction(); |
2004 break; | 2008 break; |
2005 } | 2009 } |
2006 | 2010 |
2007 case Token::PERIOD: { | 2011 case Token::PERIOD: { |
2008 Consume(Token::PERIOD); | 2012 Consume(Token::PERIOD); |
2009 int pos = position(); | 2013 int pos = position(); |
2010 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2014 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2011 result = factory()->NewProperty( | 2015 result = factory()->NewProperty( |
2012 result, factory()->NewLiteral(name, pos), pos); | 2016 result, factory()->NewStringLiteral(name, pos), pos); |
2013 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2017 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
2014 break; | 2018 break; |
2015 } | 2019 } |
2016 | 2020 |
2017 default: | 2021 default: |
2018 return result; | 2022 return result; |
2019 } | 2023 } |
2020 } | 2024 } |
2021 } | 2025 } |
2022 | 2026 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 this->PushPropertyName(fni_, index); | 2129 this->PushPropertyName(fni_, index); |
2126 } | 2130 } |
2127 Expect(Token::RBRACK, CHECK_OK); | 2131 Expect(Token::RBRACK, CHECK_OK); |
2128 break; | 2132 break; |
2129 } | 2133 } |
2130 case Token::PERIOD: { | 2134 case Token::PERIOD: { |
2131 Consume(Token::PERIOD); | 2135 Consume(Token::PERIOD); |
2132 int pos = position(); | 2136 int pos = position(); |
2133 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2137 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2134 expression = factory()->NewProperty( | 2138 expression = factory()->NewProperty( |
2135 expression, factory()->NewLiteral(name, pos), pos); | 2139 expression, factory()->NewStringLiteral(name, pos), pos); |
2136 if (fni_ != NULL) { | 2140 if (fni_ != NULL) { |
2137 this->PushLiteralName(fni_, name); | 2141 this->PushLiteralName(fni_, name); |
2138 } | 2142 } |
2139 break; | 2143 break; |
2140 } | 2144 } |
2141 default: | 2145 default: |
2142 return expression; | 2146 return expression; |
2143 } | 2147 } |
2144 } | 2148 } |
2145 ASSERT(false); | 2149 ASSERT(false); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2203 parser()->ReportMessage("accessor_get_set"); | 2207 parser()->ReportMessage("accessor_get_set"); |
2204 } | 2208 } |
2205 *ok = false; | 2209 *ok = false; |
2206 } | 2210 } |
2207 } | 2211 } |
2208 | 2212 |
2209 | 2213 |
2210 } } // v8::internal | 2214 } } // v8::internal |
2211 | 2215 |
2212 #endif // V8_PREPARSER_H | 2216 #endif // V8_PREPARSER_H |
OLD | NEW |