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

Side by Side Diff: runtime/vm/parser.cc

Issue 8893008: Helper ast node sequences must not wrongly grab ownership of the enclosing (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/opt_code_generator_ia32.cc ('k') | tests/language/src/Closure2Test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 (follower != Token::kIDENT) && // Variable name following a type. 3599 (follower != Token::kIDENT) && // Variable name following a type.
3600 (follower != Token::kTHIS)) { // Field parameter following a type. 3600 (follower != Token::kTHIS)) { // Field parameter following a type.
3601 return Type::DynamicType(); 3601 return Type::DynamicType();
3602 } 3602 }
3603 } 3603 }
3604 return ParseType(type_resolution); 3604 return ParseType(type_resolution);
3605 } 3605 }
3606 3606
3607 3607
3608 // Returns ast nodes of the variable initialization, or NULL if variables 3608 // Returns ast nodes of the variable initialization, or NULL if variables
3609 // are not initialized. If several variables are declared and initialized, 3609 // are not initialized. If several variables are declared and initialized,
hausner 2011/12/09 21:19:21 This comment is outdated, since variables are now
regis 2011/12/09 21:31:22 Done.
3610 // the individual initializers are collected in a sequence node. 3610 // the individual initializers are collected in a sequence node.
3611 AstNode* Parser::ParseVariableDeclarationList() { 3611 AstNode* Parser::ParseVariableDeclarationList() {
3612 TRACE_PARSER("ParseVariableDeclarationList"); 3612 TRACE_PARSER("ParseVariableDeclarationList");
3613 bool is_final = (CurrentToken() == Token::kFINAL); 3613 bool is_final = (CurrentToken() == Token::kFINAL);
3614 const AbstractType& type = AbstractType::ZoneHandle( 3614 const AbstractType& type = AbstractType::ZoneHandle(
3615 ParseFinalVarOrType(kIsMandatory, kMustResolve)); 3615 ParseFinalVarOrType(kIsMandatory, kMustResolve));
3616 if (CurrentToken() != Token::kIDENT) { 3616 if (CurrentToken() != Token::kIDENT) {
3617 ErrorMsg("identifier expected"); 3617 ErrorMsg("identifier expected");
3618 } 3618 }
3619 3619
3620 AstNode* initializers = ParseVariableDeclaration(type, is_final); 3620 AstNode* initializers = ParseVariableDeclaration(type, is_final);
3621 ASSERT(initializers != NULL);
3621 while (CurrentToken() == Token::kCOMMA) { 3622 while (CurrentToken() == Token::kCOMMA) {
3622 ConsumeToken(); 3623 ConsumeToken();
3623 if (CurrentToken() != Token::kIDENT) { 3624 if (CurrentToken() != Token::kIDENT) {
3624 ErrorMsg("identifier expected after comma"); 3625 ErrorMsg("identifier expected after comma");
3625 } 3626 }
3626 AstNode* right = ParseVariableDeclaration(type, is_final); 3627 // We have a second initializer. Allocate a sequence node now.
3627 if (right != NULL) { 3628 // The sequence does not own the current scope. Set its own scope to NULL.
3628 if (initializers == NULL) { 3629 SequenceNode* sequence = NodeAsSequenceNode(initializers->token_index(),
3629 initializers = right; 3630 initializers,
3630 } else { 3631 NULL);
3631 // We have a second initializer. Allocate a sequence node now. 3632 sequence->Add(ParseVariableDeclaration(type, is_final));
3632 SequenceNode* sequence = NodeAsSequenceNode(initializers->token_index(), 3633 initializers = sequence;
3633 initializers,
3634 current_block_->scope);
3635 sequence->Add(right);
3636 initializers = sequence;
3637 }
3638 }
3639 } 3634 }
3640 return initializers; 3635 return initializers;
3641 } 3636 }
3642 3637
3643 3638
3644 AstNode* Parser::ParseFunctionStatement(bool is_literal) { 3639 AstNode* Parser::ParseFunctionStatement(bool is_literal) {
3645 TRACE_PARSER("ParseFunctionStatement"); 3640 TRACE_PARSER("ParseFunctionStatement");
3646 AbstractType& result_type = AbstractType::Handle(); 3641 AbstractType& result_type = AbstractType::Handle();
3647 const String* variable_name = NULL; 3642 const String* variable_name = NULL;
3648 const String* function_name = NULL; 3643 const String* function_name = NULL;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 } 4090 }
4096 return if_node; 4091 return if_node;
4097 } 4092 }
4098 4093
4099 4094
4100 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, 4095 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value,
4101 SourceLabel* case_label) { 4096 SourceLabel* case_label) {
4102 TRACE_PARSER("ParseCaseStatement"); 4097 TRACE_PARSER("ParseCaseStatement");
4103 bool default_seen = false; 4098 bool default_seen = false;
4104 const intptr_t case_pos = token_index_; 4099 const intptr_t case_pos = token_index_;
4105 SequenceNode* case_expressions = 4100 // The case expressions node sequence does not own the enclosing scope.
4106 new SequenceNode(case_pos, current_block_->scope); 4101 SequenceNode* case_expressions = new SequenceNode(case_pos, NULL);
4107 while (CurrentToken() == Token::kCASE || CurrentToken() == Token::kDEFAULT) { 4102 while (CurrentToken() == Token::kCASE || CurrentToken() == Token::kDEFAULT) {
4108 if (CurrentToken() == Token::kCASE) { 4103 if (CurrentToken() == Token::kCASE) {
4109 if (default_seen) { 4104 if (default_seen) {
4110 ErrorMsg("default clause must be last case"); 4105 ErrorMsg("default clause must be last case");
4111 } 4106 }
4112 ConsumeToken(); // Keyword case. 4107 ConsumeToken(); // Keyword case.
4113 const intptr_t expr_pos = token_index_; 4108 const intptr_t expr_pos = token_index_;
4114 AstNode* expr = ParseExpr(kAllowConst); 4109 AstNode* expr = ParseExpr(kAllowConst);
4115 AstNode* switch_expr_load = new LoadLocalNode(case_pos, 4110 AstNode* switch_expr_load = new LoadLocalNode(case_pos,
4116 *switch_expr_value); 4111 *switch_expr_value);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
4542 // Function literal in assert implies a call. 4537 // Function literal in assert implies a call.
4543 condition = 4538 condition =
4544 new ClosureCallNode(condition_pos, 4539 new ClosureCallNode(condition_pos,
4545 condition, 4540 condition,
4546 new ArgumentListNode(condition_pos)); 4541 new ArgumentListNode(condition_pos));
4547 } 4542 }
4548 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition); 4543 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition);
4549 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); 4544 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end);
4550 return new IfNode(condition_pos, 4545 return new IfNode(condition_pos,
4551 condition, 4546 condition,
4552 NodeAsSequenceNode(condition_pos, 4547 NodeAsSequenceNode(condition_pos, assert_throw, NULL),
4553 assert_throw,
4554 current_block_->scope),
4555 NULL); 4548 NULL);
4556 } 4549 }
4557 4550
4558 4551
4559 struct CatchParamDesc { 4552 struct CatchParamDesc {
4560 CatchParamDesc() 4553 CatchParamDesc()
4561 : token_index(0), type(NULL), var(NULL), is_final(false) { } 4554 : token_index(0), type(NULL), var(NULL), is_final(false) { }
4562 intptr_t token_index; 4555 intptr_t token_index;
4563 const AbstractType* type; 4556 const AbstractType* type;
4564 const String* var; 4557 const String* var;
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
5352 || expr->IsStaticGetterNode() 5345 || expr->IsStaticGetterNode()
5353 || expr->IsInstanceGetterNode() 5346 || expr->IsInstanceGetterNode()
5354 || expr->IsLoadIndexedNode(); 5347 || expr->IsLoadIndexedNode();
5355 } 5348 }
5356 5349
5357 5350
5358 AstNode* Parser::ParseExprList() { 5351 AstNode* Parser::ParseExprList() {
5359 TRACE_PARSER("ParseExprList"); 5352 TRACE_PARSER("ParseExprList");
5360 AstNode* expressions = ParseExpr(kAllowConst); 5353 AstNode* expressions = ParseExpr(kAllowConst);
5361 if (CurrentToken() == Token::kCOMMA) { 5354 if (CurrentToken() == Token::kCOMMA) {
5362 // Collect comma-separated expressions in a sequence node. 5355 // Collect comma-separated expressions in a non scope owning sequence node.
5363 SequenceNode* list = new SequenceNode(token_index_, current_block_->scope); 5356 SequenceNode* list = new SequenceNode(token_index_, NULL);
5364 list->Add(expressions); 5357 list->Add(expressions);
5365 while (CurrentToken() == Token::kCOMMA) { 5358 while (CurrentToken() == Token::kCOMMA) {
5366 ConsumeToken(); 5359 ConsumeToken();
5367 AstNode* expr = ParseExpr(kAllowConst); 5360 AstNode* expr = ParseExpr(kAllowConst);
5368 list->Add(expr); 5361 list->Add(expr);
5369 } 5362 }
5370 expressions = list; 5363 expressions = list;
5371 } 5364 }
5372 return expressions; 5365 return expressions;
5373 } 5366 }
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after
7638 } 7631 }
7639 7632
7640 7633
7641 void Parser::SkipNestedExpr() { 7634 void Parser::SkipNestedExpr() {
7642 const bool saved_mode = SetAllowFunctionLiterals(true); 7635 const bool saved_mode = SetAllowFunctionLiterals(true);
7643 SkipExpr(); 7636 SkipExpr();
7644 SetAllowFunctionLiterals(saved_mode); 7637 SetAllowFunctionLiterals(saved_mode);
7645 } 7638 }
7646 7639
7647 } // namespace dart 7640 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/opt_code_generator_ia32.cc ('k') | tests/language/src/Closure2Test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698