Commit a6124a42 by J"orn Rennecke Committed by Joern Rennecke

glimits.h (SHRT_MIN): Define in a way suitable for 16 bit hosts.

        * glimits.h (SHRT_MIN): Define in a way suitable for 16 bit hosts.

        * c-lex.c (whitespace_cr, skip_white_space_on_line): New functions.
        (skip_white_space): Use whitespace_cr.
        (check_newline): Handle whitespace more consistently.

From-SVN: r16433
parent 8f3189a4
Tue Nov 11 21:47:27 1997 J"orn Rennecke <amylaar@cygnus.co.uk>
* glimits.h (SHRT_MIN): Define in a way suitable for 16 bit hosts.
* c-lex.c (whitespace_cr, skip_white_space_on_line): New functions.
(skip_white_space): Use whitespace_cr.
(check_newline): Handle whitespace more consistently.
Tue Nov 11 16:25:49 1997 Jim Wilson <wilson@cygnus.com> Tue Nov 11 16:25:49 1997 Jim Wilson <wilson@cygnus.com>
* i386/cygwin32.h (CPP_PREDEFINES): Delete -DPOSIX. * i386/cygwin32.h (CPP_PREDEFINES): Delete -DPOSIX.
......
...@@ -332,6 +332,29 @@ yyprint (file, yychar, yylval) ...@@ -332,6 +332,29 @@ yyprint (file, yychar, yylval)
} }
/* Iff C is a carriage return, warn about it - if appropriate -
and return nonzero. */
int
whitespace_cr (c)
int c;
{
static int newline_warning = 0;
if (c == '\r')
{
/* ANSI C says the effects of a carriage return in a source file
are undefined. */
if (pedantic && !newline_warning)
{
warning ("carriage return in source file");
warning ("(we only warn about the first carriage return)");
newline_warning = 1;
}
return 1;
}
return 0;
}
/* If C is not whitespace, return C. /* If C is not whitespace, return C.
Otherwise skip whitespace and return first nonwhite char read. */ Otherwise skip whitespace and return first nonwhite char read. */
...@@ -339,8 +362,6 @@ static int ...@@ -339,8 +362,6 @@ static int
skip_white_space (c) skip_white_space (c)
register int c; register int c;
{ {
static int newline_warning = 0;
for (;;) for (;;)
{ {
switch (c) switch (c)
...@@ -362,14 +383,7 @@ skip_white_space (c) ...@@ -362,14 +383,7 @@ skip_white_space (c)
break; break;
case '\r': case '\r':
/* ANSI C says the effects of a carriage return in a source file whitespace_cr (c);
are undefined. */
if (pedantic && !newline_warning)
{
warning ("carriage return in source file");
warning ("(we only warn about the first carriage return)");
newline_warning = 1;
}
c = GETC(); c = GETC();
break; break;
...@@ -406,6 +420,38 @@ position_after_white_space () ...@@ -406,6 +420,38 @@ position_after_white_space ()
UNGETC (skip_white_space (c)); UNGETC (skip_white_space (c));
} }
/* Like skip_white_space, but don't advance beyond the end of line.
Moreover, we don't get passed a character to start with. */
static int
skip_white_space_on_line ()
{
register int c;
while (1)
{
c = GETC();
switch (c)
{
case '\n':
default:
break;
case ' ':
case '\t':
case '\f':
case '\v':
case '\b':
continue;
case '\r':
whitespace_cr (c);
continue;
}
break;
}
return c;
}
/* Make the token buffer longer, preserving the data in it. /* Make the token buffer longer, preserving the data in it.
P should point to just beyond the last valid character in the old buffer. P should point to just beyond the last valid character in the old buffer.
The value we return is a pointer to the new buffer The value we return is a pointer to the new buffer
...@@ -550,9 +596,10 @@ check_newline () ...@@ -550,9 +596,10 @@ check_newline ()
&& GETC() == 'g' && GETC() == 'g'
&& GETC() == 'm' && GETC() == 'm'
&& GETC() == 'a' && GETC() == 'a'
&& ((c = GETC()) == ' ' || c == '\t' || c == '\n')) && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
|| whitespace_cr (c) ))
{ {
while (c == ' ' || c == '\t') while (c == ' ' || c == '\t' || whitespace_cr (c))
c = GETC (); c = GETC ();
if (c == '\n') if (c == '\n')
return c; return c;
...@@ -631,8 +678,7 @@ check_newline () ...@@ -631,8 +678,7 @@ check_newline ()
/* Here we have just seen `#ident '. /* Here we have just seen `#ident '.
A string constant should follow. */ A string constant should follow. */
while (c == ' ' || c == '\t') c = skip_white_space_on_line ();
c = GETC();
/* If no argument, ignore the line. */ /* If no argument, ignore the line. */
if (c == '\n') if (c == '\n')
...@@ -667,8 +713,11 @@ linenum: ...@@ -667,8 +713,11 @@ linenum:
/* Here we have either `#line' or `# <nonletter>'. /* Here we have either `#line' or `# <nonletter>'.
In either case, it should be a line number; a digit should follow. */ In either case, it should be a line number; a digit should follow. */
while (c == ' ' || c == '\t') /* Can't use skip_white_space here, but must handle all whitespace
c = GETC(); that is not '\n', lest we get a recursion for '\r' '\n' when
calling yylex. */
UNGETC (c);
c = skip_white_space_on_line ();
/* If the # is the only nonwhite char on the line, /* If the # is the only nonwhite char on the line,
just ignore it. Check the new newline. */ just ignore it. Check the new newline. */
...@@ -691,9 +740,7 @@ linenum: ...@@ -691,9 +740,7 @@ linenum:
int l = TREE_INT_CST_LOW (yylval.ttype) - 1; int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
/* Is this the last nonwhite stuff on the line? */ /* Is this the last nonwhite stuff on the line? */
c = GETC(); c = skip_white_space_on_line ();
while (c == ' ' || c == '\t')
c = GETC();
if (c == '\n') if (c == '\n')
{ {
/* No more: store the line number and check following line. */ /* No more: store the line number and check following line. */
...@@ -726,9 +773,7 @@ linenum: ...@@ -726,9 +773,7 @@ linenum:
main_input_filename = input_filename; main_input_filename = input_filename;
/* Is this the last nonwhite stuff on the line? */ /* Is this the last nonwhite stuff on the line? */
c = GETC(); c = skip_white_space_on_line ();
while (c == ' ' || c == '\t')
c = GETC();
if (c == '\n') if (c == '\n')
{ {
/* Update the name in the top element of input_file_stack. */ /* Update the name in the top element of input_file_stack. */
...@@ -798,9 +843,7 @@ linenum: ...@@ -798,9 +843,7 @@ linenum:
if (used_up) if (used_up)
{ {
/* Is this the last nonwhite stuff on the line? */ /* Is this the last nonwhite stuff on the line? */
c = GETC(); c = skip_white_space_on_line ();
while (c == ' ' || c == '\t')
c = GETC();
if (c == '\n') if (c == '\n')
return c; return c;
UNGETC (c); UNGETC (c);
...@@ -819,9 +862,7 @@ linenum: ...@@ -819,9 +862,7 @@ linenum:
if (used_up) if (used_up)
{ {
/* Is this the last nonwhite stuff on the line? */ /* Is this the last nonwhite stuff on the line? */
c = GETC(); c = skip_white_space_on_line ();
while (c == ' ' || c == '\t')
c = GETC();
if (c == '\n') if (c == '\n')
return c; return c;
UNGETC (c); UNGETC (c);
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
/* Minimum and maximum values a `signed short int' can hold. */ /* Minimum and maximum values a `signed short int' can hold. */
#undef SHRT_MIN #undef SHRT_MIN
#define SHRT_MIN (-32768) /* For the sake of 16 bit hosts, we may not use -32768 */
#define SHRT_MIN (-32767-1)
#undef SHRT_MAX #undef SHRT_MAX
#define SHRT_MAX 32767 #define SHRT_MAX 32767
......
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