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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 290 |
291 #define CHECK_FAILED /**/); \ | 291 #define CHECK_FAILED /**/); \ |
292 if (failed_) return nullptr; \ | 292 if (failed_) return nullptr; \ |
293 ((void)0 | 293 ((void)0 |
294 #define DUMMY ) // to make indentation work | 294 #define DUMMY ) // to make indentation work |
295 #undef DUMMY | 295 #undef DUMMY |
296 | 296 |
297 // ---------------------------------------------------------------------------- | 297 // ---------------------------------------------------------------------------- |
298 // Implementation of Parser | 298 // Implementation of Parser |
299 | 299 |
300 bool ParserTraits::IsEval(const AstRawString* identifier) const { | 300 bool ParserBaseTraits<Parser>::IsEval(const AstRawString* identifier) const { |
301 return identifier == parser_->ast_value_factory()->eval_string(); | 301 return identifier == delegate()->ast_value_factory()->eval_string(); |
302 } | 302 } |
303 | 303 |
304 bool ParserTraits::IsArguments(const AstRawString* identifier) const { | 304 bool ParserBaseTraits<Parser>::IsArguments( |
305 return identifier == parser_->ast_value_factory()->arguments_string(); | 305 const AstRawString* identifier) const { |
| 306 return identifier == delegate()->ast_value_factory()->arguments_string(); |
306 } | 307 } |
307 | 308 |
308 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { | 309 bool ParserBaseTraits<Parser>::IsEvalOrArguments( |
| 310 const AstRawString* identifier) const { |
309 return IsEval(identifier) || IsArguments(identifier); | 311 return IsEval(identifier) || IsArguments(identifier); |
310 } | 312 } |
311 | 313 |
312 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { | 314 bool ParserBaseTraits<Parser>::IsUndefined( |
313 return identifier == parser_->ast_value_factory()->undefined_string(); | 315 const AstRawString* identifier) const { |
| 316 return identifier == delegate()->ast_value_factory()->undefined_string(); |
314 } | 317 } |
315 | 318 |
316 bool ParserTraits::IsPrototype(const AstRawString* identifier) const { | 319 bool ParserBaseTraits<Parser>::IsPrototype( |
317 return identifier == parser_->ast_value_factory()->prototype_string(); | 320 const AstRawString* identifier) const { |
| 321 return identifier == delegate()->ast_value_factory()->prototype_string(); |
318 } | 322 } |
319 | 323 |
320 | 324 bool ParserBaseTraits<Parser>::IsConstructor( |
321 bool ParserTraits::IsConstructor(const AstRawString* identifier) const { | 325 const AstRawString* identifier) const { |
322 return identifier == parser_->ast_value_factory()->constructor_string(); | 326 return identifier == delegate()->ast_value_factory()->constructor_string(); |
323 } | 327 } |
324 | 328 |
325 | 329 bool ParserBaseTraits<Parser>::IsThisProperty(Expression* expression) { |
326 bool ParserTraits::IsThisProperty(Expression* expression) { | |
327 DCHECK(expression != NULL); | 330 DCHECK(expression != NULL); |
328 Property* property = expression->AsProperty(); | 331 Property* property = expression->AsProperty(); |
329 return property != NULL && property->obj()->IsVariableProxy() && | 332 return property != NULL && property->obj()->IsVariableProxy() && |
330 property->obj()->AsVariableProxy()->is_this(); | 333 property->obj()->AsVariableProxy()->is_this(); |
331 } | 334 } |
332 | 335 |
333 | 336 bool ParserBaseTraits<Parser>::IsIdentifier(Expression* expression) { |
334 bool ParserTraits::IsIdentifier(Expression* expression) { | |
335 VariableProxy* operand = expression->AsVariableProxy(); | 337 VariableProxy* operand = expression->AsVariableProxy(); |
336 return operand != NULL && !operand->is_this(); | 338 return operand != NULL && !operand->is_this(); |
337 } | 339 } |
338 | 340 |
339 | 341 void ParserBaseTraits<Parser>::PushPropertyName(FuncNameInferrer* fni, |
340 void ParserTraits::PushPropertyName(FuncNameInferrer* fni, | 342 Expression* expression) { |
341 Expression* expression) { | |
342 if (expression->IsPropertyName()) { | 343 if (expression->IsPropertyName()) { |
343 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); | 344 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); |
344 } else { | 345 } else { |
345 fni->PushLiteralName( | 346 fni->PushLiteralName( |
346 parser_->ast_value_factory()->anonymous_function_string()); | 347 delegate()->ast_value_factory()->anonymous_function_string()); |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 | 351 void ParserBaseTraits<Parser>::CheckAssigningFunctionLiteralToProperty( |
351 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, | 352 Expression* left, Expression* right) { |
352 Expression* right) { | |
353 DCHECK(left != NULL); | 353 DCHECK(left != NULL); |
354 if (left->IsProperty() && right->IsFunctionLiteral()) { | 354 if (left->IsProperty() && right->IsFunctionLiteral()) { |
355 right->AsFunctionLiteral()->set_pretenure(); | 355 right->AsFunctionLiteral()->set_pretenure(); |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 | 359 Expression* ParserBaseTraits<Parser>::MarkExpressionAsAssigned( |
360 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) { | 360 Expression* expression) { |
361 VariableProxy* proxy = | 361 VariableProxy* proxy = |
362 expression != NULL ? expression->AsVariableProxy() : NULL; | 362 expression != NULL ? expression->AsVariableProxy() : NULL; |
363 if (proxy != NULL) proxy->set_is_assigned(); | 363 if (proxy != NULL) proxy->set_is_assigned(); |
364 return expression; | 364 return expression; |
365 } | 365 } |
366 | 366 |
367 | 367 bool ParserBaseTraits<Parser>::ShortcutNumericLiteralBinaryExpression( |
368 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( | |
369 Expression** x, Expression* y, Token::Value op, int pos, | 368 Expression** x, Expression* y, Token::Value op, int pos, |
370 AstNodeFactory* factory) { | 369 AstNodeFactory* factory) { |
371 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && | 370 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && |
372 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { | 371 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { |
373 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); | 372 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); |
374 double y_val = y->AsLiteral()->raw_value()->AsNumber(); | 373 double y_val = y->AsLiteral()->raw_value()->AsNumber(); |
375 bool x_has_dot = (*x)->AsLiteral()->raw_value()->ContainsDot(); | 374 bool x_has_dot = (*x)->AsLiteral()->raw_value()->ContainsDot(); |
376 bool y_has_dot = y->AsLiteral()->raw_value()->ContainsDot(); | 375 bool y_has_dot = y->AsLiteral()->raw_value()->ContainsDot(); |
377 bool has_dot = x_has_dot || y_has_dot; | 376 bool has_dot = x_has_dot || y_has_dot; |
378 switch (op) { | 377 switch (op) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 has_dot); | 427 has_dot); |
429 return true; | 428 return true; |
430 } | 429 } |
431 default: | 430 default: |
432 break; | 431 break; |
433 } | 432 } |
434 } | 433 } |
435 return false; | 434 return false; |
436 } | 435 } |
437 | 436 |
438 | 437 Expression* ParserBaseTraits<Parser>::BuildUnaryExpression( |
439 Expression* ParserTraits::BuildUnaryExpression(Expression* expression, | 438 Expression* expression, Token::Value op, int pos, AstNodeFactory* factory) { |
440 Token::Value op, int pos, | |
441 AstNodeFactory* factory) { | |
442 DCHECK(expression != NULL); | 439 DCHECK(expression != NULL); |
443 if (expression->IsLiteral()) { | 440 if (expression->IsLiteral()) { |
444 const AstValue* literal = expression->AsLiteral()->raw_value(); | 441 const AstValue* literal = expression->AsLiteral()->raw_value(); |
445 if (op == Token::NOT) { | 442 if (op == Token::NOT) { |
446 // Convert the literal to a boolean condition and negate it. | 443 // Convert the literal to a boolean condition and negate it. |
447 bool condition = literal->BooleanValue(); | 444 bool condition = literal->BooleanValue(); |
448 return factory->NewBooleanLiteral(!condition, pos); | 445 return factory->NewBooleanLiteral(!condition, pos); |
449 } else if (literal->IsNumber()) { | 446 } else if (literal->IsNumber()) { |
450 // Compute some expressions involving only number literals. | 447 // Compute some expressions involving only number literals. |
451 double value = literal->AsNumber(); | 448 double value = literal->AsNumber(); |
(...skipping 21 matching lines...) Expand all Loading... |
473 Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos); | 470 Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos); |
474 } | 471 } |
475 // ...and one more time for '~foo' => 'foo^(~0)'. | 472 // ...and one more time for '~foo' => 'foo^(~0)'. |
476 if (op == Token::BIT_NOT) { | 473 if (op == Token::BIT_NOT) { |
477 return factory->NewBinaryOperation( | 474 return factory->NewBinaryOperation( |
478 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); | 475 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); |
479 } | 476 } |
480 return factory->NewUnaryOperation(op, expression, pos); | 477 return factory->NewUnaryOperation(op, expression, pos); |
481 } | 478 } |
482 | 479 |
483 Expression* ParserTraits::BuildIteratorResult(Expression* value, bool done) { | 480 Expression* ParserBaseTraits<Parser>::BuildIteratorResult(Expression* value, |
| 481 bool done) { |
484 int pos = kNoSourcePosition; | 482 int pos = kNoSourcePosition; |
485 AstNodeFactory* factory = parser_->factory(); | 483 AstNodeFactory* factory = delegate()->factory(); |
486 Zone* zone = parser_->zone(); | 484 Zone* zone = delegate()->zone(); |
487 | 485 |
488 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); | 486 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); |
489 | 487 |
490 auto args = new (zone) ZoneList<Expression*>(2, zone); | 488 auto args = new (zone) ZoneList<Expression*>(2, zone); |
491 args->Add(value, zone); | 489 args->Add(value, zone); |
492 args->Add(factory->NewBooleanLiteral(done, pos), zone); | 490 args->Add(factory->NewBooleanLiteral(done, pos), zone); |
493 | 491 |
494 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, | 492 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, |
495 pos); | 493 pos); |
496 } | 494 } |
497 | 495 |
498 Expression* ParserTraits::NewThrowReferenceError( | 496 Expression* ParserBaseTraits<Parser>::NewThrowReferenceError( |
499 MessageTemplate::Template message, int pos) { | 497 MessageTemplate::Template message, int pos) { |
500 return parser_->NewThrowError(Runtime::kNewReferenceError, message, | 498 return delegate()->NewThrowError( |
501 parser_->ast_value_factory()->empty_string(), | 499 Runtime::kNewReferenceError, message, |
502 pos); | 500 delegate()->ast_value_factory()->empty_string(), pos); |
503 } | 501 } |
504 | 502 |
505 | 503 Expression* ParserBaseTraits<Parser>::NewThrowSyntaxError( |
506 Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message, | 504 MessageTemplate::Template message, const AstRawString* arg, int pos) { |
507 const AstRawString* arg, | 505 return delegate()->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); |
508 int pos) { | |
509 return parser_->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); | |
510 } | 506 } |
511 | 507 |
512 | 508 Expression* ParserBaseTraits<Parser>::NewThrowTypeError( |
513 Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message, | 509 MessageTemplate::Template message, const AstRawString* arg, int pos) { |
514 const AstRawString* arg, int pos) { | 510 return delegate()->NewThrowError(Runtime::kNewTypeError, message, arg, pos); |
515 return parser_->NewThrowError(Runtime::kNewTypeError, message, arg, pos); | |
516 } | 511 } |
517 | 512 |
518 Expression* Parser::NewThrowError(Runtime::FunctionId id, | 513 Expression* Parser::NewThrowError(Runtime::FunctionId id, |
519 MessageTemplate::Template message, | 514 MessageTemplate::Template message, |
520 const AstRawString* arg, int pos) { | 515 const AstRawString* arg, int pos) { |
521 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 516 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
522 args->Add(factory()->NewSmiLiteral(message, pos), zone()); | 517 args->Add(factory()->NewSmiLiteral(message, pos), zone()); |
523 args->Add(factory()->NewStringLiteral(arg, pos), zone()); | 518 args->Add(factory()->NewStringLiteral(arg, pos), zone()); |
524 CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos); | 519 CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos); |
525 return factory()->NewThrow(call_constructor, pos); | 520 return factory()->NewThrow(call_constructor, pos); |
526 } | 521 } |
527 | 522 |
528 | 523 void ParserBaseTraits<Parser>::ReportMessageAt( |
529 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 524 Scanner::Location source_location, MessageTemplate::Template message, |
530 MessageTemplate::Template message, | 525 const char* arg, ParseErrorType error_type) { |
531 const char* arg, ParseErrorType error_type) { | 526 if (delegate()->stack_overflow()) { |
532 if (parser_->stack_overflow()) { | |
533 // Suppress the error message (syntax error or such) in the presence of a | 527 // Suppress the error message (syntax error or such) in the presence of a |
534 // stack overflow. The isolate allows only one pending exception at at time | 528 // stack overflow. The isolate allows only one pending exception at at time |
535 // and we want to report the stack overflow later. | 529 // and we want to report the stack overflow later. |
536 return; | 530 return; |
537 } | 531 } |
538 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 532 delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
539 source_location.end_pos, | 533 source_location.end_pos, |
540 message, arg, error_type); | 534 message, arg, error_type); |
541 } | 535 } |
542 | 536 |
543 | 537 void ParserBaseTraits<Parser>::ReportMessageAt( |
544 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 538 Scanner::Location source_location, MessageTemplate::Template message, |
545 MessageTemplate::Template message, | 539 const AstRawString* arg, ParseErrorType error_type) { |
546 const AstRawString* arg, | 540 if (delegate()->stack_overflow()) { |
547 ParseErrorType error_type) { | |
548 if (parser_->stack_overflow()) { | |
549 // Suppress the error message (syntax error or such) in the presence of a | 541 // Suppress the error message (syntax error or such) in the presence of a |
550 // stack overflow. The isolate allows only one pending exception at at time | 542 // stack overflow. The isolate allows only one pending exception at at time |
551 // and we want to report the stack overflow later. | 543 // and we want to report the stack overflow later. |
552 return; | 544 return; |
553 } | 545 } |
554 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 546 delegate()->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
555 source_location.end_pos, | 547 source_location.end_pos, |
556 message, arg, error_type); | 548 message, arg, error_type); |
557 } | 549 } |
558 | 550 |
559 | 551 const AstRawString* ParserBaseTraits<Parser>::GetSymbol( |
560 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) const { | 552 Scanner* scanner) const { |
561 const AstRawString* result = | 553 const AstRawString* result = |
562 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); | 554 delegate()->scanner()->CurrentSymbol(delegate()->ast_value_factory()); |
563 DCHECK(result != NULL); | 555 DCHECK(result != NULL); |
564 return result; | 556 return result; |
565 } | 557 } |
566 | 558 |
567 | 559 const AstRawString* ParserBaseTraits<Parser>::GetNumberAsSymbol( |
568 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) const { | 560 Scanner* scanner) const { |
569 double double_value = parser_->scanner()->DoubleValue(); | 561 double double_value = delegate()->scanner()->DoubleValue(); |
570 char array[100]; | 562 char array[100]; |
571 const char* string = DoubleToCString(double_value, ArrayVector(array)); | 563 const char* string = DoubleToCString(double_value, ArrayVector(array)); |
572 return parser_->ast_value_factory()->GetOneByteString(string); | 564 return delegate()->ast_value_factory()->GetOneByteString(string); |
573 } | 565 } |
574 | 566 |
575 | 567 const AstRawString* ParserBaseTraits<Parser>::GetNextSymbol( |
576 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) const { | 568 Scanner* scanner) const { |
577 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 569 return delegate()->scanner()->NextSymbol(delegate()->ast_value_factory()); |
578 } | 570 } |
579 | 571 |
580 Expression* ParserTraits::ThisExpression(int pos) { | 572 Expression* ParserBaseTraits<Parser>::ThisExpression(int pos) { |
581 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), | 573 return delegate()->NewUnresolved( |
582 pos, pos + 4, Variable::THIS); | 574 delegate()->ast_value_factory()->this_string(), pos, pos + 4, |
| 575 Variable::THIS); |
583 } | 576 } |
584 | 577 |
585 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, | 578 Expression* ParserBaseTraits<Parser>::NewSuperPropertyReference( |
586 int pos) { | 579 AstNodeFactory* factory, int pos) { |
587 // this_function[home_object_symbol] | 580 // this_function[home_object_symbol] |
588 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 581 VariableProxy* this_function_proxy = delegate()->NewUnresolved( |
589 parser_->ast_value_factory()->this_function_string(), pos); | 582 delegate()->ast_value_factory()->this_function_string(), pos); |
590 Expression* home_object_symbol_literal = | 583 Expression* home_object_symbol_literal = |
591 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); | 584 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); |
592 Expression* home_object = factory->NewProperty( | 585 Expression* home_object = factory->NewProperty( |
593 this_function_proxy, home_object_symbol_literal, pos); | 586 this_function_proxy, home_object_symbol_literal, pos); |
594 return factory->NewSuperPropertyReference( | 587 return factory->NewSuperPropertyReference( |
595 ThisExpression(pos)->AsVariableProxy(), home_object, pos); | 588 ThisExpression(pos)->AsVariableProxy(), home_object, pos); |
596 } | 589 } |
597 | 590 |
598 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, | 591 Expression* ParserBaseTraits<Parser>::NewSuperCallReference( |
599 int pos) { | 592 AstNodeFactory* factory, int pos) { |
600 VariableProxy* new_target_proxy = parser_->NewUnresolved( | 593 VariableProxy* new_target_proxy = delegate()->NewUnresolved( |
601 parser_->ast_value_factory()->new_target_string(), pos); | 594 delegate()->ast_value_factory()->new_target_string(), pos); |
602 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 595 VariableProxy* this_function_proxy = delegate()->NewUnresolved( |
603 parser_->ast_value_factory()->this_function_string(), pos); | 596 delegate()->ast_value_factory()->this_function_string(), pos); |
604 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), | 597 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), |
605 new_target_proxy, this_function_proxy, | 598 new_target_proxy, this_function_proxy, |
606 pos); | 599 pos); |
607 } | 600 } |
608 | 601 |
609 Expression* ParserTraits::NewTargetExpression(int pos) { | 602 Expression* ParserBaseTraits<Parser>::NewTargetExpression(int pos) { |
610 static const int kNewTargetStringLength = 10; | 603 static const int kNewTargetStringLength = 10; |
611 auto proxy = | 604 auto proxy = delegate()->NewUnresolved( |
612 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), | 605 delegate()->ast_value_factory()->new_target_string(), pos, |
613 pos, pos + kNewTargetStringLength); | 606 pos + kNewTargetStringLength); |
614 proxy->set_is_new_target(); | 607 proxy->set_is_new_target(); |
615 return proxy; | 608 return proxy; |
616 } | 609 } |
617 | 610 |
618 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, | 611 Expression* ParserBaseTraits<Parser>::FunctionSentExpression( |
619 int pos) const { | 612 AstNodeFactory* factory, int pos) const { |
620 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). | 613 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). |
621 Zone* zone = parser_->zone(); | 614 Zone* zone = delegate()->zone(); |
622 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); | 615 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); |
623 VariableProxy* generator = factory->NewVariableProxy( | 616 VariableProxy* generator = factory->NewVariableProxy( |
624 parser_->function_state_->generator_object_variable()); | 617 delegate()->function_state_->generator_object_variable()); |
625 args->Add(generator, zone); | 618 args->Add(generator, zone); |
626 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, | 619 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, |
627 args, pos); | 620 args, pos); |
628 } | 621 } |
629 | 622 |
630 | 623 Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral( |
631 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, | 624 Token::Value token, int pos, Scanner* scanner, |
632 Scanner* scanner, | 625 AstNodeFactory* factory) const { |
633 AstNodeFactory* factory) const { | |
634 switch (token) { | 626 switch (token) { |
635 case Token::NULL_LITERAL: | 627 case Token::NULL_LITERAL: |
636 return factory->NewNullLiteral(pos); | 628 return factory->NewNullLiteral(pos); |
637 case Token::TRUE_LITERAL: | 629 case Token::TRUE_LITERAL: |
638 return factory->NewBooleanLiteral(true, pos); | 630 return factory->NewBooleanLiteral(true, pos); |
639 case Token::FALSE_LITERAL: | 631 case Token::FALSE_LITERAL: |
640 return factory->NewBooleanLiteral(false, pos); | 632 return factory->NewBooleanLiteral(false, pos); |
641 case Token::SMI: { | 633 case Token::SMI: { |
642 int value = scanner->smi_value(); | 634 int value = scanner->smi_value(); |
643 return factory->NewSmiLiteral(value, pos); | 635 return factory->NewSmiLiteral(value, pos); |
644 } | 636 } |
645 case Token::NUMBER: { | 637 case Token::NUMBER: { |
646 bool has_dot = scanner->ContainsDot(); | 638 bool has_dot = scanner->ContainsDot(); |
647 double value = scanner->DoubleValue(); | 639 double value = scanner->DoubleValue(); |
648 return factory->NewNumberLiteral(value, pos, has_dot); | 640 return factory->NewNumberLiteral(value, pos, has_dot); |
649 } | 641 } |
650 default: | 642 default: |
651 DCHECK(false); | 643 DCHECK(false); |
652 } | 644 } |
653 return NULL; | 645 return NULL; |
654 } | 646 } |
655 | 647 |
656 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 648 Expression* ParserBaseTraits<Parser>::ExpressionFromIdentifier( |
657 int start_position, | 649 const AstRawString* name, int start_position, int end_position, |
658 int end_position, | 650 InferName infer) { |
659 InferName infer) { | 651 if (infer == InferName::kYes && delegate()->fni_ != NULL) { |
660 if (infer == InferName::kYes && parser_->fni_ != NULL) { | 652 delegate()->fni_->PushVariableName(name); |
661 parser_->fni_->PushVariableName(name); | |
662 } | 653 } |
663 return parser_->NewUnresolved(name, start_position, end_position); | 654 return delegate()->NewUnresolved(name, start_position, end_position); |
664 } | 655 } |
665 | 656 |
666 | 657 Expression* ParserBaseTraits<Parser>::ExpressionFromString( |
667 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 658 int pos, Scanner* scanner, AstNodeFactory* factory) const { |
668 AstNodeFactory* factory) const { | |
669 const AstRawString* symbol = GetSymbol(scanner); | 659 const AstRawString* symbol = GetSymbol(scanner); |
670 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 660 if (delegate()->fni_ != NULL) delegate()->fni_->PushLiteralName(symbol); |
671 return factory->NewStringLiteral(symbol, pos); | 661 return factory->NewStringLiteral(symbol, pos); |
672 } | 662 } |
673 | 663 |
674 | 664 Expression* ParserBaseTraits<Parser>::GetIterator(Expression* iterable, |
675 Expression* ParserTraits::GetIterator(Expression* iterable, | 665 AstNodeFactory* factory, |
676 AstNodeFactory* factory, int pos) { | 666 int pos) { |
677 Expression* iterator_symbol_literal = | 667 Expression* iterator_symbol_literal = |
678 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); | 668 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); |
679 Expression* prop = | 669 Expression* prop = |
680 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 670 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
681 Zone* zone = parser_->zone(); | 671 Zone* zone = delegate()->zone(); |
682 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 672 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
683 return factory->NewCall(prop, args, pos); | 673 return factory->NewCall(prop, args, pos); |
684 } | 674 } |
685 | 675 |
686 | 676 Literal* ParserBaseTraits<Parser>::GetLiteralTheHole( |
687 Literal* ParserTraits::GetLiteralTheHole(int position, | 677 int position, AstNodeFactory* factory) const { |
688 AstNodeFactory* factory) const { | |
689 return factory->NewTheHoleLiteral(kNoSourcePosition); | 678 return factory->NewTheHoleLiteral(kNoSourcePosition); |
690 } | 679 } |
691 | 680 |
692 | 681 Expression* ParserBaseTraits<Parser>::ParseV8Intrinsic(bool* ok) { |
693 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 682 return delegate()->ParseV8Intrinsic(ok); |
694 return parser_->ParseV8Intrinsic(ok); | |
695 } | 683 } |
696 | 684 |
697 | 685 FunctionLiteral* ParserBaseTraits<Parser>::ParseFunctionLiteral( |
698 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | |
699 const AstRawString* name, Scanner::Location function_name_location, | 686 const AstRawString* name, Scanner::Location function_name_location, |
700 FunctionNameValidity function_name_validity, FunctionKind kind, | 687 FunctionNameValidity function_name_validity, FunctionKind kind, |
701 int function_token_position, FunctionLiteral::FunctionType type, | 688 int function_token_position, FunctionLiteral::FunctionType type, |
702 LanguageMode language_mode, bool* ok) { | 689 LanguageMode language_mode, bool* ok) { |
703 return parser_->ParseFunctionLiteral( | 690 return delegate()->ParseFunctionLiteral( |
704 name, function_name_location, function_name_validity, kind, | 691 name, function_name_location, function_name_validity, kind, |
705 function_token_position, type, language_mode, ok); | 692 function_token_position, type, language_mode, ok); |
706 } | 693 } |
707 | 694 |
708 Expression* ParserTraits::ParseClassLiteral( | 695 Expression* ParserBaseTraits<Parser>::ParseClassLiteral( |
709 Type::ExpressionClassifier* classifier, const AstRawString* name, | 696 Type::ExpressionClassifier* classifier, const AstRawString* name, |
710 Scanner::Location class_name_location, bool name_is_strict_reserved, | 697 Scanner::Location class_name_location, bool name_is_strict_reserved, |
711 int pos, bool* ok) { | 698 int pos, bool* ok) { |
712 return parser_->ParseClassLiteral(classifier, name, class_name_location, | 699 return delegate()->ParseClassLiteral(classifier, name, class_name_location, |
713 name_is_strict_reserved, pos, ok); | 700 name_is_strict_reserved, pos, ok); |
714 } | 701 } |
715 | 702 |
716 void ParserTraits::MarkTailPosition(Expression* expression) { | 703 void ParserBaseTraits<Parser>::MarkTailPosition(Expression* expression) { |
717 expression->MarkTail(); | 704 expression->MarkTail(); |
718 } | 705 } |
719 | 706 |
720 void ParserTraits::MarkCollectedTailCallExpressions() { | 707 void ParserBaseTraits<Parser>::MarkCollectedTailCallExpressions() { |
721 parser_->MarkCollectedTailCallExpressions(); | 708 delegate()->MarkCollectedTailCallExpressions(); |
722 } | 709 } |
723 | 710 |
724 Parser::Parser(ParseInfo* info) | 711 Parser::Parser(ParseInfo* info) |
725 : ParserBase<ParserTraits>(info->zone(), &scanner_, info->stack_limit(), | 712 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), |
726 info->extension(), info->ast_value_factory(), | 713 info->extension(), info->ast_value_factory(), NULL), |
727 NULL, this), | |
728 scanner_(info->unicode_cache()), | 714 scanner_(info->unicode_cache()), |
729 reusable_preparser_(NULL), | 715 reusable_preparser_(NULL), |
730 original_scope_(NULL), | 716 original_scope_(NULL), |
731 target_stack_(NULL), | 717 target_stack_(NULL), |
732 compile_options_(info->compile_options()), | 718 compile_options_(info->compile_options()), |
733 cached_parse_data_(NULL), | 719 cached_parse_data_(NULL), |
734 total_preparse_skipped_(0), | 720 total_preparse_skipped_(0), |
735 pre_parse_timer_(NULL), | 721 pre_parse_timer_(NULL), |
736 parsing_on_main_thread_(true) { | 722 parsing_on_main_thread_(true) { |
737 // Even though we were passed ParseInfo, we should not store it in | 723 // Even though we were passed ParseInfo, we should not store it in |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (body->length() != 1 || | 932 if (body->length() != 1 || |
947 !body->at(0)->IsExpressionStatement() || | 933 !body->at(0)->IsExpressionStatement() || |
948 !body->at(0)->AsExpressionStatement()-> | 934 !body->at(0)->AsExpressionStatement()-> |
949 expression()->IsFunctionLiteral()) { | 935 expression()->IsFunctionLiteral()) { |
950 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 936 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
951 ok = false; | 937 ok = false; |
952 } | 938 } |
953 } | 939 } |
954 | 940 |
955 if (ok) { | 941 if (ok) { |
956 ParserTraits::RewriteDestructuringAssignments(); | 942 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); |
957 result = factory()->NewScriptOrEvalFunctionLiteral( | 943 result = factory()->NewScriptOrEvalFunctionLiteral( |
958 scope, body, function_state.materialized_literal_count(), | 944 scope, body, function_state.materialized_literal_count(), |
959 function_state.expected_property_count()); | 945 function_state.expected_property_count()); |
960 } | 946 } |
961 } | 947 } |
962 | 948 |
963 // Make sure the target stack is empty. | 949 // Make sure the target stack is empty. |
964 DCHECK(target_stack_ == NULL); | 950 DCHECK(target_stack_ == NULL); |
965 | 951 |
966 return result; | 952 return result; |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2329 // Don't infer if it is "a = function(){...}();"-like expression. | 2315 // Don't infer if it is "a = function(){...}();"-like expression. |
2330 if (single_name) { | 2316 if (single_name) { |
2331 if (fni_ != NULL && value->AsCall() == NULL && | 2317 if (fni_ != NULL && value->AsCall() == NULL && |
2332 value->AsCallNew() == NULL) { | 2318 value->AsCallNew() == NULL) { |
2333 fni_->Infer(); | 2319 fni_->Infer(); |
2334 } else { | 2320 } else { |
2335 fni_->RemoveLastFunction(); | 2321 fni_->RemoveLastFunction(); |
2336 } | 2322 } |
2337 } | 2323 } |
2338 | 2324 |
2339 ParserTraits::SetFunctionNameFromIdentifierRef(value, pattern); | 2325 ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef(value, |
| 2326 pattern); |
2340 | 2327 |
2341 // End position of the initializer is after the assignment expression. | 2328 // End position of the initializer is after the assignment expression. |
2342 initializer_position = scanner()->location().end_pos; | 2329 initializer_position = scanner()->location().end_pos; |
2343 } else { | 2330 } else { |
2344 // Initializers may be either required or implied unless this is a | 2331 // Initializers may be either required or implied unless this is a |
2345 // for-in/of iteration variable. | 2332 // for-in/of iteration variable. |
2346 if (var_context != kForStatement || !PeekInOrOf()) { | 2333 if (var_context != kForStatement || !PeekInOrOf()) { |
2347 // ES6 'const' and binding patterns require initializers. | 2334 // ES6 'const' and binding patterns require initializers. |
2348 if (parsing_result->descriptor.mode == CONST || | 2335 if (parsing_result->descriptor.mode == CONST || |
2349 !pattern->IsVariableProxy()) { | 2336 !pattern->IsVariableProxy()) { |
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3989 if (expr->IsAssignment()) { | 3976 if (expr->IsAssignment()) { |
3990 Assignment* assignment = expr->AsAssignment(); | 3977 Assignment* assignment = expr->AsAssignment(); |
3991 DCHECK(!assignment->is_compound()); | 3978 DCHECK(!assignment->is_compound()); |
3992 initializer = assignment->value(); | 3979 initializer = assignment->value(); |
3993 expr = assignment->target(); | 3980 expr = assignment->target(); |
3994 } | 3981 } |
3995 | 3982 |
3996 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 3983 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); |
3997 } | 3984 } |
3998 | 3985 |
3999 void ParserTraits::ParseAsyncArrowSingleExpressionBody( | 3986 void ParserBaseTraits<Parser>::ParseAsyncArrowSingleExpressionBody( |
4000 ZoneList<Statement*>* body, bool accept_IN, | 3987 ZoneList<Statement*>* body, bool accept_IN, |
4001 Type::ExpressionClassifier* classifier, int pos, bool* ok) { | 3988 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
4002 parser_->DesugarAsyncFunctionBody( | 3989 delegate()->DesugarAsyncFunctionBody( |
4003 parser_->ast_value_factory()->empty_string(), parser_->scope(), body, | 3990 delegate()->ast_value_factory()->empty_string(), delegate()->scope(), |
4004 classifier, kAsyncArrowFunction, | 3991 body, classifier, kAsyncArrowFunction, |
4005 Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok); | 3992 Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok); |
4006 } | 3993 } |
4007 | 3994 |
4008 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, | 3995 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, |
4009 Scope* scope, ZoneList<Statement*>* body, | 3996 Scope* scope, ZoneList<Statement*>* body, |
4010 ExpressionClassifier* classifier, | 3997 ExpressionClassifier* classifier, |
4011 FunctionKind kind, | 3998 FunctionKind kind, |
4012 FunctionBodyType body_type, | 3999 FunctionBodyType body_type, |
4013 bool accept_IN, int pos, bool* ok) { | 4000 bool accept_IN, int pos, bool* ok) { |
4014 // function async_function() { | 4001 // function async_function() { |
(...skipping 20 matching lines...) Expand all Loading... |
4035 | 4022 |
4036 ZoneList<Statement*>* inner_body = try_block->statements(); | 4023 ZoneList<Statement*>* inner_body = try_block->statements(); |
4037 | 4024 |
4038 Expression* return_value = nullptr; | 4025 Expression* return_value = nullptr; |
4039 if (body_type == FunctionBodyType::kNormal) { | 4026 if (body_type == FunctionBodyType::kNormal) { |
4040 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); | 4027 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); |
4041 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); | 4028 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); |
4042 } else { | 4029 } else { |
4043 return_value = | 4030 return_value = |
4044 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); | 4031 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); |
4045 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_VOID); | 4032 ParserBaseTraits<Parser>::RewriteNonPattern(classifier, CHECK_OK_VOID); |
4046 } | 4033 } |
4047 | 4034 |
4048 return_value = BuildPromiseResolve(return_value, return_value->position()); | 4035 return_value = BuildPromiseResolve(return_value, return_value->position()); |
4049 inner_body->Add( | 4036 inner_body->Add( |
4050 factory()->NewReturnStatement(return_value, return_value->position()), | 4037 factory()->NewReturnStatement(return_value, return_value->position()), |
4051 zone()); | 4038 zone()); |
4052 body->Add(BuildRejectPromiseOnException(try_block), zone()); | 4039 body->Add(BuildRejectPromiseOnException(try_block), zone()); |
4053 scope->set_end_position(scanner()->location().end_pos); | 4040 scope->set_end_position(scanner()->location().end_pos); |
4054 } | 4041 } |
4055 | 4042 |
4056 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4043 DoExpression* Parser::ParseDoExpression(bool* ok) { |
4057 // AssignmentExpression :: | 4044 // AssignmentExpression :: |
4058 // do '{' StatementList '}' | 4045 // do '{' StatementList '}' |
4059 int pos = peek_position(); | 4046 int pos = peek_position(); |
4060 | 4047 |
4061 Expect(Token::DO, CHECK_OK); | 4048 Expect(Token::DO, CHECK_OK); |
4062 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 4049 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
4063 Block* block = ParseBlock(nullptr, CHECK_OK); | 4050 Block* block = ParseBlock(nullptr, CHECK_OK); |
4064 DoExpression* expr = factory()->NewDoExpression(block, result, pos); | 4051 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
4065 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 4052 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
4066 *ok = false; | 4053 *ok = false; |
4067 return nullptr; | 4054 return nullptr; |
4068 } | 4055 } |
4069 return expr; | 4056 return expr; |
4070 } | 4057 } |
4071 | 4058 |
4072 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4059 void ParserBaseTraits<Parser>::ParseArrowFunctionFormalParameterList( |
4073 ParserFormalParameters* parameters, Expression* expr, | 4060 ParserFormalParameters* parameters, Expression* expr, |
4074 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 4061 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
4075 const Scope::Snapshot& scope_snapshot, bool* ok) { | 4062 const Scope::Snapshot& scope_snapshot, bool* ok) { |
4076 if (expr->IsEmptyParentheses()) return; | 4063 if (expr->IsEmptyParentheses()) return; |
4077 | 4064 |
4078 parser_->ParseArrowFunctionFormalParameters( | 4065 delegate()->ParseArrowFunctionFormalParameters( |
4079 parameters, expr, params_loc.end_pos, CHECK_OK_VOID); | 4066 parameters, expr, params_loc.end_pos, CHECK_OK_VOID); |
4080 | 4067 |
4081 scope_snapshot.Reparent(parameters->scope); | 4068 scope_snapshot.Reparent(parameters->scope); |
4082 | 4069 |
4083 if (parameters->Arity() > Code::kMaxArguments) { | 4070 if (parameters->Arity() > Code::kMaxArguments) { |
4084 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 4071 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
4085 *ok = false; | 4072 *ok = false; |
4086 return; | 4073 return; |
4087 } | 4074 } |
4088 | 4075 |
4089 Type::ExpressionClassifier classifier(parser_); | 4076 Type::ExpressionClassifier classifier(delegate()); |
4090 if (!parameters->is_simple) { | 4077 if (!parameters->is_simple) { |
4091 classifier.RecordNonSimpleParameter(); | 4078 classifier.RecordNonSimpleParameter(); |
4092 } | 4079 } |
4093 for (int i = 0; i < parameters->Arity(); ++i) { | 4080 for (int i = 0; i < parameters->Arity(); ++i) { |
4094 auto parameter = parameters->at(i); | 4081 auto parameter = parameters->at(i); |
4095 DeclareFormalParameter(parameters->scope, parameter, &classifier); | 4082 DeclareFormalParameter(parameters->scope, parameter, &classifier); |
4096 if (!duplicate_loc->IsValid()) { | 4083 if (!duplicate_loc->IsValid()) { |
4097 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 4084 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; |
4098 } | 4085 } |
4099 } | 4086 } |
4100 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); | 4087 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); |
4101 } | 4088 } |
4102 | 4089 |
4103 | 4090 void ParserBaseTraits<Parser>::ReindexLiterals( |
4104 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { | 4091 const ParserFormalParameters& parameters) { |
4105 if (parser_->function_state_->materialized_literal_count() > 0) { | 4092 if (delegate()->function_state_->materialized_literal_count() > 0) { |
4106 AstLiteralReindexer reindexer; | 4093 AstLiteralReindexer reindexer; |
4107 | 4094 |
4108 for (const auto p : parameters.params) { | 4095 for (const auto p : parameters.params) { |
4109 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); | 4096 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); |
4110 if (p.initializer != nullptr) reindexer.Reindex(p.initializer); | 4097 if (p.initializer != nullptr) reindexer.Reindex(p.initializer); |
4111 } | 4098 } |
4112 | 4099 |
4113 DCHECK(reindexer.count() <= | 4100 DCHECK(reindexer.count() <= |
4114 parser_->function_state_->materialized_literal_count()); | 4101 delegate()->function_state_->materialized_literal_count()); |
4115 } | 4102 } |
4116 } | 4103 } |
4117 | 4104 |
4118 | 4105 |
4119 FunctionLiteral* Parser::ParseFunctionLiteral( | 4106 FunctionLiteral* Parser::ParseFunctionLiteral( |
4120 const AstRawString* function_name, Scanner::Location function_name_location, | 4107 const AstRawString* function_name, Scanner::Location function_name_location, |
4121 FunctionNameValidity function_name_validity, FunctionKind kind, | 4108 FunctionNameValidity function_name_validity, FunctionKind kind, |
4122 int function_token_pos, FunctionLiteral::FunctionType function_type, | 4109 int function_token_pos, FunctionLiteral::FunctionType function_type, |
4123 LanguageMode language_mode, bool* ok) { | 4110 LanguageMode language_mode, bool* ok) { |
4124 // Function :: | 4111 // Function :: |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4339 if (is_strict(language_mode)) { | 4326 if (is_strict(language_mode)) { |
4340 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4327 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4341 CHECK_OK); | 4328 CHECK_OK); |
4342 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(), | 4329 CheckDecimalLiteralWithLeadingZero(use_counts_, scope->start_position(), |
4343 scope->end_position()); | 4330 scope->end_position()); |
4344 } | 4331 } |
4345 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4332 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4346 | 4333 |
4347 if (body) { | 4334 if (body) { |
4348 // If body can be inspected, rewrite queued destructuring assignments | 4335 // If body can be inspected, rewrite queued destructuring assignments |
4349 ParserTraits::RewriteDestructuringAssignments(); | 4336 ParserBaseTraits<Parser>::RewriteDestructuringAssignments(); |
4350 } | 4337 } |
4351 has_duplicate_parameters = | 4338 has_duplicate_parameters = |
4352 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4339 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4353 | 4340 |
4354 if (use_temp_zone) { | 4341 if (use_temp_zone) { |
4355 DCHECK(main_scope != scope); | 4342 DCHECK(main_scope != scope); |
4356 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory); | 4343 scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory); |
4357 } | 4344 } |
4358 } // DiscardableZoneScope goes out of scope. | 4345 } // DiscardableZoneScope goes out of scope. |
4359 | 4346 |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5361 | 5348 |
5362 // We cannot internalize on a background thread; a foreground task will take | 5349 // We cannot internalize on a background thread; a foreground task will take |
5363 // care of calling Parser::Internalize just before compilation. | 5350 // care of calling Parser::Internalize just before compilation. |
5364 | 5351 |
5365 if (produce_cached_parse_data()) { | 5352 if (produce_cached_parse_data()) { |
5366 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); | 5353 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); |
5367 log_ = NULL; | 5354 log_ = NULL; |
5368 } | 5355 } |
5369 } | 5356 } |
5370 | 5357 |
5371 | 5358 ParserBaseTraits<Parser>::TemplateLiteralState Parser::OpenTemplateLiteral( |
5372 ParserTraits::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { | 5359 int pos) { |
5373 return new (zone()) ParserTraits::TemplateLiteral(zone(), pos); | 5360 return new (zone()) ParserBaseTraits<Parser>::TemplateLiteral(zone(), pos); |
5374 } | 5361 } |
5375 | 5362 |
5376 | 5363 |
5377 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | 5364 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { |
5378 int pos = scanner()->location().beg_pos; | 5365 int pos = scanner()->location().beg_pos; |
5379 int end = scanner()->location().end_pos - (tail ? 1 : 2); | 5366 int end = scanner()->location().end_pos - (tail ? 1 : 2); |
5380 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); | 5367 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); |
5381 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); | 5368 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); |
5382 Literal* cooked = factory()->NewStringLiteral(tv, pos); | 5369 Literal* cooked = factory()->NewStringLiteral(tv, pos); |
5383 Literal* raw = factory()->NewStringLiteral(trv, pos); | 5370 Literal* raw = factory()->NewStringLiteral(trv, pos); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5628 for (int i = 0; i < tail_call_expressions.length(); ++i) { | 5615 for (int i = 0; i < tail_call_expressions.length(); ++i) { |
5629 Expression* expression = tail_call_expressions[i]; | 5616 Expression* expression = tail_call_expressions[i]; |
5630 // If only FLAG_harmony_explicit_tailcalls is enabled then expression | 5617 // If only FLAG_harmony_explicit_tailcalls is enabled then expression |
5631 // must be a Call expression. | 5618 // must be a Call expression. |
5632 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || | 5619 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || |
5633 expression->IsCall()); | 5620 expression->IsCall()); |
5634 MarkTailPosition(expression); | 5621 MarkTailPosition(expression); |
5635 } | 5622 } |
5636 } | 5623 } |
5637 | 5624 |
5638 Expression* ParserTraits::ExpressionListToExpression( | 5625 Expression* ParserBaseTraits<Parser>::ExpressionListToExpression( |
5639 ZoneList<Expression*>* args) { | 5626 ZoneList<Expression*>* args) { |
5640 AstNodeFactory* factory = parser_->factory(); | 5627 AstNodeFactory* factory = delegate()->factory(); |
5641 Expression* expr = args->at(0); | 5628 Expression* expr = args->at(0); |
5642 for (int i = 1; i < args->length(); ++i) { | 5629 for (int i = 1; i < args->length(); ++i) { |
5643 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), | 5630 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), |
5644 expr->position()); | 5631 expr->position()); |
5645 } | 5632 } |
5646 return expr; | 5633 return expr; |
5647 } | 5634 } |
5648 | 5635 |
5649 void ParserTraits::RewriteDestructuringAssignments() { | 5636 void ParserBaseTraits<Parser>::RewriteDestructuringAssignments() { |
5650 parser_->RewriteDestructuringAssignments(); | 5637 delegate()->RewriteDestructuringAssignments(); |
5651 } | 5638 } |
5652 | 5639 |
5653 Expression* ParserTraits::RewriteExponentiation(Expression* left, | 5640 Expression* ParserBaseTraits<Parser>::RewriteExponentiation(Expression* left, |
5654 Expression* right, int pos) { | 5641 Expression* right, |
5655 return parser_->RewriteExponentiation(left, right, pos); | 5642 int pos) { |
| 5643 return delegate()->RewriteExponentiation(left, right, pos); |
5656 } | 5644 } |
5657 | 5645 |
5658 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left, | 5646 Expression* ParserBaseTraits<Parser>::RewriteAssignExponentiation( |
5659 Expression* right, | 5647 Expression* left, Expression* right, int pos) { |
5660 int pos) { | 5648 return delegate()->RewriteAssignExponentiation(left, right, pos); |
5661 return parser_->RewriteAssignExponentiation(left, right, pos); | |
5662 } | 5649 } |
5663 | 5650 |
5664 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5651 void ParserBaseTraits<Parser>::RewriteNonPattern( |
5665 bool* ok) { | 5652 Type::ExpressionClassifier* classifier, bool* ok) { |
5666 parser_->RewriteNonPattern(classifier, ok); | 5653 delegate()->RewriteNonPattern(classifier, ok); |
5667 } | 5654 } |
5668 | 5655 |
5669 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, | 5656 Expression* ParserBaseTraits<Parser>::RewriteAwaitExpression(Expression* value, |
5670 int await_pos) { | 5657 int await_pos) { |
5671 // yield %AsyncFunctionAwait(.generator_object, <operand>) | 5658 // yield %AsyncFunctionAwait(.generator_object, <operand>) |
5672 Variable* generator_object_variable = | 5659 Variable* generator_object_variable = |
5673 parser_->function_state_->generator_object_variable(); | 5660 delegate()->function_state_->generator_object_variable(); |
5674 | 5661 |
5675 // If generator_object_variable is null, | 5662 // If generator_object_variable is null, |
5676 if (!generator_object_variable) return value; | 5663 if (!generator_object_variable) return value; |
5677 | 5664 |
5678 auto factory = parser_->factory(); | 5665 auto factory = delegate()->factory(); |
5679 const int nopos = kNoSourcePosition; | 5666 const int nopos = kNoSourcePosition; |
5680 | 5667 |
5681 Variable* temp_var = | 5668 Variable* temp_var = |
5682 parser_->NewTemporary(parser_->ast_value_factory()->empty_string()); | 5669 delegate()->NewTemporary(delegate()->ast_value_factory()->empty_string()); |
5683 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); | 5670 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); |
5684 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); | 5671 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); |
5685 | 5672 |
5686 // Wrap value evaluation to provide a break location. | 5673 // Wrap value evaluation to provide a break location. |
5687 Expression* value_assignment = | 5674 Expression* value_assignment = |
5688 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); | 5675 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); |
5689 do_block->statements()->Add( | 5676 do_block->statements()->Add( |
5690 factory->NewExpressionStatement(value_assignment, value->position()), | 5677 factory->NewExpressionStatement(value_assignment, value->position()), |
5691 zone()); | 5678 zone()); |
5692 | 5679 |
5693 ZoneList<Expression*>* async_function_await_args = | 5680 ZoneList<Expression*>* async_function_await_args = |
5694 new (zone()) ZoneList<Expression*>(2, zone()); | 5681 new (zone()) ZoneList<Expression*>(2, zone()); |
5695 Expression* generator_object = | 5682 Expression* generator_object = |
5696 factory->NewVariableProxy(generator_object_variable); | 5683 factory->NewVariableProxy(generator_object_variable); |
5697 async_function_await_args->Add(generator_object, zone()); | 5684 async_function_await_args->Add(generator_object, zone()); |
5698 async_function_await_args->Add(temp_proxy, zone()); | 5685 async_function_await_args->Add(temp_proxy, zone()); |
5699 Expression* async_function_await = parser_->factory()->NewCallRuntime( | 5686 Expression* async_function_await = delegate()->factory()->NewCallRuntime( |
5700 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); | 5687 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); |
5701 // Wrap await to provide a break location between value evaluation and yield. | 5688 // Wrap await to provide a break location between value evaluation and yield. |
5702 Expression* await_assignment = factory->NewAssignment( | 5689 Expression* await_assignment = factory->NewAssignment( |
5703 Token::ASSIGN, temp_proxy, async_function_await, nopos); | 5690 Token::ASSIGN, temp_proxy, async_function_await, nopos); |
5704 do_block->statements()->Add( | 5691 do_block->statements()->Add( |
5705 factory->NewExpressionStatement(await_assignment, await_pos), zone()); | 5692 factory->NewExpressionStatement(await_assignment, await_pos), zone()); |
5706 Expression* do_expr = factory->NewDoExpression(do_block, temp_var, nopos); | 5693 Expression* do_expr = factory->NewDoExpression(do_block, temp_var, nopos); |
5707 | 5694 |
5708 generator_object = factory->NewVariableProxy(generator_object_variable); | 5695 generator_object = factory->NewVariableProxy(generator_object_variable); |
5709 return factory->NewYield(generator_object, do_expr, nopos, | 5696 return factory->NewYield(generator_object, do_expr, nopos, |
5710 Yield::kOnExceptionRethrow); | 5697 Yield::kOnExceptionRethrow); |
5711 } | 5698 } |
5712 | 5699 |
5713 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { | 5700 ZoneList<Expression*>* ParserBaseTraits<Parser>::GetNonPatternList() const { |
5714 return parser_->function_state_->non_patterns_to_rewrite(); | 5701 return delegate()->function_state_->non_patterns_to_rewrite(); |
5715 } | 5702 } |
5716 | 5703 |
5717 | 5704 ZoneList<typename ParserBaseTraits<Parser>::Type::ExpressionClassifier::Error>* |
5718 ZoneList<typename ParserTraits::Type::ExpressionClassifier::Error>* | 5705 ParserBaseTraits<Parser>::GetReportedErrorList() const { |
5719 ParserTraits::GetReportedErrorList() const { | 5706 return delegate()->function_state_->GetReportedErrorList(); |
5720 return parser_->function_state_->GetReportedErrorList(); | |
5721 } | 5707 } |
5722 | 5708 |
5723 Zone* ParserTraits::zone() const { return parser_->zone(); } | 5709 Zone* ParserBaseTraits<Parser>::zone() const { return delegate()->zone(); } |
5724 | 5710 |
5725 class NonPatternRewriter : public AstExpressionRewriter { | 5711 class NonPatternRewriter : public AstExpressionRewriter { |
5726 public: | 5712 public: |
5727 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) | 5713 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) |
5728 : AstExpressionRewriter(stack_limit), parser_(parser) {} | 5714 : AstExpressionRewriter(stack_limit), parser_(parser) {} |
5729 ~NonPatternRewriter() override {} | 5715 ~NonPatternRewriter() override {} |
5730 | 5716 |
5731 private: | 5717 private: |
5732 bool RewriteExpression(Expression* expr) override { | 5718 bool RewriteExpression(Expression* expr) override { |
5733 if (expr->IsRewritableExpression()) return true; | 5719 if (expr->IsRewritableExpression()) return true; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5913 append_body, finalize); | 5899 append_body, finalize); |
5914 do_block->statements()->Add(loop, zone()); | 5900 do_block->statements()->Add(loop, zone()); |
5915 } | 5901 } |
5916 } | 5902 } |
5917 // Now, rewind the original array literal to truncate everything from the | 5903 // Now, rewind the original array literal to truncate everything from the |
5918 // first spread (included) until the end. This fixes $R's initialization. | 5904 // first spread (included) until the end. This fixes $R's initialization. |
5919 lit->RewindSpreads(); | 5905 lit->RewindSpreads(); |
5920 return factory()->NewDoExpression(do_block, result, lit->position()); | 5906 return factory()->NewDoExpression(do_block, result, lit->position()); |
5921 } | 5907 } |
5922 | 5908 |
5923 | 5909 void ParserBaseTraits<Parser>::QueueDestructuringAssignmentForRewriting( |
5924 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 5910 Expression* expr) { |
5925 DCHECK(expr->IsRewritableExpression()); | 5911 DCHECK(expr->IsRewritableExpression()); |
5926 parser_->function_state_->AddDestructuringAssignment( | 5912 delegate()->function_state_->AddDestructuringAssignment( |
5927 Parser::DestructuringAssignment(expr, parser_->scope())); | 5913 Parser::DestructuringAssignment(expr, delegate()->scope())); |
5928 } | 5914 } |
5929 | 5915 |
5930 | 5916 void ParserBaseTraits<Parser>::QueueNonPatternForRewriting(Expression* expr, |
5931 void ParserTraits::QueueNonPatternForRewriting(Expression* expr, bool* ok) { | 5917 bool* ok) { |
5932 DCHECK(expr->IsRewritableExpression()); | 5918 DCHECK(expr->IsRewritableExpression()); |
5933 parser_->function_state_->AddNonPatternForRewriting(expr, ok); | 5919 delegate()->function_state_->AddNonPatternForRewriting(expr, ok); |
5934 } | 5920 } |
5935 | 5921 |
5936 | 5922 void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName( |
5937 void ParserTraits::SetFunctionNameFromPropertyName( | |
5938 ObjectLiteralProperty* property, const AstRawString* name) { | 5923 ObjectLiteralProperty* property, const AstRawString* name) { |
5939 Expression* value = property->value(); | 5924 Expression* value = property->value(); |
5940 | 5925 |
5941 // Computed name setting must happen at runtime. | 5926 // Computed name setting must happen at runtime. |
5942 if (property->is_computed_name()) return; | 5927 if (property->is_computed_name()) return; |
5943 | 5928 |
5944 // Getter and setter names are handled here because their names | 5929 // Getter and setter names are handled here because their names |
5945 // change in ES2015, even though they are not anonymous. | 5930 // change in ES2015, even though they are not anonymous. |
5946 auto function = value->AsFunctionLiteral(); | 5931 auto function = value->AsFunctionLiteral(); |
5947 if (function != nullptr) { | 5932 if (function != nullptr) { |
5948 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER; | 5933 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER; |
5949 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER; | 5934 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER; |
5950 if (is_getter || is_setter) { | 5935 if (is_getter || is_setter) { |
5951 DCHECK_NOT_NULL(name); | 5936 DCHECK_NOT_NULL(name); |
5952 const AstRawString* prefix = | 5937 const AstRawString* prefix = |
5953 is_getter ? parser_->ast_value_factory()->get_space_string() | 5938 is_getter ? delegate()->ast_value_factory()->get_space_string() |
5954 : parser_->ast_value_factory()->set_space_string(); | 5939 : delegate()->ast_value_factory()->set_space_string(); |
5955 function->set_raw_name( | 5940 function->set_raw_name( |
5956 parser_->ast_value_factory()->NewConsString(prefix, name)); | 5941 delegate()->ast_value_factory()->NewConsString(prefix, name)); |
5957 return; | 5942 return; |
5958 } | 5943 } |
5959 } | 5944 } |
5960 | 5945 |
5961 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] | 5946 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] |
5962 // of an object literal. | 5947 // of an object literal. |
5963 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; | 5948 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; |
5964 | 5949 |
5965 DCHECK(!value->IsAnonymousFunctionDefinition() || | 5950 DCHECK(!value->IsAnonymousFunctionDefinition() || |
5966 property->kind() == ObjectLiteralProperty::COMPUTED); | 5951 property->kind() == ObjectLiteralProperty::COMPUTED); |
5967 parser_->SetFunctionName(value, name); | 5952 delegate()->SetFunctionName(value, name); |
5968 } | 5953 } |
5969 | 5954 |
5970 | 5955 void ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef( |
5971 void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value, | 5956 Expression* value, Expression* identifier) { |
5972 Expression* identifier) { | |
5973 if (!identifier->IsVariableProxy()) return; | 5957 if (!identifier->IsVariableProxy()) return; |
5974 parser_->SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); | 5958 delegate()->SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); |
5975 } | 5959 } |
5976 | 5960 |
5977 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { | 5961 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { |
5978 DCHECK_NOT_NULL(name); | 5962 DCHECK_NOT_NULL(name); |
5979 if (!value->IsAnonymousFunctionDefinition()) return; | 5963 if (!value->IsAnonymousFunctionDefinition()) return; |
5980 auto function = value->AsFunctionLiteral(); | 5964 auto function = value->AsFunctionLiteral(); |
5981 if (function != nullptr) { | 5965 if (function != nullptr) { |
5982 function->set_raw_name(name); | 5966 function->set_raw_name(name); |
5983 } else { | 5967 } else { |
5984 DCHECK(value->IsDoExpression()); | 5968 DCHECK(value->IsDoExpression()); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6917 node->Print(Isolate::Current()); | 6901 node->Print(Isolate::Current()); |
6918 } | 6902 } |
6919 #endif // DEBUG | 6903 #endif // DEBUG |
6920 | 6904 |
6921 #undef CHECK_OK | 6905 #undef CHECK_OK |
6922 #undef CHECK_OK_VOID | 6906 #undef CHECK_OK_VOID |
6923 #undef CHECK_FAILED | 6907 #undef CHECK_FAILED |
6924 | 6908 |
6925 } // namespace internal | 6909 } // namespace internal |
6926 } // namespace v8 | 6910 } // namespace v8 |
OLD | NEW |