From patchwork Thu May 11 17:40:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 761257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wP0kV358hz9ryT for ; Fri, 12 May 2017 03:40:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cUetGptg"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=V1ftyZ/4vmWW3apYVkcbBYCX4/jDN6DF48z3CCofqc9krP89T7 0O7f2SXMQYbIX5k1T3CCN1uCdpubLym9XZ7iZ12RcZQDuaJaZHXnqlOzynVUyxI0 zGmlRV69bzlJkeYmGWtuJuKHHziowlbOC1Dl11GJ2SqSCB4hy0gu8n9xc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=SCOcSxn5OcgAFOhgfylqQ2Hi0Hc=; b=cUetGptg5H+qzQS3CvXu NZkVgiXSZ7Osc3J6hfG31m/346SFq5ZQCL8Fhyp8egA1GbHN/GAWgcQxRIuBkFz8 U9ANqt7iyaYH6WWeJ2ufScB3/tbcOYtyVAm5y4hSxvZDozh2l8mODzWmP+pUQV7G k35rpIOwlJ1OiOIwzOZ34ME= Received: (qmail 19117 invoked by alias); 11 May 2017 17:40:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19090 invoked by uid 89); 11 May 2017 17:40:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yb0-f172.google.com Received: from mail-yb0-f172.google.com (HELO mail-yb0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 May 2017 17:40:18 +0000 Received: by mail-yb0-f172.google.com with SMTP id 8so8320440ybw.1 for ; Thu, 11 May 2017 10:40:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=fliF1sXHCQIRRV+ph+nHoYaW3dsvKNgxMxzMHUv+NaY=; b=S46DcDg6owJqNF/5eVAjEBQ5PIweJZiAb0jkbAZcs+M3fp6L0JQMAJpeSfaEQavk2c MBBKwV2tA8tDT8AsUhQoTbmFBeeiIasXxJJJXYfvzZCRc5OiJ/xjzFnE5VbJwayr5foO hHKRa0277vy/vRq2y9xOon9UgbzFLSSDSwg3Q/dJJFcz3h/Qts2vOz6DyPDApgLWCSiz 73q2e4RmPkO2qNuUQd6BHlyTuzAoFSZQ9jJ3+Alx6dJcfFd2mNyTI607eF+2zlZJvLeA DcxMkWtupaE2KPF53a/FRwE30AHR1BwbYc7vb7A5SS287YRi4f/da9d/nxPf4H8lyrQq eaFw== X-Gm-Message-State: AODbwcDkY+zaeAnyNOCUd98Zp1wbzr7qavUyb2sCibmsGsSOhHvgAv9/ b6rVjbu1vBImmw== X-Received: by 10.37.164.35 with SMTP id f32mr335441ybi.26.1494524420103; Thu, 11 May 2017 10:40:20 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::7:4a1a]) by smtp.googlemail.com with ESMTPSA id f82sm470389ywf.18.2017.05.11.10.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 May 2017 10:40:19 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] pushdecl and friends Message-ID: <1ee6aaae-7e65-f06c-ea5d-dfd8584a5a70@acm.org> Date: Thu, 11 May 2017 13:40:17 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 This patch reduces the variants of pushdecl by use of default arguments. gone are the _maybe_friend variants. nathan 2017-05-11 Nathan Sidwell * name-lookup.h (pushdecl): Add default friend parm. (pushdecl_maybe_friend): Delete. (pushdecl_top_level): Add default friend parm. (pushdecl_top_level_maybe_friend): Delete. * name-lookup.c (pushdecl_maybe_friend): Delete. (pushdecl): Add is_friend parm. (pushdecl_top_level): Add is friend_parm. (pushdecl_top_level_maybe_friend, pushdecl_top_level_1): Delete. (pushdecl_top_level_and_finish): Do pushing and finishing directly. * friend.c (do_friend): Adjust. * pt.c (tsubst_friend_class): Adjust. Index: friend.c =================================================================== --- friend.c (revision 247916) +++ friend.c (working copy) @@ -620,7 +620,7 @@ do_friend (tree ctype, tree declarator, declaration, the program is ill-formed. */ tree t = lookup_name_innermost_nonclass_level (DECL_NAME (decl)); if (t) - decl = pushdecl_maybe_friend (decl, /*is_friend=*/true); + decl = pushdecl (decl, /*is_friend=*/true); else { error ("friend declaration %qD in local class without " Index: name-lookup.c =================================================================== --- name-lookup.c (revision 247916) +++ name-lookup.c (working copy) @@ -1862,10 +1862,11 @@ pushdecl_maybe_friend_1 (tree x, bool is return x; } -/* Wrapper for pushdecl_maybe_friend_1. */ +/* Record a decl-node X as belonging to the current lexical scope. + It's a friend if IS_FRIEND is true. */ tree -pushdecl_maybe_friend (tree x, bool is_friend) +pushdecl (tree x, bool is_friend) { tree ret; bool subtime = timevar_cond_start (TV_NAME_LOOKUP); @@ -1874,14 +1875,6 @@ pushdecl_maybe_friend (tree x, bool is_f return ret; } -/* Record a decl-node X as belonging to the current lexical scope. */ - -tree -pushdecl (tree x) -{ - return pushdecl_maybe_friend (x, false); -} - /* Enter DECL into the symbol table, if that's appropriate. Returns DECL, or a modified version thereof. */ @@ -2862,7 +2855,7 @@ pushdecl_with_scope_1 (tree x, cp_bindin { b = current_binding_level; current_binding_level = level; - x = pushdecl_maybe_friend (x, is_friend); + x = pushdecl (x, is_friend); current_binding_level = b; } current_function_decl = function_decl; @@ -4548,47 +4541,30 @@ parse_using_directive (tree name_space, } } -/* Like pushdecl, only it places X in the global scope if appropriate. - Calls cp_finish_decl to register the variable, initializing it with - *INIT, if INIT is non-NULL. */ +/* Pushes X into the global namespace. */ -static tree -pushdecl_top_level_1 (tree x, tree *init, bool is_friend) +tree +pushdecl_top_level (tree x, bool is_friend) { bool subtime = timevar_cond_start (TV_NAME_LOOKUP); push_to_top_level (); x = pushdecl_namespace_level (x, is_friend); - if (init) - cp_finish_decl (x, *init, false, NULL_TREE, 0); pop_from_top_level (); timevar_cond_stop (TV_NAME_LOOKUP, subtime); return x; } -/* Like pushdecl, only it places X in the global scope if appropriate. */ - -tree -pushdecl_top_level (tree x) -{ - return pushdecl_top_level_1 (x, NULL, false); -} - -/* Like pushdecl_top_level, but adding the IS_FRIEND parameter. */ - -tree -pushdecl_top_level_maybe_friend (tree x, bool is_friend) -{ - return pushdecl_top_level_1 (x, NULL, is_friend); -} - -/* Like pushdecl, only it places X in the global scope if - appropriate. Calls cp_finish_decl to register the variable, - initializing it with INIT. */ +/* Pushes X into the global namespace and Calls cp_finish_decl to + register the variable, initializing it with INIT. */ tree pushdecl_top_level_and_finish (tree x, tree init) { - return pushdecl_top_level_1 (x, &init, false); + push_to_top_level (); + x = pushdecl_namespace_level (x, false); + cp_finish_decl (x, init, false, NULL_TREE, 0); + pop_from_top_level (); + return x; } /* Combines two sets of overloaded functions into an OVERLOAD chain, removing Index: name-lookup.h =================================================================== --- name-lookup.h (revision 247916) +++ name-lookup.h (working copy) @@ -335,11 +335,9 @@ extern tree innermost_non_namespace_valu extern cxx_binding *outer_binding (tree, cxx_binding *, bool); extern void cp_emit_debug_info_for_using (tree, tree); -extern tree pushdecl_maybe_friend (tree, bool is_friend); -extern tree pushdecl (tree); extern tree pushdecl_outermost_localscope (tree); -extern tree pushdecl_top_level_maybe_friend (tree, bool is_friend); -extern tree pushdecl_top_level (tree); +extern tree pushdecl (tree, bool is_friend = false); +extern tree pushdecl_top_level (tree, bool is_friend = false); extern tree pushdecl_top_level_and_finish (tree, tree); extern tree pushtag (tree, tree, tag_scope); extern bool push_namespace (tree); Index: pt.c =================================================================== --- pt.c (revision 247916) +++ pt.c (working copy) @@ -9920,7 +9920,7 @@ tsubst_friend_class (tree friend_tmpl, t = INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (TREE_TYPE (tmpl))); /* Inject this template into the global scope. */ - friend_type = TREE_TYPE (pushdecl_top_level_maybe_friend (tmpl, true)); + friend_type = TREE_TYPE (pushdecl_top_level (tmpl, true)); } if (context != global_namespace)