mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13:04 +00:00
* reader.c (copy_definition): Use copy_string and copy_comment.
Removed now unused `match', `ended', `cplus_comment'. (copy_comment, copy_string): Moved, to be visible from copy_definition.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2000-03-17 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* reader.c (copy_definition): Use copy_string and copy_comment.
|
||||||
|
Removed now unused `match', `ended', `cplus_comment'.
|
||||||
|
(copy_comment, copy_string): Moved, to be visible from
|
||||||
|
copy_definition.
|
||||||
|
|
||||||
2000-03-17 Akim Demaille <akim@epita.fr>
|
2000-03-17 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* reader.c (copy_string): Declared `static inline'. No problems
|
* reader.c (copy_string): Declared `static inline'. No problems
|
||||||
|
|||||||
274
src/reader.c
274
src/reader.c
@@ -172,6 +172,99 @@ skip_to_char (int target)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Dump the string from FINPUT to FOUTPUT. MATCH is the delimiter of
|
||||||
|
the string (either ' or "). */
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
copy_string (FILE *finput, FILE *foutput, int match)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
putc (match, foutput);
|
||||||
|
c = getc (finput);
|
||||||
|
|
||||||
|
while (c != match)
|
||||||
|
{
|
||||||
|
if (c == EOF)
|
||||||
|
fatal (_("unterminated string at end of file"));
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
warn (_("unterminated string"));
|
||||||
|
ungetc (c, finput);
|
||||||
|
c = match; /* invent terminator */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
putc(c, foutput);
|
||||||
|
|
||||||
|
if (c == '\\')
|
||||||
|
{
|
||||||
|
c = getc (finput);
|
||||||
|
if (c == EOF)
|
||||||
|
fatal (_("unterminated string at end of file"));
|
||||||
|
putc (c, foutput);
|
||||||
|
if (c == '\n')
|
||||||
|
lineno++;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = getc(finput);
|
||||||
|
}
|
||||||
|
|
||||||
|
putc(c, foutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Dump the comment from FINPUT to FOUTPUT. C is either `*' or `/',
|
||||||
|
depending upon the type of comments used. */
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
copy_comment (FILE *finput, FILE *foutput, int c)
|
||||||
|
{
|
||||||
|
int cplus_comment;
|
||||||
|
register int match;
|
||||||
|
register int ended;
|
||||||
|
|
||||||
|
cplus_comment = (c == '/');
|
||||||
|
putc (c, foutput);
|
||||||
|
c = getc (finput);
|
||||||
|
|
||||||
|
ended = 0;
|
||||||
|
while (!ended)
|
||||||
|
{
|
||||||
|
if (!cplus_comment && c == '*')
|
||||||
|
{
|
||||||
|
while (c == '*')
|
||||||
|
{
|
||||||
|
putc(c, foutput);
|
||||||
|
c = getc(finput);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '/')
|
||||||
|
{
|
||||||
|
putc(c, foutput);
|
||||||
|
ended = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
lineno++;
|
||||||
|
putc (c, foutput);
|
||||||
|
if (cplus_comment)
|
||||||
|
ended = 1;
|
||||||
|
else
|
||||||
|
c = getc(finput);
|
||||||
|
}
|
||||||
|
else if (c == EOF)
|
||||||
|
fatal (_("unterminated comment"));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
putc (c, foutput);
|
||||||
|
c = getc (finput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
reader (void)
|
reader (void)
|
||||||
{
|
{
|
||||||
@@ -353,24 +446,22 @@ read_declarations (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* copy the contents of a %{ ... %} into the definitions file.
|
/* Copy the contents of a `%{ ... %}' into the definitions file. The
|
||||||
The %{ has already been read. Return after reading the %}. */
|
`%{' has already been read. Return after reading the `%}'. */
|
||||||
|
|
||||||
void
|
void
|
||||||
copy_definition (void)
|
copy_definition (void)
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
register int match;
|
/* -1 while reading a character if prev char was %. */
|
||||||
register int ended;
|
register int after_percent;
|
||||||
register int after_percent; /* -1 while reading a character if prev char was % */
|
|
||||||
int cplus_comment;
|
|
||||||
|
|
||||||
if (!nolinesflag)
|
if (!nolinesflag)
|
||||||
fprintf(fattrs, "#line %d \"%s\"\n", lineno, infile);
|
fprintf(fattrs, "#line %d \"%s\"\n", lineno, infile);
|
||||||
|
|
||||||
after_percent = 0;
|
after_percent = 0;
|
||||||
|
|
||||||
c = getc(finput);
|
c = getc (finput);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@@ -387,85 +478,15 @@ copy_definition (void)
|
|||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
case '"':
|
case '"':
|
||||||
match = c;
|
copy_string (finput, fattrs, c);
|
||||||
putc(c, fattrs);
|
|
||||||
c = getc(finput);
|
|
||||||
|
|
||||||
while (c != match)
|
|
||||||
{
|
|
||||||
if (c == EOF)
|
|
||||||
fatal(_("unterminated string at end of file"));
|
|
||||||
if (c == '\n')
|
|
||||||
{
|
|
||||||
warn(_("unterminated string"));
|
|
||||||
ungetc(c, finput);
|
|
||||||
c = match;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
putc(c, fattrs);
|
|
||||||
|
|
||||||
if (c == '\\')
|
|
||||||
{
|
|
||||||
c = getc(finput);
|
|
||||||
if (c == EOF)
|
|
||||||
fatal(_("unterminated string at end of file"));
|
|
||||||
putc(c, fattrs);
|
|
||||||
if (c == '\n')
|
|
||||||
lineno++;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
putc(c, fattrs);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '/':
|
case '/':
|
||||||
putc(c, fattrs);
|
putc (c, fattrs);
|
||||||
c = getc(finput);
|
c = getc (finput);
|
||||||
if (c != '*' && c != '/')
|
if (c != '*' && c != '/')
|
||||||
continue;
|
continue;
|
||||||
|
copy_comment (finput, fattrs, c);
|
||||||
cplus_comment = (c == '/');
|
|
||||||
putc(c, fattrs);
|
|
||||||
c = getc(finput);
|
|
||||||
|
|
||||||
ended = 0;
|
|
||||||
while (!ended)
|
|
||||||
{
|
|
||||||
if (!cplus_comment && c == '*')
|
|
||||||
{
|
|
||||||
while (c == '*')
|
|
||||||
{
|
|
||||||
putc(c, fattrs);
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '/')
|
|
||||||
{
|
|
||||||
putc(c, fattrs);
|
|
||||||
ended = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
lineno++;
|
|
||||||
putc(c, fattrs);
|
|
||||||
if (cplus_comment)
|
|
||||||
ended = 1;
|
|
||||||
else
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
else if (c == EOF)
|
|
||||||
fatal(_("unterminated comment in `%{' definition"));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
putc(c, fattrs);
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EOF:
|
case EOF:
|
||||||
@@ -989,97 +1010,6 @@ get_type_name (int n, symbol_list *rule)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Dump the string from FINPUT to FOUTPUT. MATCH is the delimiter of
|
|
||||||
the string (either ' or "). */
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
copy_string (FILE *finput, FILE *foutput, int match)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
|
|
||||||
putc (match, foutput);
|
|
||||||
c = getc (finput);
|
|
||||||
|
|
||||||
while (c != match)
|
|
||||||
{
|
|
||||||
if (c == EOF)
|
|
||||||
fatal(_("unterminated string at end of file"));
|
|
||||||
if (c == '\n')
|
|
||||||
{
|
|
||||||
warn (_("unterminated string"));
|
|
||||||
ungetc (c, finput);
|
|
||||||
c = match; /* invent terminator */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
putc(c, foutput);
|
|
||||||
|
|
||||||
if (c == '\\')
|
|
||||||
{
|
|
||||||
c = getc (finput);
|
|
||||||
if (c == EOF)
|
|
||||||
fatal (_("unterminated string"));
|
|
||||||
putc (c, foutput);
|
|
||||||
if (c == '\n')
|
|
||||||
lineno++;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
putc(c, foutput);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Dump the comment from FINPUT to FOUTPUT. C is either `*' or `/',
|
|
||||||
depending upon the type of comments used. */
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
copy_comment (FILE *finput, FILE *foutput, int c)
|
|
||||||
{
|
|
||||||
int cplus_comment;
|
|
||||||
register int match;
|
|
||||||
register int ended;
|
|
||||||
|
|
||||||
cplus_comment = (c == '/');
|
|
||||||
putc (c, foutput);
|
|
||||||
c = getc (finput);
|
|
||||||
|
|
||||||
ended = 0;
|
|
||||||
while (!ended)
|
|
||||||
{
|
|
||||||
if (!cplus_comment && c == '*')
|
|
||||||
{
|
|
||||||
while (c == '*')
|
|
||||||
{
|
|
||||||
putc(c, foutput);
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '/')
|
|
||||||
{
|
|
||||||
putc(c, foutput);
|
|
||||||
ended = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
lineno++;
|
|
||||||
putc (c, foutput);
|
|
||||||
if (cplus_comment)
|
|
||||||
ended = 1;
|
|
||||||
else
|
|
||||||
c = getc(finput);
|
|
||||||
}
|
|
||||||
else if (c == EOF)
|
|
||||||
fatal (_("unterminated comment"));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
putc (c, foutput);
|
|
||||||
c = getc (finput);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* After `%guard' is seen in the input file, copy the actual guard
|
/* After `%guard' is seen in the input file, copy the actual guard
|
||||||
into the guards file. If the guard is followed by an action, copy
|
into the guards file. If the guard is followed by an action, copy
|
||||||
|
|||||||
Reference in New Issue
Block a user