Skip to content

Commit

Permalink
compiler: Handle newlines in general comments.
Browse files Browse the repository at this point in the history
    
    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


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@226794 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
ian committed Aug 11, 2015
1 parent daa5a8a commit 39867fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gcc/go/gofrontend/MERGE
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 11 additions & 2 deletions gcc/go/gofrontend/lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gcc/go/gofrontend/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class Lex
one_character_operator(char);

bool
skip_c_comment();
skip_c_comment(bool* found_newline);

void
skip_cpp_comment();
Expand Down

0 comments on commit 39867fd

Please sign in to comment.