Commit 7f7c467f by Richard Sandiford Committed by Richard Sandiford

read-md.h (read_char): Increment read_md_lineno after reading '\n'.

gcc/
	* read-md.h (read_char): Increment read_md_lineno after reading '\n'.
	(unread_char): Decrement read_md_lineno after putting back '\n'.
	* read-md.c (fatal_with_file_and_line): Push back any characters
	that we decide not to add to the context.
	(read_skip_spaces): Don't increment read_md_lineno here.  Avoid using
	fatal_expected_char in cases where '/' ends a line (for example).
	(read_name): Don't increment read_md_lineno here.
	(read_escape): Likewise.
	(read_quoted_string): Likewise.
	(read_braced_string): Likewise.

From-SVN: r160576
parent 9f418533
2010-06-10 Richard Sandiford <rdsandiford@googlemail.com> 2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
* read-md.h (read_char): Increment read_md_lineno after reading '\n'.
(unread_char): Decrement read_md_lineno after putting back '\n'.
* read-md.c (fatal_with_file_and_line): Push back any characters
that we decide not to add to the context.
(read_skip_spaces): Don't increment read_md_lineno here. Avoid using
fatal_expected_char in cases where '/' ends a line (for example).
(read_name): Don't increment read_md_lineno here.
(read_escape): Likewise.
(read_quoted_string): Likewise.
(read_braced_string): Likewise.
2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
* Makefile.in (READ_MD_H): Add $(HASHTAB_H). * Makefile.in (READ_MD_H): Add $(HASHTAB_H).
(build/genconstants.o): Depend on $(READ_MD_H) gensupport.h. (build/genconstants.o): Depend on $(READ_MD_H) gensupport.h.
* genconstants.c: Include read-md.h. * genconstants.c: Include read-md.h.
......
...@@ -259,7 +259,10 @@ fatal_with_file_and_line (const char *msg, ...) ...@@ -259,7 +259,10 @@ fatal_with_file_and_line (const char *msg, ...)
if (c == EOF) if (c == EOF)
break; break;
if (c == '\r' || c == '\n') if (c == '\r' || c == '\n')
break; {
unread_char (c);
break;
}
context[i] = c; context[i] = c;
} }
context[i] = '\0'; context[i] = '\0';
...@@ -298,18 +301,13 @@ read_skip_spaces (void) ...@@ -298,18 +301,13 @@ read_skip_spaces (void)
c = read_char (); c = read_char ();
switch (c) switch (c)
{ {
case '\n': case ' ': case '\t': case '\f': case '\r': case '\n':
read_md_lineno++;
break;
case ' ': case '\t': case '\f': case '\r':
break; break;
case ';': case ';':
do do
c = read_char (); c = read_char ();
while (c != '\n' && c != EOF); while (c != '\n' && c != EOF);
read_md_lineno++;
break; break;
case '/': case '/':
...@@ -317,14 +315,15 @@ read_skip_spaces (void) ...@@ -317,14 +315,15 @@ read_skip_spaces (void)
int prevc; int prevc;
c = read_char (); c = read_char ();
if (c != '*') if (c != '*')
fatal_expected_char ('*', c); {
unread_char (c);
fatal_with_file_and_line ("stray '/' in file");
}
prevc = 0; prevc = 0;
while ((c = read_char ()) && c != EOF) while ((c = read_char ()) && c != EOF)
{ {
if (c == '\n') if (prevc == '*' && c == '/')
read_md_lineno++;
else if (prevc == '*' && c == '/')
break; break;
prevc = c; prevc = c;
} }
...@@ -370,8 +369,6 @@ read_name (struct md_name *name) ...@@ -370,8 +369,6 @@ read_name (struct md_name *name)
if (i == 0) if (i == 0)
fatal_with_file_and_line ("missing name or number"); fatal_with_file_and_line ("missing name or number");
if (c == '\n')
read_md_lineno++;
name->buffer[i] = 0; name->buffer[i] = 0;
name->string = name->buffer; name->string = name->buffer;
...@@ -406,7 +403,6 @@ read_escape (void) ...@@ -406,7 +403,6 @@ read_escape (void)
{ {
/* Backslash-newline is replaced by nothing, as in C. */ /* Backslash-newline is replaced by nothing, as in C. */
case '\n': case '\n':
read_md_lineno++;
return; return;
/* \" \' \\ are replaced by the second character. */ /* \" \' \\ are replaced by the second character. */
...@@ -458,9 +454,7 @@ read_quoted_string (void) ...@@ -458,9 +454,7 @@ read_quoted_string (void)
while (1) while (1)
{ {
c = read_char (); /* Read the string */ c = read_char (); /* Read the string */
if (c == '\n') if (c == '\\')
read_md_lineno++;
else if (c == '\\')
{ {
read_escape (); read_escape ();
continue; continue;
...@@ -491,9 +485,7 @@ read_braced_string (void) ...@@ -491,9 +485,7 @@ read_braced_string (void)
{ {
c = read_char (); /* Read the string */ c = read_char (); /* Read the string */
if (c == '\n') if (c == '{')
read_md_lineno++;
else if (c == '{')
brace_depth++; brace_depth++;
else if (c == '}') else if (c == '}')
brace_depth--; brace_depth--;
......
...@@ -51,7 +51,12 @@ extern struct obstack string_obstack; ...@@ -51,7 +51,12 @@ extern struct obstack string_obstack;
static inline int static inline int
read_char (void) read_char (void)
{ {
return getc (read_md_file); int ch;
ch = getc (read_md_file);
if (ch == '\n')
read_md_lineno++;
return ch;
} }
/* Put back CH, which was the last character read from the MD file. */ /* Put back CH, which was the last character read from the MD file. */
...@@ -59,6 +64,8 @@ read_char (void) ...@@ -59,6 +64,8 @@ read_char (void)
static inline void static inline void
unread_char (int ch) unread_char (int ch)
{ {
if (ch == '\n')
read_md_lineno--;
ungetc (ch, read_md_file); ungetc (ch, read_md_file);
} }
......
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