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 "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 uint32_t value = DoubleToUint32(x_val) >> shift; | 432 uint32_t value = DoubleToUint32(x_val) >> shift; |
433 *x = factory->NewNumberLiteral(value, pos, has_dot); | 433 *x = factory->NewNumberLiteral(value, pos, has_dot); |
434 return true; | 434 return true; |
435 } | 435 } |
436 case Token::SAR: { | 436 case Token::SAR: { |
437 uint32_t shift = DoubleToInt32(y_val) & 0x1f; | 437 uint32_t shift = DoubleToInt32(y_val) & 0x1f; |
438 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); | 438 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); |
439 *x = factory->NewNumberLiteral(value, pos, has_dot); | 439 *x = factory->NewNumberLiteral(value, pos, has_dot); |
440 return true; | 440 return true; |
441 } | 441 } |
442 case Token::EXP: { | |
443 double value = std::pow(x_val, y_val); | |
444 int int_value = static_cast<int>(value); | |
445 *x = factory->NewNumberLiteral( | |
446 int_value == value && value != -0.0 ? int_value : value, pos, | |
447 has_dot); | |
448 return true; | |
449 } | |
442 default: | 450 default: |
443 break; | 451 break; |
444 } | 452 } |
445 } | 453 } |
446 return false; | 454 return false; |
447 } | 455 } |
448 | 456 |
449 | 457 |
450 Expression* ParserTraits::BuildUnaryExpression(Expression* expression, | 458 Expression* ParserTraits::BuildUnaryExpression(Expression* expression, |
451 Token::Value op, int pos, | 459 Token::Value op, int pos, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 775 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
768 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); | 776 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); |
769 set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind); | 777 set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind); |
770 set_allow_harmony_destructuring_assignment( | 778 set_allow_harmony_destructuring_assignment( |
771 FLAG_harmony_destructuring_assignment); | 779 FLAG_harmony_destructuring_assignment); |
772 set_allow_strong_mode(FLAG_strong_mode); | 780 set_allow_strong_mode(FLAG_strong_mode); |
773 set_allow_legacy_const(FLAG_legacy_const); | 781 set_allow_legacy_const(FLAG_legacy_const); |
774 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 782 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
775 set_allow_harmony_function_name(FLAG_harmony_function_name); | 783 set_allow_harmony_function_name(FLAG_harmony_function_name); |
776 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 784 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
785 set_allow_harmony_exponentiation_operator( | |
786 FLAG_harmony_exponentiation_operator); | |
777 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 787 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
778 ++feature) { | 788 ++feature) { |
779 use_counts_[feature] = 0; | 789 use_counts_[feature] = 0; |
780 } | 790 } |
781 if (info->ast_value_factory() == NULL) { | 791 if (info->ast_value_factory() == NULL) { |
782 // info takes ownership of AstValueFactory. | 792 // info takes ownership of AstValueFactory. |
783 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 793 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
784 info->set_ast_value_factory_owned(); | 794 info->set_ast_value_factory_owned(); |
785 ast_value_factory_ = info->ast_value_factory(); | 795 ast_value_factory_ = info->ast_value_factory(); |
786 } | 796 } |
(...skipping 4035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4822 SET_ALLOW(natives); | 4832 SET_ALLOW(natives); |
4823 SET_ALLOW(harmony_sloppy); | 4833 SET_ALLOW(harmony_sloppy); |
4824 SET_ALLOW(harmony_sloppy_let); | 4834 SET_ALLOW(harmony_sloppy_let); |
4825 SET_ALLOW(harmony_default_parameters); | 4835 SET_ALLOW(harmony_default_parameters); |
4826 SET_ALLOW(harmony_destructuring_bind); | 4836 SET_ALLOW(harmony_destructuring_bind); |
4827 SET_ALLOW(harmony_destructuring_assignment); | 4837 SET_ALLOW(harmony_destructuring_assignment); |
4828 SET_ALLOW(strong_mode); | 4838 SET_ALLOW(strong_mode); |
4829 SET_ALLOW(harmony_do_expressions); | 4839 SET_ALLOW(harmony_do_expressions); |
4830 SET_ALLOW(harmony_function_name); | 4840 SET_ALLOW(harmony_function_name); |
4831 SET_ALLOW(harmony_function_sent); | 4841 SET_ALLOW(harmony_function_sent); |
4842 SET_ALLOW(harmony_exponentiation_operator); | |
4832 #undef SET_ALLOW | 4843 #undef SET_ALLOW |
4833 } | 4844 } |
4834 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4845 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4835 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4846 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4836 logger, bookmark); | 4847 logger, bookmark); |
4837 if (pre_parse_timer_ != NULL) { | 4848 if (pre_parse_timer_ != NULL) { |
4838 pre_parse_timer_->Stop(); | 4849 pre_parse_timer_->Stop(); |
4839 } | 4850 } |
4840 return result; | 4851 return result; |
4841 } | 4852 } |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5521 void Parser::RaiseLanguageMode(LanguageMode mode) { | 5532 void Parser::RaiseLanguageMode(LanguageMode mode) { |
5522 SetLanguageMode(scope_, | 5533 SetLanguageMode(scope_, |
5523 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 5534 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
5524 } | 5535 } |
5525 | 5536 |
5526 | 5537 |
5527 void ParserTraits::RewriteDestructuringAssignments() { | 5538 void ParserTraits::RewriteDestructuringAssignments() { |
5528 parser_->RewriteDestructuringAssignments(); | 5539 parser_->RewriteDestructuringAssignments(); |
5529 } | 5540 } |
5530 | 5541 |
5542 Expression* ParserTraits::RewriteExponentiation(Expression* left, | |
5543 Expression* right, | |
5544 Token::Value op, int pos) { | |
5545 return parser_->RewriteExponentiation(left, right, op, pos); | |
5546 } | |
5531 | 5547 |
5532 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5548 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
5533 bool* ok) { | 5549 bool* ok) { |
5534 parser_->RewriteNonPattern(classifier, ok); | 5550 parser_->RewriteNonPattern(classifier, ok); |
5535 } | 5551 } |
5536 | 5552 |
5537 | 5553 |
5538 Zone* ParserTraits::zone() const { | 5554 Zone* ParserTraits::zone() const { |
5539 return parser_->function_state_->scope()->zone(); | 5555 return parser_->function_state_->scope()->zone(); |
5540 } | 5556 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5611 RewritableExpression* to_rewrite = | 5627 RewritableExpression* to_rewrite = |
5612 pair.assignment->AsRewritableExpression(); | 5628 pair.assignment->AsRewritableExpression(); |
5613 DCHECK_NOT_NULL(to_rewrite); | 5629 DCHECK_NOT_NULL(to_rewrite); |
5614 if (!to_rewrite->is_rewritten()) { | 5630 if (!to_rewrite->is_rewritten()) { |
5615 PatternRewriter::RewriteDestructuringAssignment(this, to_rewrite, | 5631 PatternRewriter::RewriteDestructuringAssignment(this, to_rewrite, |
5616 pair.scope); | 5632 pair.scope); |
5617 } | 5633 } |
5618 } | 5634 } |
5619 } | 5635 } |
5620 | 5636 |
5637 Expression* Parser::RewriteExponentiation(Expression* left, Expression* right, | |
5638 Token::Value op, int pos) { | |
5639 // TODO(bmeurer): remove rewriting craziness and replace with | |
5640 // backend support for exponent op, some day | |
5641 if (op == Token::EXP) { | |
Dan Ehrenberg
2016/02/25 19:17:41
Callers already know whether they are doing EXP or
caitp (gmail)
2016/03/11 15:54:19
Done.
| |
5642 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | |
5643 args->Add(left, zone()); | |
5644 args->Add(right, zone()); | |
5645 return factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5646 } | |
5647 | |
5648 DCHECK_EQ(op, Token::ASSIGN_EXP); | |
5649 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | |
5650 if (left->IsVariableProxy()) { | |
5651 VariableProxy* lhs = left->AsVariableProxy(); | |
5652 | |
5653 Expression* result; | |
5654 DCHECK_NOT_NULL(lhs->raw_name()); | |
5655 result = | |
5656 this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), | |
5657 lhs->end_position(), scope_, factory()); | |
5658 args->Add(left, zone()); | |
5659 args->Add(right, zone()); | |
5660 Expression* call = | |
5661 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5662 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); | |
5663 } else if (left->IsProperty()) { | |
5664 Property* prop = left->AsProperty(); | |
5665 auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); | |
5666 auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); | |
5667 Expression* assign_obj = factory()->NewAssignment( | |
5668 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), | |
5669 RelocInfo::kNoPosition); | |
5670 Expression* assign_key = factory()->NewAssignment( | |
5671 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(), | |
5672 RelocInfo::kNoPosition); | |
5673 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj), | |
5674 factory()->NewVariableProxy(temp_key), | |
5675 left->position()), | |
5676 zone()); | |
5677 args->Add(right, zone()); | |
5678 Expression* call = | |
5679 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5680 Expression* assign = | |
5681 factory()->NewAssignment(Token::ASSIGN, left, call, pos); | |
5682 return factory()->NewBinaryOperation( | |
5683 Token::COMMA, assign_obj, | |
5684 factory()->NewBinaryOperation(Token::COMMA, assign_key, assign, pos), | |
5685 pos); | |
5686 } else { | |
5687 return factory()->NewAssignment(Token::ASSIGN_MUL, left, right, pos); | |
Dan Ehrenberg
2016/02/25 19:17:41
This should be unreachable because of the check pr
caitp (gmail)
2016/03/11 15:54:19
Done.
| |
5688 } | |
5689 } | |
5621 | 5690 |
5622 Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { | 5691 Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { |
5623 // Array literals containing spreads are rewritten using do expressions, e.g. | 5692 // Array literals containing spreads are rewritten using do expressions, e.g. |
5624 // [1, 2, 3, ...x, 4, ...y, 5] | 5693 // [1, 2, 3, ...x, 4, ...y, 5] |
5625 // is roughly rewritten as: | 5694 // is roughly rewritten as: |
5626 // do { | 5695 // do { |
5627 // $R = [1, 2, 3]; | 5696 // $R = [1, 2, 3]; |
5628 // for ($i of x) %AppendElement($R, $i); | 5697 // for ($i of x) %AppendElement($R, $i); |
5629 // %AppendElement($R, 4); | 5698 // %AppendElement($R, 4); |
5630 // for ($j of y) %AppendElement($R, $j); | 5699 // for ($j of y) %AppendElement($R, $j); |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6932 Expression* do_each = | 7001 Expression* do_each = |
6933 factory->NewDoExpression(new_assign_each, var_each, nopos); | 7002 factory->NewDoExpression(new_assign_each, var_each, nopos); |
6934 loop->set_assign_each(do_each); | 7003 loop->set_assign_each(do_each); |
6935 | 7004 |
6936 return final_loop; | 7005 return final_loop; |
6937 } | 7006 } |
6938 | 7007 |
6939 | 7008 |
6940 } // namespace internal | 7009 } // namespace internal |
6941 } // namespace v8 | 7010 } // namespace v8 |
OLD | NEW |