Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3497 // Populate function scope with the formal parameters. Since in this case | 3497 // Populate function scope with the formal parameters. Since in this case |
| 3498 // we are compiling a getter this will at most populate the receiver. | 3498 // we are compiling a getter this will at most populate the receiver. |
| 3499 AddFormalParamsToScope(¶ms, current_block_->scope); | 3499 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3500 } else if (func.IsAsyncClosure()) { | 3500 } else if (func.IsAsyncClosure()) { |
| 3501 AddAsyncClosureParameters(¶ms); | 3501 AddAsyncClosureParameters(¶ms); |
| 3502 SetupDefaultsForOptionalParams(params); | 3502 SetupDefaultsForOptionalParams(params); |
| 3503 AddFormalParamsToScope(¶ms, current_block_->scope); | 3503 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3504 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3504 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
| 3505 ASSERT(func.NumParameters() == params.parameters->length()); | 3505 ASSERT(func.NumParameters() == params.parameters->length()); |
| 3506 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { | 3506 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { |
| 3507 // Parse and discard any formal parameters. They are accessed as | 3507 // Skip formal parameters. They are accessed as context variables. |
| 3508 // context variables. | 3508 // Parsing them again (and discarding them) does not work in case of |
| 3509 ParamList discarded_params; | 3509 // default values with same name as already parsed formal parameter. |
| 3510 ParseFormalParameterList(allow_explicit_default_values, | 3510 SkipToMatchingParenthesis(); |
| 3511 false, | |
| 3512 &discarded_params); | |
| 3513 } | 3511 } |
| 3514 } else if (func.IsSyncGenClosure()) { | 3512 } else if (func.IsSyncGenClosure()) { |
| 3515 AddSyncGenClosureParameters(¶ms); | 3513 AddSyncGenClosureParameters(¶ms); |
| 3516 SetupDefaultsForOptionalParams(params); | 3514 SetupDefaultsForOptionalParams(params); |
| 3517 AddFormalParamsToScope(¶ms, current_block_->scope); | 3515 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3518 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3516 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
| 3519 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { | 3517 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { |
| 3520 // Parse and discard any formal parameters. They are accessed as | 3518 // Skip formal parameters. They are accessed as context variables. |
| 3521 // context variables. | 3519 // Parsing them again (and discarding them) does not work in case of |
| 3522 ParamList discarded_params; | 3520 // default values with same name as already parsed formal parameter. |
| 3523 ParseFormalParameterList(allow_explicit_default_values, | 3521 SkipToMatchingParenthesis(); |
| 3524 false, | |
| 3525 &discarded_params); | |
| 3526 } | 3522 } |
| 3527 } else if (func.IsAsyncGenClosure()) { | 3523 } else if (func.IsAsyncGenClosure()) { |
| 3528 AddAsyncGenClosureParameters(¶ms); | 3524 AddAsyncGenClosureParameters(¶ms); |
| 3529 SetupDefaultsForOptionalParams(params); | 3525 SetupDefaultsForOptionalParams(params); |
| 3530 AddFormalParamsToScope(¶ms, current_block_->scope); | 3526 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3531 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3527 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
| 3532 ASSERT(func.NumParameters() == params.parameters->length()); | 3528 ASSERT(func.NumParameters() == params.parameters->length()); |
| 3533 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { | 3529 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { |
| 3534 // Parse and discard any formal parameters. They are accessed as | 3530 // Skip formal parameters. They are accessed as context variables. |
| 3535 // context variables. | 3531 // Parsing them again (and discarding them) does not work in case of |
| 3536 ParamList discarded_params; | 3532 // default values with same name as already parsed formal parameter. |
| 3537 ParseFormalParameterList(allow_explicit_default_values, | 3533 SkipToMatchingParenthesis(); |
| 3538 false, | |
| 3539 &discarded_params); | |
| 3540 } | 3534 } |
| 3541 } else { | 3535 } else { |
| 3542 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 3536 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 3543 | 3537 |
| 3544 // The number of parameters and their type are not yet set in local | 3538 // The number of parameters and their type are not yet set in local |
| 3545 // functions, since they are not 'top-level' parsed. | 3539 // functions, since they are not 'top-level' parsed. |
| 3546 // However, they are already set when the local function is compiled, since | 3540 // However, they are already set when the local function is compiled, since |
| 3547 // the local function was parsed when its parent was compiled. | 3541 // the local function was parsed when its parent was compiled. |
| 3548 if (func.parameter_types() == Object::empty_array().raw()) { | 3542 if (func.parameter_types() == Object::empty_array().raw()) { |
| 3549 AddFormalParamsToFunction(¶ms, func); | 3543 AddFormalParamsToFunction(¶ms, func); |
| (...skipping 7694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11244 } | 11238 } |
| 11245 | 11239 |
| 11246 | 11240 |
| 11247 // Evaluates the value of the compile time constant expression | 11241 // Evaluates the value of the compile time constant expression |
| 11248 // and returns a literal node for the value. | 11242 // and returns a literal node for the value. |
| 11249 LiteralNode* Parser::FoldConstExpr(TokenPosition expr_pos, AstNode* expr) { | 11243 LiteralNode* Parser::FoldConstExpr(TokenPosition expr_pos, AstNode* expr) { |
| 11250 if (expr->IsLiteralNode()) { | 11244 if (expr->IsLiteralNode()) { |
| 11251 return expr->AsLiteralNode(); | 11245 return expr->AsLiteralNode(); |
| 11252 } | 11246 } |
| 11253 if (expr->EvalConstExpr() == NULL) { | 11247 if (expr->EvalConstExpr() == NULL) { |
| 11248 // DEBUG | |
| 11249 expr->EvalConstExpr(); | |
|
hausner
2016/10/25 15:04:55
Why do you evaluate the expression a second time?
regis
2016/10/25 15:08:46
Oops. Let's blame it on the jetlag.
Removed. Thank
| |
| 11254 ReportError(expr_pos, "expression is not a valid compile-time constant"); | 11250 ReportError(expr_pos, "expression is not a valid compile-time constant"); |
| 11255 } | 11251 } |
| 11256 return new(Z) LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); | 11252 return new(Z) LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); |
| 11257 } | 11253 } |
| 11258 | 11254 |
| 11259 | 11255 |
| 11260 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { | 11256 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { |
| 11261 AstNode* node = *expr; | 11257 AstNode* node = *expr; |
| 11262 TokenPosition token_pos = node->token_pos(); | 11258 TokenPosition token_pos = node->token_pos(); |
| 11263 LetNode* result = new(Z) LetNode(token_pos); | 11259 LetNode* result = new(Z) LetNode(token_pos); |
| (...skipping 3431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14695 | 14691 |
| 14696 | 14692 |
| 14697 void Parser::SkipFunctionLiteral() { | 14693 void Parser::SkipFunctionLiteral() { |
| 14698 if (IsIdentifier()) { | 14694 if (IsIdentifier()) { |
| 14699 if (LookaheadToken(1) != Token::kLPAREN) { | 14695 if (LookaheadToken(1) != Token::kLPAREN) { |
| 14700 SkipType(true); | 14696 SkipType(true); |
| 14701 } | 14697 } |
| 14702 ExpectIdentifier("function name expected"); | 14698 ExpectIdentifier("function name expected"); |
| 14703 } | 14699 } |
| 14704 if (CurrentToken() == Token::kLPAREN) { | 14700 if (CurrentToken() == Token::kLPAREN) { |
| 14705 const bool allow_explicit_default_values = true; | 14701 SkipToMatchingParenthesis(); |
| 14706 ParamList params; | |
| 14707 params.skipped = true; | |
| 14708 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | |
| 14709 } | 14702 } |
| 14710 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier(); | 14703 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier(); |
| 14711 BoolScope allow_await(&this->await_is_keyword_, | 14704 BoolScope allow_await(&this->await_is_keyword_, |
| 14712 async_modifier != RawFunction::kNoModifier); | 14705 async_modifier != RawFunction::kNoModifier); |
| 14713 if (CurrentToken() == Token::kLBRACE) { | 14706 if (CurrentToken() == Token::kLBRACE) { |
| 14714 SkipBlock(); | 14707 SkipBlock(); |
| 14715 ExpectToken(Token::kRBRACE); | 14708 ExpectToken(Token::kRBRACE); |
| 14716 } else if (CurrentToken() == Token::kARROW) { | 14709 } else if (CurrentToken() == Token::kARROW) { |
| 14717 ConsumeToken(); | 14710 ConsumeToken(); |
| 14718 SkipExpr(); | 14711 SkipExpr(); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15154 const ArgumentListNode& function_args, | 15147 const ArgumentListNode& function_args, |
| 15155 const LocalVariable* temp_for_last_arg, | 15148 const LocalVariable* temp_for_last_arg, |
| 15156 bool is_super_invocation) { | 15149 bool is_super_invocation) { |
| 15157 UNREACHABLE(); | 15150 UNREACHABLE(); |
| 15158 return NULL; | 15151 return NULL; |
| 15159 } | 15152 } |
| 15160 | 15153 |
| 15161 } // namespace dart | 15154 } // namespace dart |
| 15162 | 15155 |
| 15163 #endif // DART_PRECOMPILED_RUNTIME | 15156 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |