Patchwork [gccgo] Better error recovery in parser

login
register
mail settings
Submitter Ian Taylor
Date Sept. 8, 2010, 7 p.m.
Message ID <mcrsk1kgiwn.fsf@google.com>
Download mbox | patch
Permalink /patch/64196/
State New
Headers show

Comments

Ian Taylor - Sept. 8, 2010, 7 p.m.
This patch adds better error recovery for a couple of cases in the
parser.  Committed to gccgo branch.

Ian

Patch

diff -r 4caf9042fc50 go/parse.cc
--- a/go/parse.cc	Wed Sep 08 11:28:19 2010 -0700
+++ b/go/parse.cc	Wed Sep 08 11:58:01 2010 -0700
@@ -539,7 +539,18 @@ 
   if (is_anonymous)
     {
       if (is_anonymous_pointer)
-	this->advance_token();
+	{
+	  this->advance_token();
+	  if (!this->peek_token()->is_identifier())
+	    {
+	      this->error("expected field name");
+	      while (!token->is_op(OPERATOR_SEMICOLON)
+		     && !token->is_op(OPERATOR_RCURLY)
+		     && !token->is_eof())
+		token = this->advance_token();
+	      return;
+	    }
+	}
       Type* type = this->type_name(true);
 
       std::string tag;
@@ -2026,7 +2037,28 @@ 
   if (token->is_op(OPERATOR_MULT))
     {
       is_pointer = true;
-      this->advance_token();
+      token = this->advance_token();
+    }
+
+  if (!token->is_identifier())
+    {
+      this->error("expected receiver name or type");
+      int c = token->is_op(OPERATOR_LPAREN) ? 1 : 0;
+      while (!token->is_eof())
+	{
+	  token = this->advance_token();
+	  if (token->is_op(OPERATOR_LPAREN))
+	    ++c;
+	  else if (token->is_op(OPERATOR_RPAREN))
+	    {
+	      if (c == 0)
+		break;
+	      --c;
+	    }
+	}
+      if (!token->is_eof())
+	this->advance_token();
+      return NULL;
     }
 
   Type* type = this->type_name(true);