getdecls and pop_binding are only ever used to deal with local scopes. (the one getdecls use that didn't is now a different hook).

This patch renames things to make that clearer (get_local_decls and pop_local_binding). I also cleaned up poplevel, whose logic was somewhat more complex than necessary.

nathan
--
Nathan Sidwell
2017-05-11  Nathan Sidwell  <nat...@acm.org>

	* name-lookup.h (pop_binding): Rename to pop_local_binding.
	(getdecls): Rename to get_local_decls.
	* name-lookup.c (pop_binding): Rename to ...
	(pop_local_binding): ... here.
	(pop_bindings_and_leave_scope): Adjust.
	(getdecls): Rename to ...
	(get_local_decls): ... here.  Assert local scope.
	* decl.c (poplevel): Assert not namespace.  Adjust and simplify
	logic.
	(store_parm_decls): Adjust get_local_decls call.
	(parser.c (synthesize_implicit_template_parm): Likewise.

Index: decl.c
===================================================================
--- decl.c	(revision 247900)
+++ decl.c	(working copy)
@@ -582,7 +582,8 @@ poplevel (int keep, int reverse, int fun
 
   block = NULL_TREE;
 
-  gcc_assert (current_binding_level->kind != sk_class);
+  gcc_assert (current_binding_level->kind != sk_class
+	      && current_binding_level->kind != sk_namespace);
 
   if (current_binding_level->kind == sk_cleanup)
     functionbody = 0;
@@ -644,12 +645,13 @@ poplevel (int keep, int reverse, int fun
   if ((warn_unused_variable || warn_unused_but_set_variable)
       && current_binding_level->kind != sk_template_parms
       && !processing_template_decl)
-    for (tree d = getdecls (); d; d = TREE_CHAIN (d))
+    for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
       {
 	/* There are cases where D itself is a TREE_LIST.  See in
 	   push_local_binding where the list of decls returned by
 	   getdecls is built.  */
 	decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
+
 	tree type = TREE_TYPE (decl);
 	if (VAR_P (decl)
 	    && (! TREE_USED (decl) || !DECL_READ_P (decl))
@@ -680,14 +682,15 @@ poplevel (int keep, int reverse, int fun
   /* Remove declarations for all the DECLs in this level.  */
   for (link = decls; link; link = TREE_CHAIN (link))
     {
-      if (leaving_for_scope && VAR_P (link)
+      decl = TREE_CODE (link) == TREE_LIST ? TREE_VALUE (link) : link;
+      tree name = DECL_NAME (OVL_CURRENT (decl));
+
+      if (leaving_for_scope && VAR_P (decl)
 	  /* It's hard to make this ARM compatibility hack play nicely with
 	     lambdas, and it really isn't necessary in C++11 mode.  */
 	  && cxx_dialect < cxx11
-	  && DECL_NAME (link))
+	  && name)
 	{
-	  tree name = DECL_NAME (link);
-
 	  cxx_binding *ob = outer_binding (name,
 					   IDENTIFIER_BINDING (name),
 					   /*class_p=*/true);
@@ -703,7 +706,7 @@ poplevel (int keep, int reverse, int fun
 
 	       and we are leaving the `for' scope.  There's no reason to
 	       keep the binding of the inner `i' in this case.  */
-	    pop_binding (name, link);
+	    ;
 	  else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
 		   || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
 	    /* Here, we have something like:
@@ -716,7 +719,7 @@ poplevel (int keep, int reverse, int fun
 
 	       We must pop the for-scope binding so we know what's a
 	       type and what isn't.  */
-	    pop_binding (name, link);
+	    ;
 	  else
 	    {
 	      /* Mark this VAR_DECL as dead so that we can tell we left it
@@ -742,32 +745,20 @@ poplevel (int keep, int reverse, int fun
 		 its SCOPE since the scope is going away now.  */
 	      IDENTIFIER_BINDING (name)->scope
 		= current_binding_level->level_chain;
-	    }
-	}
-      else
-	{
-	  tree name;
-
-	  /* Remove the binding.  */
-	  decl = link;
 
-	  if (TREE_CODE (decl) == TREE_LIST)
-	    decl = TREE_VALUE (decl);
-	  name = decl;
-
-	  if (TREE_CODE (name) == OVERLOAD)
-	    name = OVL_FUNCTION (name);
-
-	  gcc_assert (DECL_P (name));
-	  pop_binding (DECL_NAME (name), decl);
+	      /* Don't remove the binding. */
+	      name = NULL_TREE;
+	    }
 	}
+      /* Remove the binding.  */
+      pop_local_binding (name, decl);
     }
 
   /* Remove declarations for any `for' variables from inner scopes
      that we kept around.  */
   FOR_EACH_VEC_SAFE_ELT_REVERSE (current_binding_level->dead_vars_from_for,
 			         ix, decl)
-    pop_binding (DECL_NAME (decl), decl);
+    pop_local_binding (DECL_NAME (decl), decl);
 
   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
   for (link = current_binding_level->type_shadowed;
@@ -15231,7 +15222,7 @@ store_parm_decls (tree current_function_
       /* Get the decls in their original chain order and record in the
 	 function.  This is all and only the PARM_DECLs that were
 	 pushed into scope by the loop above.  */
-      DECL_ARGUMENTS (fndecl) = getdecls ();
+      DECL_ARGUMENTS (fndecl) = get_local_decls ();
     }
   else
     DECL_ARGUMENTS (fndecl) = NULL_TREE;
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 247900)
+++ name-lookup.c	(working copy)
@@ -936,7 +936,7 @@ push_binding (tree id, tree decl, cp_bin
    for ID.  */
 
 void
-pop_binding (tree id, tree decl)
+pop_local_binding (tree id, tree decl)
 {
   cxx_binding *binding;
 
@@ -979,8 +979,8 @@ pop_binding (tree id, tree decl)
 void
 pop_bindings_and_leave_scope (void)
 {
-  for (tree t = getdecls (); t; t = DECL_CHAIN (t))
-    pop_binding (DECL_NAME (t), t);
+  for (tree t = get_local_decls (); t; t = DECL_CHAIN (t))
+    pop_local_binding (DECL_NAME (t), t);
   leave_scope ();
 }
 
@@ -2367,14 +2367,13 @@ keep_next_level (bool keep)
   keep_next_level_flag = keep;
 }
 
-/* Return the list of declarations of the current level.
-   Note that this list is in reverse order unless/until
-   you nreverse it; and when you do nreverse it, you must
-   store the result back using `storedecls' or you will lose.  */
+/* Return the list of declarations of the current local scope.  */
 
 tree
-getdecls (void)
+get_local_decls (void)
 {
+  gcc_assert (current_binding_level->kind != sk_namespace
+	      && current_binding_level->kind != sk_class);
   return current_binding_level->names;
 }
 
Index: name-lookup.h
===================================================================
--- name-lookup.h	(revision 247900)
+++ name-lookup.h	(working copy)
@@ -89,7 +89,7 @@ struct GTY(()) cxx_saved_binding {
 extern tree identifier_type_value (tree);
 extern void set_identifier_type_value (tree, tree);
 extern void push_binding (tree, tree, cp_binding_level*);
-extern void pop_binding (tree, tree);
+extern void pop_local_binding (tree, tree);
 extern void pop_bindings_and_leave_scope (void);
 extern tree constructor_name (tree);
 extern bool constructor_name_p (tree, tree);
@@ -324,7 +324,7 @@ extern void push_local_binding (tree, tr
 extern bool pushdecl_class_level (tree);
 extern tree pushdecl_namespace_level (tree, bool);
 extern bool push_class_level_binding (tree, tree);
-extern tree getdecls (void);
+extern tree get_local_decls ();
 extern int function_parm_depth (void);
 extern tree cp_namespace_decls (tree);
 extern void set_decl_namespace (tree, tree, bool);
Index: parser.c
===================================================================
--- parser.c	(revision 247900)
+++ parser.c	(working copy)
@@ -38970,7 +38970,7 @@ synthesize_implicit_template_parm  (cp_p
   else
     parser->implicit_template_parms = new_parm;
 
-  tree new_decl = getdecls ();
+  tree new_decl = get_local_decls ();
   if (non_type)
     /* Return the TEMPLATE_PARM_INDEX, not the PARM_DECL.  */
     new_decl = DECL_INITIAL (new_decl);

Reply via email to