Commit 80512db7 by Jim Wilson

(rescan): Don't look for C++ // comment before directive.

Handle \-newline inside a C++ // comment.
(skip_if_group): Likewise.
(handle_directive): Also handle C++ // comment after #.  Point
ip->bufp after the comment start before calling
skip_to_end_of_comment.
(validate_else): Handle \-newline inside a C++ // comment.
(skip_to_end_of_comment, macarg1, discard_comments): Likewise.

From-SVN: r7028
parent 2ba3a0ec
...@@ -2536,10 +2536,9 @@ do { ip = &instack[indepth]; \ ...@@ -2536,10 +2536,9 @@ do { ip = &instack[indepth]; \
bp++; bp++;
bp += 2; bp += 2;
} }
else if (cplusplus_comments && *bp == '/' && bp[1] == '/') { /* There is no point in trying to deal with C++ // comments here,
bp += 2; because if there is one, then this # must be part of the
while (*bp++ != '\n') ; comment and we would never reach here. */
}
else break; else break;
} }
if (bp + 1 != ibp) if (bp + 1 != ibp)
...@@ -2708,13 +2707,23 @@ do { ip = &instack[indepth]; \ ...@@ -2708,13 +2707,23 @@ do { ip = &instack[indepth]; \
U_CHAR *before_bp = ibp+2; U_CHAR *before_bp = ibp+2;
while (ibp < limit) { while (ibp < limit) {
if (*ibp++ == '\n') { if (ibp[-1] != '\\' && *ibp == '\n') {
ibp--;
if (put_out_comments) { if (put_out_comments) {
bcopy (before_bp, obp, ibp - before_bp); bcopy (before_bp, obp, ibp - before_bp);
obp += ibp - before_bp; obp += ibp - before_bp;
} }
break; break;
} else {
if (*ibp == '\n') {
++ip->lineno;
/* Copy the newline into the output buffer, in order to
avoid the pain of a #line every time a multiline comment
is seen. */
if (!put_out_comments)
*obp++ = '\n';
++op->lineno;
}
ibp++;
} }
} }
break; break;
...@@ -3361,8 +3370,9 @@ handle_directive (ip, op) ...@@ -3361,8 +3370,9 @@ handle_directive (ip, op)
pedwarn ("%s in preprocessing directive", pedwarn ("%s in preprocessing directive",
*bp == '\f' ? "formfeed" : "vertical tab"); *bp == '\f' ? "formfeed" : "vertical tab");
bp++; bp++;
} else if (*bp == '/' && bp[1] == '*') { } else if (*bp == '/' && (bp[1] == '*'
ip->bufp = bp; || (cplusplus_comments && bp[1] == '/'))) {
ip->bufp = bp + 2;
skip_to_end_of_comment (ip, &ip->lineno, 0); skip_to_end_of_comment (ip, &ip->lineno, 0);
bp = ip->bufp; bp = ip->bufp;
} else if (*bp == '\\' && bp[1] == '\n') { } else if (*bp == '\\' && bp[1] == '\n') {
...@@ -6836,10 +6846,10 @@ skip_if_group (ip, any) ...@@ -6836,10 +6846,10 @@ skip_if_group (ip, any)
while (!(*bp == '*' && bp[1] == '/')) while (!(*bp == '*' && bp[1] == '/'))
bp++; bp++;
bp += 2; bp += 2;
} else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
bp += 2;
while (*bp++ != '\n') ;
} }
/* There is no point in trying to deal with C++ // comments here,
because if there is one, then this # must be part of the
comment and we would never reach here. */
else break; else break;
} }
if (bp != ip->bufp) { if (bp != ip->bufp) {
...@@ -6865,7 +6875,11 @@ skip_if_group (ip, any) ...@@ -6865,7 +6875,11 @@ skip_if_group (ip, any)
bp += 2; bp += 2;
} else if (cplusplus_comments && *bp == '/' && bp[1] == '/') { } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
bp += 2; bp += 2;
while (*bp++ != '\n') ; while (bp[-1] == '\\' || *bp != '\n') {
if (*bp == '\n')
ip->lineno++;
bp++;
}
} }
else break; else break;
} }
...@@ -7132,7 +7146,8 @@ validate_else (p) ...@@ -7132,7 +7146,8 @@ validate_else (p)
} }
else if (cplusplus_comments && p[1] == '/') { else if (cplusplus_comments && p[1] == '/') {
p += 2; p += 2;
while (*p && *p++ != '\n') ; while (*p && (*p != '\n' || p[-1] == '\\'))
p++;
} }
} else break; } else break;
} }
...@@ -7170,19 +7185,27 @@ skip_to_end_of_comment (ip, line_counter, nowarn) ...@@ -7170,19 +7185,27 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
} }
if (cplusplus_comments && bp[-1] == '/') { if (cplusplus_comments && bp[-1] == '/') {
if (output) { if (output) {
while (bp < limit) while (bp < limit) {
if ((*op->bufp++ = *bp++) == '\n') { *op->bufp++ = *bp;
bp--; if (*bp == '\n' && bp[-1] != '\\')
break; break;
if (*bp == '\n') {
++*line_counter;
++op->lineno;
}
bp++;
} }
op->bufp[-1] = '*'; op->bufp[-1] = '*';
*op->bufp++ = '/'; *op->bufp++ = '/';
*op->bufp++ = '\n'; *op->bufp++ = '\n';
} else { } else {
while (bp < limit) { while (bp < limit) {
if (*bp++ == '\n') { if (bp[-1] != '\\' && *bp == '\n') {
bp--;
break; break;
} else {
if (*bp == '\n' && line_counter)
++*line_counter;
bp++;
} }
} }
} }
...@@ -8061,8 +8084,10 @@ macarg1 (start, limit, depthptr, newlines, comments, rest_args) ...@@ -8061,8 +8084,10 @@ macarg1 (start, limit, depthptr, newlines, comments, rest_args)
if (cplusplus_comments && bp[1] == '/') { if (cplusplus_comments && bp[1] == '/') {
*comments = 1; *comments = 1;
bp += 2; bp += 2;
while (bp < limit && *bp++ != '\n') ; while (bp < limit && (*bp != '\n' || bp[-1] == '\\')) {
++*newlines; if (*bp == '\n') ++*newlines;
bp++;
}
break; break;
} }
if (bp[1] != '*' || bp + 1 >= limit) if (bp[1] != '*' || bp + 1 >= limit)
...@@ -8173,7 +8198,8 @@ discard_comments (start, length, newlines) ...@@ -8173,7 +8198,8 @@ discard_comments (start, length, newlines)
/* Comments are equivalent to spaces. */ /* Comments are equivalent to spaces. */
obp[-1] = ' '; obp[-1] = ' ';
ibp++; ibp++;
while (ibp < limit && *ibp++ != '\n') ; while (ibp < limit && (*ibp != '\n' || ibp[-1] == '\\'))
ibp++;
break; break;
} }
if (ibp[0] != '*' || ibp + 1 >= limit) if (ibp[0] != '*' || ibp + 1 >= limit)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment