public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [C++ PATCH] pushdecl
Date: Mon, 08 May 2017 18:02:00 -0000	[thread overview]
Message-ID: <7dfbb0e2-965e-738c-9b51-9101de018094@acm.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

This small patch replaces pushdecl_with_scope with a more-specific 
pushdecl_outermost_localscope.  It's used in 2 places to inject an 
artifical decl into the outermost block scope of a function 
(__FUNCTION__ var and lambda capture proxies).

This moves some binding-level handling into name-lookup, where it belongs.

Applied to trunk.

nathan
-- 
Nathan Sidwell

[-- Attachment #2: scpe.diff --]
[-- Type: text/x-patch, Size: 4626 bytes --]

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

	* name-lookup.h (pushdecl_with_scope): Replace with ...
	(pushdecl_outermost_localscope): ... this.
	* name-lookup.c (pushdecl_with_scope): Replace with ...
	(pushdecl_outermost_localscope): ... this.
	(pushdecl_namespace_level): Adjust.
	* decl.c (cp_make_fname_decl): Use pushdecl_outermost_localscope.
	* lambda.c (insert_capture_proxy): Likewise.

Index: decl.c
===================================================================
--- decl.c	(revision 247751)
+++ decl.c	(working copy)
@@ -4335,9 +4335,6 @@ cp_make_fname_decl (location_t loc, tree
   if (name)
     free (CONST_CAST (char *, name));
 
-  /* As we're using pushdecl_with_scope, we must set the context.  */
-  DECL_CONTEXT (decl) = current_function_decl;
-
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
@@ -4346,12 +4343,8 @@ cp_make_fname_decl (location_t loc, tree
 
   if (current_function_decl)
     {
-      cp_binding_level *b = current_binding_level;
-      if (b->kind == sk_function_parms)
-	return error_mark_node;
-      while (b->level_chain->kind != sk_function_parms)
-	b = b->level_chain;
-      pushdecl_with_scope (decl, b, /*is_friend=*/false);
+      DECL_CONTEXT (decl) = current_function_decl;
+      decl = pushdecl_outermost_localscope (decl);
       cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE,
 		      LOOKUP_ONLYCONVERTING);
     }
Index: lambda.c
===================================================================
--- lambda.c	(revision 247751)
+++ lambda.c	(working copy)
@@ -295,24 +295,13 @@ is_normal_capture_proxy (tree decl)
 void
 insert_capture_proxy (tree var)
 {
-  cp_binding_level *b;
-  tree stmt_list;
-
   /* Put the capture proxy in the extra body block so that it won't clash
      with a later local variable.  */
-  b = current_binding_level;
-  for (;;)
-    {
-      cp_binding_level *n = b->level_chain;
-      if (n->kind == sk_function_parms)
-	break;
-      b = n;
-    }
-  pushdecl_with_scope (var, b, false);
+  pushdecl_outermost_localscope (var);
 
   /* And put a DECL_EXPR in the STATEMENT_LIST for the same block.  */
   var = build_stmt (DECL_SOURCE_LOCATION (var), DECL_EXPR, var);
-  stmt_list = (*stmt_list_stack)[1];
+  tree stmt_list = (*stmt_list_stack)[1];
   gcc_assert (stmt_list);
   append_to_statement_list_force (var, &stmt_list);
 }
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 247751)
+++ name-lookup.c	(working copy)
@@ -2870,14 +2870,23 @@ pushdecl_with_scope_1 (tree x, cp_bindin
   return x;
 }
  
-/* Wrapper for pushdecl_with_scope_1.  */
+/* Inject X into the local scope just before the function parms.  */
 
 tree
-pushdecl_with_scope (tree x, cp_binding_level *level, bool is_friend)
+pushdecl_outermost_localscope (tree x)
 {
-  tree ret;
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  ret = pushdecl_with_scope_1 (x, level, is_friend);
+  cp_binding_level *b  = NULL, *n = current_binding_level;
+
+  if (n->kind == sk_function_parms)
+    return error_mark_node;
+  do
+    {
+      b = n;
+      n = b->level_chain;
+    }
+  while (n->kind != sk_function_parms);
+  tree ret = pushdecl_with_scope_1 (x, b, false);
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
   return ret;
 }
@@ -4350,7 +4359,8 @@ pushdecl_namespace_level (tree x, bool i
   tree t;
 
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace), is_friend);
+  t = pushdecl_with_scope_1
+    (x, NAMESPACE_LEVEL (current_namespace), is_friend);
 
   /* Now, the type_shadowed stack may screw us.  Munge it so it does
      what we want.  */
Index: name-lookup.h
===================================================================
--- name-lookup.h	(revision 247751)
+++ name-lookup.h	(working copy)
@@ -300,6 +300,7 @@ extern tree push_inner_scope (tree);
 extern void pop_inner_scope (tree, tree);
 extern void push_binding_level (cp_binding_level *);
 \f
+extern tree pushdecl_outermost_localscope (tree);
 extern bool push_namespace (tree);
 extern void pop_namespace (void);
 extern void push_nested_namespace (tree);
@@ -307,7 +308,6 @@ extern void pop_nested_namespace (tree);
 extern bool handle_namespace_attrs (tree, tree);
 extern void pushlevel_class (void);
 extern void poplevel_class (void);
-extern tree pushdecl_with_scope (tree, cp_binding_level *, bool);
 extern tree lookup_name_prefer_type (tree, int);
 extern tree lookup_name_real (tree, int, int, bool, int, int);
 extern tree lookup_type_scope (tree, tag_scope);

             reply	other threads:[~2017-05-08 17:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08 18:02 Nathan Sidwell [this message]
2017-05-23 22:04 Nathan Sidwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7dfbb0e2-965e-738c-9b51-9101de018094@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).