From patchwork Fri May 19 14:14:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 764683 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 3wTqnx70ccz9s3s for ; Sat, 20 May 2017 00:15:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ovDnOfHK"; 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=jNA8BW9LK3jK4/V0A7dDpv/UDbIoSwiB25adYj6eHFg4ZoM6Wu qt3wsP7GCTdeRRuKUM3hL9dc6+Jyx/rX+nja9EeLuF0fL298/EahRSRqfYVS5I+G fewwAGxg3hoIVEsV0wxeH4GYTMVM71aXwJmY1d1kOXV3f0k0OGv2nBwpU= 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=tmGrVkWpDmWaq10BX6FMKrt9mPA=; b=ovDnOfHKjFbj3Bg3PEJa vsHvSx6mXBL2Y0+Yoc15yfPmdCS86TQWU0ZuzmNAMLOECkzLYkCgbsCVNi+ejvxw ZEl8g1fuv5UsELtkGydrwG9q/bvA3EG1THXWC+Grq5e42uYlUfLYsfXfBfxZp8gF GjrioZrf6w99/VVA+ZTCDYs= Received: (qmail 68266 invoked by alias); 19 May 2017 14:15:00 -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 67954 invoked by uid 89); 19 May 2017 14:14:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=exciting X-HELO: mail-yw0-f172.google.com Received: from mail-yw0-f172.google.com (HELO mail-yw0-f172.google.com) (209.85.161.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 May 2017 14:14:54 +0000 Received: by mail-yw0-f172.google.com with SMTP id p73so24776017ywp.0 for ; Fri, 19 May 2017 07:14:57 -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=tkcKLkf8o0zi5wKmrL6M7KdguDVp2T2gNaZzwPC38Mo=; b=I/VLtHO7xAIpMAtV2QktLVMFm/2612Ly/oHFqg4OaHn5GHK0XyulTlwRBqu/saFPlV E/f6u88spHba4Ow/2vrhj/P1wj6vrML04nmGyBa0K6IQE86xD94ByzB2VCu6SmZNYW1G PY8jQh7g3QALMxrJlyN7tVl73G917aEbKhDEGDtXCKxhQVGZoQAXXDuE8Wxv6Rp3T7a7 Zm+DHE362glA0Rkr1aFVaL3KFR3JgZjBTJCmHoRJfklGdmmEeuBRA/nQ1LWX5Tu69iut 0E3fheHVWj9xdVSlsSv/Ijc1EOQY4gbw2jOtrQEU6go4VJVosPw0vXWtGrmwgeOCh1Zm BuYg== X-Gm-Message-State: AODbwcClWF3PIxAdOMnWKdRHEE6+SKyGQWn9/A/k3hrayY2/8bwTS1Gi lYvNCrx+wAXEfg== X-Received: by 10.129.167.199 with SMTP id e190mr8176278ywh.261.1495203296063; Fri, 19 May 2017 07:14:56 -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 h1sm3635296ywk.57.2017.05.19.07.14.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 07:14:55 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] OVERLOAD iterators #8 Message-ID: <0f6be996-1266-425a-c023-8f22a25fbe56@acm.org> Date: Fri, 19 May 2017 10:14:53 -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 gets the remaining stragglers outside of name-lookup. Nothing particularly exciting here. Remaining patches will be primarily in name-lookup.c, with a few in cp-tree.h, tree.c and the parser. These will be the patches that are the significant changes (all this lot was just ground work!) nathan 2017-05-19 Nathan Sidwell * call.c (add_list_candidates): Use OVL_FIRST. (build_new_method_call_1): Likewise. * cp-tree.h (OVL_SINGLE_P): New. (TYPE_HIDDEN_P): New. * decl.c (xref_tag_1): Use TYPE_HIDDEN_P. * dump.c (cp_tump_tree): Adjust overload dumping. * error.c (dump_decl): Use OVL_SINGLE_P, simplify context printing. * method.c (lazily_declare_fn): Assert we added it. * parser.c (cp_parser_nested_name_specifier): Use OVL_SINGLE_P, OVL_FIRST. (cp_parser_template_name): Use lkp_iterator. * pt.c (begin_template_parm_list): Fixup comment. (instantiate_class_template_1): Use TYPE_HIDDEN_P. * tree.c (ovl_iterator::remove_node): Cope with inherited ctors. (ovl_scope): Use lkp_iterator. Index: call.c =================================================================== --- call.c (revision 248265) +++ call.c (working copy) @@ -3666,7 +3666,7 @@ add_list_candidates (tree fns, tree firs avoid the copy constructor call for copy-list-initialization. */ flags |= LOOKUP_NO_NARROWING; - unsigned nart = num_artificial_parms_for (get_first_fn (fns)) - 1; + unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1; tree init_list = (*args)[nart]; /* Always use the default constructor if the list is empty (DR 990). */ @@ -8539,7 +8539,7 @@ build_new_method_call_1 (tree instance, gcc_assert (TREE_CODE (fns) == FUNCTION_DECL || TREE_CODE (fns) == TEMPLATE_DECL || TREE_CODE (fns) == OVERLOAD); - fn = get_first_fn (fns); + fn = OVL_FIRST (fns); name = DECL_NAME (fn); basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance)); @@ -8708,7 +8708,7 @@ build_new_method_call_1 (tree instance, tree errname = name; if (IDENTIFIER_CTOR_OR_DTOR_P (errname)) { - tree fn = DECL_ORIGIN (get_first_fn (fns)); + tree fn = DECL_ORIGIN (OVL_FIRST (fns)); errname = DECL_NAME (fn); } if (explicit_targs) Index: cp-tree.h =================================================================== --- cp-tree.h (revision 248265) +++ cp-tree.h (working copy) @@ -655,6 +655,10 @@ typedef struct ptrmem_cst * ptrmem_cst_t /* The name of the overload set. */ #define OVL_NAME(NODE) DECL_NAME (OVL_FIRST (NODE)) +/* Whether this is a single member overload. */ +#define OVL_SINGLE_P(NODE) \ + (TREE_CODE (NODE) != OVERLOAD || !OVL_CHAIN (NODE)) + struct GTY(()) tree_overload { struct tree_common common; tree function; @@ -3750,6 +3754,11 @@ more_aggr_init_expr_args_p (const aggr_i (DECL_LANG_SPECIFIC (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK (NODE)) \ ->u.base.anticipated_p) +/* True if this is a hidden class type. */ +#define TYPE_HIDDEN_P(NODE) \ + (DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \ + && DECL_ANTICIPATED (TYPE_NAME (NODE))) + /* True for artificial decls added for OpenMP privatized non-static data members. */ #define DECL_OMP_PRIVATIZED_MEMBER(NODE) \ Index: decl.c =================================================================== --- decl.c (revision 248265) +++ decl.c (working copy) @@ -13636,16 +13636,18 @@ xref_tag_1 (enum tag_types tag_code, tre } /* Make injected friend class visible. */ - if (scope != ts_within_enclosing_non_class - && hidden_name_p (TYPE_NAME (t))) + if (scope != ts_within_enclosing_non_class && TYPE_HIDDEN_P (t)) { - DECL_ANTICIPATED (TYPE_NAME (t)) = 0; - DECL_FRIEND_P (TYPE_NAME (t)) = 0; + tree decl = TYPE_NAME (t); + + DECL_ANTICIPATED (decl) = false; + DECL_FRIEND_P (decl) = false; if (TYPE_TEMPLATE_INFO (t)) { - DECL_ANTICIPATED (TYPE_TI_TEMPLATE (t)) = 0; - DECL_FRIEND_P (TYPE_TI_TEMPLATE (t)) = 0; + tree tmpl = TYPE_TI_TEMPLATE (t); + DECL_ANTICIPATED (tmpl) = false; + DECL_FRIEND_P (tmpl) = false; } } } Index: dump.c =================================================================== --- dump.c (revision 248265) +++ dump.c (working copy) @@ -364,8 +364,10 @@ cp_dump_tree (void* dump_info, tree t) break; case OVERLOAD: - dump_child ("crnt", OVL_CURRENT (t)); - dump_child ("chan", OVL_CHAIN (t)); + dump_child ("name", OVL_NAME (t)); + if (!dump_flag (di, TDF_SLIM, t)) + for (lkp_iterator iter (t); iter; ++iter) + dump_child ("chld", *iter); break; case TRY_BLOCK: Index: error.c =================================================================== --- error.c (revision 248265) +++ error.c (working copy) @@ -1189,17 +1189,16 @@ dump_decl (cxx_pretty_printer *pp, tree break; case OVERLOAD: - if (OVL_CHAIN (t)) + if (!OVL_SINGLE_P (t)) { - t = OVL_CURRENT (t); - if (DECL_CLASS_SCOPE_P (t)) + t = OVL_FIRST (t); + tree ctx = CP_DECL_CONTEXT (t); + if (ctx != global_namespace) { - dump_type (pp, DECL_CONTEXT (t), flags); - pp_cxx_colon_colon (pp); - } - else if (!DECL_FILE_SCOPE_P (t)) - { - dump_decl (pp, DECL_CONTEXT (t), flags); + if (TYPE_P (ctx)) + dump_type (pp, ctx, flags); + else + dump_decl (pp, ctx, flags); pp_cxx_colon_colon (pp); } dump_decl (pp, DECL_NAME (t), flags); Index: method.c =================================================================== --- method.c (revision 248265) +++ method.c (working copy) @@ -2387,7 +2387,8 @@ lazily_declare_fn (special_function_kind || sfk == sfk_copy_assignment) check_for_override (fn, type); /* Add it to CLASSTYPE_METHOD_VEC. */ - add_method (type, fn, false); + bool added = add_method (type, fn, false); + gcc_assert (added); /* Add it to TYPE_METHODS. */ if (sfk == sfk_destructor && DECL_VIRTUAL_P (fn)) Index: parser.c =================================================================== --- parser.c (revision 248265) +++ parser.c (working copy) @@ -6028,8 +6028,8 @@ cp_parser_nested_name_specifier_opt (cp_ if (is_overloaded_fn (tid)) { tree fns = get_fns (tid); - if (!OVL_CHAIN (fns)) - tmpl = OVL_CURRENT (fns); + if (OVL_SINGLE_P (fns)) + tmpl = OVL_FIRST (fns); error_at (token->location, "function template-id %qD " "in nested-name-specifier", tid); } @@ -15639,7 +15639,6 @@ cp_parser_template_name (cp_parser* pars { tree identifier; tree decl; - tree fns; cp_token *token = cp_lexer_peek_token (parser->lexer); /* If the next token is `operator', then we have either an @@ -15765,20 +15764,19 @@ cp_parser_template_name (cp_parser* pars } else { - tree fn = NULL_TREE; - /* The standard does not explicitly indicate whether a name that names a set of overloaded declarations, some of which are templates, is a template-name. However, such a name should be a template-name; otherwise, there is no way to form a template-id for the overloaded templates. */ - fns = BASELINK_P (decl) ? BASELINK_FUNCTIONS (decl) : decl; - if (TREE_CODE (fns) == OVERLOAD) - for (fn = fns; fn; fn = OVL_NEXT (fn)) - if (TREE_CODE (OVL_CURRENT (fn)) == TEMPLATE_DECL) - break; + bool found = false; + + for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl)); + !found && iter; ++iter) + if (TREE_CODE (*iter) == TEMPLATE_DECL) + found = true; - if (!fn) + if (!found) { /* The name does not name a template. */ cp_parser_error (parser, "expected template-name"); Index: pt.c =================================================================== --- pt.c (revision 248265) +++ pt.c (working copy) @@ -648,8 +648,8 @@ begin_template_parm_list (void) template struct S2 {}; }; - pushtag contains special code to call pushdecl_with_scope on the - TEMPLATE_DECL for S2. */ + pushtag contains special code to insert the TEMPLATE_DECL for S2 + at the right scope. */ begin_scope (sk_template_parms, NULL); ++processing_template_decl; ++processing_template_parmlist; @@ -10592,7 +10592,7 @@ instantiate_class_template_1 (tree type) --processing_template_decl; } else if (!CLASSTYPE_USE_TEMPLATE (friend_type) - && hidden_name_p (TYPE_NAME (friend_type))) + && TYPE_HIDDEN_P (friend_type)) { /* friend class C; Index: tree.c =================================================================== --- tree.c (revision 248265) +++ tree.c (working copy) @@ -2230,7 +2230,11 @@ ovl_iterator::remove_node (tree overload singleton overload (and consequently maybe setting its type), because all uses of this function will be followed by inserting a new node that must follow the place we've cut this out from. */ - *slot = OVL_CHAIN (node); + if (TREE_CODE (node) != OVERLOAD) + /* Cloned inherited ctors don't mark themselves as via_using. */ + *slot = NULL_TREE; + else + *slot = OVL_CHAIN (node); return overload; } @@ -2362,9 +2366,12 @@ ovl_scope (tree ovl) if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR) ovl = TREE_OPERAND (ovl, 0); /* Skip using-declarations. */ - while (TREE_CODE (ovl) == OVERLOAD && OVL_USING_P (ovl) && OVL_CHAIN (ovl)) - ovl = OVL_CHAIN (ovl); - return CP_DECL_CONTEXT (OVL_CURRENT (ovl)); + lkp_iterator iter (ovl); + do + ovl = *iter; + while (iter.using_p () && ++iter); + + return CP_DECL_CONTEXT (ovl); } #define PRINT_RING_SIZE 4