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/func-name-inferrer.h" | 8 #include "src/func-name-inferrer.h" |
9 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 typename Traits::Type::Scope* outer_scope_; | 142 typename Traits::Type::Scope* outer_scope_; |
143 typename Traits::Type::Scope* scope_; | 143 typename Traits::Type::Scope* scope_; |
144 }; | 144 }; |
145 | 145 |
146 class FunctionState BASE_EMBEDDED { | 146 class FunctionState BASE_EMBEDDED { |
147 public: | 147 public: |
148 FunctionState( | 148 FunctionState( |
149 FunctionState** function_state_stack, | 149 FunctionState** function_state_stack, |
150 typename Traits::Type::Scope** scope_stack, | 150 typename Traits::Type::Scope** scope_stack, |
151 typename Traits::Type::Scope* scope, | 151 typename Traits::Type::Scope* scope, |
152 typename Traits::Type::Zone* zone = NULL, | 152 typename Traits::Type::Zone* zone = NULL); |
153 AstValueFactory* ast_value_factory = NULL); | |
154 ~FunctionState(); | 153 ~FunctionState(); |
155 | 154 |
156 int NextMaterializedLiteralIndex() { | 155 int NextMaterializedLiteralIndex() { |
157 return next_materialized_literal_index_++; | 156 return next_materialized_literal_index_++; |
158 } | 157 } |
159 int materialized_literal_count() { | 158 int materialized_literal_count() { |
160 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | 159 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; |
161 } | 160 } |
162 | 161 |
163 int NextHandlerIndex() { return next_handler_index_++; } | 162 int NextHandlerIndex() { return next_handler_index_++; } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 349 |
351 // Report syntax errors. | 350 // Report syntax errors. |
352 void ReportMessage(const char* message, const char* arg = NULL, | 351 void ReportMessage(const char* message, const char* arg = NULL, |
353 bool is_reference_error = false) { | 352 bool is_reference_error = false) { |
354 Scanner::Location source_location = scanner()->location(); | 353 Scanner::Location source_location = scanner()->location(); |
355 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); | 354 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); |
356 } | 355 } |
357 | 356 |
358 void ReportMessageAt(Scanner::Location location, const char* message, | 357 void ReportMessageAt(Scanner::Location location, const char* message, |
359 bool is_reference_error = false) { | 358 bool is_reference_error = false) { |
360 Traits::ReportMessageAt(location, message, | 359 Traits::ReportMessageAt(location, message, NULL, is_reference_error); |
361 reinterpret_cast<const char*>(NULL), | |
362 is_reference_error); | |
363 } | 360 } |
364 | 361 |
365 void ReportUnexpectedToken(Token::Value token); | 362 void ReportUnexpectedToken(Token::Value token); |
366 | 363 |
367 // Recursive descent functions: | 364 // Recursive descent functions: |
368 | 365 |
369 // 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 |
370 // 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 |
371 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 368 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
372 // "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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } | 736 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } |
740 | 737 |
741 private: | 738 private: |
742 ScopeType scope_type_; | 739 ScopeType scope_type_; |
743 StrictMode strict_mode_; | 740 StrictMode strict_mode_; |
744 }; | 741 }; |
745 | 742 |
746 | 743 |
747 class PreParserFactory { | 744 class PreParserFactory { |
748 public: | 745 public: |
749 explicit PreParserFactory(void* extra_param1, void* extra_param2) {} | 746 explicit PreParserFactory(void* extra_param) {} |
750 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 747 PreParserExpression NewLiteral(PreParserIdentifier identifier, |
751 int pos) { | 748 int pos) { |
752 return PreParserExpression::Default(); | 749 return PreParserExpression::Default(); |
753 } | 750 } |
754 PreParserExpression NewNumberLiteral(double number, | 751 PreParserExpression NewNumberLiteral(double number, |
755 int pos) { | 752 int pos) { |
756 return PreParserExpression::Default(); | 753 return PreParserExpression::Default(); |
757 } | 754 } |
758 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 755 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
759 PreParserIdentifier js_flags, | 756 PreParserIdentifier js_flags, |
760 int literal_index, | 757 int literal_index, |
761 int pos) { | 758 int pos) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 } | 990 } |
994 | 991 |
995 // Odd-ball literal creators. | 992 // Odd-ball literal creators. |
996 static PreParserExpression GetLiteralTheHole(int position, | 993 static PreParserExpression GetLiteralTheHole(int position, |
997 PreParserFactory* factory) { | 994 PreParserFactory* factory) { |
998 return PreParserExpression::Default(); | 995 return PreParserExpression::Default(); |
999 } | 996 } |
1000 | 997 |
1001 // Producing data during the recursive descent. | 998 // Producing data during the recursive descent. |
1002 PreParserIdentifier GetSymbol(Scanner* scanner); | 999 PreParserIdentifier GetSymbol(Scanner* scanner); |
1003 | 1000 static PreParserIdentifier NextLiteralString(Scanner* scanner, |
1004 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { | 1001 PretenureFlag tenured) { |
1005 return PreParserIdentifier::Default(); | 1002 return PreParserIdentifier::Default(); |
1006 } | 1003 } |
1007 | 1004 |
1008 static PreParserExpression ThisExpression(PreParserScope* scope, | 1005 static PreParserExpression ThisExpression(PreParserScope* scope, |
1009 PreParserFactory* factory) { | 1006 PreParserFactory* factory) { |
1010 return PreParserExpression::This(); | 1007 return PreParserExpression::This(); |
1011 } | 1008 } |
1012 | 1009 |
1013 static PreParserExpression ExpressionFromLiteral( | 1010 static PreParserExpression ExpressionFromLiteral( |
1014 Token::Value token, int pos, Scanner* scanner, | 1011 Token::Value token, int pos, Scanner* scanner, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 void ParseLazyFunctionLiteralBody(bool* ok); | 1179 void ParseLazyFunctionLiteralBody(bool* ok); |
1183 | 1180 |
1184 bool CheckInOrOf(bool accept_OF); | 1181 bool CheckInOrOf(bool accept_OF); |
1185 }; | 1182 }; |
1186 | 1183 |
1187 template<class Traits> | 1184 template<class Traits> |
1188 ParserBase<Traits>::FunctionState::FunctionState( | 1185 ParserBase<Traits>::FunctionState::FunctionState( |
1189 FunctionState** function_state_stack, | 1186 FunctionState** function_state_stack, |
1190 typename Traits::Type::Scope** scope_stack, | 1187 typename Traits::Type::Scope** scope_stack, |
1191 typename Traits::Type::Scope* scope, | 1188 typename Traits::Type::Scope* scope, |
1192 typename Traits::Type::Zone* extra_param, | 1189 typename Traits::Type::Zone* extra_param) |
1193 AstValueFactory* ast_value_factory) | |
1194 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 1190 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
1195 next_handler_index_(0), | 1191 next_handler_index_(0), |
1196 expected_property_count_(0), | 1192 expected_property_count_(0), |
1197 is_generator_(false), | 1193 is_generator_(false), |
1198 generator_object_variable_(NULL), | 1194 generator_object_variable_(NULL), |
1199 function_state_stack_(function_state_stack), | 1195 function_state_stack_(function_state_stack), |
1200 outer_function_state_(*function_state_stack), | 1196 outer_function_state_(*function_state_stack), |
1201 scope_stack_(scope_stack), | 1197 scope_stack_(scope_stack), |
1202 outer_scope_(*scope_stack), | 1198 outer_scope_(*scope_stack), |
1203 saved_ast_node_id_(0), | 1199 saved_ast_node_id_(0), |
1204 extra_param_(extra_param), | 1200 extra_param_(extra_param), |
1205 factory_(extra_param, ast_value_factory) { | 1201 factory_(extra_param) { |
1206 *scope_stack_ = scope; | 1202 *scope_stack_ = scope; |
1207 *function_state_stack = this; | 1203 *function_state_stack = this; |
1208 Traits::SetUpFunctionState(this, extra_param); | 1204 Traits::SetUpFunctionState(this, extra_param); |
1209 } | 1205 } |
1210 | 1206 |
1211 | 1207 |
1212 template<class Traits> | 1208 template<class Traits> |
1213 ParserBase<Traits>::FunctionState::~FunctionState() { | 1209 ParserBase<Traits>::FunctionState::~FunctionState() { |
1214 *scope_stack_ = outer_scope_; | 1210 *scope_stack_ = outer_scope_; |
1215 *function_state_stack_ = outer_function_state_; | 1211 *function_state_stack_ = outer_function_state_; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 int pos = peek_position(); | 1317 int pos = peek_position(); |
1322 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1318 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
1323 Next(); | 1319 Next(); |
1324 ReportMessage("unterminated_regexp"); | 1320 ReportMessage("unterminated_regexp"); |
1325 *ok = false; | 1321 *ok = false; |
1326 return Traits::EmptyExpression(); | 1322 return Traits::EmptyExpression(); |
1327 } | 1323 } |
1328 | 1324 |
1329 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1325 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1330 | 1326 |
1331 IdentifierT js_pattern = this->GetNextSymbol(scanner()); | 1327 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); |
1332 if (!scanner()->ScanRegExpFlags()) { | 1328 if (!scanner()->ScanRegExpFlags()) { |
1333 Next(); | 1329 Next(); |
1334 ReportMessage("invalid_regexp_flags"); | 1330 ReportMessage("invalid_regexp_flags"); |
1335 *ok = false; | 1331 *ok = false; |
1336 return Traits::EmptyExpression(); | 1332 return Traits::EmptyExpression(); |
1337 } | 1333 } |
1338 IdentifierT js_flags = this->GetNextSymbol(scanner()); | 1334 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); |
1339 Next(); | 1335 Next(); |
1340 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); | 1336 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); |
1341 } | 1337 } |
1342 | 1338 |
1343 | 1339 |
1344 #define CHECK_OK ok); \ | 1340 #define CHECK_OK ok); \ |
1345 if (!*ok) return this->EmptyExpression(); \ | 1341 if (!*ok) return this->EmptyExpression(); \ |
1346 ((void)0 | 1342 ((void)0 |
1347 #define DUMMY ) // to make indentation work | 1343 #define DUMMY ) // to make indentation work |
1348 #undef DUMMY | 1344 #undef DUMMY |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 } | 1569 } |
1574 | 1570 |
1575 if (fni_ != NULL) { | 1571 if (fni_ != NULL) { |
1576 fni_->Infer(); | 1572 fni_->Infer(); |
1577 fni_->Leave(); | 1573 fni_->Leave(); |
1578 } | 1574 } |
1579 continue; // restart the while | 1575 continue; // restart the while |
1580 } | 1576 } |
1581 // Failed to parse as get/set property, so it's just a normal property | 1577 // Failed to parse as get/set property, so it's just a normal property |
1582 // (which might be called "get" or "set" or something else). | 1578 // (which might be called "get" or "set" or something else). |
1583 key = factory()->NewStringLiteral(id, next_pos); | 1579 key = factory()->NewLiteral(id, next_pos); |
1584 break; | 1580 break; |
1585 } | 1581 } |
1586 case Token::STRING: { | 1582 case Token::STRING: { |
1587 Consume(Token::STRING); | 1583 Consume(Token::STRING); |
1588 IdentifierT string = this->GetSymbol(scanner_); | 1584 IdentifierT string = this->GetSymbol(scanner_); |
1589 if (fni_ != NULL) this->PushLiteralName(fni_, string); | 1585 if (fni_ != NULL) this->PushLiteralName(fni_, string); |
1590 uint32_t index; | 1586 uint32_t index; |
1591 if (this->IsArrayIndex(string, &index)) { | 1587 if (this->IsArrayIndex(string, &index)) { |
1592 key = factory()->NewNumberLiteral(index, next_pos); | 1588 key = factory()->NewNumberLiteral(index, next_pos); |
1593 break; | 1589 break; |
1594 } | 1590 } |
1595 key = factory()->NewStringLiteral(string, next_pos); | 1591 key = factory()->NewLiteral(string, next_pos); |
1596 break; | 1592 break; |
1597 } | 1593 } |
1598 case Token::NUMBER: { | 1594 case Token::NUMBER: { |
1599 Consume(Token::NUMBER); | 1595 Consume(Token::NUMBER); |
1600 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, | 1596 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, |
1601 factory()); | 1597 factory()); |
1602 break; | 1598 break; |
1603 } | 1599 } |
1604 default: | 1600 default: |
1605 if (Token::IsKeyword(next)) { | 1601 if (Token::IsKeyword(next)) { |
1606 Consume(next); | 1602 Consume(next); |
1607 IdentifierT string = this->GetSymbol(scanner_); | 1603 IdentifierT string = this->GetSymbol(scanner_); |
1608 key = factory()->NewStringLiteral(string, next_pos); | 1604 key = factory()->NewLiteral(string, next_pos); |
1609 } else { | 1605 } else { |
1610 Token::Value next = Next(); | 1606 Token::Value next = Next(); |
1611 ReportUnexpectedToken(next); | 1607 ReportUnexpectedToken(next); |
1612 *ok = false; | 1608 *ok = false; |
1613 return this->EmptyLiteral(); | 1609 return this->EmptyLiteral(); |
1614 } | 1610 } |
1615 } | 1611 } |
1616 | 1612 |
1617 // Validate the property | 1613 // Validate the property |
1618 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1614 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 result = factory()->NewCall(result, args, pos); | 1963 result = factory()->NewCall(result, args, pos); |
1968 if (fni_ != NULL) fni_->RemoveLastFunction(); | 1964 if (fni_ != NULL) fni_->RemoveLastFunction(); |
1969 break; | 1965 break; |
1970 } | 1966 } |
1971 | 1967 |
1972 case Token::PERIOD: { | 1968 case Token::PERIOD: { |
1973 Consume(Token::PERIOD); | 1969 Consume(Token::PERIOD); |
1974 int pos = position(); | 1970 int pos = position(); |
1975 IdentifierT name = ParseIdentifierName(CHECK_OK); | 1971 IdentifierT name = ParseIdentifierName(CHECK_OK); |
1976 result = factory()->NewProperty( | 1972 result = factory()->NewProperty( |
1977 result, factory()->NewStringLiteral(name, pos), pos); | 1973 result, factory()->NewLiteral(name, pos), pos); |
1978 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 1974 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
1979 break; | 1975 break; |
1980 } | 1976 } |
1981 | 1977 |
1982 default: | 1978 default: |
1983 return result; | 1979 return result; |
1984 } | 1980 } |
1985 } | 1981 } |
1986 } | 1982 } |
1987 | 1983 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 this->PushPropertyName(fni_, index); | 2086 this->PushPropertyName(fni_, index); |
2091 } | 2087 } |
2092 Expect(Token::RBRACK, CHECK_OK); | 2088 Expect(Token::RBRACK, CHECK_OK); |
2093 break; | 2089 break; |
2094 } | 2090 } |
2095 case Token::PERIOD: { | 2091 case Token::PERIOD: { |
2096 Consume(Token::PERIOD); | 2092 Consume(Token::PERIOD); |
2097 int pos = position(); | 2093 int pos = position(); |
2098 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2094 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2099 expression = factory()->NewProperty( | 2095 expression = factory()->NewProperty( |
2100 expression, factory()->NewStringLiteral(name, pos), pos); | 2096 expression, factory()->NewLiteral(name, pos), pos); |
2101 if (fni_ != NULL) { | 2097 if (fni_ != NULL) { |
2102 this->PushLiteralName(fni_, name); | 2098 this->PushLiteralName(fni_, name); |
2103 } | 2099 } |
2104 break; | 2100 break; |
2105 } | 2101 } |
2106 default: | 2102 default: |
2107 return expression; | 2103 return expression; |
2108 } | 2104 } |
2109 } | 2105 } |
2110 ASSERT(false); | 2106 ASSERT(false); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 parser()->ReportMessage("accessor_get_set"); | 2164 parser()->ReportMessage("accessor_get_set"); |
2169 } | 2165 } |
2170 *ok = false; | 2166 *ok = false; |
2171 } | 2167 } |
2172 } | 2168 } |
2173 | 2169 |
2174 | 2170 |
2175 } } // v8::internal | 2171 } } // v8::internal |
2176 | 2172 |
2177 #endif // V8_PREPARSER_H | 2173 #endif // V8_PREPARSER_H |
OLD | NEW |