Partially revert/redo 2003-10-01 change; fix -fworking-directory.
* c-ppoutput.c (pp_dir_change): New function. * c-common.h (pp_dir_change): New declaration. * cpplib.h (struct cpp_options): Remove working_directory field. * cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to (cpp_read_main_file): as before 10-01. Call _cpp_stack_file. Don't handle -fworking_directory here, but in c_common_post_options. (read_original_directory): Don't back up when done. Don't clear no-longer used working_directory flag. * cpplib.h: Update declarations to match. * c-lex.c (cb_dir_change): Move to c-opts.c. (init_c_lex): Don't set dir_change callback here, since we want to set it even if flag_preprocess_only. * c-opts.c (cb_dir_change): Function moved from c-lex.c. (c_common_post_options): Set dir_change callback. Call pp_dir_change if approporiate. (finish_options): Don't call cpp_find_main_file here. Hence remove unneeded parameter and result. Do LC_RENAME for <built-in>. (c_common_post_options): Call cpp_read_main_file here instead. (c_common_init): Update accordingly. (push_command_line_include): Don't cpp_push_main_file. Do LC_RENAME rather than LC_LEASE to get back to main file. Compared to pre-10-01 version, inline cpp_rename_to_main_file. (c_common_parse_file): Call cpp_read_main_file for subsequent main files, but call finish_options for all files. * c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory. * fix-header.c (read_scan_file): Call cpp_read_main_file instead of cpp_find_main_file + cpp_push_main_file. * c-lex.c (fe_file_change): Don't set main_input_filename here. * opts.c (handle_options): Only set main_input_filename first time. From-SVN: r77303
This commit is contained in:
parent
5384443a5f
commit
8e9ea4d72c
@ -1,3 +1,36 @@
|
||||
2004-02-04 Per Bothner <per@bothner.com>
|
||||
|
||||
Partially revert/redo 2003-10-01 change; fix -fworking-directory.
|
||||
* c-ppoutput.c (pp_dir_change): New function.
|
||||
* c-common.h (pp_dir_change): New declaration.
|
||||
* cpplib.h (struct cpp_options): Remove working_directory field.
|
||||
* cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to
|
||||
(cpp_read_main_file): as before 10-01. Call _cpp_stack_file.
|
||||
Don't handle -fworking_directory here, but in c_common_post_options.
|
||||
(read_original_directory): Don't back up when done.
|
||||
Don't clear no-longer used working_directory flag.
|
||||
* cpplib.h: Update declarations to match.
|
||||
* c-lex.c (cb_dir_change): Move to c-opts.c.
|
||||
(init_c_lex): Don't set dir_change callback here, since we want
|
||||
to set it even if flag_preprocess_only.
|
||||
* c-opts.c (cb_dir_change): Function moved from c-lex.c.
|
||||
(c_common_post_options): Set dir_change callback.
|
||||
Call pp_dir_change if approporiate.
|
||||
(finish_options): Don't call cpp_find_main_file here. Hence remove
|
||||
unneeded parameter and result. Do LC_RENAME for <built-in>.
|
||||
(c_common_post_options): Call cpp_read_main_file here instead.
|
||||
(c_common_init): Update accordingly.
|
||||
(push_command_line_include): Don't cpp_push_main_file.
|
||||
Do LC_RENAME rather than LC_LEASE to get back to main file.
|
||||
Compared to pre-10-01 version, inline cpp_rename_to_main_file.
|
||||
(c_common_parse_file): Call cpp_read_main_file for subsequent main
|
||||
files, but call finish_options for all files.
|
||||
* c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory.
|
||||
* fix-header.c (read_scan_file): Call cpp_read_main_file instead of
|
||||
cpp_find_main_file + cpp_push_main_file.
|
||||
* c-lex.c (fe_file_change): Don't set main_input_filename here.
|
||||
* opts.c (handle_options): Only set main_input_filename first time.
|
||||
|
||||
2004-02-05 Ian Lance Taylor <ian@wasabisystems.com>
|
||||
|
||||
* config/arm/arm.h (REG_CLASS_NAMES): Add missing comma.
|
||||
|
@ -1340,5 +1340,6 @@ extern void objc_mark_locals_volatile (void *);
|
||||
extern void init_pp_output (FILE *);
|
||||
extern void preprocess_file (cpp_reader *);
|
||||
extern void pp_file_change (const struct line_map *);
|
||||
extern void pp_dir_change (cpp_reader *, const char *);
|
||||
|
||||
#endif /* ! GCC_C_COMMON_H */
|
||||
|
13
gcc/c-lex.c
13
gcc/c-lex.c
@ -69,7 +69,6 @@ static tree lex_charconst (const cpp_token *);
|
||||
static void update_header_times (const char *);
|
||||
static int dump_one_header (splay_tree_node, void *);
|
||||
static void cb_line_change (cpp_reader *, const cpp_token *, int);
|
||||
static void cb_dir_change (cpp_reader *, const char *);
|
||||
static void cb_ident (cpp_reader *, unsigned int, const cpp_string *);
|
||||
static void cb_def_pragma (cpp_reader *, unsigned int);
|
||||
static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
|
||||
@ -96,7 +95,6 @@ init_c_lex (void)
|
||||
cb = cpp_get_callbacks (parse_in);
|
||||
|
||||
cb->line_change = cb_line_change;
|
||||
cb->dir_change = cb_dir_change;
|
||||
cb->ident = cb_ident;
|
||||
cb->def_pragma = cb_def_pragma;
|
||||
cb->valid_pch = c_common_valid_pch;
|
||||
@ -202,13 +200,6 @@ cb_line_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const cpp_token *token,
|
||||
input_line = SOURCE_LINE (map, token->line);
|
||||
}
|
||||
|
||||
static void
|
||||
cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
|
||||
{
|
||||
if (! set_src_pwd (dir))
|
||||
warning ("too late for # directive to set debug directory");
|
||||
}
|
||||
|
||||
void
|
||||
fe_file_change (const struct line_map *new_map)
|
||||
{
|
||||
@ -222,9 +213,7 @@ fe_file_change (const struct line_map *new_map)
|
||||
{
|
||||
/* Don't stack the main buffer on the input stack;
|
||||
we already did in compile_file. */
|
||||
if (map == NULL)
|
||||
main_input_filename = new_map->to_file;
|
||||
else
|
||||
if (map != NULL)
|
||||
{
|
||||
int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1);
|
||||
|
||||
|
66
gcc/c-opts.c
66
gcc/c-opts.c
@ -108,7 +108,8 @@ static void sanitize_cpp_opts (void);
|
||||
static void add_prefixed_path (const char *, size_t);
|
||||
static void push_command_line_include (void);
|
||||
static void cb_file_change (cpp_reader *, const struct line_map *);
|
||||
static bool finish_options (const char *);
|
||||
static void cb_dir_change (cpp_reader *, const char *);
|
||||
static void finish_options (void);
|
||||
|
||||
#ifndef STDC_0_IN_SYSTEM_HEADERS
|
||||
#define STDC_0_IN_SYSTEM_HEADERS 0
|
||||
@ -1053,8 +1054,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
|
||||
|
||||
/* Post-switch processing. */
|
||||
bool
|
||||
c_common_post_options (const char **pfilename ATTRIBUTE_UNUSED)
|
||||
c_common_post_options (const char **pfilename)
|
||||
{
|
||||
struct cpp_callbacks *cb;
|
||||
|
||||
/* Canonicalize the input and output filenames. */
|
||||
if (in_fnames == NULL)
|
||||
{
|
||||
@ -1142,7 +1145,9 @@ c_common_post_options (const char **pfilename ATTRIBUTE_UNUSED)
|
||||
input_line = 0;
|
||||
}
|
||||
|
||||
cpp_get_callbacks (parse_in)->file_change = cb_file_change;
|
||||
cb = cpp_get_callbacks (parse_in);
|
||||
cb->file_change = cb_file_change;
|
||||
cb->dir_change = cb_dir_change;
|
||||
cpp_post_options (parse_in);
|
||||
|
||||
saved_lineno = input_line;
|
||||
@ -1152,6 +1157,14 @@ c_common_post_options (const char **pfilename ATTRIBUTE_UNUSED)
|
||||
immediately. */
|
||||
errorcount += cpp_errors (parse_in);
|
||||
|
||||
*pfilename = this_input_filename
|
||||
= cpp_read_main_file (parse_in, in_fnames[0]);
|
||||
if (this_input_filename == NULL)
|
||||
return true;
|
||||
|
||||
if (flag_preprocess_only && flag_working_directory)
|
||||
pp_dir_change (parse_in, get_src_pwd ());
|
||||
|
||||
return flag_preprocess_only;
|
||||
}
|
||||
|
||||
@ -1176,8 +1189,8 @@ c_common_init (void)
|
||||
|
||||
if (flag_preprocess_only)
|
||||
{
|
||||
if (finish_options (in_fnames[0]))
|
||||
preprocess_file (parse_in);
|
||||
finish_options ();
|
||||
preprocess_file (parse_in);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1211,10 +1224,12 @@ c_common_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
|
||||
|
||||
/* Reset cpplib's macros and start a new file. */
|
||||
cpp_undef_all (parse_in);
|
||||
main_input_filename = this_input_filename
|
||||
= cpp_read_main_file (parse_in, in_fnames[file_index]);
|
||||
if (this_input_filename == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (! finish_options(in_fnames[file_index]))
|
||||
break;
|
||||
finish_options ();
|
||||
if (file_index == 0)
|
||||
pch_init();
|
||||
c_parse_file ();
|
||||
@ -1355,8 +1370,6 @@ sanitize_cpp_opts (void)
|
||||
actually output the current directory? */
|
||||
if (flag_working_directory == -1)
|
||||
flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
|
||||
cpp_opts->working_directory
|
||||
= flag_preprocess_only && flag_working_directory;
|
||||
}
|
||||
|
||||
/* Add include path with a prefix at the front of its name. */
|
||||
@ -1379,21 +1392,15 @@ add_prefixed_path (const char *suffix, size_t chain)
|
||||
add_path (path, chain, 0);
|
||||
}
|
||||
|
||||
/* Handle -D, -U, -A, -imacros, and the first -include.
|
||||
TIF is the input file to which we will return after processing all
|
||||
the includes. Returns true on success. */
|
||||
static bool
|
||||
finish_options (const char *tif)
|
||||
/* Handle -D, -U, -A, -imacros, and the first -include. */
|
||||
static void
|
||||
finish_options (void)
|
||||
{
|
||||
this_input_filename = tif;
|
||||
if (! cpp_find_main_file (parse_in, this_input_filename))
|
||||
return false;
|
||||
|
||||
if (!cpp_opts->preprocessed)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
cpp_change_file (parse_in, LC_ENTER, _("<built-in>"));
|
||||
cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
|
||||
cpp_init_builtins (parse_in, flag_hosted);
|
||||
c_cpp_builtins (parse_in);
|
||||
|
||||
@ -1443,7 +1450,6 @@ finish_options (const char *tif)
|
||||
|
||||
include_cursor = 0;
|
||||
push_command_line_include ();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Give CPP the next file given by -include, if any. */
|
||||
@ -1462,12 +1468,15 @@ push_command_line_include (void)
|
||||
if (include_cursor == deferred_count)
|
||||
{
|
||||
include_cursor++;
|
||||
/* Restore the line map from <command line>. */
|
||||
if (! cpp_opts->preprocessed)
|
||||
cpp_change_file (parse_in, LC_LEAVE, NULL);
|
||||
/* -Wunused-macros should only warn about macros defined hereafter. */
|
||||
cpp_opts->warn_unused_macros = warn_unused_macros;
|
||||
cpp_push_main_file (parse_in);
|
||||
/* Restore the line map from <command line>. */
|
||||
if (! cpp_opts->preprocessed)
|
||||
cpp_change_file (parse_in, LC_RENAME, main_input_filename);
|
||||
|
||||
/* Set this here so the client can change the option if it wishes,
|
||||
and after stacking the main file so we don't trace the main file. */
|
||||
line_table.trace_includes = cpp_opts->print_include_names;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1485,6 +1494,13 @@ cb_file_change (cpp_reader *pfile ATTRIBUTE_UNUSED,
|
||||
push_command_line_include ();
|
||||
}
|
||||
|
||||
void
|
||||
cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
|
||||
{
|
||||
if (! set_src_pwd (dir))
|
||||
warning ("too late for # directive to set debug directory");
|
||||
}
|
||||
|
||||
/* Set the C 89 standard (with 1994 amendments if C94, without GNU
|
||||
extensions if ISO). There is no concept of gnu94. */
|
||||
static void
|
||||
|
@ -334,6 +334,22 @@ cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, fileline line,
|
||||
print.line++;
|
||||
}
|
||||
|
||||
/* Callback called when -fworking-director and -E to emit working
|
||||
diretory in cpp output file. */
|
||||
|
||||
void
|
||||
pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
|
||||
{
|
||||
size_t to_file_len = strlen (dir);
|
||||
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 *) dir, to_file_len);
|
||||
*p = '\0';
|
||||
fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted);
|
||||
}
|
||||
|
||||
/* The file name, line number or system header flags have changed, as
|
||||
described in MAP. From this point on, the old print.map might be
|
||||
pointing to freed memory, and so must not be dereferenced. */
|
||||
|
@ -453,9 +453,10 @@ cpp_post_options (cpp_reader *pfile)
|
||||
}
|
||||
|
||||
/* Setup for processing input from the file named FNAME, or stdin if
|
||||
it is the empty string. Returns true if the file was found. */
|
||||
bool
|
||||
cpp_find_main_file (cpp_reader *pfile, const char *fname)
|
||||
it is the empty string. Return the original filename
|
||||
on success (e.g. foo.i->foo.c), or NULL on failure. */
|
||||
const char *
|
||||
cpp_read_main_file (cpp_reader *pfile, const char *fname)
|
||||
{
|
||||
if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
|
||||
{
|
||||
@ -471,37 +472,16 @@ cpp_find_main_file (cpp_reader *pfile, const char *fname)
|
||||
if (_cpp_find_failed (pfile->main_file))
|
||||
return false;
|
||||
|
||||
if (CPP_OPTION (pfile, working_directory))
|
||||
{
|
||||
const char *dir = getpwd ();
|
||||
char *dir_with_slashes = alloca (strlen (dir) + 3);
|
||||
|
||||
memcpy (dir_with_slashes, dir, strlen (dir));
|
||||
memcpy (dir_with_slashes + strlen (dir), "//", 3);
|
||||
|
||||
if (pfile->cb.dir_change)
|
||||
pfile->cb.dir_change (pfile, dir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* This function reads the file, but does not start preprocessing.
|
||||
This will generate at least one file change callback, and possibly
|
||||
a line change callback. */
|
||||
void
|
||||
cpp_push_main_file (cpp_reader *pfile)
|
||||
{
|
||||
_cpp_stack_file (pfile, pfile->main_file, false);
|
||||
|
||||
/* For foo.i, read the original filename foo.c now, for the benefit
|
||||
of the front ends. */
|
||||
if (CPP_OPTION (pfile, preprocessed))
|
||||
read_original_filename (pfile);
|
||||
|
||||
/* Set this here so the client can change the option if it wishes,
|
||||
and after stacking the main file so we don't trace the main
|
||||
file. */
|
||||
pfile->line_table->trace_includes = CPP_OPTION (pfile, print_include_names);
|
||||
{
|
||||
read_original_filename (pfile);
|
||||
fname = pfile->map->to_file;
|
||||
}
|
||||
return fname;
|
||||
}
|
||||
|
||||
/* For preprocessed files, if the first tokens are of the form # NUM.
|
||||
@ -579,13 +559,7 @@ read_original_directory (cpp_reader *pfile)
|
||||
debugdir[token->val.str.len - 4] = '\0';
|
||||
|
||||
pfile->cb.dir_change (pfile, debugdir);
|
||||
}
|
||||
|
||||
/* We want to process the fake line changes as regular changes, to
|
||||
get them output. */
|
||||
_cpp_backup_tokens (pfile, 3);
|
||||
|
||||
CPP_OPTION (pfile, working_directory) = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is called at the end of preprocessing. It pops the last
|
||||
|
19
gcc/cpplib.h
19
gcc/cpplib.h
@ -373,11 +373,6 @@ struct cpp_options
|
||||
|
||||
/* Nonzero means __STDC__ should have the value 0 in system headers. */
|
||||
unsigned char stdc_0_in_system_headers;
|
||||
|
||||
/* Nonzero means output a directory line marker right after the
|
||||
initial file name line marker, and before a duplicate initial
|
||||
line marker. */
|
||||
bool working_directory;
|
||||
};
|
||||
|
||||
/* Call backs to cpplib client. */
|
||||
@ -536,14 +531,12 @@ extern const struct line_maps *cpp_get_line_maps (cpp_reader *);
|
||||
extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
|
||||
extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
|
||||
|
||||
/* This function finds the main file, but does not start reading it.
|
||||
Returns true iff the file was found. */
|
||||
extern bool cpp_find_main_file (cpp_reader *, const char *);
|
||||
|
||||
/* This function reads the file, but does not start preprocessing.
|
||||
This will generate at least one file change callback, and possibly
|
||||
a line change callback. */
|
||||
extern void cpp_push_main_file (cpp_reader *);
|
||||
/* This function reads the file, but does not start preprocessing. It
|
||||
returns the name of the original file; this is the same as the
|
||||
input file, except for preprocessed input. This will generate at
|
||||
least one file change callback, and possibly a line change callback
|
||||
too. If there was an error opening the file, it returns NULL. */
|
||||
extern const char *cpp_read_main_file (cpp_reader *, const char *);
|
||||
|
||||
/* Set up built-ins like __FILE__. */
|
||||
extern void cpp_init_builtins (cpp_reader *, int);
|
||||
|
@ -606,9 +606,8 @@ read_scan_file (char *in_fname, int argc, char **argv)
|
||||
options->inhibit_errors = 1;
|
||||
cpp_post_options (scan_in);
|
||||
|
||||
if (!cpp_find_main_file (scan_in, in_fname))
|
||||
if (!cpp_read_main_file (scan_in, in_fname))
|
||||
exit (FATAL_EXIT_CODE);
|
||||
cpp_push_main_file (scan_in);
|
||||
|
||||
cpp_change_file (scan_in, LC_RENAME, "<built-in>");
|
||||
cpp_init_builtins (scan_in, true);
|
||||
|
@ -448,7 +448,8 @@ handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
|
||||
/* Interpret "-" or a non-switch as a file name. */
|
||||
if (opt[0] != '-' || opt[1] == '\0')
|
||||
{
|
||||
main_input_filename = opt;
|
||||
if (main_input_filename == NULL)
|
||||
main_input_filename = opt;
|
||||
add_input_filename (opt);
|
||||
n = 1;
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user