Commit 9ec7291f by Zack Weinberg Committed by Zack Weinberg

configure.in (--enable-c-cpplib): Uncomment.

	* configure.in (--enable-c-cpplib): Uncomment.  Use AC_DEFINE
	instead of extra_c_flags.
	(--enable-c-mbchar): Use AC_DEFINE instead of extra_c_flags.
	* configure: Regenerate.
	* config.in: Regenerate.

	* cpperror.c (cpp_type2name): New function.
	* cpplex.c (lex_line): If we issued an error for an invalid
	preprocessing directive, discard that logical line.
	* cpplib.c (do_line): Call a hook function if the current file
	is renamed by #line.
	(do_ident): Pass the contents of the string, not the entire
	token, to the callback function.
	* cpplib.h (CPP_LAST_PUNCTUATOR): New #define.
	(cb.rename_file): New hook function.
	(cb.ident): Adjust prototype.
	(cpp_type2name): Prototype.
	* cppmacro.c (dump_macro_args): Correct precedence lossage.

	* cppmain.c (cb_ident): Update for changed interface.
	(cb_rename_file): New function.
	(main): Set rename callback.

From-SVN: r35593
parent 9cc82a01
2000-08-09 Zack Weinberg <zack@wolery.cumb.org>
* configure.in (--enable-c-cpplib): Uncomment. Use AC_DEFINE
instead of extra_c_flags.
(--enable-c-mbchar): Use AC_DEFINE instead of extra_c_flags.
* configure: Regenerate.
* config.in: Regenerate.
* cpperror.c (cpp_type2name): New function.
* cpplex.c (lex_line): If we issued an error for an invalid
preprocessing directive, discard that logical line.
* cpplib.c (do_line): Call a hook function if the current file
is renamed by #line.
(do_ident): Pass the contents of the string, not the entire
token, to the callback function.
* cpplib.h (CPP_LAST_PUNCTUATOR): New #define.
(cb.rename_file): New hook function.
(cb.ident): Adjust prototype.
(cpp_type2name): Prototype.
* cppmacro.c (dump_macro_args): Correct precedence lossage.
* cppmain.c (cb_ident): Update for changed interface.
(cb_rename_file): New function.
(main): Set rename callback.
2000-08-09 Alexandre Oliva <aoliva@redhat.com> 2000-08-09 Alexandre Oliva <aoliva@redhat.com>
* caller-save.c (mark_referenced_regs): Mark partially-overwritten * caller-save.c (mark_referenced_regs): Mark partially-overwritten
......
...@@ -308,6 +308,14 @@ ...@@ -308,6 +308,14 @@
every opportunity. This is extremely expensive. */ every opportunity. This is extremely expensive. */
#undef ENABLE_GC_ALWAYS_COLLECT #undef ENABLE_GC_ALWAYS_COLLECT
/* Define if you want the preprocessor merged into the C and C++ compilers.
This mode is not ready for production use. */
#undef USE_CPPLIB
/* Define if you want the C and C++ compilers to support multibyte
character sets for source code. */
#undef MULTIBYTE_CHARS
/* Define if your compiler understands volatile. */ /* Define if your compiler understands volatile. */
#undef HAVE_VOLATILE #undef HAVE_VOLATILE
......
...@@ -254,22 +254,26 @@ elif test x$withval != xno; then ...@@ -254,22 +254,26 @@ elif test x$withval != xno; then
cpp_install_dir=$withval cpp_install_dir=$withval
fi]) fi])
dnl Disable this for the moment; the library interface is changing. # Link cpplib into the compiler proper, for C/C++/ObjC.
dnl # Link cpplib into the compiler proper, for C/C++/ObjC. AC_ARG_ENABLE(c-cpplib,
dnl AC_ARG_ENABLE(c-cpplib, [ --enable-c-cpplib link cpplib directly into C and C++ compilers
dnl [ --enable-c-cpplib link cpplib directly into C and C++ compilers (HIGHLY EXPERIMENTAL).],
dnl (EXPERIMENTAL) (implies --enable-cpplib).], if test x$enable_c_cpplib != xno; then
dnl if test x$enable_c_cpplib != xno; then extra_c_objs="${extra_c_objs} libcpp.a"
dnl extra_c_objs="${extra_c_objs} libcpp.a" extra_cxx_objs="${extra_cxx_objs} ../libcpp.a"
dnl extra_cxx_objs="${extra_cxx_objs} ../libcpp.a" AC_DEFINE(USE_CPPLIB, 1,
dnl extra_c_flags="${extra_c_flags} -DUSE_CPPLIB=1" [Define if you want the preprocessor merged into the C and C++ compilers.
dnl fi) This mode is not ready for production use.])
fi)
# Enable Multibyte Characters for C/C++ # Enable Multibyte Characters for C/C++
AC_ARG_ENABLE(c-mbchar, AC_ARG_ENABLE(c-mbchar,
[ --enable-c-mbchar Enable multibyte characters for C and C++.], [ --enable-c-mbchar Enable multibyte characters for C and C++.],
if test x$enable_c_mbchar != xno; then if test x$enable_c_mbchar != xno; then
extra_c_flags="${extra_c_flags} -DMULTIBYTE_CHARS=1" AC_DEFINE(MULTIBYTE_CHARS, 1,
[Define if you want the C and C++ compilers to support multibyte
character sets for source code.])
fi) fi)
# Enable threads # Enable threads
......
...@@ -458,3 +458,11 @@ cpp_notice_from_errno (pfile, name) ...@@ -458,3 +458,11 @@ cpp_notice_from_errno (pfile, name)
name = "stdout"; name = "stdout";
cpp_notice (pfile, "%s: %s", name, xstrerror (errno)); cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
} }
const char *
cpp_type2name (type)
enum cpp_ttype type;
{
return (const char *) _cpp_token_spellings[type].name;
}
...@@ -1294,7 +1294,8 @@ lex_line (pfile, list) ...@@ -1294,7 +1294,8 @@ lex_line (pfile, list)
if (!(list->flags & LIST_OFFSET)) if (!(list->flags & LIST_OFFSET))
(abort) (); (abort) ();
retry:
list->file = buffer->nominal_fname; list->file = buffer->nominal_fname;
list->line = CPP_BUF_LINE (buffer); list->line = CPP_BUF_LINE (buffer);
pfile->col_adjust = 0; pfile->col_adjust = 0;
...@@ -1823,6 +1824,10 @@ lex_line (pfile, list) ...@@ -1823,6 +1824,10 @@ lex_line (pfile, list)
first[1].val.node->name); first[1].val.node->name);
else else
cpp_error (pfile, "invalid preprocessing directive"); cpp_error (pfile, "invalid preprocessing directive");
/* Discard this line to prevent further errors from cc1. */
_cpp_clear_toklist (list);
goto retry;
} }
/* Put EOF at end of known directives. This covers "directives do /* Put EOF at end of known directives. This covers "directives do
......
...@@ -477,7 +477,7 @@ do_line (pfile) ...@@ -477,7 +477,7 @@ do_line (pfile)
/* C99 raised the minimum limit on #line numbers. */ /* C99 raised the minimum limit on #line numbers. */
unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767;
int action_number = 0; int action_number = 0;
int enter = 0, leave = 0; int enter = 0, leave = 0, rename = 0;
enum cpp_ttype type; enum cpp_ttype type;
const U_CHAR *str; const U_CHAR *str;
char *fname; char *fname;
...@@ -492,7 +492,7 @@ do_line (pfile) ...@@ -492,7 +492,7 @@ do_line (pfile)
if (type != CPP_NUMBER || strtoul_for_line (str, len, &new_lineno)) if (type != CPP_NUMBER || strtoul_for_line (str, len, &new_lineno))
{ {
cpp_error (pfile, "token after #line is not a positive integer"); cpp_error (pfile, "token after #line is not a positive integer");
goto done; return;
} }
if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap)) if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
...@@ -511,7 +511,7 @@ do_line (pfile) ...@@ -511,7 +511,7 @@ do_line (pfile)
{ {
cpp_error (pfile, "second token after #line is not a string"); cpp_error (pfile, "second token after #line is not a string");
ip->lineno = old_lineno; /* malformed #line should have no effect */ ip->lineno = old_lineno; /* malformed #line should have no effect */
goto done; return;
} }
fname = alloca (len + 1); fname = alloca (len + 1);
...@@ -520,6 +520,7 @@ do_line (pfile) ...@@ -520,6 +520,7 @@ do_line (pfile)
if (strcmp (fname, ip->nominal_fname)) if (strcmp (fname, ip->nominal_fname))
{ {
rename = 1;
if (!strcmp (fname, ip->inc->name)) if (!strcmp (fname, ip->inc->name))
ip->nominal_fname = ip->inc->name; ip->nominal_fname = ip->inc->name;
else else
...@@ -527,7 +528,7 @@ do_line (pfile) ...@@ -527,7 +528,7 @@ do_line (pfile)
} }
if (read_line_number (pfile, &action_number) == 0) if (read_line_number (pfile, &action_number) == 0)
return; goto done;
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "garbage at end of #line"); cpp_pedwarn (pfile, "garbage at end of #line");
...@@ -555,13 +556,13 @@ do_line (pfile) ...@@ -555,13 +556,13 @@ do_line (pfile)
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
done:
if (enter && pfile->cb.enter_file) if (enter && pfile->cb.enter_file)
(*pfile->cb.enter_file) (pfile); (*pfile->cb.enter_file) (pfile);
if (leave && pfile->cb.leave_file) if (leave && pfile->cb.leave_file)
(*pfile->cb.leave_file) (pfile); (*pfile->cb.leave_file) (pfile);
if (rename && pfile->cb.rename_file)
done: (*pfile->cb.rename_file) (pfile);
return;
} }
/* /*
...@@ -610,7 +611,7 @@ do_ident (pfile) ...@@ -610,7 +611,7 @@ do_ident (pfile)
if (str->type == CPP_STRING && _cpp_get_token (pfile)->type == CPP_EOF) if (str->type == CPP_STRING && _cpp_get_token (pfile)->type == CPP_EOF)
{ {
if (pfile->cb.ident) if (pfile->cb.ident)
(*pfile->cb.ident) (pfile, str); (*pfile->cb.ident) (pfile, str->val.str.text, str->val.str.len);
return; return;
} }
......
...@@ -48,6 +48,7 @@ typedef struct cpp_hashnode cpp_hashnode; ...@@ -48,6 +48,7 @@ typedef struct cpp_hashnode cpp_hashnode;
/* Positions in the table. */ /* Positions in the table. */
#define CPP_LAST_EQ CPP_MAX #define CPP_LAST_EQ CPP_MAX
#define CPP_FIRST_DIGRAPH CPP_HASH #define CPP_FIRST_DIGRAPH CPP_HASH
#define CPP_LAST_PUNCTUATOR CPP_DOT_STAR
#define TTYPE_TABLE \ #define TTYPE_TABLE \
OP(CPP_EQ = 0, "=") \ OP(CPP_EQ = 0, "=") \
...@@ -522,12 +523,13 @@ struct cpp_reader ...@@ -522,12 +523,13 @@ struct cpp_reader
struct { struct {
void (*enter_file) PARAMS ((cpp_reader *)); void (*enter_file) PARAMS ((cpp_reader *));
void (*leave_file) PARAMS ((cpp_reader *)); void (*leave_file) PARAMS ((cpp_reader *));
void (*rename_file) PARAMS ((cpp_reader *));
void (*include) PARAMS ((cpp_reader *, const unsigned char *, void (*include) PARAMS ((cpp_reader *, const unsigned char *,
const unsigned char *, unsigned int, int)); const unsigned char *, unsigned int, int));
void (*define) PARAMS ((cpp_reader *, cpp_hashnode *)); void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *)); void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*poison) PARAMS ((cpp_reader *)); void (*poison) PARAMS ((cpp_reader *));
void (*ident) PARAMS ((cpp_reader *, const cpp_token *)); void (*ident) PARAMS ((cpp_reader *, const unsigned char *, unsigned int));
void (*def_pragma) PARAMS ((cpp_reader *)); void (*def_pragma) PARAMS ((cpp_reader *));
} cb; } cb;
...@@ -693,6 +695,8 @@ extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, ...@@ -693,6 +695,8 @@ extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *,
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *)); extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *)); extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
extern const char *cpp_type2name PARAMS ((enum cpp_ttype));
/* In cpplex.c */ /* In cpplex.c */
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *, extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
const unsigned char *, long)); const unsigned char *, long));
......
...@@ -595,7 +595,7 @@ dump_macro_args (fp, list) ...@@ -595,7 +595,7 @@ dump_macro_args (fp, list)
unsigned int len; unsigned int len;
len = ustrlen (param); len = ustrlen (param);
if (!list->flags & VAR_ARGS || ustrcmp (param, U"__VA_ARGS__")) if (!(list->flags & VAR_ARGS) || ustrcmp (param, U"__VA_ARGS__"))
ufputs (param, fp); ufputs (param, fp);
if (i < list->paramc) if (i < list->paramc)
fputs (", ", fp); fputs (", ", fp);
......
...@@ -39,9 +39,11 @@ static void cb_undef PARAMS ((cpp_reader *, cpp_hashnode *)); ...@@ -39,9 +39,11 @@ static void cb_undef PARAMS ((cpp_reader *, cpp_hashnode *));
static void cb_include PARAMS ((cpp_reader *, const unsigned char *, static void cb_include PARAMS ((cpp_reader *, const unsigned char *,
const unsigned char *, unsigned int, int)); const unsigned char *, unsigned int, int));
static void cb_ident PARAMS ((cpp_reader *, const cpp_token *)); static void cb_ident PARAMS ((cpp_reader *, const unsigned char *,
unsigned int));
static void cb_enter_file PARAMS ((cpp_reader *)); static void cb_enter_file PARAMS ((cpp_reader *));
static void cb_leave_file PARAMS ((cpp_reader *)); static void cb_leave_file PARAMS ((cpp_reader *));
static void cb_rename_file PARAMS ((cpp_reader *));
static void cb_def_pragma PARAMS ((cpp_reader *)); static void cb_def_pragma PARAMS ((cpp_reader *));
static void do_pragma_implementation PARAMS ((cpp_reader *)); static void do_pragma_implementation PARAMS ((cpp_reader *));
...@@ -90,6 +92,7 @@ main (argc, argv) ...@@ -90,6 +92,7 @@ main (argc, argv)
{ {
pfile->cb.enter_file = cb_enter_file; pfile->cb.enter_file = cb_enter_file;
pfile->cb.leave_file = cb_leave_file; pfile->cb.leave_file = cb_leave_file;
pfile->cb.rename_file = cb_rename_file;
} }
if (CPP_OPTION (pfile, dump_includes)) if (CPP_OPTION (pfile, dump_includes))
pfile->cb.include = cb_include; pfile->cb.include = cb_include;
...@@ -132,12 +135,12 @@ main (argc, argv) ...@@ -132,12 +135,12 @@ main (argc, argv)
/* Callbacks */ /* Callbacks */
static void static void
cb_ident (pfile, token) cb_ident (pfile, str, len)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *token; const unsigned char *str;
unsigned int len;
{ {
cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", (int) len, str);
(int) token->val.str.len, token->val.str.text);
} }
static void static void
...@@ -209,6 +212,19 @@ cb_leave_file (pfile) ...@@ -209,6 +212,19 @@ cb_leave_file (pfile)
} }
static void static void
cb_rename_file (pfile)
cpp_reader *pfile;
{
cpp_buffer *ip = CPP_BUFFER (pfile);
cpp_printf (pfile, &parse_out, "# %u \"%s\"%s\n", ip->lineno,
ip->nominal_fname, cpp_syshdr_flags (pfile, ip));
parse_out.lineno = ip->lineno;
parse_out.last_fname = ip->nominal_fname;
}
static void
cb_def_pragma (pfile) cb_def_pragma (pfile)
cpp_reader *pfile; cpp_reader *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