Patchwork [pph] Fix token dumping within a window (issue4991046)

login
register
mail settings
Submitter Diego Novillo
Date Sept. 8, 2011, 6:44 p.m.
Message ID <20110908184412.08CE01DA1D5@topo.tor.corp.google.com>
Download mbox | patch
Permalink /patch/113931/
State New
Headers show

Comments

Diego Novillo - Sept. 8, 2011, 6:44 p.m.
When dumping a range of tokens, I was not properly counting the tokens
to be dumped, which resulted in empty output when dumping a range
of tokens in the middle of a large array.

I also reduced the size of the window to print.  It was too large to
be useful.

Tested on x86_64.  Committed to branch.


Diego.


	* parser.c (cp_lexer_dump_tokens): Properly count number of printed
	tokens to know when to stop.
	(cp_debug_parser): Reduce token window size to 20.


--
This patch is available for review at http://codereview.appspot.com/4991046

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 700ca64..a46edba 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -259,7 +259,7 @@  cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer,
 		      cp_token *start_token, unsigned num,
 		      cp_token *curr_token)
 {
-  unsigned i;
+  unsigned i, nprinted;
   cp_token *token;
   bool do_print;
 
@@ -281,7 +281,8 @@  cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer,
     }
 
   do_print = false;
-  for (i = 0; VEC_iterate (cp_token, buffer, i, token) && i < num; i++)
+  nprinted = 0;
+  for (i = 0; VEC_iterate (cp_token, buffer, i, token) && nprinted < num; i++)
     {
       if (token == start_token)
 	do_print = true;
@@ -289,6 +290,7 @@  cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer,
       if (!do_print)
 	continue;
 
+      nprinted++;
       if (token == curr_token)
 	fprintf (file, "[[");
 
@@ -462,7 +464,7 @@  cp_debug_parser_tokens (FILE *file, cp_parser *parser, int window_size)
 void
 cp_debug_parser (FILE *file, cp_parser *parser)
 {
-  const size_t window_size = 200;
+  const size_t window_size = 20;
 
   if (file == NULL)
     file = stderr;