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

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

Issue 8450009: No returns allowed in constructors (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month 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 | « no previous file | tests/language/language.status » ('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 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 current_block_->statements->Add( 1763 current_block_->statements->Add(
1764 new StaticCallNode(token_index_, super_ctor, super_call_args)); 1764 new StaticCallNode(token_index_, super_ctor, super_call_args));
1765 } 1765 }
1766 } 1766 }
1767 if (CurrentToken() == Token::kLBRACE) { 1767 if (CurrentToken() == Token::kLBRACE) {
1768 ConsumeToken(); 1768 ConsumeToken();
1769 ParseStatementSequence(); 1769 ParseStatementSequence();
1770 ExpectToken(Token::kRBRACE); 1770 ExpectToken(Token::kRBRACE);
1771 } else if (CurrentToken() == Token::kARROW) { 1771 } else if (CurrentToken() == Token::kARROW) {
1772 ConsumeToken(); 1772 ConsumeToken();
1773 if (func.IsConstructor()) {
1774 ErrorMsg("constructors may not return a value");
1775 }
1773 intptr_t expr_pos = token_index_; 1776 intptr_t expr_pos = token_index_;
1774 AstNode* expr = ParseExpr(kAllowConst); 1777 AstNode* expr = ParseExpr(kAllowConst);
1775 ASSERT(expr != NULL); 1778 ASSERT(expr != NULL);
1776 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); 1779 current_block_->statements->Add(new ReturnNode(expr_pos, expr));
1777 } else if (IsLiteral("native")) { 1780 } else if (IsLiteral("native")) {
1778 ParseNativeFunctionBlock(&params, func); 1781 ParseNativeFunctionBlock(&params, func);
1779 } else if (CurrentToken() == Token::kSEMICOLON) { 1782 } else if (CurrentToken() == Token::kSEMICOLON) {
1780 ConsumeToken(); 1783 ConsumeToken();
1781 ASSERT(func.IsConstructor()); 1784 ASSERT(func.IsConstructor());
1782 // Some constructors have no function body. 1785 // Some constructors have no function body.
(...skipping 3048 matching lines...) Expand 10 before | Expand all | Expand 10 after
4831 statement = ParseWhileStatement(label_name); 4834 statement = ParseWhileStatement(label_name);
4832 } else if (CurrentToken() == Token::kFOR) { 4835 } else if (CurrentToken() == Token::kFOR) {
4833 statement = ParseForStatement(label_name); 4836 statement = ParseForStatement(label_name);
4834 } else if (CurrentToken() == Token::kDO) { 4837 } else if (CurrentToken() == Token::kDO) {
4835 statement = ParseDoWhileStatement(label_name); 4838 statement = ParseDoWhileStatement(label_name);
4836 } else if (CurrentToken() == Token::kSWITCH) { 4839 } else if (CurrentToken() == Token::kSWITCH) {
4837 statement = ParseSwitchStatement(label_name); 4840 statement = ParseSwitchStatement(label_name);
4838 } else if (CurrentToken() == Token::kTRY) { 4841 } else if (CurrentToken() == Token::kTRY) {
4839 statement = ParseTryStatement(label_name); 4842 statement = ParseTryStatement(label_name);
4840 } else if (CurrentToken() == Token::kRETURN) { 4843 } else if (CurrentToken() == Token::kRETURN) {
4844 const intptr_t return_pos = token_index_;
4841 ConsumeToken(); 4845 ConsumeToken();
4842 if (CurrentToken() != Token::kSEMICOLON) { 4846 if (CurrentToken() != Token::kSEMICOLON) {
4847 if (current_function().IsConstructor() &&
4848 (current_block_->scope->function_level() == 0)) {
4849 ErrorMsg(return_pos, "return of a value not allowed in constructors");
4850 }
4843 AstNode* expr = ParseExpr(kAllowConst); 4851 AstNode* expr = ParseExpr(kAllowConst);
4844 statement = new ReturnNode(statement_pos, expr); 4852 statement = new ReturnNode(statement_pos, expr);
4845 } else { 4853 } else {
4846 statement = new ReturnNode(statement_pos); 4854 statement = new ReturnNode(statement_pos);
4847 } 4855 }
4848 AddNodeForFinallyInlining(statement); 4856 AddNodeForFinallyInlining(statement);
4849 ExpectSemicolon(); 4857 ExpectSemicolon();
4850 } else if (CurrentToken() == Token::kIF) { 4858 } else if (CurrentToken() == Token::kIF) {
4851 statement = ParseIfStatement(label_name); 4859 statement = ParseIfStatement(label_name);
4852 } else if (CurrentToken() == Token::kASSERT) { 4860 } else if (CurrentToken() == Token::kASSERT) {
(...skipping 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after
7199 } 7207 }
7200 7208
7201 7209
7202 void Parser::SkipNestedExpr() { 7210 void Parser::SkipNestedExpr() {
7203 const bool saved_mode = SetAllowFunctionLiterals(true); 7211 const bool saved_mode = SetAllowFunctionLiterals(true);
7204 SkipExpr(); 7212 SkipExpr();
7205 SetAllowFunctionLiterals(saved_mode); 7213 SetAllowFunctionLiterals(saved_mode);
7206 } 7214 }
7207 7215
7208 } // namespace dart 7216 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698