This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
More adjustments to cpplib to support the integrated preprocessor
- To: gcc-patches at gcc dot gnu dot org
- Subject: More adjustments to cpplib to support the integrated preprocessor
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Wed, 9 Aug 2000 12:34:02 -0700
This patch corrects a number of problems in cpplib which showed up
while working on the integrated preprocessor. Most of them are
invisible in the standalone preprocessor, but there are a couple of
places where they fix bugs in that mode - notably with the ordering of
#line and #pragma interface.
zw
* 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.
===================================================================
Index: cpperror.c
--- cpperror.c 2000/08/02 01:13:42 1.35
+++ cpperror.c 2000/08/09 19:29:17
@@ -458,3 +458,11 @@ cpp_notice_from_errno (pfile, name)
name = "stdout";
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;
+}
+
===================================================================
Index: cpplex.c
--- cpplex.c 2000/08/04 01:30:05 1.86
+++ cpplex.c 2000/08/09 19:29:26
@@ -1294,7 +1294,8 @@ lex_line (pfile, list)
if (!(list->flags & LIST_OFFSET))
(abort) ();
-
+
+ retry:
list->file = buffer->nominal_fname;
list->line = CPP_BUF_LINE (buffer);
pfile->col_adjust = 0;
@@ -1823,6 +1824,10 @@ lex_line (pfile, list)
first[1].val.node->name);
else
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
===================================================================
Index: cpplib.c
--- cpplib.c 2000/08/04 01:30:05 1.196
+++ cpplib.c 2000/08/09 19:29:26
@@ -477,7 +477,7 @@ do_line (pfile)
/* C99 raised the minimum limit on #line numbers. */
unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767;
int action_number = 0;
- int enter = 0, leave = 0;
+ int enter = 0, leave = 0, rename = 0;
enum cpp_ttype type;
const U_CHAR *str;
char *fname;
@@ -492,7 +492,7 @@ do_line (pfile)
if (type != CPP_NUMBER || strtoul_for_line (str, len, &new_lineno))
{
cpp_error (pfile, "token after #line is not a positive integer");
- goto done;
+ return;
}
if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
@@ -511,7 +511,7 @@ do_line (pfile)
{
cpp_error (pfile, "second token after #line is not a string");
ip->lineno = old_lineno; /* malformed #line should have no effect */
- goto done;
+ return;
}
fname = alloca (len + 1);
@@ -520,6 +520,7 @@ do_line (pfile)
if (strcmp (fname, ip->nominal_fname))
{
+ rename = 1;
if (!strcmp (fname, ip->inc->name))
ip->nominal_fname = ip->inc->name;
else
@@ -527,7 +528,7 @@ do_line (pfile)
}
if (read_line_number (pfile, &action_number) == 0)
- return;
+ goto done;
if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "garbage at end of #line");
@@ -555,13 +556,13 @@ do_line (pfile)
read_line_number (pfile, &action_number);
}
+ done:
if (enter && pfile->cb.enter_file)
(*pfile->cb.enter_file) (pfile);
if (leave && pfile->cb.leave_file)
(*pfile->cb.leave_file) (pfile);
-
- done:
- return;
+ if (rename && pfile->cb.rename_file)
+ (*pfile->cb.rename_file) (pfile);
}
/*
@@ -610,7 +611,7 @@ do_ident (pfile)
if (str->type == CPP_STRING && _cpp_get_token (pfile)->type == CPP_EOF)
{
if (pfile->cb.ident)
- (*pfile->cb.ident) (pfile, str);
+ (*pfile->cb.ident) (pfile, str->val.str.text, str->val.str.len);
return;
}
===================================================================
Index: cpplib.h
--- cpplib.h 2000/08/04 01:30:05 1.116
+++ cpplib.h 2000/08/09 19:29:26
@@ -48,6 +48,7 @@ typedef struct cpp_hashnode cpp_hashnode
/* Positions in the table. */
#define CPP_LAST_EQ CPP_MAX
#define CPP_FIRST_DIGRAPH CPP_HASH
+#define CPP_LAST_PUNCTUATOR CPP_DOT_STAR
#define TTYPE_TABLE \
OP(CPP_EQ = 0, "=") \
@@ -522,12 +523,13 @@ struct cpp_reader
struct {
void (*enter_file) PARAMS ((cpp_reader *));
void (*leave_file) PARAMS ((cpp_reader *));
+ void (*rename_file) PARAMS ((cpp_reader *));
void (*include) PARAMS ((cpp_reader *, const unsigned char *,
const unsigned char *, unsigned int, int));
void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *));
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 *));
} cb;
@@ -692,6 +694,8 @@ extern void cpp_pedwarn_with_file_and_li
ATTRIBUTE_PRINTF_5;
extern void cpp_error_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 */
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
===================================================================
Index: cppmacro.c
--- cppmacro.c 2000/08/04 01:30:06 1.7
+++ cppmacro.c 2000/08/09 19:29:26
@@ -595,7 +595,7 @@ dump_macro_args (fp, list)
unsigned int len;
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);
if (i < list->paramc)
fputs (", ", fp);
===================================================================
Index: cppmain.c
--- cppmain.c 2000/08/05 00:50:00 1.32
+++ cppmain.c 2000/08/09 19:29:26
@@ -39,9 +39,11 @@ static void cb_undef PARAMS ((cpp_reader
static void cb_include PARAMS ((cpp_reader *, const unsigned char *,
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_leave_file PARAMS ((cpp_reader *));
+static void cb_rename_file PARAMS ((cpp_reader *));
static void cb_def_pragma PARAMS ((cpp_reader *));
static void do_pragma_implementation PARAMS ((cpp_reader *));
@@ -90,6 +92,7 @@ main (argc, argv)
{
pfile->cb.enter_file = cb_enter_file;
pfile->cb.leave_file = cb_leave_file;
+ pfile->cb.rename_file = cb_rename_file;
}
if (CPP_OPTION (pfile, dump_includes))
pfile->cb.include = cb_include;
@@ -132,12 +135,12 @@ main (argc, argv)
/* Callbacks */
static void
-cb_ident (pfile, token)
+cb_ident (pfile, str, len)
cpp_reader *pfile;
- const cpp_token *token;
+ const unsigned char *str;
+ unsigned int len;
{
- cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n",
- (int) token->val.str.len, token->val.str.text);
+ cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", (int) len, str);
}
static void
@@ -202,6 +205,19 @@ cb_leave_file (pfile)
cpp_buffer *ip = CPP_BUFFER (pfile);
cpp_printf (pfile, &parse_out, "# %u \"%s\" 2%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_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;