Patchwork [pph] Add debugging for namespace_decl (issue4368079)

login
register
mail settings
Submitter Diego Novillo
Date April 12, 2011, 7:53 p.m.
Message ID <20110412195323.3B1DB1DA1BE@topo.tor.corp.google.com>
Download mbox | patch
Permalink /patch/90858/
State New
Headers show

Comments

Diego Novillo - April 12, 2011, 7:53 p.m.
This patch adds some debugging support for printing namespace_decls and 
their associated binding level.

Committed to pph branch.

2011-04-12  Diego Novillo  <dnovillo@google.com>

	* cp-tree.h (print_namespace): Declare.
	* name-lookup.c (print_namespace): New.
	* parser.c (cp_debug_print_context_stack): Increment loop counter.


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

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 9ce164b..1fcd0d7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4758,6 +4758,7 @@  extern void print_other_binding_stack		(struct cp_binding_level *);
 extern tree maybe_push_decl			(tree);
 extern tree current_decl_namespace		(void);
 extern cxx_binding *cxx_binding_make            (tree, tree);
+extern void print_namespace                     (tree);
 
 /* decl.c */
 extern tree poplevel				(int, int, int);
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index d4fd216..e39456e 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1751,6 +1751,21 @@  print_binding_level (struct cp_binding_level* lvl)
     }
 }
 
+
+/* Print the given namespace decl NS to stderr.  */
+
+void
+print_namespace (tree ns)
+{
+  struct cp_binding_level *level = NAMESPACE_LEVEL (ns);
+
+  fprintf (stderr, "Namespace name: ");
+  print_generic_expr (stderr, ns, 0);
+  fprintf (stderr, "\nBinding contour\n");
+  print_binding_level (level);
+}
+
+
 void
 print_other_binding_stack (struct cp_binding_level *stack)
 {
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index fd2da62..32c81a4 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -352,6 +352,7 @@  cp_debug_print_context (FILE *file, cp_parser_context *c)
 
 
 /* Print the stack of parsing contexts to FILE starting with FIRST.  */
+
 static void
 cp_debug_print_context_stack (FILE *file, cp_parser_context *first)
 {
@@ -359,7 +360,7 @@  cp_debug_print_context_stack (FILE *file, cp_parser_context *first)
   cp_parser_context *c;
 
   fprintf (file, "Parsing context stack:\n");
-  for (i = 0, c = first; c; c = c->next)
+  for (i = 0, c = first; c; c = c->next, i++)
     {
       fprintf (file, "\t#%u: ", i);
       cp_debug_print_context (file, c);