Commit 2c8f0515 by Zack Weinberg Committed by Zack Weinberg

cpperror.c (print_file_and_line): If line is (unsigned int)-1, print just the filename.

	* cpperror.c (print_file_and_line): If line is (unsigned int)-1,
	print just the filename.
	* cpplex.c (_cpp_run_directive): Add additional argument, the
	name to give the synthetic buffer.  This defaults to
	translated "<command line>".
	* cpplib.c (cpp_define, cpp_undef, cpp_assert, cpp_unassert):
	Adjust to match.
	(_cpp_define_builtin): New function.
	* cppinit.c (initialize_builtins): Use _cpp_define_builtin.
	* cpphash.h: Update prototypes.

	* tradcpp.c (main): Process -D and -U simultaneously, in the
	order they appeared on the command line.

From-SVN: r36043
parent 5c5d1cd6
2000-08-29 Zack Weinberg <zack@wolery.cumb.org>
* cpperror.c (print_file_and_line): If line is (unsigned int)-1,
print just the filename.
* cpplex.c (_cpp_run_directive): Add additional argument, the
name to give the synthetic buffer. This defaults to
translated "<command line>".
* cpplib.c (cpp_define, cpp_undef, cpp_assert, cpp_unassert):
Adjust to match.
(_cpp_define_builtin): New function.
* cppinit.c (initialize_builtins): Use _cpp_define_builtin.
* cpphash.h: Update prototypes.
* tradcpp.c (main): Process -D and -U simultaneously, in the
order they appeared on the command line.
2000-08-29 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2000-08-29 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* c-decl.c (define_label): Call warning_with_file_and_line and * c-decl.c (define_label): Call warning_with_file_and_line and
......
...@@ -91,17 +91,15 @@ print_file_and_line (filename, line, column) ...@@ -91,17 +91,15 @@ print_file_and_line (filename, line, column)
const char *filename; const char *filename;
unsigned int line, column; unsigned int line, column;
{ {
if (line == 0)
fputs (_("<command line>: "), stderr);
else
{
if (filename == 0 || *filename == '\0') if (filename == 0 || *filename == '\0')
filename = "<stdin>"; filename = "<stdin>";
if (column > 0)
if (line == (unsigned int)-1)
fprintf (stderr, "%s: ", filename);
else if (column > 0)
fprintf (stderr, "%s:%u:%u: ", filename, line, column); fprintf (stderr, "%s:%u:%u: ", filename, line, column);
else else
fprintf (stderr, "%s:%u: ", filename, line); fprintf (stderr, "%s:%u: ", filename, line);
}
} }
/* Set up for an error message: print the file and line, bump the error /* Set up for an error message: print the file and line, bump the error
......
...@@ -267,7 +267,8 @@ extern int _cpp_equiv_tokens PARAMS ((const cpp_token *, ...@@ -267,7 +267,8 @@ extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
const cpp_token *)); const cpp_token *));
extern void _cpp_run_directive PARAMS ((cpp_reader *, extern void _cpp_run_directive PARAMS ((cpp_reader *,
const struct directive *, const struct directive *,
const char *, size_t)); const char *, size_t,
const char *));
extern unsigned int _cpp_get_line PARAMS ((cpp_reader *, extern unsigned int _cpp_get_line PARAMS ((cpp_reader *,
unsigned int *)); unsigned int *));
extern const cpp_token *_cpp_get_token PARAMS ((cpp_reader *)); extern const cpp_token *_cpp_get_token PARAMS ((cpp_reader *));
...@@ -284,6 +285,8 @@ extern cpp_hashnode *_cpp_parse_assertion PARAMS ((cpp_reader *, ...@@ -284,6 +285,8 @@ extern cpp_hashnode *_cpp_parse_assertion PARAMS ((cpp_reader *,
struct answer **)); struct answer **));
extern struct answer **_cpp_find_answer PARAMS ((cpp_hashnode *, extern struct answer **_cpp_find_answer PARAMS ((cpp_hashnode *,
const cpp_toklist *)); const cpp_toklist *));
extern void _cpp_define_builtin PARAMS ((cpp_reader *, const char *));
extern void _cpp_init_stacks PARAMS ((cpp_reader *)); extern void _cpp_init_stacks PARAMS ((cpp_reader *));
extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *)); extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *)); extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
......
...@@ -610,9 +610,9 @@ initialize_builtins (pfile) ...@@ -610,9 +610,9 @@ initialize_builtins (pfile)
if (b->flags & VERS) if (b->flags & VERS)
{ {
/* Allocate enough space for 'name="value"\0'. */ /* Allocate enough space for 'name "value"\n\0'. */
str = xmalloc (b->len + strlen (version_string) + 4); str = alloca (b->len + strlen (version_string) + 5);
sprintf (str, "%s=\"%s\"", b->name, version_string); sprintf (str, "%s \"%s\"\n", b->name, version_string);
} }
else else
{ {
...@@ -621,13 +621,12 @@ initialize_builtins (pfile) ...@@ -621,13 +621,12 @@ initialize_builtins (pfile)
else else
val = b->value; val = b->value;
/* Allocate enough space for "name=value\0". */ /* Allocate enough space for "name value\n\0". */
str = xmalloc (b->len + strlen (val) + 2); str = alloca (b->len + strlen (val) + 3);
sprintf(str, "%s=%s", b->name, val); sprintf(str, "%s %s\n", b->name, val);
} }
cpp_define (pfile, str); _cpp_define_builtin (pfile, str);
free (str);
} }
else else
{ {
......
...@@ -3565,16 +3565,23 @@ _cpp_skip_rest_of_line (pfile) ...@@ -3565,16 +3565,23 @@ _cpp_skip_rest_of_line (pfile)
/* Directive handler wrapper used by the command line option /* Directive handler wrapper used by the command line option
processor. */ processor. */
void void
_cpp_run_directive (pfile, dir, buf, count) _cpp_run_directive (pfile, dir, buf, count, name)
cpp_reader *pfile; cpp_reader *pfile;
const struct directive *dir; const struct directive *dir;
const char *buf; const char *buf;
size_t count; size_t count;
const char *name;
{ {
if (cpp_push_buffer (pfile, (const U_CHAR *)buf, count) != NULL) if (cpp_push_buffer (pfile, (const U_CHAR *)buf, count) != NULL)
{ {
unsigned int prev_lvl = 0; unsigned int prev_lvl = 0;
if (name)
CPP_BUFFER (pfile)->nominal_fname = name;
else
CPP_BUFFER (pfile)->nominal_fname = _("<command line>");
CPP_BUFFER (pfile)->lineno = (unsigned int)-1;
/* Scan the line now, else prevent_macro_expansion won't work. */ /* Scan the line now, else prevent_macro_expansion won't work. */
lex_next (pfile, 1); lex_next (pfile, 1);
if (! (dir->flags & EXPAND)) if (! (dir->flags & EXPAND))
......
...@@ -1410,7 +1410,20 @@ cpp_define (pfile, str) ...@@ -1410,7 +1410,20 @@ cpp_define (pfile, str)
strcpy (&buf[count-4], " 1\n"); strcpy (&buf[count-4], " 1\n");
} }
_cpp_run_directive (pfile, &dtable[T_DEFINE], buf, count - 1); _cpp_run_directive (pfile, &dtable[T_DEFINE], buf, count - 1, 0);
}
/* Slight variant of the above for use by initialize_builtins, which (a)
knows how to set up the buffer itself, (b) needs a different "filename"
tag. */
void
_cpp_define_builtin (pfile, str)
cpp_reader *pfile;
const char *str;
{
_cpp_run_directive (pfile, &dtable[T_DEFINE],
str, strlen (str),
_("<builtin>"));
} }
/* Process MACRO as if it appeared as the body of an #undef. */ /* Process MACRO as if it appeared as the body of an #undef. */
...@@ -1419,7 +1432,7 @@ cpp_undef (pfile, macro) ...@@ -1419,7 +1432,7 @@ cpp_undef (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
const char *macro; const char *macro;
{ {
_cpp_run_directive (pfile, &dtable[T_UNDEF], macro, strlen (macro)); _cpp_run_directive (pfile, &dtable[T_UNDEF], macro, strlen (macro), 0);
} }
/* Process the string STR as if it appeared as the body of a #assert. */ /* Process the string STR as if it appeared as the body of a #assert. */
...@@ -1428,7 +1441,7 @@ cpp_assert (pfile, str) ...@@ -1428,7 +1441,7 @@ cpp_assert (pfile, str)
cpp_reader *pfile; cpp_reader *pfile;
const char *str; const char *str;
{ {
_cpp_run_directive (pfile, &dtable[T_ASSERT], str, strlen (str)); _cpp_run_directive (pfile, &dtable[T_ASSERT], str, strlen (str), 0);
} }
/* Process STR as if it appeared as the body of an #unassert. */ /* Process STR as if it appeared as the body of an #unassert. */
...@@ -1437,7 +1450,7 @@ cpp_unassert (pfile, str) ...@@ -1437,7 +1450,7 @@ cpp_unassert (pfile, str)
cpp_reader *pfile; cpp_reader *pfile;
const char *str; const char *str;
{ {
_cpp_run_directive (pfile, &dtable[T_UNASSERT], str, strlen (str)); _cpp_run_directive (pfile, &dtable[T_UNASSERT], str, strlen (str), 0);
} }
/* Determine whether the identifier ID, of length LEN, is a defined macro. */ /* Determine whether the identifier ID, of length LEN, is a defined macro. */
......
...@@ -711,14 +711,11 @@ main (argc, argv) ...@@ -711,14 +711,11 @@ main (argc, argv)
and option processing. */ and option processing. */
initialize_builtins (); initialize_builtins ();
/* Do defines specified with -D. */ /* Do defines specified with -D and undefines specified with -U. */
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if (pend_defs[i]) if (pend_defs[i])
make_definition ((U_CHAR *)pend_defs[i]); make_definition ((U_CHAR *)pend_defs[i]);
else if (pend_undefs[i])
/* Do undefines specified with -U. */
for (i = 1; i < argc; i++)
if (pend_undefs[i])
make_undef ((U_CHAR *)pend_undefs[i]); make_undef ((U_CHAR *)pend_undefs[i]);
/* Unless -fnostdinc, /* Unless -fnostdinc,
......
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