Commit 26aea073 by Neil Booth Committed by Neil Booth

cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove.

	* cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD,
	MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove.
	(struct include_file): Remove fefcnt, mapped members.
	(open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching.
	(read_include_file): Don't use mmap, terminate buffers in '\r'.
	(purge_cache): Don't use munmap.
	* cpphash.h (CPP_BUF_COLUMN): Update.
	(lexer_state): Remove lexing_comment.
	(struct _cpp_line_note): New.
	(struct cpp_buffer): New members cur_note, notes_used, notes_cap,
	next_line and need_line.  Remove col_adjust and saved_flags.
	(_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line,
	_cpp_skip_block_comment, scan_out_logical_line): New.
	(_cpp_init_mbchar): Remove.
	* cppinit.c (init_library): Remove call to _cpp_init_mbchar.
	(cpp_read_main_file): Set line to 1 earlier.
	(post_options): -traditional-cpp doesn't want trigraphs.
	* cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this.
	(add_line_note, _cpp_clean_line, _cpp_process_line_notes,
	_cpp_get_fresh_line): New.
	(handle_newline, skip_escaped_newlines, trigraph_p,
	continue_after_nul, _cpp_init_mbchar): Remove.
	(get_effective_char): Update.
	(_cpp_skip_block_comment): Rename from skip_block_comment, simplify.
	(skip_line_comment): Simplify.
	(skip_whitespace, parse_identifier, parse_slow, parse_number,
	parse_string): Update.
	(cpp_lex_direct): Use clean lines and process line notes.  Update.
	(cpp_interpret_charconst): No MULTIBYTE_CHARS.
	* cpplib.c (prepare_directive_trad): Call scan_out_logical_line
	directly.
	(_cpp_handle_directive): Don't set saved_flags.
	(run_directive, destringize_and_run, cpp_define, cpp_define_builtin,
	cpp_undef, handle_assertion, cpp_push_buffer): Update.
	(_cpp_pop_buffer): Free notes.
	* cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer.
	* cpppch.c (cpp_read_state): \n terminate buffer.
	* cpptrad.c (skip_escaped_newlines, handle_newline): Remove.
	(copy_comment): Use _cpp_skip_block_comment.
	(skip_whitespace, lex_identifier, _cpp_read_logical_line_trad):
	Simplify.
	(_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text,
	save_replacement_text): Update.
	(scan_out_logical_line): Update to use clean lines and process
	line notes.
	* fix-header.c (read_scan_file): Update.
testsuite:
	* gcc.dg/cpp/_Pragma4.c: Remove stray space.
	* gcc.dg/cpp/trad/escaped-eof.c: Correct line number.

From-SVN: r65808
parent 606c9991
2003-04-19 Neil Booth <neil@daikokuya.co.uk>
* cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD,
MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove.
(struct include_file): Remove fefcnt, mapped members.
(open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching.
(read_include_file): Don't use mmap, terminate buffers in '\r'.
(purge_cache): Don't use munmap.
* cpphash.h (CPP_BUF_COLUMN): Update.
(lexer_state): Remove lexing_comment.
(struct _cpp_line_note): New.
(struct cpp_buffer): New members cur_note, notes_used, notes_cap,
next_line and need_line. Remove col_adjust and saved_flags.
(_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line,
_cpp_skip_block_comment, scan_out_logical_line): New.
(_cpp_init_mbchar): Remove.
* cppinit.c (init_library): Remove call to _cpp_init_mbchar.
(cpp_read_main_file): Set line to 1 earlier.
(post_options): -traditional-cpp doesn't want trigraphs.
* cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this.
(add_line_note, _cpp_clean_line, _cpp_process_line_notes,
_cpp_get_fresh_line): New.
(handle_newline, skip_escaped_newlines, trigraph_p,
continue_after_nul, _cpp_init_mbchar): Remove.
(get_effective_char): Update.
(_cpp_skip_block_comment): Rename from skip_block_comment, simplify.
(skip_line_comment): Simplify.
(skip_whitespace, parse_identifier, parse_slow, parse_number,
parse_string): Update.
(cpp_lex_direct): Use clean lines and process line notes. Update.
(cpp_interpret_charconst): No MULTIBYTE_CHARS.
* cpplib.c (prepare_directive_trad): Call scan_out_logical_line
directly.
(_cpp_handle_directive): Don't set saved_flags.
(run_directive, destringize_and_run, cpp_define, cpp_define_builtin,
cpp_undef, handle_assertion, cpp_push_buffer): Update.
(_cpp_pop_buffer): Free notes.
* cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer.
* cpppch.c (cpp_read_state): \n terminate buffer.
* cpptrad.c (skip_escaped_newlines, handle_newline): Remove.
(copy_comment): Use _cpp_skip_block_comment.
(skip_whitespace, lex_identifier, _cpp_read_logical_line_trad):
Simplify.
(_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text,
save_replacement_text): Update.
(scan_out_logical_line): Update to use clean lines and process
line notes.
* fix-header.c (read_scan_file): Update.
2003-04-18 Douglas B Rupp <rupp@gnat.com> 2003-04-18 Douglas B Rupp <rupp@gnat.com>
* unwind-dw2-fde.c (__register_frame_info_bases): Check for * unwind-dw2-fde.c (__register_frame_info_bases): Check for
......
...@@ -30,47 +30,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -30,47 +30,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "intl.h" #include "intl.h"
#include "mkdeps.h" #include "mkdeps.h"
#include "splay-tree.h" #include "splay-tree.h"
#ifdef ENABLE_VALGRIND_CHECKING
# ifdef HAVE_MEMCHECK_H
# include <memcheck.h>
# else
# include <valgrind.h>
# endif
#else
/* Avoid #ifdef:s when we can help it. */
#define VALGRIND_DISCARD(x)
#endif
#ifdef HAVE_MMAP_FILE
# include <sys/mman.h>
# ifndef MMAP_THRESHOLD
# define MMAP_THRESHOLD 3 /* Minimum page count to mmap the file. */
# endif
# if MMAP_THRESHOLD
# define TEST_THRESHOLD(size, pagesize) \
(size / pagesize >= MMAP_THRESHOLD && (size % pagesize) != 0)
/* Use mmap if the file is big enough to be worth it (controlled
by MMAP_THRESHOLD) and if we can safely count on there being
at least one readable NUL byte after the end of the file's
contents. This is true for all tested operating systems when
the file size is not an exact multiple of the page size. */
# ifndef __CYGWIN__
# define SHOULD_MMAP(size, pagesize) TEST_THRESHOLD (size, pagesize)
# else
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
/* Cygwin can't correctly emulate mmap under Windows 9x style systems so
disallow use of mmap on those systems. Windows 9x does not zero fill
memory at EOF and beyond, as required. */
# define SHOULD_MMAP(size, pagesize) ((GetVersion() & 0x80000000) \
? 0 : TEST_THRESHOLD (size, pagesize))
# endif
# endif
#else /* No MMAP_FILE */
# undef MMAP_THRESHOLD
# define MMAP_THRESHOLD 0
#endif
#ifndef O_BINARY #ifndef O_BINARY
# define O_BINARY 0 # define O_BINARY 0
...@@ -102,8 +61,6 @@ struct include_file { ...@@ -102,8 +61,6 @@ struct include_file {
int fd; /* fd open on file (short term storage only) */ int fd; /* fd open on file (short term storage only) */
int err_no; /* errno obtained if opening a file failed */ int err_no; /* errno obtained if opening a file failed */
unsigned short include_count; /* number of times file has been read */ unsigned short include_count; /* number of times file has been read */
unsigned short refcnt; /* number of stacked buffers using this file */
unsigned char mapped; /* file buffer is mmapped */
unsigned char pch; /* 0: file not known to be a PCH. unsigned char pch; /* 0: file not known to be a PCH.
1: file is a PCH 1: file is a PCH
(on return from find_include_file). (on return from find_include_file).
...@@ -278,7 +235,7 @@ open_file (pfile, filename) ...@@ -278,7 +235,7 @@ open_file (pfile, filename)
return file; return file;
/* Don't reopen one which is already loaded. */ /* Don't reopen one which is already loaded. */
if (file->buffer != NULL) if (0 && file->buffer != NULL)
return file; return file;
/* We used to open files in nonblocking mode, but that caused more /* We used to open files in nonblocking mode, but that caused more
...@@ -446,7 +403,7 @@ stack_include_file (pfile, inc) ...@@ -446,7 +403,7 @@ stack_include_file (pfile, inc)
} }
/* Not in cache? */ /* Not in cache? */
if (! inc->buffer) if (1 || ! inc->buffer)
{ {
if (read_include_file (pfile, inc)) if (read_include_file (pfile, inc))
{ {
...@@ -471,7 +428,6 @@ stack_include_file (pfile, inc) ...@@ -471,7 +428,6 @@ stack_include_file (pfile, inc)
fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size, fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size,
/* from_stage3 */ CPP_OPTION (pfile, preprocessed), 0); /* from_stage3 */ CPP_OPTION (pfile, preprocessed), 0);
fp->inc = inc; fp->inc = inc;
fp->inc->refcnt++;
/* Initialize controlling macro state. */ /* Initialize controlling macro state. */
pfile->mi_valid = true; pfile->mi_valid = true;
...@@ -507,9 +463,6 @@ read_include_file (pfile, inc) ...@@ -507,9 +463,6 @@ read_include_file (pfile, inc)
{ {
ssize_t size, offset, count; ssize_t size, offset, count;
uchar *buf; uchar *buf;
#if MMAP_THRESHOLD
static int pagesize = -1;
#endif
if (S_ISREG (inc->st.st_mode)) if (S_ISREG (inc->st.st_mode))
{ {
...@@ -528,25 +481,6 @@ read_include_file (pfile, inc) ...@@ -528,25 +481,6 @@ read_include_file (pfile, inc)
} }
size = inc->st.st_size; size = inc->st.st_size;
inc->mapped = 0;
#if MMAP_THRESHOLD
if (pagesize == -1)
pagesize = getpagesize ();
if (SHOULD_MMAP (size, pagesize))
{
buf = (uchar *) mmap (0, size, PROT_READ, MAP_PRIVATE, inc->fd, 0);
if (buf == (uchar *) -1)
goto perror_fail;
/* We must tell Valgrind that the byte at buf[size] is actually
readable. Discard the handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (buf + size, 1));
inc->mapped = 1;
}
else
#endif
{ {
buf = (uchar *) xmalloc (size + 1); buf = (uchar *) xmalloc (size + 1);
offset = 0; offset = 0;
...@@ -567,8 +501,8 @@ read_include_file (pfile, inc) ...@@ -567,8 +501,8 @@ read_include_file (pfile, inc)
} }
offset += count; offset += count;
} }
/* The lexer requires that the buffer be NUL-terminated. */ /* The lexer requires that the buffer be \n-terminated. */
buf[size] = '\0'; buf[size] = '\n';
} }
} }
else if (S_ISBLK (inc->st.st_mode)) else if (S_ISBLK (inc->st.st_mode))
...@@ -600,8 +534,8 @@ read_include_file (pfile, inc) ...@@ -600,8 +534,8 @@ read_include_file (pfile, inc)
if (offset + 1 < size) if (offset + 1 < size)
buf = xrealloc (buf, offset + 1); buf = xrealloc (buf, offset + 1);
/* The lexer requires that the buffer be NUL-terminated. */ /* The lexer requires that the buffer be \n-terminated. */
buf[offset] = '\0'; buf[offset] = '\n';
inc->st.st_size = offset; inc->st.st_size = offset;
} }
...@@ -614,26 +548,14 @@ read_include_file (pfile, inc) ...@@ -614,26 +548,14 @@ read_include_file (pfile, inc)
return 1; return 1;
} }
/* Drop INC's buffer from memory, if we are unlikely to need it again. */ /* Drop INC's buffer from memory. */
static void static void
purge_cache (inc) purge_cache (inc)
struct include_file *inc; struct include_file *inc;
{ {
if (inc->buffer) if (inc->buffer)
{ {
#if MMAP_THRESHOLD free ((PTR) inc->buffer);
if (inc->mapped)
{
/* Undo the previous annotation for the
known-zero-byte-after-mmap. Discard the handle to avoid
handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (inc->buffer
+ inc->st.st_size, 1));
munmap ((PTR) inc->buffer, inc->st.st_size);
}
else
#endif
free ((PTR) inc->buffer);
inc->buffer = NULL; inc->buffer = NULL;
} }
} }
...@@ -929,9 +851,7 @@ _cpp_pop_file_buffer (pfile, inc) ...@@ -929,9 +851,7 @@ _cpp_pop_file_buffer (pfile, inc)
/* Invalidate control macros in the #including file. */ /* Invalidate control macros in the #including file. */
pfile->mi_valid = false; pfile->mi_valid = false;
inc->refcnt--; purge_cache (inc);
if (inc->refcnt == 0 && DO_NOT_REREAD (inc))
purge_cache (inc);
} }
/* Returns the first place in the include chain to start searching for /* Returns the first place in the include chain to start searching for
......
...@@ -45,7 +45,7 @@ typedef unsigned char uchar; ...@@ -45,7 +45,7 @@ typedef unsigned char uchar;
#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
#define CPP_BUFFER(PFILE) ((PFILE)->buffer) #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + (BUF)->col_adjust) #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur) #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
/* Maximum nesting of cpp_buffers. We use a static limit, partly for /* Maximum nesting of cpp_buffers. We use a static limit, partly for
...@@ -212,9 +212,6 @@ struct lexer_state ...@@ -212,9 +212,6 @@ struct lexer_state
all directives apart from #define. */ all directives apart from #define. */
unsigned char save_comments; unsigned char save_comments;
/* Nonzero if we're mid-comment. */
unsigned char lexing_comment;
/* Nonzero if lexing __VA_ARGS__ is valid. */ /* Nonzero if lexing __VA_ARGS__ is valid. */
unsigned char va_args_ok; unsigned char va_args_ok;
...@@ -240,17 +237,37 @@ struct spec_nodes ...@@ -240,17 +237,37 @@ struct spec_nodes
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
}; };
typedef struct _cpp_line_note _cpp_line_note;
struct _cpp_line_note
{
/* Location in the clean line the note refers to. */
const uchar *pos;
/* Type of note. */
enum { NOTE_ESC_NL = 0,
NOTE_ESC_SPACE_NL,
NOTE_TRIGRAPH,
NOTE_NEWLINE } type;
};
/* Represents the contents of a file cpplib has read in. */ /* Represents the contents of a file cpplib has read in. */
struct cpp_buffer struct cpp_buffer
{ {
const unsigned char *cur; /* current position */ const uchar *cur; /* Current location. */
const unsigned char *backup_to; /* if peeked character is not wanted */ const uchar *line_base; /* Start of current physical line. */
const unsigned char *rlimit; /* end of valid data */ const uchar *next_line; /* Start of to-be-cleaned logical line. */
const unsigned char *line_base; /* start of current line */
const uchar *buf; /* Entire character buffer. */
const uchar *rlimit; /* Writable byte at end of file. */
_cpp_line_note *notes; /* Array of notes. */
unsigned int cur_note; /* Next note to process. */
unsigned int notes_used; /* Number of notes. */
unsigned int notes_cap; /* Size of allocated array. */
struct cpp_buffer *prev; struct cpp_buffer *prev;
const unsigned char *buf; /* Entire character buffer. */ const unsigned char *backup_to; /* Soon to die. */
/* Pointer into the include table; non-NULL if this is a file /* Pointer into the include table; non-NULL if this is a file
buffer. Used for include_next and to record control macros. */ buffer. Used for include_next and to record control macros. */
...@@ -260,15 +277,8 @@ struct cpp_buffer ...@@ -260,15 +277,8 @@ struct cpp_buffer
Used to prohibit unmatched #endif (etc) in an include file. */ Used to prohibit unmatched #endif (etc) in an include file. */
struct if_stack *if_stack; struct if_stack *if_stack;
/* Token column position adjustment owing to tabs in whitespace. */ /* True if we need to get the next clean line. */
unsigned int col_adjust; bool need_line;
/* Contains PREV_WHITE and/or AVOID_LPASTE. */
unsigned char saved_flags;
/* Because of the way the lexer works, -Wtrigraphs can sometimes
warn twice for the same trigraph. This helps prevent that. */
const unsigned char *last_Wtrigraphs;
/* True if we have already warned about C++ comments in this file. /* True if we have already warned about C++ comments in this file.
The warning happens only for C89 extended mode with -pedantic on, The warning happens only for C89 extended mode with -pedantic on,
...@@ -503,13 +513,16 @@ extern bool _cpp_parse_expr PARAMS ((cpp_reader *)); ...@@ -503,13 +513,16 @@ extern bool _cpp_parse_expr PARAMS ((cpp_reader *));
extern struct op *_cpp_expand_op_stack PARAMS ((cpp_reader *)); extern struct op *_cpp_expand_op_stack PARAMS ((cpp_reader *));
/* In cpplex.c */ /* In cpplex.c */
extern void _cpp_process_line_notes PARAMS ((cpp_reader *, int));
extern void _cpp_clean_line PARAMS ((cpp_reader *));
extern bool _cpp_get_fresh_line PARAMS ((cpp_reader *));
extern bool _cpp_skip_block_comment PARAMS ((cpp_reader *));
extern cpp_token *_cpp_temp_token PARAMS ((cpp_reader *)); extern cpp_token *_cpp_temp_token PARAMS ((cpp_reader *));
extern const cpp_token *_cpp_lex_token PARAMS ((cpp_reader *)); extern const cpp_token *_cpp_lex_token PARAMS ((cpp_reader *));
extern cpp_token *_cpp_lex_direct PARAMS ((cpp_reader *)); extern cpp_token *_cpp_lex_direct PARAMS ((cpp_reader *));
extern int _cpp_equiv_tokens PARAMS ((const cpp_token *, extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
const cpp_token *)); const cpp_token *));
extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int)); extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int));
extern void _cpp_init_mbchar PARAMS ((void));
/* In cppinit.c. */ /* In cppinit.c. */
extern void _cpp_maybe_push_include_file PARAMS ((cpp_reader *)); extern void _cpp_maybe_push_include_file PARAMS ((cpp_reader *));
...@@ -529,6 +542,7 @@ extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum lc_reason, ...@@ -529,6 +542,7 @@ extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum lc_reason,
extern void _cpp_pop_buffer PARAMS ((cpp_reader *)); extern void _cpp_pop_buffer PARAMS ((cpp_reader *));
/* In cpptrad.c. */ /* In cpptrad.c. */
extern bool scan_out_logical_line PARAMS ((cpp_reader *, cpp_macro *));
extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *)); extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *));
extern void _cpp_overlay_buffer PARAMS ((cpp_reader *pfile, const uchar *, extern void _cpp_overlay_buffer PARAMS ((cpp_reader *pfile, const uchar *,
size_t)); size_t));
......
...@@ -125,8 +125,6 @@ init_library () ...@@ -125,8 +125,6 @@ init_library ()
we were compiled with a compiler that supports C99 designated we were compiled with a compiler that supports C99 designated
initializers. */ initializers. */
init_trigraph_map (); init_trigraph_map ();
_cpp_init_mbchar ();
} }
} }
...@@ -167,7 +165,6 @@ cpp_create_reader (lang, table) ...@@ -167,7 +165,6 @@ cpp_create_reader (lang, table)
/* Initialize the line map. Start at logical line 1, so we can use /* Initialize the line map. Start at logical line 1, so we can use
a line number of zero for special states. */ a line number of zero for special states. */
init_line_maps (&pfile->line_maps); init_line_maps (&pfile->line_maps);
pfile->line = 1;
/* Initialize lexer state. */ /* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
...@@ -454,6 +451,7 @@ cpp_read_main_file (pfile, fname) ...@@ -454,6 +451,7 @@ cpp_read_main_file (pfile, fname)
} }
/* Open the main input file. */ /* Open the main input file. */
pfile->line = 1;
if (!_cpp_read_file (pfile, fname)) if (!_cpp_read_file (pfile, fname))
return NULL; return NULL;
...@@ -556,7 +554,11 @@ post_options (pfile) ...@@ -556,7 +554,11 @@ post_options (pfile)
CPP_OPTION (pfile, traditional) = 0; CPP_OPTION (pfile, traditional) = 0;
} }
/* Traditional CPP does not accurately track column information. */
if (CPP_OPTION (pfile, traditional)) if (CPP_OPTION (pfile, traditional))
CPP_OPTION (pfile, show_column) = 0; {
/* Traditional CPP does not accurately track column information. */
CPP_OPTION (pfile, show_column) = 0;
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, warn_trigraphs) = 0;
}
} }
...@@ -295,7 +295,7 @@ prepare_directive_trad (pfile) ...@@ -295,7 +295,7 @@ prepare_directive_trad (pfile)
|| pfile->directive == &dtable[T_ELIF]); || pfile->directive == &dtable[T_ELIF]);
if (no_expand) if (no_expand)
pfile->state.prevent_expansion++; pfile->state.prevent_expansion++;
_cpp_read_logical_line_trad (pfile); scan_out_logical_line (pfile, NULL);
if (no_expand) if (no_expand)
pfile->state.prevent_expansion--; pfile->state.prevent_expansion--;
pfile->state.skipping = was_skipping; pfile->state.skipping = was_skipping;
...@@ -451,13 +451,12 @@ _cpp_handle_directive (pfile, indented) ...@@ -451,13 +451,12 @@ _cpp_handle_directive (pfile, indented)
/* Restore state when within macro args. */ /* Restore state when within macro args. */
pfile->state.parsing_args = 2; pfile->state.parsing_args = 2;
pfile->state.prevent_expansion = 1; pfile->state.prevent_expansion = 1;
pfile->buffer->saved_flags |= PREV_WHITE;
} }
return skip; return skip;
} }
/* Directive handler wrapper used by the command line option /* Directive handler wrapper used by the command line option
processor. */ processor. BUF is \n terminated. */
static void static void
run_directive (pfile, dir_no, buf, count) run_directive (pfile, dir_no, buf, count)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -471,8 +470,11 @@ run_directive (pfile, dir_no, buf, count) ...@@ -471,8 +470,11 @@ run_directive (pfile, dir_no, buf, count)
if (dir_no == T_PRAGMA) if (dir_no == T_PRAGMA)
pfile->buffer->inc = pfile->buffer->prev->inc; pfile->buffer->inc = pfile->buffer->prev->inc;
start_directive (pfile); start_directive (pfile);
/* We don't want a leading # to be interpreted as a directive. */
pfile->buffer->saved_flags = 0; /* This is a short-term fix to prevent a leading '#' being
interpreted as a directive. */
_cpp_clean_line (pfile);
pfile->directive = &dtable[dir_no]; pfile->directive = &dtable[dir_no];
if (CPP_OPTION (pfile, traditional)) if (CPP_OPTION (pfile, traditional))
prepare_directive_trad (pfile); prepare_directive_trad (pfile);
...@@ -1378,7 +1380,7 @@ destringize_and_run (pfile, in) ...@@ -1378,7 +1380,7 @@ destringize_and_run (pfile, in)
src++; src++;
*dest++ = *src++; *dest++ = *src++;
} }
*dest = '\0'; *dest = '\n';
/* Ugh; an awful kludge. We are really not set up to be lexing /* Ugh; an awful kludge. We are really not set up to be lexing
tokens when in the middle of a macro expansion. Use a new tokens when in the middle of a macro expansion. Use a new
...@@ -1904,7 +1906,7 @@ cpp_define (pfile, str) ...@@ -1904,7 +1906,7 @@ cpp_define (pfile, str)
buf[count++] = ' '; buf[count++] = ' ';
buf[count++] = '1'; buf[count++] = '1';
} }
buf[count] = '\0'; buf[count] = '\n';
run_directive (pfile, T_DEFINE, buf, count); run_directive (pfile, T_DEFINE, buf, count);
} }
...@@ -1915,7 +1917,11 @@ _cpp_define_builtin (pfile, str) ...@@ -1915,7 +1917,11 @@ _cpp_define_builtin (pfile, str)
cpp_reader *pfile; cpp_reader *pfile;
const char *str; const char *str;
{ {
run_directive (pfile, T_DEFINE, str, strlen (str)); size_t len = strlen (str);
char *buf = alloca (len + 1);
memcpy (buf, str, len);
buf[len] = '\n';
run_directive (pfile, T_DEFINE, buf, len);
} }
/* Process MACRO as if it appeared as the body of an #undef. */ /* Process MACRO as if it appeared as the body of an #undef. */
...@@ -1924,7 +1930,11 @@ cpp_undef (pfile, macro) ...@@ -1924,7 +1930,11 @@ cpp_undef (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
const char *macro; const char *macro;
{ {
run_directive (pfile, T_UNDEF, macro, strlen (macro)); size_t len = strlen (macro);
char *buf = alloca (len + 1);
memcpy (buf, macro, len);
buf[len] = '\n';
run_directive (pfile, T_UNDEF, buf, len);
} }
/* 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. */
...@@ -1955,18 +1965,18 @@ handle_assertion (pfile, str, type) ...@@ -1955,18 +1965,18 @@ handle_assertion (pfile, str, type)
size_t count = strlen (str); size_t count = strlen (str);
const char *p = strchr (str, '='); const char *p = strchr (str, '=');
/* Copy the entire option so we can modify it. Change the first
"=" in the string to a '(', and tack a ')' on the end. */
char *buf = (char *) alloca (count + 2);
memcpy (buf, str, count);
if (p) if (p)
{ {
/* Copy the entire option so we can modify it. Change the first
"=" in the string to a '(', and tack a ')' on the end. */
char *buf = (char *) alloca (count + 2);
memcpy (buf, str, count);
buf[p - str] = '('; buf[p - str] = '(';
buf[count++] = ')'; buf[count++] = ')';
buf[count] = '\0';
str = buf;
} }
buf[count] = '\n';
str = buf;
run_directive (pfile, type, str, count); run_directive (pfile, type, str, count);
} }
...@@ -2028,15 +2038,14 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof) ...@@ -2028,15 +2038,14 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof)
/* Clears, amongst other things, if_stack and mi_cmacro. */ /* Clears, amongst other things, if_stack and mi_cmacro. */
memset (new, 0, sizeof (cpp_buffer)); memset (new, 0, sizeof (cpp_buffer));
new->line_base = new->buf = new->cur = buffer; new->next_line = new->buf = buffer;
new->rlimit = buffer + len; new->rlimit = buffer + len;
new->from_stage3 = from_stage3 || CPP_OPTION (pfile, traditional); new->from_stage3 = from_stage3;
new->prev = pfile->buffer; new->prev = pfile->buffer;
new->return_at_eof = return_at_eof; new->return_at_eof = return_at_eof;
new->saved_flags = BOL; new->need_line = true;
pfile->buffer = new; pfile->buffer = new;
return new; return new;
} }
...@@ -2062,6 +2071,8 @@ _cpp_pop_buffer (pfile) ...@@ -2062,6 +2071,8 @@ _cpp_pop_buffer (pfile)
/* _cpp_do_file_change expects pfile->buffer to be the new one. */ /* _cpp_do_file_change expects pfile->buffer to be the new one. */
pfile->buffer = buffer->prev; pfile->buffer = buffer->prev;
free (buffer->notes);
/* Free the buffer object now; we may want to push a new buffer /* Free the buffer object now; we may want to push a new buffer
in _cpp_push_next_include_file. */ in _cpp_push_next_include_file. */
obstack_free (&pfile->buffer_ob, buffer); obstack_free (&pfile->buffer_ob, buffer);
......
...@@ -265,6 +265,8 @@ builtin_macro (pfile, node) ...@@ -265,6 +265,8 @@ builtin_macro (pfile, node)
cpp_hashnode *node; cpp_hashnode *node;
{ {
const uchar *buf; const uchar *buf;
size_t len;
char *nbuf;
if (node->value.builtin == BT_PRAGMA) if (node->value.builtin == BT_PRAGMA)
{ {
...@@ -278,14 +280,13 @@ builtin_macro (pfile, node) ...@@ -278,14 +280,13 @@ builtin_macro (pfile, node)
} }
buf = _cpp_builtin_macro_text (pfile, node); buf = _cpp_builtin_macro_text (pfile, node);
len = ustrlen (buf);
nbuf = alloca (len + 1);
memcpy (nbuf, buf, len);
nbuf[len]='\n';
cpp_push_buffer (pfile, buf, ustrlen (buf), /* from_stage3 */ true, 1); cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true, 1);
_cpp_clean_line (pfile);
/* Tweak the column number the lexer will report. */
pfile->buffer->col_adjust = pfile->cur_token[-1].col - 1;
/* We don't want a leading # to be interpreted as a directive. */
pfile->buffer->saved_flags = 0;
/* Set pfile->cur_token as required by _cpp_lex_direct. */ /* Set pfile->cur_token as required by _cpp_lex_direct. */
pfile->cur_token = _cpp_temp_token (pfile); pfile->cur_token = _cpp_temp_token (pfile);
...@@ -445,15 +446,10 @@ paste_tokens (pfile, plhs, rhs) ...@@ -445,15 +446,10 @@ paste_tokens (pfile, plhs, rhs)
if (lhs->type == CPP_DIV && rhs->type != CPP_EQ) if (lhs->type == CPP_DIV && rhs->type != CPP_EQ)
*end++ = ' '; *end++ = ' ';
end = cpp_spell_token (pfile, rhs, end); end = cpp_spell_token (pfile, rhs, end);
*end = '\0'; *end = '\n';
cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true, 1); cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true, 1);
_cpp_clean_line (pfile);
/* Tweak the column number the lexer will report. */
pfile->buffer->col_adjust = pfile->cur_token[-1].col - 1;
/* We don't want a leading # to be interpreted as a directive. */
pfile->buffer->saved_flags = 0;
/* Set pfile->cur_token as required by _cpp_lex_direct. */ /* Set pfile->cur_token as required by _cpp_lex_direct. */
pfile->cur_token = _cpp_temp_token (pfile); pfile->cur_token = _cpp_temp_token (pfile);
......
...@@ -708,7 +708,7 @@ cpp_read_state (r, name, f, data) ...@@ -708,7 +708,7 @@ cpp_read_state (r, name, f, data)
if (fread (defn, 1, m.definition_length, f) != m.definition_length) if (fread (defn, 1, m.definition_length, f) != m.definition_length)
goto error; goto error;
defn[m.definition_length] = '\0'; defn[m.definition_length] = '\n';
h = cpp_lookup (r, defn, m.name_length); h = cpp_lookup (r, defn, m.name_length);
...@@ -722,6 +722,7 @@ cpp_read_state (r, name, f, data) ...@@ -722,6 +722,7 @@ cpp_read_state (r, name, f, data)
m.definition_length - m.name_length, m.definition_length - m.name_length,
true, 1) != NULL) true, 1) != NULL)
{ {
_cpp_clean_line (r);
if (!_cpp_create_definition (r, h)) if (!_cpp_create_definition (r, h))
abort (); abort ();
_cpp_pop_buffer (r); _cpp_pop_buffer (r);
......
...@@ -692,7 +692,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -692,7 +692,7 @@ read_scan_file (in_fname, argc, argv)
if (special_file_handling == stdio_h if (special_file_handling == stdio_h
&& (fn = lookup_std_proto ("_filbuf", 7)) != NULL) && (fn = lookup_std_proto ("_filbuf", 7)) != NULL)
{ {
static const unsigned char getchar_call[] = "getchar();"; unsigned char getchar_call[] = "getchar();\n";
int seen_filbuf = 0; int seen_filbuf = 0;
/* Scan the macro expansion of "getchar();". */ /* Scan the macro expansion of "getchar();". */
......
2003-04-19 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/cpp/_Pragma4.c: Remove stray space.
* gcc.dg/cpp/trad/escaped-eof.c: Correct line number.
2003-04-18 Eric Botcazou <ebotcazou@libertysurf.fr> 2003-04-18 Eric Botcazou <ebotcazou@libertysurf.fr>
* gcc.c-torture/compile/20030418-1.c: New test. * gcc.c-torture/compile/20030418-1.c: New test.
......
...@@ -7,6 +7,6 @@ a b c ...@@ -7,6 +7,6 @@ a b c
/* /*
{ dg-final { if ![file exists _Pragma4.i] { return } } } { dg-final { if ![file exists _Pragma4.i] { return } } }
{ dg-final { if { [grep _Pragma4.i "#pragma bar "] != "" } { return } } } { dg-final { if { [grep _Pragma4.i "#pragma bar"] != "" } { return } } }
{ dg-final { fail "_Pragma4.c: #pragma appearing on its own line" } } { dg-final { fail "_Pragma4.c: #pragma appearing on its own line" } }
*/ */
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
/* { dg-do preprocess } */ /* { dg-do preprocess } */
/* { dg-warning "backslash-new" "escaped EOF warning" { target *-*-* } 7 } */ /* { dg-warning "backslash-new" "escaped EOF warning" { target *-*-* } 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