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

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

Issue 10086015: Fix bug 918 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | 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) 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 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 3629 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 ParseClassDefinition(pending_classes); 3640 ParseClassDefinition(pending_classes);
3641 } else if ((CurrentToken() == Token::kTYPEDEF) && 3641 } else if ((CurrentToken() == Token::kTYPEDEF) &&
3642 (LookaheadToken(1) != Token::kLPAREN)) { 3642 (LookaheadToken(1) != Token::kLPAREN)) {
3643 ParseFunctionTypeAlias(pending_classes); 3643 ParseFunctionTypeAlias(pending_classes);
3644 } else if (CurrentToken() == Token::kINTERFACE) { 3644 } else if (CurrentToken() == Token::kINTERFACE) {
3645 ParseInterfaceDefinition(pending_classes); 3645 ParseInterfaceDefinition(pending_classes);
3646 } else { 3646 } else {
3647 set_current_class(toplevel_class); 3647 set_current_class(toplevel_class);
3648 if (IsVariableDeclaration()) { 3648 if (IsVariableDeclaration()) {
3649 ParseTopLevelVariable(&top_level); 3649 ParseTopLevelVariable(&top_level);
3650 } else if (IsTopLevelFunction()) { 3650 } else if (IsFunctionDeclaration()) {
3651 ParseTopLevelFunction(&top_level); 3651 ParseTopLevelFunction(&top_level);
3652 } else if (IsTopLevelAccessor()) { 3652 } else if (IsTopLevelAccessor()) {
3653 ParseTopLevelAccessor(&top_level); 3653 ParseTopLevelAccessor(&top_level);
3654 } else if (CurrentToken() == Token::kEOS) { 3654 } else if (CurrentToken() == Token::kEOS) {
3655 break; 3655 break;
3656 } else { 3656 } else {
3657 UnexpectedToken(); 3657 UnexpectedToken();
3658 } 3658 }
3659 } 3659 }
3660 } 3660 }
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 (CurrentToken() == Token::kASSIGN)) { 4266 (CurrentToken() == Token::kASSIGN)) {
4267 is_var_decl = true; 4267 is_var_decl = true;
4268 } 4268 }
4269 } 4269 }
4270 } 4270 }
4271 SetPosition(saved_pos); 4271 SetPosition(saved_pos);
4272 return is_var_decl; 4272 return is_var_decl;
4273 } 4273 }
4274 4274
4275 4275
4276 // Look ahead to detect whether the next tokens should be parsed as
4277 // a function declaration. Token position remains unchanged.
4276 bool Parser::IsFunctionDeclaration() { 4278 bool Parser::IsFunctionDeclaration() {
4277 // A function declaration is like a function literal but it must have 4279 const intptr_t saved_pos = token_index_;
4278 // a name. 4280 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) {
4279 return (CurrentToken() != Token::kLPAREN) && IsFunctionLiteral(); 4281 // Possibly a function without explicit return type.
4280 } 4282 ConsumeToken(); // Consume function identifier.
4281 4283 } else if (TryParseReturnType()) {
4282 4284 if (!IsIdentifier()) {
4283 bool Parser::IsTopLevelFunction() { 4285 SetPosition(saved_pos);
4284 // Top-level function declarations can omit the return type. Check for 4286 return false;
4285 // that case separately. 4287 }
4286 return (IsIdentifier() && 4288 ConsumeToken(); // Consume function identifier.
4287 (LookaheadToken(1) == Token::kLPAREN)) || IsFunctionDeclaration(); 4289 } else {
4290 SetPosition(saved_pos);
4291 return false;
4292 }
4293 // Check parameter list and the following token.
4294 if (CurrentToken() == Token::kLPAREN) {
4295 SkipToMatchingParenthesis();
4296 if ((CurrentToken() == Token::kLBRACE) ||
4297 (CurrentToken() == Token::kARROW) ||
4298 (is_top_level_ && IsLiteral("native"))) {
4299 SetPosition(saved_pos);
4300 return true;
4301 }
4302 }
4303 SetPosition(saved_pos);
4304 return false;
4288 } 4305 }
4289 4306
4290 4307
4291 bool Parser::IsTopLevelAccessor() { 4308 bool Parser::IsTopLevelAccessor() {
4292 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 4309 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
4293 return true; 4310 return true;
4294 } 4311 }
4295 const intptr_t saved_pos = token_index_; 4312 const intptr_t saved_pos = token_index_;
4296 if (TryParseReturnType()) { 4313 if (TryParseReturnType()) {
4297 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 4314 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
(...skipping 4056 matching lines...) Expand 10 before | Expand all | Expand 10 after
8354 void Parser::SkipQualIdent() { 8371 void Parser::SkipQualIdent() {
8355 ASSERT(IsIdentifier()); 8372 ASSERT(IsIdentifier());
8356 ConsumeToken(); 8373 ConsumeToken();
8357 if (CurrentToken() == Token::kPERIOD) { 8374 if (CurrentToken() == Token::kPERIOD) {
8358 ConsumeToken(); // Consume the kPERIOD token. 8375 ConsumeToken(); // Consume the kPERIOD token.
8359 ExpectIdentifier("identifier expected after '.'"); 8376 ExpectIdentifier("identifier expected after '.'");
8360 } 8377 }
8361 } 8378 }
8362 8379
8363 } // namespace dart 8380 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698