Commit a58d32c2 by Zack Weinberg Committed by Zack Weinberg

cppfiles.c: Move all default-#defines to top of file.

	* cppfiles.c: Move all default-#defines to top of file.
	(open_include_file): Replace by lookup_include_file.
	(read_with_read, read_file): Merged into read_include_file.
	(stack_include_file, purge_cache): New functions.
	(close_cached_fd): Delete.
	(lookup_include_file, read_include_file, _cpp_pop_file_buffer):
	Cache the in-memory buffer, not the file descriptor.

	* cpphash.h (struct include_file): Add buffer, st, refcnt,
	mapped fields.
	(xcnew): New utility macro.
	(DO_NOT_REREAD, NEVER_REREAD): Move up by struct include_file.
	* cpplib.h (struct cpp_buffer): Remove mapped field.

	* cpplex.c (parse_string): Accept backslash space newline as a
	line continuation.
	(lex_line): Likewise.
	(_cpp_get_token): Remove hard limit on macro nesting.

testsuite:
	* gcc.dg/cpp/backslash.c: New test.

From-SVN: r36347
parent 4ba01ed2
2000-09-11 Zack Weinberg <zack@wolery.cumb.org>
* cppfiles.c: Move all default-#defines to top of file.
(open_include_file): Replace by lookup_include_file.
(read_with_read, read_file): Merged into read_include_file.
(stack_include_file, purge_cache): New functions.
(close_cached_fd): Delete.
(lookup_include_file, read_include_file, _cpp_pop_file_buffer):
Cache the in-memory buffer, not the file descriptor.
* cpphash.h (struct include_file): Add buffer, st, refcnt,
mapped fields.
(xcnew): New utility macro.
(DO_NOT_REREAD, NEVER_REREAD): Move up by struct include_file.
* cpplib.h (struct cpp_buffer): Remove mapped field.
2000-09-11 Zack Weinberg <zack@wolery.cumb.org>
* cpplex.c (parse_string): Accept backslash space newline as a
line continuation.
(lex_line): Likewise.
(_cpp_get_token): Remove hard limit on macro nesting.
2000-09-12 Philipp Thomas <pthomas@suse.de>
* aclocal.m4 (AM_WITH_NLS): Don't force use of included gettext.
......
......@@ -115,12 +115,24 @@ struct include_file
const struct file_name_list *foundhere;
/* location in search path where file was
found, for #include_next */
int fd; /* file descriptor possibly open on file */
const unsigned char *buffer; /* pointer to cached file contents */
struct stat st; /* copy of stat(2) data for file */
int fd; /* fd open on file (short term storage only) */
unsigned short include_count; /* number of times file has been read */
unsigned short sysp; /* file is a system header */
time_t date; /* modification date of file, if known */
unsigned short refcnt; /* number of stacked buffers using this file */
unsigned char sysp; /* file is a system header */
unsigned char mapped; /* file buffer is mmapped */
};
/* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is
to be included again if the macro is not defined. */
#define NEVER_REREAD ((const cpp_hashnode *)-1)
#define DO_NOT_REREAD(inc) \
((inc)->cmacro && \
((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
/* Special nodes - identifiers with predefined significance.
Note that the array length of dirs[] must be kept in sync with
cpplib.c's dtable[]. */
......@@ -133,16 +145,6 @@ struct spec_nodes
cpp_hashnode *dirs[19]; /* 19 directives counting #sccs */
};
/* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is
to be included again if the macro is not defined. */
#define NEVER_REREAD ((const cpp_hashnode *)-1)
#define DO_NOT_REREAD(inc) \
((inc)->cmacro && \
((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
/* Character classes.
If the definition of `numchar' looks odd to you, please look up the
definition of a pp-number in the C standard [section 6.4.8 of C99].
......@@ -293,6 +295,7 @@ extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
/* Utility routines and macros. */
#define xnew(T) (T *) xmalloc (sizeof(T))
#define xcnew(T) (T *) xcalloc (1, sizeof(T))
#define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
#define xcnewvec(T, N) (T *) xcalloc (N, sizeof(T))
#define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T))
......
......@@ -1106,12 +1106,23 @@ parse_string (pfile, list, token, terminator)
if (is_vspace (c))
{
/* Drop a backslash newline, and continue. */
U_CHAR *old = namebuf;
while (namebuf > list->namebuf && is_hspace (namebuf[-1]))
namebuf--;
if (namebuf > list->namebuf && namebuf[-1] == '\\')
{
handle_newline (cur, buffer->rlimit, c);
namebuf--;
if (old[-1] != '\\')
{
buffer->cur = cur;
cpp_warning (pfile,
"backslash and newline separated by space");
}
continue;
}
else
namebuf = old;
cur--;
......@@ -1516,37 +1527,40 @@ lex_line (pfile, list)
handle_newline (cur, buffer->rlimit, c);
if (PREV_TOKEN_TYPE == CPP_BACKSLASH)
{
if (IMMED_TOKEN ())
{
/* Remove the escaped newline. Then continue to process
any interrupted name or number. */
cur_token--;
/* Backslash-newline may not be immediately followed by
EOF (C99 5.1.1.2). */
if (cur >= buffer->rlimit)
{
cpp_pedwarn (pfile, "backslash-newline at end of file");
break;
}
if (IMMED_TOKEN ())
{
cur_token--;
if (cur_token->type == CPP_NAME)
goto continue_name;
else if (cur_token->type == CPP_NUMBER)
goto continue_number;
cur_token++;
}
/* Remember whitespace setting. */
flags = cur_token->flags;
break;
}
else
/* backslash space newline is still treated as backslash-newline;
we think this is standard conforming, with some reservations
about actually _using_ the weasel words in C99 5.1.1.2
(translation phase 1 is allowed to do whatever it wants to
your input as long as it's documented). */
if (! IMMED_TOKEN ())
{
buffer->cur = cur;
cpp_warning (pfile,
"backslash and newline separated by space");
}
/* Remove the escaped newline. Then continue to process
any interrupted name or number. */
cur_token--;
/* Backslash-newline may not be immediately followed by
EOF (C99 5.1.1.2). */
if (cur >= buffer->rlimit)
{
cpp_pedwarn (pfile, "backslash-newline at end of file");
break;
}
if (IMMED_TOKEN ())
{
cur_token--;
if (cur_token->type == CPP_NAME)
goto continue_name;
else if (cur_token->type == CPP_NUMBER)
goto continue_number;
cur_token++;
}
/* Remember whitespace setting. */
flags = cur_token->flags;
break;
}
else if (MIGHT_BE_DIRECTIVE ())
{
......@@ -3187,12 +3201,6 @@ _cpp_get_token (pfile)
if (is_macro_disabled (pfile, node->value.expansion, token))
return token;
if (pfile->cur_context > CPP_STACK_MAX)
{
cpp_error (pfile, "macros nested too deep invoking '%s'", node->name);
return token;
}
if (push_macro_context (pfile, token))
return token;
/* else loop */
......
......@@ -246,9 +246,6 @@ struct cpp_buffer
or for -Wtraditional, and only once per file (otherwise it would
be far too noisy). */
char warned_cplusplus_comments;
/* True if this buffer's data is mmapped. */
char mapped;
};
struct file_name_map_list;
......
2000-09-11 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp/backslash.c: New test.
2000-09-11 Alexandre Oliva <aoliva@redhat.com>
* gcc.c-torture/execute/20000910-1.c: New test.
......
/* Test backslash newline with and without trailing spaces. */
#define alpha(a, b, c) \
a, \
b, \
c
/* Note the trailing whitespace on the next three lines. */
#define beta(a, b, c) \
a, \
b, \
c
/* { dg-warning "separated by space" "space" { target *-*-* } 9 } */
/* { dg-warning "separated by space" "tab" { target *-*-* } 10 } */
/* { dg-warning "separated by space" "space and tab" { target *-*-* } 11 } */
int x[] = {
alpha(1, 2, 3),
beta(4, 5, 6)
};
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