Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: src/parsing/parser.cc

Issue 2277843002: [parser] Clean up (pre)parser traits, part 5, last (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2274113002-ref-traits
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 // Don't infer if it is "a = function(){...}();"-like expression. 2118 // Don't infer if it is "a = function(){...}();"-like expression.
2119 if (single_name) { 2119 if (single_name) {
2120 if (fni_ != NULL && value->AsCall() == NULL && 2120 if (fni_ != NULL && value->AsCall() == NULL &&
2121 value->AsCallNew() == NULL) { 2121 value->AsCallNew() == NULL) {
2122 fni_->Infer(); 2122 fni_->Infer();
2123 } else { 2123 } else {
2124 fni_->RemoveLastFunction(); 2124 fni_->RemoveLastFunction();
2125 } 2125 }
2126 } 2126 }
2127 2127
2128 ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef(value, 2128 SetFunctionNameFromIdentifierRef(value, pattern);
2129 pattern);
2130 2129
2131 // End position of the initializer is after the assignment expression. 2130 // End position of the initializer is after the assignment expression.
2132 initializer_position = scanner()->location().end_pos; 2131 initializer_position = scanner()->location().end_pos;
2133 } else { 2132 } else {
2134 // Initializers may be either required or implied unless this is a 2133 // Initializers may be either required or implied unless this is a
2135 // for-in/of iteration variable. 2134 // for-in/of iteration variable.
2136 if (var_context != kForStatement || !PeekInOrOf()) { 2135 if (var_context != kForStatement || !PeekInOrOf()) {
2137 // ES6 'const' and binding patterns require initializers. 2136 // ES6 'const' and binding patterns require initializers.
2138 if (parsing_result->descriptor.mode == CONST || 2137 if (parsing_result->descriptor.mode == CONST ||
2139 !pattern->IsVariableProxy()) { 2138 !pattern->IsVariableProxy()) {
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3551 expression->IsObjectLiteral()); 3550 expression->IsObjectLiteral());
3552 3551
3553 if (is_destructuring) { 3552 if (is_destructuring) {
3554 ValidateAssignmentPattern(&classifier, CHECK_OK); 3553 ValidateAssignmentPattern(&classifier, CHECK_OK);
3555 } else { 3554 } else {
3556 RewriteNonPattern(&classifier, CHECK_OK); 3555 RewriteNonPattern(&classifier, CHECK_OK);
3557 } 3556 }
3558 3557
3559 if (is_for_each) { 3558 if (is_for_each) {
3560 if (!is_destructuring) { 3559 if (!is_destructuring) {
3561 expression = this->CheckAndRewriteReferenceExpression( 3560 expression = CheckAndRewriteReferenceExpression(
3562 expression, lhs_beg_pos, lhs_end_pos, 3561 expression, lhs_beg_pos, lhs_end_pos,
3563 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); 3562 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK);
3564 } 3563 }
3565 3564
3566 ForEachStatement* loop = 3565 ForEachStatement* loop =
3567 factory()->NewForEachStatement(mode, labels, stmt_pos); 3566 factory()->NewForEachStatement(mode, labels, stmt_pos);
3568 Target target(&this->target_stack_, loop); 3567 Target target(&this->target_stack_, loop);
3569 3568
3570 int each_keyword_position = scanner()->location().beg_pos; 3569 int each_keyword_position = scanner()->location().beg_pos;
3571 3570
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
3842 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); 3841 Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
3843 Block* block = ParseBlock(nullptr, CHECK_OK); 3842 Block* block = ParseBlock(nullptr, CHECK_OK);
3844 DoExpression* expr = factory()->NewDoExpression(block, result, pos); 3843 DoExpression* expr = factory()->NewDoExpression(block, result, pos);
3845 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { 3844 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) {
3846 *ok = false; 3845 *ok = false;
3847 return nullptr; 3846 return nullptr;
3848 } 3847 }
3849 return expr; 3848 return expr;
3850 } 3849 }
3851 3850
3852 void ParserBaseTraits<Parser>::ParseArrowFunctionFormalParameterList( 3851 void Parser::ParseArrowFunctionFormalParameterList(
3853 ParserFormalParameters* parameters, Expression* expr, 3852 ParserFormalParameters* parameters, Expression* expr,
3854 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, 3853 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
3855 const Scope::Snapshot& scope_snapshot, bool* ok) { 3854 const Scope::Snapshot& scope_snapshot, bool* ok) {
3856 if (expr->IsEmptyParentheses()) return; 3855 if (expr->IsEmptyParentheses()) return;
3857 3856
3858 delegate()->ParseArrowFunctionFormalParameters( 3857 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos,
3859 parameters, expr, params_loc.end_pos, CHECK_OK_VOID); 3858 CHECK_OK_VOID);
3860 3859
3861 scope_snapshot.Reparent(parameters->scope); 3860 scope_snapshot.Reparent(parameters->scope);
3862 3861
3863 if (parameters->Arity() > Code::kMaxArguments) { 3862 if (parameters->Arity() > Code::kMaxArguments) {
3864 delegate()->ReportMessageAt(params_loc, 3863 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3865 MessageTemplate::kMalformedArrowFunParamList);
3866 *ok = false; 3864 *ok = false;
3867 return; 3865 return;
3868 } 3866 }
3869 3867
3870 Type::ExpressionClassifier classifier(delegate()); 3868 Type::ExpressionClassifier classifier(this);
3871 if (!parameters->is_simple) { 3869 if (!parameters->is_simple) {
3872 classifier.RecordNonSimpleParameter(); 3870 classifier.RecordNonSimpleParameter();
3873 } 3871 }
3874 for (int i = 0; i < parameters->Arity(); ++i) { 3872 for (int i = 0; i < parameters->Arity(); ++i) {
3875 auto parameter = parameters->at(i); 3873 auto parameter = parameters->at(i);
3876 DeclareFormalParameter(parameters->scope, parameter, &classifier); 3874 DeclareFormalParameter(parameters->scope, parameter, &classifier);
3877 if (!duplicate_loc->IsValid()) { 3875 if (!duplicate_loc->IsValid()) {
3878 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3876 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3879 } 3877 }
3880 } 3878 }
3881 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); 3879 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters());
3882 } 3880 }
3883 3881
3884 void ParserBaseTraits<Parser>::ReindexLiterals( 3882 void Parser::ReindexLiterals(const ParserFormalParameters& parameters) {
3885 const ParserFormalParameters& parameters) { 3883 if (function_state_->materialized_literal_count() > 0) {
3886 if (delegate()->function_state_->materialized_literal_count() > 0) {
3887 AstLiteralReindexer reindexer; 3884 AstLiteralReindexer reindexer;
3888 3885
3889 for (const auto p : parameters.params) { 3886 for (const auto p : parameters.params) {
3890 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); 3887 if (p.pattern != nullptr) reindexer.Reindex(p.pattern);
3891 if (p.initializer != nullptr) reindexer.Reindex(p.initializer); 3888 if (p.initializer != nullptr) reindexer.Reindex(p.initializer);
3892 } 3889 }
3893 3890
3894 DCHECK(reindexer.count() <= 3891 DCHECK(reindexer.count() <= function_state_->materialized_literal_count());
3895 delegate()->function_state_->materialized_literal_count());
3896 } 3892 }
3897 } 3893 }
3898 3894
3899 3895
3900 FunctionLiteral* Parser::ParseFunctionLiteral( 3896 FunctionLiteral* Parser::ParseFunctionLiteral(
3901 const AstRawString* function_name, Scanner::Location function_name_location, 3897 const AstRawString* function_name, Scanner::Location function_name_location,
3902 FunctionNameValidity function_name_validity, FunctionKind kind, 3898 FunctionNameValidity function_name_validity, FunctionKind kind,
3903 int function_token_pos, FunctionLiteral::FunctionType function_type, 3899 int function_token_pos, FunctionLiteral::FunctionType function_type,
3904 LanguageMode language_mode, bool* ok) { 3900 LanguageMode language_mode, bool* ok) {
3905 // Function :: 3901 // Function ::
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3959 3955
3960 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume 3956 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume
3961 // parenthesis before the function means that it will be called 3957 // parenthesis before the function means that it will be called
3962 // immediately). The inner function *must* be parsed eagerly to resolve the 3958 // immediately). The inner function *must* be parsed eagerly to resolve the
3963 // possible reference to the variable in foo's scope. However, it's possible 3959 // possible reference to the variable in foo's scope. However, it's possible
3964 // that it will be compiled lazily. 3960 // that it will be compiled lazily.
3965 3961
3966 // To make this additional case work, both Parser and PreParser implement a 3962 // To make this additional case work, both Parser and PreParser implement a
3967 // logic where only top-level functions will be parsed lazily. 3963 // logic where only top-level functions will be parsed lazily.
3968 bool is_lazily_parsed = mode() == PARSE_LAZILY && 3964 bool is_lazily_parsed = mode() == PARSE_LAZILY &&
3969 this->scope()->AllowsLazyParsing() && 3965 scope()->AllowsLazyParsing() &&
3970 !function_state_->next_function_is_parenthesized(); 3966 !function_state_->next_function_is_parenthesized();
3971 3967
3972 // Determine whether the function body can be discarded after parsing. 3968 // Determine whether the function body can be discarded after parsing.
3973 // The preconditions are: 3969 // The preconditions are:
3974 // - Lazy compilation has to be enabled. 3970 // - Lazy compilation has to be enabled.
3975 // - Neither V8 natives nor native function declarations can be allowed, 3971 // - Neither V8 natives nor native function declarations can be allowed,
3976 // since parsing one would retroactively force the function to be 3972 // since parsing one would retroactively force the function to be
3977 // eagerly compiled. 3973 // eagerly compiled.
3978 // - The invoker of this parser can't depend on the AST being eagerly 3974 // - The invoker of this parser can't depend on the AST being eagerly
3979 // built (either because the function is about to be compiled, or 3975 // built (either because the function is about to be compiled, or
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
4259 4255
4260 Expression* condition = factory()->NewBinaryOperation( 4256 Expression* condition = factory()->NewBinaryOperation(
4261 Token::OR, 4257 Token::OR,
4262 factory()->NewCompareOperation( 4258 factory()->NewCompareOperation(
4263 Token::EQ_STRICT, factory()->NewVariableProxy(var), 4259 Token::EQ_STRICT, factory()->NewVariableProxy(var),
4264 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), 4260 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition),
4265 factory()->NewCompareOperation( 4261 factory()->NewCompareOperation(
4266 Token::EQ_STRICT, factory()->NewVariableProxy(var), 4262 Token::EQ_STRICT, factory()->NewVariableProxy(var),
4267 factory()->NewNullLiteral(kNoSourcePosition), kNoSourcePosition), 4263 factory()->NewNullLiteral(kNoSourcePosition), kNoSourcePosition),
4268 kNoSourcePosition); 4264 kNoSourcePosition);
4269 Expression* throw_type_error = this->NewThrowTypeError( 4265 Expression* throw_type_error =
4270 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), 4266 NewThrowTypeError(MessageTemplate::kNonCoercible,
4271 kNoSourcePosition); 4267 ast_value_factory()->empty_string(), kNoSourcePosition);
4272 IfStatement* if_statement = factory()->NewIfStatement( 4268 IfStatement* if_statement = factory()->NewIfStatement(
4273 condition, 4269 condition,
4274 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition), 4270 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition),
4275 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); 4271 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition);
4276 return if_statement; 4272 return if_statement;
4277 } 4273 }
4278 4274
4279 4275
4280 class InitializerRewriter final 4276 class InitializerRewriter final
4281 : public AstTraversalVisitor<InitializerRewriter> { 4277 : public AstTraversalVisitor<InitializerRewriter> {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4533 } else if (IsAsyncFunction(kind)) { 4529 } else if (IsAsyncFunction(kind)) {
4534 const bool accept_IN = true; 4530 const bool accept_IN = true;
4535 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, 4531 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind,
4536 FunctionBodyType::kNormal, accept_IN, pos, 4532 FunctionBodyType::kNormal, accept_IN, pos,
4537 CHECK_OK); 4533 CHECK_OK);
4538 } else { 4534 } else {
4539 ParseStatementList(body, Token::RBRACE, CHECK_OK); 4535 ParseStatementList(body, Token::RBRACE, CHECK_OK);
4540 } 4536 }
4541 4537
4542 if (IsSubclassConstructor(kind)) { 4538 if (IsSubclassConstructor(kind)) {
4543 body->Add(factory()->NewReturnStatement( 4539 body->Add(factory()->NewReturnStatement(ThisExpression(kNoSourcePosition),
4544 this->ThisExpression(kNoSourcePosition), kNoSourcePosition), 4540 kNoSourcePosition),
4545 zone()); 4541 zone());
4546 } 4542 }
4547 } 4543 }
4548 4544
4549 Expect(Token::RBRACE, CHECK_OK); 4545 Expect(Token::RBRACE, CHECK_OK);
4550 scope()->set_end_position(scanner()->location().end_pos); 4546 scope()->set_end_position(scanner()->location().end_pos);
4551 4547
4552 if (!parameters.is_simple) { 4548 if (!parameters.is_simple) {
4553 DCHECK_NOT_NULL(inner_scope); 4549 DCHECK_NOT_NULL(inner_scope);
4554 DCHECK_EQ(function_scope, scope()); 4550 DCHECK_EQ(function_scope, scope());
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
5406 for (int i = 0; i < tail_call_expressions.length(); ++i) { 5402 for (int i = 0; i < tail_call_expressions.length(); ++i) {
5407 Expression* expression = tail_call_expressions[i]; 5403 Expression* expression = tail_call_expressions[i];
5408 // If only FLAG_harmony_explicit_tailcalls is enabled then expression 5404 // If only FLAG_harmony_explicit_tailcalls is enabled then expression
5409 // must be a Call expression. 5405 // must be a Call expression.
5410 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || 5406 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls ||
5411 expression->IsCall()); 5407 expression->IsCall());
5412 MarkTailPosition(expression); 5408 MarkTailPosition(expression);
5413 } 5409 }
5414 } 5410 }
5415 5411
5416 Expression* ParserBaseTraits<Parser>::ExpressionListToExpression( 5412 Expression* Parser::ExpressionListToExpression(ZoneList<Expression*>* args) {
5417 ZoneList<Expression*>* args) {
5418 AstNodeFactory* factory = delegate()->factory();
5419 Expression* expr = args->at(0); 5413 Expression* expr = args->at(0);
5420 for (int i = 1; i < args->length(); ++i) { 5414 for (int i = 1; i < args->length(); ++i) {
5421 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i), 5415 expr = factory()->NewBinaryOperation(Token::COMMA, expr, args->at(i),
5422 expr->position()); 5416 expr->position());
5423 } 5417 }
5424 return expr; 5418 return expr;
5425 } 5419 }
5426 5420
5427 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { 5421 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) {
5428 // yield %AsyncFunctionAwait(.generator_object, <operand>) 5422 // yield %AsyncFunctionAwait(.generator_object, <operand>)
5429 Variable* generator_object_variable = 5423 Variable* generator_object_variable =
5430 delegate()->function_state_->generator_object_variable(); 5424 function_state_->generator_object_variable();
5431 5425
5432 // If generator_object_variable is null, 5426 // If generator_object_variable is null,
5433 if (!generator_object_variable) return value; 5427 if (!generator_object_variable) return value;
5434 5428
5435 auto factory = delegate()->factory();
5436 const int nopos = kNoSourcePosition; 5429 const int nopos = kNoSourcePosition;
5437 5430
5438 Variable* temp_var = 5431 Variable* temp_var = NewTemporary(ast_value_factory()->empty_string());
5439 delegate()->NewTemporary(delegate()->ast_value_factory()->empty_string()); 5432 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp_var);
5440 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); 5433 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos);
5441 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
5442 5434
5443 // Wrap value evaluation to provide a break location. 5435 // Wrap value evaluation to provide a break location.
5444 Expression* value_assignment = 5436 Expression* value_assignment =
5445 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); 5437 factory()->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos);
5446 do_block->statements()->Add( 5438 do_block->statements()->Add(
5447 factory->NewExpressionStatement(value_assignment, value->position()), 5439 factory()->NewExpressionStatement(value_assignment, value->position()),
5448 zone()); 5440 zone());
5449 5441
5450 ZoneList<Expression*>* async_function_await_args = 5442 ZoneList<Expression*>* async_function_await_args =
5451 new (zone()) ZoneList<Expression*>(2, zone()); 5443 new (zone()) ZoneList<Expression*>(2, zone());
5452 Expression* generator_object = 5444 Expression* generator_object =
5453 factory->NewVariableProxy(generator_object_variable); 5445 factory()->NewVariableProxy(generator_object_variable);
5454 async_function_await_args->Add(generator_object, zone()); 5446 async_function_await_args->Add(generator_object, zone());
5455 async_function_await_args->Add(temp_proxy, zone()); 5447 async_function_await_args->Add(temp_proxy, zone());
5456 Expression* async_function_await = delegate()->factory()->NewCallRuntime( 5448 Expression* async_function_await = factory()->NewCallRuntime(
5457 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); 5449 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos);
5458 // Wrap await to provide a break location between value evaluation and yield. 5450 // Wrap await to provide a break location between value evaluation and yield.
5459 Expression* await_assignment = factory->NewAssignment( 5451 Expression* await_assignment = factory()->NewAssignment(
5460 Token::ASSIGN, temp_proxy, async_function_await, nopos); 5452 Token::ASSIGN, temp_proxy, async_function_await, nopos);
5461 do_block->statements()->Add( 5453 do_block->statements()->Add(
5462 factory->NewExpressionStatement(await_assignment, await_pos), zone()); 5454 factory()->NewExpressionStatement(await_assignment, await_pos), zone());
5463 Expression* do_expr = factory->NewDoExpression(do_block, temp_var, nopos); 5455 Expression* do_expr = factory()->NewDoExpression(do_block, temp_var, nopos);
5464 5456
5465 generator_object = factory->NewVariableProxy(generator_object_variable); 5457 generator_object = factory()->NewVariableProxy(generator_object_variable);
5466 return factory->NewYield(generator_object, do_expr, nopos, 5458 return factory()->NewYield(generator_object, do_expr, nopos,
5467 Yield::kOnExceptionRethrow); 5459 Yield::kOnExceptionRethrow);
5468 } 5460 }
5469 5461
5470 ZoneList<Expression*>* ParserBaseTraits<Parser>::GetNonPatternList() const {
5471 return delegate()->function_state_->non_patterns_to_rewrite();
5472 }
5473
5474 ZoneList<typename ParserBaseTraits<Parser>::Type::ExpressionClassifier::Error>*
5475 ParserBaseTraits<Parser>::GetReportedErrorList() const {
5476 return delegate()->function_state_->GetReportedErrorList();
5477 }
5478
5479 Zone* ParserBaseTraits<Parser>::zone() const { return delegate()->zone(); }
5480
5481 class NonPatternRewriter : public AstExpressionRewriter { 5462 class NonPatternRewriter : public AstExpressionRewriter {
5482 public: 5463 public:
5483 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) 5464 NonPatternRewriter(uintptr_t stack_limit, Parser* parser)
5484 : AstExpressionRewriter(stack_limit), parser_(parser) {} 5465 : AstExpressionRewriter(stack_limit), parser_(parser) {}
5485 ~NonPatternRewriter() override {} 5466 ~NonPatternRewriter() override {}
5486 5467
5487 private: 5468 private:
5488 bool RewriteExpression(Expression* expr) override { 5469 bool RewriteExpression(Expression* expr) override {
5489 if (expr->IsRewritableExpression()) return true; 5470 if (expr->IsRewritableExpression()) return true;
5490 // Rewrite only what could have been a pattern but is not. 5471 // Rewrite only what could have been a pattern but is not.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
5558 } 5539 }
5559 5540
5560 Expression* Parser::RewriteAssignExponentiation(Expression* left, 5541 Expression* Parser::RewriteAssignExponentiation(Expression* left,
5561 Expression* right, int pos) { 5542 Expression* right, int pos) {
5562 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); 5543 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
5563 if (left->IsVariableProxy()) { 5544 if (left->IsVariableProxy()) {
5564 VariableProxy* lhs = left->AsVariableProxy(); 5545 VariableProxy* lhs = left->AsVariableProxy();
5565 5546
5566 Expression* result; 5547 Expression* result;
5567 DCHECK_NOT_NULL(lhs->raw_name()); 5548 DCHECK_NOT_NULL(lhs->raw_name());
5568 result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), 5549 result = ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
5569 lhs->end_position()); 5550 lhs->end_position());
5570 args->Add(left, zone()); 5551 args->Add(left, zone());
5571 args->Add(right, zone()); 5552 args->Add(right, zone());
5572 Expression* call = 5553 Expression* call =
5573 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos); 5554 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos);
5574 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); 5555 return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
5575 } else if (left->IsProperty()) { 5556 } else if (left->IsProperty()) {
5576 Property* prop = left->AsProperty(); 5557 Property* prop = left->AsProperty();
5577 auto temp_obj = NewTemporary(ast_value_factory()->empty_string()); 5558 auto temp_obj = NewTemporary(ast_value_factory()->empty_string());
5578 auto temp_key = NewTemporary(ast_value_factory()->empty_string()); 5559 auto temp_key = NewTemporary(ast_value_factory()->empty_string());
5579 Expression* assign_obj = factory()->NewAssignment( 5560 Expression* assign_obj = factory()->NewAssignment(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
5671 } 5652 }
5672 // Now, rewind the original array literal to truncate everything from the 5653 // Now, rewind the original array literal to truncate everything from the
5673 // first spread (included) until the end. This fixes $R's initialization. 5654 // first spread (included) until the end. This fixes $R's initialization.
5674 lit->RewindSpreads(); 5655 lit->RewindSpreads();
5675 return factory()->NewDoExpression(do_block, result, lit->position()); 5656 return factory()->NewDoExpression(do_block, result, lit->position());
5676 } 5657 }
5677 5658
5678 void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) { 5659 void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) {
5679 DCHECK(expr->IsRewritableExpression()); 5660 DCHECK(expr->IsRewritableExpression());
5680 function_state_->AddDestructuringAssignment( 5661 function_state_->AddDestructuringAssignment(
5681 DestructuringAssignment(expr, delegate()->scope())); 5662 DestructuringAssignment(expr, scope()));
5682 } 5663 }
5683 5664
5684 void Parser::QueueNonPatternForRewriting(Expression* expr, bool* ok) { 5665 void Parser::QueueNonPatternForRewriting(Expression* expr, bool* ok) {
5685 DCHECK(expr->IsRewritableExpression()); 5666 DCHECK(expr->IsRewritableExpression());
5686 function_state_->AddNonPatternForRewriting(expr, ok); 5667 function_state_->AddNonPatternForRewriting(expr, ok);
5687 } 5668 }
5688 5669
5689 void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName( 5670 void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
5690 ObjectLiteralProperty* property, const AstRawString* name) { 5671 const AstRawString* name) {
5691 Expression* value = property->value(); 5672 Expression* value = property->value();
5692 5673
5693 // Computed name setting must happen at runtime. 5674 // Computed name setting must happen at runtime.
5694 if (property->is_computed_name()) return; 5675 if (property->is_computed_name()) return;
5695 5676
5696 // Getter and setter names are handled here because their names 5677 // Getter and setter names are handled here because their names
5697 // change in ES2015, even though they are not anonymous. 5678 // change in ES2015, even though they are not anonymous.
5698 auto function = value->AsFunctionLiteral(); 5679 auto function = value->AsFunctionLiteral();
5699 if (function != nullptr) { 5680 if (function != nullptr) {
5700 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER; 5681 bool is_getter = property->kind() == ObjectLiteralProperty::GETTER;
5701 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER; 5682 bool is_setter = property->kind() == ObjectLiteralProperty::SETTER;
5702 if (is_getter || is_setter) { 5683 if (is_getter || is_setter) {
5703 DCHECK_NOT_NULL(name); 5684 DCHECK_NOT_NULL(name);
5704 const AstRawString* prefix = 5685 const AstRawString* prefix =
5705 is_getter ? delegate()->ast_value_factory()->get_space_string() 5686 is_getter ? ast_value_factory()->get_space_string()
5706 : delegate()->ast_value_factory()->set_space_string(); 5687 : ast_value_factory()->set_space_string();
5707 function->set_raw_name( 5688 function->set_raw_name(ast_value_factory()->NewConsString(prefix, name));
5708 delegate()->ast_value_factory()->NewConsString(prefix, name));
5709 return; 5689 return;
5710 } 5690 }
5711 } 5691 }
5712 5692
5713 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] 5693 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
5714 // of an object literal. 5694 // of an object literal.
5715 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; 5695 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return;
5716 5696
5717 DCHECK(!value->IsAnonymousFunctionDefinition() || 5697 DCHECK(!value->IsAnonymousFunctionDefinition() ||
5718 property->kind() == ObjectLiteralProperty::COMPUTED); 5698 property->kind() == ObjectLiteralProperty::COMPUTED);
5719 delegate()->SetFunctionName(value, name); 5699 SetFunctionName(value, name);
5720 } 5700 }
5721 5701
5722 void ParserBaseTraits<Parser>::SetFunctionNameFromIdentifierRef( 5702 void Parser::SetFunctionNameFromIdentifierRef(Expression* value,
5723 Expression* value, Expression* identifier) { 5703 Expression* identifier) {
5724 if (!identifier->IsVariableProxy()) return; 5704 if (!identifier->IsVariableProxy()) return;
5725 delegate()->SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); 5705 SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
5726 } 5706 }
5727 5707
5728 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { 5708 void Parser::SetFunctionName(Expression* value, const AstRawString* name) {
5729 DCHECK_NOT_NULL(name); 5709 DCHECK_NOT_NULL(name);
5730 if (!value->IsAnonymousFunctionDefinition()) return; 5710 if (!value->IsAnonymousFunctionDefinition()) return;
5731 auto function = value->AsFunctionLiteral(); 5711 auto function = value->AsFunctionLiteral();
5732 if (function != nullptr) { 5712 if (function != nullptr) {
5733 function->set_raw_name(name); 5713 function->set_raw_name(name);
5734 } else { 5714 } else {
5735 DCHECK(value->IsDoExpression()); 5715 DCHECK(value->IsDoExpression());
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
6668 node->Print(Isolate::Current()); 6648 node->Print(Isolate::Current());
6669 } 6649 }
6670 #endif // DEBUG 6650 #endif // DEBUG
6671 6651
6672 #undef CHECK_OK 6652 #undef CHECK_OK
6673 #undef CHECK_OK_VOID 6653 #undef CHECK_OK_VOID
6674 #undef CHECK_FAILED 6654 #undef CHECK_FAILED
6675 6655
6676 } // namespace internal 6656 } // namespace internal
6677 } // namespace v8 6657 } // namespace v8
OLDNEW
« src/parsing/parser.h ('K') | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698