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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 786 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
779 set_allow_harmony_sloppy(FLAG_harmony_sloppy); | 787 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
780 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); | 788 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); |
781 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 789 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
782 set_allow_legacy_const(FLAG_legacy_const); | 790 set_allow_legacy_const(FLAG_legacy_const); |
783 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 791 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
784 set_allow_harmony_function_name(FLAG_harmony_function_name); | 792 set_allow_harmony_function_name(FLAG_harmony_function_name); |
785 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 793 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
786 set_allow_harmony_restrictive_declarations( | 794 set_allow_harmony_restrictive_declarations( |
787 FLAG_harmony_restrictive_declarations); | 795 FLAG_harmony_restrictive_declarations); |
796 set_allow_harmony_exponentiation_operator( | |
797 FLAG_harmony_exponentiation_operator); | |
788 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 798 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
789 ++feature) { | 799 ++feature) { |
790 use_counts_[feature] = 0; | 800 use_counts_[feature] = 0; |
791 } | 801 } |
792 if (info->ast_value_factory() == NULL) { | 802 if (info->ast_value_factory() == NULL) { |
793 // info takes ownership of AstValueFactory. | 803 // info takes ownership of AstValueFactory. |
794 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 804 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
795 info->set_ast_value_factory_owned(); | 805 info->set_ast_value_factory_owned(); |
796 ast_value_factory_ = info->ast_value_factory(); | 806 ast_value_factory_ = info->ast_value_factory(); |
797 } | 807 } |
(...skipping 3875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4673 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | 4683 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), |
4674 NULL, stack_limit_); | 4684 NULL, stack_limit_); |
4675 reusable_preparser_->set_allow_lazy(true); | 4685 reusable_preparser_->set_allow_lazy(true); |
4676 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 4686 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
4677 SET_ALLOW(natives); | 4687 SET_ALLOW(natives); |
4678 SET_ALLOW(harmony_sloppy); | 4688 SET_ALLOW(harmony_sloppy); |
4679 SET_ALLOW(harmony_sloppy_let); | 4689 SET_ALLOW(harmony_sloppy_let); |
4680 SET_ALLOW(harmony_do_expressions); | 4690 SET_ALLOW(harmony_do_expressions); |
4681 SET_ALLOW(harmony_function_name); | 4691 SET_ALLOW(harmony_function_name); |
4682 SET_ALLOW(harmony_function_sent); | 4692 SET_ALLOW(harmony_function_sent); |
4693 SET_ALLOW(harmony_exponentiation_operator); | |
4683 #undef SET_ALLOW | 4694 #undef SET_ALLOW |
4684 } | 4695 } |
4685 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4696 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4686 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4697 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4687 logger, bookmark); | 4698 logger, bookmark); |
4688 if (pre_parse_timer_ != NULL) { | 4699 if (pre_parse_timer_ != NULL) { |
4689 pre_parse_timer_->Stop(); | 4700 pre_parse_timer_->Stop(); |
4690 } | 4701 } |
4691 return result; | 4702 return result; |
4692 } | 4703 } |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5363 void Parser::RaiseLanguageMode(LanguageMode mode) { | 5374 void Parser::RaiseLanguageMode(LanguageMode mode) { |
5364 LanguageMode old = scope_->language_mode(); | 5375 LanguageMode old = scope_->language_mode(); |
5365 SetLanguageMode(scope_, old > mode ? old : mode); | 5376 SetLanguageMode(scope_, old > mode ? old : mode); |
5366 } | 5377 } |
5367 | 5378 |
5368 | 5379 |
5369 void ParserTraits::RewriteDestructuringAssignments() { | 5380 void ParserTraits::RewriteDestructuringAssignments() { |
5370 parser_->RewriteDestructuringAssignments(); | 5381 parser_->RewriteDestructuringAssignments(); |
5371 } | 5382 } |
5372 | 5383 |
5384 Expression* ParserTraits::RewriteExponentiation(Expression* left, | |
5385 Expression* right, int pos) { | |
5386 return parser_->RewriteExponentiation(left, right, pos); | |
5387 } | |
5388 | |
5389 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left, | |
5390 Expression* right, | |
5391 int pos) { | |
5392 return parser_->RewriteAssignExponentiation(left, right, pos); | |
5393 } | |
5373 | 5394 |
5374 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5395 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
5375 bool* ok) { | 5396 bool* ok) { |
5376 parser_->RewriteNonPattern(classifier, ok); | 5397 parser_->RewriteNonPattern(classifier, ok); |
5377 } | 5398 } |
5378 | 5399 |
5379 | 5400 |
5380 Zone* ParserTraits::zone() const { | 5401 Zone* ParserTraits::zone() const { |
5381 return parser_->function_state_->scope()->zone(); | 5402 return parser_->function_state_->scope()->zone(); |
5382 } | 5403 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5452 RewritableExpression* to_rewrite = | 5473 RewritableExpression* to_rewrite = |
5453 pair.assignment->AsRewritableExpression(); | 5474 pair.assignment->AsRewritableExpression(); |
5454 DCHECK_NOT_NULL(to_rewrite); | 5475 DCHECK_NOT_NULL(to_rewrite); |
5455 if (!to_rewrite->is_rewritten()) { | 5476 if (!to_rewrite->is_rewritten()) { |
5456 PatternRewriter::RewriteDestructuringAssignment(this, to_rewrite, | 5477 PatternRewriter::RewriteDestructuringAssignment(this, to_rewrite, |
5457 pair.scope); | 5478 pair.scope); |
5458 } | 5479 } |
5459 } | 5480 } |
5460 } | 5481 } |
5461 | 5482 |
5483 Expression* Parser::RewriteExponentiation(Expression* left, Expression* right, | |
5484 int pos) { | |
5485 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | |
5486 args->Add(left, zone()); | |
5487 args->Add(right, zone()); | |
5488 return factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5489 } | |
5490 | |
5491 Expression* Parser::RewriteAssignExponentiation(Expression* left, | |
5492 Expression* right, int pos) { | |
5493 // TODO(compilers): Use register rather than temp variable to hold base ref, | |
5494 // avoid ToNumber() when possible (the common cases). | |
Dan Ehrenberg
2016/03/15 01:00:56
Please remove this TODO.
caitp (gmail)
2016/03/15 01:03:04
Done, but I think this is something that should be
| |
5495 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | |
5496 if (left->IsVariableProxy()) { | |
5497 VariableProxy* lhs = left->AsVariableProxy(); | |
5498 | |
5499 Expression* result; | |
5500 DCHECK_NOT_NULL(lhs->raw_name()); | |
5501 result = | |
5502 this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), | |
5503 lhs->end_position(), scope_, factory()); | |
5504 args->Add(left, zone()); | |
5505 args->Add(right, zone()); | |
5506 Expression* call = | |
5507 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5508 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); | |
5509 } else if (left->IsProperty()) { | |
5510 Property* prop = left->AsProperty(); | |
5511 auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); | |
5512 auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); | |
5513 Expression* assign_obj = factory()->NewAssignment( | |
5514 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), | |
5515 RelocInfo::kNoPosition); | |
5516 Expression* assign_key = factory()->NewAssignment( | |
5517 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(), | |
5518 RelocInfo::kNoPosition); | |
5519 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj), | |
5520 factory()->NewVariableProxy(temp_key), | |
5521 left->position()), | |
5522 zone()); | |
5523 args->Add(right, zone()); | |
5524 Expression* call = | |
5525 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | |
5526 Expression* target = factory()->NewProperty( | |
5527 factory()->NewVariableProxy(temp_obj), | |
5528 factory()->NewVariableProxy(temp_key), RelocInfo::kNoPosition); | |
5529 Expression* assign = | |
5530 factory()->NewAssignment(Token::ASSIGN, target, call, pos); | |
5531 return factory()->NewBinaryOperation( | |
5532 Token::COMMA, assign_obj, | |
5533 factory()->NewBinaryOperation(Token::COMMA, assign_key, assign, pos), | |
5534 pos); | |
5535 } | |
5536 UNREACHABLE(); | |
5537 return nullptr; | |
5538 } | |
5462 | 5539 |
5463 Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { | 5540 Expression* Parser::RewriteSpreads(ArrayLiteral* lit) { |
5464 // Array literals containing spreads are rewritten using do expressions, e.g. | 5541 // Array literals containing spreads are rewritten using do expressions, e.g. |
5465 // [1, 2, 3, ...x, 4, ...y, 5] | 5542 // [1, 2, 3, ...x, 4, ...y, 5] |
5466 // is roughly rewritten as: | 5543 // is roughly rewritten as: |
5467 // do { | 5544 // do { |
5468 // $R = [1, 2, 3]; | 5545 // $R = [1, 2, 3]; |
5469 // for ($i of x) %AppendElement($R, $i); | 5546 // for ($i of x) %AppendElement($R, $i); |
5470 // %AppendElement($R, 4); | 5547 // %AppendElement($R, 4); |
5471 // for ($j of y) %AppendElement($R, $j); | 5548 // for ($j of y) %AppendElement($R, $j); |
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6783 try_block, target); | 6860 try_block, target); |
6784 final_loop = target; | 6861 final_loop = target; |
6785 } | 6862 } |
6786 | 6863 |
6787 return final_loop; | 6864 return final_loop; |
6788 } | 6865 } |
6789 | 6866 |
6790 | 6867 |
6791 } // namespace internal | 6868 } // namespace internal |
6792 } // namespace v8 | 6869 } // namespace v8 |
OLD | NEW |