Commit e8037d57 by Per Bothner

cpplib.c (line_for_error): Make it work; add extra parameter.

* cpplib.c (line_for_error):  Make it work; add extra parameter.
(skip_quoted_string, cpp_get_token):  Update calls to line_for_error.
(macroexpand):  Remember initial line so we can report it if the
call is unterminated.  Also, simplify error logic slightly.
(do_include):  Cast alloca return value, to avoid pcc warning.

From-SVN: r9635
parent 8f4686fa
...@@ -512,7 +512,7 @@ skip_quoted_string (pfile, first, start_line) ...@@ -512,7 +512,7 @@ skip_quoted_string (pfile, first, start_line)
c = GETC (); c = GETC ();
if (c == EOF) if (c == EOF)
{ {
cpp_error_with_line (pfile, line_for_error (start_line), cpp_error_with_line (pfile, line_for_error (pfile, start_line),
"unterminated string or character constant"); "unterminated string or character constant");
#if 0 #if 0
cpp_error_with_line (pfile, multiline_string_line, cpp_error_with_line (pfile, multiline_string_line,
...@@ -536,7 +536,7 @@ skip_quoted_string (pfile, first, start_line) ...@@ -536,7 +536,7 @@ skip_quoted_string (pfile, first, start_line)
} }
if (CPP_PEDANTIC (pfile) || first == '\'') if (CPP_PEDANTIC (pfile) || first == '\'')
{ {
cpp_error_with_line (pfile, line_for_error (start_line), cpp_error_with_line (pfile, line_for_error (pfile, start_line),
"unterminated string or character constant"); "unterminated string or character constant");
FORWARD(-1); FORWARD(-1);
break; break;
...@@ -2707,6 +2707,7 @@ macroexpand (pfile, hp) ...@@ -2707,6 +2707,7 @@ macroexpand (pfile, hp)
int nargs; int nargs;
DEFINITION *defn = hp->value.defn; DEFINITION *defn = hp->value.defn;
register U_CHAR *xbuf; register U_CHAR *xbuf;
long start_line, start_col;
int xbuf_len; int xbuf_len;
struct argdata *args; struct argdata *args;
long old_written = CPP_WRITTEN (pfile); long old_written = CPP_WRITTEN (pfile);
...@@ -2728,12 +2729,12 @@ macroexpand (pfile, hp) ...@@ -2728,12 +2729,12 @@ macroexpand (pfile, hp)
#endif #endif
pfile->output_escapes++; pfile->output_escapes++;
cpp_buf_line_and_col (CPP_BUFFER (pfile), &start_line, &start_col);
nargs = defn->nargs; nargs = defn->nargs;
if (nargs >= 0) if (nargs >= 0)
{ {
char *parse_error = 0;
enum cpp_token token; enum cpp_token token;
args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata)); args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
...@@ -2772,13 +2773,9 @@ macroexpand (pfile, hp) ...@@ -2772,13 +2773,9 @@ macroexpand (pfile, hp)
token = macarg (pfile, 0); token = macarg (pfile, 0);
if (token == CPP_EOF || token == CPP_POP) if (token == CPP_EOF || token == CPP_POP)
{ {
parse_error = "unterminated macro call"; cpp_error_with_line (pfile, line_for_error (pfile, start_line),
#if 1 "unterminated macro call");
cpp_error_with_line (pfile, line_for_error (0), parse_error); return;
#else
cpp_error_with_line (pfile, line_for_error (start_line), parse_error);
#endif
break;
} }
i++; i++;
} while (token == CPP_COMMA); } while (token == CPP_COMMA);
...@@ -2801,8 +2798,7 @@ macroexpand (pfile, hp) ...@@ -2801,8 +2798,7 @@ macroexpand (pfile, hp)
rest_zero = 0; rest_zero = 0;
if (nargs == 0 && i > 0) if (nargs == 0 && i > 0)
{ {
if (! parse_error) cpp_error (pfile, "arguments given to macro `%s'", hp->name);
cpp_error (pfile, "arguments given to macro `%s'", hp->name);
} }
else if (i < nargs) else if (i < nargs)
{ {
...@@ -2812,8 +2808,6 @@ macroexpand (pfile, hp) ...@@ -2812,8 +2808,6 @@ macroexpand (pfile, hp)
/* the rest args token is allowed to absorb 0 tokens */ /* the rest args token is allowed to absorb 0 tokens */
else if (i == nargs - 1 && defn->rest_args) else if (i == nargs - 1 && defn->rest_args)
rest_zero = 1; rest_zero = 1;
else if (parse_error)
;
else if (i == 0) else if (i == 0)
cpp_error (pfile, "macro `%s' used without args", hp->name); cpp_error (pfile, "macro `%s' used without args", hp->name);
else if (i == 1) else if (i == 1)
...@@ -2824,9 +2818,8 @@ macroexpand (pfile, hp) ...@@ -2824,9 +2818,8 @@ macroexpand (pfile, hp)
} }
else if (i > nargs) else if (i > nargs)
{ {
if (! parse_error) cpp_error (pfile,
cpp_error (pfile, "macro `%s' used with too many (%d) args", hp->name, i);
"macro `%s' used with too many (%d) args", hp->name, i);
} }
} }
...@@ -3461,8 +3454,8 @@ do_include (pfile, keyword, unused1, unused2) ...@@ -3461,8 +3454,8 @@ do_include (pfile, keyword, unused1, unused2)
if (searchptr->fname[0] == 0) if (searchptr->fname[0] == 0)
continue; continue;
p = alloca (strlen (searchptr->fname) p = (char *) alloca (strlen (searchptr->fname)
+ strlen (fname) + 2); + strlen (fname) + 2);
strcpy (p, searchptr->fname); strcpy (p, searchptr->fname);
strcat (p, "/"); strcat (p, "/");
strcat (p, fname); strcat (p, fname);
...@@ -4716,7 +4709,8 @@ cpp_get_token (pfile) ...@@ -4716,7 +4709,8 @@ cpp_get_token (pfile)
goto randomchar; goto randomchar;
if (c == EOF) if (c == EOF)
{ {
cpp_error_with_line (pfile, line_for_error (pfile->start_line), cpp_error_with_line (pfile,
line_for_error (pfile, pfile->start_line),
"unterminated comment"); "unterminated comment");
goto handle_eof; goto handle_eof;
} }
...@@ -4847,7 +4841,8 @@ cpp_get_token (pfile) ...@@ -4847,7 +4841,8 @@ cpp_get_token (pfile)
#if 0 #if 0
if (!CPP_TRADITIONAL (pfile)) if (!CPP_TRADITIONAL (pfile))
{ {
cpp_error_with_line (pfile, line_for_error (start_line), cpp_error_with_line (pfile,
line_for_error (pfile, start_line),
"unterminated string or character constant"); "unterminated string or character constant");
cpp_error_with_line (pfile, multiline_string_line, cpp_error_with_line (pfile, multiline_string_line,
"possible real start of unterminated constant"); "possible real start of unterminated constant");
...@@ -4867,14 +4862,15 @@ cpp_get_token (pfile) ...@@ -4867,14 +4862,15 @@ cpp_get_token (pfile)
#if 0 #if 0
if (c == '\'') if (c == '\'')
{ {
cpp_error_with_line (pfile, line_for_error (start_line), cpp_error_with_line (pfile,
"unterminated character constant"); line_for_error (pfile, start_line),
"unterminated character constant");
goto while2end; goto while2end;
} }
if (CPP_PEDANTIC (pfile) && multiline_string_line == 0) if (CPP_PEDANTIC (pfile) && multiline_string_line == 0)
{ {
cpp_pedwarn_with_line (pfile, cpp_pedwarn_with_line (pfile,
line_for_error (start_line), line_for_error (pfile, start_line),
"string constant runs past end of line"); "string constant runs past end of line");
} }
if (multiline_string_line == 0) if (multiline_string_line == 0)
...@@ -7281,25 +7277,20 @@ savestring (input) ...@@ -7281,25 +7277,20 @@ savestring (input)
In that case, we return the lineno of the innermost file. */ In that case, we return the lineno of the innermost file. */
static int static int
line_for_error (line) line_for_error (pfile, line)
cpp_reader *pfile;
int line; int line;
{ {
#if 0 long line1 = line, col;
int i; cpp_buffer *ip = CPP_BUFFER (pfile);
int line1 = line;
for (i = indepth; i >= 0; ) { while (ip != CPP_NULL_BUFFER (pfile))
if (instack[i].fname != 0) {
return line1; if (ip->fname != NULL)
i--; return line1;
if (i < 0) ip = CPP_PREV_BUFFER (ip);
return 0; cpp_buf_line_and_col (ip, &line1, &col);
line1 = instack[i].lineno; }
}
abort ();
/*NOTREACHED*/
#endif
return 0;
} }
/* Initialize PMARK to remember the current position of PFILE. */ /* Initialize PMARK to remember the current position of PFILE. */
......
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