Patchwork Go patch committed: Correct inserting semicolon at EOF if required

login
register
mail settings
Submitter Ian Taylor
Date Dec. 14, 2010, 6:52 p.m.
Message ID <mcrtyig89wj.fsf@google.com>
Download mbox | patch
Permalink /patch/75522/
State New
Headers show

Comments

Ian Taylor - Dec. 14, 2010, 6:52 p.m.
Lexing in Go is based on inserting a semicolon at end of line under
certain clearly defined conditions.  The gccgo frontend was not doing
this correctly when an EOF was seen after a partial line--i.e., a file
that does not end with a newline.  This patch fixes that problem.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 73aace1c638c go/lex.cc
--- a/go/lex.cc	Tue Dec 14 09:54:32 2010 -0800
+++ b/go/lex.cc	Tue Dec 14 10:18:48 2010 -0800
@@ -542,7 +542,13 @@ 
   while (true)
     {
       if (!this->require_line())
-	return this->make_eof_token();
+	{
+	  bool add_semi_at_eol = this->add_semi_at_eol_;
+	  this->add_semi_at_eol_ = false;
+	  if (add_semi_at_eol)
+	    return this->make_operator(OPERATOR_SEMICOLON, 1);
+	  return this->make_eof_token();
+	}
 
       const char* p = this->linebuf_ + this->lineoff_;
       const char* pend = this->linebuf_ + this->linesize_;