[pph] Cleanup line_table and includes streaming (issue4921052)

2011-08-22 Thread Gabriel Charette
This is a refactoring patch, it doesn't change/fix anything in pph itself.

I extracted out/in logic for includes into their own functions.

I removed the LINETAB parameter from in/out functions for the line_table as 
there is only one line_table and that's the only one we stream, the main/global 
one.

I wanted to move pph_loc_offset to pph_stream.encoder.r, but it's not possible 
while locations are called by the streamer hook as in the callback we do not 
have a pph_stream* parameter, added a FIXME to do it later if we do get rid of 
the hook for locations.

Tested with bootstrap and pph regression testing on x64.

Cheers,
Gab

2011-08-22  Gabriel Charette  gch...@google.com

* pph-streamer-in.c (pph_loc_offset): Add FIXME to move this variable
to pph_stream.encoder.r
(pph_in_include): New.
(pph_in_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_in_include. And call it.
(pph_read_file_1): Remove extra parameter in call to
pph_in_line_table_and_includes.
* pph-streamer-out.c (pph_out_include): New.
(pph_get_next_include): Fix comment.
(pph_out_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_out_include. And call it.
* gcc/cp/pph-streamer.h (pph_stream): Fix indenting.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 07e1135..2b7dc2d 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -75,7 +75,11 @@ static int pph_reading_includes = 0;
 } while (0)
 
 /* Set in pph_in_and_merge_line_table. Represents the source_location offset
-   which every streamed in token must add to it's serialized source_location. 
*/
+   which every streamed in token must add to it's serialized source_location.
+
+   FIXME pph: Ideally this would be in pph_stream.encoder.r, but for that we
+   first need to get rid of the dependency to the streamer_hook for locations.
+   */
 static int pph_loc_offset;
 
 
@@ -1336,9 +1340,37 @@ pph_in_line_map (pph_stream *stream, struct line_map *lm)
 }
 
 
-/* Read the line_table from STREAM and merge it in LINETAB.  At the same time
-   load includes in the order they were originally included by loading them at
-   the point they were referenced in the line_table.
+/* Read in from STREAM and merge a referenced include into the current parsing
+   context.  */
+
+static void
+pph_in_include (pph_stream *stream)
+{
+  int old_loc_offset;
+  const char *include_name;
+  pph_stream *include;
+  source_location prev_start_loc = pph_in_source_location (stream);
+
+  /* Simulate highest_location to be as it would be at this point in a non-pph
+ compilation.  */
+  line_table-highest_location = (prev_start_loc - 1) + pph_loc_offset;
+
+  /* FIXME pph: If we move pph_loc_offset to pph_stream.encoder.r, we could
+ have an independent offset for each stream and not have to save and
+ restore the state of a global pph_loc_offset as we are doing here.  */
+  old_loc_offset = pph_loc_offset;
+
+  include_name = pph_in_string (stream);
+  include = pph_read_file (include_name);
+  pph_add_include (include, false);
+
+  pph_loc_offset = old_loc_offset;
+}
+
+
+/* Read the line_table from STREAM and merge it in the current line_table.  At
+   the same time load includes in the order they were originally included by
+   loading them at the point they were referenced in the line_table.
 
Returns the source_location of line 1 / col 0 for this include.
 
@@ -1348,13 +1380,13 @@ pph_in_line_map (pph_stream *stream, struct line_map 
*lm)
a known current issue, so I didn't bother working around it here for now.  
*/
 
 static source_location
-pph_in_line_table_and_includes (pph_stream *stream, struct line_maps *linetab)
+pph_in_line_table_and_includes (pph_stream *stream)
 {
   unsigned int old_depth;
   bool first;
   int includer_ix = -1;
-  unsigned int used_before = linetab-used;
-  int entries_offset = linetab-used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
+  unsigned int used_before = line_table-used;
+  int entries_offset = line_table-used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
   enum pph_linetable_marker next_lt_marker = pph_in_linetable_marker (stream);
 
   pph_reading_includes++;
@@ -1364,29 +1396,16 @@ pph_in_line_table_and_includes (pph_stream *stream, 
struct line_maps *linetab)
 {
   if (next_lt_marker == PPH_LINETABLE_REFERENCE)
{
- int old_loc_offset;
- const char *include_name = pph_in_string (stream);
- source_location prev_start_loc = pph_in_source_location (stream);
- pph_stream *include;
-
  gcc_assert (!first);
-
- linetab-highest_location = (prev_start_loc - 1) + pph_loc_offset;
-
- old_loc_offset = pph_loc_offset;
-
- include = pph_read_file (include_name);

Re: [pph] Cleanup line_table and includes streaming (issue4921052)

2011-08-22 Thread Diego Novillo

On 11-08-22 14:20 , Gabriel Charette wrote:


2011-08-22  Gabriel Charettegch...@google.com

* pph-streamer-in.c (pph_loc_offset): Add FIXME to move this variable
to pph_stream.encoder.r
(pph_in_include): New.
(pph_in_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_in_include. And call it.
(pph_read_file_1): Remove extra parameter in call to
pph_in_line_table_and_includes.
* pph-streamer-out.c (pph_out_include): New.
(pph_get_next_include): Fix comment.
(pph_out_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_out_include. And call it.
* gcc/cp/pph-streamer.h (pph_stream): Fix indenting.


OK.


Diego.