Commit dcc229e5 by Zack Weinberg

cpphash.h (struct lexer_state): Remove line_extension member.

	* cpphash.h (struct lexer_state): Remove line_extension member.
	* cpplib.c (dequote_string, do_linemarker): New functions.
	(linemarker_dir): New data object.
	(DIRECTIVE_TABLE): No longer need to interpret #line in
	preprocessed source.  Delete obsolete comment about return
	values of handlers.
	(end_directive, directive_diagnostics, _cpp_handle_directive):
	Don't muck with line_extension.
	(directive_diagnostics): No need to issue warnings for
	linemarkers here.
	(_cpp_handle_directive): Issue warnings for linemarkers here,
	when appropriate.  Dispatch linemarkers to do_linemarker, not
	do_line.
	(do_line): Code to handle linemarkers split out to do_linemarker.
	Convert escape sequences in filename argument, both places.

	* cppmacro.c (quote_string): Rename cpp_quote_string and
	export.  All callers changed.
	* cpplib.h (cpp_quote_string): Prototype.
	* cppmain.c (print_line): Call cpp_quote_string on to_file
	before printing it.

	* doc/cpp.texi: Document that escapes are now interpreted in
	#line and in linemarkers, and that non-printing characters are
	converted to octal escapes when linemarkers are generated.

From-SVN: r50779
parent 83a49407
......@@ -152,9 +152,6 @@ struct lexer_state
/* Nonzero when parsing arguments to a function-like macro. */
unsigned char parsing_args;
/* Nonzero when in a # NUMBER directive. */
unsigned char line_extension;
};
/* Special nodes - identifiers with predefined significance. */
......
......@@ -592,6 +592,9 @@ extern void cpp_forall_identifiers PARAMS ((cpp_reader *,
/* In cppmacro.c */
extern void cpp_scan_nooutput PARAMS ((cpp_reader *));
extern int cpp_sys_macro_p PARAMS ((cpp_reader *));
extern unsigned char *cpp_quote_string PARAMS ((unsigned char *,
const unsigned char *,
unsigned int));
/* In cppfiles.c */
extern int cpp_included PARAMS ((cpp_reader *, const char *));
......
......@@ -64,9 +64,6 @@ static cpp_context *next_context PARAMS ((cpp_reader *));
static const cpp_token *padding_token
PARAMS ((cpp_reader *, const cpp_token *));
static void expand_arg PARAMS ((cpp_reader *, macro_arg *));
static unsigned char *quote_string PARAMS ((unsigned char *,
const unsigned char *,
unsigned int));
static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *,
unsigned int));
static const cpp_token *new_number_token PARAMS ((cpp_reader *, unsigned int));
......@@ -164,7 +161,7 @@ builtin_macro (pfile, node)
name = map->to_file;
len = strlen (name);
buf = _cpp_unaligned_alloc (pfile, len * 4 + 1);
len = quote_string (buf, (const unsigned char *) name, len) - buf;
len = cpp_quote_string (buf, (const unsigned char *) name, len) - buf;
result = new_string_token (pfile, buf, len);
}
......@@ -244,9 +241,10 @@ builtin_macro (pfile, node)
/* Copies SRC, of length LEN, to DEST, adding backslashes before all
backslashes and double quotes. Non-printable characters are
converted to octal. DEST must be of sufficient size. */
static U_CHAR *
quote_string (dest, src, len)
converted to octal. DEST must be of sufficient size. Returns
a pointer to the end of the string. */
U_CHAR *
cpp_quote_string (dest, src, len)
U_CHAR *dest;
const U_CHAR *src;
unsigned int len;
......@@ -331,7 +329,7 @@ stringify_arg (pfile, arg)
_cpp_buff *buff = _cpp_get_buff (pfile, len);
unsigned char *buf = BUFF_FRONT (buff);
len = cpp_spell_token (pfile, token, buf) - buf;
dest = quote_string (dest, buf, len);
dest = cpp_quote_string (dest, buf, len);
_cpp_release_buff (pfile, buff);
}
else
......
......@@ -321,8 +321,17 @@ print_line (map, line, special_flags)
print.line = line;
if (! options->no_line_commands)
{
size_t to_file_len = strlen (map->to_file);
unsigned char *to_file_quoted = alloca (to_file_len * 4 + 1);
unsigned char *p;
/* cpp_quote_string does not nul-terminate, so we have to do it
ourselves. */
p = cpp_quote_string (to_file_quoted,
(unsigned char *)map->to_file, to_file_len);
*p = '\0';
fprintf (print.outf, "# %u \"%s\"%s",
SOURCE_LINE (map, print.line), map->to_file, special_flags);
SOURCE_LINE (map, print.line), to_file_quoted, special_flags);
if (map->sysp == 2)
fputs (" 3 4", print.outf);
......
......@@ -3087,6 +3087,13 @@ input. Subsequent lines are counted from @var{linenum}.
effect. In addition, @var{filename} is a string constant. The
following line and all subsequent lines are reported to come from the
file it specifies, until something else happens to change that.
@var{filename} is interpreted according to the normal rules for a string
constant: backslash escapes are interpreted. This is different from
@samp{#include}.
Previous versions of GNU CPP did not interpret escapes in @samp{#line};
we have changed it because the standard requires they be interpreted,
and most other compilers do.
@item #line @var{anything else}
@var{anything else} is checked for macro calls, which are expanded.
......@@ -3304,7 +3311,8 @@ of the form
These are called @dfn{linemarkers}. They are inserted as needed into
the output (but never within a string or character constant). They mean
that the following line originated in file @var{filename} at line
@var{linenum}.
@var{linenum}. @var{filename} will never contain any non-printing
characters; they are replaced with octal escape sequences.
After the file name comes zero or more flags, which are @samp{1},
@samp{2}, @samp{3}, or @samp{4}. If there are multiple flags, spaces
......@@ -3868,6 +3876,17 @@ The @samp{#line} directive used to change GCC's notion of the
a double-quoted header file name. In 3.0 and later, it does not.
@xref{Line Control}, for further explanation.
@item Syntax of @samp{#line}
In GCC 2.95 and previous, the string constant argument to @samp{#line}
was treated the same way as the argument to @samp{#include}: backslash
escapes were not honored, and the string ended at the second @samp{"}.
This is not compliant with the C standard. In GCC 3.0, an attempt was
made to correct the behavior, so that the string was treated as a real
string constant, but it turned out to be buggy. In 3.1, the bugs have
been fixed. (We are not fixing the bugs in 3.0 because they affect
relatively few people and the fix is quite invasive.)
@end itemize
@node Invocation
......
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