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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 #define CHECK_OK_CUSTOM(x) ok); \ | 129 #define CHECK_OK_CUSTOM(x) ok); \ |
130 if (!*ok) return this->x(); \ | 130 if (!*ok) return this->x(); \ |
131 ((void)0 | 131 ((void)0 |
132 #define DUMMY ) // to make indentation work | 132 #define DUMMY ) // to make indentation work |
133 #undef DUMMY | 133 #undef DUMMY |
134 | 134 |
135 // Used in functions where the return type is ExpressionT. | 135 // Used in functions where the return type is ExpressionT. |
136 #define CHECK_OK CHECK_OK_CUSTOM(EmptyExpression) | 136 #define CHECK_OK CHECK_OK_CUSTOM(EmptyExpression) |
137 | 137 |
138 | 138 |
139 // Common base class shared between parser and pre-parser. Traits encapsulate | 139 // Common base class template shared between parser and pre-parser. |
140 // the differences between Parser and PreParser: | 140 // The Impl parameter is the actual class of the parser/pre-parser, |
141 // following the Curiously Recurring Template Pattern (CRTP). | |
142 | |
143 // The traits class template encapsulates the differences between | |
144 // parser/pre-parser implementations. In particular: | |
141 | 145 |
142 // - Return types: For example, Parser functions return Expression* and | 146 // - Return types: For example, Parser functions return Expression* and |
143 // PreParser functions return PreParserExpression. | 147 // PreParser functions return PreParserExpression. |
144 | 148 |
145 // - Creating parse tree nodes: Parser generates an AST during the recursive | 149 // - Creating parse tree nodes: Parser generates an AST during the recursive |
146 // descent. PreParser doesn't create a tree. Instead, it passes around minimal | 150 // descent. PreParser doesn't create a tree. Instead, it passes around minimal |
147 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 151 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
148 // just enough data for the upper layer functions. PreParserFactory is | 152 // just enough data for the upper layer functions. PreParserFactory is |
149 // responsible for creating these dummy objects. It provides a similar kind of | 153 // responsible for creating these dummy objects. It provides a similar kind of |
150 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is | 154 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is |
151 // used. | 155 // used. |
152 | 156 |
153 // - Miscellaneous other tasks interleaved with the recursive descent. For | 157 // - Miscellaneous other tasks interleaved with the recursive descent. For |
154 // example, Parser keeps track of which function literals should be marked as | 158 // example, Parser keeps track of which function literals should be marked as |
155 // pretenured, and PreParser doesn't care. | 159 // pretenured, and PreParser doesn't care. |
156 | 160 |
marja
2016/08/23 09:09:39
Could you add the "outline" how the classes inheri
nickie
2016/08/23 12:10:12
Done.
| |
157 // The traits are expected to contain the following typedefs: | 161 // The traits are expected to contain the following typedefs: |
158 // struct Traits { | 162 // template <> |
163 // class ParserBaseTraits<Impl> { | |
159 // // In particular... | 164 // // In particular... |
160 // struct Type { | 165 // struct Type { |
161 // // Used by FunctionState and BlockState. | |
162 // typedef Scope; | |
163 // typedef GeneratorVariable; | 166 // typedef GeneratorVariable; |
167 // typedef AstProperties; | |
168 // typedef ExpressionClassifier; | |
164 // // Return types for traversing functions. | 169 // // Return types for traversing functions. |
165 // typedef Identifier; | 170 // typedef Identifier; |
166 // typedef Expression; | 171 // typedef Expression; |
172 // typedef YieldExpression; | |
167 // typedef FunctionLiteral; | 173 // typedef FunctionLiteral; |
168 // typedef ClassLiteral; | 174 // typedef ClassLiteral; |
175 // typedef Literal; | |
169 // typedef ObjectLiteralProperty; | 176 // typedef ObjectLiteralProperty; |
170 // typedef Literal; | |
171 // typedef ExpressionList; | 177 // typedef ExpressionList; |
172 // typedef PropertyList; | 178 // typedef PropertyList; |
173 // typedef FormalParameter; | 179 // typedef FormalParameter; |
174 // typedef FormalParameters; | 180 // typedef FormalParameters; |
181 // typedef StatementList; | |
175 // // For constructing objects returned by the traversing functions. | 182 // // For constructing objects returned by the traversing functions. |
176 // typedef Factory; | 183 // typedef Factory; |
177 // }; | 184 // }; |
178 // // ... | 185 // // ... |
179 // }; | 186 // }; |
180 | 187 |
181 template <typename Traits> | 188 template <typename Impl> |
182 class ParserBase : public Traits { | 189 class ParserBaseTraits; |
190 | |
191 template <typename Impl> | |
192 class ParserBase : public ParserBaseTraits<Impl> { | |
183 public: | 193 public: |
184 // Shorten type names defined by Traits. | 194 // Shorten type names defined by Traits. |
195 typedef ParserBaseTraits<Impl> Traits; | |
185 typedef typename Traits::Type::Expression ExpressionT; | 196 typedef typename Traits::Type::Expression ExpressionT; |
186 typedef typename Traits::Type::Identifier IdentifierT; | 197 typedef typename Traits::Type::Identifier IdentifierT; |
187 typedef typename Traits::Type::FormalParameter FormalParameterT; | 198 typedef typename Traits::Type::FormalParameter FormalParameterT; |
188 typedef typename Traits::Type::FormalParameters FormalParametersT; | 199 typedef typename Traits::Type::FormalParameters FormalParametersT; |
189 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 200 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
190 typedef typename Traits::Type::Literal LiteralT; | 201 typedef typename Traits::Type::Literal LiteralT; |
191 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 202 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
192 typedef typename Traits::Type::StatementList StatementListT; | 203 typedef typename Traits::Type::StatementList StatementListT; |
193 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; | 204 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; |
194 | 205 |
206 // All implementation-specific methods must be called through this. | |
207 Impl* impl() { return static_cast<Impl*>(this); } | |
208 const Impl* impl() const { return static_cast<const Impl*>(this); } | |
209 | |
195 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 210 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
196 v8::Extension* extension, AstValueFactory* ast_value_factory, | 211 v8::Extension* extension, AstValueFactory* ast_value_factory, |
197 ParserRecorder* log, typename Traits::Type::Parser this_object) | 212 ParserRecorder* log) |
198 : Traits(this_object), | 213 : scope_state_(nullptr), |
199 scope_state_(nullptr), | |
200 function_state_(nullptr), | 214 function_state_(nullptr), |
201 extension_(extension), | 215 extension_(extension), |
202 fni_(nullptr), | 216 fni_(nullptr), |
203 ast_value_factory_(ast_value_factory), | 217 ast_value_factory_(ast_value_factory), |
204 ast_node_factory_(ast_value_factory), | 218 ast_node_factory_(ast_value_factory), |
205 log_(log), | 219 log_(log), |
206 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 220 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
207 parsing_module_(false), | 221 parsing_module_(false), |
208 stack_limit_(stack_limit), | 222 stack_limit_(stack_limit), |
209 zone_(zone), | 223 zone_(zone), |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 ZoneList<typename ExpressionClassifier::Error> reported_errors_; | 522 ZoneList<typename ExpressionClassifier::Error> reported_errors_; |
509 | 523 |
510 // If true, the next (and immediately following) function literal is | 524 // If true, the next (and immediately following) function literal is |
511 // preceded by a parenthesis. | 525 // preceded by a parenthesis. |
512 bool next_function_is_parenthesized_; | 526 bool next_function_is_parenthesized_; |
513 | 527 |
514 // The value of the parents' next_function_is_parenthesized_, as it applies | 528 // The value of the parents' next_function_is_parenthesized_, as it applies |
515 // to this function. Filled in by constructor. | 529 // to this function. Filled in by constructor. |
516 bool this_function_is_parenthesized_; | 530 bool this_function_is_parenthesized_; |
517 | 531 |
518 friend class ParserTraits; | 532 friend class ParserBaseTraits<Impl>; |
519 friend class PreParserTraits; | |
520 friend class Checkpoint; | 533 friend class Checkpoint; |
521 }; | 534 }; |
522 | 535 |
523 // This scope sets current ReturnExprContext to given value. | 536 // This scope sets current ReturnExprContext to given value. |
524 class ReturnExprScope { | 537 class ReturnExprScope { |
525 public: | 538 public: |
526 explicit ReturnExprScope(FunctionState* function_state, | 539 explicit ReturnExprScope(FunctionState* function_state, |
527 ReturnExprContext return_expr_context) | 540 ReturnExprContext return_expr_context) |
528 : function_state_(function_state), | 541 : function_state_(function_state), |
529 sav_return_expr_context_(function_state->return_expr_context()) { | 542 sav_return_expr_context_(function_state->return_expr_context()) { |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 bool allow_harmony_do_expressions_; | 1290 bool allow_harmony_do_expressions_; |
1278 bool allow_harmony_for_in_; | 1291 bool allow_harmony_for_in_; |
1279 bool allow_harmony_function_sent_; | 1292 bool allow_harmony_function_sent_; |
1280 bool allow_harmony_async_await_; | 1293 bool allow_harmony_async_await_; |
1281 bool allow_harmony_restrictive_generators_; | 1294 bool allow_harmony_restrictive_generators_; |
1282 bool allow_harmony_trailing_commas_; | 1295 bool allow_harmony_trailing_commas_; |
1283 | 1296 |
1284 friend class DiscardableZoneScope; | 1297 friend class DiscardableZoneScope; |
1285 }; | 1298 }; |
1286 | 1299 |
1287 template <class Traits> | 1300 template <typename Impl> |
1288 ParserBase<Traits>::FunctionState::FunctionState( | 1301 ParserBase<Impl>::FunctionState::FunctionState( |
1289 FunctionState** function_state_stack, ScopeState** scope_stack, | 1302 FunctionState** function_state_stack, ScopeState** scope_stack, |
1290 Scope* scope, FunctionKind kind) | 1303 Scope* scope, FunctionKind kind) |
1291 : ScopeState(scope_stack, scope), | 1304 : ScopeState(scope_stack, scope), |
1292 next_materialized_literal_index_(0), | 1305 next_materialized_literal_index_(0), |
1293 expected_property_count_(0), | 1306 expected_property_count_(0), |
1294 kind_(kind), | 1307 kind_(kind), |
1295 generator_object_variable_(NULL), | 1308 generator_object_variable_(NULL), |
1296 function_state_stack_(function_state_stack), | 1309 function_state_stack_(function_state_stack), |
1297 outer_function_state_(*function_state_stack), | 1310 outer_function_state_(*function_state_stack), |
1298 destructuring_assignments_to_rewrite_(16, scope->zone()), | 1311 destructuring_assignments_to_rewrite_(16, scope->zone()), |
1299 tail_call_expressions_(scope->zone()), | 1312 tail_call_expressions_(scope->zone()), |
1300 return_expr_context_(ReturnExprContext::kInsideValidBlock), | 1313 return_expr_context_(ReturnExprContext::kInsideValidBlock), |
1301 non_patterns_to_rewrite_(0, scope->zone()), | 1314 non_patterns_to_rewrite_(0, scope->zone()), |
1302 reported_errors_(16, scope->zone()), | 1315 reported_errors_(16, scope->zone()), |
1303 next_function_is_parenthesized_(false), | 1316 next_function_is_parenthesized_(false), |
1304 this_function_is_parenthesized_(false) { | 1317 this_function_is_parenthesized_(false) { |
1305 *function_state_stack = this; | 1318 *function_state_stack = this; |
1306 if (outer_function_state_) { | 1319 if (outer_function_state_) { |
1307 this_function_is_parenthesized_ = | 1320 this_function_is_parenthesized_ = |
1308 outer_function_state_->next_function_is_parenthesized_; | 1321 outer_function_state_->next_function_is_parenthesized_; |
1309 outer_function_state_->next_function_is_parenthesized_ = false; | 1322 outer_function_state_->next_function_is_parenthesized_ = false; |
1310 } | 1323 } |
1311 } | 1324 } |
1312 | 1325 |
1313 | 1326 |
1314 template <class Traits> | 1327 template <typename Impl> |
1315 ParserBase<Traits>::FunctionState::~FunctionState() { | 1328 ParserBase<Impl>::FunctionState::~FunctionState() { |
1316 *function_state_stack_ = outer_function_state_; | 1329 *function_state_stack_ = outer_function_state_; |
1317 } | 1330 } |
1318 | 1331 |
1319 template <class Traits> | 1332 template <typename Impl> |
1320 void ParserBase<Traits>::GetUnexpectedTokenMessage( | 1333 void ParserBase<Impl>::GetUnexpectedTokenMessage( |
1321 Token::Value token, MessageTemplate::Template* message, | 1334 Token::Value token, MessageTemplate::Template* message, |
1322 Scanner::Location* location, const char** arg, | 1335 Scanner::Location* location, const char** arg, |
1323 MessageTemplate::Template default_) { | 1336 MessageTemplate::Template default_) { |
1324 *arg = nullptr; | 1337 *arg = nullptr; |
1325 switch (token) { | 1338 switch (token) { |
1326 case Token::EOS: | 1339 case Token::EOS: |
1327 *message = MessageTemplate::kUnexpectedEOS; | 1340 *message = MessageTemplate::kUnexpectedEOS; |
1328 break; | 1341 break; |
1329 case Token::SMI: | 1342 case Token::SMI: |
1330 case Token::NUMBER: | 1343 case Token::NUMBER: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1369 break; | 1382 break; |
1370 default: | 1383 default: |
1371 const char* name = Token::String(token); | 1384 const char* name = Token::String(token); |
1372 DCHECK(name != NULL); | 1385 DCHECK(name != NULL); |
1373 *arg = name; | 1386 *arg = name; |
1374 break; | 1387 break; |
1375 } | 1388 } |
1376 } | 1389 } |
1377 | 1390 |
1378 | 1391 |
1379 template <class Traits> | 1392 template <typename Impl> |
1380 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1393 void ParserBase<Impl>::ReportUnexpectedToken(Token::Value token) { |
1381 return ReportUnexpectedTokenAt(scanner_->location(), token); | 1394 return ReportUnexpectedTokenAt(scanner_->location(), token); |
1382 } | 1395 } |
1383 | 1396 |
1384 | 1397 |
1385 template <class Traits> | 1398 template <typename Impl> |
1386 void ParserBase<Traits>::ReportUnexpectedTokenAt( | 1399 void ParserBase<Impl>::ReportUnexpectedTokenAt( |
1387 Scanner::Location source_location, Token::Value token, | 1400 Scanner::Location source_location, Token::Value token, |
1388 MessageTemplate::Template message) { | 1401 MessageTemplate::Template message) { |
1389 const char* arg; | 1402 const char* arg; |
1390 GetUnexpectedTokenMessage(token, &message, &source_location, &arg); | 1403 GetUnexpectedTokenMessage(token, &message, &source_location, &arg); |
1391 Traits::ReportMessageAt(source_location, message, arg); | 1404 Traits::ReportMessageAt(source_location, message, arg); |
1392 } | 1405 } |
1393 | 1406 |
1394 | 1407 |
1395 template <class Traits> | 1408 template <typename Impl> |
1396 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1409 typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifier( |
1397 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1410 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
1398 ExpressionClassifier classifier(this); | 1411 ExpressionClassifier classifier(this); |
1399 auto result = | 1412 auto result = |
1400 ParseAndClassifyIdentifier(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); | 1413 ParseAndClassifyIdentifier(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); |
1401 | 1414 |
1402 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { | 1415 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { |
1403 ValidateAssignmentPattern(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); | 1416 ValidateAssignmentPattern(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); |
1404 ValidateBindingPattern(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); | 1417 ValidateBindingPattern(&classifier, CHECK_OK_CUSTOM(EmptyIdentifier)); |
1405 } | 1418 } |
1406 | 1419 |
1407 return result; | 1420 return result; |
1408 } | 1421 } |
1409 | 1422 |
1410 | 1423 |
1411 template <class Traits> | 1424 template <typename Impl> |
1412 typename ParserBase<Traits>::IdentifierT | 1425 typename ParserBase<Impl>::IdentifierT |
1413 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 1426 ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
1414 bool* ok) { | 1427 bool* ok) { |
1415 Token::Value next = Next(); | 1428 Token::Value next = Next(); |
1416 if (next == Token::IDENTIFIER || next == Token::ASYNC || | 1429 if (next == Token::IDENTIFIER || next == Token::ASYNC || |
1417 (next == Token::AWAIT && !parsing_module_)) { | 1430 (next == Token::AWAIT && !parsing_module_)) { |
1418 IdentifierT name = this->GetSymbol(scanner()); | 1431 IdentifierT name = this->GetSymbol(scanner()); |
1419 // When this function is used to read a formal parameter, we don't always | 1432 // When this function is used to read a formal parameter, we don't always |
1420 // know whether the function is going to be strict or sloppy. Indeed for | 1433 // know whether the function is going to be strict or sloppy. Indeed for |
1421 // arrow functions we don't always know that the identifier we are reading | 1434 // arrow functions we don't always know that the identifier we are reading |
1422 // is actually a formal parameter. Therefore besides the errors that we | 1435 // is actually a formal parameter. Therefore besides the errors that we |
1423 // must detect because we know we're in strict mode, we also record any | 1436 // must detect because we know we're in strict mode, we also record any |
1424 // error that we might make in the future once we know the language mode. | 1437 // error that we might make in the future once we know the language mode. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 } | 1486 } |
1474 return this->GetSymbol(scanner()); | 1487 return this->GetSymbol(scanner()); |
1475 } else { | 1488 } else { |
1476 this->ReportUnexpectedToken(next); | 1489 this->ReportUnexpectedToken(next); |
1477 *ok = false; | 1490 *ok = false; |
1478 return Traits::EmptyIdentifier(); | 1491 return Traits::EmptyIdentifier(); |
1479 } | 1492 } |
1480 } | 1493 } |
1481 | 1494 |
1482 | 1495 |
1483 template <class Traits> | 1496 template <typename Impl> |
1484 typename ParserBase<Traits>::IdentifierT | 1497 typename ParserBase<Impl>::IdentifierT |
1485 ParserBase<Traits>::ParseIdentifierOrStrictReservedWord( | 1498 ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(bool is_generator, |
1486 bool is_generator, bool* is_strict_reserved, bool* ok) { | 1499 bool* is_strict_reserved, |
1500 bool* ok) { | |
1487 Token::Value next = Next(); | 1501 Token::Value next = Next(); |
1488 if (next == Token::IDENTIFIER || (next == Token::AWAIT && !parsing_module_) || | 1502 if (next == Token::IDENTIFIER || (next == Token::AWAIT && !parsing_module_) || |
1489 next == Token::ASYNC) { | 1503 next == Token::ASYNC) { |
1490 *is_strict_reserved = false; | 1504 *is_strict_reserved = false; |
1491 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 1505 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || |
1492 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { | 1506 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { |
1493 *is_strict_reserved = true; | 1507 *is_strict_reserved = true; |
1494 } else { | 1508 } else { |
1495 ReportUnexpectedToken(next); | 1509 ReportUnexpectedToken(next); |
1496 *ok = false; | 1510 *ok = false; |
1497 return Traits::EmptyIdentifier(); | 1511 return Traits::EmptyIdentifier(); |
1498 } | 1512 } |
1499 | 1513 |
1500 return this->GetSymbol(scanner()); | 1514 return this->GetSymbol(scanner()); |
1501 } | 1515 } |
1502 | 1516 |
1503 template <class Traits> | 1517 template <typename Impl> |
1504 typename ParserBase<Traits>::IdentifierT | 1518 typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName( |
1505 ParserBase<Traits>::ParseIdentifierName(bool* ok) { | 1519 bool* ok) { |
1506 Token::Value next = Next(); | 1520 Token::Value next = Next(); |
1507 if (next != Token::IDENTIFIER && next != Token::ASYNC && | 1521 if (next != Token::IDENTIFIER && next != Token::ASYNC && |
1508 next != Token::ENUM && next != Token::AWAIT && next != Token::LET && | 1522 next != Token::ENUM && next != Token::AWAIT && next != Token::LET && |
1509 next != Token::STATIC && next != Token::YIELD && | 1523 next != Token::STATIC && next != Token::YIELD && |
1510 next != Token::FUTURE_STRICT_RESERVED_WORD && | 1524 next != Token::FUTURE_STRICT_RESERVED_WORD && |
1511 next != Token::ESCAPED_KEYWORD && | 1525 next != Token::ESCAPED_KEYWORD && |
1512 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { | 1526 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { |
1513 this->ReportUnexpectedToken(next); | 1527 this->ReportUnexpectedToken(next); |
1514 *ok = false; | 1528 *ok = false; |
1515 return Traits::EmptyIdentifier(); | 1529 return Traits::EmptyIdentifier(); |
1516 } | 1530 } |
1517 | 1531 |
1518 return this->GetSymbol(scanner()); | 1532 return this->GetSymbol(scanner()); |
1519 } | 1533 } |
1520 | 1534 |
1521 template <class Traits> | 1535 template <typename Impl> |
1522 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( | 1536 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( |
1523 bool* ok) { | 1537 bool* ok) { |
1524 int pos = peek_position(); | 1538 int pos = peek_position(); |
1525 if (!scanner()->ScanRegExpPattern()) { | 1539 if (!scanner()->ScanRegExpPattern()) { |
1526 Next(); | 1540 Next(); |
1527 ReportMessage(MessageTemplate::kUnterminatedRegExp); | 1541 ReportMessage(MessageTemplate::kUnterminatedRegExp); |
1528 *ok = false; | 1542 *ok = false; |
1529 return Traits::EmptyExpression(); | 1543 return Traits::EmptyExpression(); |
1530 } | 1544 } |
1531 | 1545 |
1532 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1546 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1533 | 1547 |
1534 IdentifierT js_pattern = this->GetNextSymbol(scanner()); | 1548 IdentifierT js_pattern = this->GetNextSymbol(scanner()); |
1535 Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags(); | 1549 Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags(); |
1536 if (flags.IsNothing()) { | 1550 if (flags.IsNothing()) { |
1537 Next(); | 1551 Next(); |
1538 ReportMessage(MessageTemplate::kMalformedRegExpFlags); | 1552 ReportMessage(MessageTemplate::kMalformedRegExpFlags); |
1539 *ok = false; | 1553 *ok = false; |
1540 return Traits::EmptyExpression(); | 1554 return Traits::EmptyExpression(); |
1541 } | 1555 } |
1542 int js_flags = flags.FromJust(); | 1556 int js_flags = flags.FromJust(); |
1543 Next(); | 1557 Next(); |
1544 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); | 1558 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); |
1545 } | 1559 } |
1546 | 1560 |
1547 | 1561 |
1548 template <class Traits> | 1562 template <typename Impl> |
1549 typename ParserBase<Traits>::ExpressionT | 1563 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( |
1550 ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, | 1564 ExpressionClassifier* classifier, bool* is_async, bool* ok) { |
1551 bool* is_async, bool* ok) { | |
1552 // PrimaryExpression :: | 1565 // PrimaryExpression :: |
1553 // 'this' | 1566 // 'this' |
1554 // 'null' | 1567 // 'null' |
1555 // 'true' | 1568 // 'true' |
1556 // 'false' | 1569 // 'false' |
1557 // Identifier | 1570 // Identifier |
1558 // Number | 1571 // Number |
1559 // String | 1572 // String |
1560 // ArrayLiteral | 1573 // ArrayLiteral |
1561 // ObjectLiteral | 1574 // ObjectLiteral |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1719 default: | 1732 default: |
1720 break; | 1733 break; |
1721 } | 1734 } |
1722 | 1735 |
1723 ReportUnexpectedToken(Next()); | 1736 ReportUnexpectedToken(Next()); |
1724 *ok = false; | 1737 *ok = false; |
1725 return this->EmptyExpression(); | 1738 return this->EmptyExpression(); |
1726 } | 1739 } |
1727 | 1740 |
1728 | 1741 |
1729 template <class Traits> | 1742 template <typename Impl> |
1730 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1743 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression( |
1731 bool accept_IN, bool* ok) { | 1744 bool accept_IN, bool* ok) { |
1732 ExpressionClassifier classifier(this); | 1745 ExpressionClassifier classifier(this); |
1733 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1746 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
1734 Traits::RewriteNonPattern(&classifier, CHECK_OK); | 1747 Traits::RewriteNonPattern(&classifier, CHECK_OK); |
1735 return result; | 1748 return result; |
1736 } | 1749 } |
1737 | 1750 |
1738 template <class Traits> | 1751 template <typename Impl> |
1739 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1752 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression( |
1740 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1753 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
1741 // Expression :: | 1754 // Expression :: |
1742 // AssignmentExpression | 1755 // AssignmentExpression |
1743 // Expression ',' AssignmentExpression | 1756 // Expression ',' AssignmentExpression |
1744 | 1757 |
1745 ExpressionT result; | 1758 ExpressionT result; |
1746 { | 1759 { |
1747 ExpressionClassifier binding_classifier(this); | 1760 ExpressionClassifier binding_classifier(this); |
1748 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, | 1761 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, |
1749 CHECK_OK); | 1762 CHECK_OK); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1794 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); | 1807 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
1795 } | 1808 } |
1796 if (!is_simple_parameter_list || seen_rest) { | 1809 if (!is_simple_parameter_list || seen_rest) { |
1797 classifier->RecordNonSimpleParameter(); | 1810 classifier->RecordNonSimpleParameter(); |
1798 } | 1811 } |
1799 | 1812 |
1800 return result; | 1813 return result; |
1801 } | 1814 } |
1802 | 1815 |
1803 | 1816 |
1804 template <class Traits> | 1817 template <typename Impl> |
1805 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( | 1818 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral( |
1806 ExpressionClassifier* classifier, bool* ok) { | 1819 ExpressionClassifier* classifier, bool* ok) { |
1807 // ArrayLiteral :: | 1820 // ArrayLiteral :: |
1808 // '[' Expression? (',' Expression?)* ']' | 1821 // '[' Expression? (',' Expression?)* ']' |
1809 | 1822 |
1810 int pos = peek_position(); | 1823 int pos = peek_position(); |
1811 typename Traits::Type::ExpressionList values = | 1824 typename Traits::Type::ExpressionList values = |
1812 this->NewExpressionList(4, zone_); | 1825 this->NewExpressionList(4, zone_); |
1813 int first_spread_index = -1; | 1826 int first_spread_index = -1; |
1814 Expect(Token::LBRACK, CHECK_OK); | 1827 Expect(Token::LBRACK, CHECK_OK); |
1815 while (peek() != Token::RBRACK) { | 1828 while (peek() != Token::RBRACK) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1870 // rewriting other things than spreads, this error message will have | 1883 // rewriting other things than spreads, this error message will have |
1871 // to change. Also, this error message will never appear while pre- | 1884 // to change. Also, this error message will never appear while pre- |
1872 // parsing (this is OK, as it is an implementation limitation). | 1885 // parsing (this is OK, as it is an implementation limitation). |
1873 ReportMessage(MessageTemplate::kTooManySpreads); | 1886 ReportMessage(MessageTemplate::kTooManySpreads); |
1874 return this->EmptyExpression(); | 1887 return this->EmptyExpression(); |
1875 } | 1888 } |
1876 } | 1889 } |
1877 return result; | 1890 return result; |
1878 } | 1891 } |
1879 | 1892 |
1880 template <class Traits> | 1893 template <typename Impl> |
1881 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( | 1894 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName( |
1882 IdentifierT* name, bool* is_get, bool* is_set, bool* is_await, | 1895 IdentifierT* name, bool* is_get, bool* is_set, bool* is_await, |
1883 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { | 1896 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { |
1884 Token::Value token = peek(); | 1897 Token::Value token = peek(); |
1885 int pos = peek_position(); | 1898 int pos = peek_position(); |
1886 | 1899 |
1887 // For non computed property names we normalize the name a bit: | 1900 // For non computed property names we normalize the name a bit: |
1888 // | 1901 // |
1889 // "12" -> 12 | 1902 // "12" -> 12 |
1890 // 12.3 -> "12.3" | 1903 // 12.3 -> "12.3" |
1891 // 12.30 -> "12.3" | 1904 // 12.30 -> "12.3" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1930 } | 1943 } |
1931 break; | 1944 break; |
1932 } | 1945 } |
1933 | 1946 |
1934 uint32_t index; | 1947 uint32_t index; |
1935 return this->IsArrayIndex(*name, &index) | 1948 return this->IsArrayIndex(*name, &index) |
1936 ? factory()->NewNumberLiteral(index, pos) | 1949 ? factory()->NewNumberLiteral(index, pos) |
1937 : factory()->NewStringLiteral(*name, pos); | 1950 : factory()->NewStringLiteral(*name, pos); |
1938 } | 1951 } |
1939 | 1952 |
1940 template <class Traits> | 1953 template <typename Impl> |
1941 typename ParserBase<Traits>::ObjectLiteralPropertyT | 1954 typename ParserBase<Impl>::ObjectLiteralPropertyT |
1942 ParserBase<Traits>::ParsePropertyDefinition( | 1955 ParserBase<Impl>::ParsePropertyDefinition( |
1943 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1956 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
1944 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, | 1957 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, |
1945 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { | 1958 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { |
1946 DCHECK(!in_class || IsStaticMethod(method_kind) || | 1959 DCHECK(!in_class || IsStaticMethod(method_kind) || |
1947 has_seen_constructor != nullptr); | 1960 has_seen_constructor != nullptr); |
1948 bool is_get = false; | 1961 bool is_get = false; |
1949 bool is_set = false; | 1962 bool is_set = false; |
1950 bool is_await = false; | 1963 bool is_await = false; |
1951 bool is_generator = Check(Token::MUL); | 1964 bool is_generator = Check(Token::MUL); |
1952 bool is_async = false; | 1965 bool is_async = false; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2155 is_static, *is_computed_name); | 2168 is_static, *is_computed_name); |
2156 } | 2169 } |
2157 | 2170 |
2158 Token::Value next = Next(); | 2171 Token::Value next = Next(); |
2159 ReportUnexpectedToken(next); | 2172 ReportUnexpectedToken(next); |
2160 *ok = false; | 2173 *ok = false; |
2161 return this->EmptyObjectLiteralProperty(); | 2174 return this->EmptyObjectLiteralProperty(); |
2162 } | 2175 } |
2163 | 2176 |
2164 | 2177 |
2165 template <class Traits> | 2178 template <typename Impl> |
2166 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 2179 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( |
2167 ExpressionClassifier* classifier, bool* ok) { | 2180 ExpressionClassifier* classifier, bool* ok) { |
2168 // ObjectLiteral :: | 2181 // ObjectLiteral :: |
2169 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2182 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
2170 | 2183 |
2171 int pos = peek_position(); | 2184 int pos = peek_position(); |
2172 typename Traits::Type::PropertyList properties = | 2185 typename Traits::Type::PropertyList properties = |
2173 this->NewPropertyList(4, zone_); | 2186 this->NewPropertyList(4, zone_); |
2174 int number_of_boilerplate_properties = 0; | 2187 int number_of_boilerplate_properties = 0; |
2175 bool has_computed_names = false; | 2188 bool has_computed_names = false; |
2176 ObjectLiteralChecker checker(this); | 2189 ObjectLiteralChecker checker(this); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2211 | 2224 |
2212 // Computation of literal_index must happen before pre parse bailout. | 2225 // Computation of literal_index must happen before pre parse bailout. |
2213 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2226 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
2214 | 2227 |
2215 return factory()->NewObjectLiteral(properties, | 2228 return factory()->NewObjectLiteral(properties, |
2216 literal_index, | 2229 literal_index, |
2217 number_of_boilerplate_properties, | 2230 number_of_boilerplate_properties, |
2218 pos); | 2231 pos); |
2219 } | 2232 } |
2220 | 2233 |
2221 template <class Traits> | 2234 template <typename Impl> |
2222 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2235 typename ParserBase<Impl>::Traits::Type::ExpressionList |
2223 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, | 2236 ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc, |
2224 ExpressionClassifier* classifier, bool* ok) { | 2237 bool maybe_arrow, |
2238 ExpressionClassifier* classifier, bool* ok) { | |
2225 // Arguments :: | 2239 // Arguments :: |
2226 // '(' (AssignmentExpression)*[','] ')' | 2240 // '(' (AssignmentExpression)*[','] ')' |
2227 | 2241 |
2228 Scanner::Location spread_arg = Scanner::Location::invalid(); | 2242 Scanner::Location spread_arg = Scanner::Location::invalid(); |
2229 typename Traits::Type::ExpressionList result = | 2243 typename Traits::Type::ExpressionList result = |
2230 this->NewExpressionList(4, zone_); | 2244 this->NewExpressionList(4, zone_); |
2231 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2245 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
2232 bool done = (peek() == Token::RPAREN); | 2246 bool done = (peek() == Token::RPAREN); |
2233 bool was_unspread = false; | 2247 bool was_unspread = false; |
2234 int unspread_sequences_count = 0; | 2248 int unspread_sequences_count = 0; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2294 // parser. Ensure that the number of materialized literals matches between | 2308 // parser. Ensure that the number of materialized literals matches between |
2295 // the parser and preparser | 2309 // the parser and preparser |
2296 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); | 2310 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
2297 } | 2311 } |
2298 } | 2312 } |
2299 | 2313 |
2300 return result; | 2314 return result; |
2301 } | 2315 } |
2302 | 2316 |
2303 // Precedence = 2 | 2317 // Precedence = 2 |
2304 template <class Traits> | 2318 template <typename Impl> |
2305 typename ParserBase<Traits>::ExpressionT | 2319 typename ParserBase<Impl>::ExpressionT |
2306 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, | 2320 ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, |
2307 ExpressionClassifier* classifier, | 2321 ExpressionClassifier* classifier, |
2308 bool* ok) { | 2322 bool* ok) { |
2309 // AssignmentExpression :: | 2323 // AssignmentExpression :: |
2310 // ConditionalExpression | 2324 // ConditionalExpression |
2311 // ArrowFunction | 2325 // ArrowFunction |
2312 // YieldExpression | 2326 // YieldExpression |
2313 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2327 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2314 bool is_destructuring_assignment = false; | 2328 bool is_destructuring_assignment = false; |
2315 int lhs_beg_pos = peek_position(); | 2329 int lhs_beg_pos = peek_position(); |
2316 | 2330 |
2317 if (peek() == Token::YIELD && is_generator()) { | 2331 if (peek() == Token::YIELD && is_generator()) { |
2318 return this->ParseYieldExpression(accept_IN, classifier, ok); | 2332 return this->ParseYieldExpression(accept_IN, classifier, ok); |
2319 } | 2333 } |
2320 | 2334 |
2321 FuncNameInferrer::State fni_state(fni_); | 2335 FuncNameInferrer::State fni_state(fni_); |
2322 ParserBase<Traits>::Checkpoint checkpoint(this); | 2336 Checkpoint checkpoint(this); |
2323 ExpressionClassifier arrow_formals_classifier(this, | 2337 ExpressionClassifier arrow_formals_classifier(this, |
2324 classifier->duplicate_finder()); | 2338 classifier->duplicate_finder()); |
2325 | 2339 |
2326 Scope::Snapshot scope_snapshot(scope()); | 2340 Scope::Snapshot scope_snapshot(scope()); |
2327 | 2341 |
2328 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && | 2342 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && |
2329 !scanner()->HasAnyLineTerminatorAfterNext() && | 2343 !scanner()->HasAnyLineTerminatorAfterNext() && |
2330 IsValidArrowFormalParametersStart(PeekAhead()); | 2344 IsValidArrowFormalParametersStart(PeekAhead()); |
2331 | 2345 |
2332 bool parenthesized_formals = peek() == Token::LPAREN; | 2346 bool parenthesized_formals = peek() == Token::LPAREN; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2501 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2515 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
2502 | 2516 |
2503 if (is_destructuring_assignment) { | 2517 if (is_destructuring_assignment) { |
2504 result = factory()->NewRewritableExpression(result); | 2518 result = factory()->NewRewritableExpression(result); |
2505 Traits::QueueDestructuringAssignmentForRewriting(result); | 2519 Traits::QueueDestructuringAssignmentForRewriting(result); |
2506 } | 2520 } |
2507 | 2521 |
2508 return result; | 2522 return result; |
2509 } | 2523 } |
2510 | 2524 |
2511 template <class Traits> | 2525 template <typename Impl> |
2512 typename ParserBase<Traits>::ExpressionT | 2526 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression( |
2513 ParserBase<Traits>::ParseYieldExpression(bool accept_IN, | 2527 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
2514 ExpressionClassifier* classifier, | |
2515 bool* ok) { | |
2516 // YieldExpression :: | 2528 // YieldExpression :: |
2517 // 'yield' ([no line terminator] '*'? AssignmentExpression)? | 2529 // 'yield' ([no line terminator] '*'? AssignmentExpression)? |
2518 int pos = peek_position(); | 2530 int pos = peek_position(); |
2519 classifier->RecordPatternError(scanner()->peek_location(), | 2531 classifier->RecordPatternError(scanner()->peek_location(), |
2520 MessageTemplate::kInvalidDestructuringTarget); | 2532 MessageTemplate::kInvalidDestructuringTarget); |
2521 classifier->RecordFormalParameterInitializerError( | 2533 classifier->RecordFormalParameterInitializerError( |
2522 scanner()->peek_location(), MessageTemplate::kYieldInParameter); | 2534 scanner()->peek_location(), MessageTemplate::kYieldInParameter); |
2523 Expect(Token::YIELD, CHECK_OK); | 2535 Expect(Token::YIELD, CHECK_OK); |
2524 ExpressionT generator_object = | 2536 ExpressionT generator_object = |
2525 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 2537 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
(...skipping 28 matching lines...) Expand all Loading... | |
2554 } | 2566 } |
2555 | 2567 |
2556 expression = Traits::BuildIteratorResult(expression, false); | 2568 expression = Traits::BuildIteratorResult(expression, false); |
2557 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2569 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
2558 // TODO(verwaest): Come up with a better solution. | 2570 // TODO(verwaest): Come up with a better solution. |
2559 typename Traits::Type::YieldExpression yield = factory()->NewYield( | 2571 typename Traits::Type::YieldExpression yield = factory()->NewYield( |
2560 generator_object, expression, pos, Yield::kOnExceptionThrow); | 2572 generator_object, expression, pos, Yield::kOnExceptionThrow); |
2561 return yield; | 2573 return yield; |
2562 } | 2574 } |
2563 | 2575 |
2564 template <class Traits> | 2576 template <typename Impl> |
2565 typename ParserBase<Traits>::ExpressionT | 2577 typename ParserBase<Impl>::ExpressionT |
2566 ParserBase<Traits>::ParseTailCallExpression(ExpressionClassifier* classifier, | 2578 ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier, |
2567 bool* ok) { | 2579 bool* ok) { |
2568 // TailCallExpression:: | 2580 // TailCallExpression:: |
2569 // 'continue' MemberExpression Arguments | 2581 // 'continue' MemberExpression Arguments |
2570 // 'continue' CallExpression Arguments | 2582 // 'continue' CallExpression Arguments |
2571 // 'continue' MemberExpression TemplateLiteral | 2583 // 'continue' MemberExpression TemplateLiteral |
2572 // 'continue' CallExpression TemplateLiteral | 2584 // 'continue' CallExpression TemplateLiteral |
2573 Expect(Token::CONTINUE, CHECK_OK); | 2585 Expect(Token::CONTINUE, CHECK_OK); |
2574 int pos = position(); | 2586 int pos = position(); |
2575 int sub_expression_pos = peek_position(); | 2587 int sub_expression_pos = peek_position(); |
2576 ExpressionT expression = | 2588 ExpressionT expression = |
2577 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2589 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2617 *ok = false; | 2629 *ok = false; |
2618 return Traits::EmptyExpression(); | 2630 return Traits::EmptyExpression(); |
2619 } | 2631 } |
2620 classifier->RecordTailCallExpressionError( | 2632 classifier->RecordTailCallExpressionError( |
2621 loc, MessageTemplate::kUnexpectedTailCall); | 2633 loc, MessageTemplate::kUnexpectedTailCall); |
2622 function_state_->AddExplicitTailCallExpression(expression, loc); | 2634 function_state_->AddExplicitTailCallExpression(expression, loc); |
2623 return expression; | 2635 return expression; |
2624 } | 2636 } |
2625 | 2637 |
2626 // Precedence = 3 | 2638 // Precedence = 3 |
2627 template <class Traits> | 2639 template <typename Impl> |
2628 typename ParserBase<Traits>::ExpressionT | 2640 typename ParserBase<Impl>::ExpressionT |
2629 ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, | 2641 ParserBase<Impl>::ParseConditionalExpression(bool accept_IN, |
2630 ExpressionClassifier* classifier, | 2642 ExpressionClassifier* classifier, |
2631 bool* ok) { | 2643 bool* ok) { |
2632 // ConditionalExpression :: | 2644 // ConditionalExpression :: |
2633 // LogicalOrExpression | 2645 // LogicalOrExpression |
2634 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2646 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2635 | 2647 |
2636 int pos = peek_position(); | 2648 int pos = peek_position(); |
2637 // We start using the binary expression parser for prec >= 4 only! | 2649 // We start using the binary expression parser for prec >= 4 only! |
2638 ExpressionT expression = | 2650 ExpressionT expression = |
2639 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2651 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
2640 if (peek() != Token::CONDITIONAL) return expression; | 2652 if (peek() != Token::CONDITIONAL) return expression; |
2641 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2653 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2642 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2654 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2643 BindingPatternUnexpectedToken(classifier); | 2655 BindingPatternUnexpectedToken(classifier); |
2644 ArrowFormalParametersUnexpectedToken(classifier); | 2656 ArrowFormalParametersUnexpectedToken(classifier); |
2645 Consume(Token::CONDITIONAL); | 2657 Consume(Token::CONDITIONAL); |
2646 // In parsing the first assignment expression in conditional | 2658 // In parsing the first assignment expression in conditional |
2647 // expressions we always accept the 'in' keyword; see ECMA-262, | 2659 // expressions we always accept the 'in' keyword; see ECMA-262, |
2648 // section 11.12, page 58. | 2660 // section 11.12, page 58. |
2649 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2661 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
2650 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2662 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2651 Expect(Token::COLON, CHECK_OK); | 2663 Expect(Token::COLON, CHECK_OK); |
2652 ExpressionT right = | 2664 ExpressionT right = |
2653 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2665 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2654 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2666 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2655 return factory()->NewConditional(expression, left, right, pos); | 2667 return factory()->NewConditional(expression, left, right, pos); |
2656 } | 2668 } |
2657 | 2669 |
2658 | 2670 |
2659 // Precedence >= 4 | 2671 // Precedence >= 4 |
2660 template <class Traits> | 2672 template <typename Impl> |
2661 typename ParserBase<Traits>::ExpressionT | 2673 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression( |
2662 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2674 int prec, bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
2663 ExpressionClassifier* classifier, | |
2664 bool* ok) { | |
2665 DCHECK(prec >= 4); | 2675 DCHECK(prec >= 4); |
2666 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2676 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2667 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2677 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2668 // prec1 >= 4 | 2678 // prec1 >= 4 |
2669 while (Precedence(peek(), accept_IN) == prec1) { | 2679 while (Precedence(peek(), accept_IN) == prec1) { |
2670 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2680 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2671 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2681 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2672 BindingPatternUnexpectedToken(classifier); | 2682 BindingPatternUnexpectedToken(classifier); |
2673 ArrowFormalParametersUnexpectedToken(classifier); | 2683 ArrowFormalParametersUnexpectedToken(classifier); |
2674 Token::Value op = Next(); | 2684 Token::Value op = Next(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2709 } else { | 2719 } else { |
2710 // We have a "normal" binary operation. | 2720 // We have a "normal" binary operation. |
2711 x = factory()->NewBinaryOperation(op, x, y, pos); | 2721 x = factory()->NewBinaryOperation(op, x, y, pos); |
2712 } | 2722 } |
2713 } | 2723 } |
2714 } | 2724 } |
2715 return x; | 2725 return x; |
2716 } | 2726 } |
2717 | 2727 |
2718 | 2728 |
2719 template <class Traits> | 2729 template <typename Impl> |
2720 typename ParserBase<Traits>::ExpressionT | 2730 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression( |
2721 ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier, | 2731 ExpressionClassifier* classifier, bool* ok) { |
2722 bool* ok) { | |
2723 // UnaryExpression :: | 2732 // UnaryExpression :: |
2724 // PostfixExpression | 2733 // PostfixExpression |
2725 // 'delete' UnaryExpression | 2734 // 'delete' UnaryExpression |
2726 // 'void' UnaryExpression | 2735 // 'void' UnaryExpression |
2727 // 'typeof' UnaryExpression | 2736 // 'typeof' UnaryExpression |
2728 // '++' UnaryExpression | 2737 // '++' UnaryExpression |
2729 // '--' UnaryExpression | 2738 // '--' UnaryExpression |
2730 // '+' UnaryExpression | 2739 // '+' UnaryExpression |
2731 // '-' UnaryExpression | 2740 // '-' UnaryExpression |
2732 // '~' UnaryExpression | 2741 // '~' UnaryExpression |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2814 classifier->RecordFormalParameterInitializerError( | 2823 classifier->RecordFormalParameterInitializerError( |
2815 Scanner::Location(beg_pos, scanner()->location().end_pos), | 2824 Scanner::Location(beg_pos, scanner()->location().end_pos), |
2816 MessageTemplate::kAwaitExpressionFormalParameter); | 2825 MessageTemplate::kAwaitExpressionFormalParameter); |
2817 return Traits::RewriteAwaitExpression(value, await_pos); | 2826 return Traits::RewriteAwaitExpression(value, await_pos); |
2818 } else { | 2827 } else { |
2819 return this->ParsePostfixExpression(classifier, ok); | 2828 return this->ParsePostfixExpression(classifier, ok); |
2820 } | 2829 } |
2821 } | 2830 } |
2822 | 2831 |
2823 | 2832 |
2824 template <class Traits> | 2833 template <typename Impl> |
2825 typename ParserBase<Traits>::ExpressionT | 2834 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression( |
2826 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, | 2835 ExpressionClassifier* classifier, bool* ok) { |
2827 bool* ok) { | |
2828 // PostfixExpression :: | 2836 // PostfixExpression :: |
2829 // LeftHandSideExpression ('++' | '--')? | 2837 // LeftHandSideExpression ('++' | '--')? |
2830 | 2838 |
2831 int lhs_beg_pos = peek_position(); | 2839 int lhs_beg_pos = peek_position(); |
2832 ExpressionT expression = | 2840 ExpressionT expression = |
2833 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2841 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
2834 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 2842 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
2835 Token::IsCountOp(peek())) { | 2843 Token::IsCountOp(peek())) { |
2836 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2844 CheckNoTailCallExpressions(classifier, CHECK_OK); |
2837 BindingPatternUnexpectedToken(classifier); | 2845 BindingPatternUnexpectedToken(classifier); |
2838 ArrowFormalParametersUnexpectedToken(classifier); | 2846 ArrowFormalParametersUnexpectedToken(classifier); |
2839 | 2847 |
2840 expression = this->CheckAndRewriteReferenceExpression( | 2848 expression = this->CheckAndRewriteReferenceExpression( |
2841 expression, lhs_beg_pos, scanner()->location().end_pos, | 2849 expression, lhs_beg_pos, scanner()->location().end_pos, |
2842 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 2850 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
2843 expression = this->MarkExpressionAsAssigned(expression); | 2851 expression = this->MarkExpressionAsAssigned(expression); |
2844 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2852 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2845 | 2853 |
2846 Token::Value next = Next(); | 2854 Token::Value next = Next(); |
2847 expression = | 2855 expression = |
2848 factory()->NewCountOperation(next, | 2856 factory()->NewCountOperation(next, |
2849 false /* postfix */, | 2857 false /* postfix */, |
2850 expression, | 2858 expression, |
2851 position()); | 2859 position()); |
2852 } | 2860 } |
2853 return expression; | 2861 return expression; |
2854 } | 2862 } |
2855 | 2863 |
2856 template <class Traits> | 2864 template <typename Impl> |
2857 typename ParserBase<Traits>::ExpressionT | 2865 typename ParserBase<Impl>::ExpressionT |
2858 ParserBase<Traits>::ParseLeftHandSideExpression( | 2866 ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
2859 ExpressionClassifier* classifier, bool* ok) { | 2867 bool* ok) { |
2860 // LeftHandSideExpression :: | 2868 // LeftHandSideExpression :: |
2861 // (NewExpression | MemberExpression) ... | 2869 // (NewExpression | MemberExpression) ... |
2862 | 2870 |
2863 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { | 2871 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { |
2864 return this->ParseTailCallExpression(classifier, ok); | 2872 return this->ParseTailCallExpression(classifier, ok); |
2865 } | 2873 } |
2866 | 2874 |
2867 bool is_async = false; | 2875 bool is_async = false; |
2868 ExpressionT result = this->ParseMemberWithNewPrefixesExpression( | 2876 ExpressionT result = this->ParseMemberWithNewPrefixesExpression( |
2869 classifier, &is_async, CHECK_OK); | 2877 classifier, &is_async, CHECK_OK); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2994 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); | 3002 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); |
2995 break; | 3003 break; |
2996 } | 3004 } |
2997 | 3005 |
2998 default: | 3006 default: |
2999 return result; | 3007 return result; |
3000 } | 3008 } |
3001 } | 3009 } |
3002 } | 3010 } |
3003 | 3011 |
3004 template <class Traits> | 3012 template <typename Impl> |
3005 typename ParserBase<Traits>::ExpressionT | 3013 typename ParserBase<Impl>::ExpressionT |
3006 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( | 3014 ParserBase<Impl>::ParseMemberWithNewPrefixesExpression( |
3007 ExpressionClassifier* classifier, bool* is_async, bool* ok) { | 3015 ExpressionClassifier* classifier, bool* is_async, bool* ok) { |
3008 // NewExpression :: | 3016 // NewExpression :: |
3009 // ('new')+ MemberExpression | 3017 // ('new')+ MemberExpression |
3010 // | 3018 // |
3011 // NewTarget :: | 3019 // NewTarget :: |
3012 // 'new' '.' 'target' | 3020 // 'new' '.' 'target' |
3013 | 3021 |
3014 // The grammar for new expressions is pretty warped. We can have several 'new' | 3022 // The grammar for new expressions is pretty warped. We can have several 'new' |
3015 // keywords following each other, and then a MemberExpression. When we see '(' | 3023 // keywords following each other, and then a MemberExpression. When we see '(' |
3016 // after the MemberExpression, it's associated with the rightmost unassociated | 3024 // after the MemberExpression, it's associated with the rightmost unassociated |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3059 return result; | 3067 return result; |
3060 } | 3068 } |
3061 // NewExpression without arguments. | 3069 // NewExpression without arguments. |
3062 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 3070 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
3063 new_pos); | 3071 new_pos); |
3064 } | 3072 } |
3065 // No 'new' or 'super' keyword. | 3073 // No 'new' or 'super' keyword. |
3066 return this->ParseMemberExpression(classifier, is_async, ok); | 3074 return this->ParseMemberExpression(classifier, is_async, ok); |
3067 } | 3075 } |
3068 | 3076 |
3069 template <class Traits> | 3077 template <typename Impl> |
3070 typename ParserBase<Traits>::ExpressionT | 3078 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( |
3071 ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, | 3079 ExpressionClassifier* classifier, bool* is_async, bool* ok) { |
3072 bool* is_async, bool* ok) { | |
3073 // MemberExpression :: | 3080 // MemberExpression :: |
3074 // (PrimaryExpression | FunctionLiteral | ClassLiteral) | 3081 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
3075 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* | 3082 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
3076 | 3083 |
3077 // The '[' Expression ']' and '.' Identifier parts are parsed by | 3084 // The '[' Expression ']' and '.' Identifier parts are parsed by |
3078 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 3085 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
3079 // caller. | 3086 // caller. |
3080 | 3087 |
3081 // Parse the initial primary or function expression. | 3088 // Parse the initial primary or function expression. |
3082 ExpressionT result; | 3089 ExpressionT result; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3127 result = ParseSuperExpression(is_new, CHECK_OK); | 3134 result = ParseSuperExpression(is_new, CHECK_OK); |
3128 } else { | 3135 } else { |
3129 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); | 3136 result = ParsePrimaryExpression(classifier, is_async, CHECK_OK); |
3130 } | 3137 } |
3131 | 3138 |
3132 result = | 3139 result = |
3133 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); | 3140 ParseMemberExpressionContinuation(result, is_async, classifier, CHECK_OK); |
3134 return result; | 3141 return result; |
3135 } | 3142 } |
3136 | 3143 |
3137 template <class Traits> | 3144 template <typename Impl> |
3138 typename ParserBase<Traits>::ExpressionT | 3145 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( |
3139 ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) { | 3146 bool is_new, bool* ok) { |
3140 Expect(Token::SUPER, CHECK_OK); | 3147 Expect(Token::SUPER, CHECK_OK); |
3141 int pos = position(); | 3148 int pos = position(); |
3142 | 3149 |
3143 DeclarationScope* scope = GetReceiverScope(); | 3150 DeclarationScope* scope = GetReceiverScope(); |
3144 FunctionKind kind = scope->function_kind(); | 3151 FunctionKind kind = scope->function_kind(); |
3145 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3152 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3146 IsClassConstructor(kind)) { | 3153 IsClassConstructor(kind)) { |
3147 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3154 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
3148 scope->RecordSuperPropertyUsage(); | 3155 scope->RecordSuperPropertyUsage(); |
3149 return this->NewSuperPropertyReference(factory(), pos); | 3156 return this->NewSuperPropertyReference(factory(), pos); |
3150 } | 3157 } |
3151 // new super() is never allowed. | 3158 // new super() is never allowed. |
3152 // super() is only allowed in derived constructor | 3159 // super() is only allowed in derived constructor |
3153 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3160 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
3154 // TODO(rossberg): This might not be the correct FunctionState for the | 3161 // TODO(rossberg): This might not be the correct FunctionState for the |
3155 // method here. | 3162 // method here. |
3156 return this->NewSuperCallReference(factory(), pos); | 3163 return this->NewSuperCallReference(factory(), pos); |
3157 } | 3164 } |
3158 } | 3165 } |
3159 | 3166 |
3160 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); | 3167 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); |
3161 *ok = false; | 3168 *ok = false; |
3162 return this->EmptyExpression(); | 3169 return this->EmptyExpression(); |
3163 } | 3170 } |
3164 | 3171 |
3165 template <class Traits> | 3172 template <typename Impl> |
3166 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name, | 3173 void ParserBase<Impl>::ExpectMetaProperty(Vector<const char> property_name, |
3167 const char* full_name, int pos, | 3174 const char* full_name, int pos, |
3168 bool* ok) { | 3175 bool* ok) { |
3169 Consume(Token::PERIOD); | 3176 Consume(Token::PERIOD); |
3170 ExpectContextualKeyword(property_name, CHECK_OK_CUSTOM(Void)); | 3177 ExpectContextualKeyword(property_name, CHECK_OK_CUSTOM(Void)); |
3171 if (scanner()->literal_contains_escapes()) { | 3178 if (scanner()->literal_contains_escapes()) { |
3172 Traits::ReportMessageAt( | 3179 Traits::ReportMessageAt( |
3173 Scanner::Location(pos, scanner()->location().end_pos), | 3180 Scanner::Location(pos, scanner()->location().end_pos), |
3174 MessageTemplate::kInvalidEscapedMetaProperty, full_name); | 3181 MessageTemplate::kInvalidEscapedMetaProperty, full_name); |
3175 *ok = false; | 3182 *ok = false; |
3176 } | 3183 } |
3177 } | 3184 } |
3178 | 3185 |
3179 template <class Traits> | 3186 template <typename Impl> |
3180 typename ParserBase<Traits>::ExpressionT | 3187 typename ParserBase<Impl>::ExpressionT |
3181 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { | 3188 ParserBase<Impl>::ParseNewTargetExpression(bool* ok) { |
3182 int pos = position(); | 3189 int pos = position(); |
3183 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); | 3190 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); |
3184 | 3191 |
3185 if (!GetReceiverScope()->is_function_scope()) { | 3192 if (!GetReceiverScope()->is_function_scope()) { |
3186 ReportMessageAt(scanner()->location(), | 3193 ReportMessageAt(scanner()->location(), |
3187 MessageTemplate::kUnexpectedNewTarget); | 3194 MessageTemplate::kUnexpectedNewTarget); |
3188 *ok = false; | 3195 *ok = false; |
3189 return this->EmptyExpression(); | 3196 return this->EmptyExpression(); |
3190 } | 3197 } |
3191 | 3198 |
3192 return this->NewTargetExpression(pos); | 3199 return this->NewTargetExpression(pos); |
3193 } | 3200 } |
3194 | 3201 |
3195 template <class Traits> | 3202 template <typename Impl> |
3196 typename ParserBase<Traits>::ExpressionT | 3203 typename ParserBase<Impl>::ExpressionT |
3197 ParserBase<Traits>::ParseMemberExpressionContinuation( | 3204 ParserBase<Impl>::ParseMemberExpressionContinuation( |
3198 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, | 3205 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
3199 bool* ok) { | 3206 bool* ok) { |
3200 // Parses this part of MemberExpression: | 3207 // Parses this part of MemberExpression: |
3201 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 3208 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
3202 while (true) { | 3209 while (true) { |
3203 switch (peek()) { | 3210 switch (peek()) { |
3204 case Token::LBRACK: { | 3211 case Token::LBRACK: { |
3205 *is_async = false; | 3212 *is_async = false; |
3206 Traits::RewriteNonPattern(classifier, CHECK_OK); | 3213 Traits::RewriteNonPattern(classifier, CHECK_OK); |
3207 BindingPatternUnexpectedToken(classifier); | 3214 BindingPatternUnexpectedToken(classifier); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3262 } | 3269 } |
3263 default: | 3270 default: |
3264 return expression; | 3271 return expression; |
3265 } | 3272 } |
3266 } | 3273 } |
3267 DCHECK(false); | 3274 DCHECK(false); |
3268 return this->EmptyExpression(); | 3275 return this->EmptyExpression(); |
3269 } | 3276 } |
3270 | 3277 |
3271 | 3278 |
3272 template <class Traits> | 3279 template <typename Impl> |
3273 void ParserBase<Traits>::ParseFormalParameter( | 3280 void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters, |
3274 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3281 ExpressionClassifier* classifier, |
3282 bool* ok) { | |
3275 // FormalParameter[Yield,GeneratorParameter] : | 3283 // FormalParameter[Yield,GeneratorParameter] : |
3276 // BindingElement[?Yield, ?GeneratorParameter] | 3284 // BindingElement[?Yield, ?GeneratorParameter] |
3277 bool is_rest = parameters->has_rest; | 3285 bool is_rest = parameters->has_rest; |
3278 | 3286 |
3279 ExpressionT pattern = | 3287 ExpressionT pattern = |
3280 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void)); | 3288 ParsePrimaryExpression(classifier, CHECK_OK_CUSTOM(Void)); |
3281 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void)); | 3289 ValidateBindingPattern(classifier, CHECK_OK_CUSTOM(Void)); |
3282 | 3290 |
3283 if (!Traits::IsIdentifier(pattern)) { | 3291 if (!Traits::IsIdentifier(pattern)) { |
3284 parameters->is_simple = false; | 3292 parameters->is_simple = false; |
(...skipping 13 matching lines...) Expand all Loading... | |
3298 classifier->RecordNonSimpleParameter(); | 3306 classifier->RecordNonSimpleParameter(); |
3299 | 3307 |
3300 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); | 3308 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); |
3301 } | 3309 } |
3302 | 3310 |
3303 Traits::AddFormalParameter(parameters, pattern, initializer, | 3311 Traits::AddFormalParameter(parameters, pattern, initializer, |
3304 scanner()->location().end_pos, is_rest); | 3312 scanner()->location().end_pos, is_rest); |
3305 } | 3313 } |
3306 | 3314 |
3307 | 3315 |
3308 template <class Traits> | 3316 template <typename Impl> |
3309 void ParserBase<Traits>::ParseFormalParameterList( | 3317 void ParserBase<Impl>::ParseFormalParameterList( |
3310 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3318 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { |
3311 // FormalParameters[Yield] : | 3319 // FormalParameters[Yield] : |
3312 // [empty] | 3320 // [empty] |
3313 // FunctionRestParameter[?Yield] | 3321 // FunctionRestParameter[?Yield] |
3314 // FormalParameterList[?Yield] | 3322 // FormalParameterList[?Yield] |
3315 // FormalParameterList[?Yield] , | 3323 // FormalParameterList[?Yield] , |
3316 // FormalParameterList[?Yield] , FunctionRestParameter[?Yield] | 3324 // FormalParameterList[?Yield] , FunctionRestParameter[?Yield] |
3317 // | 3325 // |
3318 // FormalParameterList[Yield] : | 3326 // FormalParameterList[Yield] : |
3319 // FormalParameter[?Yield] | 3327 // FormalParameter[?Yield] |
(...skipping 29 matching lines...) Expand all Loading... | |
3349 } | 3357 } |
3350 } | 3358 } |
3351 } | 3359 } |
3352 | 3360 |
3353 for (int i = 0; i < parameters->Arity(); ++i) { | 3361 for (int i = 0; i < parameters->Arity(); ++i) { |
3354 auto parameter = parameters->at(i); | 3362 auto parameter = parameters->at(i); |
3355 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); | 3363 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); |
3356 } | 3364 } |
3357 } | 3365 } |
3358 | 3366 |
3359 template <class Traits> | 3367 template <typename Impl> |
3360 void ParserBase<Traits>::CheckArityRestrictions(int param_count, | 3368 void ParserBase<Impl>::CheckArityRestrictions(int param_count, |
3361 FunctionKind function_kind, | 3369 FunctionKind function_kind, |
3362 bool has_rest, | 3370 bool has_rest, |
3363 int formals_start_pos, | 3371 int formals_start_pos, |
3364 int formals_end_pos, bool* ok) { | 3372 int formals_end_pos, bool* ok) { |
3365 if (IsGetterFunction(function_kind)) { | 3373 if (IsGetterFunction(function_kind)) { |
3366 if (param_count != 0) { | 3374 if (param_count != 0) { |
3367 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 3375 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
3368 MessageTemplate::kBadGetterArity); | 3376 MessageTemplate::kBadGetterArity); |
3369 *ok = false; | 3377 *ok = false; |
3370 } | 3378 } |
3371 } else if (IsSetterFunction(function_kind)) { | 3379 } else if (IsSetterFunction(function_kind)) { |
3372 if (param_count != 1) { | 3380 if (param_count != 1) { |
3373 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 3381 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
3374 MessageTemplate::kBadSetterArity); | 3382 MessageTemplate::kBadSetterArity); |
3375 *ok = false; | 3383 *ok = false; |
3376 } | 3384 } |
3377 if (has_rest) { | 3385 if (has_rest) { |
3378 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), | 3386 ReportMessageAt(Scanner::Location(formals_start_pos, formals_end_pos), |
3379 MessageTemplate::kBadSetterRestParameter); | 3387 MessageTemplate::kBadSetterRestParameter); |
3380 *ok = false; | 3388 *ok = false; |
3381 } | 3389 } |
3382 } | 3390 } |
3383 } | 3391 } |
3384 | 3392 |
3385 | 3393 |
3386 template <class Traits> | 3394 template <typename Impl> |
3387 bool ParserBase<Traits>::IsNextLetKeyword() { | 3395 bool ParserBase<Impl>::IsNextLetKeyword() { |
3388 DCHECK(peek() == Token::LET); | 3396 DCHECK(peek() == Token::LET); |
3389 Token::Value next_next = PeekAhead(); | 3397 Token::Value next_next = PeekAhead(); |
3390 switch (next_next) { | 3398 switch (next_next) { |
3391 case Token::LBRACE: | 3399 case Token::LBRACE: |
3392 case Token::LBRACK: | 3400 case Token::LBRACK: |
3393 case Token::IDENTIFIER: | 3401 case Token::IDENTIFIER: |
3394 case Token::STATIC: | 3402 case Token::STATIC: |
3395 case Token::LET: // `let let;` is disallowed by static semantics, but the | 3403 case Token::LET: // `let let;` is disallowed by static semantics, but the |
3396 // token must be first interpreted as a keyword in order | 3404 // token must be first interpreted as a keyword in order |
3397 // for those semantics to apply. This ensures that ASI is | 3405 // for those semantics to apply. This ensures that ASI is |
3398 // not honored when a LineTerminator separates the | 3406 // not honored when a LineTerminator separates the |
3399 // tokens. | 3407 // tokens. |
3400 case Token::YIELD: | 3408 case Token::YIELD: |
3401 case Token::AWAIT: | 3409 case Token::AWAIT: |
3402 case Token::ASYNC: | 3410 case Token::ASYNC: |
3403 return true; | 3411 return true; |
3404 case Token::FUTURE_STRICT_RESERVED_WORD: | 3412 case Token::FUTURE_STRICT_RESERVED_WORD: |
3405 return is_sloppy(language_mode()); | 3413 return is_sloppy(language_mode()); |
3406 default: | 3414 default: |
3407 return false; | 3415 return false; |
3408 } | 3416 } |
3409 } | 3417 } |
3410 | 3418 |
3411 template <class Traits> | 3419 template <typename Impl> |
3412 bool ParserBase<Traits>::IsTrivialExpression() { | 3420 bool ParserBase<Impl>::IsTrivialExpression() { |
3413 Token::Value peek_token = peek(); | 3421 Token::Value peek_token = peek(); |
3414 if (peek_token == Token::SMI || peek_token == Token::NUMBER || | 3422 if (peek_token == Token::SMI || peek_token == Token::NUMBER || |
3415 peek_token == Token::NULL_LITERAL || peek_token == Token::TRUE_LITERAL || | 3423 peek_token == Token::NULL_LITERAL || peek_token == Token::TRUE_LITERAL || |
3416 peek_token == Token::FALSE_LITERAL || peek_token == Token::STRING || | 3424 peek_token == Token::FALSE_LITERAL || peek_token == Token::STRING || |
3417 peek_token == Token::IDENTIFIER || peek_token == Token::THIS) { | 3425 peek_token == Token::IDENTIFIER || peek_token == Token::THIS) { |
3418 // PeekAhead() is expensive & may not always be called, so we only call it | 3426 // PeekAhead() is expensive & may not always be called, so we only call it |
3419 // after checking peek(). | 3427 // after checking peek(). |
3420 Token::Value peek_ahead = PeekAhead(); | 3428 Token::Value peek_ahead = PeekAhead(); |
3421 if (peek_ahead == Token::COMMA || peek_ahead == Token::RPAREN || | 3429 if (peek_ahead == Token::COMMA || peek_ahead == Token::RPAREN || |
3422 peek_ahead == Token::SEMICOLON || peek_ahead == Token::RBRACK) { | 3430 peek_ahead == Token::SEMICOLON || peek_ahead == Token::RBRACK) { |
3423 return true; | 3431 return true; |
3424 } | 3432 } |
3425 } | 3433 } |
3426 return false; | 3434 return false; |
3427 } | 3435 } |
3428 | 3436 |
3429 template <class Traits> | 3437 template <typename Impl> |
3430 typename ParserBase<Traits>::ExpressionT | 3438 typename ParserBase<Impl>::ExpressionT |
3431 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3439 ParserBase<Impl>::ParseArrowFunctionLiteral( |
3432 bool accept_IN, const FormalParametersT& formal_parameters, bool is_async, | 3440 bool accept_IN, const FormalParametersT& formal_parameters, bool is_async, |
3433 const ExpressionClassifier& formals_classifier, bool* ok) { | 3441 const ExpressionClassifier& formals_classifier, bool* ok) { |
3434 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3442 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3435 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3443 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3436 // `=> ...` is never a valid expression, so report as syntax error. | 3444 // `=> ...` is never a valid expression, so report as syntax error. |
3437 // If next token is not `=>`, it's a syntax error anyways. | 3445 // If next token is not `=>`, it's a syntax error anyways. |
3438 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3446 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3439 *ok = false; | 3447 *ok = false; |
3440 return this->EmptyExpression(); | 3448 return this->EmptyExpression(); |
3441 } | 3449 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3538 | 3546 |
3539 function_literal->set_function_token_position( | 3547 function_literal->set_function_token_position( |
3540 formal_parameters.scope->start_position()); | 3548 formal_parameters.scope->start_position()); |
3541 | 3549 |
3542 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3550 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
3543 | 3551 |
3544 return function_literal; | 3552 return function_literal; |
3545 } | 3553 } |
3546 | 3554 |
3547 | 3555 |
3548 template <typename Traits> | 3556 template <typename Impl> |
3549 typename ParserBase<Traits>::ExpressionT | 3557 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( |
3550 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, | 3558 ExpressionT tag, int start, ExpressionClassifier* classifier, bool* ok) { |
3551 ExpressionClassifier* classifier, | |
3552 bool* ok) { | |
3553 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal | 3559 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal |
3554 // text followed by a substitution expression), finalized by a single | 3560 // text followed by a substitution expression), finalized by a single |
3555 // TEMPLATE_TAIL. | 3561 // TEMPLATE_TAIL. |
3556 // | 3562 // |
3557 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or | 3563 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or |
3558 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or | 3564 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or |
3559 // NoSubstitutionTemplate. | 3565 // NoSubstitutionTemplate. |
3560 // | 3566 // |
3561 // When parsing a TemplateLiteral, we must have scanned either an initial | 3567 // When parsing a TemplateLiteral, we must have scanned either an initial |
3562 // TEMPLATE_SPAN, or a TEMPLATE_TAIL. | 3568 // TEMPLATE_SPAN, or a TEMPLATE_TAIL. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3635 Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); | 3641 Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); |
3636 } while (next == Token::TEMPLATE_SPAN); | 3642 } while (next == Token::TEMPLATE_SPAN); |
3637 | 3643 |
3638 DCHECK_EQ(next, Token::TEMPLATE_TAIL); | 3644 DCHECK_EQ(next, Token::TEMPLATE_TAIL); |
3639 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | 3645 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); |
3640 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. | 3646 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. |
3641 return Traits::CloseTemplateLiteral(&ts, start, tag); | 3647 return Traits::CloseTemplateLiteral(&ts, start, tag); |
3642 } | 3648 } |
3643 | 3649 |
3644 | 3650 |
3645 template <typename Traits> | 3651 template <typename Impl> |
3646 typename ParserBase<Traits>::ExpressionT | 3652 typename ParserBase<Impl>::ExpressionT |
3647 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 3653 ParserBase<Impl>::CheckAndRewriteReferenceExpression( |
3648 ExpressionT expression, int beg_pos, int end_pos, | 3654 ExpressionT expression, int beg_pos, int end_pos, |
3649 MessageTemplate::Template message, bool* ok) { | 3655 MessageTemplate::Template message, bool* ok) { |
3650 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, | 3656 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, |
3651 message, kReferenceError, ok); | 3657 message, kReferenceError, ok); |
3652 } | 3658 } |
3653 | 3659 |
3654 | 3660 |
3655 template <typename Traits> | 3661 template <typename Impl> |
3656 typename ParserBase<Traits>::ExpressionT | 3662 typename ParserBase<Impl>::ExpressionT |
3657 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 3663 ParserBase<Impl>::CheckAndRewriteReferenceExpression( |
3658 ExpressionT expression, int beg_pos, int end_pos, | 3664 ExpressionT expression, int beg_pos, int end_pos, |
3659 MessageTemplate::Template message, ParseErrorType type, bool* ok) { | 3665 MessageTemplate::Template message, ParseErrorType type, bool* ok) { |
3660 if (this->IsIdentifier(expression) && is_strict(language_mode()) && | 3666 if (this->IsIdentifier(expression) && is_strict(language_mode()) && |
3661 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 3667 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
3662 ReportMessageAt(Scanner::Location(beg_pos, end_pos), | 3668 ReportMessageAt(Scanner::Location(beg_pos, end_pos), |
3663 MessageTemplate::kStrictEvalArguments, kSyntaxError); | 3669 MessageTemplate::kStrictEvalArguments, kSyntaxError); |
3664 *ok = false; | 3670 *ok = false; |
3665 return this->EmptyExpression(); | 3671 return this->EmptyExpression(); |
3666 } | 3672 } |
3667 if (expression->IsValidReferenceExpression()) { | 3673 if (expression->IsValidReferenceExpression()) { |
3668 return expression; | 3674 return expression; |
3669 } | 3675 } |
3670 if (expression->IsCall()) { | 3676 if (expression->IsCall()) { |
3671 // If it is a call, make it a runtime error for legacy web compatibility. | 3677 // If it is a call, make it a runtime error for legacy web compatibility. |
3672 // Rewrite `expr' to `expr[throw ReferenceError]'. | 3678 // Rewrite `expr' to `expr[throw ReferenceError]'. |
3673 ExpressionT error = this->NewThrowReferenceError(message, beg_pos); | 3679 ExpressionT error = this->NewThrowReferenceError(message, beg_pos); |
3674 return factory()->NewProperty(expression, error, beg_pos); | 3680 return factory()->NewProperty(expression, error, beg_pos); |
3675 } | 3681 } |
3676 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); | 3682 ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type); |
3677 *ok = false; | 3683 *ok = false; |
3678 return this->EmptyExpression(); | 3684 return this->EmptyExpression(); |
3679 } | 3685 } |
3680 | 3686 |
3681 | 3687 |
3682 template <typename Traits> | 3688 template <typename Impl> |
3683 bool ParserBase<Traits>::IsValidReferenceExpression(ExpressionT expression) { | 3689 bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) { |
3684 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); | 3690 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); |
3685 } | 3691 } |
3686 | 3692 |
3687 | 3693 |
3688 template <typename Traits> | 3694 template <typename Impl> |
3689 void ParserBase<Traits>::CheckDestructuringElement( | 3695 void ParserBase<Impl>::CheckDestructuringElement( |
3690 ExpressionT expression, ExpressionClassifier* classifier, int begin, | 3696 ExpressionT expression, ExpressionClassifier* classifier, int begin, |
3691 int end) { | 3697 int end) { |
3692 if (!IsValidPattern(expression) && !expression->IsAssignment() && | 3698 if (!IsValidPattern(expression) && !expression->IsAssignment() && |
3693 !IsValidReferenceExpression(expression)) { | 3699 !IsValidReferenceExpression(expression)) { |
3694 classifier->RecordAssignmentPatternError( | 3700 classifier->RecordAssignmentPatternError( |
3695 Scanner::Location(begin, end), | 3701 Scanner::Location(begin, end), |
3696 MessageTemplate::kInvalidDestructuringTarget); | 3702 MessageTemplate::kInvalidDestructuringTarget); |
3697 } | 3703 } |
3698 } | 3704 } |
3699 | 3705 |
3700 | 3706 |
3701 #undef CHECK_OK | 3707 #undef CHECK_OK |
3702 #undef CHECK_OK_CUSTOM | 3708 #undef CHECK_OK_CUSTOM |
3703 | 3709 |
3704 template <typename Traits> | 3710 template <typename Impl> |
3705 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3711 void ParserBase<Impl>::ObjectLiteralChecker::CheckProperty( |
3706 Token::Value property, PropertyKind type, MethodKind method_type, | 3712 Token::Value property, PropertyKind type, MethodKind method_type, |
3707 ExpressionClassifier* classifier, bool* ok) { | 3713 ExpressionClassifier* classifier, bool* ok) { |
3708 DCHECK(!IsStaticMethod(method_type)); | 3714 DCHECK(!IsStaticMethod(method_type)); |
3709 DCHECK(!IsSpecialMethod(method_type) || type == kMethodProperty); | 3715 DCHECK(!IsSpecialMethod(method_type) || type == kMethodProperty); |
3710 | 3716 |
3711 if (property == Token::SMI || property == Token::NUMBER) return; | 3717 if (property == Token::SMI || property == Token::NUMBER) return; |
3712 | 3718 |
3713 if (type == kValueProperty && IsProto()) { | 3719 if (type == kValueProperty && IsProto()) { |
3714 if (has_seen_proto_) { | 3720 if (has_seen_proto_) { |
3715 classifier->RecordObjectLiteralError( | 3721 classifier->RecordObjectLiteralError( |
3716 this->scanner()->location(), MessageTemplate::kDuplicateProto); | 3722 this->scanner()->location(), MessageTemplate::kDuplicateProto); |
3717 return; | 3723 return; |
3718 } | 3724 } |
3719 has_seen_proto_ = true; | 3725 has_seen_proto_ = true; |
3720 } | 3726 } |
3721 } | 3727 } |
3722 | 3728 |
3723 template <typename Traits> | 3729 template <typename Impl> |
3724 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( | 3730 void ParserBase<Impl>::ClassLiteralChecker::CheckProperty( |
3725 Token::Value property, PropertyKind type, MethodKind method_type, | 3731 Token::Value property, PropertyKind type, MethodKind method_type, |
3726 ExpressionClassifier* classifier, bool* ok) { | 3732 ExpressionClassifier* classifier, bool* ok) { |
3727 DCHECK(type == kMethodProperty || type == kAccessorProperty); | 3733 DCHECK(type == kMethodProperty || type == kAccessorProperty); |
3728 | 3734 |
3729 if (property == Token::SMI || property == Token::NUMBER) return; | 3735 if (property == Token::SMI || property == Token::NUMBER) return; |
3730 | 3736 |
3731 if (IsStaticMethod(method_type)) { | 3737 if (IsStaticMethod(method_type)) { |
3732 if (IsPrototype()) { | 3738 if (IsPrototype()) { |
3733 this->parser()->ReportMessage(MessageTemplate::kStaticPrototype); | 3739 this->parser()->ReportMessage(MessageTemplate::kStaticPrototype); |
3734 *ok = false; | 3740 *ok = false; |
(...skipping 19 matching lines...) Expand all Loading... | |
3754 has_seen_constructor_ = true; | 3760 has_seen_constructor_ = true; |
3755 return; | 3761 return; |
3756 } | 3762 } |
3757 } | 3763 } |
3758 | 3764 |
3759 | 3765 |
3760 } // namespace internal | 3766 } // namespace internal |
3761 } // namespace v8 | 3767 } // namespace v8 |
3762 | 3768 |
3763 #endif // V8_PARSING_PARSER_BASE_H | 3769 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |