diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-26 21:38:46 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-26 21:38:46 +0000 |
commit | 18a3d34c624b0fbaaae8afb8f02b61b88b11347d (patch) | |
tree | a5124e3c47e8d988de14e9615b356c0d0eb3b461 /gcc/toplev.c | |
parent | 268b27189b0a4e59bec0d2a150ebb1251c1b0f4e (diff) | |
download | gcc-18a3d34c624b0fbaaae8afb8f02b61b88b11347d.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116479 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r-- | gcc/toplev.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c index 55019ed5413..53fcdfe580c 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 |