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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 6540)
+++ runtime/vm/parser.cc (working copy)
@@ -3647,7 +3647,7 @@
set_current_class(toplevel_class);
if (IsVariableDeclaration()) {
ParseTopLevelVariable(&top_level);
- } else if (IsTopLevelFunction()) {
+ } else if (IsFunctionDeclaration()) {
ParseTopLevelFunction(&top_level);
} else if (IsTopLevelAccessor()) {
ParseTopLevelAccessor(&top_level);
@@ -4273,21 +4273,38 @@
}
+// Look ahead to detect whether the next tokens should be parsed as
+// a function declaration. Token position remains unchanged.
bool Parser::IsFunctionDeclaration() {
- // A function declaration is like a function literal but it must have
- // a name.
- return (CurrentToken() != Token::kLPAREN) && IsFunctionLiteral();
+ const intptr_t saved_pos = token_index_;
+ if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) {
+ // Possibly a function without explicit return type.
+ ConsumeToken(); // Consume function identifier.
+ } else if (TryParseReturnType()) {
+ if (!IsIdentifier()) {
+ SetPosition(saved_pos);
+ return false;
+ }
+ ConsumeToken(); // Consume function identifier.
+ } else {
+ SetPosition(saved_pos);
+ return false;
+ }
+ // Check parameter list and the following token.
+ if (CurrentToken() == Token::kLPAREN) {
+ SkipToMatchingParenthesis();
+ if ((CurrentToken() == Token::kLBRACE) ||
+ (CurrentToken() == Token::kARROW) ||
+ (is_top_level_ && IsLiteral("native"))) {
+ SetPosition(saved_pos);
+ return true;
+ }
+ }
+ SetPosition(saved_pos);
+ return false;
}
-bool Parser::IsTopLevelFunction() {
- // Top-level function declarations can omit the return type. Check for
- // that case separately.
- return (IsIdentifier() &&
- (LookaheadToken(1) == Token::kLPAREN)) || IsFunctionDeclaration();
-}
-
-
bool Parser::IsTopLevelAccessor() {
if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
return true;
« 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