From patchwork Thu May 18 10:52:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 763912 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 3wT7Lg3fLTz9s3s for ; Thu, 18 May 2017 20:52:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vUBV0RrS"; 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=PwZFWZ+5vR4pHB/0SbTfGLmdipE6Fzk0sxE0fEqyYjZj3MgkMn RoOdJn57RF/GYqxT7DuGzjmLjuNoviumqtmcwmakuw9JcuiOmW559nh2NGzcwuOJ o6NrUYpkZGpsnSq7ReDUSEuHpY8JCJ9cEOvekxEtYYob7kw99l+XKHhtc= 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=YQGoUASzPa0CwqhZHZUkcWDIjCM=; b=vUBV0RrSVgp8lTB71dGv 0f2Nt3abgL893O8VZWfHf6D6VMMfOTdp8ByRJXiWGFjyKlqA/kSnVbfqLuooHGof 0zmMbJDMNPpMY2qicZejWK8Yet67klUN40rs42hdqUmNbYFmToa5AVlWFMyAx9iO fzSN1/lf/eETuSvQMDDtcq4= Received: (qmail 52945 invoked by alias); 18 May 2017 10:52:30 -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 52874 invoked by uid 89); 18 May 2017 10:52:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=placed X-HELO: mail-yb0-f174.google.com Received: from mail-yb0-f174.google.com (HELO mail-yb0-f174.google.com) (209.85.213.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 May 2017 10:52:24 +0000 Received: by mail-yb0-f174.google.com with SMTP id 132so9559318ybq.1 for ; Thu, 18 May 2017 03:52:27 -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=dR+iw6b0YmpT9X3n7fQtekYxt8QqRrSYJky6g58Cjes=; b=plMWcKzGZ9EQQPjfAc6J1TEb7q7gyFBY3jDGqneSE2zeQYQSm6WEmnJN4xjESJaaSV 4umovlT5RUma0BU40OXdnSCwKcGzGWdpSn7mpqmk5S5PLP5QLTet9wOYFo5nn4KXN8jp B0jTxGMuvV0+pBnPEVLpyUzYYdiD53Ver7drcBA4+ltxLIinDnRgtbpLXk4BtNMejPXG 6wmK1sxrW2N3PTyEsYVlJTZMLwZ2EgH20i5PusYAI4unSTPa7dIqkPKpqro05llJwsYX jYjJ8rgsFDudJf8Besi/KGEk5VPos9Ic3ycsWIypR/whF70o0g6dv+j9VzxTm9aIjvz3 NJTg== X-Gm-Message-State: AODbwcAXfZ7JgKYlIT2Omv0gdydd2octBVjTtLov8e4lrZlZw8IB2+2v 51Uu2nHwsy5yhw== X-Received: by 10.37.125.129 with SMTP id y123mr2746349ybc.162.1495104746370; Thu, 18 May 2017 03:52:26 -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 t68sm2250387ywe.40.2017.05.18.03.52.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 03:52:25 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] name-lookup args ordering Message-ID: <50087be0-859a-941d-068d-bfa5137b42cc@acm.org> Date: Thu, 18 May 2017 06:52:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 We're being inconsistent as to what order the name/scope args on lookup and insertion are placed. The lookup ones are scope:name whereas (some of) the insertion ones are name:scope. That's confusing. This patch fixes things up to consistently use scope:name. I also break out a local scope lookup function, which will be used elsewhere shortly. Applied to trunk. nathan 2017-05-18 Nathan Sidwell * name-lookup.c (find_local_binding): New, broken out of ... (lookup_name_innermost_nonclass_level_1): ... here. Call it. (set_namespace_binding): Swap scope & name args. (namespace_binding_1): Likewise. (pushdecl_maybe_friend_1): Adjust set_namespace_binding call. (push_overloaded_decl_1): Likewise. (set_global_binding): Likewise. (get_namespace_binding): Adjust namespace_binding_1 call. Index: name-lookup.c =================================================================== --- name-lookup.c (revision 248166) +++ name-lookup.c (working copy) @@ -37,7 +37,7 @@ static cxx_binding *cxx_binding_make (tr static cp_binding_level *innermost_nonclass_level (void); static void set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b); -static void set_namespace_binding (tree name, tree scope, tree val); +static void set_namespace_binding (tree scope, tree name, tree val); /* The bindings for a particular name in a particular scope. */ @@ -99,6 +99,26 @@ add_decl_to_level (tree decl, cp_binding } } +/* Find the binding for NAME in the local binding level B. */ + +static cxx_binding * +find_local_binding (cp_binding_level *b, tree name) +{ + if (cxx_binding *binding = IDENTIFIER_BINDING (name)) + for (;; b = b->level_chain) + { + if (binding->scope == b + && !(VAR_P (binding->value) + && DECL_DEAD_FOR_LOCAL (binding->value))) + return binding; + + /* Cleanup contours are transparent to the language. */ + if (b->kind != sk_cleanup) + break; + } + return NULL; +} + /* [basic.lookup.koenig] */ /* A nonzero return value in the functions below indicates an error. */ @@ -1778,7 +1798,7 @@ pushdecl_maybe_friend_1 (tree x, bool is || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == CONST_DECL || TREE_CODE (x) == TEMPLATE_DECL)) - set_namespace_binding (name, current_namespace, x); + set_namespace_binding (current_namespace, name, x); /* If new decl is `static' and an `extern' was seen previously, warn about it. */ @@ -2952,7 +2972,7 @@ push_overloaded_decl_1 (tree decl, int f new_binding = decl; if (doing_global) - set_namespace_binding (name, current_namespace, new_binding); + set_namespace_binding (current_namespace, name, new_binding); else { /* We only create an OVERLOAD if there was a previous binding at @@ -3964,7 +3984,7 @@ do_class_using_decl (tree scope, tree na static tree -namespace_binding_1 (tree name, tree scope) +namespace_binding_1 (tree scope, tree name) { cxx_binding *binding; @@ -3988,13 +4008,13 @@ get_namespace_binding (tree ns, tree nam bool subtime = timevar_cond_start (TV_NAME_LOOKUP); if (!ns) ns = global_namespace; - tree ret = namespace_binding_1 (name, ns); + tree ret = namespace_binding_1 (ns, name); timevar_cond_stop (TV_NAME_LOOKUP, subtime); return ret; } static void -set_namespace_binding (tree name, tree scope, tree val) +set_namespace_binding (tree scope, tree name, tree val) { cxx_binding *b; @@ -4020,7 +4040,7 @@ set_global_binding (tree name, tree val) { bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - set_namespace_binding (name, global_namespace, val); + set_namespace_binding (global_namespace, name, val); timevar_cond_stop (TV_NAME_LOOKUP, subtime); } @@ -5760,39 +5780,14 @@ lookup_type_scope (tree name, tag_scope static tree lookup_name_innermost_nonclass_level_1 (tree name) { - cp_binding_level *b; - tree t = NULL_TREE; - - b = innermost_nonclass_level (); + cp_binding_level *b = innermost_nonclass_level (); if (b->kind == sk_namespace) - { - t = get_namespace_binding (current_namespace, name); - - /* extern "C" function() */ - if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) - t = TREE_VALUE (t); - } - else if (IDENTIFIER_BINDING (name) - && LOCAL_BINDING_P (IDENTIFIER_BINDING (name))) - { - cxx_binding *binding; - binding = IDENTIFIER_BINDING (name); - while (1) - { - if (binding->scope == b - && !(VAR_P (binding->value) - && DECL_DEAD_FOR_LOCAL (binding->value))) - return binding->value; - - if (b->kind == sk_cleanup) - b = b->level_chain; - else - break; - } - } - - return t; + return namespace_binding_1 (current_namespace, name); + else if (cxx_binding *binding = find_local_binding (b, name)) + return binding->value; + else + return NULL_TREE; } /* Wrapper for lookup_name_innermost_nonclass_level_1. */