Commit c03413c7 by Richard Kenner

(char_name): New var.

(initialize_char_syntax): Initialize it.
(handle_directive): Use it to simplify printing of diagnostics.
Warn about '\r' too.
(create_definition, do_pragma, do_endif, make_assertion): Be consistent
about skipping all horizontal white space, not just space and tab.

From-SVN: r8627
parent bced43dd
...@@ -966,6 +966,8 @@ U_CHAR is_idstart[256]; ...@@ -966,6 +966,8 @@ U_CHAR is_idstart[256];
U_CHAR is_hor_space[256]; U_CHAR is_hor_space[256];
/* table to tell if c is horizontal or vertical space. */ /* table to tell if c is horizontal or vertical space. */
static U_CHAR is_space[256]; static U_CHAR is_space[256];
/* names of some characters */
static char *char_name[256];
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0) #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
...@@ -3469,9 +3471,8 @@ handle_directive (ip, op) ...@@ -3469,9 +3471,8 @@ handle_directive (ip, op)
/* Skip whitespace and \-newline. */ /* Skip whitespace and \-newline. */
while (1) { while (1) {
if (is_hor_space[*bp]) { if (is_hor_space[*bp]) {
if ((*bp == '\f' || *bp == '\v') && pedantic) if (*bp != ' ' && *bp != '\t' && pedantic)
pedwarn ("%s in preprocessing directive", pedwarn ("%s in preprocessing directive", char_name[*bp]);
*bp == '\f' ? "formfeed" : "vertical tab");
bp++; bp++;
} else if (*bp == '/' && (bp[1] == '*' } else if (*bp == '/' && (bp[1] == '*'
|| (cplusplus_comments && bp[1] == '/'))) { || (cplusplus_comments && bp[1] == '/'))) {
...@@ -3644,10 +3645,10 @@ handle_directive (ip, op) ...@@ -3644,10 +3645,10 @@ handle_directive (ip, op)
break; break;
case '\f': case '\f':
case '\r':
case '\v': case '\v':
if (pedantic) if (pedantic)
pedwarn ("%s in preprocessing directive", pedwarn ("%s in preprocessing directive", char_name[c]);
c == '\f' ? "formfeed" : "vertical tab");
break; break;
case '\n': case '\n':
...@@ -5403,9 +5404,7 @@ create_definition (buf, limit, op) ...@@ -5403,9 +5404,7 @@ create_definition (buf, limit, op)
} }
++bp; /* skip paren */ ++bp; /* skip paren */
/* Skip spaces and tabs if any. */ SKIP_WHITE_SPACE (bp);
while (bp < limit && (*bp == ' ' || *bp == '\t'))
++bp;
/* now everything from bp before limit is the definition. */ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs); defn = collect_expansion (bp, limit, argno, arg_ptrs);
defn->rest_args = rest_args; defn->rest_args = rest_args;
...@@ -5432,14 +5431,11 @@ create_definition (buf, limit, op) ...@@ -5432,14 +5431,11 @@ create_definition (buf, limit, op)
if (bp < limit) if (bp < limit)
{ {
switch (*bp) if (is_hor_space[*bp]) {
{ bp++;
case '\t': case ' ': case '\r': SKIP_WHITE_SPACE (bp);
/* Skip spaces and tabs. */ } else {
while (++bp < limit && (*bp == ' ' || *bp == '\t' || *bp == '\r')) switch (*bp) {
continue;
break;
case '!': case '"': case '#': case '%': case '&': case '\'': case '!': case '"': case '#': case '%': case '&': case '\'':
case ')': case '*': case '+': case ',': case '-': case '.': case ')': case '*': case '+': case ',': case '-': case '.':
case '/': case ':': case ';': case '<': case '=': case '>': case '/': case ':': case ';': case '<': case '=': case '>':
...@@ -5455,6 +5451,7 @@ create_definition (buf, limit, op) ...@@ -5455,6 +5451,7 @@ create_definition (buf, limit, op)
break; break;
} }
} }
}
/* Now everything from bp before limit is the definition. */ /* Now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, NULL_PTR); defn = collect_expansion (bp, limit, -1, NULL_PTR);
defn->args.argnames = (U_CHAR *) ""; defn->args.argnames = (U_CHAR *) "";
...@@ -6640,8 +6637,7 @@ static int ...@@ -6640,8 +6637,7 @@ static int
do_pragma (buf, limit) do_pragma (buf, limit)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
{ {
while (*buf == ' ' || *buf == '\t') SKIP_WHITE_SPACE (buf);
buf++;
if (!strncmp (buf, "once", 4)) { if (!strncmp (buf, "once", 4)) {
/* Allow #pragma once in system headers, since that's not the user's /* Allow #pragma once in system headers, since that's not the user's
fault. */ fault. */
...@@ -7271,22 +7267,15 @@ do_endif (buf, limit, op, keyword) ...@@ -7271,22 +7267,15 @@ do_endif (buf, limit, op, keyword)
while (p != ep) { while (p != ep) {
U_CHAR c = *p++; U_CHAR c = *p++;
switch (c) { if (!is_space[c]) {
case ' ': if (c == '/' && p != ep && *p == '*') {
case '\t':
case '\n':
break;
case '/':
if (p != ep && *p == '*') {
/* Skip this comment. */ /* Skip this comment. */
int junk = 0; int junk = 0;
U_CHAR *save_bufp = ip->bufp; U_CHAR *save_bufp = ip->bufp;
ip->bufp = p + 1; ip->bufp = p + 1;
p = skip_to_end_of_comment (ip, &junk, 1); p = skip_to_end_of_comment (ip, &junk, 1);
ip->bufp = save_bufp; ip->bufp = save_bufp;
} } else
break;
default:
goto fail; goto fail;
} }
} }
...@@ -9169,6 +9158,10 @@ initialize_char_syntax () ...@@ -9169,6 +9158,10 @@ initialize_char_syntax ()
is_space['\f'] = 1; is_space['\f'] = 1;
is_space['\n'] = 1; is_space['\n'] = 1;
is_space['\r'] = 1; is_space['\r'] = 1;
char_name['\v'] = "vertical tab";
char_name['\f'] = "formfeed";
char_name['\r'] = "carriage return";
} }
/* Initialize the built-in macros. */ /* Initialize the built-in macros. */
...@@ -9414,7 +9407,7 @@ make_assertion (option, str) ...@@ -9414,7 +9407,7 @@ make_assertion (option, str)
} }
while (is_idchar[*++p]) while (is_idchar[*++p])
; ;
while (*p == ' ' || *p == '\t') p++; SKIP_WHITE_SPACE (p);
if (! (*p == 0 || *p == '(')) { if (! (*p == 0 || *p == '(')) {
error ("malformed option `%s %s'", option, str); error ("malformed option `%s %s'", option, str);
return; return;
......
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