compiler: Handle newlines in general comments.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 11 Aug 2015 22:45:32 +0000 (22:45 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 11 Aug 2015 22:45:32 +0000 (22:45 +0000)
    On comments, the specification says
    (http://golang.org/ref/spec#Comments): General comments start with the
    character sequence /* and continue through the character sequence */.
    A general comment containing one or more newlines acts like a newline,
    otherwise it acts like a space.

    Fixes golang/go#11528.

    Reviewed-on: https://go-review.googlesource.com/13064

From-SVN: r226794

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/lex.cc
gcc/go/gofrontend/lex.h

index 2696ea5b36d88bd3c21d4b499ef891251acdd1a9..2cbe25ce606ba77573e2b1b67f2d8bbbdbdd8191 100644 (file)
@@ -1,4 +1,4 @@
-3bd90ea170b9c9aecedd37796acdd2712b29922b
+3b590ff53700963c1b8207a78594138e6a4e47f4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 1d9085f62807e7bb06fd2023b8d3ac880d438c47..8de94c5114b726d6270c4e16e7a7a554d4b2a2b3 100644 (file)
@@ -600,8 +600,14 @@ Lex::next_token()
                {
                  this->lineoff_ = p + 2 - this->linebuf_;
                  Location location = this->location();
-                 if (!this->skip_c_comment())
+                  bool found_newline = false;
+                 if (!this->skip_c_comment(&found_newline))
                    return Token::make_invalid_token(location);
+                  if (found_newline && this->add_semi_at_eol_)
+                    {
+                      this->add_semi_at_eol_ = false;
+                      return this->make_operator(OPERATOR_SEMICOLON, 1);
+                    }
                  p = this->linebuf_ + this->lineoff_;
                  pend = this->linebuf_ + this->linesize_;
                }
@@ -1621,7 +1627,7 @@ Lex::one_character_operator(char c)
 // Skip a C-style comment.
 
 bool
-Lex::skip_c_comment()
+Lex::skip_c_comment(bool* found_newline)
 {
   while (true)
     {
@@ -1642,6 +1648,9 @@ Lex::skip_c_comment()
              return true;
            }
 
+          if (p[0] == '\n')
+            *found_newline = true;
+
          this->lineoff_ = p - this->linebuf_;
          unsigned int c;
          bool issued_error;
index 383a91787802c563337ea80ddfde83bcca9d155b..3e0152aaf2d76ce4e056a0a6d4dc1b4474900c5a 100644 (file)
@@ -469,7 +469,7 @@ class Lex
   one_character_operator(char);
 
   bool
-  skip_c_comment();
+  skip_c_comment(bool* found_newline);
 
   void
   skip_cpp_comment();