aboutsummaryrefslogtreecommitdiff
path: root/gcc/toplev.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2006-08-26 22:38:46 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2006-08-26 22:38:46 +0100
commit02ec74b9d26c400f219a1975a1d39e03c39b3c0c (patch)
treea5124e3c47e8d988de14e9615b356c0d0eb3b461 /gcc/toplev.c
parent63d0dca480ee0f7ebe02d1e73c579e5547e1d6d2 (diff)
downloadgcc-02ec74b9d26c400f219a1975a1d39e03c39b3c0c.zip
gcc-02ec74b9d26c400f219a1975a1d39e03c39b3c0c.tar.gz
gcc-02ec74b9d26c400f219a1975a1d39e03c39b3c0c.tar.bz2
re PR c++/24009 (C++ fails to print #include stack)
PR c++/24009 * input.h (restore_input_file_stack): Declare. (INPUT_FILE_STACK_BITS): Define. * toplev.c (fs_p, input_file_stack_history, input_file_stack_restored, restore_input_file_stack): New. (push_srcloc, pop_srcloc): Check for input_file_stack_tick overflowing INPUT_FILE_STACK_BITS bits. Save new state of stack. (pop_srcloc): Don't free old state of stack. cp: * parser.c (struct cp_token): Add input_file_stack_index. (eof_token): Update. (cp_lexer_get_preprocessor_token): Save input_file_stack_tick. (cp_lexer_set_source_position_from_token): Restore input file stack. From-SVN: r116479
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r--gcc/toplev.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 55019ed..53fcdfe 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -164,6 +164,16 @@ struct file_stack *input_file_stack;
/* Incremented on each change to input_file_stack. */
int input_file_stack_tick;
+/* Record of input_file_stack at each tick. */
+typedef struct file_stack *fs_p;
+DEF_VEC_P(fs_p);
+DEF_VEC_ALLOC_P(fs_p,heap);
+static VEC(fs_p,heap) *input_file_stack_history;
+
+/* Whether input_file_stack has been restored to a previous state (in
+ which case there should be no more pushing). */
+static bool input_file_stack_restored;
+
/* Name to use as base of names for dump output files. */
const char *dump_base_name;
@@ -951,6 +961,10 @@ push_srcloc (const char *file, int line)
{
struct file_stack *fs;
+ gcc_assert (!input_file_stack_restored);
+ if (input_file_stack_tick == (int) ((1U << INPUT_FILE_STACK_BITS) - 1))
+ sorry ("GCC supports only %d input file changes", input_file_stack_tick);
+
fs = XNEW (struct file_stack);
fs->location = input_location;
fs->next = input_file_stack;
@@ -962,6 +976,7 @@ push_srcloc (const char *file, int line)
#endif
input_file_stack = fs;
input_file_stack_tick++;
+ VEC_safe_push (fs_p, heap, input_file_stack_history, input_file_stack);
}
/* Pop the top entry off the stack of presently open source files.
@@ -973,11 +988,30 @@ pop_srcloc (void)
{
struct file_stack *fs;
+ gcc_assert (!input_file_stack_restored);
+ if (input_file_stack_tick == (int) ((1U << INPUT_FILE_STACK_BITS) - 1))
+ sorry ("GCC supports only %d input file changes", input_file_stack_tick);
+
fs = input_file_stack;
input_location = fs->location;
input_file_stack = fs->next;
- free (fs);
input_file_stack_tick++;
+ VEC_safe_push (fs_p, heap, input_file_stack_history, input_file_stack);
+}
+
+/* Restore the input file stack to its state as of TICK, for the sake
+ of diagnostics after processing the whole input. Once this has
+ been called, push_srcloc and pop_srcloc may no longer be
+ called. */
+void
+restore_input_file_stack (int tick)
+{
+ if (tick == 0)
+ input_file_stack = NULL;
+ else
+ input_file_stack = VEC_index (fs_p, input_file_stack_history, tick - 1);
+ input_file_stack_tick = tick;
+ input_file_stack_restored = true;
}
/* Compile an entire translation unit. Write a file of assembly